Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
TerritoryTexture.h
Go to the documentation of this file.
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#include "lib/code_annotation.h"
20#include "maths/Matrix3D.h"
21
22#include <cstddef>
23#include <memory>
24
25class CSimulation2;
26namespace Renderer::Backend { class IDeviceCommandContext; }
27namespace Renderer::Backend { class ITexture; }
28template<typename T> class Grid;
29
30/**
31 * Maintains the territory boundary texture, used for
32 * rendering and for the minimap.
33 */
35{
37
38public:
41
42 /**
43 * Recomputes the territory texture if necessary, and returns the texture handle.
44 * Also potentially switches the current active texture unit, and enables texturing on it.
45 * The texture is in 32-bit BGRA format.
46 */
48
49 /**
50 * Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture
51 * coordinates, in the form expected by a matrix uniform.
52 * This must only be called after UpdateIfNeeded.
53 */
55
56 /**
57 * Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture
58 * coordinates, in the form expected by a matrix uniform.
59 * This must only be called after UpdateIfNeeded.
60 */
62
63 /**
64 * Updates the texture if needed (territory was changed or the texture
65 * wasn't created).
66 */
68
69private:
70 /**
71 * Returns true if the territory state has changed since the last call to this function
72 */
73 bool UpdateDirty();
74
75 void DeleteTexture();
78
79 void GenerateBitmap(const Grid<std::uint8_t>& territories, std::uint8_t* bitmap, ssize_t w,
80 ssize_t h);
81
83
84 size_t m_DirtyID;
85
86 std::unique_ptr<Renderer::Backend::ITexture> m_Texture;
87
88 ssize_t m_MapSize; // tiles per side
89
92};
Definition: Matrix3D.h:36
Public API for simulation system.
Definition: Simulation2.h:57
Maintains the territory boundary texture, used for rendering and for the minimap.
Definition: TerritoryTexture.h:35
std::unique_ptr< Renderer::Backend::ITexture > m_Texture
Definition: TerritoryTexture.h:86
void ConstructTexture(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Definition: TerritoryTexture.cpp:87
const CMatrix3D & GetTextureMatrix()
Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture coordinates, in the form expecte...
Definition: TerritoryTexture.cpp:75
CMatrix3D m_MinimapTextureMatrix
Definition: TerritoryTexture.h:91
NONCOPYABLE(CTerritoryTexture)
void DeleteTexture()
Definition: TerritoryTexture.cpp:58
bool UpdateDirty()
Returns true if the territory state has changed since the last call to this function.
Definition: TerritoryTexture.cpp:63
size_t m_DirtyID
Definition: TerritoryTexture.h:84
const CMatrix3D & GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture coordinates, in the form expecte...
Definition: TerritoryTexture.cpp:81
CSimulation2 & m_Simulation
Definition: TerritoryTexture.h:82
CMatrix3D m_TextureMatrix
Definition: TerritoryTexture.h:90
~CTerritoryTexture()
Definition: TerritoryTexture.cpp:53
ssize_t m_MapSize
Definition: TerritoryTexture.h:88
Renderer::Backend::ITexture * GetTexture()
Recomputes the territory texture if necessary, and returns the texture handle.
Definition: TerritoryTexture.cpp:69
CTerritoryTexture(CSimulation2 &simulation)
Definition: TerritoryTexture.cpp:48
void UpdateIfNeeded(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Updates the texture if needed (territory was changed or the texture wasn't created).
Definition: TerritoryTexture.cpp:262
void RecomputeTexture(Renderer::Backend::IDeviceCommandContext *deviceCommandContext)
Definition: TerritoryTexture.cpp:144
void GenerateBitmap(const Grid< std::uint8_t > &territories, std::uint8_t *bitmap, ssize_t w, ssize_t h)
Definition: TerritoryTexture.cpp:171
Basic 2D array, intended for storing tile data, plus support for lazy updates by ICmpObstructionManag...
Definition: Grid.h:46
Definition: IDeviceCommandContext.h:46
Definition: ITexture.h:33
Definition: Canvas2D.h:30
intptr_t ssize_t
Definition: wposix_types.h:36