Pyrogenesis  trunk
Buffer.h
Go to the documentation of this file.
1 /* Copyright (C) 2023 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER
19 #define INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER
20 
23 
24 #include <glad/vulkan.h>
25 #include <memory>
26 
27 namespace Renderer
28 {
29 
30 namespace Backend
31 {
32 
33 namespace Vulkan
34 {
35 
36 class CDevice;
37 
38 class CBuffer final : public IBuffer
39 {
40 public:
41  ~CBuffer() override;
42 
43  IDevice* GetDevice() override;
44 
45  Type GetType() const override { return m_Type; }
46  uint32_t GetSize() const override { return m_Size; }
47  bool IsDynamic() const override { return m_Dynamic; }
48 
49  VkBuffer GetVkBuffer() { return m_Buffer; }
50 
51  /**
52  * @return mapped data for UPLOAD buffers else returns nullptr.
53  */
55 
56 private:
57  friend class CDevice;
58 
59  static std::unique_ptr<CBuffer> Create(
60  CDevice* device, const char* name, const Type type, const uint32_t size,
61  const bool dynamic);
62 
63  CBuffer();
64 
65  CDevice* m_Device = nullptr;
66 
69  bool m_Dynamic = false;
70 
71  VkBuffer m_Buffer = VK_NULL_HANDLE;
72  VmaAllocation m_Allocation = VK_NULL_HANDLE;
74 };
75 
76 } // namespace Vulkan
77 
78 } // namespace Backend
79 
80 } // namespace Renderer
81 
82 #endif // INCLUDED_RENDERER_BACKEND_VULKAN_BUFFER
Definition: IBuffer.h:31
~CBuffer() override
Definition: Buffer.cpp:101
VmaAllocation m_Allocation
Definition: Buffer.h:72
Type
Definition: IBuffer.h:34
VmaAllocationInfo m_AllocationInfo
Definition: Buffer.h:73
Definition: Buffer.h:38
void * GetMappedData()
Definition: Buffer.h:54
IDevice * GetDevice() override
Definition: Buffer.cpp:108
VkBuffer GetVkBuffer()
Definition: Buffer.h:49
Definition: Device.h:59
Definition: IDevice.h:47
Type GetType() const override
Definition: Buffer.h:45
bool IsDynamic() const override
Definition: Buffer.h:47
Represents single memory allocation.
CDevice * m_Device
Definition: Buffer.h:65
Parameters of VmaAllocation objects, that can be retrieved using function vmaGetAllocationInfo().
Definition: vk_mem_alloc.h:1336
uint32_t m_Size
Definition: Buffer.h:68
Backend
Definition: Backend.h:27
void *VMA_NULLABLE pMappedData
Pointer to the beginning of this allocation as mapped data.
Definition: vk_mem_alloc.h:1379
bool m_Dynamic
Definition: Buffer.h:69
Type m_Type
Definition: Buffer.h:67
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
VkBuffer m_Buffer
Definition: Buffer.h:71
static std::unique_ptr< CBuffer > Create(CDevice *device, const char *name, const Type type, const uint32_t size, const bool dynamic)
Definition: Buffer.cpp:34
uint32_t GetSize() const override
Definition: Buffer.h:46