KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::VulkanVertexBuffer Class Reference

Vulkan's vertex buffer class. Vertex buffer is used in agnostic Mesh instance. More...

#include <VulkanBuffer.h>

Inheritance diagram for Karma::VulkanVertexBuffer:
Collaboration diagram for Karma::VulkanVertexBuffer:

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 BufferLayoutGetLayout () 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 Public Member Functions inherited from Karma::VertexBuffer
static VertexBufferCreate (float *vertices, uint32_t size)
 

Detailed Description

Vulkan's vertex buffer class. Vertex buffer is used in agnostic Mesh instance.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ VulkanVertexBuffer()

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.

Parameters
verticesfloat array of interleaved vertex data (including position, uv, color, normal, and tangent) based on the BufferLayout
sizeSize (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
};
will have size = 3 * (7 * sizeof(float)).
See also
Mesh::DealVertexIndexBufferData, VulkanVertexBuffer::CreateBuffer
Since
Karma 1.0.0

◆ ~VulkanVertexBuffer()

Karma::VulkanVertexBuffer::~VulkanVertexBuffer ( )
virtual

Destructor.

Deletes the buffers and clears up Vulkan relevant resources

Since
Karma 1.0.0

Member Function Documentation

◆ Bind()

void Karma::VulkanVertexBuffer::Bind ( ) const
overridevirtual

Not useful for Vulkan API atm.

Todo
Ponder over Vulkan equivalent of glBindBuffer
Since
Karma 1.0.0

Implements Karma::VertexBuffer.

◆ CopyBuffer()

void Karma::VulkanVertexBuffer::CopyBuffer ( VkBuffer srcBuffer,
VkBuffer dstBuffer,
VkDeviceSize size )

Copy buffer.

Parameters
srcBufferThe source buffer to copy data from
dstBufferThe destination buffer to copy data to
sizeThe total size of data in bytes
Since
Karma 1.0.0

◆ CreateBuffer()

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.

Parameters
sizeThe size (in bytes) of the buffer object to be created
usageThe bitmask of VkBufferUsageFlagBits (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html) specifying allowed usages of the buffer.
propertiesThe bitmask of VkMemoryPropertyFlagBits of properties for this memory type of the buffer.
bufferThe pointer to a VkBuffer handle in which the resulting buffer object is returned.
bufferMemoryThe pointer to a VkDeviceMemory handle in which information about the allocated memory is returned.
Since
Karma 1.0.0

◆ FindMemoryType()

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.

Parameters
typeFilterA 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.
propertiesThe demanded properties (https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkBufferUsageFlagBits.html).
Returns
Memory type index i
See also
VulkanUniformBuffer::CreateBuffer
Since
Karma 1.0.0

◆ GetLayout()

virtual const BufferLayout & Karma::VulkanVertexBuffer::GetLayout ( ) const
inlineoverridevirtual

Getter for the layout of the vertex buffer.

Since
Karma 1.0.0

Implements Karma::VertexBuffer.

◆ GetVertexBuffer()

VkBuffer Karma::VulkanVertexBuffer::GetVertexBuffer ( ) const
inline

Getter for vertex buffer.

Since
Karma 1.0.0

◆ GetVertexBufferMemory()

VkDeviceMemory Karma::VulkanVertexBuffer::GetVertexBufferMemory ( ) const
inline

Getter for vertex buffer memory.

Since
Karma 1.0.0

◆ SetLayout()

virtual void Karma::VulkanVertexBuffer::SetLayout ( const BufferLayout & layout)
inlineoverridevirtual

Sets the layout of the vertexbuffer.

Parameters
layoutThe reference to layout to be set
Since
Karma 1.0.0

Implements Karma::VertexBuffer.

◆ UnBind()

void Karma::VulkanVertexBuffer::UnBind ( ) const
overridevirtual

Not useful for Vulkan API atm.

Todo
Ponder over Vulkan equivalent of glBindBuffer(GL_ARRAY_BUFFER, 0);
Since
Karma 1.0.0

Implements Karma::VertexBuffer.


The documentation for this class was generated from the following files: