Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 "ps/Overlay.h"
30 
31 class CSimulation2;
32 
33 struct SWavesVertex {
34  // vertex position
36  u8 m_UV[2];
37 };
38 cassert(sizeof(SWavesVertex) == 16);
39 
40 
41 
42 /**
43  * Class WaterManager: Maintain water settings and textures.
44  *
45  * This could be extended to provide more advanced water rendering effects
46  * (refractive/reflective water) in the future.
47  */
48 
50 {
51 public:
56  float* m_WaveX;
57  float* m_WaveZ;
59  float* m_FoamFactor;
60 
61  size_t m_MapSize;
63 
64  GLuint m_depthTT;
65  GLuint m_waveTT;
66 
67  // used to know what to update when updating parts of the terrain only.
72 
76 
77  // Those variables register the current quality level. If there is a change, I have to recompile the shader.
85 
87  // requires also recreating the super fancy information.
89 
95 
103 
104  // Reflection and refraction textures for fancy water
109 
110  // Model-view-projection matrices for reflected & refracted cameras
111  // (used to let the vertex shader do projective texturing)
114 
115  // Shader parameters for fancy water
118  float m_Shininess;
120  float m_Waviness;
121  float m_Murkiness;
124 
125  // Waves
126  // see the struct above.
129 
130 public:
131  WaterManager();
132  ~WaterManager();
133 
134  /**
135  * LoadWaterTextures: Load water textures from within the
136  * progressive load framework.
137  *
138  * @return 0 if loading has completed, a value from 1 to 100 (in percent of completion)
139  * if more textures need to be loaded and a negative error value on failure.
140  */
141  int LoadWaterTextures();
142 
143  /**
144  * UnloadWaterTextures: Free any loaded water textures and reset the internal state
145  * so that another call to LoadWaterTextures will begin progressive loading.
146  */
147  void UnloadWaterTextures();
148 
149  /**
150  * CreateSuperfancyInfo: creates textures and wave vertices for superfancy water
151  */
152  void CreateSuperfancyInfo(CSimulation2* simulation);
153 
154  /**
155  * Updates the map size. Will trigger a complete recalculation of fancy water information the next turn.
156  */
157  void SetMapSize(size_t size);
158 
159  /**
160  * Updates the settings to the one from the renderer, and sets m_NeedsReloading.
161  */
162  void UpdateQuality();
163 
164  /**
165  * Returns true if fancy water shaders will be used (i.e. the hardware is capable
166  * and it hasn't been configured off)
167  */
168  bool WillRenderFancyWater();
169 };
170 
171 
172 #endif // INCLUDED_WATERMANAGER
CTexturePtr m_WaterTexture[60]
Definition: WaterManager.h:52
bool m_WaterScroll
Definition: WaterManager.h:90
#define u8
Definition: types.h:39
bool m_NeedInfoUpdate
Definition: WaterManager.h:88
float m_RepeatPeriod
Definition: WaterManager.h:117
float m_Shininess
Definition: WaterManager.h:118
float m_WaterMaxAlpha
Definition: WaterManager.h:92
float m_SWaterTrans
Definition: WaterManager.h:98
GLuint m_depthTT
Definition: WaterManager.h:64
Definition: Overlay.h:34
#define i32
Definition: types.h:36
bool m_WaterRealDepth
Definition: WaterManager.h:79
size_t m_RefractionTextureSize
Definition: WaterManager.h:108
CVertexBuffer::VBChunk * m_VBWaves
Definition: WaterManager.h:127
float m_Waviness
Definition: WaterManager.h:120
bool m_WaterShadows
Definition: WaterManager.h:84
bool m_WaterNormal
Definition: WaterManager.h:78
size_t m_ReflectionTextureSize
Definition: WaterManager.h:107
CTexturePtr m_NormalMap[60]
Definition: WaterManager.h:53
GLuint m_RefractionTexture
Definition: WaterManager.h:106
int m_WaterCurrentTex
Definition: WaterManager.h:73
float m_TWaterScrollCounter
Definition: WaterManager.h:101
float m_TWaterTrans
Definition: WaterManager.h:99
VBChunk: describes a portion of this vertex buffer.
Definition: VertexBuffer.h:47
float m_WaterHeight
Definition: WaterManager.h:91
float m_TWaterSpeed
Definition: WaterManager.h:97
bool m_WaterFoam
Definition: WaterManager.h:80
float * m_WaveX
Definition: WaterManager.h:56
CMatrix3D m_ReflectionMatrix
Definition: WaterManager.h:112
Public API for simulation system.
Definition: Simulation2.h:46
CTexturePtr m_Foam
Definition: WaterManager.h:54
void SetMapSize(size_t size)
Updates the map size.
float * m_FoamFactor
Definition: WaterManager.h:59
float m_WaterAlphaOffset
Definition: WaterManager.h:94
bool m_NeedsReloading
Definition: WaterManager.h:86
float m_Murkiness
Definition: WaterManager.h:121
void UpdateQuality()
Updates the settings to the one from the renderer, and sets m_NeedsReloading.
bool m_RenderWater
Definition: WaterManager.h:75
GLuint m_waveTT
Definition: WaterManager.h:65
CMatrix3D m_RefractionMatrix
Definition: WaterManager.h:113
CColor m_WaterTint
Definition: WaterManager.h:116
int LoadWaterTextures()
LoadWaterTextures: Load water textures from within the progressive load framework.
float m_SWaterScrollCounter
Definition: WaterManager.h:100
bool m_WaterRefraction
Definition: WaterManager.h:82
void UnloadWaterTextures()
UnloadWaterTextures: Free any loaded water textures and reset the internal state so that another call...
float m_SpecularStrength
Definition: WaterManager.h:119
intptr_t ssize_t
Definition: wposix_types.h:82
void CreateSuperfancyInfo(CSimulation2 *simulation)
CreateSuperfancyInfo: creates textures and wave vertices for superfancy water.
bool WillRenderFancyWater()
Returns true if fancy water shaders will be used (i.e.
float * m_WaveZ
Definition: WaterManager.h:57
float m_ReflectionTintStrength
Definition: WaterManager.h:123
GLuint m_ReflectionTexture
Definition: WaterManager.h:105
CVertexBuffer::VBChunk * m_VBWavesIndices
Definition: WaterManager.h:128
CTexturePtr m_Wave
Definition: WaterManager.h:55
bool m_WaterReflection
Definition: WaterManager.h:83
CColor m_WaterColor
Definition: WaterManager.h:74
float m_SWaterSpeed
Definition: WaterManager.h:96
double m_WaterTexTimer
Definition: WaterManager.h:102
#define cassert(expr)
Compile-time assertion.
float m_WaterFullDepth
Definition: WaterManager.h:93
float * m_DistanceToShore
Definition: WaterManager.h:58
size_t m_MapSize
Definition: WaterManager.h:61
ssize_t m_TexSize
Definition: WaterManager.h:62
CVector3D m_Position
Definition: WaterManager.h:35
bool m_WaterCoastalWaves
Definition: WaterManager.h:81
Class WaterManager: Maintain water settings and textures.
Definition: WaterManager.h:49
shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22
CColor m_ReflectionTint
Definition: WaterManager.h:122