Pyrogenesis  trunk
PipelineState.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_RENDERER_BACKEND_PIPELINESTATE
19 #define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
20 
21 #include "graphics/Color.h"
25 
26 class CStr;
27 
28 namespace Renderer
29 {
30 
31 namespace Backend
32 {
33 
34 enum class StencilOp
35 {
36  // Keeps the current value.
37  KEEP,
38  // Sets the value to zero.
39  ZERO,
40  // Sets the value to reference.
41  REPLACE,
42  // Increments the value and clamps to the maximum representable unsigned
43  // value.
45  // Decrements the value and clamps to zero.
47  // Bitwise inverts the value.
48  INVERT,
49  // Increments the value and wraps it to zero when incrementing the maximum
50  // representable unsigned value.
52  // Decrements the value and wraps it to the maximum representable unsigned
53  // value when decrementing zero.
55 };
56 
58 {
63 };
64 
66 {
76 };
77 
78 // TODO: add per constant description.
79 
80 enum class BlendFactor
81 {
82  ZERO,
83  ONE,
84  SRC_COLOR,
86  DST_COLOR,
88  SRC_ALPHA,
90  DST_ALPHA,
97  SRC1_COLOR,
99  SRC1_ALPHA,
101 };
102 
103 enum class BlendOp
104 {
105  ADD,
106  SUBTRACT,
108  MIN,
109  MAX
110 };
111 
112 // Using a namespace instead of a enum allows using the same syntax while
113 // avoiding adding operator overrides and additional checks on casts.
114 namespace ColorWriteMask
115 {
116 constexpr uint8_t RED = 0x01;
117 constexpr uint8_t GREEN = 0x02;
118 constexpr uint8_t BLUE = 0x04;
119 constexpr uint8_t ALPHA = 0x08;
120 } // namespace ColorWriteMask
121 
123 {
124  bool enabled;
133 };
134 
135 enum class PolygonMode
136 {
137  FILL,
138  LINE
139 };
140 
141 enum class CullMode
142 {
143  NONE,
144  FRONT,
145  BACK
146 };
147 
148 enum class FrontFace
149 {
151  CLOCKWISE
152 };
153 
155 {
162 };
163 
165 {
166  // It's a backend client reponsibility to keep the shader program alive
167  // while it's bound.
172 };
173 
174 // We don't provide additional helpers intentionally because all custom states
175 // should be described with a related shader and should be switched together.
177 
178 StencilOp ParseStencilOp(const CStr& str);
179 
180 BlendFactor ParseBlendFactor(const CStr& str);
181 BlendOp ParseBlendOp(const CStr& str);
182 
183 PolygonMode ParsePolygonMode(const CStr& str);
184 CullMode ParseCullMode(const CStr& str);
185 FrontFace ParseFrontFace(const CStr& str);
186 
187 /**
188  * A holder for precompiled graphics pipeline description.
189  */
190 class IGraphicsPipelineState : public IDeviceObject<IGraphicsPipelineState>
191 {
192 public:
193  virtual IShaderProgram* GetShaderProgram() const = 0;
194 };
195 
196 } // namespace Backend
197 
198 } // namespace Renderer
199 
200 #endif // INCLUDED_RENDERER_BACKEND_PIPELINESTATE
SStencilOpState stencilFrontFace
Definition: PipelineState.h:74
bool stencilTestEnabled
Definition: PipelineState.h:70
float depthBiasConstantFactor
Definition: PipelineState.h:160
BlendFactor srcAlphaBlendFactor
Definition: PipelineState.h:128
constexpr uint8_t RED
Definition: PipelineState.h:116
uint32_t stencilReference
Definition: PipelineState.h:73
BlendOp alphaBlendOp
Definition: PipelineState.h:130
SRasterizationStateDesc rasterizationState
Definition: PipelineState.h:171
float depthBiasSlopeFactor
Definition: PipelineState.h:161
Definition: Color.h:42
StencilOp
Definition: PipelineState.h:34
CompareOp compareOp
Definition: PipelineState.h:62
CColor constant
Definition: PipelineState.h:131
CullMode ParseCullMode(const CStr &str)
Definition: PipelineState.cpp:135
Definition: PipelineState.h:57
constexpr uint8_t ALPHA
Definition: PipelineState.h:119
BlendFactor dstColorBlendFactor
Definition: PipelineState.h:126
SGraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc()
Definition: PipelineState.cpp:30
constexpr uint8_t BLUE
Definition: PipelineState.h:118
bool depthTestEnabled
Definition: PipelineState.h:67
BlendFactor srcColorBlendFactor
Definition: PipelineState.h:125
StencilOp ParseStencilOp(const CStr &str)
Definition: PipelineState.cpp:68
SBlendStateDesc blendState
Definition: PipelineState.h:170
BlendOp ParseBlendOp(const CStr &str)
Definition: PipelineState.cpp:112
StencilOp failOp
Definition: PipelineState.h:59
bool depthBiasEnabled
Definition: PipelineState.h:159
Definition: PipelineState.h:154
FrontFace ParseFrontFace(const CStr &str)
Definition: PipelineState.cpp:147
StencilOp depthFailOp
Definition: PipelineState.h:61
unsigned char uint8_t
Definition: wposix_types.h:51
BlendFactor ParseBlendFactor(const CStr &str)
Definition: PipelineState.cpp:84
CompareOp depthCompareOp
Definition: PipelineState.h:68
uint8_t colorWriteMask
Definition: PipelineState.h:132
FrontFace
Definition: PipelineState.h:148
Definition: PipelineState.h:122
Definition: PipelineState.h:164
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:190
BlendFactor dstAlphaBlendFactor
Definition: PipelineState.h:129
CullMode
Definition: PipelineState.h:141
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:80
Backend
Definition: Backend.h:27
CullMode cullMode
Definition: PipelineState.h:157
BlendFactor
Definition: PipelineState.h:80
IShaderProgram * shaderProgram
Definition: PipelineState.h:168
CompareOp
Definition: CompareOp.h:31
unsigned int uint32_t
Definition: wposix_types.h:53
Definition: VideoMode.h:28
bool depthWriteEnabled
Definition: PipelineState.h:69
uint32_t stencilReadMask
Definition: PipelineState.h:71
Definition: IDeviceObject.h:32
SStencilOpState stencilBackFace
Definition: PipelineState.h:75
uint32_t stencilWriteMask
Definition: PipelineState.h:72
PolygonMode ParsePolygonMode(const CStr &str)
Definition: PipelineState.cpp:125
Definition: PipelineState.h:65
SDepthStencilStateDesc depthStencilState
Definition: PipelineState.h:169
constexpr uint8_t GREEN
Definition: PipelineState.h:117
StencilOp passOp
Definition: PipelineState.h:60
PolygonMode polygonMode
Definition: PipelineState.h:156
BlendOp colorBlendOp
Definition: PipelineState.h:127
bool enabled
Definition: PipelineState.h:124
PolygonMode
Definition: PipelineState.h:135
BlendOp
Definition: PipelineState.h:103
FrontFace frontFace
Definition: PipelineState.h:158