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/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_TEXTUREENTRY
|
|
|
|
#define INCLUDED_TEXTUREENTRY
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
#include <map>
|
|
|
|
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/handle.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CStr.h"
|
2004-06-08 14:10:51 +02:00
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
#include "TextureManager.h"
|
|
|
|
|
|
|
|
class XMBElement;
|
|
|
|
class CXeromyces;
|
|
|
|
|
2004-06-08 14:10:51 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CTextureEntry: class wrapping a terrain texture object; contains various other required
|
2004-06-07 21:56:26 +02:00
|
|
|
// elements - color of minimap, terrain "group" it belongs to, etc
|
2004-05-29 22:56:24 +02:00
|
|
|
class CTextureEntry
|
|
|
|
{
|
|
|
|
public:
|
2005-08-07 23:58:36 +02:00
|
|
|
typedef std::vector<CTerrainGroup *> GroupVector;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Tag = file name stripped of path and extension (grass_dark_1)
|
2009-11-03 22:46:35 +01:00
|
|
|
CStrW m_Tag;
|
2005-08-07 23:58:36 +02:00
|
|
|
|
|
|
|
// The property sheet used by this texture
|
2005-10-28 03:43:16 +02:00
|
|
|
CTerrainPropertiesPtr m_pProperties;
|
2005-08-07 23:58:36 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath m_TexturePath;
|
2005-08-07 23:58:36 +02:00
|
|
|
|
|
|
|
Handle m_Handle; // handle to GL texture data
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
// BGRA color of topmost mipmap level, for coloring minimap, or a color
|
|
|
|
// specified by the terrain properties
|
|
|
|
u32 m_BaseColor;
|
|
|
|
// ..Valid is true if the base color has been cached
|
|
|
|
bool m_BaseColorValid;
|
|
|
|
|
|
|
|
// All terrain type groups we're a member of
|
|
|
|
GroupVector m_Groups;
|
|
|
|
|
|
|
|
// load texture from file
|
|
|
|
void LoadTexture();
|
|
|
|
// calculate the root color of the texture, used for coloring minimap
|
|
|
|
void BuildBaseColor();
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Most of the texture's data is delay-loaded, so after the constructor has
|
|
|
|
// been called, the texture entry is ready to be used.
|
2009-11-03 22:46:35 +01:00
|
|
|
CTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path);
|
2004-12-16 13:01:47 +01:00
|
|
|
~CTextureEntry();
|
2004-06-08 14:10:51 +02:00
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
CStr GetTag() const
|
|
|
|
{ return m_Tag; }
|
|
|
|
|
2005-10-28 03:43:16 +02:00
|
|
|
CTerrainPropertiesPtr GetProperties() const
|
2005-08-07 23:58:36 +02:00
|
|
|
{ return m_pProperties; }
|
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath GetTexturePath() const
|
2005-06-20 17:14:36 +02:00
|
|
|
{ return m_TexturePath; }
|
2004-06-08 14:10:51 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
// Get texture handle, load texture if not loaded.
|
2004-06-08 14:10:51 +02:00
|
|
|
Handle GetHandle() {
|
2004-12-16 13:01:47 +01:00
|
|
|
if (m_Handle==-1) LoadTexture();
|
2004-06-08 14:10:51 +02:00
|
|
|
return m_Handle;
|
|
|
|
}
|
2005-08-07 23:58:36 +02:00
|
|
|
// Get mipmap color in BGRA format
|
2004-06-08 14:10:51 +02:00
|
|
|
u32 GetBaseColor() {
|
|
|
|
if (!m_BaseColorValid) BuildBaseColor();
|
|
|
|
return m_BaseColor;
|
|
|
|
}
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
// ScEd wants to sort textures by their group's index.
|
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 GetType() const
|
2005-06-20 19:34:17 +02:00
|
|
|
{ return m_Groups[0]->GetIndex(); }
|
2005-06-20 17:14:36 +02:00
|
|
|
const GroupVector &GetGroups() const
|
|
|
|
{ return m_Groups; }
|
|
|
|
|
2005-02-10 00:19:48 +01:00
|
|
|
// returns whether this texture-entry has loaded any data yet
|
|
|
|
bool IsLoaded() { return (m_Handle!=-1); }
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
#endif
|