LCOV - code coverage report
Current view: top level - source/graphics - TerrainTextureEntry.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 8 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 0 -

          Line data    Source code
       1             : /* Copyright (C) 2026 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 "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"
      27             : 
      28             : #include <vector>
      29             : 
      30             : class CTerrainProperties;
      31             : 
      32             : // CTerrainTextureEntry: class wrapping a terrain texture object; contains various other required
      33             : // elements - color of minimap, terrain "group" it belongs to, etc
      34             : class CTerrainTextureEntry
      35             : {
      36             : public:
      37             :     using GroupVector = std::vector<CTerrainGroup*>;
      38             : 
      39             :     // Most of the texture's data is delay-loaded, so after the constructor has
      40             :     // been called, the texture entry is ready to be used.
      41             :     CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path);
      42             : 
      43             :     /**
      44             :      * @brief Constructs a terrain texture entry with the given tag.
      45             :      *
      46             :      * This constructor creates a placeholder (dummy) texture entry,
      47             :      * allowing the system to handle missing terrain textures gracefully.
      48             :      * It ensures stability by avoiding crashes when a texture file is
      49             :      * not found.
      50             :      *
      51             :      * @param tag The identifier for the terrain texture entry.
      52             :      */
      53             :     CTerrainTextureEntry(const CStr tag);
      54             : 
      55             :     ~CTerrainTextureEntry();
      56             : 
      57           0 :     const CStr& GetTag() const { return m_Tag; }
      58             : 
      59             :     const CTerrainProperties& GetProperties() const { return *m_pProperties; }
      60             : 
      61             :     // Get texture handle, load texture if not loaded.
      62           0 :     const CTexturePtr& GetTexture() const { return m_Material.GetDiffuseTexture(); }
      63             : 
      64           0 :     const CMaterial& GetMaterial() const { return m_Material; }
      65             : 
      66             :     // Returns a matrix of the form [c 0 -s 0; -s 0 -c 0; 0 0 0 0; 0 0 0 1]
      67             :     // mapping world-space (x,y,z,1) coordinates onto (u,v,0,1) texcoords
      68           0 :     const CMatrix3D& GetTextureMatrix() const { return m_TextureMatrix; }
      69             : 
      70             :     // Used in Atlas to retrieve a texture for previews. Can't use textures
      71             :     // directly because they're required on CPU side. Another solution is to
      72             :     // retrieve path from diffuse texture from material.
      73           0 :     const VfsPath& GetDiffuseTexturePath() const { return m_DiffuseTexturePath; }
      74             : 
      75             :     // Get mipmap color in BGRA format
      76           0 :     std::uint32_t GetBaseColor()
      77             :     {
      78           0 :         if (!m_BaseColorValid) BuildBaseColor();
      79           0 :         return m_BaseColor;
      80             :     }
      81             : 
      82             :     CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha;
      83             : 
      84             : private:
      85             :     void GenerateTextureMatrix(const float texAngle, const float texSize);
      86             :     // Tag = file name stripped of path and extension (grass_dark_1)
      87             :     CStr m_Tag;
      88             : 
      89             :     VfsPath m_DiffuseTexturePath;
      90             : 
      91             :     // The property sheet used by this texture
      92             :     CTerrainPropertiesPtr m_pProperties;
      93             : 
      94             :     CMaterial m_Material;
      95             : 
      96             :     CMatrix3D m_TextureMatrix;
      97             : 
      98             :     // BGRA color of topmost mipmap level, for coloring minimap, or a color
      99             :     // specified by the terrain properties
     100             :     std::uint32_t m_BaseColor;
     101             :     // ..Valid is true if the base color has been cached
     102             :     bool m_BaseColorValid;
     103             : 
     104             :     // All terrain type groups we're a member of
     105             :     GroupVector m_Groups;
     106             : 
     107             :     // calculate the root color of the texture, used for coloring minimap
     108             :     void BuildBaseColor();
     109             : };
     110             : 
     111             : #endif

Generated by: LCOV version 1.16