1 /* Copyright (C) 2012 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_PATCHRDATA
19 #define INCLUDED_PATCHRDATA
22 #include "graphics/SColor.h"
23 #include "maths/Vector3D.h"
24 #include "maths/Vector2D.h"
25 #include "graphics/RenderableObject.h"
26 #include "graphics/ShaderProgramPtr.h"
27 #include "VertexBufferManager.h"
31 class CTerrainTextureEntry
;
35 //////////////////////////////////////////////////////////////////////////////////////////////////
36 // CPatchRData: class encapsulating logic for rendering terrain patches; holds per
37 // patch data, plus some supporting static functions for batching, etc
38 class CPatchRData
: public CRenderData
41 CPatchRData(CPatch
* patch
, CSimulation2
* simulation
);
44 void Update(CSimulation2
* simulation
);
46 void RenderSides(CShaderProgramPtr
& shader
);
47 void RenderPriorities(CTextRenderer
& textRenderer
);
49 void RenderWater(CShaderProgramPtr
& shader
, bool onlyShore
= false, bool fixedPipeline
= false);
51 static void RenderBases(const std::vector
<CPatchRData
*>& patches
, const CShaderDefines
& context
,
52 ShadowMap
* shadow
, bool isDummyShader
=false, const CShaderProgramPtr
& dummy
=CShaderProgramPtr());
53 static void RenderBlends(const std::vector
<CPatchRData
*>& patches
, const CShaderDefines
& context
,
54 ShadowMap
* shadow
, bool isDummyShader
=false, const CShaderProgramPtr
& dummy
=CShaderProgramPtr());
55 static void RenderStreams(const std::vector
<CPatchRData
*>& patches
, const CShaderProgramPtr
& shader
, int streamflags
);
57 CPatch
* GetPatch() { return m_Patch
; }
59 static void PrepareShader(const CShaderProgramPtr
& shader
, ShadowMap
* shadow
);
61 const CBoundingBoxAligned
& GetWaterBounds() const { return m_WaterBounds
; }
64 friend struct SBlendStackItem
;
67 SSplat() : m_Texture(0), m_IndexCount(0) {}
69 // texture to apply during splat
70 CTerrainTextureEntry
* m_Texture
;
71 // offset into the index array for this patch where splat starts
73 // number of indices used by splat
80 // diffuse color from sunlight
81 SColor4ub m_DiffuseColor
;
83 // pad to a power of two
86 cassert(sizeof(SBaseVertex
) == 32);
91 // pad to a power of two
94 cassert(sizeof(SSideVertex
) == 16);
99 // diffuse color from sunlight
100 SColor4ub m_DiffuseColor
;
101 // vertex uvs for alpha texture
104 // pad to a power of two
107 cassert(sizeof(SBlendVertex
) == 64);
109 // Mixed Fancy/Simple water vertex description data structure
110 struct SWaterVertex
{
112 CVector3D m_Position
;
113 CVector2D m_WaterData
;
114 // pad to a power of two
117 cassert(sizeof(SWaterVertex
) == 32);
119 // build this renderdata object
122 void AddBlend(std::vector
<SBlendVertex
>& blendVertices
, std::vector
<u16
>& blendIndices
,
123 u16 i
, u16 j
, u8 shape
, CTerrainTextureEntry
* texture
);
127 void BuildVertices();
130 void BuildSide(std::vector
<SSideVertex
>& vertices
, CPatchSideFlags side
);
135 // vertex buffer handle for side vertices
136 CVertexBuffer::VBChunk
* m_VBSides
;
138 // vertex buffer handle for base vertices
139 CVertexBuffer::VBChunk
* m_VBBase
;
141 // vertex buffer handle for base vertex indices
142 CVertexBuffer::VBChunk
* m_VBBaseIndices
;
144 // vertex buffer handle for blend vertices
145 CVertexBuffer::VBChunk
* m_VBBlends
;
147 // vertex buffer handle for blend vertex indices
148 CVertexBuffer::VBChunk
* m_VBBlendIndices
;
150 // list of base splats to apply to this patch
151 std::vector
<SSplat
> m_Splats
;
153 // splats used in blend pass
154 std::vector
<SSplat
> m_BlendSplats
;
156 // boundary of water in this patch
157 CBoundingBoxAligned m_WaterBounds
;
159 // Water vertex buffer
160 CVertexBuffer::VBChunk
* m_VBWater
;
161 CVertexBuffer::VBChunk
* m_VBWaterShore
;
163 // Water indices buffer
164 CVertexBuffer::VBChunk
* m_VBWaterIndices
;
165 CVertexBuffer::VBChunk
* m_VBWaterIndicesShore
;
167 CSimulation2
* m_Simulation
;
169 // Build water vertices and indices (vertex buffer and data vector)
172 // parameter allowing a varying number of triangles per patch for LOD
173 // MUST be an exact divisor of PATCH_SIZE
174 // compiled const for the moment until/if dynamic water LOD is offered
175 // savings would be mostly beneficial for GPU or simple water
176 static const ssize_t water_cell_size
= 1;