File: WaterManager.h

package info (click to toggle)
0ad 0.0.23.1-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,412 kB
  • sloc: cpp: 245,162; ansic: 200,249; javascript: 19,244; python: 13,754; sh: 6,104; perl: 4,620; makefile: 977; xml: 810; java: 533; ruby: 229; erlang: 46; pascal: 30; sql: 21; tcl: 4
file content (202 lines) | stat: -rw-r--r-- 5,887 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* Copyright (C) 2017 Wildfire Games.
 * This file is part of 0 A.D.
 *
 * 0 A.D. is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * 0 A.D. is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * Water settings (speed, height) and texture management
 */

#ifndef INCLUDED_WATERMANAGER
#define INCLUDED_WATERMANAGER

#include "graphics/Texture.h"
#include "lib/ogl.h"
#include "maths/Matrix3D.h"
#include "maths/Vector2D.h"
#include "ps/Shapes.h"
#include "renderer/VertexBufferManager.h"

class CSimulation2;
class CFrustum;

struct CoastalPoint;
struct WaveObject;

/**
 * Class WaterManager: Maintain rendering-related water settings and textures
 * Anything that affects gameplay should go in CcmpWaterManager.cpp and passed to this (possibly as copy).
 */

class WaterManager
{
public:
	CTexturePtr m_WaterTexture[60];
	CTexturePtr m_NormalMap[60];

	float* m_WindStrength;	// How strong the waves are at point X. % of waviness.
	float* m_DistanceHeightmap; // How far from the shore a point is. Manhattan
	CVector3D* m_BlurredNormalMap;	// Cache a slightly blurred map of the normals of the terrain.

	// Waves vertex buffers
	std::vector< WaveObject* > m_ShoreWaves;	// TODO: once we get C++11, remove pointer
	// Waves indices buffer. Only one since All Wave Objects have the same.
	CVertexBuffer::VBChunk* m_ShoreWaves_VBIndices;

	size_t m_MapSize;
	ssize_t m_TexSize;

	CTexturePtr m_WaveTex;
	CTexturePtr m_FoamTex;

	GLuint m_depthTT;
	GLuint m_FancyTextureNormal;
	GLuint m_FancyTextureOther;
	GLuint m_FancyTextureDepth;
	GLuint m_ReflFboDepthTexture;
	GLuint m_RefrFboDepthTexture;

	// used to know what to update when updating parts of the terrain only.
	u32 m_updatei0;
	u32 m_updatej0;
	u32 m_updatei1;
	u32 m_updatej1;

	int m_WaterCurrentTex;
	bool m_RenderWater;

	// If disabled, force the use of the fixed function for rendering.
	bool m_WaterEffects;
	// Those variables register the current quality level. If there is a change, I have to recompile the shader.
	// Use real depth or use the fake precomputed one.
	bool m_WaterRealDepth;
	// Use fancy shore effects and show trails behind ships
	bool m_WaterFancyEffects;
	// Use refractions instead of simply making the water more or less transparent.
	bool m_WaterRefraction;
	// Use complete reflections instead of showing merely the sky.
	bool m_WaterReflection;
	// Show shadows on the water.
	bool m_WaterShadows;

	bool m_NeedsReloading;
	// requires also recreating the super fancy information.
	bool m_NeedInfoUpdate;

	float m_WaterHeight;

	double m_WaterTexTimer;
	float m_RepeatPeriod;

	// Reflection and refraction textures for fancy water
	GLuint m_ReflectionTexture;
	GLuint m_RefractionTexture;
	size_t m_RefTextureSize;

	// framebuffer objects
	GLuint m_RefractionFbo;
	GLuint m_ReflectionFbo;
	GLuint m_FancyEffectsFBO;

	// Model-view-projection matrices for reflected & refracted cameras
	// (used to let the vertex shader do projective texturing)
	CMatrix3D m_ReflectionMatrix;
	CMatrix3D m_RefractionMatrix;

	// Water parameters
	std::wstring m_WaterType;		// Which texture to use.
	CColor m_WaterColor;	// Color of the water without refractions. This is what you're seeing when the water's deep or murkiness high.
	CColor m_WaterTint;		// Tint of refraction in the water.
	float m_Waviness;		// How big the waves are.
	float m_Murkiness;		// How murky the water is.
	float m_WindAngle;	// In which direction the water waves go.

public:
	WaterManager();
	~WaterManager();

	/**
	 * LoadWaterTextures: Load water textures from within the
	 * progressive load framework.
	 *
	 * @return 0 if loading has completed, a value from 1 to 100 (in percent of completion)
	 * if more textures need to be loaded and a negative error value on failure.
	 */
	int LoadWaterTextures();

	/**
	 * Resize: Updates the fancy water textures so that water will render correctly
	 * with fancy water.
	 */
	void Resize();

	/**
	 * ReloadWaterNormalTextures: Reload the normal textures so that changing
	 * water type in Atlas will actually do the right thing.
	 */
	void ReloadWaterNormalTextures();

	/**
	 * UnloadWaterTextures: Free any loaded water textures and reset the internal state
	 * so that another call to LoadWaterTextures will begin progressive loading.
	 */
	void UnloadWaterTextures();

	/**
	 * RecomputeWaterData: calculates all derived data from the waterheight
	 */
	void RecomputeWaterData();

	/**
	 * RecomputeWindStrength: calculates the intensity of waves
	 */
	void RecomputeWindStrength();

	/**
	 * RecomputeDistanceHeightmap: recalculates (or calculates) the distance heightmap.
	 */
	void RecomputeDistanceHeightmap();

	/**
	 * RecomputeBlurredNormalMap: calculates the blurred normal map of the terrain. Slow.
	 */
	void RecomputeBlurredNormalMap();

	/**
	 * CreateWaveMeshes: Creates the waves objects (and meshes).
	 */
	void CreateWaveMeshes();

	/**
	 * Updates the map size. Will trigger a complete recalculation of fancy water information the next turn.
	 */
	void SetMapSize(size_t size);

	/**
	 * Updates the settings to the one from the renderer, and sets m_NeedsReloading.
	 */
	void UpdateQuality();

	/**
	 * Returns true if fancy water shaders will be used (i.e. the hardware is capable
	 * and it hasn't been configured off)
	 */
	bool WillRenderFancyWater();

	void RenderWaves(const CFrustum& frustrum);
};


#endif // INCLUDED_WATERMANAGER