vOOlkan
An object oriented approach to Vulkan
UniformBuffer.h
Go to the documentation of this file.
1#ifndef VULKAN_UNIFORMBUFFER
2#define VULKAN_UNIFORMBUFFER
3
4#include <vulkan/vulkan.h>
5#include <concepts>
6
7#include "LogicalDevice.h"
8#include "PhysicalDevice.h"
9#include "Buffer.h"
10
11
12namespace Vulkan::Buffers { class UniformBuffer; }
13
14
19public:
20 UniformBuffer(const LogicalDevice& virtualGpu, const PhysicalDevice& realGpu, size_t size) : Buffer(virtualGpu, realGpu, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {}
21
22
23
31 template<typename D>
32 void fillBuffer(const D& data, int offset = 0) {
33 void* rawData;
34 vkMapMemory(+virtualGpu, bufferMemory, offset, sizeof(D), 0, &rawData);
35 memcpy(rawData, &data, sizeof(D));
36 vkUnmapMemory(+virtualGpu, bufferMemory);
37 }
38
39};
40
41#endif
Definition: Buffer.h:14
const size_t size
Definition: Buffer.h:112
const LogicalDevice & virtualGpu
Definition: Buffer.h:111
VkDeviceMemory bufferMemory
Definition: Buffer.h:110
This buffer is used to store the uniform data (such as matrices) to be used by the shaders in the GPU...
Definition: UniformBuffer.h:18
void fillBuffer(const D &data, int offset=0)
Fills the buffer with the specified data.
Definition: UniformBuffer.h:32
UniformBuffer(const LogicalDevice &virtualGpu, const PhysicalDevice &realGpu, size_t size)
Definition: UniformBuffer.h:20
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Represents the GPU (or any other device) that will be used with Vulkan to perform computer graphics.
Definition: PhysicalDevice.h:17
Definition: Buffer.h:12