2022-01-14 18:34:58 +01:00
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2009-04-18 19:00:33 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_PATCHRDATA
|
|
|
|
#define INCLUDED_PATCHRDATA
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2019-06-12 22:03:22 +02:00
|
|
|
#include "graphics/Patch.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "graphics/RenderableObject.h"
|
2020-11-04 16:53:33 +01:00
|
|
|
#include "maths/Vector2D.h"
|
|
|
|
#include "maths/Vector3D.h"
|
2022-01-19 18:28:47 +01:00
|
|
|
#include "renderer/backend/gl/DeviceCommandContext.h"
|
2022-03-14 23:16:14 +01:00
|
|
|
#include "renderer/backend/gl/ShaderProgram.h"
|
2019-06-12 22:03:22 +02:00
|
|
|
#include "renderer/VertexBufferManager.h"
|
|
|
|
|
|
|
|
#include <vector>
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
class CPatch;
|
2019-06-12 22:03:22 +02:00
|
|
|
class CShaderDefines;
|
2012-09-28 20:20:36 +02:00
|
|
|
class CSimulation2;
|
2010-09-10 23:02:10 +02:00
|
|
|
class CTerrainTextureEntry;
|
2012-02-12 21:45:31 +01:00
|
|
|
class CTextRenderer;
|
2014-06-25 03:11:10 +02:00
|
|
|
class ShadowMap;
|
2004-06-11 00:24:03 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// CPatchRData: class encapsulating logic for rendering terrain patches; holds per
|
2004-06-07 21:53:58 +02:00
|
|
|
// patch data, plus some supporting static functions for batching, etc
|
2004-05-29 22:53:40 +02:00
|
|
|
class CPatchRData : public CRenderData
|
|
|
|
{
|
|
|
|
public:
|
2012-09-28 20:20:36 +02:00
|
|
|
CPatchRData(CPatch* patch, CSimulation2* simulation);
|
2006-01-07 02:04:26 +01:00
|
|
|
~CPatchRData();
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2012-09-28 20:20:36 +02:00
|
|
|
void Update(CSimulation2* simulation);
|
2004-05-29 22:53:40 +02:00
|
|
|
void RenderOutline();
|
2012-02-12 21:45:31 +01:00
|
|
|
void RenderPriorities(CTextRenderer& textRenderer);
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2022-02-18 18:33:12 +01:00
|
|
|
void RenderWaterSurface(
|
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2022-03-14 23:16:14 +01:00
|
|
|
Renderer::Backend::GL::CShaderProgram* shader, const bool bindWaterData);
|
2022-02-18 18:33:12 +01:00
|
|
|
void RenderWaterShore(
|
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2022-03-14 23:16:14 +01:00
|
|
|
Renderer::Backend::GL::CShaderProgram* shader);
|
2011-07-13 01:48:05 +02:00
|
|
|
|
2011-03-13 20:22:05 +01:00
|
|
|
CPatch* GetPatch() { return m_Patch; }
|
2016-11-23 12:18:37 +01:00
|
|
|
|
2011-11-25 07:36:13 +01:00
|
|
|
const CBoundingBoxAligned& GetWaterBounds() const { return m_WaterBounds; }
|
2011-07-13 01:48:05 +02:00
|
|
|
|
2021-02-02 16:34:52 +01:00
|
|
|
static void RenderBases(
|
2022-01-19 18:28:47 +01:00
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2021-02-02 16:34:52 +01:00
|
|
|
const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
|
|
|
|
static void RenderBlends(
|
2022-01-19 18:28:47 +01:00
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2021-02-02 16:34:52 +01:00
|
|
|
const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
|
2022-02-18 18:33:12 +01:00
|
|
|
static void RenderStreams(
|
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2022-03-14 23:16:14 +01:00
|
|
|
const std::vector<CPatchRData*>& patches, Renderer::Backend::GL::CShaderProgram* shader,
|
2022-03-06 21:53:39 +01:00
|
|
|
const bool bindPositionAsTexCoord);
|
2022-02-18 18:33:12 +01:00
|
|
|
static void RenderSides(
|
|
|
|
Renderer::Backend::GL::CDeviceCommandContext* deviceCommandContext,
|
2022-03-14 23:16:14 +01:00
|
|
|
const std::vector<CPatchRData*>& patches, Renderer::Backend::GL::CShaderProgram* shader);
|
2021-02-02 16:34:52 +01:00
|
|
|
|
2022-03-14 23:16:14 +01:00
|
|
|
static void PrepareShader(Renderer::Backend::GL::CShaderProgram* shader, ShadowMap* shadow);
|
2021-02-02 16:34:52 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
private:
|
2011-03-30 23:42:35 +02:00
|
|
|
friend struct SBlendStackItem;
|
|
|
|
|
2021-02-02 16:34:52 +01:00
|
|
|
struct SSplat
|
|
|
|
{
|
2006-02-13 15:18:20 +01:00
|
|
|
SSplat() : m_Texture(0), m_IndexCount(0) {}
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
// texture to apply during splat
|
|
|
|
CTerrainTextureEntry* m_Texture;
|
2004-06-11 00:24:03 +02:00
|
|
|
// offset into the index array for this patch where splat starts
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t m_IndexStart;
|
2004-06-11 00:24:03 +02:00
|
|
|
// number of indices used by splat
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t m_IndexCount;
|
2004-06-11 00:24:03 +02:00
|
|
|
};
|
|
|
|
|
2021-02-02 16:34:52 +01:00
|
|
|
struct SBaseVertex
|
|
|
|
{
|
2004-06-11 00:24:03 +02:00
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2012-08-07 20:21:16 +02:00
|
|
|
CVector3D m_Normal;
|
2015-01-25 16:38:51 +01:00
|
|
|
// pad to a power of two
|
2020-11-04 13:54:17 +01:00
|
|
|
u8 m_Padding[8];
|
2006-02-13 15:18:20 +01:00
|
|
|
};
|
2015-01-25 16:38:51 +01:00
|
|
|
cassert(sizeof(SBaseVertex) == 32);
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2021-02-02 16:34:52 +01:00
|
|
|
struct SSideVertex
|
|
|
|
{
|
2011-02-03 15:36:54 +01:00
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2015-01-25 16:38:51 +01:00
|
|
|
// pad to a power of two
|
|
|
|
u8 m_Padding[4];
|
2011-02-03 15:36:54 +01:00
|
|
|
};
|
2011-03-13 20:06:33 +01:00
|
|
|
cassert(sizeof(SSideVertex) == 16);
|
2011-02-03 15:36:54 +01:00
|
|
|
|
2021-02-02 16:34:52 +01:00
|
|
|
struct SBlendVertex
|
|
|
|
{
|
2004-06-11 00:24:03 +02:00
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
|
|
|
// vertex uvs for alpha texture
|
|
|
|
float m_AlphaUVs[2];
|
2012-08-07 20:21:16 +02:00
|
|
|
CVector3D m_Normal;
|
2006-02-13 15:18:20 +01:00
|
|
|
};
|
2020-11-04 13:54:17 +01:00
|
|
|
cassert(sizeof(SBlendVertex) == 32);
|
2004-06-11 00:24:03 +02:00
|
|
|
|
2011-07-13 01:48:05 +02:00
|
|
|
// Mixed Fancy/Simple water vertex description data structure
|
2021-02-02 16:34:52 +01:00
|
|
|
struct SWaterVertex
|
|
|
|
{
|
2011-07-13 01:48:05 +02:00
|
|
|
// vertex position
|
|
|
|
CVector3D m_Position;
|
2014-07-28 12:14:00 +02:00
|
|
|
CVector2D m_WaterData;
|
2015-01-25 16:38:51 +01:00
|
|
|
// pad to a power of two
|
|
|
|
u8 m_Padding[12];
|
2011-07-13 01:48:05 +02:00
|
|
|
};
|
2015-01-25 16:38:51 +01:00
|
|
|
cassert(sizeof(SWaterVertex) == 32);
|
2011-07-13 01:48:05 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// build this renderdata object
|
|
|
|
void Build();
|
|
|
|
|
2016-11-23 12:18:37 +01:00
|
|
|
void AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices,
|
2012-08-07 20:21:16 +02:00
|
|
|
u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture);
|
2011-01-29 17:31:48 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
void BuildBlends();
|
|
|
|
void BuildIndices();
|
|
|
|
void BuildVertices();
|
2011-02-03 15:36:54 +01:00
|
|
|
void BuildSides();
|
|
|
|
|
|
|
|
void BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side);
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
// owner patch
|
|
|
|
CPatch* m_Patch;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2011-03-13 20:10:38 +01:00
|
|
|
// vertex buffer handle for side vertices
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBSides;
|
2011-03-13 20:10:38 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// vertex buffer handle for base vertices
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBBase;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2011-03-13 20:06:33 +01:00
|
|
|
// vertex buffer handle for base vertex indices
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBBaseIndices;
|
2011-03-13 20:06:33 +01:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// vertex buffer handle for blend vertices
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBBlends;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2011-03-13 20:10:38 +01:00
|
|
|
// vertex buffer handle for blend vertex indices
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBBlendIndices;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// list of base splats to apply to this patch
|
|
|
|
std::vector<SSplat> m_Splats;
|
2005-10-09 10:14:42 +02:00
|
|
|
|
2004-05-29 22:53:40 +02:00
|
|
|
// splats used in blend pass
|
2004-06-11 00:24:03 +02:00
|
|
|
std::vector<SSplat> m_BlendSplats;
|
2011-07-13 01:48:05 +02:00
|
|
|
|
|
|
|
// boundary of water in this patch
|
2011-11-25 07:36:13 +01:00
|
|
|
CBoundingBoxAligned m_WaterBounds;
|
2011-07-13 01:48:05 +02:00
|
|
|
|
|
|
|
// Water vertex buffer
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBWater;
|
|
|
|
CVertexBufferManager::Handle m_VBWaterShore;
|
2011-07-13 01:48:05 +02:00
|
|
|
|
|
|
|
// Water indices buffer
|
2021-02-08 23:34:10 +01:00
|
|
|
CVertexBufferManager::Handle m_VBWaterIndices;
|
|
|
|
CVertexBufferManager::Handle m_VBWaterIndicesShore;
|
2011-07-13 01:48:05 +02:00
|
|
|
|
2012-09-28 20:20:36 +02:00
|
|
|
CSimulation2* m_Simulation;
|
|
|
|
|
2011-07-13 01:48:05 +02:00
|
|
|
// Build water vertices and indices (vertex buffer and data vector)
|
|
|
|
void BuildWater();
|
|
|
|
|
|
|
|
// parameter allowing a varying number of triangles per patch for LOD
|
|
|
|
// MUST be an exact divisor of PATCH_SIZE
|
|
|
|
// compiled const for the moment until/if dynamic water LOD is offered
|
|
|
|
// savings would be mostly beneficial for GPU or simple water
|
|
|
|
static const ssize_t water_cell_size = 1;
|
2004-05-29 22:53:40 +02:00
|
|
|
};
|
|
|
|
|
2019-06-12 22:03:22 +02:00
|
|
|
#endif // INCLUDED_PATCHRDATA
|