Hymn to Beauty
C++ 3D Engine
RenderPassAllocator.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "RenderPass.hpp"
4#include <map>
5
6namespace Video {
7
8class Texture;
9
12 public:
15
17 virtual ~RenderPassAllocator();
18
20
26 RenderPass* CreateRenderPass(Texture* colorAttachment, RenderPass::LoadOperation colorLoadOperation, Texture* depthAttachment, RenderPass::LoadOperation depthLoadOperation);
27
29
33 RenderPass* CreateAttachmentlessRenderPass(const glm::uvec2& size, uint32_t msaaSamples);
34
36
39 void FreePasses(const Texture* attachment);
40
41 private:
42 struct RenderPassInfo {
43 uint64_t colorAttachment;
44 RenderPass::LoadOperation colorLoadOperation;
45 uint64_t depthAttachment;
46 RenderPass::LoadOperation depthLoadOperation;
47 };
48
49 struct RenderPassInfoCompare {
50 bool operator()(const RenderPassInfo& a, const RenderPassInfo& b) const {
51 if (a.colorAttachment != b.colorAttachment) {
52 return a.colorAttachment < b.colorAttachment;
53 }
54
55 if (a.colorLoadOperation != b.colorLoadOperation) {
56 return a.colorLoadOperation < b.colorLoadOperation;
57 }
58
59 if (a.depthAttachment != b.depthAttachment) {
60 return a.depthAttachment < b.depthAttachment;
61 }
62
63 return a.depthLoadOperation < b.depthLoadOperation;
64 }
65 };
66
67 std::map<RenderPassInfo, RenderPass*, RenderPassInfoCompare> renderPasses;
68
69 struct AttachmentlessRenderPassInfo {
70 glm::uvec2 size;
71 uint32_t msaaSamples;
72 };
73
74 struct AttachmentlessRenderPassInfoCompare {
75 bool operator()(const AttachmentlessRenderPassInfo& a, const AttachmentlessRenderPassInfo& b) const {
76 if (a.size.x != b.size.x) {
77 return a.size.x < b.size.x;
78 }
79
80 if (a.size.y != b.size.y) {
81 return a.size.y < b.size.y;
82 }
83
84 return a.msaaSamples < b.msaaSamples;
85 }
86 };
87
88 std::map<AttachmentlessRenderPassInfo, RenderPass*, AttachmentlessRenderPassInfoCompare> attachmentlessRenderPasses;
89
90 virtual RenderPass* AllocateRenderPass(Texture* colorAttachment, RenderPass::LoadOperation colorLoadOperation, Texture* depthAttachment, RenderPass::LoadOperation depthLoadOperation) = 0;
91 virtual RenderPass* AllocateAttachmentlessRenderPass(const glm::uvec2& size, uint32_t msaaSamples) = 0;
92};
93
94}
Responsible for allocating render passes and framebuffers.
Definition: RenderPassAllocator.hpp:11
RenderPass * CreateAttachmentlessRenderPass(const glm::uvec2 &size, uint32_t msaaSamples)
Create an attachmentless render pass.
Definition: RenderPassAllocator.cpp:43
void FreePasses(const Texture *attachment)
Free all render passes that contain the given attachment.
Definition: RenderPassAllocator.cpp:60
RenderPassAllocator()
Create a new render pass allocator.
Definition: RenderPassAllocator.cpp:8
RenderPass * CreateRenderPass(Texture *colorAttachment, RenderPass::LoadOperation colorLoadOperation, Texture *depthAttachment, RenderPass::LoadOperation depthLoadOperation)
Create a render pass.
Definition: RenderPassAllocator.cpp:22
virtual ~RenderPassAllocator()
Destructor.
Definition: RenderPassAllocator.cpp:12
A render pass.
Definition: RenderPass.hpp:11
LoadOperation
What to do with an image being rendered to before rendering to it.
Definition: RenderPass.hpp:14
A texture.
Definition: Texture.hpp:8
Definition: Editor.hpp:18