Changeset View
Changeset View
Standalone View
Standalone View
source/graphics/LOSTexture.cpp
Show All 14 Lines | |||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#include "precompiled.h" | #include "precompiled.h" | ||||
#include "LOSTexture.h" | #include "LOSTexture.h" | ||||
#include "graphics/ShaderManager.h" | #include "graphics/ShaderManager.h" | ||||
#include "graphics/Terrain.h" | |||||
#include "lib/bits.h" | #include "lib/bits.h" | ||||
#include "lib/config2.h" | #include "lib/config2.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "ps/Game.h" | #include "ps/Game.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
#include "renderer/Renderer.h" | #include "renderer/Renderer.h" | ||||
#include "renderer/RenderingOptions.h" | #include "renderer/RenderingOptions.h" | ||||
#include "renderer/TimeManager.h" | #include "renderer/TimeManager.h" | ||||
#include "simulation2/Simulation2.h" | #include "simulation2/Simulation2.h" | ||||
#include "simulation2/components/ICmpRangeManager.h" | #include "simulation2/components/ICmpRangeManager.h" | ||||
#include "simulation2/components/ICmpTerrain.h" | |||||
#include "simulation2/helpers/Los.h" | #include "simulation2/helpers/Los.h" | ||||
/* | /* | ||||
The LOS bitmap is computed with one value per map vertex, based on | The LOS bitmap is computed with one value per LOS vertex, based on | ||||
CCmpRangeManager's visibility information. | CCmpRangeManager's visibility information. | ||||
The bitmap is then blurred using an NxN filter (in particular a | The bitmap is then blurred using an NxN filter (in particular a | ||||
7-tap Binomial filter as an efficient integral approximation of a Gaussian). | 7-tap Binomial filter as an efficient integral approximation of a Gaussian). | ||||
To implement the blur efficiently without using extra memory for a second copy | To implement the blur efficiently without using extra memory for a second copy | ||||
of the bitmap, we generate the bitmap with (N-1)/2 pixels of padding on each side, | of the bitmap, we generate the bitmap with (N-1)/2 pixels of padding on each side, | ||||
then the blur shifts the image back into the corner. | then the blur shifts the image back into the corner. | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | |||||
const CMatrix3D* CLOSTexture::GetMinimapTextureMatrix() | const CMatrix3D* CLOSTexture::GetMinimapTextureMatrix() | ||||
{ | { | ||||
ENSURE(!m_Dirty); | ENSURE(!m_Dirty); | ||||
return &m_MinimapTextureMatrix; | return &m_MinimapTextureMatrix; | ||||
} | } | ||||
void CLOSTexture::ConstructTexture(int unit) | void CLOSTexture::ConstructTexture(int unit) | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | CmpPtr<ICmpRangeManager> cmpRangeManager(m_Simulation, SYSTEM_ENTITY); | ||||
if (!cmpTerrain) | if (!cmpRangeManager) | ||||
return; | return; | ||||
m_MapSize = cmpTerrain->GetVerticesPerSide(); | m_MapSize = cmpRangeManager->GetVerticesPerSide(); | ||||
m_TextureSize = (GLsizei)round_up_to_pow2(round_up((size_t)m_MapSize + g_BlurSize - 1, g_SubTextureAlignment)); | m_TextureSize = (GLsizei)round_up_to_pow2(round_up((size_t)m_MapSize + g_BlurSize - 1, g_SubTextureAlignment)); | ||||
glGenTextures(1, &m_Texture); | glGenTextures(1, &m_Texture); | ||||
// Initialise texture with SoD color, for the areas we don't | // Initialise texture with SoD color, for the areas we don't | ||||
// overwrite with glTexSubImage2D later | // overwrite with glTexSubImage2D later | ||||
u8* texData = new u8[m_TextureSize * m_TextureSize * 4]; | u8* texData = new u8[m_TextureSize * m_TextureSize * 4]; | ||||
Show All 30 Lines | void CLOSTexture::ConstructTexture(int unit) | ||||
{ | { | ||||
// Texture matrix: We want to map | // Texture matrix: We want to map | ||||
// world pos (0, y, 0) (i.e. first vertex) | // world pos (0, y, 0) (i.e. first vertex) | ||||
// onto texcoord (0.5/texsize, 0.5/texsize) (i.e. middle of first texel); | // onto texcoord (0.5/texsize, 0.5/texsize) (i.e. middle of first texel); | ||||
// world pos ((mapsize-1)*cellsize, y, (mapsize-1)*cellsize) (i.e. last vertex) | // world pos ((mapsize-1)*cellsize, y, (mapsize-1)*cellsize) (i.e. last vertex) | ||||
// onto texcoord ((mapsize-0.5) / texsize, (mapsize-0.5) / texsize) (i.e. middle of last texel) | // onto texcoord ((mapsize-0.5) / texsize, (mapsize-0.5) / texsize) (i.e. middle of last texel) | ||||
float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * TERRAIN_TILE_SIZE); | float s = (m_MapSize-1) / (float)(m_TextureSize * (m_MapSize-1) * LOS_TILE_SIZE); | ||||
float t = 0.5f / m_TextureSize; | float t = 0.5f / m_TextureSize; | ||||
m_TextureMatrix.SetZero(); | m_TextureMatrix.SetZero(); | ||||
m_TextureMatrix._11 = s; | m_TextureMatrix._11 = s; | ||||
m_TextureMatrix._23 = s; | m_TextureMatrix._23 = s; | ||||
m_TextureMatrix._14 = t; | m_TextureMatrix._14 = t; | ||||
m_TextureMatrix._24 = t; | m_TextureMatrix._24 = t; | ||||
m_TextureMatrix._44 = 1; | m_TextureMatrix._44 = 1; | ||||
} | } | ||||
Show All 9 Lines | void CLOSTexture::ConstructTexture(int unit) | ||||
} | } | ||||
} | } | ||||
void CLOSTexture::RecomputeTexture(int unit) | void CLOSTexture::RecomputeTexture(int unit) | ||||
{ | { | ||||
// If the map was resized, delete and regenerate the texture | // If the map was resized, delete and regenerate the texture | ||||
if (m_Texture) | if (m_Texture) | ||||
{ | { | ||||
CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); | CmpPtr<ICmpRangeManager> cmpRangeManager(m_Simulation, SYSTEM_ENTITY); | ||||
if (cmpTerrain && m_MapSize != (ssize_t)cmpTerrain->GetVerticesPerSide()) | if (!cmpRangeManager || m_MapSize != cmpRangeManager->GetVerticesPerSide()) | ||||
DeleteTexture(); | DeleteTexture(); | ||||
} | } | ||||
bool recreated = false; | bool recreated = false; | ||||
if (!m_Texture) | if (!m_Texture) | ||||
{ | { | ||||
ConstructTexture(unit); | ConstructTexture(unit); | ||||
recreated = true; | recreated = true; | ||||
▲ Show 20 Lines • Show All 108 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator