| Fling Engine 0.00.1 Fling Engine is a game engine written in Vulkan

Buffer.h
Go to the documentation of this file.
1 #pragma once
2
3 #include "FlingVulkan.h"
4 #include "FlingExports.h"
5
6 namespace Fling
7 {
11 class FLING_API Buffer
12 {
13 public:
14
18 Buffer()
19 : m_Size(0)
20 , m_Buffer(VK_NULL_HANDLE)
21 , m_BufferMemory(VK_NULL_HANDLE)
22 , m_Descriptor{}
23 , m_MappedMem(nullptr)
24 {
25 }
26
28 Buffer(const Buffer& t_Other);
29
38 Buffer(
39 const VkDeviceSize& t_Size,
40 const VkBufferUsageFlags& t_Usage,
41 const VkMemoryPropertyFlags& t_Properties,
42 const void* t_Data = nullptr
43 );
44
48 ~Buffer();
49
50 bool operator==(const Buffer& other) const;
51 bool operator!=(const Buffer& other) const;
52
53 FORCEINLINE const VkBuffer& GetVkBuffer() const { return m_Buffer; }
54
55 FORCEINLINE const VkDeviceMemory& GetVkDeviceMemory() const { return m_BufferMemory; }
56
57 FORCEINLINE const VkDeviceSize& GetSize() const { return m_Size; }
58
59 FORCEINLINE VkDescriptorBufferInfo& GetDescriptor() { return m_Descriptor; }
60
68 static void CopyBuffer(Buffer* t_SrcBuffer, Buffer* t_DstBuffer, VkDeviceSize t_Size);
69
74 void Release();
75
81 bool IsUsed() const { return m_BufferMemory != VK_NULL_HANDLE && m_Buffer != VK_NULL_HANDLE && m_Size; }
82
88 VkResult MapMemory(VkDeviceSize t_Size = VK_WHOLE_SIZE, VkDeviceSize t_Offset = 0);
89
93 void UnmapMemory();
94
104 void CreateBuffer(
105 const VkDeviceSize& t_size,
106 const VkBufferUsageFlags& t_Usage,
107 const VkMemoryPropertyFlags& t_Properties,
108 bool t_unmapBuffer,
109 const void* t_Data = nullptr);
110
117 void Flush(VkDeviceSize t_size, VkDeviceSize t_offset);
118
119 void* m_MappedMem = nullptr;
120
121 private:
122
124 VkDeviceSize m_Size;
125
127 VkBuffer m_Buffer;
128
130 VkDeviceMemory m_BufferMemory;
131
133 VkDescriptorBufferInfo m_Descriptor;
134
136 VkDeviceSize m_Offset = 0;
137 };
138 } // namespace Fling
Fling::Buffer::GetSize
FORCEINLINE const VkDeviceSize & GetSize() const
Definition: Buffer.h:57
Fling::Buffer::m_Descriptor
VkDescriptorBufferInfo m_Descriptor
The descriptor stores info about the offset, buffer, and; size of this.
Definition: Buffer.h:133
FlingVulkan.h
Fling::Buffer::m_BufferMemory
VkDeviceMemory m_BufferMemory
Pointer to the physical device memory for this buffer.
Definition: Buffer.h:130
Fling::GraphicsHelpers::CreateBuffer
void CreateBuffer(VkDevice t_Device, VkPhysicalDevice t_PhysicalDevice, VkDeviceSize t_Size, VkBufferUsageFlags t_Usage, VkMemoryPropertyFlags t_Properties, VkBuffer &t_Buffer, VkDeviceMemory &t_BuffMemory)
Definition: GraphicsHelpers.cpp:30
Fling::Buffer::GetVkDeviceMemory
FORCEINLINE const VkDeviceMemory & GetVkDeviceMemory() const
Definition: Buffer.h:55
Fling::Buffer::m_Size
VkDeviceSize m_Size
The size of this buffer in bytes.
Definition: Buffer.h:124
Fling::Buffer::GetDescriptor
FORCEINLINE VkDescriptorBufferInfo & GetDescriptor()
Definition: Buffer.h:59
FlingExports.h
Fling::Buffer::IsUsed
bool IsUsed() const
Check if this buffer&#39;s Vulkan assets are used.
Definition: Buffer.h:81
Fling::Buffer::m_Buffer
VkBuffer m_Buffer
Vulkan logical buffer object.
Definition: Buffer.h:127
Fling::Buffer
A Buffer represents a Vulkan buffer with a size, buffer pointer, and buffer memory.
Definition: Buffer.h:11
Fling::Buffer::GetVkBuffer
FORCEINLINE const VkBuffer & GetVkBuffer() const
Definition: Buffer.h:53
Fling
Definition: Engine.h:29
Fling::Buffer::Buffer
Buffer()
Default Ctor for a buffer.
Definition: Buffer.h:18