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: 1 93 1.1 %
Date: 2023-01-19 00:18:29 Functions: 2 9 22.2 %

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

Generated by: LCOV version 1.13