2021-05-31 22:47:03 +02:00
|
|
|
/* Copyright (C) 2021 Wildfire Games.
|
2011-02-03 02:12:24 +01:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-05-31 22:47:03 +02:00
|
|
|
#ifndef INCLUDED_LOSTEXTURE
|
|
|
|
#define INCLUDED_LOSTEXTURE
|
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
#include "lib/ogl.h"
|
|
|
|
|
2020-11-21 12:20:29 +01:00
|
|
|
#include "graphics/ShaderTechniquePtr.h"
|
2021-05-15 19:27:01 +02:00
|
|
|
#include "maths/Matrix3D.h"
|
2021-12-25 01:26:10 +01:00
|
|
|
#include "renderer/backend/gl/Texture.h"
|
2012-08-07 00:38:42 +02:00
|
|
|
|
2020-11-21 12:20:29 +01:00
|
|
|
class CLosQuerier;
|
2011-04-05 22:32:03 +02:00
|
|
|
class CSimulation2;
|
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
/**
|
|
|
|
* Maintains the LOS (fog-of-war / shroud-of-darkness) texture, used for
|
|
|
|
* rendering and for the minimap.
|
|
|
|
*/
|
|
|
|
class CLOSTexture
|
|
|
|
{
|
|
|
|
NONCOPYABLE(CLOSTexture);
|
|
|
|
friend class TestLOSTexture;
|
|
|
|
|
|
|
|
public:
|
2011-04-05 22:32:03 +02:00
|
|
|
CLOSTexture(CSimulation2& simulation);
|
2011-02-03 02:12:24 +01:00
|
|
|
~CLOSTexture();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Marks the LOS texture as needing recomputation. Call this after each
|
|
|
|
* simulation update, to ensure responsive updates.
|
|
|
|
*/
|
|
|
|
void MakeDirty();
|
|
|
|
|
2011-03-26 21:17:21 +01:00
|
|
|
/**
|
|
|
|
* Recomputes the LOS texture if necessary, and returns the texture handle.
|
|
|
|
* Also potentially switches the current active texture unit, and enables texturing on it.
|
|
|
|
* The texture is in 8-bit ALPHA format.
|
|
|
|
*/
|
2021-12-30 17:37:51 +01:00
|
|
|
Renderer::Backend::GL::CTexture* GetTexture();
|
2014-07-14 19:15:22 +02:00
|
|
|
|
2012-08-07 00:38:42 +02:00
|
|
|
void InterpolateLOS();
|
2021-12-30 17:37:51 +01:00
|
|
|
Renderer::Backend::GL::CTexture* GetTextureSmooth();
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
/**
|
|
|
|
* Returns a matrix to map (x,y,z) world coordinates onto (u,v) LOS texture
|
2021-10-11 14:39:01 +02:00
|
|
|
* coordinates, in the form expected by a matrix uniform.
|
2011-02-03 02:12:24 +01:00
|
|
|
* This must only be called after BindTexture.
|
|
|
|
*/
|
2012-01-29 13:04:39 +01:00
|
|
|
const CMatrix3D& GetTextureMatrix();
|
2011-02-03 02:12:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a matrix to map (0,0)-(1,1) texture coordinates onto LOS texture
|
2021-10-11 14:39:01 +02:00
|
|
|
* coordinates, in the form expected by a matrix uniform.
|
2011-02-03 02:12:24 +01:00
|
|
|
* This must only be called after BindTexture.
|
|
|
|
*/
|
2014-07-14 19:15:22 +02:00
|
|
|
const CMatrix3D* GetMinimapTextureMatrix();
|
2011-02-03 02:12:24 +01:00
|
|
|
|
|
|
|
private:
|
2011-05-29 17:02:02 +02:00
|
|
|
void DeleteTexture();
|
2014-10-05 22:02:04 +02:00
|
|
|
bool CreateShader();
|
2021-12-25 01:26:10 +01:00
|
|
|
void ConstructTexture();
|
|
|
|
void RecomputeTexture();
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2014-05-25 15:30:39 +02:00
|
|
|
size_t GetBitmapSize(size_t w, size_t h, size_t* pitch);
|
2020-06-14 22:39:03 +02:00
|
|
|
void GenerateBitmap(const CLosQuerier& los, u8* losData, size_t w, size_t h, size_t pitch);
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2011-04-05 22:32:03 +02:00
|
|
|
CSimulation2& m_Simulation;
|
|
|
|
|
2011-02-03 02:12:24 +01:00
|
|
|
bool m_Dirty;
|
|
|
|
|
2014-10-05 22:02:04 +02:00
|
|
|
bool m_ShaderInitialized;
|
|
|
|
|
2021-12-25 01:26:10 +01:00
|
|
|
std::unique_ptr<Renderer::Backend::GL::CTexture>
|
|
|
|
m_Texture, m_TextureSmooth1, m_TextureSmooth2;
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2012-08-07 00:38:42 +02:00
|
|
|
bool whichTex;
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2012-08-07 00:38:42 +02:00
|
|
|
GLuint m_smoothFbo;
|
2016-11-23 12:18:37 +01:00
|
|
|
CShaderTechniquePtr m_smoothShader;
|
2011-02-03 02:12:24 +01:00
|
|
|
|
2021-03-02 17:44:40 +01:00
|
|
|
size_t m_MapSize; // vertexes per side
|
2011-02-03 02:12:24 +01:00
|
|
|
GLsizei m_TextureSize; // texels per side
|
2011-02-03 03:33:37 +01:00
|
|
|
|
|
|
|
CMatrix3D m_TextureMatrix;
|
|
|
|
CMatrix3D m_MinimapTextureMatrix;
|
2011-02-03 02:12:24 +01:00
|
|
|
};
|
2021-05-31 22:47:03 +02:00
|
|
|
|
2021-12-25 01:26:10 +01:00
|
|
|
#endif // INCLUDED_LOSTEXTURE
|