2004-05-29 22:56:24 +02:00
|
|
|
#ifndef _TEXTUREENTRY_H
|
|
|
|
#define _TEXTUREENTRY_H
|
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
#include <map>
|
|
|
|
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/handle.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
#include "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)
|
|
|
|
CStr m_Tag;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
// Path to the texture file
|
|
|
|
CStr m_TexturePath;
|
|
|
|
|
|
|
|
void* m_Bitmap; // UI bitmap object (user data for ScEd)
|
|
|
|
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;
|
|
|
|
|
|
|
|
// A map of all loaded textures and their texture handles for GetByHandle.
|
|
|
|
static std::map<Handle, CTextureEntry *> m_LoadedTextures;
|
|
|
|
|
|
|
|
// 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.
|
2005-10-28 03:43:16 +02:00
|
|
|
CTextureEntry(CTerrainPropertiesPtr props, CStr 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; }
|
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
CStr GetTexturePath() const
|
|
|
|
{ return m_TexturePath; }
|
2004-06-08 14:10:51 +02:00
|
|
|
|
|
|
|
void* GetBitmap() const { return m_Bitmap; }
|
|
|
|
void SetBitmap(void* bmp) { m_Bitmap=bmp; }
|
|
|
|
|
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.
|
2005-06-20 19:34:17 +02:00
|
|
|
int GetType() const
|
|
|
|
{ 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); }
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
// The texture entry class maintains a map of loaded textures and their
|
|
|
|
// handles.
|
|
|
|
static CTextureEntry *GetByHandle(Handle handle);
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
#endif
|