Pyrogenesis  trunk
WaterManager.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  * Water settings (speed, height) and texture management
20  */
21 
22 #ifndef INCLUDED_WATERMANAGER
23 #define INCLUDED_WATERMANAGER
24 
25 #include "graphics/Texture.h"
26 #include "lib/ogl.h"
27 #include "maths/Matrix3D.h"
28 #include "maths/Vector2D.h"
29 #include "ps/Shapes.h"
31 
32 class CSimulation2;
33 class CFrustum;
34 
35 struct CoastalPoint;
36 struct WaveObject;
37 
38 /**
39  * Class WaterManager: Maintain rendering-related water settings and textures
40  * Anything that affects gameplay should go in CcmpWaterManager.cpp and passed to this (possibly as copy).
41  */
42 
44 {
45 public:
48 
49  float* m_WindStrength; // How strong the waves are at point X. % of waviness.
50  float* m_DistanceHeightmap; // How far from the shore a point is. Manhattan
51  CVector3D* m_BlurredNormalMap; // Cache a slightly blurred map of the normals of the terrain.
52 
53  // Waves vertex buffers
54  std::vector< WaveObject* > m_ShoreWaves; // TODO: once we get C++11, remove pointer
55  // Waves indices buffer. Only one since All Wave Objects have the same.
57 
58  size_t m_MapSize;
60 
63 
64  GLuint m_depthTT;
70 
71  // used to know what to update when updating parts of the terrain only.
76 
79 
80  // Force the use of the fixed function for rendering.
82  // Those variables register the current quality level. If there is a change, I have to recompile the shader.
83  // Use real depth or use the fake precomputed one.
85  // Use fancy shore effects and show trails behind ships
87  // Use refractions instead of simply making the water more or less transparent.
89  // Use complete reflections instead of showing merely the sky.
91  // Show shadows on the water.
93 
95  // requires also recreating the super fancy information.
97 
99 
102 
103  // Reflection and refraction textures for fancy water
107 
108  // framebuffer objects
112 
113  // Model-view-projection matrices for reflected & refracted cameras
114  // (used to let the vertex shader do projective texturing)
117 
118  // Water parameters
119  std::wstring m_WaterType; // Which texture to use.
120  CColor m_WaterColor; // Color of the water without refractions. This is what you're seeing when the water's deep or murkiness high.
121  CColor m_WaterTint; // Tint of refraction in the water.
122  float m_Waviness; // How big the waves are.
123  float m_Murkiness; // How murky the water is.
124  float m_WindAngle; // In which direction the water waves go.
125 
126 public:
127  WaterManager();
128  ~WaterManager();
129 
130  /**
131  * LoadWaterTextures: Load water textures from within the
132  * progressive load framework.
133  *
134  * @return 0 if loading has completed, a value from 1 to 100 (in percent of completion)
135  * if more textures need to be loaded and a negative error value on failure.
136  */
137  int LoadWaterTextures();
138 
139  /**
140  * Resize: Updates the fancy water textures so that water will render correctly
141  * with fancy water.
142  */
143  void Resize();
144 
145  /**
146  * ReloadWaterNormalTextures: Reload the normal textures so that changing
147  * water type in Atlas will actually do the right thing.
148  */
150 
151  /**
152  * UnloadWaterTextures: Free any loaded water textures and reset the internal state
153  * so that another call to LoadWaterTextures will begin progressive loading.
154  */
155  void UnloadWaterTextures();
156 
157  /**
158  * RecomputeWindStrength: calculates the intensity of waves
159  */
160  void RecomputeWindStrength();
161 
162  /**
163  * RecomputeDistanceHeightmap: recalculates (or calculates) the distance heightmap.
164  */
166 
167  /**
168  * RecomputeBlurredNormalMap: calculates the blurred normal map of the terrain. Slow.
169  */
171 
172  /**
173  * CreateWaveMeshes: Creates the waves objects (and meshes).
174  */
175  void CreateWaveMeshes();
176 
177  /**
178  * Updates the map size. Will trigger a complete recalculation of fancy water information the next turn.
179  */
180  void SetMapSize(size_t size);
181 
182  /**
183  * Updates the settings to the one from the renderer, and sets m_NeedsReloading.
184  */
185  void UpdateQuality();
186 
187  /**
188  * Returns true if fancy water shaders will be used (i.e. the hardware is capable
189  * and it hasn't been configured off)
190  */
191  bool WillRenderFancyWater();
192 
193  void RenderWaves(const CFrustum& frustrum);
194 };
195 
196 
197 #endif // INCLUDED_WATERMANAGER
CTexturePtr m_WaterTexture[60]
Definition: WaterManager.h:46
void Resize()
Resize: Updates the fancy water textures so that water will render correctly with fancy water...
Definition: WaterManager.cpp:365
bool m_WaterFancyEffects
Definition: WaterManager.h:86
GLuint m_ReflFboDepthTexture
Definition: WaterManager.h:68
bool m_NeedInfoUpdate
Definition: WaterManager.h:96
u32 m_updatei1
Definition: WaterManager.h:74
float m_RepeatPeriod
Definition: WaterManager.h:101
GLuint m_FancyTextureOther
Definition: WaterManager.h:66
GLuint m_RefrFboDepthTexture
Definition: WaterManager.h:69
CTexturePtr m_FoamTex
Definition: WaterManager.h:62
void RecomputeBlurredNormalMap()
RecomputeBlurredNormalMap: calculates the blurred normal map of the terrain.
Definition: WaterManager.cpp:945
GLuint m_depthTT
Definition: WaterManager.h:64
Definition: Shapes.h:36
float * m_DistanceHeightmap
Definition: WaterManager.h:50
void ReloadWaterNormalTextures()
ReloadWaterNormalTextures: Reload the normal textures so that changing water type in Atlas will actua...
Definition: WaterManager.cpp:380
bool m_WaterRealDepth
Definition: WaterManager.h:84
u32 m_updatei0
Definition: WaterManager.h:72
float m_Waviness
Definition: WaterManager.h:122
bool m_WaterShadows
Definition: WaterManager.h:92
Definition: Vector3D.h:28
Definition: Frustum.h:39
CTexturePtr m_NormalMap[60]
Definition: WaterManager.h:47
GLuint m_RefractionTexture
Definition: WaterManager.h:105
int m_WaterCurrentTex
Definition: WaterManager.h:77
~WaterManager()
Definition: WaterManager.cpp:141
VBChunk: describes a portion of this vertex buffer.
Definition: VertexBuffer.h:62
GLuint m_FancyTextureNormal
Definition: WaterManager.h:65
float m_WaterHeight
Definition: WaterManager.h:98
CMatrix3D m_ReflectionMatrix
Definition: WaterManager.h:115
Public API for simulation system.
Definition: Simulation2.h:47
void SetMapSize(size_t size)
Updates the map size.
Definition: WaterManager.cpp:1084
Definition: WaterManager.cpp:52
Definition: Matrix3D.h:33
u32 m_updatej1
Definition: WaterManager.h:75
bool m_NeedsReloading
Definition: WaterManager.h:94
float m_Murkiness
Definition: WaterManager.h:123
std::wstring m_WaterType
Definition: WaterManager.h:119
void UpdateQuality()
Updates the settings to the one from the renderer, and sets m_NeedsReloading.
Definition: WaterManager.cpp:1101
uint32_t u32
Definition: types.h:39
bool m_RenderWater
Definition: WaterManager.h:78
void RenderWaves(const CFrustum &frustrum)
Definition: WaterManager.cpp:868
CMatrix3D m_RefractionMatrix
Definition: WaterManager.h:116
CColor m_WaterTint
Definition: WaterManager.h:121
CTexturePtr m_WaveTex
Definition: WaterManager.h:61
int LoadWaterTextures()
LoadWaterTextures: Load water textures from within the progressive load framework.
Definition: WaterManager.cpp:178
float * m_WindStrength
Definition: WaterManager.h:49
size_t m_RefTextureSize
Definition: WaterManager.h:106
bool m_WaterUgly
Definition: WaterManager.h:81
bool m_WaterRefraction
Definition: WaterManager.h:88
GLuint m_FancyEffectsFBO
Definition: WaterManager.h:111
CVertexBuffer::VBChunk * m_ShoreWaves_VBIndices
Definition: WaterManager.h:56
WaterManager()
Definition: WaterManager.cpp:84
void UnloadWaterTextures()
UnloadWaterTextures: Free any loaded water textures and reset the internal state so that another call...
Definition: WaterManager.cpp:399
GLuint m_ReflectionFbo
Definition: WaterManager.h:110
intptr_t ssize_t
Definition: wposix_types.h:82
void CreateWaveMeshes()
CreateWaveMeshes: Creates the waves objects (and meshes).
Definition: WaterManager.cpp:482
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22
bool WillRenderFancyWater()
Returns true if fancy water shaders will be used (i.e.
Definition: WaterManager.cpp:1129
GLuint m_ReflectionTexture
Definition: WaterManager.h:104
GLuint m_RefractionFbo
Definition: WaterManager.h:109
CVector3D * m_BlurredNormalMap
Definition: WaterManager.h:51
GLuint m_FancyTextureDepth
Definition: WaterManager.h:67
bool m_WaterReflection
Definition: WaterManager.h:90
CColor m_WaterColor
Definition: WaterManager.h:120
double m_WaterTexTimer
Definition: WaterManager.h:100
void RecomputeWindStrength()
RecomputeWindStrength: calculates the intensity of waves.
Definition: WaterManager.cpp:1003
std::vector< WaveObject * > m_ShoreWaves
Definition: WaterManager.h:54
void RecomputeDistanceHeightmap()
RecomputeDistanceHeightmap: recalculates (or calculates) the distance heightmap.
Definition: WaterManager.cpp:418
size_t m_MapSize
Definition: WaterManager.h:58
float m_WindAngle
Definition: WaterManager.h:124
u32 m_updatej0
Definition: WaterManager.h:73
ssize_t m_TexSize
Definition: WaterManager.h:59
Definition: WaterManager.cpp:74
Class WaterManager: Maintain rendering-related water settings and textures Anything that affects game...
Definition: WaterManager.h:43