KarmaEngine
Game Engine for practical learning and research purposes
|
Vulkan's vertex buffer class. Vertex buffer is used in agnostic Mesh instance. More...
#include <VulkanBuffer.h>
Public Member Functions | |
VulkanVertexBuffer (float *vertices, uint32_t size) | |
Constructor. | |
virtual | ~VulkanVertexBuffer () |
Destructor. | |
virtual void | Bind () const override |
Not useful for Vulkan API atm. | |
virtual void | UnBind () const override |
Not useful for Vulkan API atm. | |
virtual const BufferLayout & | GetLayout () const override |
Getter for the layout of the vertex buffer. | |
virtual void | SetLayout (const BufferLayout &layout) override |
Sets the layout of the vertexbuffer. | |
void | CreateBuffer (VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer &buffer, VkDeviceMemory &bufferMemory) |
Actual creation of buffer using Vulkan API. Memory is also allocated appropriately. | |
void | CopyBuffer (VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) |
Copy buffer. | |
uint32_t | FindMemoryType (uint32_t typeFilter, VkMemoryPropertyFlags properties) |
Finds appropriate memory type with demanded properties. Basically a loop is run from counter i = 0 to VkPhysicalDeviceMemoryProperties.memoryTypeCount (number of valid elements in the memoryTypes array) and memoryType[i] is queried for appropriate properties. On condition satisfaction, counter i is returned. | |
VkBuffer | GetVertexBuffer () const |
Getter for vertex buffer. | |
VkDeviceMemory | GetVertexBufferMemory () const |
Getter for vertex buffer memory. | |
size_t | GetBufferSize () |
Getter for buffer size (in bytes) | |
Additional Inherited Members | |
![]() | |
static VertexBuffer * | Create (float *vertices, uint32_t size) |
Vulkan's vertex buffer class. Vertex buffer is used in agnostic Mesh instance.
Karma::VulkanVertexBuffer::VulkanVertexBuffer | ( | float * | vertices, |
uint32_t | size ) |
Constructor.
The single vertex buffer works correctly, but the memory type that allows us to access it from the CPU may not be the most optimal memory type for the graphics card itself to read from. The most optimal memory has the VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT flag and is usually not accessible by the CPU on dedicated graphics cards. In this chapter (https://vulkan-tutorial.com/Vertex_buffers/Staging_buffer) we're going to create two vertex buffers. One staging buffer in CPU accessible memory to upload the data from the vertex array to, and the final vertex buffer in device (GPU) local memory. We'll then use a buffer copy command to move the data from the staging buffer to the actual vertex buffer.
vertices | float array of interleaved vertex data (including position, uv, color, normal, and tangent) based on the BufferLayout |
size | Size (in bytes) of the vertex buffer (number of mesh vertices * sum of each vertex attribute's size). For instance: float vertices[3 * 7] = {
-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f
};
|
|
virtual |
Destructor.
Deletes the buffers and clears up Vulkan relevant resources
|
overridevirtual |
Not useful for Vulkan API atm.
Implements Karma::VertexBuffer.
void Karma::VulkanVertexBuffer::CopyBuffer | ( | VkBuffer | srcBuffer, |
VkBuffer | dstBuffer, | ||
VkDeviceSize | size ) |
Copy buffer.
srcBuffer | The source buffer to copy data from |
dstBuffer | The destination buffer to copy data to |
size | The total size of data in bytes |
void Karma::VulkanVertexBuffer::CreateBuffer | ( | VkDeviceSize | size, |
VkBufferUsageFlags | usage, | ||
VkMemoryPropertyFlags | properties, | ||
VkBuffer & | buffer, | ||
VkDeviceMemory & | bufferMemory ) |
Actual creation of buffer using Vulkan API. Memory is also allocated appropriately.
size | The size (in bytes) of the buffer object to be created |
usage | The bitmask of VkBufferUsageFlagBits (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html) specifying allowed usages of the buffer. |
properties | The bitmask of VkMemoryPropertyFlagBits of properties for this memory type of the buffer. |
buffer | The pointer to a VkBuffer handle in which the resulting buffer object is returned. |
bufferMemory | The pointer to a VkDeviceMemory handle in which information about the allocated memory is returned. |
uint32_t Karma::VulkanVertexBuffer::FindMemoryType | ( | uint32_t | typeFilter, |
VkMemoryPropertyFlags | properties ) |
Finds appropriate memory type with demanded properties. Basically a loop is run from counter i = 0 to VkPhysicalDeviceMemoryProperties.memoryTypeCount (number of valid elements in the memoryTypes array) and memoryType[i] is queried for appropriate properties. On condition satisfaction, counter i is returned.
Graphics cards can offer different types of memory to allocate from. Each type of memory varies in terms of allowed operations and performance characteristics. We need to combine the requirements of the buffer and our own application requirements to find the right type of memory to use.
typeFilter | A bitmask, and contains one bit set for every supported memory type for the resource. Bit i is set if and only if the memory type i in the VkPhysicalDeviceMemoryProperties structure for the physical device is supported for the resource. |
properties | The demanded properties (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html). |
|
inlineoverridevirtual |
|
inline |
Getter for vertex buffer.
|
inline |
Getter for vertex buffer memory.
|
inlineoverridevirtual |
Sets the layout of the vertexbuffer.
layout | The reference to layout to be set |
Implements Karma::VertexBuffer.
|
overridevirtual |
Not useful for Vulkan API atm.
Implements Karma::VertexBuffer.