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);
105 :
Buffer (app, vk::BufferUsageFlagBits::eVertexBuffer, nVerts*sizeof(V))
122 void copyTo (vk::ArrayProxy<V>
const &src)
124 assert ((src.size() *
sizeof(V) <= this->_mem->size()) &&
"src is too large");
125 this->
_copyTo(src.data(), 0, src.size()*
sizeof(V));
131 void copyTo (vk::ArrayProxy<V>
const &src, uint32_t offset)
133 assert (((src.size()+offset) *
sizeof(V) <= this->_mem->size())
134 &&
"src is too large");
135 this->
_copyTo(src.data(), offset*
sizeof(V), src.size()*
sizeof(V));
152 :
Buffer (app, vk::BufferUsageFlagBits::eIndexBuffer,
nIndices*sizeof(I)),
166 uint32_t
nIndices ()
const {
return this->_nIndices; }
170 void copyTo (vk::ArrayProxy<I>
const &src)
172 assert ((src.size() *
sizeof(I) <= this->_mem->size()) &&
"src is too large");
173 this->
_copyTo(src.data(), 0, src.size()*
sizeof(I));
179 void copyTo (vk::ArrayProxy<I>
const &src, uint32_t offset)
181 assert (((src.size()+offset) *
sizeof(I) <= this->_mem->size())
182 &&
"src is too large");
183 this->
_copyTo(src.data(), offset*
sizeof(I), src.size()*
sizeof(I));
193template <
typename UB>
203 :
Buffer (app, vk::BufferUsageFlagBits::eUniformBuffer, sizeof(UB))
219 this->
_copyTo(&src, 0,
sizeof(UB));
225 return vk::DescriptorBufferInfo(this->
_buf, 0,
sizeof(UB));
233template <
typename SV>
244 :
Buffer (app, vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eVertexBuffer, nVerts*sizeof(SV))
258 void copyTo (vk::ArrayProxy<SV>
const &src)
260 assert ((src.size() *
sizeof(SV) <= this->_mem->size()) &&
"src is too large");
261 this->
_copyTo(src.data(), 0, src.size()*
sizeof(SV));
267 void copyTo (vk::ArrayProxy<SV>
const &src, uint32_t offset)
269 assert (((src.size()+offset) *
sizeof(SV) <= this->_mem->size())
270 &&
"src is too large");
271 this->
_copyTo(src.data(), offset*
sizeof(SV), src.size()*
sizeof(SV));
277 return vk::DescriptorBufferInfo(this->
_buf, 0,
sizeof(SV));
294 :
Buffer (app, vk::BufferUsageFlagBits::eStorageBuffer, sizeof(S))
310 :
Buffer (app, vk::BufferUsageFlagBits::eStorageBuffer, src.size()*sizeof(S))
320 this->
_copyTo(&src, 0,
sizeof(S));
326 return vk::DescriptorBufferInfo(this->
_buf, 0,
sizeof(S));
331 void copyTo (vk::ArrayProxy<S>
const &src)
333 assert ((src.size() *
sizeof(S) <= this->_mem->size()) &&
"src is too large");
334 this->
_copyTo(src.data(), 0, src.size()*
sizeof(S));
340 void copyTo (vk::ArrayProxy<S>
const &src, uint32_t offset)
342 assert (((src.size()+offset) *
sizeof(S) <= this->_mem->size())
343 &&
"src is too large");
344 this->
_copyTo(src.data(), offset*
sizeof(S), src.size()*
sizeof(S));
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
void _copyTo(const void *src)
Definition buffer.hpp:85
vk::MemoryRequirements requirements()
get the memory requirements of this buffer
Definition buffer.hpp:32
~Buffer()
destructor
Definition buffer.hpp:67
vk::Buffer _buf
the Vulkan buffer object
Definition buffer.hpp:41
MemoryObj * _mem
the Vulkan memory object that holds the buffer
Definition buffer.hpp:42
Buffer(Application *app, vk::BufferUsageFlags usage, size_t sz)
Definition buffer.hpp:48
void _copyTo(const void *src, size_t offset, size_t sz)
Definition buffer.hpp:78
MemoryObj * memory() const
get the memory object for this buffer
Definition buffer.hpp:29
Application * _app
the application
Definition buffer.hpp:40
vk::Buffer vkBuffer() const
get the Vulkan buffer object for this buffer
Definition buffer.hpp:26
Buffer class for index data; the type parameter I is the index type.
Definition buffer.hpp:142
I IndexType
the type of indices
Definition buffer.hpp:146
void copyTo(vk::ArrayProxy< I > const &src)
Definition buffer.hpp:170
uint32_t nIndices() const
get the number of indices in the buffer
Definition buffer.hpp:166
void copyTo(vk::ArrayProxy< I > const &src, uint32_t offset)
Definition buffer.hpp:179
IndexBuffer(Application *app, vk::ArrayProxy< I > const &src)
Definition buffer.hpp:159
IndexBuffer(Application *app, uint32_t nIndices)
Definition buffer.hpp:151
wrapper around Vulkan memory objects
Definition memory-obj.hpp:23
vk::DeviceMemory _mem
the device memory object
Definition memory-obj.hpp:59
void copyTo(const void *src, size_t offset, size_t sz)
Definition memory-obj.hpp:34
Definition buffer.hpp:285
StorageBuffer(Application *app, S const &src)
Definition buffer.hpp:300
void copyTo(S const &src)
Definition buffer.hpp:318
void copyTo(vk::ArrayProxy< S > const &src, uint32_t offset)
Definition buffer.hpp:340
S BufferType
the type of the buffer's contents
Definition buffer.hpp:289
vk::DescriptorBufferInfo descInfo()
get the default buffer-descriptor info for this buffer
Definition buffer.hpp:324
void copyTo(vk::ArrayProxy< S > const &src)
Definition buffer.hpp:331
StorageBuffer(Application *app)
Definition buffer.hpp:293
StorageBuffer(Application *app, vk::ArrayProxy< S > const &src)
Definition buffer.hpp:309
Definition buffer.hpp:234
StorageVertexBuffer(Application *app, vk::ArrayProxy< SV > const &src)
Definition buffer.hpp:250
void copyTo(vk::ArrayProxy< SV > const &src, uint32_t offset)
Definition buffer.hpp:267
void copyTo(vk::ArrayProxy< SV > const &src)
Definition buffer.hpp:258
SV BufferType
the type of the buffer's contents
Definition buffer.hpp:238
StorageVertexBuffer(Application *app, uint32_t nVerts)
Definition buffer.hpp:243
vk::DescriptorBufferInfo descInfo()
get the default buffer-descriptor info for this buffer
Definition buffer.hpp:275
V VertexType
the type of vertices
Definition buffer.hpp:96
void copyTo(vk::ArrayProxy< V > const &src)
Definition buffer.hpp:122
VertexBuffer(Application *app, uint32_t nVerts)
Definition buffer.hpp:104
VertexBuffer(Application *app, vk::ArrayProxy< V > const &src)
Definition buffer.hpp:114
void copyTo(vk::ArrayProxy< V > const &src, uint32_t offset)
Definition buffer.hpp:131