LCOV - code coverage report
Current view: top level - source/graphics - ShaderTechnique.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 2 7 28.6 %
Date: 2023-01-19 00:18:29 Functions: 2 7 28.6 %

          Line data    Source code
       1             : /* Copyright (C) 2022 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_SHADERTECHNIQUE
      19             : #define INCLUDED_SHADERTECHNIQUE
      20             : 
      21             : #include "graphics/ShaderDefines.h"
      22             : #include "graphics/ShaderProgram.h"
      23             : #include "graphics/ShaderTechniquePtr.h"
      24             : #include "lib/code_annotation.h"
      25             : #include "lib/file/vfs/vfs_path.h"
      26             : #include "renderer/backend/PipelineState.h"
      27             : 
      28             : #include <functional>
      29             : #include <memory>
      30             : #include <vector>
      31             : 
      32             : /**
      33             :  * Implements a render pass consisting of a pipeline state and a shader,
      34             :  * used by CShaderTechnique.
      35             :  */
      36           0 : class CShaderPass
      37             : {
      38             : public:
      39             :     CShaderPass(
      40             :         std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> pipelineState,
      41             :         const CShaderProgramPtr& shader);
      42           0 :     MOVABLE(CShaderPass);
      43             : 
      44             :     const CShaderProgramPtr& GetShaderProgram() const noexcept { return m_Shader; }
      45             : 
      46             :     Renderer::Backend::IGraphicsPipelineState*
      47           0 :     GetPipelineState() const noexcept { return m_PipelineState.get(); }
      48             : 
      49             : private:
      50             :     CShaderProgramPtr m_Shader;
      51             : 
      52             :     std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> m_PipelineState;
      53             : };
      54             : 
      55             : /**
      56             :  * Implements a render technique consisting of a sequence of passes.
      57             :  * CShaderManager loads these from shader effect XML files.
      58             :  */
      59          60 : class CShaderTechnique
      60             : {
      61             : public:
      62             :     using PipelineStateDescCallback =
      63             :         std::function<void(Renderer::Backend::SGraphicsPipelineStateDesc& pipelineStateDesc)>;
      64             : 
      65             :     CShaderTechnique(const VfsPath& path, const CShaderDefines& defines, const PipelineStateDescCallback& callback);
      66             : 
      67             :     void SetPasses(std::vector<CShaderPass>&& passes);
      68             : 
      69             :     int GetNumPasses() const;
      70             : 
      71             :     Renderer::Backend::IShaderProgram* GetShader(int pass = 0) const;
      72             : 
      73             :     Renderer::Backend::IGraphicsPipelineState*
      74             :     GetGraphicsPipelineState(int pass = 0) const;
      75             : 
      76             :     /**
      77             :      * Whether this technique uses alpha blending that requires objects to be
      78             :      * drawn from furthest to nearest.
      79             :      */
      80             :     bool GetSortByDistance() const;
      81             : 
      82             :     void SetSortByDistance(bool enable);
      83             : 
      84         180 :     const VfsPath& GetPath() { return m_Path; }
      85             : 
      86           0 :     const CShaderDefines& GetShaderDefines() { return m_Defines; }
      87             : 
      88           0 :     const PipelineStateDescCallback& GetPipelineStateDescCallback() const { return m_PipelineStateDescCallback; };
      89             : 
      90             : private:
      91             :     std::vector<CShaderPass> m_Passes;
      92             : 
      93             :     bool m_SortByDistance = false;
      94             : 
      95             :     // We need additional data to reload the technique.
      96             :     VfsPath m_Path;
      97             :     CShaderDefines m_Defines;
      98             : 
      99             :     PipelineStateDescCallback m_PipelineStateDescCallback;
     100             : };
     101             : 
     102             : #endif // INCLUDED_SHADERTECHNIQUE

Generated by: LCOV version 1.13