Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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(CPatch* patch);
63 
64  /**
65  * Submit: Add a terrain decal for rendering in this frame.
66  */
67  void Submit(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  * CullPatches: Culls patches and decals against a frustum,
86  * and stores the results in a special filtered list that
87  * is used when calling render functions with @p filtered true.
88  */
89  bool CullPatches(const CFrustum* frustum);
90 
91  /**
92  * RenderTerrain: Render textured terrain (including blends between
93  * different terrain types).
94  *
95  * preconditions : PrepareForRendering must have been called this
96  * frame before calling RenderTerrain.
97  *
98  * @param filtered If true then only render objects that passed CullPatches.
99  */
100  void RenderTerrain(bool filtered = false);
101 
102  /**
103  * Render textured terrain, as with RenderTerrain, but using shaders
104  * instead of multitexturing.
105  *
106  * @param shadow A prepared shadow map, in case rendering with shadows is enabled.
107  * @param filtered If true then only render objects that passed CullPatches.
108  */
109  void RenderTerrainShader(const CShaderDefines& context, ShadowMap* shadow, bool filtered = false);
110 
111  /**
112  * RenderPatches: Render all patches un-textured as polygons.
113  *
114  * preconditions : PrepareForRendering must have been called this
115  * frame before calling RenderPatches.
116  *
117  * @param filtered If true then only render objects that passed CullPatches.
118  */
119  void RenderPatches(bool filtered = false);
120 
121  /**
122  * RenderOutlines: Render the outline of patches as lines.
123  *
124  * preconditions : PrepareForRendering must have been called this
125  * frame before calling RenderOutlines.
126  *
127  * @param filtered If true then only render objects that passed CullPatches.
128  */
129  void RenderOutlines(bool filtered = false);
130 
131  /**
132  * RenderWater: Render water for all patches that have been submitted
133  * this frame.
134  *
135  * preconditions : PrepareForRendering must have been called this
136  * frame before calling RenderWater.
137  */
138  void RenderWater(const CShaderDefines& context, ShadowMap* shadow);
139 
140  /**
141  * Calculate a scissor rectangle for the visible water patches.
142  */
143  CBoundingBoxAligned ScissorWater(const CMatrix3D& viewproj);
144 
145  /**
146  * Render priority text for all submitted patches, for debugging.
147  */
148  void RenderPriorities();
149 
150  /**
151  * Render texture unit 0 over the terrain mesh, with UV coords calculated
152  * by the given texture matrix.
153  * Intended for use by TerrainTextureOverlay.
154  */
155  void RenderTerrainOverlayTexture(CMatrix3D& textureMatrix);
156 
157 private:
159 
160  /**
161  * RenderFancyWater: internal rendering method for fancy water.
162  * Returns false if unable to render with fancy water.
163  */
164  bool RenderFancyWater(const CShaderDefines& context, ShadowMap* shadow);
165 
166  /**
167  * RenderSimpleWater: internal rendering method for water
168  */
169  void RenderSimpleWater();
170 
171  static void PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow);
172 };
173 
174 #endif // INCLUDED_TERRAINRENDERER
void RenderOutlines(bool filtered=false)
RenderOutlines: Render the outline of patches as lines.
void RenderWater(const CShaderDefines &context, ShadowMap *shadow)
RenderWater: Render water for all patches that have been submitted this frame.
void PrepareForRendering()
PrepareForRendering: Prepare internal data structures like vertex buffers for rendering.
Struct TerrainRendererInternals: Internal variables used by the TerrainRenderer class.
void RenderTerrainShader(const CShaderDefines &context, ShadowMap *shadow, bool filtered=false)
Render textured terrain, as with RenderTerrain, but using shaders instead of multitexturing.
void RenderTerrain(bool filtered=false)
RenderTerrain: Render textured terrain (including blends between different terrain types)...
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:46
void RenderPatches(bool filtered=false)
RenderPatches: Render all patches un-textured as polygons.
void RenderPriorities()
Render priority text for all submitted patches, for debugging.
bool CullPatches(const CFrustum *frustum)
CullPatches: Culls patches and decals against a frustum, and stores the results in a special filtered...
void EndFrame()
EndFrame: Remove all patches from the list of submitted patches.
Definition: Patch.h:48
void RenderTerrainOverlayTexture(CMatrix3D &textureMatrix)
Render texture unit 0 over the terrain mesh, with UV coords calculated by the given texture matrix...
void Submit(CPatch *patch)
Submit: Add a patch for rendering in this frame.
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
void RenderSimpleWater()
RenderSimpleWater: internal rendering method for water.
static void PrepareShader(const CShaderProgramPtr &shader, ShadowMap *shadow)
Set up all the uniforms for a shader pass.
Class TerrainRenderer: Render everything related to the terrain, especially patches and water...
bool RenderFancyWater(const CShaderDefines &context, ShadowMap *shadow)
RenderFancyWater: internal rendering method for fancy water.
CBoundingBoxAligned ScissorWater(const CMatrix3D &viewproj)
Calculate a scissor rectangle for the visible water patches.
shared_ptr< CShaderProgram > CShaderProgramPtr
void SetSimulation(CSimulation2 *simulation)
Set the simulation context for this frame.
Class WaterManager: Maintain water settings and textures.
Definition: WaterManager.h:49
TerrainRendererInternals * m