Pyrogenesis  trunk
LOSTexture.h
Go to the documentation of this file.
1 /* Copyright (C) 2014 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 #include "graphics/ShaderManager.h"
24 
25 
26 class CSimulation2;
27 
28 /**
29  * Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for
30  * rendering and for the minimap.
31  */
33 {
35  friend class TestLOSTexture;
36 
37 public:
38  CLOSTexture(CSimulation2& simulation);
39  ~CLOSTexture();
40 
41  /**
42  * Marks the LOS texture as needing recomputation. Call this after each
43  * simulation update, to ensure responsive updates.
44  */
45  void MakeDirty();
46 
47  /**
48  * Recomputes the LOS texture if necessary, and binds it to the requested
49  * texture unit.
50  * Also switches the current active texture unit, and enables texturing on it.
51  * The texture is in 8-bit ALPHA format.
52  */
53  void BindTexture(int unit);
54 
55  /**
56  * Recomputes the LOS texture if necessary, and returns the texture handle.
57  * Also potentially switches the current active texture unit, and enables texturing on it.
58  * The texture is in 8-bit ALPHA format.
59  */
60  GLuint GetTexture();
61 
62  void InterpolateLOS();
63  GLuint GetTextureSmooth();
64 
65  /**
66  * Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture
67  * coordinates, in the form expected by glLoadMatrixf.
68  * This must only be called after BindTexture.
69  */
70  const CMatrix3D& GetTextureMatrix();
71 
72  /**
73  * Returns a matrix to map (0,0)-(1,1) texture coordinates onto LOS texture
74  * coordinates, in the form expected by glLoadMatrixf.
75  * This must only be called after BindTexture.
76  */
78 
79 private:
80  void DeleteTexture();
81  bool CreateShader();
82  void ConstructTexture(int unit);
83  void RecomputeTexture(int unit);
84 
85  size_t GetBitmapSize(size_t w, size_t h, size_t* pitch);
86  void GenerateBitmap(ICmpRangeManager::CLosQuerier los, u8* losData, size_t w, size_t h, size_t pitch);
87 
89 
90  bool m_Dirty;
91 
93 
94  GLuint m_Texture;
96 
97  bool whichTex;
98 
99  GLuint m_smoothFbo;
101 
102  ssize_t m_MapSize; // vertexes per side
103  GLsizei m_TextureSize; // texels per side
104 
107 };
void RecomputeTexture(int unit)
Definition: LOSTexture.cpp:318
size_t GetBitmapSize(size_t w, size_t h, size_t *pitch)
Definition: LOSTexture.cpp:361
~CLOSTexture()
Definition: LOSTexture.cpp:69
void DeleteTexture()
Definition: LOSTexture.cpp:94
CLOSTexture(CSimulation2 &simulation)
Definition: LOSTexture.cpp:60
CMatrix3D m_MinimapTextureMatrix
Definition: LOSTexture.h:106
friend class TestLOSTexture
Definition: LOSTexture.h:35
GLsizei m_TextureSize
Definition: LOSTexture.h:103
NONCOPYABLE(CLOSTexture)
GLuint m_TextureSmooth1
Definition: LOSTexture.h:95
GLuint GetTextureSmooth()
Definition: LOSTexture.cpp:125
GLuint m_Texture
Definition: LOSTexture.h:94
shared_ptr< CShaderTechnique > CShaderTechniquePtr
Definition: ShaderTechnique.h:113
uint8_t u8
Definition: types.h:37
bool m_ShaderInitialized
Definition: LOSTexture.h:92
CShaderTechniquePtr m_smoothShader
Definition: LOSTexture.h:100
Public API for simulation system.
Definition: Simulation2.h:47
GLuint m_TextureSmooth2
Definition: LOSTexture.h:95
Definition: Matrix3D.h:33
bool m_Dirty
Definition: LOSTexture.h:90
CSimulation2 & m_Simulation
Definition: LOSTexture.h:88
const CMatrix3D * GetMinimapTextureMatrix()
Returns a matrix to map (0,0)-(1,1) texture coordinates onto LOS texture coordinates, in the form expected by glLoadMatrixf.
Definition: LOSTexture.cpp:238
GLuint GetTexture()
Recomputes the LOS texture if necessary, and returns the texture handle.
Definition: LOSTexture.cpp:221
void MakeDirty()
Marks the LOS texture as needing recomputation.
Definition: LOSTexture.cpp:109
ssize_t m_MapSize
Definition: LOSTexture.h:102
intptr_t ssize_t
Definition: wposix_types.h:82
void ConstructTexture(int unit)
Definition: LOSTexture.cpp:244
bool CreateShader()
Definition: LOSTexture.cpp:76
CMatrix3D m_TextureMatrix
Definition: LOSTexture.h:105
Object providing efficient abstracted access to the LOS state.
Definition: ICmpRangeManager.h:242
void BindTexture(int unit)
Recomputes the LOS texture if necessary, and binds it to the requested texture unit.
Definition: LOSTexture.cpp:114
Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for rendering and for the minimap...
Definition: LOSTexture.h:32
const CMatrix3D & GetTextureMatrix()
Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture coordinates, in the form expected by glLoadMatrixf.
Definition: LOSTexture.cpp:232
GLuint m_smoothFbo
Definition: LOSTexture.h:99
void InterpolateLOS()
Definition: LOSTexture.cpp:133
void GenerateBitmap(ICmpRangeManager::CLosQuerier los, u8 *losData, size_t w, size_t h, size_t pitch)
Definition: LOSTexture.cpp:367
bool whichTex
Definition: LOSTexture.h:97