vOOlkan
An object oriented approach to Vulkan
VertexBuffer.h
Go to the documentation of this file.
1#ifndef VULKAN_VERTEXBUFFER
2#define VULKAN_VERTEXBUFFER
3
4#include <vulkan/vulkan.h>
5
6#include "LogicalDevice.h"
7#include "PhysicalDevice.h"
8#include "VulkanException.h"
9#include "VertexInput.h"
10#include "Buffer.h"
11#include "Model.h"
12
13
14namespace Vulkan::Buffers { class VertexBuffer; }
15
17public:
18
19 VertexBuffer(const LogicalDevice& virtualGpu, const PhysicalDevice& realGpu, size_t size) : Buffer(virtualGpu, realGpu, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
20
21 }
22
23
24 template<typename... C, typename... S, template<typename, typename...> class... M> requires (std::same_as<M<PipelineOptions::Vertex<C...>, S...>, Objects::Model<PipelineOptions::Vertex<C...>, S...>> && ...)
25 void fillBuffer(const M<PipelineOptions::Vertex<C...>, S...>&... models) {
26 std::vector<PipelineOptions::Vertex<C...>> data{};
27 (data.insert(data.end(), models.getVertices().begin(), models.getVertices().end()), ...); //copy all the vertices to one vector
28
29 verticesCount = data.size();
30
31 //TODO staging buffer
32
33 //copy data to vertex buffer
34 void* rawData;
35 vkMapMemory(+virtualGpu, bufferMemory, 0, data.size() * sizeof(data[0]), 0, &rawData);
36 memcpy(rawData, data.data(), data.size() * sizeof(data[0]));
37 vkUnmapMemory(+virtualGpu, bufferMemory);
38 }
39
40
41 unsigned int getVerticesCount() const {
42 return verticesCount;
43 }
44
45
46private:
47
48 unsigned int verticesCount;
49};
50
51#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
Definition: VertexBuffer.h:16
unsigned int getVerticesCount() const
Definition: VertexBuffer.h:41
void fillBuffer(const M< PipelineOptions::Vertex< C... >, S... > &... models)
Definition: VertexBuffer.h:25
VertexBuffer(const LogicalDevice &virtualGpu, const PhysicalDevice &realGpu, size_t size)
Definition: VertexBuffer.h:19
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Definition: Model.h:27
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