Pyrogenesis  trunk
ShaderTechnique.h
Go to the documentation of this file.
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"
24 #include "lib/code_annotation.h"
25 #include "lib/file/vfs/vfs_path.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 {
38 public:
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 
49 private:
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 {
61 public:
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 
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  const VfsPath& GetPath() { return m_Path; }
85 
86  const CShaderDefines& GetShaderDefines() { return m_Defines; }
87 
88  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.
98 
100 };
101 
102 #endif // INCLUDED_SHADERTECHNIQUE
VfsPath m_Path
Definition: ShaderTechnique.h:96
CShaderDefines m_Defines
Definition: ShaderTechnique.h:97
CShaderProgramPtr m_Shader
Definition: ShaderTechnique.h:50
Implements a render pass consisting of a pipeline state and a shader, used by CShaderTechnique.
Definition: ShaderTechnique.h:36
CShaderPass(std::unique_ptr< Renderer::Backend::IGraphicsPipelineState > pipelineState, const CShaderProgramPtr &shader)
Definition: ShaderTechnique.cpp:25
MOVABLE(CShaderPass)
Definition: path.h:79
std::unique_ptr< Renderer::Backend::IGraphicsPipelineState > m_PipelineState
Definition: ShaderTechnique.h:52
const CShaderDefines & GetShaderDefines()
Definition: ShaderTechnique.h:86
Implements a render technique consisting of a sequence of passes.
Definition: ShaderTechnique.h:59
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:190
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:80
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:146
Renderer::Backend::IGraphicsPipelineState * GetPipelineState() const noexcept
Definition: ShaderTechnique.h:47
const VfsPath & GetPath()
Definition: ShaderTechnique.h:84
std::function< void(Renderer::Backend::SGraphicsPipelineStateDesc &pipelineStateDesc)> PipelineStateDescCallback
Definition: ShaderTechnique.h:63
PipelineStateDescCallback m_PipelineStateDescCallback
Definition: ShaderTechnique.h:99
std::vector< CShaderPass > m_Passes
Definition: ShaderTechnique.h:88
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:25
const CShaderProgramPtr & GetShaderProgram() const noexcept
Definition: ShaderTechnique.h:44