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 #include "precompiled.h"
20 #include "PipelineState.h"
30 SGraphicsPipelineStateDesc
MakeDefaultGraphicsPipelineStateDesc()
32 SGraphicsPipelineStateDesc desc
{};
34 desc
.shaderProgram
= nullptr;
36 desc
.depthStencilState
.depthTestEnabled
= true;
37 desc
.depthStencilState
.depthCompareOp
= CompareOp::LESS_OR_EQUAL
;
38 desc
.depthStencilState
.depthWriteEnabled
= true;
39 desc
.depthStencilState
.stencilTestEnabled
= false;
40 desc
.depthStencilState
.stencilFrontFace
.failOp
= StencilOp::KEEP
;
41 desc
.depthStencilState
.stencilFrontFace
.passOp
= StencilOp::KEEP
;
42 desc
.depthStencilState
.stencilFrontFace
.depthFailOp
= StencilOp::KEEP
;
43 desc
.depthStencilState
.stencilFrontFace
.compareOp
= CompareOp::ALWAYS
;
44 desc
.depthStencilState
.stencilBackFace
= desc
.depthStencilState
.stencilFrontFace
;
45 desc
.depthStencilState
.stencilReadMask
= desc
.depthStencilState
.stencilWriteMask
=
46 std::numeric_limits
<uint32_t>::max();
47 desc
.depthStencilState
.stencilReference
= 0;
49 desc
.blendState
.enabled
= false;
50 desc
.blendState
.srcColorBlendFactor
= desc
.blendState
.srcAlphaBlendFactor
=
52 desc
.blendState
.dstColorBlendFactor
= desc
.blendState
.dstAlphaBlendFactor
=
54 desc
.blendState
.colorBlendOp
= desc
.blendState
.alphaBlendOp
= BlendOp::ADD
;
55 desc
.blendState
.constant
= CColor(0.0f
, 0.0f
, 0.0f
, 0.0f
);
56 desc
.blendState
.colorWriteMask
=
57 ColorWriteMask::RED
| ColorWriteMask::GREEN
| ColorWriteMask::BLUE
| ColorWriteMask::ALPHA
;
59 desc
.rasterizationState
.polygonMode
= PolygonMode::FILL
;
60 desc
.rasterizationState
.cullMode
= CullMode::BACK
;
61 desc
.rasterizationState
.frontFace
= FrontFace::COUNTER_CLOCKWISE
;
62 desc
.rasterizationState
.depthBiasEnabled
= false;
63 desc
.rasterizationState
.depthBiasConstantFactor
= 0.0f
;
64 desc
.rasterizationState
.depthBiasSlopeFactor
= 0.0f
;
68 StencilOp
ParseStencilOp(const CStr
& str
)
70 #define CASE(NAME) if (str == #NAME) return StencilOp::NAME
74 CASE(INCREMENT_AND_CLAMP
);
75 CASE(DECREMENT_AND_CLAMP
);
77 CASE(INCREMENT_AND_WRAP
);
78 CASE(DECREMENT_AND_WRAP
);
80 debug_warn("Invalid stencil op");
81 return StencilOp::KEEP
;
84 BlendFactor
ParseBlendFactor(const CStr
& str
)
86 // TODO: it might make sense to use upper case in XML for consistency.
87 #define CASE(NAME, VALUE) if (str == NAME) return BlendFactor::VALUE
90 CASE("src_color", SRC_COLOR
);
91 CASE("one_minus_src_color", ONE_MINUS_SRC_COLOR
);
92 CASE("dst_color", DST_COLOR
);
93 CASE("one_minus_dst_color", ONE_MINUS_DST_COLOR
);
94 CASE("src_alpha", SRC_ALPHA
);
95 CASE("one_minus_src_alpha", ONE_MINUS_SRC_ALPHA
);
96 CASE("dst_alpha", DST_ALPHA
);
97 CASE("one_minus_dst_alpha", ONE_MINUS_DST_ALPHA
);
98 CASE("constant_color", CONSTANT_COLOR
);
99 CASE("one_minus_constant_color", ONE_MINUS_CONSTANT_COLOR
);
100 CASE("constant_alpha", CONSTANT_ALPHA
);
101 CASE("one_minus_constant_alpha", ONE_MINUS_CONSTANT_ALPHA
);
102 CASE("src_alpha_saturate", SRC_ALPHA_SATURATE
);
103 CASE("src1_color", SRC1_COLOR
);
104 CASE("one_minus_src1_color", ONE_MINUS_SRC1_COLOR
);
105 CASE("src1_alpha", SRC1_ALPHA
);
106 CASE("one_minus_src1_alpha", ONE_MINUS_SRC1_ALPHA
);
108 debug_warn("Invalid blend factor");
109 return BlendFactor::ZERO
;
112 BlendOp
ParseBlendOp(const CStr
& str
)
114 #define CASE(NAME) if (str == #NAME) return BlendOp::NAME
117 CASE(REVERSE_SUBTRACT
);
121 debug_warn("Invalid blend op");
125 PolygonMode
ParsePolygonMode(const CStr
& str
)
128 return PolygonMode::FILL
;
129 else if (str
== "LINE")
130 return PolygonMode::LINE
;
131 debug_warn("Invalid polygon mode");
132 return PolygonMode::FILL
;
135 CullMode
ParseCullMode(const CStr
& str
)
138 return CullMode::NONE
;
139 else if (str
== "FRONT")
140 return CullMode::FRONT
;
141 else if (str
== "BACK")
142 return CullMode::BACK
;
143 debug_warn("Invalid cull mode");
144 return CullMode::BACK
;
147 FrontFace
ParseFrontFace(const CStr
& str
)
149 if (str
== "CLOCKWISE")
150 return FrontFace::CLOCKWISE
;
151 else if (str
== "COUNTER_CLOCKWISE")
152 return FrontFace::COUNTER_CLOCKWISE
;
153 debug_warn("Invalid front face");
154 return FrontFace::COUNTER_CLOCKWISE
;
157 } // namespace Backend
159 } // namespace Renderer