2012-11-26 03:28:35 +01:00
|
|
|
/* Copyright (C) 2012 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Water settings (speed, height) and texture management
|
2006-01-07 02:04:26 +01:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_WATERMANAGER
|
|
|
|
#define INCLUDED_WATERMANAGER
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
#include "graphics/Texture.h"
|
2006-06-11 09:03:59 +02:00
|
|
|
#include "lib/ogl.h"
|
2012-11-26 03:28:35 +01:00
|
|
|
#include "maths/Matrix3D.h"
|
2014-07-03 22:07:15 +02:00
|
|
|
#include "maths/Vector2D.h"
|
2015-03-15 19:06:32 +01:00
|
|
|
#include "ps/Shapes.h"
|
2012-11-26 03:28:35 +01:00
|
|
|
#include "renderer/VertexBufferManager.h"
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2013-04-27 14:20:42 +02:00
|
|
|
class CSimulation2;
|
2014-07-28 12:14:00 +02:00
|
|
|
class CFrustum;
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2014-07-28 12:14:00 +02:00
|
|
|
struct CoastalPoint;
|
|
|
|
struct WaveObject;
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
/**
|
2014-07-03 22:07:15 +02:00
|
|
|
* 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).
|
2006-01-07 02:04:26 +01:00
|
|
|
*/
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
class WaterManager
|
|
|
|
{
|
|
|
|
public:
|
2010-09-10 23:02:10 +02:00
|
|
|
CTexturePtr m_WaterTexture[60];
|
|
|
|
CTexturePtr m_NormalMap[60];
|
2014-07-03 22:07:15 +02:00
|
|
|
|
|
|
|
float* m_WindStrength; // How strong the waves are at point X. % of waviness.
|
2014-07-28 12:14:00 +02:00
|
|
|
float* m_DistanceHeightmap; // How far from the shore a point is. Manhattan
|
2014-07-03 22:07:15 +02:00
|
|
|
CVector3D* m_BlurredNormalMap; // Cache a slightly blurred map of the normals of the terrain.
|
2014-07-01 18:05:05 +02:00
|
|
|
|
2014-07-28 12:14:00 +02:00
|
|
|
// 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;
|
|
|
|
|
2013-08-18 11:27:11 +02:00
|
|
|
size_t m_MapSize;
|
2012-10-31 19:42:17 +01:00
|
|
|
ssize_t m_TexSize;
|
|
|
|
|
2014-07-28 12:14:00 +02:00
|
|
|
CTexturePtr m_WaveTex;
|
|
|
|
CTexturePtr m_FoamTex;
|
|
|
|
|
2012-10-31 19:42:17 +01:00
|
|
|
GLuint m_depthTT;
|
2014-07-28 12:14:00 +02:00
|
|
|
GLuint m_FancyTextureNormal;
|
|
|
|
GLuint m_FancyTextureOther;
|
|
|
|
GLuint m_FancyTextureDepth;
|
2014-07-04 12:14:35 +02:00
|
|
|
GLuint m_ReflFboDepthTexture;
|
|
|
|
GLuint m_RefrFboDepthTexture;
|
2006-05-28 04:13:32 +02:00
|
|
|
|
2013-08-18 11:27:11 +02:00
|
|
|
// used to know what to update when updating parts of the terrain only.
|
2014-02-25 07:27:15 +01:00
|
|
|
u32 m_updatei0;
|
|
|
|
u32 m_updatej0;
|
|
|
|
u32 m_updatei1;
|
|
|
|
u32 m_updatej1;
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
int m_WaterCurrentTex;
|
|
|
|
bool m_RenderWater;
|
2012-11-04 16:54:36 +01:00
|
|
|
|
2014-07-01 18:05:05 +02:00
|
|
|
// Force the use of the fixed function for rendering.
|
|
|
|
bool m_WaterUgly;
|
2012-11-04 16:54:36 +01:00
|
|
|
// Those variables register the current quality level. If there is a change, I have to recompile the shader.
|
2014-07-01 18:05:05 +02:00
|
|
|
// Use real depth or use the fake precomputed one.
|
2012-11-04 16:54:36 +01:00
|
|
|
bool m_WaterRealDepth;
|
2014-07-01 18:05:05 +02:00
|
|
|
// Use fancy shore effects and show trails behind ships
|
|
|
|
bool m_WaterFancyEffects;
|
|
|
|
// Use refractions instead of simply making the water more or less transparent.
|
2012-11-04 16:54:36 +01:00
|
|
|
bool m_WaterRefraction;
|
2014-07-01 18:05:05 +02:00
|
|
|
// Use complete reflections instead of showing merely the sky.
|
2012-11-04 16:54:36 +01:00
|
|
|
bool m_WaterReflection;
|
2014-07-01 18:05:05 +02:00
|
|
|
// Show shadows on the water.
|
2012-11-04 16:54:36 +01:00
|
|
|
bool m_WaterShadows;
|
|
|
|
|
2012-10-31 19:42:17 +01:00
|
|
|
bool m_NeedsReloading;
|
2012-11-04 16:54:36 +01:00
|
|
|
// requires also recreating the super fancy information.
|
2013-08-18 11:27:11 +02:00
|
|
|
bool m_NeedInfoUpdate;
|
2012-11-04 16:54:36 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
float m_WaterHeight;
|
2014-07-03 22:07:15 +02:00
|
|
|
|
2006-03-14 22:29:19 +01:00
|
|
|
double m_WaterTexTimer;
|
2014-07-03 22:07:15 +02:00
|
|
|
float m_RepeatPeriod;
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-05-28 23:58:56 +02:00
|
|
|
// Reflection and refraction textures for fancy water
|
|
|
|
GLuint m_ReflectionTexture;
|
|
|
|
GLuint m_RefractionTexture;
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t m_ReflectionTextureSize;
|
|
|
|
size_t m_RefractionTextureSize;
|
2006-05-28 23:58:56 +02:00
|
|
|
|
2014-07-03 22:07:15 +02:00
|
|
|
// framebuffer objects
|
|
|
|
GLuint m_RefractionFbo;
|
|
|
|
GLuint m_ReflectionFbo;
|
2014-07-28 12:14:00 +02:00
|
|
|
GLuint m_FancyEffectsFBO;
|
2014-07-03 22:07:15 +02:00
|
|
|
|
2006-05-28 23:58:56 +02:00
|
|
|
// Model-view-projection matrices for reflected & refracted cameras
|
|
|
|
// (used to let the vertex shader do projective texturing)
|
|
|
|
CMatrix3D m_ReflectionMatrix;
|
|
|
|
CMatrix3D m_RefractionMatrix;
|
|
|
|
|
2014-07-03 22:07:15 +02:00
|
|
|
// 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.
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
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();
|
2015-02-10 20:41:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize: Updates the fancy water textures so that water will render correctly
|
|
|
|
* with fancy water.
|
|
|
|
*/
|
|
|
|
void Resize();
|
|
|
|
|
2015-02-28 14:50:52 +01:00
|
|
|
/**
|
|
|
|
* ReloadWaterNormalTextures: Reload the normal textures so that changing
|
|
|
|
* water type in Atlas will actually do the right thing.
|
|
|
|
*/
|
|
|
|
void ReloadWaterNormalTextures();
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
/**
|
|
|
|
* UnloadWaterTextures: Free any loaded water textures and reset the internal state
|
|
|
|
* so that another call to LoadWaterTextures will begin progressive loading.
|
|
|
|
*/
|
|
|
|
void UnloadWaterTextures();
|
|
|
|
|
2014-07-03 22:07:15 +02:00
|
|
|
/**
|
|
|
|
* RecomputeWindStrength: calculates the intensity of waves
|
|
|
|
*/
|
|
|
|
void RecomputeWindStrength();
|
|
|
|
|
2014-07-01 18:05:05 +02:00
|
|
|
/**
|
|
|
|
* RecomputeDistanceHeightmap: recalculates (or calculates) the distance heightmap.
|
|
|
|
*/
|
|
|
|
void RecomputeDistanceHeightmap();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RecomputeBlurredNormalMap: calculates the blurred normal map of the terrain. Slow.
|
|
|
|
*/
|
|
|
|
void RecomputeBlurredNormalMap();
|
|
|
|
|
2012-10-31 19:42:17 +01:00
|
|
|
/**
|
2014-07-28 12:14:00 +02:00
|
|
|
* CreateWaveMeshes: Creates the waves objects (and meshes).
|
2012-10-31 19:42:17 +01:00
|
|
|
*/
|
2014-07-28 12:14:00 +02:00
|
|
|
void CreateWaveMeshes();
|
2012-10-31 19:42:17 +01:00
|
|
|
|
2013-08-18 11:27:11 +02:00
|
|
|
/**
|
|
|
|
* Updates the map size. Will trigger a complete recalculation of fancy water information the next turn.
|
|
|
|
*/
|
|
|
|
void SetMapSize(size_t size);
|
|
|
|
|
2010-03-21 15:18:15 +01:00
|
|
|
/**
|
2012-11-04 16:54:36 +01:00
|
|
|
* Updates the settings to the one from the renderer, and sets m_NeedsReloading.
|
2010-03-21 15:18:15 +01:00
|
|
|
*/
|
2013-08-18 11:27:11 +02:00
|
|
|
void UpdateQuality();
|
2012-10-31 19:42:17 +01:00
|
|
|
|
|
|
|
/**
|
2012-11-04 16:54:36 +01:00
|
|
|
* Returns true if fancy water shaders will be used (i.e. the hardware is capable
|
2012-10-31 19:42:17 +01:00
|
|
|
* and it hasn't been configured off)
|
|
|
|
*/
|
2012-11-04 16:54:36 +01:00
|
|
|
bool WillRenderFancyWater();
|
2014-07-28 12:14:00 +02:00
|
|
|
|
|
|
|
void RenderWaves(const CFrustum& frustrum);
|
2006-01-07 02:04:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_WATERMANAGER
|