LCOV - code coverage report
Current view: top level - source/renderer - PatchRData.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 7 0.0 %
Date: 2021-09-24 14:46:47 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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"
      22             : #include "graphics/RenderableObject.h"
      23             : #include "graphics/ShaderProgramPtr.h"
      24             : #include "maths/Vector2D.h"
      25             : #include "maths/Vector3D.h"
      26             : #include "renderer/VertexBufferManager.h"
      27             : 
      28             : #include <vector>
      29             : 
      30             : class CPatch;
      31             : class CShaderDefines;
      32             : class CSimulation2;
      33             : class CTerrainTextureEntry;
      34             : class CTextRenderer;
      35             : class ShadowMap;
      36             : 
      37             : //////////////////////////////////////////////////////////////////////////////////////////////////
      38             : // CPatchRData: class encapsulating logic for rendering terrain patches; holds per
      39             : // patch data, plus some supporting static functions for batching, etc
      40           0 : class CPatchRData : public CRenderData
      41             : {
      42             : public:
      43             :     CPatchRData(CPatch* patch, CSimulation2* simulation);
      44             :     ~CPatchRData();
      45             : 
      46             :     void Update(CSimulation2* simulation);
      47             :     void RenderOutline();
      48             :     void RenderPriorities(CTextRenderer& textRenderer);
      49             : 
      50             :     void RenderWater(CShaderProgramPtr& shader, bool onlyShore = false, bool fixedPipeline = false);
      51             : 
      52             :     CPatch* GetPatch() { return m_Patch; }
      53             : 
      54           0 :     const CBoundingBoxAligned& GetWaterBounds() const { return m_WaterBounds; }
      55             : 
      56             :     static void RenderBases(
      57             :         const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
      58             :     static void RenderBlends(
      59             :         const std::vector<CPatchRData*>& patches, const CShaderDefines& context, ShadowMap* shadow);
      60             :     static void RenderStreams(const std::vector<CPatchRData*>& patches, const CShaderProgramPtr& shader, int streamflags);
      61             :     static void RenderSides(const std::vector<CPatchRData*>& patches, const CShaderProgramPtr& shader);
      62             : 
      63             :     static void PrepareShader(const CShaderProgramPtr& shader, ShadowMap* shadow);
      64             : 
      65             : private:
      66             :     friend struct SBlendStackItem;
      67             : 
      68             :     struct SSplat
      69             :     {
      70           0 :         SSplat() : m_Texture(0), m_IndexCount(0) {}
      71             : 
      72             :         // texture to apply during splat
      73             :         CTerrainTextureEntry* m_Texture;
      74             :         // offset into the index array for this patch where splat starts
      75             :         size_t m_IndexStart;
      76             :         // number of indices used by splat
      77             :         size_t m_IndexCount;
      78             :     };
      79             : 
      80           0 :     struct SBaseVertex
      81             :     {
      82             :         // vertex position
      83             :         CVector3D m_Position;
      84             :         CVector3D m_Normal;
      85             :         // pad to a power of two
      86             :         u8 m_Padding[8];
      87             :     };
      88             :     cassert(sizeof(SBaseVertex) == 32);
      89             : 
      90           0 :     struct SSideVertex
      91             :     {
      92             :         // vertex position
      93             :         CVector3D m_Position;
      94             :         // pad to a power of two
      95             :         u8 m_Padding[4];
      96             :     };
      97             :     cassert(sizeof(SSideVertex) == 16);
      98             : 
      99           0 :     struct SBlendVertex
     100             :     {
     101             :         // vertex position
     102             :         CVector3D m_Position;
     103             :         // vertex uvs for alpha texture
     104             :         float m_AlphaUVs[2];
     105             :         CVector3D m_Normal;
     106             :     };
     107             :     cassert(sizeof(SBlendVertex) == 32);
     108             : 
     109             :     // Mixed Fancy/Simple water vertex description data structure
     110           0 :     struct SWaterVertex
     111             :     {
     112             :         // vertex position
     113             :         CVector3D m_Position;
     114             :         CVector2D m_WaterData;
     115             :         // pad to a power of two
     116             :         u8 m_Padding[12];
     117             :     };
     118             :     cassert(sizeof(SWaterVertex) == 32);
     119             : 
     120             :     // build this renderdata object
     121             :     void Build();
     122             : 
     123             :     void AddBlend(std::vector<SBlendVertex>& blendVertices, std::vector<u16>& blendIndices,
     124             :                u16 i, u16 j, u8 shape, CTerrainTextureEntry* texture);
     125             : 
     126             :     void BuildBlends();
     127             :     void BuildIndices();
     128             :     void BuildVertices();
     129             :     void BuildSides();
     130             : 
     131             :     void BuildSide(std::vector<SSideVertex>& vertices, CPatchSideFlags side);
     132             : 
     133             :     // owner patch
     134             :     CPatch* m_Patch;
     135             : 
     136             :     // vertex buffer handle for side vertices
     137             :     CVertexBufferManager::Handle m_VBSides;
     138             : 
     139             :     // vertex buffer handle for base vertices
     140             :     CVertexBufferManager::Handle m_VBBase;
     141             : 
     142             :     // vertex buffer handle for base vertex indices
     143             :     CVertexBufferManager::Handle m_VBBaseIndices;
     144             : 
     145             :     // vertex buffer handle for blend vertices
     146             :     CVertexBufferManager::Handle m_VBBlends;
     147             : 
     148             :     // vertex buffer handle for blend vertex indices
     149             :     CVertexBufferManager::Handle m_VBBlendIndices;
     150             : 
     151             :     // list of base splats to apply to this patch
     152             :     std::vector<SSplat> m_Splats;
     153             : 
     154             :     // splats used in blend pass
     155             :     std::vector<SSplat> m_BlendSplats;
     156             : 
     157             :     // boundary of water in this patch
     158             :     CBoundingBoxAligned m_WaterBounds;
     159             : 
     160             :     // Water vertex buffer
     161             :     CVertexBufferManager::Handle m_VBWater;
     162             :     CVertexBufferManager::Handle m_VBWaterShore;
     163             : 
     164             :     // Water indices buffer
     165             :     CVertexBufferManager::Handle m_VBWaterIndices;
     166             :     CVertexBufferManager::Handle m_VBWaterIndicesShore;
     167             : 
     168             :     CSimulation2* m_Simulation;
     169             : 
     170             :     // Build water vertices and indices (vertex buffer and data vector)
     171             :     void BuildWater();
     172             : 
     173             :     // parameter allowing a varying number of triangles per patch for LOD
     174             :     // MUST be an exact divisor of PATCH_SIZE
     175             :     // compiled const for the moment until/if dynamic water LOD is offered
     176             :     // savings would be mostly beneficial for GPU or simple water
     177             :     static const ssize_t water_cell_size = 1;
     178             : };
     179             : 
     180             : #endif // INCLUDED_PATCHRDATA

Generated by: LCOV version 1.13