Removes unused forward declarations of class and struct.
[0ad.git] / source / renderer / ShadowMap.h
blob4509737b4debadde14b352ed204cc64c3241feb0
1 /* Copyright (C) 2021 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/>.
18 #ifndef INCLUDED_SHADOWMAP
19 #define INCLUDED_SHADOWMAP
21 #include "graphics/ShaderProgramPtr.h"
22 #include "lib/ogl.h"
24 class CBoundingBoxAligned;
25 class CCamera;
26 class CFrustum;
27 class CVector3D;
29 struct ShadowMapInternals;
31 /**
32 * Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup,
33 * including matrix calculations.
35 * The class will automatically generate a texture the first time the shadow map is rendered into.
36 * The texture will not be resized afterwards.
38 class ShadowMap
40 public:
41 ShadowMap();
42 ~ShadowMap();
44 /**
45 * RecreateTexture: Destroy the current shadow texture and force creation of
46 * a new one. Useful when the renderer's size has changed and the texture
47 * should be resized too.
49 void RecreateTexture();
51 /**
52 * GetDepthTextureBits: Return the number of bits to use for depth textures when
53 * enabled.
55 * @return depth texture bit depth
57 int GetDepthTextureBits() const;
59 /**
60 * SetDepthTextureBits: Sets the number of bits to use for depth textures when enabled.
61 * Possible values are 16, 24, 32 and 0 (= use default)
63 * @param bits number of bits
65 void SetDepthTextureBits(int bits);
67 /**
68 * SetupFrame: Configure light space for the given camera and light direction,
69 * create the shadow texture if necessary, etc.
71 * @param camera the camera that will be used for world rendering
72 * @param lightdir the direction of the (directional) sunlight
74 void SetupFrame(const CCamera& camera, const CVector3D& lightdir);
76 /**
77 * Add the bounding box of an object that will cast a shadow.
78 * This is used to calculate the bounds for the shadow map.
80 * @param bounds world space bounding box
82 void AddShadowCasterBound(const int cascade, const CBoundingBoxAligned& bounds);
84 /**
85 * Add the bounding box of an object that will receive a shadow.
86 * This is used to calculate the bounds for the shadow map.
88 * @param bounds world space bounding box
90 void AddShadowReceiverBound(const CBoundingBoxAligned& bounds);
92 /**
93 * Compute the frustum originating at the light source, that encompasses
94 * all the objects passed into AddShadowReceiverBound so far.
96 * This frustum can be used to determine which objects might cast a visible
97 * shadow. Those objects should be passed to AddShadowCasterBound and
98 * then should be rendered into the shadow map.
100 CFrustum GetShadowCasterCullFrustum(const int cascade);
103 * BeginRender: Set OpenGL state for rendering into the shadow map texture.
105 * @todo this depends in non-obvious ways on the behaviour of the call-site
107 void BeginRender();
110 * EndRender: Finish rendering into the shadow map.
112 * @todo this depends in non-obvious ways on the behaviour of the call-site
114 void EndRender();
117 * Returns the current number of used cascades.
119 int GetCascadeCount() const;
122 * Sets the renderer camera for the cascade.
124 void PrepareCamera(const int cascade);
127 * Binds all needed resources and uniforms to draw shadows using the shader.
129 void BindTo(const CShaderProgramPtr& shader) const;
132 * Visualize shadow mapping calculations to help in
133 * debugging and optimal shadow map usage.
135 void RenderDebugBounds();
138 * Visualize shadow map texture to help in debugging.
140 void RenderDebugTexture();
142 private:
143 ShadowMapInternals* m;
146 #endif // INCLUDED_SHADOWMAP