Merge 'remotes/trunk'
[0ad.git] / source / renderer / TerrainRenderer.h
blobd70c11e5d19494a156f873100ec1672444d5c7af
1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
19 * Terrain rendering (everything related to patches and water) is
20 * encapsulated in TerrainRenderer
23 #ifndef INCLUDED_TERRAINRENDERER
24 #define INCLUDED_TERRAINRENDERER
26 class CPatch;
27 class CSimulation2;
28 class ShadowMap;
29 class WaterManager;
31 struct TerrainRendererInternals;
33 /**
34 * Class TerrainRenderer: Render everything related to the terrain,
35 * especially patches and water.
37 class TerrainRenderer
39 friend class CPatchRData;
40 friend class CDecalRData;
42 public:
43 TerrainRenderer();
44 ~TerrainRenderer();
46 /**
47 * Set the simulation context for this frame.
48 * Call at start of frame, before any other Submits.
50 void SetSimulation(CSimulation2* simulation);
52 /**
53 * Submit: Add a patch for rendering in this frame.
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).
60 * @param patch the patch
62 void Submit(int cullGroup, CPatch* patch);
64 /**
65 * Submit: Add a terrain decal for rendering in this frame.
67 void Submit(int cullGroup, CModelDecal* decal);
69 /**
70 * PrepareForRendering: Prepare internal data structures like vertex
71 * buffers for rendering.
73 * All patches must have been submitted before the call to
74 * PrepareForRendering.
75 * PrepareForRendering must be called before any rendering calls.
77 void PrepareForRendering();
79 /**
80 * EndFrame: Remove all patches from the list of submitted patches.
82 void EndFrame();
84 /**
85 * RenderTerrain: Render textured terrain (including blends between
86 * different terrain types).
88 * preconditions : PrepareForRendering must have been called this
89 * frame before calling RenderTerrain.
91 void RenderTerrain(int cullGroup);
93 /**
94 * Render textured terrain, as with RenderTerrain, but using shaders
95 * instead of multitexturing.
97 * @param shadow A prepared shadow map, in case rendering with shadows is enabled.
99 void RenderTerrainShader(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
102 * RenderPatches: Render all patches un-textured as polygons.
104 * preconditions : PrepareForRendering must have been called this
105 * frame before calling RenderPatches.
107 * @param filtered If true then only render objects that passed CullPatches.
109 void RenderPatches(int cullGroup);
112 * RenderOutlines: Render the outline of patches as lines.
114 * preconditions : PrepareForRendering must have been called this
115 * frame before calling RenderOutlines.
117 * @param filtered If true then only render objects that passed CullPatches.
119 void RenderOutlines(int cullGroup);
122 * RenderWater: Render water for all patches that have been submitted
123 * this frame.
125 * preconditions : PrepareForRendering must have been called this
126 * frame before calling RenderWater.
128 void RenderWater(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
131 * Calculate a scissor rectangle for the visible water patches.
133 CBoundingBoxAligned ScissorWater(int cullGroup, const CMatrix3D& viewproj);
136 * Render priority text for all submitted patches, for debugging.
138 void RenderPriorities(int cullGroup);
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.
145 void RenderTerrainOverlayTexture(int cullGroup, CMatrix3D& textureMatrix);
147 private:
148 TerrainRendererInternals* m;
151 * RenderFancyWater: internal rendering method for fancy water.
152 * Returns false if unable to render with fancy water.
154 bool RenderFancyWater(const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
157 * RenderSimpleWater: internal rendering method for water
159 void RenderSimpleWater(int cullGroup);
161 static void PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow);
164 #endif // INCLUDED_TERRAINRENDERER