Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
PatchRData.h
Go to the documentation of this file.
1/* Copyright (C) 2023 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#ifndef INCLUDED_PATCHRDATA
19#define INCLUDED_PATCHRDATA
20
21#include "graphics/Patch.h"
23#include "maths/Vector2D.h"
24#include "maths/Vector3D.h"
28
29#include <vector>
30
31class CPatch;
32class CShaderDefines;
33class CSimulation2;
35class CTextRenderer;
36class ShadowMap;
37
38//////////////////////////////////////////////////////////////////////////////////////////////////
39// CPatchRData: class encapsulating logic for rendering terrain patches; holds per
40// patch data, plus some supporting static functions for batching, etc
42{
43public:
44 CPatchRData(CPatch* patch, CSimulation2* simulation);
46
50 const bool bindPositionAsTexCoord);
52
54 const bool bindWaterData);
56
57 void Update(CSimulation2* simulation);
58 void RenderOutline();
59 void RenderPriorities(CTextRenderer& textRenderer);
60
62 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
63 Renderer::Backend::IVertexInputLayout* vertexInputLayout);
65 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
66 Renderer::Backend::IVertexInputLayout* vertexInputLayout);
67
68 CPatch* GetPatch() { return m_Patch; }
69
71
72 static void RenderBases(
73 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
75 const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
76 static void RenderBlends(
77 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
79 const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
80 static void RenderStreams(
81 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
83 const std::vector<CPatchRData*>& patches);
84 static void RenderSides(
85 Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
87 const std::vector<CPatchRData*>& patches);
88
89 static void PrepareShader(ShadowMap* shadow);
90
91private:
92 friend struct SBlendStackItem;
93
94 struct SSplat
95 {
97
98 // texture to apply during splat
100 // offset into the index array for this patch where splat starts
102 // number of indices used by splat
104 };
105
107 {
108 // vertex position
111 // pad to a power of two
113 };
114 cassert(sizeof(SBaseVertex) == 32);
115
117 {
118 // vertex position
120 // pad to a power of two
122 };
123 cassert(sizeof(SSideVertex) == 16);
124
126 {
127 // vertex position
129 // vertex uvs for alpha texture
130 float m_AlphaUVs[2];
132 };
133 cassert(sizeof(SBlendVertex) == 32);
134
135 // Mixed Fancy/Simple water vertex description data structure
137 {
138 // vertex position
141 // pad to a power of two
143 };
144 cassert(sizeof(SWaterVertex) == 32);
145
146 // build this renderdata object
147 void Build();
148
149 void AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices,
150 u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture);
151
152 void BuildBlends();
153 void BuildIndices();
154 void BuildVertices();
155 void BuildSides();
156
157 void BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side);
158
159 // owner patch
161
162 // vertex buffer handle for side vertices
164
165 // vertex buffer handle for base vertices
167
168 // vertex buffer handle for base vertex indices
170
171 // vertex buffer handle for blend vertices
173
174 // vertex buffer handle for blend vertex indices
176
177 // list of base splats to apply to this patch
178 std::vector<SSplat> m_Splats;
179
180 // splats used in blend pass
181 std::vector<SSplat> m_BlendSplats;
182
183 // boundary of water in this patch
185
186 // Water vertex buffer
189
190 // Water indices buffer
193
195
196 // Build water vertices and indices (vertex buffer and data vector)
197 void BuildWater();
198
199 // parameter allowing a varying number of triangles per patch for LOD
200 // MUST be an exact divisor of PATCH_SIZE
201 // compiled const for the moment until/if dynamic water LOD is offered
202 // savings would be mostly beneficial for GPU or simple water
203 static const ssize_t water_cell_size = 1;
204};
205
206#endif // INCLUDED_PATCHRDATA
CPatchSideFlags
Definition: Patch.h:39
Definition: BoundingBoxAligned.h:34
Definition: PatchRData.h:42
void BuildSides()
Definition: PatchRData.cpp:749
void BuildVertices()
Definition: PatchRData.cpp:647
static void PrepareShader(ShadowMap *shadow)
void AddBlend(std::vector< SBlendVertex > &blendVertices, std::vector< u16 > &blendIndices, u16 i, u16 j, u8 shape, CTerrainTextureEntry *texture)
Definition: PatchRData.cpp:443
CSimulation2 * m_Simulation
Definition: PatchRData.h:194
static Renderer::Backend::IVertexInputLayout * GetSideVertexInputLayout()
Definition: PatchRData.cpp:145
void BuildIndices()
Definition: PatchRData.cpp:550
static Renderer::Backend::IVertexInputLayout * GetBaseVertexInputLayout()
Definition: PatchRData.cpp:68
static Renderer::Backend::IVertexInputLayout * GetWaterShoreVertexInputLayout()
Definition: PatchRData.cpp:190
CPatch * m_Patch
Definition: PatchRData.h:160
static Renderer::Backend::IVertexInputLayout * GetStreamVertexInputLayout(const bool bindPositionAsTexCoord)
Definition: PatchRData.cpp:114
std::vector< SSplat > m_BlendSplats
Definition: PatchRData.h:181
static Renderer::Backend::IVertexInputLayout * GetWaterSurfaceVertexInputLayout(const bool bindWaterData)
Definition: PatchRData.cpp:158
CVertexBufferManager::Handle m_VBWaterIndices
Definition: PatchRData.h:191
static void RenderBlends(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout, const std::vector< CPatchRData * > &patches, const CShaderDefines &context, ShadowMap *shadow)
Definition: PatchRData.cpp:1021
CVertexBufferManager::Handle m_VBBase
Definition: PatchRData.h:166
void RenderOutline()
Definition: PatchRData.cpp:1281
void RenderWaterShore(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout)
Definition: PatchRData.cpp:1605
static const ssize_t water_cell_size
Definition: PatchRData.h:203
const CBoundingBoxAligned & GetWaterBounds() const
Definition: PatchRData.h:70
CVertexBufferManager::Handle m_VBBlendIndices
Definition: PatchRData.h:175
CPatch * GetPatch()
Definition: PatchRData.h:68
void BuildBlends()
Definition: PatchRData.cpp:271
CVertexBufferManager::Handle m_VBWaterIndicesShore
Definition: PatchRData.h:192
void Build()
Definition: PatchRData.cpp:790
void RenderPriorities(CTextRenderer &textRenderer)
Definition: PatchRData.cpp:1347
static void RenderStreams(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout, const std::vector< CPatchRData * > &patches)
Definition: PatchRData.cpp:1224
CVertexBufferManager::Handle m_VBBaseIndices
Definition: PatchRData.h:169
void Update(CSimulation2 *simulation)
Definition: PatchRData.cpp:799
CVertexBufferManager::Handle m_VBBlends
Definition: PatchRData.h:172
CBoundingBoxAligned m_WaterBounds
Definition: PatchRData.h:184
static void RenderSides(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout, const std::vector< CPatchRData * > &patches)
Definition: PatchRData.cpp:1313
CPatchRData(CPatch *patch, CSimulation2 *simulation)
Definition: PatchRData.cpp:206
cassert(sizeof(SSideVertex)==16)
cassert(sizeof(SWaterVertex)==32)
CVertexBufferManager::Handle m_VBSides
Definition: PatchRData.h:163
void RenderWaterSurface(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout)
Definition: PatchRData.cpp:1578
void BuildWater()
Definition: PatchRData.cpp:1379
static Renderer::Backend::IVertexInputLayout * GetBlendVertexInputLayout()
Definition: PatchRData.cpp:89
std::vector< SSplat > m_Splats
Definition: PatchRData.h:178
static void RenderBases(Renderer::Backend::IDeviceCommandContext *deviceCommandContext, Renderer::Backend::IVertexInputLayout *vertexInputLayout, const std::vector< CPatchRData * > &patches, const CShaderDefines &context, ShadowMap *shadow)
Definition: PatchRData.cpp:861
cassert(sizeof(SBaseVertex)==32)
void BuildSide(std::vector< SSideVertex > &vertices, CPatchSideFlags side)
Definition: PatchRData.cpp:696
CVertexBufferManager::Handle m_VBWater
Definition: PatchRData.h:187
CVertexBufferManager::Handle m_VBWaterShore
Definition: PatchRData.h:188
cassert(sizeof(SBlendVertex)==32)
Definition: Patch.h:49
Definition: RenderableObject.h:41
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:147
Public API for simulation system.
Definition: Simulation2.h:47
Definition: TerrainTextureEntry.h:33
Definition: TextRenderer.h:34
Definition: Vector2D.h:32
Definition: Vector3D.h:31
Definition: VertexBufferManager.h:49
Definition: IDeviceCommandContext.h:42
IVertexInputLayout stores precompiled list of vertex attributes.
Definition: IShaderProgram.h:74
Class ShadowMap: Maintain the shadow map texture and perform necessary OpenGL setup,...
Definition: ShadowMap.h:39
Definition: PatchRData.h:107
CVector3D m_Normal
Definition: PatchRData.h:110
u8 m_Padding[8]
Definition: PatchRData.h:112
CVector3D m_Position
Definition: PatchRData.h:109
Definition: PatchRData.h:126
CVector3D m_Position
Definition: PatchRData.h:128
float m_AlphaUVs[2]
Definition: PatchRData.h:130
CVector3D m_Normal
Definition: PatchRData.h:131
Definition: PatchRData.h:117
CVector3D m_Position
Definition: PatchRData.h:119
u8 m_Padding[4]
Definition: PatchRData.h:121
Definition: PatchRData.h:95
SSplat()
Definition: PatchRData.h:96
size_t m_IndexCount
Definition: PatchRData.h:103
CTerrainTextureEntry * m_Texture
Definition: PatchRData.h:99
size_t m_IndexStart
Definition: PatchRData.h:101
Definition: PatchRData.h:137
CVector3D m_Position
Definition: PatchRData.h:139
u8 m_Padding[12]
Definition: PatchRData.h:142
CVector2D m_WaterData
Definition: PatchRData.h:140
Helper structure for RenderBlends.
Definition: PatchRData.cpp:1008
uint8_t u8
Definition: types.h:37
uint16_t u16
Definition: types.h:38
intptr_t ssize_t
Definition: wposix_types.h:82