2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 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/>.
|
|
|
|
*/
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : TerrainRenderer.cpp
|
|
|
|
* Project : Pyrogenesis
|
|
|
|
* Description : Terrain rendering (everything related to patches and
|
|
|
|
* : water) is encapsulated in TerrainRenderer
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "graphics/Camera.h"
|
2006-02-13 15:18:20 +01:00
|
|
|
#include "graphics/LightEnv.h"
|
2006-01-07 02:04:26 +01:00
|
|
|
#include "graphics/Patch.h"
|
|
|
|
#include "graphics/Terrain.h"
|
2006-03-21 21:55:45 +01:00
|
|
|
#include "graphics/GameView.h"
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
#include "maths/MathUtil.h"
|
|
|
|
|
2009-03-24 22:00:41 +01:00
|
|
|
#include "ps/CLogger.h"
|
2006-01-07 02:04:26 +01:00
|
|
|
#include "ps/Game.h"
|
|
|
|
#include "ps/Profile.h"
|
2006-06-02 05:56:24 +02:00
|
|
|
#include "ps/Pyrogenesis.h" // MICROLOG
|
2007-01-13 23:44:42 +01:00
|
|
|
#include "ps/World.h"
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
#include "simulation/LOSManager.h"
|
|
|
|
|
|
|
|
#include "renderer/PatchRData.h"
|
|
|
|
#include "renderer/Renderer.h"
|
2006-02-11 19:04:32 +01:00
|
|
|
#include "renderer/ShadowMap.h"
|
2006-01-07 02:04:26 +01:00
|
|
|
#include "renderer/TerrainRenderer.h"
|
|
|
|
#include "renderer/WaterManager.h"
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
#include "lib/res/graphics/ogl_shader.h"
|
|
|
|
|
2009-03-24 22:00:41 +01:00
|
|
|
#define LOG_CATEGORY "graphics"
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// TerrainRenderer implementation
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TerrainRenderer keeps track of which phase it is in, to detect
|
|
|
|
* when Submit, PrepareForRendering etc. are called in the wrong order.
|
|
|
|
*/
|
|
|
|
enum Phase {
|
|
|
|
Phase_Submit,
|
|
|
|
Phase_Render
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Struct TerrainRendererInternals: Internal variables used by the TerrainRenderer class.
|
|
|
|
*/
|
|
|
|
struct TerrainRendererInternals
|
|
|
|
{
|
|
|
|
/// Which phase (submitting or rendering patches) are we in right now?
|
|
|
|
Phase phase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* VisiblePatches: Patches that were submitted for this frame
|
|
|
|
*
|
|
|
|
* @todo Merge this list with CPatchRData list
|
|
|
|
*/
|
|
|
|
std::vector<CPatch*> visiblePatches;
|
2006-05-25 07:46:17 +02:00
|
|
|
|
|
|
|
/// Fancy water shader
|
|
|
|
Handle fancyWaterShader;
|
2006-01-07 02:04:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Construction/Destruction
|
|
|
|
TerrainRenderer::TerrainRenderer()
|
|
|
|
{
|
|
|
|
m = new TerrainRendererInternals();
|
|
|
|
m->phase = Phase_Submit;
|
2006-05-25 07:46:17 +02:00
|
|
|
m->fancyWaterShader = 0;
|
2006-01-07 02:04:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TerrainRenderer::~TerrainRenderer()
|
|
|
|
{
|
2006-05-25 07:46:17 +02:00
|
|
|
if( m->fancyWaterShader )
|
|
|
|
{
|
|
|
|
ogl_program_free( m->fancyWaterShader );
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
delete m;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Submit a patch for rendering
|
|
|
|
void TerrainRenderer::Submit(CPatch* patch)
|
|
|
|
{
|
|
|
|
debug_assert(m->phase == Phase_Submit);
|
|
|
|
|
|
|
|
CPatchRData* data=(CPatchRData*) patch->GetRenderData();
|
|
|
|
if (data == 0)
|
|
|
|
{
|
|
|
|
// no renderdata for patch, create it now
|
|
|
|
data = new CPatchRData(patch);
|
|
|
|
patch->SetRenderData(data);
|
|
|
|
}
|
|
|
|
data->Update();
|
|
|
|
|
|
|
|
m->visiblePatches.push_back(patch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Prepare for rendering
|
|
|
|
void TerrainRenderer::PrepareForRendering()
|
|
|
|
{
|
|
|
|
debug_assert(m->phase == Phase_Submit);
|
|
|
|
|
|
|
|
m->phase = Phase_Render;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Clear submissions lists
|
|
|
|
void TerrainRenderer::EndFrame()
|
|
|
|
{
|
|
|
|
debug_assert(m->phase == Phase_Render);
|
|
|
|
|
|
|
|
m->visiblePatches.clear();
|
|
|
|
|
|
|
|
m->phase = Phase_Submit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Query if patches have been submitted this frame
|
|
|
|
bool TerrainRenderer::HaveSubmissions()
|
|
|
|
{
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
return !m->visiblePatches.empty();
|
2006-01-07 02:04:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Full-featured terrain rendering with blending and everything
|
2006-02-13 15:18:20 +01:00
|
|
|
void TerrainRenderer::RenderTerrain(ShadowMap* shadow)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
debug_assert(m->phase == Phase_Render);
|
|
|
|
|
|
|
|
// switch on required client states
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-13 15:18:20 +01:00
|
|
|
// render everything fullbright
|
2006-01-07 02:04:26 +01:00
|
|
|
// set up texture environment for base pass
|
|
|
|
MICROLOG(L"base splat textures");
|
|
|
|
pglActiveTextureARB(GL_TEXTURE0);
|
|
|
|
pglClientActiveTextureARB(GL_TEXTURE0);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
|
|
|
|
// Set alpha to 1.0
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_CONSTANT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
2006-02-15 01:45:16 +01:00
|
|
|
static const float one[4] = { 1.f, 1.f, 1.f, 1.f };
|
2006-01-07 02:04:26 +01:00
|
|
|
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, one);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
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
|
|
|
for(size_t i = 0; i < m->visiblePatches.size(); ++i)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
CPatchRData* patchdata = (CPatchRData*)m->visiblePatches[i]->GetRenderData();
|
2006-02-13 15:18:20 +01:00
|
|
|
patchdata->RenderBase(true); // with LOS color
|
2006-01-07 02:04:26 +01:00
|
|
|
}
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
// render blends
|
|
|
|
// switch on the composite alpha map texture
|
|
|
|
(void)ogl_tex_bind(g_Renderer.m_hCompositeAlphaMap, 1);
|
|
|
|
|
|
|
|
// switch on second uv set
|
|
|
|
pglClientActiveTextureARB(GL_TEXTURE1);
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
// setup additional texenv required by blend pass
|
|
|
|
pglActiveTextureARB(GL_TEXTURE1);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
// switch on blending
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
|
|
|
|
// no need to write to the depth buffer a second time
|
|
|
|
glDepthMask(0);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
// render blend passes for each patch
|
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
|
|
|
for(size_t i = 0; i < m->visiblePatches.size(); ++i)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
CPatchRData* patchdata = (CPatchRData*)m->visiblePatches[i]->GetRenderData();
|
|
|
|
patchdata->RenderBlends();
|
|
|
|
}
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-13 15:18:20 +01:00
|
|
|
// Disable second texcoord array
|
2006-01-07 02:04:26 +01:00
|
|
|
pglClientActiveTextureARB(GL_TEXTURE1);
|
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2006-02-13 15:18:20 +01:00
|
|
|
|
|
|
|
// Now apply lighting
|
|
|
|
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
|
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
2006-09-28 22:41:12 +02:00
|
|
|
|
|
|
|
// GL_TEXTURE_ENV_COLOR requires four floats, so we shouldn't use the RGBColor directly
|
|
|
|
float terrainAmbientColor[4] = {
|
|
|
|
lightEnv.m_TerrainAmbientColor.X,
|
|
|
|
lightEnv.m_TerrainAmbientColor.Y,
|
|
|
|
lightEnv.m_TerrainAmbientColor.Z,
|
|
|
|
1.f
|
|
|
|
};
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
if (!shadow)
|
|
|
|
{
|
|
|
|
pglActiveTextureARB(GL_TEXTURE0);
|
2009-04-05 20:31:05 +02:00
|
|
|
// We're not going to use a texture here, but we have to have a valid texture
|
|
|
|
// bound else the texture unit will be disabled.
|
|
|
|
// We should still have a bound splat texture from some earlier rendering,
|
|
|
|
// so assume that's still valid to use.
|
|
|
|
// (TODO: That's a bit of an ugly hack.)
|
2006-02-15 01:45:16 +01:00
|
|
|
|
|
|
|
// Shadow rendering disabled: Ambient + Diffuse
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, terrainAmbientColor);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
}
|
|
|
|
else
|
2006-02-13 15:18:20 +01:00
|
|
|
{
|
|
|
|
const CMatrix3D& texturematrix = shadow->GetTextureMatrix();
|
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
pglActiveTextureARB(GL_TEXTURE0);
|
2006-02-13 15:18:20 +01:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadMatrixf(&texturematrix._11);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
2006-02-15 01:45:16 +01:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, shadow->GetTexture());
|
|
|
|
|
|
|
|
if (shadow->GetUseDepthTexture())
|
|
|
|
{
|
|
|
|
// Ambient + ShTranslucency * Diffuse * (1 - Shadow) + Diffuse * Shadow
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
|
|
|
float shadowTransp = g_Renderer.GetLightEnv().GetTerrainShadowTransparency();
|
|
|
|
float color[4] = { shadowTransp, shadowTransp, shadowTransp, 1.0 };
|
|
|
|
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
|
|
|
|
|
|
|
|
pglActiveTextureARB(GL_TEXTURE1);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PRIMARY_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_TEXTURE0);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
|
|
|
pglActiveTextureARB(GL_TEXTURE2);
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, shadow->GetTexture()); // Need a valid texture or the unit will be disabled
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, terrainAmbientColor);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Ambient + Diffuse * Shadow
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
|
|
|
pglActiveTextureARB(GL_TEXTURE1); // + Ambient
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_CONSTANT);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
|
2006-09-28 22:41:12 +02:00
|
|
|
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, terrainAmbientColor);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
}
|
2006-02-13 15:18:20 +01:00
|
|
|
}
|
|
|
|
|
2006-02-15 01:45:16 +01:00
|
|
|
pglActiveTextureARB(GL_TEXTURE0);
|
2006-02-13 15:18:20 +01:00
|
|
|
pglClientActiveTextureARB(GL_TEXTURE0);
|
2009-03-24 22:00:41 +01:00
|
|
|
|
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
|
|
|
for (size_t i = 0; i < m->visiblePatches.size(); ++i)
|
2006-02-13 15:18:20 +01:00
|
|
|
{
|
|
|
|
CPatchRData* patchdata = (CPatchRData*)m->visiblePatches[i]->GetRenderData();
|
|
|
|
patchdata->RenderStreams(STREAM_POS|STREAM_COLOR|STREAM_POSTOUV0, false);
|
|
|
|
}
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-02-13 15:18:20 +01:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
|
|
|
|
// restore OpenGL state
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
if (shadow)
|
2006-03-31 05:30:34 +02:00
|
|
|
{
|
# Added tool for viewing models and animations outside the game.
Atlas: Added ActorViewer. Moved GL canvas into separate class for shared
use. Disabled message-handling callback while blocked on the game, and
stopped creating dialog boxes inside the game thread in order to avoid
deadlocks (hopefully). Support multiple Views (for independent sets of
camera/update/render code). Recalculate territory boundaries when
necessary. Changed default list of animations to match those currently
used by actors.
# Tidied up more code.
Moved some more #includes out of .h files, to minimise unnecessary
compilation.
MathUtil: Deleted unused/unuseful macros (M_PI (use PI instead), M_PI_2
(use PI/2), MAX3, ABS (use abs)).
ObjectManager: Removed some ScEd-specific things.
Unit: Moved creation out of UnitManager, so units can be created without
adding to the manager. Changed CStr8 to the more conventional CStr.
app_hooks: Removed warning for setting multiple times.
win: Restored SEH catcher.
GameSetup, GameView: Removed RenderNoCull, because it doesn't seem to do
what it says it does ("force renderer to load everything") since we're
loading-on-demand most stuff and it doesn't seem especially useful since
we'd prefer to minimise loading times (but feel free to correct me if
I'm wrong). (And because it crashes when things need to be initialised
in a different order, so it's easier to remove than to understand and
fix it.)
PatchRData, Renderer: Work sensibly when there's no game (hence no LOS
manager, water, etc).
LOSManager: Use entity position instead of actor position when possible.
TerritoryManager: Allow delayed recalculations (so Atlas can issue lots
of move+recalculate commands per frame).
Cinematic: Non-pointer wxTimer, so it doesn't leak and doesn't have to
be deleted manually.
This was SVN commit r4261.
2006-08-28 19:36:42 +02:00
|
|
|
if (shadow->GetUseDepthTexture())
|
|
|
|
g_Renderer.BindTexture(2,0);
|
2006-03-31 05:30:34 +02:00
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
g_Renderer.BindTexture(1,0);
|
2006-02-11 19:04:32 +01:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
pglClientActiveTextureARB(GL_TEXTURE0);
|
|
|
|
pglActiveTextureARB(GL_TEXTURE0);
|
2006-02-13 15:18:20 +01:00
|
|
|
glDepthMask(1);
|
|
|
|
glDisable(GL_BLEND);
|
2006-01-07 02:04:26 +01:00
|
|
|
glDisableClientState(GL_COLOR_ARRAY);
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
2006-02-13 15:18:20 +01:00
|
|
|
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Render un-textured patches as polygons
|
|
|
|
void TerrainRenderer::RenderPatches()
|
|
|
|
{
|
|
|
|
debug_assert(m->phase == Phase_Render);
|
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
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
|
|
|
for(size_t i = 0; i < m->visiblePatches.size(); ++i)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
CPatchRData* patchdata = (CPatchRData*)m->visiblePatches[i]->GetRenderData();
|
2006-02-13 15:18:20 +01:00
|
|
|
patchdata->RenderStreams(STREAM_POS, true);
|
2006-01-07 02:04:26 +01:00
|
|
|
}
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Render outlines of submitted patches as lines
|
|
|
|
void TerrainRenderer::RenderOutlines()
|
|
|
|
{
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
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
|
|
|
for(size_t i = 0; i < m->visiblePatches.size(); ++i)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
CPatchRData* patchdata = (CPatchRData*)m->visiblePatches[i]->GetRenderData();
|
|
|
|
patchdata->RenderOutline();
|
|
|
|
}
|
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Render water that is part of the terrain
|
|
|
|
void TerrainRenderer::RenderWater()
|
|
|
|
{
|
2006-04-19 02:56:24 +02:00
|
|
|
PROFILE( "render water" );
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
bool fancy = g_Renderer.m_Options.m_FancyWater;
|
|
|
|
|
|
|
|
// If we're using fancy water, make sure its shader is loaded
|
|
|
|
if(fancy && !m->fancyWaterShader)
|
|
|
|
{
|
2009-03-24 22:00:41 +01:00
|
|
|
Handle h = ogl_program_load("shaders/water_high.xml");
|
|
|
|
if (h < 0)
|
|
|
|
{
|
|
|
|
LOG(CLogger::Error, LOG_CATEGORY, "Failed to load water shader. Falling back to non-fancy water.\n");
|
|
|
|
g_Renderer.m_Options.m_FancyWater = false;
|
|
|
|
fancy = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m->fancyWaterShader = h;
|
|
|
|
}
|
2006-05-25 07:46:17 +02:00
|
|
|
}
|
2006-03-31 05:30:34 +02:00
|
|
|
|
|
|
|
//(Crappy) fresnel effect
|
2006-01-07 02:04:26 +01:00
|
|
|
CCamera* Camera=g_Game->GetView()->GetCamera();
|
|
|
|
CVector3D CamFace=Camera->m_Orientation.GetIn();
|
|
|
|
CamFace.Normalize();
|
|
|
|
float FresnelScalar = CamFace.Dot( CVector3D(0.0f, -1.0f, 0.0f) );
|
|
|
|
//Invert and set boundaries
|
|
|
|
FresnelScalar = (1 - FresnelScalar) * 0.4f + 0.6f;
|
|
|
|
|
|
|
|
CTerrain* terrain = g_Game->GetWorld()->GetTerrain();
|
|
|
|
int mapSize = terrain->GetVerticesPerSide();
|
|
|
|
CLOSManager* losMgr = g_Game->GetWorld()->GetLOSManager();
|
|
|
|
WaterManager* WaterMgr = g_Renderer.GetWaterManager();
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
2006-05-29 02:49:09 +02:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-01-22 00:27:42 +01:00
|
|
|
double time = WaterMgr->m_WaterTexTimer;
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
double period = 1.6;
|
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
|
|
|
int curTex = (int)(time*60/period) % 60;
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
if(fancy)
|
|
|
|
{
|
|
|
|
ogl_tex_bind(WaterMgr->m_NormalMap[curTex], 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ogl_tex_bind(WaterMgr->m_WaterTexture[curTex], 0);
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
|
2006-09-12 00:35:44 +02:00
|
|
|
// Shift the texture coordinates by these amounts to make the water "flow"
|
2006-09-29 01:27:55 +02:00
|
|
|
float tx = -fmod(time, 81.0)/81.0;
|
|
|
|
float ty = -fmod(time, 34.0)/34.0;
|
2006-09-12 00:35:44 +02:00
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
if(!fancy)
|
|
|
|
{
|
2006-09-12 00:35:44 +02:00
|
|
|
// Perform the shifting by modifying the texture matrix
|
2006-05-25 07:46:17 +02:00
|
|
|
glMatrixMode(GL_TEXTURE);
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(tx, ty, 0);
|
|
|
|
|
|
|
|
// Set up texture environment to multiply vertex RGB by texture RGB and use vertex alpha
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PRIMARY_COLOR_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA);
|
|
|
|
}
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
// Set the proper LOD bias
|
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, g_Renderer.m_Options.m_LodBias);
|
2006-03-31 05:30:34 +02:00
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
// Some offsets used to go around counterclockwise while keeping code concise
|
|
|
|
const int DX[] = {1,1,0,0};
|
|
|
|
const int DZ[] = {0,1,1,0};
|
|
|
|
|
|
|
|
GLint vertexDepth = 0; // water depth attribute, if using fancy water
|
2006-09-01 01:56:12 +02:00
|
|
|
GLint losMultiplier = 0; // LOS multiplier, if using fancy water
|
2006-05-25 07:46:17 +02:00
|
|
|
|
|
|
|
if(fancy)
|
|
|
|
{
|
2006-05-28 04:13:32 +02:00
|
|
|
// Bind reflection and refraction textures on texture units 1 and 2
|
|
|
|
pglActiveTextureARB( GL_TEXTURE1_ARB );
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, WaterMgr->m_ReflectionTexture );
|
|
|
|
pglActiveTextureARB( GL_TEXTURE2_ARB );
|
|
|
|
glEnable( GL_TEXTURE_2D );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, WaterMgr->m_RefractionTexture );
|
|
|
|
|
|
|
|
// Bind water shader and set arguments
|
2006-05-25 07:46:17 +02:00
|
|
|
ogl_program_use( m->fancyWaterShader );
|
|
|
|
|
|
|
|
GLint ambient = ogl_program_get_uniform_location( m->fancyWaterShader, "ambient" );
|
|
|
|
GLint sunDir = ogl_program_get_uniform_location( m->fancyWaterShader, "sunDir" );
|
|
|
|
GLint sunColor = ogl_program_get_uniform_location( m->fancyWaterShader, "sunColor" );
|
2006-09-10 07:31:41 +02:00
|
|
|
GLint cameraPos = ogl_program_get_uniform_location( m->fancyWaterShader, "cameraPos" );
|
2006-05-25 07:46:17 +02:00
|
|
|
GLint shininess = ogl_program_get_uniform_location( m->fancyWaterShader, "shininess" );
|
2006-09-10 07:31:41 +02:00
|
|
|
GLint specularStrength = ogl_program_get_uniform_location( m->fancyWaterShader, "specularStrength" );
|
2006-05-28 23:58:56 +02:00
|
|
|
GLint waviness = ogl_program_get_uniform_location( m->fancyWaterShader, "waviness" );
|
2006-06-22 23:11:18 +02:00
|
|
|
GLint murkiness = ogl_program_get_uniform_location( m->fancyWaterShader, "murkiness" );
|
|
|
|
GLint fullDepth = ogl_program_get_uniform_location( m->fancyWaterShader, "fullDepth" );
|
|
|
|
GLint tint = ogl_program_get_uniform_location( m->fancyWaterShader, "tint" );
|
2006-09-10 07:31:41 +02:00
|
|
|
GLint reflectionTint = ogl_program_get_uniform_location( m->fancyWaterShader, "reflectionTint" );
|
|
|
|
GLint reflectionTintStrength = ogl_program_get_uniform_location( m->fancyWaterShader, "reflectionTintStrength" );
|
2006-09-12 00:35:44 +02:00
|
|
|
GLint translation = ogl_program_get_uniform_location( m->fancyWaterShader, "translation" );
|
2006-05-28 04:13:32 +02:00
|
|
|
GLint reflectionMatrix = ogl_program_get_uniform_location( m->fancyWaterShader, "reflectionMatrix" );
|
|
|
|
GLint refractionMatrix = ogl_program_get_uniform_location( m->fancyWaterShader, "refractionMatrix" );
|
2006-05-25 07:46:17 +02:00
|
|
|
GLint normalMap = ogl_program_get_uniform_location( m->fancyWaterShader, "normalMap" );
|
2006-05-28 04:13:32 +02:00
|
|
|
GLint reflectionMap = ogl_program_get_uniform_location( m->fancyWaterShader, "reflectionMap" );
|
|
|
|
GLint refractionMap = ogl_program_get_uniform_location( m->fancyWaterShader, "refractionMap" );
|
2006-05-25 07:46:17 +02:00
|
|
|
|
2006-05-28 04:13:32 +02:00
|
|
|
const CLightEnv& lightEnv = g_Renderer.GetLightEnv();
|
2006-05-25 07:46:17 +02:00
|
|
|
pglUniform3fvARB( ambient, 1, &lightEnv.m_TerrainAmbientColor.X );
|
|
|
|
pglUniform3fvARB( sunDir, 1, &lightEnv.GetSunDir().X );
|
|
|
|
pglUniform3fvARB( sunColor, 1, &lightEnv.m_SunColor.X );
|
2006-05-28 23:58:56 +02:00
|
|
|
pglUniform1fARB( shininess, WaterMgr->m_Shininess );
|
2006-09-10 07:31:41 +02:00
|
|
|
pglUniform1fARB( specularStrength, WaterMgr->m_SpecularStrength );
|
2006-05-28 23:58:56 +02:00
|
|
|
pglUniform1fARB( waviness, WaterMgr->m_Waviness );
|
2006-06-22 23:11:18 +02:00
|
|
|
pglUniform1fARB( murkiness, WaterMgr->m_Murkiness );
|
|
|
|
pglUniform1fARB( fullDepth, WaterMgr->m_WaterFullDepth );
|
|
|
|
pglUniform3fvARB( tint, 1, WaterMgr->m_WaterTint.FloatArray() );
|
2006-09-10 07:31:41 +02:00
|
|
|
pglUniform1fARB( reflectionTintStrength, WaterMgr->m_ReflectionTintStrength );
|
|
|
|
pglUniform3fvARB( reflectionTint, 1, WaterMgr->m_ReflectionTint.FloatArray() );
|
2006-09-12 00:35:44 +02:00
|
|
|
pglUniform4fARB( translation, tx, ty, 0, 0 );
|
2006-05-28 04:13:32 +02:00
|
|
|
pglUniformMatrix4fvARB( reflectionMatrix, 1, false, &WaterMgr->m_ReflectionMatrix._11 );
|
|
|
|
pglUniformMatrix4fvARB( refractionMatrix, 1, false, &WaterMgr->m_RefractionMatrix._11 );
|
2006-05-28 23:58:56 +02:00
|
|
|
pglUniform1iARB( normalMap, 0 ); // texture unit 0
|
2006-05-28 04:13:32 +02:00
|
|
|
pglUniform1iARB( reflectionMap, 1 ); // texture unit 1
|
|
|
|
pglUniform1iARB( refractionMap, 2 ); // texture unit 2
|
2006-05-25 07:46:17 +02:00
|
|
|
|
|
|
|
const CCamera& camera = g_Renderer.GetViewCamera();
|
|
|
|
CVector3D camPos = camera.m_Orientation.GetTranslation();
|
|
|
|
pglUniform3fvARB( cameraPos, 1, &camPos.X );
|
|
|
|
|
|
|
|
vertexDepth = ogl_program_get_attrib_location( m->fancyWaterShader, "vertexDepth" );
|
2006-09-01 01:56:12 +02:00
|
|
|
losMultiplier = ogl_program_get_attrib_location( m->fancyWaterShader, "losMultiplier" );
|
2006-05-25 07:46:17 +02:00
|
|
|
}
|
|
|
|
|
2006-05-28 23:58:56 +02:00
|
|
|
float repeatPeriod = (fancy ? WaterMgr->m_RepeatPeriod : 16.0f);
|
2006-05-25 07:46:17 +02:00
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
|
|
|
|
for(size_t i=0; i<m->visiblePatches.size(); i++)
|
|
|
|
{
|
|
|
|
CPatch* patch = m->visiblePatches[i];
|
|
|
|
|
2008-07-12 12:45:11 +02:00
|
|
|
for(ssize_t dx=0; dx<PATCH_SIZE; dx++)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
2008-07-12 12:45:11 +02:00
|
|
|
for(ssize_t dz=0; dz<PATCH_SIZE; dz++)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
2008-07-12 12:45:11 +02:00
|
|
|
ssize_t x = (patch->m_X*PATCH_SIZE + dx);
|
|
|
|
ssize_t z = (patch->m_Z*PATCH_SIZE + dz);
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
// is any corner of the tile below the water height? if not, no point rendering it
|
|
|
|
bool shouldRender = false;
|
|
|
|
for(int j=0; j<4; j++)
|
|
|
|
{
|
2007-05-02 14:07:08 +02:00
|
|
|
float terrainHeight = terrain->GetVertexGroundLevel(x + DX[j], z + DZ[j]);
|
2006-03-31 05:30:34 +02:00
|
|
|
if( terrainHeight < WaterMgr->m_WaterHeight )
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
|
|
|
shouldRender = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!shouldRender)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int j=0; j<4; j++)
|
|
|
|
{
|
|
|
|
int ix = x + DX[j];
|
|
|
|
int iz = z + DZ[j];
|
|
|
|
|
|
|
|
float vertX = ix * CELL_SIZE;
|
|
|
|
float vertZ = iz * CELL_SIZE;
|
|
|
|
|
2007-05-02 14:07:08 +02:00
|
|
|
float terrainHeight = terrain->GetVertexGroundLevel(ix, iz);
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
float alpha = clamp(
|
|
|
|
(WaterMgr->m_WaterHeight - terrainHeight) / WaterMgr->m_WaterFullDepth + WaterMgr->m_WaterAlphaOffset,
|
|
|
|
-100.0f, WaterMgr->m_WaterMaxAlpha);
|
|
|
|
|
|
|
|
float losMod = 1.0f;
|
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
|
|
|
for(size_t k=0; k<4; k++)
|
2006-01-07 02:04:26 +01:00
|
|
|
{
|
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
|
|
|
ssize_t tx = ix - DX[k];
|
|
|
|
ssize_t tz = iz - DZ[k];
|
2006-01-07 02:04:26 +01:00
|
|
|
|
|
|
|
if(tx >= 0 && tz >= 0 && tx <= mapSize-2 && tz <= mapSize-2)
|
|
|
|
{
|
|
|
|
ELOSStatus s = losMgr->GetStatus(tx, tz, g_Game->GetLocalPlayer());
|
|
|
|
if(s == LOS_EXPLORED && losMod > 0.7f)
|
|
|
|
losMod = 0.7f;
|
|
|
|
else if(s==LOS_UNEXPLORED && losMod > 0.0f)
|
|
|
|
losMod = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
if(fancy)
|
|
|
|
{
|
|
|
|
pglVertexAttrib1fARB( vertexDepth, WaterMgr->m_WaterHeight - terrainHeight );
|
2006-09-01 01:56:12 +02:00
|
|
|
pglVertexAttrib1fARB( losMultiplier, losMod );
|
2006-05-25 07:46:17 +02:00
|
|
|
}
|
2006-06-22 23:11:18 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
glColor4f(WaterMgr->m_WaterColor.r*losMod, WaterMgr->m_WaterColor.g*losMod,
|
|
|
|
WaterMgr->m_WaterColor.b*losMod, alpha * FresnelScalar);
|
|
|
|
}
|
2006-05-28 23:58:56 +02:00
|
|
|
pglMultiTexCoord2fARB(GL_TEXTURE0, vertX/repeatPeriod, vertZ/repeatPeriod);
|
2006-01-07 02:04:26 +01:00
|
|
|
glVertex3f(vertX, WaterMgr->m_WaterHeight, vertZ);
|
|
|
|
}
|
|
|
|
} //end of x loop
|
|
|
|
} //end of z loop
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
if(fancy)
|
|
|
|
{
|
2006-05-28 04:13:32 +02:00
|
|
|
// Unbind the refraction/reflection textures and the shader
|
|
|
|
|
|
|
|
pglActiveTextureARB( GL_TEXTURE1_ARB );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, 0 );
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
|
|
|
|
pglActiveTextureARB( GL_TEXTURE2_ARB );
|
|
|
|
glBindTexture( GL_TEXTURE_2D, 0 );
|
|
|
|
glDisable( GL_TEXTURE_2D );
|
|
|
|
|
|
|
|
pglActiveTextureARB( GL_TEXTURE0_ARB );
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
ogl_program_use( 0 );
|
|
|
|
}
|
|
|
|
|
2006-05-28 23:58:56 +02:00
|
|
|
if(!fancy)
|
|
|
|
{
|
|
|
|
// Clean up the texture matrix and blend mode
|
|
|
|
glLoadIdentity();
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
}
|
|
|
|
|
2006-01-07 02:04:26 +01:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
}
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
|