CMSC23740 Common Code Library
Support code for CS23740 programming projects
Loading...
Searching...
No Matches
memory-obj.hpp
Go to the documentation of this file.
1
8/*
9 * COPYRIGHT (c) 2024 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
20namespace cs237 {
21
23class MemoryObj {
24 friend class Buffer;
25
26public:
27 MemoryObj (Application *app, vk::MemoryRequirements const &reqs);
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
57protected:
59 vk::DeviceMemory _mem;
60 size_t _sz;
61
62};
63
64} // namespace cs237
65
66#endif // !_CS237_MEMORY_OBJ_HPP_
the base class for applications
Definition application.hpp:25
vk::Device _device
the logical device that we are using to render
Definition application.hpp:443
A base class for buffer objects of all kinds.
Definition buffer.hpp:23
wrapper around Vulkan memory objects
Definition memory-obj.hpp:23
Application * _app
the application
Definition memory-obj.hpp:58
size_t size() const
the size of the memory object in bytes
Definition memory-obj.hpp:53
MemoryObj(Application *app, vk::MemoryRequirements const &reqs)
vk::DeviceMemory _mem
the device memory object
Definition memory-obj.hpp:59
size_t _sz
the size of the memory object
Definition memory-obj.hpp:60
void copyTo(const void *src, size_t offset, size_t sz)
Definition memory-obj.hpp:34
vk::DeviceMemory getDeviceMemory()
Definition memory-obj.hpp:55
void copyTo(const void *src)
Definition memory-obj.hpp:50
Definition aabb.hpp:22