Pyrogenesis  trunk
TerrainTextureEntry.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_TERRAINTEXTUREENTRY
19 #define INCLUDED_TERRAINTEXTUREENTRY
20 
21 #include <map>
22 
23 #include "TerrainTextureManager.h"
24 #include "TextureManager.h"
25 #include "Material.h"
26 
27 #include "lib/res/handle.h"
28 #include "lib/file/vfs/vfs_path.h"
29 #include "maths/Matrix3D.h"
30 #include "ps/CStr.h"
31 
32 class XMBElement;
33 class CXeromyces;
34 
35 //////////////////////////////////////////////////////////////////////////////////////////////////////////
36 // CTerrainTextureEntry: class wrapping a terrain texture object; contains various other required
37 // elements - color of minimap, terrain "group" it belongs to, etc
39 {
40 public:
41  typedef std::vector<CTerrainGroup *> GroupVector;
42 
43 private:
44  // Tag = file name stripped of path and extension (grass_dark_1)
45  CStr m_Tag;
46 
47  // The property sheet used by this texture
49 
51 
53 
54  // BGRA color of topmost mipmap level, for coloring minimap, or a color
55  // specified by the terrain properties
57  // ..Valid is true if the base color has been cached
59 
60  // All terrain type groups we're a member of
61  GroupVector m_Groups;
62 
63  // calculate the root color of the texture, used for coloring minimap
64  void BuildBaseColor();
65 
66  void LoadAlphaMaps(VfsPath &amtype);
67 
68 public:
69  // Most of the texture's data is delay-loaded, so after the constructor has
70  // been called, the texture entry is ready to be used.
73 
74  CStr GetTag() const
75  { return m_Tag; }
76 
78  { return *m_pProperties; }
79 
80  // Get texture handle, load texture if not loaded.
82  return m_Material.GetDiffuseTexture();
83  }
84 
86  return m_Material;
87  }
88 
89  // Returns a matrix of the form [c 0 -s 0; -s 0 -c 0; 0 0 0 0; 0 0 0 1]
90  // mapping world-space (x,y,z,1) coordinates onto (u,v,0,1) texcoords
91  const float* GetTextureMatrix();
92 
93  // Get mipmap color in BGRA format
95  if (!m_BaseColorValid) BuildBaseColor();
96  return m_BaseColor;
97  }
98 
99  //TerrainAlpha *m_TerrainAlpha;
100  CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha;
101 };
102 
103 #endif
shared_ptr< CTerrainProperties > CTerrainPropertiesPtr
Definition: TerrainProperties.h:38
void BuildBaseColor()
Definition: TerrainTextureEntry.cpp:179
const float * GetTextureMatrix()
Definition: TerrainTextureEntry.cpp:197
Definition: XeroXMB.h:160
Definition: TerrainTextureEntry.h:38
const CTexturePtr & GetDiffuseTexture() const
Definition: Material.h:51
Definition: Material.h:28
void LoadAlphaMaps(VfsPath &amtype)
Definition: TerrainTextureEntry.cpp:204
u32 GetBaseColor()
Definition: TerrainTextureEntry.h:94
Definition: Matrix3D.h:33
uint32_t u32
Definition: types.h:39
Definition: path.h:77
u32 m_BaseColor
Definition: TerrainTextureEntry.h:56
Definition: TerrainProperties.h:42
CMaterial m_Material
Definition: TerrainTextureEntry.h:50
GroupVector m_Groups
Definition: TerrainTextureEntry.h:61
const CTexturePtr & GetTexture()
Definition: TerrainTextureEntry.h:81
bool m_BaseColorValid
Definition: TerrainTextureEntry.h:58
CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath &path)
Definition: TerrainTextureEntry.cpp:40
CMatrix3D m_TextureMatrix
Definition: TerrainTextureEntry.h:52
const CMaterial & GetMaterial()
Definition: TerrainTextureEntry.h:85
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22
Definition: Xeromyces.h:42
CTerrainPropertiesPtr m_pProperties
Definition: TerrainTextureEntry.h:48
~CTerrainTextureEntry()
Definition: TerrainTextureEntry.cpp:171
CStr GetTag() const
Definition: TerrainTextureEntry.h:74
CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha
Definition: TerrainTextureEntry.h:100
const CTerrainProperties & GetProperties() const
Definition: TerrainTextureEntry.h:77
CStr m_Tag
Definition: TerrainTextureEntry.h:45
std::vector< CTerrainGroup * > GroupVector
Definition: TerrainTextureEntry.h:41