Pyrogenesis  trunk
TerrainRenderer.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 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 /*
19  * Terrain rendering (everything related to patches and water) is
20  * encapsulated in TerrainRenderer
21  */
22 
23 #ifndef INCLUDED_TERRAINRENDERER
24 #define INCLUDED_TERRAINRENDERER
25 
26 class CPatch;
27 class CSimulation2;
28 class ShadowMap;
29 class WaterManager;
30 
32 
33 /**
34  * Class TerrainRenderer: Render everything related to the terrain,
35  * especially patches and water.
36  */
38 {
39  friend class CPatchRData;
40  friend class CDecalRData;
41 
42 public:
45 
46  /**
47  * Set the simulation context for this frame.
48  * Call at start of frame, before any other Submits.
49  */
50  void SetSimulation(CSimulation2* simulation);
51 
52  /**
53  * Submit: Add a patch for rendering in this frame.
54  *
55  * preconditions : PrepareForRendering must not have been called
56  * for this frame yet.
57  * The patch must not have been submitted in this frame yet (i.e. you
58  * can only submit a frame once).
59  *
60  * @param patch the patch
61  */
62  void Submit(int cullGroup, CPatch* patch);
63 
64  /**
65  * Submit: Add a terrain decal for rendering in this frame.
66  */
67  void Submit(int cullGroup, CModelDecal* decal);
68 
69  /**
70  * PrepareForRendering: Prepare internal data structures like vertex
71  * buffers for rendering.
72  *
73  * All patches must have been submitted before the call to
74  * PrepareForRendering.
75  * PrepareForRendering must be called before any rendering calls.
76  */
77  void PrepareForRendering();
78 
79  /**
80  * EndFrame: Remove all patches from the list of submitted patches.
81  */
82  void EndFrame();
83 
84  /**
85  * RenderTerrain: Render textured terrain (including blends between
86  * different terrain types).
87  *
88  * preconditions : PrepareForRendering must have been called this
89  * frame before calling RenderTerrain.
90  */
91  void RenderTerrain(int cullGroup);
92 
93  /**
94  * Render textured terrain, as with RenderTerrain, but using shaders
95  * instead of multitexturing.
96  *
97  * @param shadow A prepared shadow map, in case rendering with shadows is enabled.
98  */
99  void RenderTerrainShader(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
100 
101  /**
102  * RenderPatches: Render all patches un-textured as polygons.
103  *
104  * preconditions : PrepareForRendering must have been called this
105  * frame before calling RenderPatches.
106  *
107  * @param filtered If true then only render objects that passed CullPatches.
108  */
109  void RenderPatches(int cullGroup);
110 
111  /**
112  * RenderOutlines: Render the outline of patches as lines.
113  *
114  * preconditions : PrepareForRendering must have been called this
115  * frame before calling RenderOutlines.
116  *
117  * @param filtered If true then only render objects that passed CullPatches.
118  */
119  void RenderOutlines(int cullGroup);
120 
121  /**
122  * RenderWater: Render water for all patches that have been submitted
123  * this frame.
124  *
125  * preconditions : PrepareForRendering must have been called this
126  * frame before calling RenderWater.
127  */
128  void RenderWater(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
129 
130  /**
131  * Calculate a scissor rectangle for the visible water patches.
132  */
133  CBoundingBoxAligned ScissorWater(int cullGroup, const CMatrix3D& viewproj);
134 
135  /**
136  * Render priority text for all submitted patches, for debugging.
137  */
138  void RenderPriorities(int cullGroup);
139 
140  /**
141  * Render texture unit 0 over the terrain mesh, with UV coords calculated
142  * by the given texture matrix.
143  * Intended for use by TerrainTextureOverlay.
144  */
145  void RenderTerrainOverlayTexture(int cullGroup, CMatrix3D& textureMatrix);
146 
147 private:
149 
150  /**
151  * RenderFancyWater: internal rendering method for fancy water.
152  * Returns false if unable to render with fancy water.
153  */
154  bool RenderFancyWater(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
155 
156  /**
157  * RenderSimpleWater: internal rendering method for water
158  */
159  void RenderSimpleWater(int cullGroup);
160 
161  static void PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow);
162 };
163 
164 #endif // INCLUDED_TERRAINRENDERER
Definition: DecalRData.h:31
void PrepareForRendering()
PrepareForRendering: Prepare internal data structures like vertex buffers for rendering.
Definition: TerrainRenderer.cpp:150
void RenderWater(const CShaderDefines &context, int cullGroup, ShadowMap *shadow)
RenderWater: Render water for all patches that have been submitted this frame.
Definition: TerrainRenderer.cpp:933
void RenderTerrainOverlayTexture(int cullGroup, CMatrix3D &textureMatrix)
Render texture unit 0 over the terrain mesh, with UV coords calculated by the given texture matrix...
Definition: TerrainRenderer.cpp:378
Struct TerrainRendererInternals: Internal variables used by the TerrainRenderer class.
Definition: TerrainRenderer.cpp:75
void RenderTerrainShader(const CShaderDefines &context, int cullGroup, ShadowMap *shadow)
Render textured terrain, as with RenderTerrain, but using shaders instead of multitexturing.
Definition: TerrainRenderer.cpp:479
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup, including matrix calculations.
Definition: ShadowMap.h:39
Public API for simulation system.
Definition: Simulation2.h:47
void RenderOutlines(int cullGroup)
RenderOutlines: Render the outline of patches as lines.
Definition: TerrainRenderer.cpp:556
Definition: Matrix3D.h:33
void RenderPatches(int cullGroup)
RenderPatches: Render all patches un-textured as polygons.
Definition: TerrainRenderer.cpp:531
void RenderTerrain(int cullGroup)
RenderTerrain: Render textured terrain (including blends between different terrain types)...
Definition: TerrainRenderer.cpp:175
void RenderPriorities(int cullGroup)
Render priority text for all submitted patches, for debugging.
Definition: TerrainRenderer.cpp:945
CBoundingBoxAligned ScissorWater(int cullGroup, const CMatrix3D &viewproj)
Calculate a scissor rectangle for the visible water patches.
Definition: TerrainRenderer.cpp:577
TerrainRenderer()
Definition: TerrainRenderer.cpp:96
Definition: PatchRData.h:38
void EndFrame()
EndFrame: Remove all patches from the list of submitted patches.
Definition: TerrainRenderer.cpp:159
Definition: Patch.h:48
~TerrainRenderer()
Definition: TerrainRenderer.cpp:102
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:133
static void PrepareShader(const CShaderProgramPtr &shader, ShadowMap *shadow)
Set up all the uniforms for a shader pass.
Definition: TerrainRenderer.cpp:451
Definition: Decal.h:50
Definition: BoundingBoxAligned.h:35
void RenderSimpleWater(int cullGroup)
RenderSimpleWater: internal rendering method for water.
Definition: TerrainRenderer.cpp:834
Class TerrainRenderer: Render everything related to the terrain, especially patches and water...
Definition: TerrainRenderer.h:37
void SetSimulation(CSimulation2 *simulation)
Set the simulation context for this frame.
Definition: TerrainRenderer.cpp:107
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:25
void Submit(int cullGroup, CPatch *patch)
Submit: Add a patch for rendering in this frame.
Definition: TerrainRenderer.cpp:114
bool RenderFancyWater(const CShaderDefines &context, int cullGroup, ShadowMap *shadow)
RenderFancyWater: internal rendering method for fancy water.
Definition: TerrainRenderer.cpp:630
Class WaterManager: Maintain rendering-related water settings and textures Anything that affects game...
Definition: WaterManager.h:43
TerrainRendererInternals * m
Definition: TerrainRenderer.h:148