28 VkBufferUsageFlags flags, VkMemoryPropertyFlags properties)
34 "Buffer [" + std::to_string((uint64_t)this->
buffer)
35 +
"] created for buffer object [" + std::to_string((uint64_t)
this)
43 VkBuffer stagingBuffer;
44 VkDeviceMemory stagingBufferMemory;
46 VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
47 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
48 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
49 &stagingBuffer, &stagingBufferMemory);
50 vkMapMemory(device.device, stagingBufferMemory, 0, size, 0, &data);
51 memcpy(data, inputData, (
size_t)size);
52 vkUnmapMemory(device.device, stagingBufferMemory);
54 device, stagingBuffer, buffer, size, commandPool);
55 vkDestroyBuffer(device.device, stagingBuffer,
nullptr);
56 vkFreeMemory(device.device, stagingBufferMemory,
nullptr);
58 "Data [" + std::to_string((uint64_t)buffer)
59 +
"] copied to device buffer [" + std::to_string((uint64_t)buffer)
65 vkDestroyBuffer(device.device, buffer,
nullptr);
66 vkFreeMemory(device.device, memory,
nullptr);
68 "Buffer [" + std::to_string((uint64_t)buffer)
69 +
"] destroyed on device ["
70 + std::to_string((uint64_t)device.device) +
"]")
77 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
78 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
80 vkMapMemory(device.
device, memory, 0, size, 0, &data);
84 float y,
float rotation,
float x_size,
float y_size)
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,
99 memcpy(data, &ubo,
sizeof(ubo));
101 "Uniform buffer object updated for buffer ["
102 + std::to_string((uint64_t)buffer) +
"]")
109 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
110 | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
112 vkMapMemory(device.
device, memory, 0, size, 0, &data);
114 "Color buffer object created for buffer ["
115 + std::to_string((uint64_t)buffer) +
"]")
123 memcpy(data, &ubo,
sizeof(ubo));
125 "Color buffer object updated for buffer ["
126 + std::to_string((uint64_t)buffer) +
"]")
Contains the Buffer and UniformBuffer class.
VkBuffer buffer
The buffer.
VkDeviceSize size
The size of the buffer.
void destroy()
Destroys the buffer and frees the memory.
void copy(void *data, VkCommandPool commandPool)
Copies the data to the buffer.
void create(Chronos::Engine::Device device, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties)
This is used to initialize the buffer.
VkDeviceMemory memory
The device memory of the buffer.
Chronos::Engine::Device device
The device on which the buffer is stored.
void update(glm::vec3 color)
Updates the buffer with the new color.
void create(Chronos::Engine::Device device)
Creates the buffer and maps the memory.
This initializes, manages and destroys the logical and physical devices(GPU).
VkDevice device
This is the logical device that is used by Vulkan.
Contains ShapeParams and UniformBufferObject structs.
Contains various common functions used by other classes in the Engine namespace.
#define LOG(LEVEL, MESSAGE)
void createBuffer(Chronos::Engine::Device device, VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, VkBuffer *buffer, VkDeviceMemory *bufferMemory)
Creates a buffer of a given size, usage and properties.
void copyBuffer(Chronos::Engine::Device device, VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size, VkCommandPool commandPool)
Copies data from one buffer to another.