LCOV - code coverage report
Current view: top level - source/graphics - ShaderTechnique.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 4 36 11.1 %
Date: 2026-12-03 01:19:39 Functions: 1 10 10.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : #include "precompiled.h"
      19             : 
      20             : #include "ShaderTechnique.h"
      21             : 
      22             : #include "graphics/ShaderProgram.h"
      23             : #include "lib/debug.h"
      24             : 
      25             : #include <utility>
      26             : 
      27             : namespace Renderer::Backend { class IShaderProgram; }
      28             : 
      29           0 : CShaderPass::CShaderPass(
      30             :     std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> pipelineState,
      31           0 :     const CShaderProgramPtr& shader)
      32           0 :     : m_Shader(shader), m_PipelineState(std::move(pipelineState))
      33             : {
      34           0 :     ENSURE(shader);
      35           0 : }
      36             : 
      37         130 : CShaderTechnique::CShaderTechnique(
      38             :     const VfsPath& path, const CShaderDefines& defines,
      39         130 :     const PipelineStateDescCallback& callback)
      40         130 :     : m_Path(path), m_Defines(defines), m_PipelineStateDescCallback(callback)
      41             : {
      42         130 : }
      43             : 
      44           0 : void CShaderTechnique::SetPasses(std::vector<CShaderPass>&& passes)
      45             : {
      46           0 :     ENSURE(!m_ComputePipelineState);
      47           0 :     m_Passes = std::move(passes);
      48           0 : }
      49             : 
      50           0 : void CShaderTechnique::SetComputePipelineState(
      51             :     std::unique_ptr<Renderer::Backend::IComputePipelineState> pipelineState,
      52             :     const CShaderProgramPtr& computeShader)
      53             : {
      54           0 :     ENSURE(m_Passes.empty());
      55           0 :     m_ComputePipelineState = std::move(pipelineState);
      56           0 :     m_ComputeShader = computeShader;
      57           0 : }
      58             : 
      59           0 : int CShaderTechnique::GetNumPasses() const
      60             : {
      61           0 :     return m_Passes.size();
      62             : }
      63             : 
      64           0 : Renderer::Backend::IShaderProgram* CShaderTechnique::GetShader(int pass) const
      65             : {
      66           0 :     if (m_ComputeShader)
      67             :     {
      68           0 :         ENSURE(pass == 0);
      69           0 :         return m_ComputeShader->GetBackendShaderProgram();
      70             :     }
      71             :     else
      72             :     {
      73           0 :         ENSURE(0 <= pass && pass < (int)m_Passes.size());
      74           0 :         return m_Passes[pass].GetPipelineState()->GetShaderProgram();
      75             :     }
      76             : }
      77             : 
      78             : Renderer::Backend::IGraphicsPipelineState*
      79           0 : CShaderTechnique::GetGraphicsPipelineState(int pass) const
      80             : {
      81           0 :     ENSURE(0 <= pass && pass < static_cast<int>(m_Passes.size()));
      82           0 :     return m_Passes[pass].GetPipelineState();
      83             : }
      84             : 
      85             : Renderer::Backend::IComputePipelineState*
      86           0 : CShaderTechnique::GetComputePipelineState() const
      87             : {
      88           0 :     return m_ComputePipelineState.get();
      89             : }
      90             : 
      91           0 : bool CShaderTechnique::GetSortByDistance() const
      92             : {
      93           0 :     return m_SortByDistance;
      94             : }
      95             : 
      96           0 : void CShaderTechnique::SetSortByDistance(bool enable)
      97             : {
      98           0 :     m_SortByDistance = enable;
      99           0 : }

Generated by: LCOV version 1.16