1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
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.
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.
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/>.
18 #ifndef INCLUDED_RENDERER_BACKEND_PIPELINESTATE
19 #define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
21 #include "graphics/Color.h"
22 #include "renderer/backend/CompareOp.h"
23 #include "renderer/backend/IDeviceObject.h"
24 #include "renderer/backend/IShaderProgram.h"
36 // Keeps the current value.
38 // Sets the value to zero.
40 // Sets the value to reference.
42 // Increments the value and clamps to the maximum representable unsigned
45 // Decrements the value and clamps to zero.
47 // Bitwise inverts the value.
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.
57 struct SStencilOpState
61 StencilOp depthFailOp
;
65 struct SDepthStencilStateDesc
67 bool depthTestEnabled
;
68 CompareOp depthCompareOp
;
69 bool depthWriteEnabled
;
70 bool stencilTestEnabled
;
71 uint32_t stencilReadMask
;
72 uint32_t stencilWriteMask
;
73 uint32_t stencilReference
;
74 SStencilOpState stencilFrontFace
;
75 SStencilOpState stencilBackFace
;
78 // TODO: add per constant description.
80 enum class BlendFactor
93 ONE_MINUS_CONSTANT_COLOR
,
95 ONE_MINUS_CONSTANT_ALPHA
,
100 ONE_MINUS_SRC1_ALPHA
,
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
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
122 struct SBlendStateDesc
125 BlendFactor srcColorBlendFactor
;
126 BlendFactor dstColorBlendFactor
;
127 BlendOp colorBlendOp
;
128 BlendFactor srcAlphaBlendFactor
;
129 BlendFactor dstAlphaBlendFactor
;
130 BlendOp alphaBlendOp
;
132 uint8_t colorWriteMask
;
135 enum class PolygonMode
154 struct SRasterizationStateDesc
156 PolygonMode polygonMode
;
159 bool depthBiasEnabled
;
160 float depthBiasConstantFactor
;
161 float depthBiasSlopeFactor
;
164 struct SGraphicsPipelineStateDesc
166 // It's a backend client reponsibility to keep the shader program alive
168 IShaderProgram
* shaderProgram
;
169 SDepthStencilStateDesc depthStencilState
;
170 SBlendStateDesc blendState
;
171 SRasterizationStateDesc rasterizationState
;
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.
176 SGraphicsPipelineStateDesc
MakeDefaultGraphicsPipelineStateDesc();
178 StencilOp
ParseStencilOp(const CStr
& str
);
180 BlendFactor
ParseBlendFactor(const CStr
& str
);
181 BlendOp
ParseBlendOp(const CStr
& str
);
183 PolygonMode
ParsePolygonMode(const CStr
& str
);
184 CullMode
ParseCullMode(const CStr
& str
);
185 FrontFace
ParseFrontFace(const CStr
& str
);
188 * A holder for precompiled graphics pipeline description.
190 class IGraphicsPipelineState
: public IDeviceObject
<IGraphicsPipelineState
>
193 virtual IShaderProgram
* GetShaderProgram() const = 0;
196 } // namespace Backend
198 } // namespace Renderer
200 #endif // INCLUDED_RENDERER_BACKEND_PIPELINESTATE