Hymn to Beauty
C++ 3D Engine
RenderTargetAllocator.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "Texture.hpp"
4#include <glm/glm.hpp>
5#include <map>
6#include <deque>
7
8namespace Video {
9
10class RenderPassAllocator;
11
14 public:
16
20 RenderTargetAllocator(uint8_t frames, RenderPassAllocator* renderPassAllocator);
21
23 virtual ~RenderTargetAllocator();
24
26 virtual void BeginFrame();
27
29
33 Texture* CreateRenderTarget(const glm::uvec2& size, Texture::Format format);
34
36
39 void FreeRenderTarget(Texture* renderTarget);
40
41 private:
42 struct RenderTargetInfo {
43 glm::uvec2 size;
44 Texture::Format format;
45 };
46
47 struct RenderTargetInfoCompare {
48 bool operator()(const RenderTargetInfo& a, const RenderTargetInfo& b) const {
49 if (a.size.x != b.size.x) {
50 return a.size.x < b.size.x;
51 }
52
53 if (a.size.y != b.size.y) {
54 return a.size.y < b.size.y;
55 }
56
57 return a.format < b.format;
58 }
59 };
60
61 struct RenderTarget {
62 Texture* texture;
63 uint8_t age;
64 };
65
66 std::map<RenderTargetInfo, std::deque<RenderTarget>, RenderTargetInfoCompare> freeRenderTargets;
67 uint8_t frames;
68 RenderPassAllocator* renderPassAllocator;
69
70 virtual Texture* AllocateRenderTarget(const glm::uvec2& size, Texture::Format format) = 0;
71 virtual void FreeRenderPasses(Texture* renderTarget);
72};
73
74}
Responsible for allocating render passes and framebuffers.
Definition: RenderPassAllocator.hpp:11
Responsible for allocating render targets.
Definition: RenderTargetAllocator.hpp:13
void FreeRenderTarget(Texture *renderTarget)
Free a render target.
Definition: RenderTargetAllocator.cpp:60
RenderTargetAllocator(uint8_t frames, RenderPassAllocator *renderPassAllocator)
Create a new render target allocator.
Definition: RenderTargetAllocator.cpp:10
Texture * CreateRenderTarget(const glm::uvec2 &size, Texture::Format format)
Create a render target.
Definition: RenderTargetAllocator.cpp:40
virtual ~RenderTargetAllocator()
Destructor.
Definition: RenderTargetAllocator.cpp:15
virtual void BeginFrame()
Call at the beginning of each frame.
Definition: RenderTargetAllocator.cpp:24
A texture.
Definition: Texture.hpp:8
Format
The format of the texture.
Definition: Texture.hpp:18
Definition: Editor.hpp:18