Line data Source code
1 : /* Copyright (C) 2025 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 "graphics/Color.h" 22 : #include "ps/containers/StaticVector.h" 23 : #include "renderer/backend/IFramebuffer.h" 24 : #include "renderer/backend/vulkan/DeviceObjectUID.h" 25 : 26 : #include <cstdint> 27 : #include <glad/vulkan.h> 28 : #include <memory> 29 : 30 : namespace Renderer::Backend::Vulkan { class CDevice; } 31 : namespace Renderer::Backend::Vulkan { class CTexture; } 32 : 33 : namespace Renderer 34 : { 35 : 36 : namespace Backend 37 : { 38 : 39 : namespace Vulkan 40 : { 41 : 42 : class CFramebuffer final : public IFramebuffer 43 : { 44 : public: 45 : ~CFramebuffer() override; 46 : 47 : IDevice* GetDevice() override; 48 : 49 0 : const CColor& GetClearColor() const override { return m_ClearColor; } 50 : 51 0 : uint32_t GetWidth() const override { return m_Width; } 52 0 : uint32_t GetHeight() const override { return m_Height; } 53 0 : uint32_t GetSampleCount() const { return m_SampleCount; } 54 : 55 0 : VkRenderPass GetRenderPass() const { return m_RenderPass; } 56 0 : VkFramebuffer GetFramebuffer() const { return m_Framebuffer; } 57 : 58 : using ColorAttachments = PS::StaticVector<CTexture*, 4>; 59 0 : const ColorAttachments& GetColorAttachments() { return m_ColorAttachments; } 60 0 : CTexture* GetDepthStencilAttachment() { return m_DepthStencilAttachment; } 61 : 62 0 : AttachmentLoadOp GetColorAttachmentLoadOp() const { return m_ColorAttachmentLoadOp; } 63 : AttachmentStoreOp GetColorAttachmentStoreOp() const { return m_ColorAttachmentStoreOp; } 64 0 : AttachmentLoadOp GetDepthStencilAttachmentLoadOp() const { return m_DepthStencilAttachmentLoadOp; } 65 : AttachmentStoreOp GetDepthStencilAttachmentStoreOp() const { return m_DepthStencilAttachmentStoreOp; } 66 : 67 0 : DeviceObjectUID GetUID() const { return m_UID; } 68 : 69 : private: 70 : friend class CDevice; 71 : friend class CSwapChain; 72 : 73 : static std::unique_ptr<CFramebuffer> Create( 74 : CDevice* device, const char* name, 75 : SColorAttachment* colorAttachment, SDepthStencilAttachment* depthStencilAttachment); 76 : 77 0 : CFramebuffer() = default; 78 : 79 : CDevice* m_Device = nullptr; 80 : 81 : DeviceObjectUID m_UID{INVALID_DEVICE_OBJECT_UID}; 82 : 83 : CColor m_ClearColor{}; 84 : 85 : uint32_t m_Width = 0; 86 : uint32_t m_Height = 0; 87 : uint32_t m_SampleCount = 0; 88 : 89 : AttachmentLoadOp m_ColorAttachmentLoadOp = AttachmentLoadOp::DONT_CARE; 90 : AttachmentStoreOp m_ColorAttachmentStoreOp = AttachmentStoreOp::DONT_CARE; 91 : AttachmentLoadOp m_DepthStencilAttachmentLoadOp = AttachmentLoadOp::DONT_CARE; 92 : AttachmentStoreOp m_DepthStencilAttachmentStoreOp = AttachmentStoreOp::DONT_CARE; 93 : 94 : VkRenderPass m_RenderPass = VK_NULL_HANDLE; 95 : VkFramebuffer m_Framebuffer = VK_NULL_HANDLE; 96 : 97 : // It's reponsibility of CFramebuffer owner to guarantee lifetime of 98 : // attachments. 99 : ColorAttachments m_ColorAttachments; 100 : CTexture* m_DepthStencilAttachment = nullptr; 101 : }; 102 : 103 : } // namespace Vulkan 104 : 105 : } // namespace Backend 106 : 107 : } // namespace Renderer 108 : 109 : #endif // INCLUDED_RENDERER_BACKEND_VULKAN_FRAMEBUFFER