2010-05-28 01:31:03 +02:00
|
|
|
/* Copyright (C) 2010 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/>.
|
|
|
|
*/
|
|
|
|
|
2004-06-08 14:10:51 +02:00
|
|
|
#include "precompiled.h"
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
#include <map>
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2011-03-23 14:36:20 +01:00
|
|
|
#include "lib/utf8.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "lib/ogl.h"
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/graphics/ogl_tex.h"
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
#include "TerrainTextureEntry.h"
|
|
|
|
#include "TerrainTextureManager.h"
|
2005-08-07 23:58:36 +02:00
|
|
|
#include "TerrainProperties.h"
|
2004-06-08 14:10:51 +02:00
|
|
|
#include "Texture.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "renderer/Renderer.h"
|
2004-06-08 14:10:51 +02:00
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry::CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path):
|
2005-08-07 23:58:36 +02:00
|
|
|
m_pProperties(props),
|
2005-06-20 17:14:36 +02:00
|
|
|
m_BaseColor(0),
|
2010-09-10 23:02:10 +02:00
|
|
|
m_BaseColorValid(false)
|
2004-12-16 13:01:47 +01:00
|
|
|
{
|
2011-04-30 15:01:45 +02:00
|
|
|
ENSURE(props);
|
2011-02-05 14:13:57 +01:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
CTextureProperties texture(path);
|
|
|
|
texture.SetWrap(GL_REPEAT);
|
|
|
|
|
|
|
|
// TODO: anisotropy should probably be user-configurable, but we want it to be
|
|
|
|
// at least 2 for terrain else the ground looks very blurry when you tilt the
|
|
|
|
// camera upwards
|
|
|
|
texture.SetMaxAnisotropy(2.0f);
|
|
|
|
|
2010-09-17 19:43:12 +02:00
|
|
|
if (CRenderer::IsInitialised())
|
|
|
|
m_Texture = g_Renderer.GetTextureManager().CreateTexture(texture);
|
2010-09-10 23:02:10 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
if (m_pProperties)
|
|
|
|
m_Groups = m_pProperties->GetGroups();
|
2005-06-20 17:14:36 +02:00
|
|
|
|
|
|
|
GroupVector::iterator it=m_Groups.begin();
|
|
|
|
for (;it!=m_Groups.end();++it)
|
2005-08-07 23:58:36 +02:00
|
|
|
(*it)->AddTerrain(this);
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2011-03-23 14:36:20 +01:00
|
|
|
m_Tag = utf8_from_wstring(path.Basename().string());
|
2005-06-20 17:14:36 +02:00
|
|
|
}
|
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry::~CTerrainTextureEntry()
|
2005-06-20 17:14:36 +02:00
|
|
|
{
|
2005-08-07 23:58:36 +02:00
|
|
|
for (GroupVector::iterator it=m_Groups.begin();it!=m_Groups.end();++it)
|
|
|
|
(*it)->RemoveTerrain(this);
|
2004-12-16 13:01:47 +01:00
|
|
|
}
|
|
|
|
|
2005-08-10 03:12:03 +02:00
|
|
|
// BuildBaseColor: calculate the root colour of the texture, used for coloring minimap, and store
|
2004-06-08 14:10:51 +02:00
|
|
|
// in m_BaseColor member
|
2010-09-04 23:26:52 +02:00
|
|
|
void CTerrainTextureEntry::BuildBaseColor()
|
2004-06-08 14:10:51 +02:00
|
|
|
{
|
2010-09-10 23:02:10 +02:00
|
|
|
// Use the explicit properties value if possible
|
2005-08-07 23:58:36 +02:00
|
|
|
if (m_pProperties && m_pProperties->HasBaseColor())
|
2005-06-20 17:14:36 +02:00
|
|
|
{
|
2005-08-07 23:58:36 +02:00
|
|
|
m_BaseColor=m_pProperties->GetBaseColor();
|
2010-09-10 23:02:10 +02:00
|
|
|
m_BaseColorValid = true;
|
2005-06-20 17:14:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
// Use the texture colour if available
|
|
|
|
if (m_Texture->TryLoad())
|
|
|
|
{
|
|
|
|
m_BaseColor = m_Texture->GetBaseColour();
|
|
|
|
m_BaseColorValid = true;
|
|
|
|
}
|
2004-06-11 04:14:18 +02:00
|
|
|
}
|