HIRO_DRAW
Computer Graphics Structures library
RenderSystem.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef HIRO_DRAW_RENDER_SYSTEM_H
7 #define HIRO_DRAW_RENDER_SYSTEM_H
8 #include <array>
9 
10 #include <GLW/FrameBuffer.h>
11 #include <GLW/UniformBuffer.h>
12 #include <Utils/GeometryStructures.h>
13 
14 #include <HIRO_DRAW/Renderer.h>
15 #include <HIRO_DRAW/Scene.h>
16 #include <HIRO_DRAW/ShaderApi.h>
17 #include <HIRO_DRAW/PrimitiveDatabase.h>
18 #include <HIRO_DRAW/TextRenderer.h>
19 
20 
21 
22 namespace hiro::draw
23 {
24  enum class AntiAliasing : uint8_t
25  {
26  none,
27  msaa2x,
28  msaa4x,
29  msaa8x,
30  msaa16x,
31  fxaa
32  };
33 
34 
35  const uint8_t DEFAULT_AXIS_OVERLAY_LAYER = 128;
36  const uint8_t DEFAULT_GROUND_OVERLAY_LAYER = 0;
37 
38 
42  class HIRO_DRAW_API RenderSystem
43  {
44  public:
45 
46  enum class Mode
47  {
52  visualizer,
57  deferred_only,
58  };
59 
60  RenderSystem(const glm::uvec2 &size, Mode mode = Mode::visualizer);
61 
63  RenderSystem(const glm::uvec2 &size, const glw::PProgramList &programlist_ptr, Mode mode);
64 
66  void SetFramebufferSize(const glm::uvec2 &size);
67 
69  void SetShaderBuildDirectory(const std::string &directory);
70 
72  void SetBackgroundColor(const cogs::Color3f &color);
73 
75  hiro::draw::TextRenderer *GetTextRenderer();
76 
78  uint32_t AddScene(const hiro::draw::PScene &scene);
79 
81  void RemoveScene(const hiro::draw::PScene &scene);
82 
84  hiro::draw::PScene GetScene(const uint32_t scene_id);
85 
87  uint32_t AddLight(const hiro::shader::Light &light);
88 
90  void SetLight(uint32_t light_id, const hiro::shader::Light &light);
91 
93  void LoadShaders();
94 
96  void ReloadShaders();
97 
99  void Render();
100 
102  void SetAntiAliasingMethod(AntiAliasing method);
103 
105  AntiAliasing GetAntiAliasingMethod();
106 
108  glm::uvec2 GetFrameBufferSize();
109 
111  void EnableShadowing(const glm::uvec2 &shadowmap_buffer_resolution, bool light_areas_outside_shadowmap = true);
112 
114  void DisableShadowing();
115 
117  bool IsShadowingEnabled() const;
118 
120  uint8_t GetAxisLayer() const;
121 
123  void SetAxisLayer(uint8_t layer);
124 
126  uint8_t GetGroundLayer() const;
127 
129  void SetGroundLayer(uint8_t layer);
130 
137  glw::PTexture2D GetPositionsAndShininessTex() const;
138 
145  glw::PTexture2D GetNormalsAndSpecularTex() const;
146 
153  glw::PTexture2D GetColorsAndLightingTex() const;
154 
160  glw::PTexture2D GetShadowMaskTex() const;
161 
167  glw::PTexture2D GetShadowmapTex() const;
168 
169 
175  glw::PTexture2D GetLabelTex() const;
176 
177  private:
178 
179  using RenderPassSceneFunc = std::function<void(const PScene &, uint8_t, const std::string &)>;
180 
181  struct SceneData
182  {
183  glm::mat4 projection;
184  glm::mat4 projection_inverse;
185  int32_t camera_id;
186  glm::vec3 padding0;
187  glm::ivec4 light_ids;
188  glm::ivec2 resolution;
189  glm::vec2 padding1;
190  };
191 
192  enum class RenderPass
193  {
194  other = 0,
195  shadow = 1,
196  };
197 
198  enum class ShadowingMethod
199  {
200  disabled = 0, // No shadows are generated.
201  shadowed_scene = 1, // Scene is shadowed using the shadow map. Regions outside shadow map have no shadow.
202  lighten_scene = 2, // Scene is lighten using the shadow map. Regions outside shadow map are fully shadowed.
203  };
204 
205  hiro::draw::TextRenderer text_renderer_;
206 
207  glw::PProgramList programs_;
208  glw::PFrameBuffer deferred_buffer_;
209  glw::PFrameBuffer combined_buffer_;
210  glw::PFrameBuffer fxaa_buffer_;
211  glw::PFrameBuffer shadowmap_buffer_;
212  AntiAliasing antialiasing_method_ = AntiAliasing::none;
213 
214  const Mode mode_ = Mode::visualizer;
215  glm::uvec2 framebuffer_size_;
216  cogs::Color3b back_color_ = cogs::color::WHITE;
217  std::vector<PScene> scenes_;
218 
219  glw::UniformBuffer<glm_ext::TransMat4> cameraview_buffer_;
220 
221  uint8_t axis_layer_ = DEFAULT_AXIS_OVERLAY_LAYER;
222  uint8_t ground_layer_ = DEFAULT_GROUND_OVERLAY_LAYER;
223 
224  uint32_t added_light_count_ = 0u;
225  glw::UniformBuffer<hiro::shader::Light> light_buffer_;
226 
227  glw::UniformBuffer<hiro::draw::RenderSystem::SceneData> scenedata_buffer_;
228  glw::PArrayObject grid_buffer_;
229 
230  std::vector<uint8_t> occupied_layers_;
231 
232  RenderPass current_pass_{ RenderPass::other };
233  ShadowingMethod shadowing_method_{ ShadowingMethod::disabled };
234 
235  void CreateGridBuffer();
236 
237  void UpdateCameraBuffers(bool use_2d);
238  void UpdateSceneDataBuffers(bool use_2d_projection);
239 
240  void UpdateOccupiedLayers();
241 
242  void PrepareSceneForRender(const uint32_t scene_id);
243 
244  void RenderGrid(GroundGrid orientation, float scale);
245  void RenderAxes(const PScene &scene);
246 
247  SceneData GetSceneData(const uint32_t scene_id, bool use_2d_projection);
248 
249  void LoadSceneShaders(const uint32_t scene_id);
250 
252  void ResetFrameBuffers();
253 
255  void RenderBufferPass(const glw::FrameBuffer &source_buffer, const std::string &shader);
256 
257  void RenderPassLayer(uint8_t layer, const RenderPassSceneFunc &RenderPassScene);
258 
259  void RenderPassAllLayers(const RenderPassSceneFunc &RenderPassScene);
260 
262  void InitDeferredRendering();
263 
264  void Render3D(const PScene &scene, uint8_t layer, const std::string &shader);
265 
266  void Render2D(const PScene &scene, uint8_t layer, const std::string &shader);
267  };
268 
269 }
270 
271 #endif /* !HIRO_DRAW_RENDER_SYSTEM_H */
GroundGrid
Mode for rendering ground grid lines.
Definition: Scene.h:77
Mode
Definition: RenderSystem.h:46
Responsible for rendering texts.
Definition: TextRenderer.h:47
Definition of scene light.
Definition: ShaderApi.h:116
Extensions for object visualization. Implements a higher level of OpenGL rendering.
Definition: API.h:20
Class responsible for rendering loop implementation and its optimization.
Definition: RenderSystem.h:42