Conquer Space 0.0.0
A space themed grand strategy game set in the near future, with realistic orbital mechanics, and an emphasis on economics and politics.
framebuffer.h
Go to the documentation of this file.
1/* Conquer Space
2 * Copyright (C) 2021-2023 Conquer Space
3 *
4 * This program 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 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <memory>
20#include <utility>
21#include <vector>
22
24#include "engine/window.h"
25
26namespace cqsp {
27namespace engine {
32 public:
33 virtual ~IFramebuffer() {}
34
35 virtual void InitTexture(int width = 1280, int height = 720) = 0;
36 virtual void Clear() = 0;
37 virtual void BeginDraw() = 0;
38 virtual void EndDraw() = 0;
39 virtual void RenderBuffer() = 0;
40 virtual void Free() = 0;
41 virtual void NewFrame(const Window& window) = 0;
42
44 virtual void SetMesh(cqsp::engine::Mesh_t) = 0;
45 virtual void SetShader(cqsp::asset::ShaderProgram_t shader) = 0;
46};
47
49 public:
52
53 void InitTexture(int width, int height) override;
54 void Clear() override;
55 void BeginDraw() override;
56 void EndDraw() override;
57 void RenderBuffer() override;
58 void Free() override;
59 void NewFrame(const Window& window) override;
60 void SetMesh(cqsp::engine::Mesh_t mesh) override { mesh_output = mesh; }
62 void SetShader(cqsp::asset::ShaderProgram_t shader) override { buffer_shader = shader; }
63 void FreeBuffer();
64
65 private:
66 unsigned int framebuffer;
67 unsigned int colorbuffer;
70};
71
73 public:
76
77 void InitTexture(int width, int height) override;
78 void Clear() override;
79 void BeginDraw() override;
80 void EndDraw() override;
81 void Free() override;
82 void RenderBuffer() override;
83 void NewFrame(const Window& window) override;
84 void FreeBuffer();
85
87 void SetMesh(cqsp::engine::Mesh_t mesh) override { mesh_output = mesh; }
88 void SetShader(cqsp::asset::ShaderProgram_t shader) override { buffer_shader = shader; }
89
90 private:
91 int width;
92 int height;
93
94 unsigned int framebuffer;
95 unsigned int intermediateFBO;
96 unsigned int screenTexture;
97 unsigned int mscat;
100};
101
134 public:
135 template <class T>
136 int AddLayer(asset::ShaderProgram_t shader, const engine::Window& window) {
137 std::unique_ptr<T> fb = std::make_unique<T>();
138 InitFramebuffer(fb.get(), shader, window);
139 framebuffers.push_back(std::move(fb));
140 return framebuffers.size() - 1;
141 }
142
143 void BeginDraw(int layer);
144 void EndDraw(int layer);
145 void DrawAllLayers();
146 void NewFrame(const cqsp::engine::Window& window);
147 int GetLayerCount();
148
149 IFramebuffer* GetFrameBuffer(int layer) { return framebuffers[layer].get(); }
150
151 private:
152 std::vector<std::unique_ptr<IFramebuffer>> framebuffers;
154};
155} // namespace engine
156} // namespace cqsp
Definition: framebuffer.h:72
unsigned int screenTexture
Definition: framebuffer.h:96
cqsp::engine::Mesh & GetMeshOutput() override
Definition: framebuffer.h:86
AAFrameBufferRenderer()
Definition: framebuffer.h:74
void BeginDraw() override
Definition: framebuffer.cpp:161
void FreeBuffer()
Definition: framebuffer.cpp:167
void Clear() override
Definition: framebuffer.cpp:154
void EndDraw() override
Definition: framebuffer.cpp:163
void SetMesh(cqsp::engine::Mesh_t mesh) override
Definition: framebuffer.h:87
void InitTexture(int width, int height) override
Definition: framebuffer.cpp:117
cqsp::asset::ShaderProgram_t buffer_shader
Definition: framebuffer.h:98
int width
Definition: framebuffer.h:91
int height
Definition: framebuffer.h:92
unsigned int framebuffer
Definition: framebuffer.h:94
unsigned int intermediateFBO
Definition: framebuffer.h:95
void RenderBuffer() override
Definition: framebuffer.cpp:174
cqsp::engine::Mesh_t mesh_output
Definition: framebuffer.h:99
void NewFrame(const Window &window) override
Definition: framebuffer.cpp:191
void Free() override
Definition: framebuffer.cpp:165
unsigned int mscat
Definition: framebuffer.h:97
~AAFrameBufferRenderer()
Definition: framebuffer.cpp:115
void SetShader(cqsp::asset::ShaderProgram_t shader) override
Definition: framebuffer.h:88
Definition: framebuffer.h:48
void SetShader(cqsp::asset::ShaderProgram_t shader) override
Definition: framebuffer.h:62
FramebufferRenderer()
Definition: framebuffer.h:50
cqsp::engine::Mesh & GetMeshOutput() override
Definition: framebuffer.h:61
void Clear() override
Definition: framebuffer.cpp:65
void BeginDraw() override
Definition: framebuffer.cpp:70
cqsp::engine::Mesh_t mesh_output
Definition: framebuffer.h:69
void EndDraw() override
Definition: framebuffer.cpp:75
void FreeBuffer()
Definition: framebuffer.cpp:96
void SetMesh(cqsp::engine::Mesh_t mesh) override
Definition: framebuffer.h:60
void Free() override
Definition: framebuffer.cpp:94
void RenderBuffer() override
Definition: framebuffer.cpp:83
unsigned int colorbuffer
Definition: framebuffer.h:67
void InitTexture(int width, int height) override
Definition: framebuffer.cpp:39
cqsp::asset::ShaderProgram_t buffer_shader
Definition: framebuffer.h:68
void NewFrame(const Window &window) override
Definition: framebuffer.cpp:101
unsigned int framebuffer
Definition: framebuffer.h:66
~FramebufferRenderer()
Definition: framebuffer.cpp:37
Interface for framebuffer renderers.
Definition: framebuffer.h:31
virtual void InitTexture(int width=1280, int height=720)=0
virtual cqsp::engine::Mesh & GetMeshOutput()=0
virtual void SetMesh(cqsp::engine::Mesh_t)=0
virtual void SetShader(cqsp::asset::ShaderProgram_t shader)=0
virtual void BeginDraw()=0
virtual void RenderBuffer()=0
virtual void Clear()=0
virtual ~IFramebuffer()
Definition: framebuffer.h:33
virtual void EndDraw()=0
virtual void NewFrame(const Window &window)=0
Renders a series of framebuffers onto screen. This is a relatively simple way of allowing organizatio...
Definition: framebuffer.h:133
void EndDraw(int layer)
Definition: framebuffer.cpp:207
void NewFrame(const cqsp::engine::Window &window)
Definition: framebuffer.cpp:223
void InitFramebuffer(IFramebuffer *buffer, cqsp::asset::ShaderProgram_t shader, const cqsp::engine::Window &window)
Definition: framebuffer.cpp:232
int AddLayer(asset::ShaderProgram_t shader, const engine::Window &window)
Definition: framebuffer.h:136
void BeginDraw(int layer)
Definition: framebuffer.cpp:205
int GetLayerCount()
Definition: framebuffer.cpp:230
std::vector< std::unique_ptr< IFramebuffer > > framebuffers
Definition: framebuffer.h:152
void DrawAllLayers()
Definition: framebuffer.cpp:209
IFramebuffer * GetFrameBuffer(int layer)
Definition: framebuffer.h:149
Definition: mesh.h:25
The window handles the initialization of the callbacks, and all the input and output....
Definition: window.h:25
std::shared_ptr< ShaderProgram > ShaderProgram_t
The preferred way of using a shader program.
Definition: shader.h:112
std::shared_ptr< Mesh > Mesh_t
Definition: mesh.h:44
When adding assets, it is extremely crucial that you read cqsp::asset::AssetLoader::LoadResources to ...
Definition: clientctx.h:21