13#ifndef _CS237_BUFFER_HPP_
14#define _CS237_BUFFER_HPP_
17#error "cs237-buffer.hpp should not be included directly"
34 vk::MemoryRequirements reqs;
51 vk::BufferCreateInfo info(
55 vk::SharingMode::eExclusive,
58 this->_buf = app->
_device.createBuffer (info);
62 this->_app->
_device.bindBufferMemory(this->_buf, this->_mem->
_mem, 0);
70 this->_app->
_device.destroyBuffer (this->_buf,
nullptr);
78 void _copyTo (
const void *src,
size_t offset,
size_t sz)
80 this->_mem->
copyTo(src, offset, sz);
102 :
Buffer (app, vk::BufferUsageFlagBits::eVertexBuffer, nVerts*sizeof(V))
116 void copyTo (vk::ArrayProxy<V>
const &src)
118 assert ((src.size() *
sizeof(V) <= this->_mem->size()) &&
"src is too large");
119 this->
_copyTo(src.data(), 0, src.size()*
sizeof(V));
125 void copyTo (vk::ArrayProxy<V>
const &src, uint32_t offset)
127 assert (((src.size()+offset) *
sizeof(V) <= this->_mem->size())
128 &&
"src is too large");
129 this->
_copyTo(src.data(), offset*
sizeof(V), src.size()*
sizeof(V));
146 :
Buffer (app, vk::BufferUsageFlagBits::eIndexBuffer,
nIndices*sizeof(I)),
160 uint32_t
nIndices ()
const {
return this->_nIndices; }
164 void copyTo (vk::ArrayProxy<I>
const &src)
166 assert ((src.size() *
sizeof(I) <= this->_mem->size()) &&
"src is too large");
167 this->
_copyTo(src.data(), 0, src.size()*
sizeof(I));
173 void copyTo (vk::ArrayProxy<I>
const &src, uint32_t offset)
175 assert (((src.size()+offset) *
sizeof(I) <= this->_mem->size())
176 &&
"src is too large");
177 this->
_copyTo(src.data(), offset*
sizeof(I), src.size()*
sizeof(I));
187template <
typename UB>
197 :
Buffer (app, vk::BufferUsageFlagBits::eUniformBuffer, sizeof(UB))
213 this->
_copyTo(&src, 0,
sizeof(UB));
219 return vk::DescriptorBufferInfo(this->
_buf, 0,
sizeof(UB));
the base class for applications
Definition cs237-application.hpp:25
vk::Device _device
the logical device that we are using to render
Definition cs237-application.hpp:380
A base class for buffer objects of all kinds.
Definition cs237-buffer.hpp:23
void _copyTo(const void *src)
Definition cs237-buffer.hpp:85
vk::MemoryRequirements requirements()
get the memory requirements of this buffer
Definition cs237-buffer.hpp:32
~Buffer()
destructor
Definition cs237-buffer.hpp:67
vk::Buffer _buf
the Vulkan buffer object
Definition cs237-buffer.hpp:41
MemoryObj * _mem
the Vulkan memory object that holds the buffer
Definition cs237-buffer.hpp:42
Buffer(Application *app, vk::BufferUsageFlags usage, size_t sz)
Definition cs237-buffer.hpp:48
void _copyTo(const void *src, size_t offset, size_t sz)
Definition cs237-buffer.hpp:78
const MemoryObj * memory() const
get the memory object for this buffer
Definition cs237-buffer.hpp:29
Application * _app
the application
Definition cs237-buffer.hpp:40
vk::Buffer vkBuffer() const
get the Vulkan buffer object for this buffer
Definition cs237-buffer.hpp:26
Buffer class for index data; the type parameter I is the index type.
Definition cs237-buffer.hpp:136
I IndexType
the type of indices
Definition cs237-buffer.hpp:140
void copyTo(vk::ArrayProxy< I > const &src)
Definition cs237-buffer.hpp:164
uint32_t nIndices() const
get the number of indices in the buffer
Definition cs237-buffer.hpp:160
void copyTo(vk::ArrayProxy< I > const &src, uint32_t offset)
Definition cs237-buffer.hpp:173
IndexBuffer(Application *app, vk::ArrayProxy< I > const &src)
Definition cs237-buffer.hpp:153
IndexBuffer(Application *app, uint32_t nIndices)
Definition cs237-buffer.hpp:145
wrapper around Vulkan memory objects
Definition cs237-memory-obj.hpp:23
vk::DeviceMemory _mem
the device memory object
Definition cs237-memory-obj.hpp:57
void copyTo(const void *src, size_t offset, size_t sz)
Definition cs237-memory-obj.hpp:34
Definition cs237-buffer.hpp:92
V VertexType
the type of vertices
Definition cs237-buffer.hpp:96
void copyTo(vk::ArrayProxy< V > const &src)
Definition cs237-buffer.hpp:116
VertexBuffer(Application *app, uint32_t nVerts)
Definition cs237-buffer.hpp:101
VertexBuffer(Application *app, vk::ArrayProxy< V > const &src)
Definition cs237-buffer.hpp:108
void copyTo(vk::ArrayProxy< V > const &src, uint32_t offset)
Definition cs237-buffer.hpp:125
Definition cs237-aabb.hpp:22