CMSC23740 Common Code Library
Support code for CS23740 programming projects
Toggle main menu visibility
Loading...
Searching...
No Matches
memory-obj.hpp
Go to the documentation of this file.
1
7
8
/*
9
* COPYRIGHT (c) 2026 John Reppy (https://cs.uchicago.edu/~jhr)
10
* All rights reserved.
11
*/
12
13
#ifndef _CS237_MEMORY_OBJ_HPP_
14
#define _CS237_MEMORY_OBJ_HPP_
15
16
#ifndef _CS237_HPP_
17
#error "cs237/memory.hpp should not be included directly"
18
#endif
19
20
namespace
cs237
{
21
23
class
MemoryObj
{
24
friend
class
Buffer
;
25
26
public
:
27
MemoryObj
(
Application
*app, vk::MemoryRequirements
const
&reqs);
28
~MemoryObj
();
29
34
void
copyTo
(
const
void
*src,
size_t
offset,
size_t
sz)
35
{
36
assert (offset + sz <= this->
_sz
);
37
38
auto
dev = this->
_app
->
_device
;
39
40
// first we need to map the object into our address space
41
auto
dst = dev.mapMemory(this->
_mem
, offset, this->_sz, {});
42
// copy the data
43
memcpy(dst, src, sz);
44
// unmap the object
45
this->
_app
->
_device
.unmapMemory (this->
_mem
);
46
}
47
50
void
copyTo
(
const
void
*src) { this->
copyTo
(src, 0, this->
_sz
); }
51
53
size_t
size
()
const
{
return
this->
_sz
; }
54
55
vk::DeviceMemory
getDeviceMemory
() {
return
this->
_mem
; }
56
57
protected
:
58
Application
*
_app
;
59
vk::DeviceMemory
_mem
;
60
size_t
_sz
;
61
62
};
63
64
}
// namespace cs237
65
66
#endif
// !_CS237_MEMORY_OBJ_HPP_
cs237::Application
the base class for applications
Definition
application.hpp:25
cs237::Application::_device
vk::Device _device
the logical device that we are using to render
Definition
application.hpp:433
cs237::MemoryObj::_app
Application * _app
the application
Definition
memory-obj.hpp:58
cs237::MemoryObj::size
size_t size() const
the size of the memory object in bytes
Definition
memory-obj.hpp:53
cs237::MemoryObj::~MemoryObj
~MemoryObj()
cs237::MemoryObj::MemoryObj
MemoryObj(Application *app, vk::MemoryRequirements const &reqs)
cs237::MemoryObj::_mem
vk::DeviceMemory _mem
the device memory object
Definition
memory-obj.hpp:59
cs237::MemoryObj::_sz
size_t _sz
the size of the memory object
Definition
memory-obj.hpp:60
cs237::MemoryObj::Buffer
friend class Buffer
Definition
memory-obj.hpp:24
cs237::MemoryObj::copyTo
void copyTo(const void *src, size_t offset, size_t sz)
Definition
memory-obj.hpp:34
cs237::MemoryObj::getDeviceMemory
vk::DeviceMemory getDeviceMemory()
Definition
memory-obj.hpp:55
cs237::MemoryObj::copyTo
void copyTo(const void *src)
Definition
memory-obj.hpp:50
cs237
Definition
aabb.hpp:22
cs237-library
include
cs237
memory-obj.hpp
Generated by
1.18.0