LCOV - code coverage report
Current view: top level - source/renderer/backend - PipelineState.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 78 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : #include "precompiled.h"
      19             : 
      20             : #include "PipelineState.h"
      21             : 
      22             : #include "lib/debug.h"
      23             : #include "renderer/backend/CompareOp.h"
      24             : 
      25             : #include <limits>
      26             : #include <string>
      27             : 
      28             : namespace Renderer
      29             : {
      30             : 
      31             : namespace Backend
      32             : {
      33             : 
      34           0 : SGraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc()
      35             : {
      36           0 :     SGraphicsPipelineStateDesc desc{};
      37             : 
      38           0 :     desc.shaderProgram = nullptr;
      39             : 
      40           0 :     desc.depthStencilState.depthTestEnabled = true;
      41           0 :     desc.depthStencilState.depthCompareOp = CompareOp::LESS_OR_EQUAL;
      42           0 :     desc.depthStencilState.depthWriteEnabled = true;
      43           0 :     desc.depthStencilState.stencilTestEnabled = false;
      44           0 :     desc.depthStencilState.stencilFrontFace.failOp = StencilOp::KEEP;
      45           0 :     desc.depthStencilState.stencilFrontFace.passOp = StencilOp::KEEP;
      46           0 :     desc.depthStencilState.stencilFrontFace.depthFailOp = StencilOp::KEEP;
      47           0 :     desc.depthStencilState.stencilFrontFace.compareOp = CompareOp::ALWAYS;
      48           0 :     desc.depthStencilState.stencilBackFace = desc.depthStencilState.stencilFrontFace;
      49           0 :     desc.depthStencilState.stencilReadMask = desc.depthStencilState.stencilWriteMask =
      50             :         std::numeric_limits<uint32_t>::max();
      51           0 :     desc.depthStencilState.stencilReference = 0;
      52             : 
      53           0 :     desc.blendState.enabled = false;
      54           0 :     desc.blendState.srcColorBlendFactor = desc.blendState.srcAlphaBlendFactor =
      55             :         BlendFactor::ONE;
      56           0 :     desc.blendState.dstColorBlendFactor = desc.blendState.dstAlphaBlendFactor =
      57             :         BlendFactor::ZERO;
      58           0 :     desc.blendState.colorBlendOp = desc.blendState.alphaBlendOp = BlendOp::ADD;
      59           0 :     desc.blendState.constant = CColor(0.0f, 0.0f, 0.0f, 0.0f);
      60           0 :     desc.blendState.colorWriteMask =
      61             :         ColorWriteMask::RED | ColorWriteMask::GREEN | ColorWriteMask::BLUE | ColorWriteMask::ALPHA;
      62             : 
      63           0 :     desc.rasterizationState.polygonMode = PolygonMode::FILL;
      64           0 :     desc.rasterizationState.cullMode = CullMode::BACK;
      65           0 :     desc.rasterizationState.frontFace = FrontFace::COUNTER_CLOCKWISE;
      66           0 :     desc.rasterizationState.depthBiasEnabled = false;
      67           0 :     desc.rasterizationState.depthBiasConstantFactor = 0.0f;
      68           0 :     desc.rasterizationState.depthBiasSlopeFactor = 0.0f;
      69           0 :     return desc;
      70             : }
      71             : 
      72           0 : StencilOp ParseStencilOp(const CStr& str)
      73             : {
      74             : #define CASE(NAME) if (str == #NAME) return StencilOp::NAME
      75           0 :     CASE(KEEP);
      76           0 :     CASE(ZERO);
      77           0 :     CASE(REPLACE);
      78           0 :     CASE(INCREMENT_AND_CLAMP);
      79           0 :     CASE(DECREMENT_AND_CLAMP);
      80           0 :     CASE(INVERT);
      81           0 :     CASE(INCREMENT_AND_WRAP);
      82           0 :     CASE(DECREMENT_AND_WRAP);
      83             : #undef CASE
      84           0 :     debug_warn("Invalid stencil op");
      85             :     return StencilOp::KEEP;
      86             : }
      87             : 
      88           0 : BlendFactor ParseBlendFactor(const CStr& str)
      89             : {
      90             :     // TODO: it might make sense to use upper case in XML for consistency.
      91             : #define CASE(NAME, VALUE) if (str == NAME) return BlendFactor::VALUE
      92           0 :     CASE("zero", ZERO);
      93           0 :     CASE("one", ONE);
      94           0 :     CASE("src_color", SRC_COLOR);
      95           0 :     CASE("one_minus_src_color", ONE_MINUS_SRC_COLOR);
      96           0 :     CASE("dst_color", DST_COLOR);
      97           0 :     CASE("one_minus_dst_color", ONE_MINUS_DST_COLOR);
      98           0 :     CASE("src_alpha", SRC_ALPHA);
      99           0 :     CASE("one_minus_src_alpha", ONE_MINUS_SRC_ALPHA);
     100           0 :     CASE("dst_alpha", DST_ALPHA);
     101           0 :     CASE("one_minus_dst_alpha", ONE_MINUS_DST_ALPHA);
     102           0 :     CASE("constant_color", CONSTANT_COLOR);
     103           0 :     CASE("one_minus_constant_color", ONE_MINUS_CONSTANT_COLOR);
     104           0 :     CASE("constant_alpha", CONSTANT_ALPHA);
     105           0 :     CASE("one_minus_constant_alpha", ONE_MINUS_CONSTANT_ALPHA);
     106           0 :     CASE("src_alpha_saturate", SRC_ALPHA_SATURATE);
     107           0 :     CASE("src1_color", SRC1_COLOR);
     108           0 :     CASE("one_minus_src1_color", ONE_MINUS_SRC1_COLOR);
     109           0 :     CASE("src1_alpha", SRC1_ALPHA);
     110           0 :     CASE("one_minus_src1_alpha", ONE_MINUS_SRC1_ALPHA);
     111             : #undef CASE
     112           0 :     debug_warn("Invalid blend factor");
     113             :     return BlendFactor::ZERO;
     114             : }
     115             : 
     116           0 : BlendOp ParseBlendOp(const CStr& str)
     117             : {
     118             : #define CASE(NAME) if (str == #NAME) return BlendOp::NAME
     119           0 :     CASE(ADD);
     120           0 :     CASE(SUBTRACT);
     121           0 :     CASE(REVERSE_SUBTRACT);
     122           0 :     CASE(MIN);
     123           0 :     CASE(MAX);
     124             : #undef CASE
     125           0 :     debug_warn("Invalid blend op");
     126             :     return BlendOp::ADD;
     127             : }
     128             : 
     129           0 : PolygonMode ParsePolygonMode(const CStr& str)
     130             : {
     131           0 :     if (str == "FILL")
     132             :         return PolygonMode::FILL;
     133           0 :     else if (str == "LINE")
     134             :         return PolygonMode::LINE;
     135           0 :     debug_warn("Invalid polygon mode");
     136             :     return PolygonMode::FILL;
     137             : }
     138             : 
     139           0 : CullMode ParseCullMode(const CStr& str)
     140             : {
     141           0 :     if (str == "NONE")
     142             :         return CullMode::NONE;
     143           0 :     else if (str == "FRONT")
     144             :         return CullMode::FRONT;
     145           0 :     else if (str == "BACK")
     146             :         return CullMode::BACK;
     147           0 :     debug_warn("Invalid cull mode");
     148             :     return CullMode::BACK;
     149             : }
     150             : 
     151           0 : FrontFace ParseFrontFace(const CStr& str)
     152             : {
     153           0 :     if (str == "CLOCKWISE")
     154             :         return FrontFace::CLOCKWISE;
     155           0 :     else if (str == "COUNTER_CLOCKWISE")
     156             :         return FrontFace::COUNTER_CLOCKWISE;
     157           0 :     debug_warn("Invalid front face");
     158             :     return FrontFace::COUNTER_CLOCKWISE;
     159             : }
     160             : 
     161             : } // namespace Backend
     162             : 
     163             : } // namespace Renderer

Generated by: LCOV version 1.16