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