Chronos 0.0
A advanced 2D rendering and animation system
Loading...
Searching...
No Matches
Chronos::Engine::UniformBuffer Class Reference

This is a Uniform buffer for storing the uniform variables in the shaders. More...

#include <buffers.hpp>

Inheritance diagram for Chronos::Engine::UniformBuffer:
Collaboration diagram for Chronos::Engine::UniformBuffer:

Public Member Functions

void create (Chronos::Engine::Device device)
 Creates the buffer and maps the memory.
 
void update (VkExtent2D swapChainExtent, float x, float y, float rotation, float x_size, float y_size)
 Updates the buffer with the given information.
 
- Public Member Functions inherited from Chronos::Engine::Buffer
void create (Chronos::Engine::Device device, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties)
 This is used to initialize the buffer.
 
void copy (void *data, VkCommandPool commandPool)
 Copies the data to the buffer.
 
void destroy ()
 Destroys the buffer and frees the memory.
 

Private Attributes

void * data
 Temporary storage used to store the data before copying to the buffer.
 

Additional Inherited Members

- Public Attributes inherited from Chronos::Engine::Buffer
VkBuffer buffer
 The buffer.
 
VkDeviceSize size
 The size of the buffer.
 
VkDeviceMemory memory
 The device memory of the buffer.
 

Detailed Description

This is a Uniform buffer for storing the uniform variables in the shaders.

Currently used only for shapes properties like postition, size etc. Can be updated on the fly using the update function.

Definition at line 104 of file buffers.hpp.

Member Function Documentation

◆ create()

void Chronos::Engine::UniformBuffer::create ( Chronos::Engine::Device  device)

Creates the buffer and maps the memory.

It uses the inherited function create to create the buffer

Parameters
deviceThe device on which the buffer should be stored.

Definition at line 73 of file buffers.cpp.

74{
75 size = sizeof(UniformBufferObject);
76 Buffer::create(device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
77 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
78 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); // want to be visible to
79 // host and device
80 vkMapMemory(device.device, memory, 0, size, 0, &data);
81}
VkDeviceSize size
The size of the buffer.
Definition buffers.hpp:83
void create(Chronos::Engine::Device device, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties)
This is used to initialize the buffer.
Definition buffers.cpp:27
VkDeviceMemory memory
The device memory of the buffer.
Definition buffers.hpp:88
Chronos::Engine::Device device
The device on which the buffer is stored.
Definition buffers.hpp:94
VkDevice device
This is the logical device that is used by Vulkan.
Definition device.hpp:52
void * data
Temporary storage used to store the data before copying to the buffer.
Definition buffers.hpp:141

References Chronos::Engine::Buffer::create(), and Chronos::Engine::Device::device.

Here is the call graph for this function:

◆ update()

void Chronos::Engine::UniformBuffer::update ( VkExtent2D  swapChainExtent,
float  x,
float  y,
float  rotation,
float  x_size,
float  y_size 
)

Updates the buffer with the given information.

It creates a UniformBufferObject. The entires in this struct are calculated using glm functions. We need the swapChainExtent to calculate the projection matrix so that the scale is correct even when resizing windows.

Parameters
swapChainExtentThe extent of the swap chain.
xThe x coordinate of the shape.
yThe y coordinate of the shape.
rotationThe rotation of the shape.
x_sizeThe x size of the shape.
y_sizeThe y size of the shape.

Definition at line 83 of file buffers.cpp.

85{
86 // This is where the shape parameters are updated
87 UniformBufferObject ubo {};
88 ubo.model = glm::translate(glm::mat4(1.0f), glm::vec3(y, -x, 0.0f));
89 ubo.model = glm::rotate(
90 ubo.model, glm::radians(rotation), glm::vec3(0.0f, 0.0f, 1.0f));
91 ubo.model = glm::scale(ubo.model, glm::vec3(y_size, x_size, 1.0f));
92 ubo.view = glm::lookAt(glm::vec3(0.0f, 0.0f, 0.1f),
93 glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f));
94 ubo.proj = glm::ortho(-1.0f, 1.0f,
95 -(float)swapChainExtent.height / (float)swapChainExtent.width,
96 (float)swapChainExtent.height / (float)swapChainExtent.width, -100.0f,
97 100.0f);
98 ubo.proj[1][1] *= -1;
99 memcpy(data, &ubo, sizeof(ubo));
100 LOG(4,
101 "Uniform buffer object updated for buffer ["
102 + std::to_string((uint64_t)buffer) + "]")
103}
VkBuffer buffer
The buffer.
Definition buffers.hpp:78
#define LOG(LEVEL, MESSAGE)
Definition logging.hpp:60

References LOG, and Chronos::Engine::UniformBufferObject::model.

Member Data Documentation

◆ data

void* Chronos::Engine::UniformBuffer::data
private

Temporary storage used to store the data before copying to the buffer.

Definition at line 141 of file buffers.hpp.


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