Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TerritoryTexture.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 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/ogl.h"
19 
20 #include "maths/Matrix3D.h"
22 
23 class CSimulation2;
24 
25 /**
26  * Maintains the territory boundary texture, used for
27  * rendering and for the minimap.
28  */
30 {
32 
33 public:
34  CTerritoryTexture(CSimulation2& simulation);
36 
37  /**
38  * Recomputes the territory texture if necessary, and binds it to the requested
39  * texture unit.
40  * Also switches the current active texture unit, and enables texturing on it.
41  * The texture is in 32-bit BGRA format.
42  */
43  void BindTexture(int unit);
44 
45  /**
46  * Recomputes the territory texture if necessary, and returns the texture handle.
47  * Also potentially switches the current active texture unit, and enables texturing on it.
48  * The texture is in 32-bit BGRA format.
49  */
50  GLuint GetTexture();
51 
52  /**
53  * Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture
54  * coordinates, in the form expected by glLoadMatrixf.
55  * This must only be called after BindTexture.
56  */
57  const float* GetTextureMatrix();
58 
59  /**
60  * Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture
61  * coordinates, in the form expected by glLoadMatrixf.
62  * This must only be called after BindTexture.
63  */
64  const float* GetMinimapTextureMatrix();
65 
66 private:
67  /**
68  * Returns true if the territory state has changed since the last call to this function
69  */
70  bool UpdateDirty();
71 
72  void DeleteTexture();
73  void ConstructTexture(int unit);
74  void RecomputeTexture(int unit);
75 
76  void GenerateBitmap(const Grid<u8>& territories, u8* bitmap, ssize_t w, ssize_t h);
77 
79 
80  size_t m_DirtyID;
81 
82  GLuint m_Texture;
83 
84  ssize_t m_MapSize; // tiles per side
85  GLsizei m_TextureSize; // texels per side
86 
89 };
#define u8
Definition: types.h:39
CTerritoryTexture(CSimulation2 &simulation)
const float * GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto texture coordinates, in the form expecte...
void BindTexture(int unit)
Recomputes the territory texture if necessary, and binds it to the requested texture unit...
Public API for simulation system.
Definition: Simulation2.h:46
CMatrix3D m_TextureMatrix
bool UpdateDirty()
Returns true if the territory state has changed since the last call to this function.
void GenerateBitmap(const Grid< u8 > &territories, u8 *bitmap, ssize_t w, ssize_t h)
GLuint GetTexture()
Recomputes the territory texture if necessary, and returns the texture handle.
CMatrix3D m_MinimapTextureMatrix
intptr_t ssize_t
Definition: wposix_types.h:82
const float * GetTextureMatrix()
Returns a matrix to map (x,y,z) world coordinates onto (u,v) texture coordinates, in the form expecte...
NONCOPYABLE(CTerritoryTexture)
void RecomputeTexture(int unit)
void ConstructTexture(int unit)
Maintains the territory boundary texture, used for rendering and for the minimap. ...
CSimulation2 & m_Simulation