Moves polygon mode handling to PipelineState and CDeviceCommandContext.
[0ad.git] / source / renderer / TerrainRenderer.h
blob8757a85b966f161402b18443e543b0fc7d757674
1 /* Copyright (C) 2022 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 #include "graphics/Color.h"
27 #include "maths/BoundingBoxAligned.h"
28 #include "renderer/backend/gl/DeviceCommandContext.h"
29 #include "renderer/backend/gl/Texture.h"
31 class CCamera;
32 class CCanvas2D;
33 class CMatrix3D;
34 class CModelDecal;
35 class CPatch;
36 class CShaderDefines;
37 class CSimulation2;
39 class ShadowMap;
41 struct TerrainRendererInternals;
43 /**
44 * Class TerrainRenderer: Render everything related to the terrain,
45 * especially patches and water.
47 class TerrainRenderer
49 friend class CPatchRData;
50 friend class CDecalRData;
52 public:
53 TerrainRenderer();
54 ~TerrainRenderer();
56 /**
57 * Set the simulation context for this frame.
58 * Call at start of frame, before any other Submits.
60 void SetSimulation(CSimulation2* simulation);
62 /**
63 * Submit: Add a patch for rendering in this frame.
65 * preconditions : PrepareForRendering must not have been called
66 * for this frame yet.
67 * The patch must not have been submitted in this frame yet (i.e. you
68 * can only submit a frame once).
70 * @param patch the patch
72 void Submit(int cullGroup, CPatch* patch);
74 /**
75 * Submit: Add a terrain decal for rendering in this frame.
77 void Submit(int cullGroup, CModelDecal* decal);
79 /**
80 * PrepareForRendering: Prepare internal data structures like vertex
81 * buffers for rendering.
83 * All patches must have been submitted before the call to
84 * PrepareForRendering.
85 * PrepareForRendering must be called before any rendering calls.
87 void PrepareForRendering();
89 /**
90 * EndFrame: Remove all patches from the list of submitted patches.
92 void EndFrame();
94 /**
95 * Render textured terrain (including blends between
96 * different terrain types).
98 * preconditions : PrepareForRendering must have been called this
99 * frame before calling RenderTerrain.
101 * @param deviceCommandContext A context to submit commands.
102 * @param shadow A prepared shadow map, in case rendering with shadows is enabled.
104 void RenderTerrainShader(
105 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
106 const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
109 * RenderPatches: Render all patches un-textured as polygons.
111 * preconditions : PrepareForRendering must have been called this
112 * frame before calling RenderPatches.
114 * @param filtered If true then only render objects that passed CullPatches.
115 * @param color Fill color of the patches.
117 void RenderPatches(
118 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
119 int cullGroup, const CShaderDefines& defines,
120 const CColor& color = CColor(0.0f, 0.0f, 0.0f, 1.0f));
123 * RenderOutlines: Render the outline of patches as lines.
125 * preconditions : PrepareForRendering must have been called this
126 * frame before calling RenderOutlines.
128 * @param filtered If true then only render objects that passed CullPatches.
130 void RenderOutlines(
131 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
132 int cullGroup);
135 * RenderWater: Render water for all patches that have been submitted
136 * this frame.
138 * preconditions : PrepareForRendering must have been called this
139 * frame before calling RenderWater.
141 void RenderWater(
142 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
143 const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
146 * Renders terrain to a framebuffer to occlude shore foams.
148 void RenderWaterFoamOccluders(
149 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
150 int cullGroup);
153 * Calculate a scissor rectangle for the visible water patches.
155 CBoundingBoxAligned ScissorWater(int cullGroup, const CCamera& camera);
158 * Render priority text for all submitted patches, for debugging.
160 void RenderPriorities(CCanvas2D& canvas, int cullGroup);
163 * Render texture unit 0 over the terrain mesh, with UV coords calculated
164 * by the given texture matrix.
165 * Intended for use by TerrainTextureOverlay.
167 void RenderTerrainOverlayTexture(
168 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
169 int cullGroup, CMatrix3D& textureMatrix, Renderer::Backend::GL::CTexture* texture);
171 private:
172 TerrainRendererInternals* m;
175 * RenderFancyWater: internal rendering method for fancy water.
176 * Returns false if unable to render with fancy water.
178 bool RenderFancyWater(
179 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
180 const CShaderDefines& context, int cullGroup, ShadowMap* shadow);
183 * RenderSimpleWater: internal rendering method for water
185 void RenderSimpleWater(
186 Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
187 int cullGroup);
189 static void PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow);
192 #endif // INCLUDED_TERRAINRENDERER