Pyrogenesis trunk
ShaderTechnique.h
Go to the documentation of this file.
1/* Copyright (C) 2024 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
24#include "lib/code_annotation.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 */
37{
38public:
40 std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> pipelineState,
41 const CShaderProgramPtr& shader);
43
44 const CShaderProgramPtr& GetShaderProgram() const noexcept { return m_Shader; }
45
47 GetPipelineState() const noexcept { return m_PipelineState.get(); }
48
49private:
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 */
60{
61public:
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);
69 std::unique_ptr<Renderer::Backend::IComputePipelineState> pipelineState,
70 const CShaderProgramPtr& computeShader);
71
72 int GetNumPasses() const;
73
75
77 GetGraphicsPipelineState(int pass = 0) const;
78
81
82 /**
83 * Whether this technique uses alpha blending that requires objects to be
84 * drawn from furthest to nearest.
85 */
86 bool GetSortByDistance() const;
87
88 void SetSortByDistance(bool enable);
89
90 const VfsPath& GetPath() { return m_Path; }
91
93
95
96private:
97 std::vector<CShaderPass> m_Passes;
98
99 bool m_SortByDistance = false;
100
101 // We need additional data to reload the technique.
104
106
107 std::unique_ptr<Renderer::Backend::IComputePipelineState> m_ComputePipelineState;
109};
110
111#endif // INCLUDED_SHADERTECHNIQUE
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:26
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:147
Implements a render pass consisting of a pipeline state and a shader, used by CShaderTechnique.
Definition: ShaderTechnique.h:37
std::unique_ptr< Renderer::Backend::IGraphicsPipelineState > m_PipelineState
Definition: ShaderTechnique.h:52
CShaderProgramPtr m_Shader
Definition: ShaderTechnique.h:50
CShaderPass(std::unique_ptr< Renderer::Backend::IGraphicsPipelineState > pipelineState, const CShaderProgramPtr &shader)
Definition: ShaderTechnique.cpp:27
Renderer::Backend::IGraphicsPipelineState * GetPipelineState() const noexcept
Definition: ShaderTechnique.h:47
MOVABLE(CShaderPass)
const CShaderProgramPtr & GetShaderProgram() const noexcept
Definition: ShaderTechnique.h:44
Implements a render technique consisting of a sequence of passes.
Definition: ShaderTechnique.h:60
void SetComputePipelineState(std::unique_ptr< Renderer::Backend::IComputePipelineState > pipelineState, const CShaderProgramPtr &computeShader)
Definition: ShaderTechnique.cpp:48
CShaderProgramPtr m_ComputeShader
Definition: ShaderTechnique.h:108
std::function< void(Renderer::Backend::SGraphicsPipelineStateDesc &pipelineStateDesc)> PipelineStateDescCallback
Definition: ShaderTechnique.h:63
std::vector< CShaderPass > m_Passes
Definition: ShaderTechnique.h:97
std::unique_ptr< Renderer::Backend::IComputePipelineState > m_ComputePipelineState
Definition: ShaderTechnique.h:107
CShaderDefines m_Defines
Definition: ShaderTechnique.h:103
const CShaderDefines & GetShaderDefines()
Definition: ShaderTechnique.h:92
CShaderTechnique(const VfsPath &path, const CShaderDefines &defines, const PipelineStateDescCallback &callback)
Definition: ShaderTechnique.cpp:35
VfsPath m_Path
Definition: ShaderTechnique.h:102
PipelineStateDescCallback m_PipelineStateDescCallback
Definition: ShaderTechnique.h:105
int GetNumPasses() const
Definition: ShaderTechnique.cpp:57
Renderer::Backend::IShaderProgram * GetShader(int pass=0) const
Definition: ShaderTechnique.cpp:62
Renderer::Backend::IComputePipelineState * GetComputePipelineState() const
Definition: ShaderTechnique.cpp:84
void SetSortByDistance(bool enable)
Definition: ShaderTechnique.cpp:94
bool m_SortByDistance
Definition: ShaderTechnique.h:99
const PipelineStateDescCallback & GetPipelineStateDescCallback() const
Definition: ShaderTechnique.h:94
void SetPasses(std::vector< CShaderPass > &&passes)
Definition: ShaderTechnique.cpp:42
Renderer::Backend::IGraphicsPipelineState * GetGraphicsPipelineState(int pass=0) const
Definition: ShaderTechnique.cpp:77
bool GetSortByDistance() const
Whether this technique uses alpha blending that requires objects to be drawn from furthest to nearest...
Definition: ShaderTechnique.cpp:89
const VfsPath & GetPath()
Definition: ShaderTechnique.h:90
Definition: path.h:80
A holder for precompiled compute pipeline description.
Definition: PipelineState.h:207
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:198
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:81
Definition: PipelineState.h:165