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/>.
|
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* Sky settings, texture management and rendering.
|
2006-05-16 06:41:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
2006-09-30 23:36:19 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
#include "lib/timer.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "lib/tex/tex.h"
|
2006-05-16 06:41:37 +02:00
|
|
|
#include "lib/res/graphics/ogl_tex.h"
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
#include "maths/MathUtil.h"
|
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/CStr.h"
|
2006-05-16 06:41:37 +02:00
|
|
|
#include "ps/CLogger.h"
|
|
|
|
#include "ps/Loader.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "ps/Filesystem.h"
|
2006-05-16 06:41:37 +02:00
|
|
|
|
|
|
|
#include "renderer/SkyManager.h"
|
|
|
|
#include "renderer/Renderer.h"
|
|
|
|
|
|
|
|
#include "graphics/Camera.h"
|
2006-05-25 07:46:17 +02:00
|
|
|
#include "graphics/LightEnv.h"
|
2010-09-10 23:02:10 +02:00
|
|
|
#include "graphics/TextureManager.h"
|
2006-05-16 06:41:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SkyManager implementation
|
|
|
|
|
|
|
|
|
2006-05-17 04:24:17 +02:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// String names for each image, in order of the IMG_ constants
|
2009-11-03 22:46:35 +01:00
|
|
|
const wchar_t* SkyManager::s_imageNames[numTextures] = {
|
|
|
|
L"front",
|
|
|
|
L"back",
|
|
|
|
L"right",
|
|
|
|
L"left",
|
|
|
|
L"top"
|
2006-05-17 04:24:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Construction/Destruction
|
|
|
|
SkyManager::SkyManager()
|
|
|
|
{
|
|
|
|
m_RenderSky = true;
|
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkySet = L"";
|
2006-05-17 04:24:17 +02:00
|
|
|
|
2006-06-01 19:05:42 +02:00
|
|
|
m_HorizonHeight = -150.0f;
|
2009-11-03 22:46:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
///////////////////////////////////////////////////////////////////
|
2010-09-10 23:02:10 +02:00
|
|
|
// Load all sky textures
|
|
|
|
void SkyManager::LoadSkyTextures()
|
2006-05-16 06:41:37 +02:00
|
|
|
{
|
2010-09-10 23:02:10 +02:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(m_SkyTexture); ++i)
|
2006-05-16 06:41:37 +02:00
|
|
|
{
|
2011-03-23 22:15:22 +01:00
|
|
|
VfsPath path = VfsPath("art/textures/skies") / m_SkySet / (Path::String(s_imageNames[i])+L".dds");
|
2006-05-16 06:41:37 +02:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
CTextureProperties textureProps(path);
|
|
|
|
textureProps.SetWrap(GL_CLAMP_TO_EDGE);
|
|
|
|
CTexturePtr texture = g_Renderer.GetTextureManager().CreateTexture(textureProps);
|
|
|
|
texture->Prefetch();
|
|
|
|
m_SkyTexture[i] = texture;
|
2006-05-16 06:41:37 +02:00
|
|
|
}
|
2006-05-17 04:24:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Switch to a different sky set (while the game is running)
|
2006-07-20 16:37:58 +02:00
|
|
|
void SkyManager::SetSkySet( const CStrW& newSet )
|
2006-05-17 04:24:17 +02:00
|
|
|
{
|
2009-11-03 22:46:35 +01:00
|
|
|
if(newSet == m_SkySet)
|
|
|
|
return;
|
|
|
|
m_SkySet = newSet;
|
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
LoadSkyTextures();
|
2006-05-16 06:41:37 +02:00
|
|
|
}
|
|
|
|
|
2006-06-22 00:37:31 +02:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Generate list of available skies
|
|
|
|
std::vector<CStrW> SkyManager::GetSkySets() const
|
|
|
|
{
|
|
|
|
std::vector<CStrW> skies;
|
|
|
|
|
|
|
|
// Find all subdirectories in art/textures/skies
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
const VfsPath path(L"art/textures/skies/");
|
2007-12-20 21:21:45 +01:00
|
|
|
DirectoryNames subdirectories;
|
2009-11-03 22:46:35 +01:00
|
|
|
if(g_VFS->GetDirectoryEntries(path, 0, &subdirectories) < 0)
|
2006-06-22 00:37:31 +02:00
|
|
|
{
|
2011-03-23 14:36:20 +01:00
|
|
|
LOGERROR(L"Error opening directory '%ls'", path.string().c_str());
|
2006-06-22 00:37:31 +02:00
|
|
|
return std::vector<CStrW>(1, GetSkySet()); // just return what we currently have
|
|
|
|
}
|
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
for(size_t i = 0; i < subdirectories.size(); i++)
|
2011-03-23 14:36:20 +01:00
|
|
|
skies.push_back(subdirectories[i].string());
|
2006-06-22 00:37:31 +02:00
|
|
|
sort(skies.begin(), skies.end());
|
|
|
|
|
|
|
|
return skies;
|
|
|
|
}
|
2006-05-16 06:41:37 +02:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
// Render sky
|
|
|
|
void SkyManager::RenderSky()
|
|
|
|
{
|
2012-02-13 16:06:25 +01:00
|
|
|
#if CONFIG2_GLES
|
|
|
|
#warning TODO: implement SkyManager::RenderSky for GLES
|
|
|
|
#else
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
// Draw the sky as a small box around the camera position, with depth write enabled.
|
|
|
|
// This will be done before anything else is drawn so we'll be overlapped by everything else.
|
|
|
|
|
|
|
|
// Note: The coordinates for this were set up through a rather cumbersome trial-and-error
|
|
|
|
// process - there might be a smarter way to do it, but this seems to work.
|
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
// Do nothing unless SetSkySet was called
|
|
|
|
if (m_SkySet.empty())
|
|
|
|
return;
|
|
|
|
|
2006-05-16 06:41:37 +02:00
|
|
|
glDepthMask( GL_FALSE );
|
|
|
|
|
|
|
|
pglActiveTextureARB(GL_TEXTURE0_ARB);
|
|
|
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
|
2006-05-25 07:46:17 +02:00
|
|
|
// Translate so we are at the camera in the X and Z directions, but
|
|
|
|
// put the horizon at a fixed height regardless of camera Y
|
2006-05-16 06:41:37 +02:00
|
|
|
const CCamera& camera = g_Renderer.GetViewCamera();
|
|
|
|
CVector3D pos = camera.m_Orientation.GetTranslation();
|
2006-05-25 07:46:17 +02:00
|
|
|
glTranslatef( pos.X, m_HorizonHeight, pos.Z );
|
|
|
|
|
|
|
|
// Rotate so that the "left" face, which contains the brightest part of each
|
|
|
|
// skymap, is in the direction of the sun from our light environment
|
# 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
|
|
|
glRotatef( 90.0f + RADTODEG(g_Renderer.GetLightEnv().GetRotation()), 0.0f, 1.0f, 0.0f );
|
2006-05-16 06:41:37 +02:00
|
|
|
|
|
|
|
// Distance to draw the faces at
|
|
|
|
const float D = 2000.0;
|
|
|
|
|
|
|
|
// Front face (positive Z)
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkyTexture[FRONT]->Bind();
|
2006-05-16 06:41:37 +02:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glTexCoord2f( 0, 1 );
|
|
|
|
glVertex3f( -D, -D, +D );
|
|
|
|
glTexCoord2f( 1, 1 );
|
|
|
|
glVertex3f( +D, -D, +D );
|
|
|
|
glTexCoord2f( 1, 0 );
|
|
|
|
glVertex3f( +D, +D, +D );
|
|
|
|
glTexCoord2f( 0, 0 );
|
|
|
|
glVertex3f( -D, +D, +D );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Back face (negative Z)
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkyTexture[BACK]->Bind();
|
2006-05-16 06:41:37 +02:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glTexCoord2f( 1, 1 );
|
|
|
|
glVertex3f( -D, -D, -D );
|
|
|
|
glTexCoord2f( 1, 0 );
|
|
|
|
glVertex3f( -D, +D, -D );
|
|
|
|
glTexCoord2f( 0, 0 );
|
|
|
|
glVertex3f( +D, +D, -D );
|
|
|
|
glTexCoord2f( 0, 1 );
|
|
|
|
glVertex3f( +D, -D, -D );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Right face (negative X)
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkyTexture[RIGHT]->Bind();
|
2006-05-16 06:41:37 +02:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glTexCoord2f( 0, 1 );
|
|
|
|
glVertex3f( -D, -D, -D );
|
|
|
|
glTexCoord2f( 1, 1 );
|
|
|
|
glVertex3f( -D, -D, +D );
|
|
|
|
glTexCoord2f( 1, 0 );
|
|
|
|
glVertex3f( -D, +D, +D );
|
|
|
|
glTexCoord2f( 0, 0 );
|
|
|
|
glVertex3f( -D, +D, -D );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Left face (positive X)
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkyTexture[LEFT]->Bind();
|
2006-05-16 06:41:37 +02:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glTexCoord2f( 1, 1 );
|
|
|
|
glVertex3f( +D, -D, -D );
|
|
|
|
glTexCoord2f( 1, 0 );
|
|
|
|
glVertex3f( +D, +D, -D );
|
|
|
|
glTexCoord2f( 0, 0 );
|
|
|
|
glVertex3f( +D, +D, +D );
|
|
|
|
glTexCoord2f( 0, 1 );
|
|
|
|
glVertex3f( +D, -D, +D );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Top face (positive Y)
|
2010-09-10 23:02:10 +02:00
|
|
|
m_SkyTexture[TOP]->Bind();
|
2006-05-16 06:41:37 +02:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glTexCoord2f( 1, 0 );
|
|
|
|
glVertex3f( +D, +D, -D );
|
|
|
|
glTexCoord2f( 0, 0 );
|
|
|
|
glVertex3f( -D, +D, -D );
|
|
|
|
glTexCoord2f( 0, 1 );
|
|
|
|
glVertex3f( -D, +D, +D );
|
|
|
|
glTexCoord2f( 1, 1 );
|
|
|
|
glVertex3f( +D, +D, +D );
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
glDepthMask( GL_TRUE );
|
2012-02-13 16:06:25 +01:00
|
|
|
|
|
|
|
#endif
|
2006-05-16 06:41:37 +02:00
|
|
|
}
|