Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
SceneRenderer.h
Go to the documentation of this file.
1/* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. 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 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_SCENERENDERER
19#define INCLUDED_RENDERER_SCENERENDERER
20
21#include "graphics/Camera.h"
25#include "ps/Singleton.h"
28#include "renderer/Scene.h"
29
30#include <memory>
31
32class CCanvas2D;
33class CLightEnv;
34class CMaterial;
36class CModel;
38class CPatch;
39class CSimulation2;
40class ShadowMap;
41class SkyManager;
42class TerrainRenderer;
43class WaterManager;
44
45// rendering modes
47
48// transparency modes
50
52{
53public:
55 {
66 };
67
70
71 void Initialize();
72 void Resize(int width, int height);
73
74 void BeginFrame();
75 void EndFrame();
76
77 /**
78 * Set simulation context for rendering purposes.
79 * Must be called at least once when the game has started and before
80 * frames are rendered.
81 */
82 void SetSimulation(CSimulation2* simulation);
83
84 // trigger a reload of shaders (when parameters they depend on have changed)
85 void MakeShadersDirty();
86
87 /**
88 * Set up the camera used for rendering the next scene; this includes
89 * setting OpenGL state like viewport, projection and modelview matrices.
90 *
91 * @param viewCamera this camera determines the eye position for rendering
92 * @param cullCamera this camera determines the frustum for culling in the renderer and
93 * for shadow calculations
94 */
95 void SetSceneCamera(const CCamera& viewCamera, const CCamera& cullCamera);
96
97 /**
98 * Enumerate and submit all objects of the given scene which should be rendered.
99 * Must be called before RenderScene.
100 */
101 void PrepareScene(
102 Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene);
103
104 /**
105 * Render submitted objects of the previously given scene.
106 */
107 void RenderScene(
108 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
109
110 /**
111 * Render overlays of the previously given scene.
112 * Must be called after RenderScene.
113 */
115 Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
116
117 /**
118 * Return the scene that is currently being rendered.
119 * Only valid when the renderer is in a RenderScene call.
120 */
121 Scene& GetScene();
122
123 /**
124 * Render text overlays on top of the scene.
125 * Assumes the caller has set up the GL environment for orthographic rendering
126 * with texturing and blending.
127 */
128 void RenderTextOverlays(CCanvas2D& canvas);
129
130 // set the current lighting environment; (note: the passed pointer is just copied to a variable within the renderer,
131 // so the lightenv passed must be scoped such that it is not destructed until after the renderer is no longer rendering)
132 void SetLightEnv(CLightEnv* lightenv)
133 {
134 m_LightEnv = lightenv;
135 }
136
137 // set the mode to render subsequent terrain patches
139 // get the mode to render subsequent terrain patches
141
142 // set the mode to render subsequent water patches
144 // get the mode to render subsequent water patches
146
147 // set the mode to render subsequent models
149 // get the mode to render subsequent models
151
152 // Get the mode to render subsequent overlays.
154 // Set the mode to render subsequent overlays.
156
157 // debugging
159
160 // return the current light environment
161 const CLightEnv &GetLightEnv() { return *m_LightEnv; }
162
163 // return the current view camera
164 const CCamera& GetViewCamera() const { return m_ViewCamera; }
165 // replace the current view camera
166 void SetViewCamera(const CCamera& camera) { m_ViewCamera = camera; }
167
168 // return the current cull camera
169 const CCamera& GetCullCamera() const { return m_CullCamera; }
170
171 /**
172 * GetWaterManager: Return the renderer's water manager.
173 *
174 * @return the WaterManager object used by the renderer
175 */
177
178 /**
179 * GetSkyManager: Return the renderer's sky manager.
180 *
181 * @return the SkyManager object used by the renderer
182 */
184
186
188
190
192
193 /**
194 * Resets the render state to default, that was before a game started
195 */
196 void ResetState();
197
199
200protected:
201 void Submit(CPatch* patch) override;
202 void Submit(SOverlayLine* overlay) override;
203 void Submit(SOverlayTexturedLine* overlay) override;
204 void Submit(SOverlaySprite* overlay) override;
205 void Submit(SOverlayQuad* overlay) override;
206 void Submit(CModelDecal* decal) override;
207 void Submit(CParticleEmitter* emitter) override;
208 void Submit(SOverlaySphere* overlay) override;
209 void SubmitNonRecursive(CModel* model) override;
210
211 /**
212 * Update and upload all needed data for submitted objects.
213 */
215 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
216 const CBoundingBoxAligned& waterScissor);
217
218 // render any batched objects
220 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
221 const CBoundingBoxAligned& waterScissor);
222
223 // patch rendering stuff
224 void RenderPatches(
225 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
226 const CShaderDefines& context, int cullGroup);
227
228 // model rendering stuff
229 void RenderModels(
230 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
231 const CShaderDefines& context, int cullGroup);
233 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
234 const CShaderDefines& context, int cullGroup, ETransparentMode transparentMode);
235
237 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
238 const CShaderDefines& context);
239
240 void RenderParticles(
241 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
242 int cullGroup);
243
244 // shadow rendering stuff
245 void RenderShadowMap(
246 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
247 const CShaderDefines& context);
248
249 // render water reflection and refraction textures
251 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
252 const CShaderDefines& context, const CBoundingBoxAligned& scissor);
254 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
255 const CShaderDefines& context, const CBoundingBoxAligned& scissor);
256
257 void ComputeReflectionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const;
258 void ComputeRefractionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const;
259
260 // debugging
261 void DisplayFrustum();
262
263 // enable oblique frustum clipping with the given clip plane
264 void SetObliqueFrustumClipping(CCamera& camera, const CVector4D& clipPlane) const;
265
266 // Private data that is not needed by inline functions.
267 class Internals;
268 std::unique_ptr<Internals> m;
269
270 // Current terrain rendering mode.
272 // Current water rendering mode.
274 // Current model rendering mode.
276 // Current overlay rendering mode.
278
279 /**
280 * m_ViewCamera: determines the eye position for rendering
281 *
282 * @see CGameView::m_ViewCamera
283 */
285
286 /**
287 * m_CullCamera: determines the frustum for culling and shadowmap calculations
288 *
289 * @see CGameView::m_ViewCamera
290 */
292
293 // only valid inside a call to RenderScene
296
298
299 // current lighting setup
301
302 /**
303 * Enable rendering of terrain tile priority text overlay, for debugging.
304 */
306};
307
308#endif // INCLUDED_RENDERER_SCENERENDERER
ETransparentMode
Definition: SceneRenderer.h:49
@ TRANSPARENT
Definition: SceneRenderer.h:49
@ TRANSPARENT_OPAQUE
Definition: SceneRenderer.h:49
@ TRANSPARENT_BLEND
Definition: SceneRenderer.h:49
ERenderMode
Definition: SceneRenderer.h:46
@ SOLID
Definition: SceneRenderer.h:46
@ EDGED_FACES
Definition: SceneRenderer.h:46
@ WIREFRAME
Definition: SceneRenderer.h:46
Definition: BoundingBoxAligned.h:34
Definition: Camera.h:42
Definition: Canvas2D.h:36
Class CLightEnv: description of a lighting environment - contains all the necessary parameters for re...
Definition: LightEnv.h:37
Definition: MaterialManager.h:26
Definition: Material.h:29
Definition: Decal.h:50
Definition: Model.h:39
Particle emitter.
Definition: ParticleEmitter.h:69
Definition: ParticleManager.h:31
Definition: Patch.h:49
Definition: SceneRenderer.h:52
CBoundingBoxAligned m_WaterScissor
Definition: SceneRenderer.h:297
void SetWaterRenderMode(ERenderMode mode)
Definition: SceneRenderer.h:143
void PrepareSubmissions(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CBoundingBoxAligned &waterScissor)
Update and upload all needed data for submitted objects.
Definition: SceneRenderer.cpp:773
void RenderPatches(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context, int cullGroup)
Definition: SceneRenderer.cpp:340
void RenderTransparentModels(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context, int cullGroup, ETransparentMode transparentMode)
Definition: SceneRenderer.cpp:393
ERenderMode GetTerrainRenderMode() const
Definition: SceneRenderer.h:140
void ComputeRefractionCamera(CCamera &camera, const CBoundingBoxAligned &scissor) const
Definition: SceneRenderer.cpp:510
void Submit(CPatch *patch) override
Submit a terrain patch that is part of the scene.
Definition: SceneRenderer.cpp:961
CMaterialManager & GetMaterialManager()
Definition: SceneRenderer.cpp:1193
CSceneRenderer(Renderer::Backend::IDevice *device)
Definition: SceneRenderer.cpp:192
void SubmitNonRecursive(CModel *model) override
Submit a model that is part of the scene, without submitting attached models.
Definition: SceneRenderer.cpp:1025
const CLightEnv & GetLightEnv()
Definition: SceneRenderer.h:161
ERenderMode GetWaterRenderMode() const
Definition: SceneRenderer.h:145
void SetViewCamera(const CCamera &camera)
Definition: SceneRenderer.h:166
ERenderMode m_OverlayRenderMode
Definition: SceneRenderer.h:277
void SetModelRenderMode(ERenderMode mode)
Definition: SceneRenderer.h:148
void RenderScene(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Render submitted objects of the previously given scene.
Definition: SceneRenderer.cpp:1139
std::unique_ptr< Internals > m
Definition: SceneRenderer.h:268
void Resize(int width, int height)
Definition: SceneRenderer.cpp:278
Scene & GetScene()
Return the scene that is currently being rendered.
Definition: SceneRenderer.cpp:1162
SkyManager & GetSkyManager()
GetSkyManager: Return the renderer's sky manager.
Definition: SceneRenderer.cpp:1178
void RenderRefractions(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context, const CBoundingBoxAligned &scissor)
Definition: SceneRenderer.cpp:625
void SetDisplayTerrainPriorities(bool enabled)
Definition: SceneRenderer.h:158
ERenderMode m_WaterRenderMode
Definition: SceneRenderer.h:273
const CCamera & GetViewCamera() const
Definition: SceneRenderer.h:164
TerrainRenderer & GetTerrainRenderer()
Definition: SceneRenderer.cpp:1188
ShadowMap & GetShadowMap()
Definition: SceneRenderer.cpp:1198
ERenderMode GetModelRenderMode() const
Definition: SceneRenderer.h:150
void RenderShadowMap(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context)
Definition: SceneRenderer.cpp:299
CParticleManager & GetParticleManager()
Definition: SceneRenderer.cpp:1183
void RenderSilhouettes(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context)
Definition: SceneRenderer.cpp:702
const CCamera & GetCullCamera() const
Definition: SceneRenderer.h:169
void ResetState()
Resets the render state to default, that was before a game started.
Definition: SceneRenderer.cpp:1203
CCamera m_CullCamera
m_CullCamera: determines the frustum for culling and shadowmap calculations
Definition: SceneRenderer.h:291
ERenderMode GetOverlayRenderMode() const
Definition: SceneRenderer.h:153
void SetSimulation(CSimulation2 *simulation)
Set simulation context for rendering purposes.
Definition: SceneRenderer.cpp:293
CCamera m_ViewCamera
m_ViewCamera: determines the eye position for rendering
Definition: SceneRenderer.h:284
void RenderReflections(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context, const CBoundingBoxAligned &scissor)
Definition: SceneRenderer.cpp:548
void DisplayFrustum()
Definition: SceneRenderer.cpp:934
void PrepareScene(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Scene &scene)
Enumerate and submit all objects of the given scene which should be rendered.
Definition: SceneRenderer.cpp:1064
void SetObliqueFrustumClipping(CCamera &camera, const CVector4D &clipPlane) const
Definition: SceneRenderer.cpp:432
void RenderParticles(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, int cullGroup)
Definition: SceneRenderer.cpp:755
CullGroup
Definition: SceneRenderer.h:55
@ CULL_SHADOWS_CASCADE_2
Definition: SceneRenderer.h:59
@ CULL_SHADOWS_CASCADE_3
Definition: SceneRenderer.h:60
@ CULL_DEFAULT
Definition: SceneRenderer.h:56
@ CULL_SHADOWS_CASCADE_0
Definition: SceneRenderer.h:57
@ CULL_SILHOUETTE_CASTER
Definition: SceneRenderer.h:64
@ CULL_SILHOUETTE_OCCLUDER
Definition: SceneRenderer.h:63
@ CULL_REFRACTIONS
Definition: SceneRenderer.h:62
@ CULL_REFLECTIONS
Definition: SceneRenderer.h:61
@ CULL_MAX
Definition: SceneRenderer.h:65
@ CULL_SHADOWS_CASCADE_1
Definition: SceneRenderer.h:58
WaterManager & GetWaterManager()
GetWaterManager: Return the renderer's water manager.
Definition: SceneRenderer.cpp:1173
CLightEnv * m_LightEnv
Definition: SceneRenderer.h:300
void MakeShadersDirty()
Definition: SceneRenderer.cpp:1168
ERenderMode m_TerrainRenderMode
Definition: SceneRenderer.h:271
void RenderTextOverlays(CCanvas2D &canvas)
Render text overlays on top of the scene.
Definition: SceneRenderer.cpp:941
void BeginFrame()
Definition: SceneRenderer.cpp:286
void SetSceneCamera(const CCamera &viewCamera, const CCamera &cullCamera)
Set up the camera used for rendering the next scene; this includes setting OpenGL state like viewport...
Definition: SceneRenderer.cpp:952
ERenderMode m_ModelRenderMode
Definition: SceneRenderer.h:275
void SetLightEnv(CLightEnv *lightenv)
Definition: SceneRenderer.h:132
void RenderModels(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CShaderDefines &context, int cullGroup)
Definition: SceneRenderer.cpp:370
void SetTerrainRenderMode(ERenderMode mode)
Definition: SceneRenderer.h:138
int m_CurrentCullGroup
Definition: SceneRenderer.h:295
void EndFrame()
Definition: SceneRenderer.cpp:917
void SetOverlayRenderMode(ERenderMode mode)
Definition: SceneRenderer.h:155
void ComputeReflectionCamera(CCamera &camera, const CBoundingBoxAligned &scissor) const
Definition: SceneRenderer.cpp:465
bool m_DisplayTerrainPriorities
Enable rendering of terrain tile priority text overlay, for debugging.
Definition: SceneRenderer.h:305
Scene * m_CurrentScene
Definition: SceneRenderer.h:294
void Initialize()
Definition: SceneRenderer.cpp:268
void RenderSubmissions(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const CBoundingBoxAligned &waterScissor)
Definition: SceneRenderer.cpp:844
~CSceneRenderer()
Definition: SceneRenderer.cpp:208
void RenderSceneOverlays(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Render overlays of the previously given scene.
Definition: SceneRenderer.cpp:1146
void ReloadShaders(Renderer::Backend::IDevice *device)
Definition: SceneRenderer.cpp:216
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:147
Public API for simulation system.
Definition: Simulation2.h:47
Definition: Vector4D.h:31
Definition: IDeviceCommandContext.h:42
Definition: IDevice.h:48
This interface accepts renderable objects.
Definition: Scene.h:90
This interface describes a scene to the renderer.
Definition: Scene.h:54
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup,...
Definition: ShadowMap.h:39
Class SkyManager: Maintain sky settings and textures, and render the sky.
Definition: SkyManager.h:38
Class TerrainRenderer: Render everything related to the terrain, especially patches and water.
Definition: TerrainRenderer.h:49
Class WaterManager: Maintain rendering-related water settings and textures Anything that affects game...
Definition: WaterManager.h:48
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:39
Rectangular single-quad terrain overlay, in world space coordinates.
Definition: Overlay.h:161
Definition: Overlay.h:169
Billboard sprite overlay, with world-space coordinates, rendered on top of all other objects.
Definition: Overlay.h:148
Textured line overlay, with world-space coordinates, rendered in the world onto the terrain.
Definition: Overlay.h:66