Pyrogenesis trunk
PipelineState.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_RENDERER_BACKEND_PIPELINESTATE
19#define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
20
21#include "graphics/Color.h"
25
26class CStr;
27
28namespace Renderer
29{
30
31namespace Backend
32{
33
34enum 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
80enum class BlendFactor
81{
82 ZERO,
83 ONE,
101};
102
103enum 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.
114namespace ColorWriteMask
115{
116constexpr uint8_t RED = 0x01;
117constexpr uint8_t GREEN = 0x02;
118constexpr uint8_t BLUE = 0x04;
119constexpr uint8_t ALPHA = 0x08;
120} // namespace ColorWriteMask
121
123{
133};
134
135enum class PolygonMode
136{
137 FILL,
138 LINE
139};
140
141enum class CullMode
142{
143 NONE,
144 FRONT,
145 BACK
146};
147
148enum class FrontFace
149{
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
175{
176 // It's a backend client reponsibility to keep the shader program alive
177 // while it's bound.
179};
180
181// We don't provide additional helpers intentionally because all custom states
182// should be described with a related shader and should be switched together.
184
185StencilOp ParseStencilOp(const CStr& str);
186
187BlendFactor ParseBlendFactor(const CStr& str);
188BlendOp ParseBlendOp(const CStr& str);
189
190PolygonMode ParsePolygonMode(const CStr& str);
191CullMode ParseCullMode(const CStr& str);
192FrontFace ParseFrontFace(const CStr& str);
193
194/**
195 * A holder for precompiled graphics pipeline description.
196 */
197class IGraphicsPipelineState : public IDeviceObject<IGraphicsPipelineState>
198{
199public:
200 virtual IShaderProgram* GetShaderProgram() const = 0;
201};
202
203/**
204 * A holder for precompiled compute pipeline description.
205 */
206class IComputePipelineState : public IDeviceObject<IComputePipelineState>
207{
208public:
209 virtual IShaderProgram* GetShaderProgram() const = 0;
210};
211
212} // namespace Backend
213
214} // namespace Renderer
215
216#endif // INCLUDED_RENDERER_BACKEND_PIPELINESTATE
#define ADD(position)
A holder for precompiled compute pipeline description.
Definition: PipelineState.h:207
virtual IShaderProgram * GetShaderProgram() const =0
Definition: IDeviceObject.h:33
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:198
virtual IShaderProgram * GetShaderProgram() const =0
IShaderProgram is a container for multiple shaders of different types.
Definition: IShaderProgram.h:81
#define REPLACE(what, with)
Definition: debug_stl.cpp:50
constexpr uint8_t RED
Definition: PipelineState.h:116
constexpr uint8_t BLUE
Definition: PipelineState.h:118
constexpr uint8_t ALPHA
Definition: PipelineState.h:119
constexpr uint8_t GREEN
Definition: PipelineState.h:117
StencilOp ParseStencilOp(const CStr &str)
Definition: PipelineState.cpp:68
CullMode ParseCullMode(const CStr &str)
Definition: PipelineState.cpp:135
CompareOp
Definition: CompareOp.h:32
BlendFactor ParseBlendFactor(const CStr &str)
Definition: PipelineState.cpp:84
PolygonMode
Definition: PipelineState.h:136
FrontFace ParseFrontFace(const CStr &str)
Definition: PipelineState.cpp:147
PolygonMode ParsePolygonMode(const CStr &str)
Definition: PipelineState.cpp:125
StencilOp
Definition: PipelineState.h:35
FrontFace
Definition: PipelineState.h:149
SGraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc()
Definition: PipelineState.cpp:30
BlendOp
Definition: PipelineState.h:104
BlendFactor
Definition: PipelineState.h:81
Backend
Definition: Backend.h:28
BlendOp ParseBlendOp(const CStr &str)
Definition: PipelineState.cpp:112
CullMode
Definition: PipelineState.h:142
Definition: VideoMode.h:29
Definition: Color.h:43
Definition: PipelineState.h:123
CColor constant
Definition: PipelineState.h:131
BlendOp colorBlendOp
Definition: PipelineState.h:127
BlendOp alphaBlendOp
Definition: PipelineState.h:130
uint8_t colorWriteMask
Definition: PipelineState.h:132
BlendFactor srcColorBlendFactor
Definition: PipelineState.h:125
BlendFactor dstColorBlendFactor
Definition: PipelineState.h:126
BlendFactor srcAlphaBlendFactor
Definition: PipelineState.h:128
bool enabled
Definition: PipelineState.h:124
BlendFactor dstAlphaBlendFactor
Definition: PipelineState.h:129
Definition: PipelineState.h:175
IShaderProgram * shaderProgram
Definition: PipelineState.h:178
Definition: PipelineState.h:66
uint32_t stencilWriteMask
Definition: PipelineState.h:72
bool stencilTestEnabled
Definition: PipelineState.h:70
bool depthTestEnabled
Definition: PipelineState.h:67
uint32_t stencilReference
Definition: PipelineState.h:73
uint32_t stencilReadMask
Definition: PipelineState.h:71
SStencilOpState stencilFrontFace
Definition: PipelineState.h:74
bool depthWriteEnabled
Definition: PipelineState.h:69
CompareOp depthCompareOp
Definition: PipelineState.h:68
SStencilOpState stencilBackFace
Definition: PipelineState.h:75
Definition: PipelineState.h:165
IShaderProgram * shaderProgram
Definition: PipelineState.h:168
SRasterizationStateDesc rasterizationState
Definition: PipelineState.h:171
SBlendStateDesc blendState
Definition: PipelineState.h:170
SDepthStencilStateDesc depthStencilState
Definition: PipelineState.h:169
Definition: PipelineState.h:155
bool depthBiasEnabled
Definition: PipelineState.h:159
CullMode cullMode
Definition: PipelineState.h:157
float depthBiasSlopeFactor
Definition: PipelineState.h:161
FrontFace frontFace
Definition: PipelineState.h:158
float depthBiasConstantFactor
Definition: PipelineState.h:160
PolygonMode polygonMode
Definition: PipelineState.h:156
Definition: PipelineState.h:58
StencilOp depthFailOp
Definition: PipelineState.h:61
StencilOp passOp
Definition: PipelineState.h:60
StencilOp failOp
Definition: PipelineState.h:59
CompareOp compareOp
Definition: PipelineState.h:62
unsigned int uint32_t
Definition: wposix_types.h:53
unsigned char uint8_t
Definition: wposix_types.h:51