-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathRenderSystem.h
More file actions
116 lines (92 loc) · 3.23 KB
/
RenderSystem.h
File metadata and controls
116 lines (92 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#pragma once
#include "../Skybox.h"
#include "../Model.h"
#include "../Graphics/GLFramebuffer.h"
#include "../Graphics/GLVertexArray.h"
#include "../Graphics/GLShaderProgram.h"
#include "../Graphics/HardwareCaps.h"
#include <pugixml.hpp>
#include <unordered_map>
#include <vector>
//https://github.com/tapio/weep/blob/master/engine/glrenderer/renderdevice.cpp
// https://github.com/pboechat/PCSS
/***********************************************************************************/
// Forward Declarations
class Camera;
class SceneBase;
class GLShaderProgram;
/***********************************************************************************/
class RenderSystem {
using RenderListIterator = std::vector<ModelPtr>::const_iterator;
public:
~RenderSystem() = default;
void Init(const pugi::xml_node& rendererNode);
void Update(const Camera& camera);
//! Release OpenGL resources
void Shutdown();
//
void UpdateView(const Camera& camera);
//! Where the magic happens
void Render(const Camera& camera,
RenderListIterator renderListBegin,
RenderListIterator renderListEnd,
const SceneBase& scene,
const bool globalWireframe = false
);
int GetVideoMemUsageKB() const;
private:
// Helper functions
//
void compileShaders();
//
void queryHardwareCaps();
// Sets the default state required for rendering
void setDefaultState();
// Render models contained in the renderlist
void renderModelsWithTextures(GLShaderProgram& shader, RenderListIterator renderListBegin, RenderListIterator renderListEnd) const;
// Render models without binding textures (for a depth or shadow pass perhaps)
void renderModelsNoTextures(GLShaderProgram& shader, RenderListIterator renderListBegin, RenderListIterator renderListEnd) const;
// Render NDC screenquad
void renderQuad() const;
// Renders shadowmap
void renderShadowMap(const SceneBase& scene, RenderListIterator renderListBegin, RenderListIterator renderListEnd);
// Configure NDC screenquad
void setupScreenquad();
// Setup texture samplers
void setupTextureSamplers();
// Setup FBO, resolution, etc for shadow mapping
void setupShadowMap();
// Configure post-processing effects
void setupPostProcessing();
// Sets projection matrix variable and updates UBO
void setProjectionMatrix(const Camera& camera);
pugi::xml_node m_rendererNode;
Graphics::HardwareCaps m_caps;
// Screen dimensions
std::size_t m_width{ 0 }, m_height{ 0 };
// Uniform buffer for projection and view matrix
GLuint m_uboMatrices{ 0 };
// Projection matrix
glm::mat4 m_projMatrix, m_lightSpaceMatrix;
// Texture samplers
GLuint m_samplerPBRTextures{ 0 };
// Shadow mapping
GLuint m_shadowMapResolution{ 1024 }, m_shadowDepthTexture{ 0 }, m_shadowColorTexture{ 0 };
GLFramebuffer m_shadowFBO;
// Environment map
Skybox m_skybox;
// Compiled shader cache
std::unordered_map<std::string, GLShaderProgram> m_shaderCache;
// Screen-quad
GLVertexArray m_quadVAO;
// Post-Processing
// HDR
GLuint m_hdrColorBuffer{ 0 }, m_brightnessThresholdColorBuffer{ 0 };
GLFramebuffer m_hdrFBO;
// Bloom
std::array<GLFramebuffer, 2> m_pingPongFBOs;
std::array<GLuint, 2> m_pingPongColorBuffers{0, 0};
// Vibrance
const float m_vibrance{ 0.1f };
const glm::vec4 m_coefficient{ 0.299f, 0.587f, 0.114f, 0.0f };
};