Line data Source code
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 :
21 : #include "ps/containers/StaticVector.h"
22 : #include "renderer/backend/IFramebuffer.h"
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 0 : const CColor& GetClearColor() const override { return m_ClearColor; }
47 :
48 0 : uint32_t GetWidth() const override { return m_Width; }
49 0 : uint32_t GetHeight() const override { return m_Height; }
50 0 : uint32_t GetSampleCount() const { return m_SampleCount; }
51 :
52 0 : VkRenderPass GetRenderPass() const { return m_RenderPass; }
53 0 : VkFramebuffer GetFramebuffer() const { return m_Framebuffer; }
54 :
55 : using ColorAttachments = PS::StaticVector<CTexture*, 4>;
56 0 : const ColorAttachments& GetColorAttachments() { return m_ColorAttachments; }
57 0 : CTexture* GetDepthStencilAttachment() { return m_DepthStencilAttachment; }
58 :
59 0 : AttachmentLoadOp GetColorAttachmentLoadOp() const { return m_ColorAttachmentLoadOp; }
60 : AttachmentStoreOp GetColorAttachmentStoreOp() const { return m_ColorAttachmentStoreOp; }
61 0 : AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; }
62 : AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; }
63 :
64 : using UID = uint32_t;
65 0 : 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 :
75 0 : CFramebuffer()
76 0 : {
77 : static uint32_t m_LastAvailableUID = 1;
78 0 : m_UID = m_LastAvailableUID++;
79 0 : }
80 :
81 : CDevice* m_Device = nullptr;
82 :
83 : UID m_UID = 0;
84 :
85 : CColor m_ClearColor{};
86 :
87 : uint32_t m_Width = 0;
88 : uint32_t m_Height = 0;
89 : uint32_t m_SampleCount = 0;
90 :
91 : AttachmentLoadOp m_ColorAttachmentLoadOp = AttachmentLoadOp::DONT_CARE;
92 : AttachmentStoreOp m_ColorAttachmentStoreOp = AttachmentStoreOp::DONT_CARE;
93 : AttachmentLoadOp m_DepthStencilAttachmentLoadOp = AttachmentLoadOp::DONT_CARE;
94 : AttachmentStoreOp m_DepthStencilAttachmentStoreOp = AttachmentStoreOp::DONT_CARE;
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.
101 : ColorAttachments m_ColorAttachments;
102 : CTexture* m_DepthStencilAttachment = nullptr;
103 : };
104 :
105 : } // namespace Vulkan
106 :
107 : } // namespace Backend
108 :
109 : } // namespace Renderer
110 :
111 : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_FRAMEBUFFER
|