Pyrogenesis  trunk
Framebuffer.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_FRAMEBUFFER
19 #define INCLUDED_RENDERER_BACKEND_VULKAN_FRAMEBUFFER
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 class CTexture;
38 
39 class CFramebuffer final : public IFramebuffer
40 {
41 public:
42  ~CFramebuffer() override;
43 
44  IDevice* GetDevice() override;
45 
46  const CColor& GetClearColor() const override { return m_ClearColor; }
47 
48  uint32_t GetWidth() const override { return m_Width; }
49  uint32_t GetHeight() const override { return m_Height; }
51 
52  VkRenderPass GetRenderPass() const { return m_RenderPass; }
53  VkFramebuffer GetFramebuffer() const { return m_Framebuffer; }
54 
58 
63 
64  using UID = uint32_t;
65  UID GetUID() const { return m_UID; }
66 
67 private:
68  friend class CDevice;
69  friend class CSwapChain;
70 
71  static std::unique_ptr<CFramebuffer> Create(
72  CDevice* device, const char* name,
73  SColorAttachment* colorAttachment, SDepthStencilAttachment* depthStencilAttachment);
74 
76  {
77  static uint32_t m_LastAvailableUID = 1;
78  m_UID = m_LastAvailableUID++;
79  }
80 
81  CDevice* m_Device = nullptr;
82 
83  UID m_UID = 0;
84 
86 
90 
95 
96  VkRenderPass m_RenderPass = VK_NULL_HANDLE;
97  VkFramebuffer m_Framebuffer = VK_NULL_HANDLE;
98 
99  // It's reponsibility of CFramebuffer owner to guarantee lifetime of
100  // attachments.
103 };
104 
105 } // namespace Vulkan
106 
107 } // namespace Backend
108 
109 } // namespace Renderer
110 
111 #endif // INCLUDED_RENDERER_BACKEND_VULKAN_FRAMEBUFFER
AttachmentLoadOp
Load operation is set for each attachment, what should be done with its content on BeginFramebufferPa...
Definition: IFramebuffer.h:36
AttachmentStoreOp GetColorAttachmentStoreOp() const
Definition: Framebuffer.h:60
const CColor & GetClearColor() const override
Returns a clear color for all color attachments of the framebuffer.
Definition: Framebuffer.h:46
uint32_t m_Height
Definition: Framebuffer.h:88
VkFramebuffer m_Framebuffer
Definition: Framebuffer.h:97
AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const
Definition: Framebuffer.h:62
AttachmentStoreOp
Store operation is set for each attachment, what should be done with its content on EndFramebufferPas...
Definition: IFramebuffer.h:51
Definition: Color.h:42
AttachmentLoadOp m_ColorAttachmentLoadOp
Definition: Framebuffer.h:91
AttachmentLoadOp m_DepthStencilAttachmentLoadOp
Definition: Framebuffer.h:93
AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const
Definition: Framebuffer.h:61
Definition: Texture.h:39
VkRenderPass m_RenderPass
Definition: Framebuffer.h:96
uint32_t GetSampleCount() const
Definition: Framebuffer.h:50
Definition: SwapChain.h:43
static std::unique_ptr< CFramebuffer > Create(CDevice *device, const char *name, SColorAttachment *colorAttachment, SDepthStencilAttachment *depthStencilAttachment)
Definition: Framebuffer.cpp:38
Definition: Device.h:59
AttachmentLoadOp GetColorAttachmentLoadOp() const
Definition: Framebuffer.h:59
CDevice * m_Device
Definition: Framebuffer.h:81
Definition: Framebuffer.h:39
UID GetUID() const
Definition: Framebuffer.h:65
uint32_t GetWidth() const override
Definition: Framebuffer.h:48
VkFramebuffer GetFramebuffer() const
Definition: Framebuffer.h:53
Definition: IDevice.h:47
Represents a texture object.
Definition: TextureManager.h:256
AttachmentStoreOp m_ColorAttachmentStoreOp
Definition: Framebuffer.h:92
uint32_t GetHeight() const override
Definition: Framebuffer.h:49
CTexture * GetDepthStencilAttachment()
Definition: Framebuffer.h:57
Definition: IFramebuffer.h:67
Backend
Definition: Backend.h:27
CFramebuffer()
Definition: Framebuffer.h:75
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
AttachmentStoreOp m_DepthStencilAttachmentStoreOp
Definition: Framebuffer.h:94
uint32_t UID
Definition: Framebuffer.h:64
CColor m_ClearColor
Definition: Framebuffer.h:85
~CFramebuffer() override
Definition: Framebuffer.cpp:113
ColorAttachments m_ColorAttachments
Definition: Framebuffer.h:101
VkRenderPass GetRenderPass() const
Definition: Framebuffer.h:52
uint32_t m_SampleCount
Definition: Framebuffer.h:89
IDevice * GetDevice() override
Definition: Framebuffer.cpp:120
Definition: IFramebuffer.h:59
const ColorAttachments & GetColorAttachments()
Definition: Framebuffer.h:56
IFramebuffer stores attachments which should be used by backend as rendering destinations.
Definition: IFramebuffer.h:84
CTexture * m_DepthStencilAttachment
Definition: Framebuffer.h:102
UID m_UID
Definition: Framebuffer.h:83
uint32_t m_Width
Definition: Framebuffer.h:87