[Gameplay] Reduce loom cost
[0ad.git] / source / graphics / TerrainTextureEntry.h
blob0cabfe3f4a2bab195c165f6d2ba7f9a33b62baa1
1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_TERRAINTEXTUREENTRY
19 #define INCLUDED_TERRAINTEXTUREENTRY
21 #include "graphics/Material.h"
22 #include "graphics/TerrainTextureManager.h"
23 #include "graphics/Texture.h"
24 #include "lib/file/vfs/vfs_path.h"
25 #include "maths/Matrix3D.h"
26 #include "ps/CStr.h"
28 #include <vector>
30 // CTerrainTextureEntry: class wrapping a terrain texture object; contains various other required
31 // elements - color of minimap, terrain "group" it belongs to, etc
32 class CTerrainTextureEntry
34 public:
35 using GroupVector = std::vector<CTerrainGroup*>;
37 // Most of the texture's data is delay-loaded, so after the constructor has
38 // been called, the texture entry is ready to be used.
39 CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path);
40 ~CTerrainTextureEntry();
42 const CStr& GetTag() const { return m_Tag; }
44 const CTerrainProperties& GetProperties() const { return *m_pProperties; }
46 // Get texture handle, load texture if not loaded.
47 const CTexturePtr& GetTexture() const { return m_Material.GetDiffuseTexture(); }
49 const CMaterial& GetMaterial() const { return m_Material; }
51 // Returns a matrix of the form [c 0 -s 0; -s 0 -c 0; 0 0 0 0; 0 0 0 1]
52 // mapping world-space (x,y,z,1) coordinates onto (u,v,0,1) texcoords
53 const CMatrix3D& GetTextureMatrix() const { return m_TextureMatrix; }
55 // Used in Atlas to retrieve a texture for previews. Can't use textures
56 // directly because they're required on CPU side. Another solution is to
57 // retrieve path from diffuse texture from material.
58 const VfsPath& GetDiffuseTexturePath() const { return m_DiffuseTexturePath; }
60 // Get mipmap color in BGRA format
61 u32 GetBaseColor()
63 if (!m_BaseColorValid) BuildBaseColor();
64 return m_BaseColor;
67 CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha;
69 private:
70 // Tag = file name stripped of path and extension (grass_dark_1)
71 CStr m_Tag;
73 VfsPath m_DiffuseTexturePath;
75 // The property sheet used by this texture
76 CTerrainPropertiesPtr m_pProperties;
78 CMaterial m_Material;
80 CMatrix3D m_TextureMatrix;
82 // BGRA color of topmost mipmap level, for coloring minimap, or a color
83 // specified by the terrain properties
84 u32 m_BaseColor;
85 // ..Valid is true if the base color has been cached
86 bool m_BaseColorValid;
88 // All terrain type groups we're a member of
89 GroupVector m_Groups;
91 // calculate the root color of the texture, used for coloring minimap
92 void BuildBaseColor();
95 #endif