2025-05-29 17:31:23 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2009-04-18 10:00:33 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2009-04-18 10:00:33 -07:00
|
|
|
* 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
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2009-04-18 10:00:33 -07:00
|
|
|
*/
|
|
|
|
|
|
2010-09-10 14:02:10 -07:00
|
|
|
#ifndef INCLUDED_TERRAINTEXTUREENTRY
|
|
|
|
|
#define INCLUDED_TERRAINTEXTUREENTRY
|
2004-05-29 13:56:24 -07:00
|
|
|
|
2021-12-26 12:39:13 -08:00
|
|
|
#include "graphics/Material.h"
|
|
|
|
|
#include "graphics/TerrainTextureManager.h"
|
2022-01-07 06:33:54 -08:00
|
|
|
#include "graphics/Texture.h"
|
2010-07-04 03:15:53 -07:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2025-07-28 11:13:46 -07:00
|
|
|
#include "lib/types.h"
|
2012-01-22 10:20:33 -08:00
|
|
|
#include "maths/Matrix3D.h"
|
2006-06-01 19:10:27 -07:00
|
|
|
#include "ps/CStr.h"
|
2004-06-08 05:10:51 -07:00
|
|
|
|
2021-03-03 15:01:08 -08:00
|
|
|
#include <vector>
|
|
|
|
|
|
2025-07-28 11:13:46 -07:00
|
|
|
class CTerrainProperties;
|
|
|
|
|
|
2010-09-04 14:26:52 -07:00
|
|
|
// CTerrainTextureEntry: class wrapping a terrain texture object; contains various other required
|
2004-06-07 12:56:26 -07:00
|
|
|
// elements - color of minimap, terrain "group" it belongs to, etc
|
2010-09-04 14:26:52 -07:00
|
|
|
class CTerrainTextureEntry
|
2004-05-29 13:56:24 -07:00
|
|
|
{
|
|
|
|
|
public:
|
2021-12-26 12:39:13 -08:00
|
|
|
using GroupVector = std::vector<CTerrainGroup*>;
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2005-08-07 14:58:36 -07:00
|
|
|
// Most of the texture's data is delay-loaded, so after the constructor has
|
|
|
|
|
// been called, the texture entry is ready to be used.
|
2010-09-04 14:26:52 -07:00
|
|
|
CTerrainTextureEntry(CTerrainPropertiesPtr props, const VfsPath& path);
|
2025-05-29 17:31:23 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Constructs a terrain texture entry with the given tag.
|
|
|
|
|
*
|
|
|
|
|
* This constructor creates a placeholder (dummy) texture entry,
|
|
|
|
|
* allowing the system to handle missing terrain textures gracefully.
|
|
|
|
|
* It ensures stability by avoiding crashes when a texture file is
|
|
|
|
|
* not found.
|
|
|
|
|
*
|
|
|
|
|
* @param tag The identifier for the terrain texture entry.
|
|
|
|
|
*/
|
|
|
|
|
CTerrainTextureEntry(const CStr tag);
|
|
|
|
|
|
2010-09-04 14:26:52 -07:00
|
|
|
~CTerrainTextureEntry();
|
2004-06-08 05:10:51 -07:00
|
|
|
|
2020-01-10 14:36:22 -08:00
|
|
|
const CStr& GetTag() const { return m_Tag; }
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2020-01-10 14:36:22 -08:00
|
|
|
const CTerrainProperties& GetProperties() const { return *m_pProperties; }
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2005-08-07 14:58:36 -07:00
|
|
|
// Get texture handle, load texture if not loaded.
|
2020-01-10 14:36:22 -08:00
|
|
|
const CTexturePtr& GetTexture() const { return m_Material.GetDiffuseTexture(); }
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2020-01-10 14:36:22 -08:00
|
|
|
const CMaterial& GetMaterial() const { return m_Material; }
|
2012-01-22 10:20:33 -08:00
|
|
|
|
|
|
|
|
// Returns a matrix of the form [c 0 -s 0; -s 0 -c 0; 0 0 0 0; 0 0 0 1]
|
|
|
|
|
// mapping world-space (x,y,z,1) coordinates onto (u,v,0,1) texcoords
|
2022-04-27 12:53:42 -07:00
|
|
|
const CMatrix3D& GetTextureMatrix() const { return m_TextureMatrix; }
|
2012-01-22 10:20:33 -08:00
|
|
|
|
2021-12-30 08:24:07 -08:00
|
|
|
// Used in Atlas to retrieve a texture for previews. Can't use textures
|
|
|
|
|
// directly because they're required on CPU side. Another solution is to
|
|
|
|
|
// retrieve path from diffuse texture from material.
|
|
|
|
|
const VfsPath& GetDiffuseTexturePath() const { return m_DiffuseTexturePath; }
|
|
|
|
|
|
2005-08-07 14:58:36 -07:00
|
|
|
// Get mipmap color in BGRA format
|
2020-01-10 14:36:22 -08:00
|
|
|
u32 GetBaseColor()
|
|
|
|
|
{
|
2004-06-08 05:10:51 -07:00
|
|
|
if (!m_BaseColorValid) BuildBaseColor();
|
|
|
|
|
return m_BaseColor;
|
|
|
|
|
}
|
2016-11-23 03:18:37 -08:00
|
|
|
|
2012-08-07 11:21:16 -07:00
|
|
|
CTerrainTextureManager::TerrainAlphaMap::iterator m_TerrainAlpha;
|
2021-12-26 12:39:13 -08:00
|
|
|
|
|
|
|
|
private:
|
2025-05-29 17:31:23 -07:00
|
|
|
void GenerateTextureMatrix(const float texAngle, const float texSize);
|
2021-12-26 12:39:13 -08:00
|
|
|
// Tag = file name stripped of path and extension (grass_dark_1)
|
|
|
|
|
CStr m_Tag;
|
|
|
|
|
|
2021-12-30 08:24:07 -08:00
|
|
|
VfsPath m_DiffuseTexturePath;
|
|
|
|
|
|
2021-12-26 12:39:13 -08:00
|
|
|
// The property sheet used by this texture
|
|
|
|
|
CTerrainPropertiesPtr m_pProperties;
|
|
|
|
|
|
|
|
|
|
CMaterial m_Material;
|
|
|
|
|
|
|
|
|
|
CMatrix3D m_TextureMatrix;
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
// calculate the root color of the texture, used for coloring minimap
|
|
|
|
|
void BuildBaseColor();
|
2004-05-29 13:56:24 -07:00
|
|
|
};
|
|
|
|
|
|
2016-11-23 03:18:37 -08:00
|
|
|
#endif
|