Karma Engine
Loading...
Searching...
No Matches
VulkanBuffer.h
1#pragma once
2
3#include "Karma/Renderer/Buffer.h"
4#include "vulkan/vulkan.h"
5
6namespace Karma
7{
8 class KARMA_API VulkanVertexBuffer : public VertexBuffer
9 {
10 public:
11 VulkanVertexBuffer(float* vertices, uint32_t size);
12 virtual ~VulkanVertexBuffer();
13
14 virtual void Bind() const override;
15 virtual void UnBind() const override;
16
17 virtual const BufferLayout& GetLayout() const override
18 {
19 return m_Layout;
20 }
21 virtual void SetLayout(const BufferLayout& layout) override
22 {
23 m_Layout = layout;
24 }
25
26 void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
27 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
28 void CopyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
29
30 uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
31
32 inline VkBuffer GetVertexBuffer() const { return m_VertexBuffer; }
33 inline VkDeviceMemory GetVertexBufferMemory() const { return m_VertexBufferMemory; }
34
35 inline size_t GetBufferSize() { return m_BufferSize; }
36
37 private:
38 VkDevice m_Device;
39 BufferLayout m_Layout;
40
41 VkBuffer m_VertexBuffer;
42 VkDeviceMemory m_VertexBufferMemory;
43
44 size_t m_BufferSize;
45 };
46
47 class KARMA_API VulkanIndexBuffer : public IndexBuffer
48 {
49 public:
50 VulkanIndexBuffer(uint32_t* indices, uint32_t count);
51 virtual ~VulkanIndexBuffer();
52
53 virtual void Bind() const override;
54 virtual void UnBind() const override;
55
56 void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
57 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
58 void CopyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
59
60 uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
61
62 virtual uint32_t GetCount() const override { return m_Count; }
63 inline VkBuffer GetIndexBuffer() const { return m_IndexBuffer; }
64 inline VkDeviceMemory GetIndexBufferMemory() const { return m_IndexBufferMemory; }
65
66 inline size_t GetBufferSize() { return m_BufferSize; }
67
68 private:
69 VkDevice m_Device;
70 uint32_t m_Count;
71
72 VkBuffer m_IndexBuffer;
73 VkDeviceMemory m_IndexBufferMemory;
74
75 size_t m_BufferSize;
76 };
77
78 struct KARMA_API VulkanUniformBuffer : public UniformBufferObject
79 {
80 public:
81 VulkanUniformBuffer(std::vector<ShaderDataType> dataTypes, uint32_t bindingPointIndex);
82 virtual ~VulkanUniformBuffer();
83
84 void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
85 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
86 uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
87 const std::vector<VkBuffer>& GetUniformBuffers() const { return m_UniformBuffers; }
88
89 void ClearBuffer();
90 void BufferCreation();
91
92 void UploadUniformBuffer(size_t frameIndex);
93
94 private:
95 VkDevice m_Device;
96 std::vector<VkBuffer> m_UniformBuffers;
97 std::vector<VkDeviceMemory> m_UniformBuffersMemory;
98 };
99
100 class KARMA_API VulkanImageBuffer : public ImageBuffer
101 {
102 public:
103 VulkanImageBuffer(const char* filename);
104 virtual ~VulkanImageBuffer();
105 void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties,
106 VkBuffer& buffer, VkDeviceMemory& bufferMemory);
107 uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
108 const inline VkBuffer& GetBuffer() const { return m_StagingBuffer; }
109
110 // Getters
111 int GetTextureWidth() const { return texWidth; }
112 int GetTextureHeight() const { return texHeight; }
113 int GetTextureChannels() const { return texChannels; }
114
115 private:
116 VkDevice m_Device;
117 VkBuffer m_StagingBuffer;
118 VkDeviceMemory m_StagingBufferMemory;
119
120 // Image props (properties)
121 int texWidth;
122 int texHeight;
123 int texChannels;
124 };
125}
Definition Buffer.h:111
Definition Buffer.h:194
Definition Buffer.h:181
Definition Buffer.h:167
Definition VulkanBuffer.h:101
Definition VulkanBuffer.h:48
Definition VulkanBuffer.h:9
Definition Buffer.h:220
Definition VulkanBuffer.h:79