mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
Adds a rasterization state to the renderer backend pipeline state.
This was SVN commit r26248.
This commit is contained in:
@@ -28,13 +28,17 @@ namespace Backend
|
||||
GraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc()
|
||||
{
|
||||
GraphicsPipelineStateDesc desc{};
|
||||
desc.blendState.enabled = false;
|
||||
desc.blendState.srcColorBlendFactor = desc.blendState.srcAlphaBlendFactor =
|
||||
BlendFactor::ONE;
|
||||
desc.blendState.dstColorBlendFactor = desc.blendState.dstAlphaBlendFactor =
|
||||
BlendFactor::ZERO;
|
||||
desc.blendState.colorBlendOp = desc.blendState.alphaBlendOp = BlendOp::ADD;
|
||||
|
||||
desc.blendState.enabled = false;
|
||||
desc.blendState.srcColorBlendFactor = desc.blendState.srcAlphaBlendFactor =
|
||||
BlendFactor::ONE;
|
||||
desc.blendState.dstColorBlendFactor = desc.blendState.dstAlphaBlendFactor =
|
||||
BlendFactor::ZERO;
|
||||
desc.blendState.colorBlendOp = desc.blendState.alphaBlendOp = BlendOp::ADD;
|
||||
desc.blendState.constant = CColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
desc.rasterizationState.cullMode = CullMode::BACK;
|
||||
desc.rasterizationState.frontFace = FrontFace::COUNTER_CLOCKWISE;
|
||||
return desc;
|
||||
}
|
||||
|
||||
@@ -79,6 +83,28 @@ BlendOp ParseBlendOp(const CStr& str)
|
||||
return BlendOp::ADD;
|
||||
}
|
||||
|
||||
CullMode ParseCullMode(const CStr& str)
|
||||
{
|
||||
if (str == "NONE")
|
||||
return CullMode::NONE;
|
||||
else if (str == "FRONT")
|
||||
return CullMode::FRONT;
|
||||
else if (str == "BACK")
|
||||
return CullMode::BACK;
|
||||
debug_warn("Invalid cull mode");
|
||||
return CullMode::BACK;
|
||||
}
|
||||
|
||||
FrontFace ParseFrontFace(const CStr& str)
|
||||
{
|
||||
if (str == "CLOCKWISE")
|
||||
return FrontFace::CLOCKWISE;
|
||||
else if (str == "COUNTER_CLOCKWISE")
|
||||
return FrontFace::COUNTER_CLOCKWISE;
|
||||
debug_warn("Invalid front face");
|
||||
return FrontFace::COUNTER_CLOCKWISE;
|
||||
}
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
@@ -1,94 +1,117 @@
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
#define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
|
||||
#include "graphics/Color.h"
|
||||
|
||||
class CStr;
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
|
||||
namespace Backend
|
||||
{
|
||||
|
||||
// TODO: add per constant description.
|
||||
|
||||
enum class BlendFactor
|
||||
{
|
||||
ZERO,
|
||||
ONE,
|
||||
SRC_COLOR,
|
||||
ONE_MINUS_SRC_COLOR,
|
||||
DST_COLOR,
|
||||
ONE_MINUS_DST_COLOR,
|
||||
SRC_ALPHA,
|
||||
ONE_MINUS_SRC_ALPHA,
|
||||
DST_ALPHA,
|
||||
ONE_MINUS_DST_ALPHA,
|
||||
CONSTANT_COLOR,
|
||||
ONE_MINUS_CONSTANT_COLOR,
|
||||
CONSTANT_ALPHA,
|
||||
ONE_MINUS_CONSTANT_ALPHA,
|
||||
SRC_ALPHA_SATURATE,
|
||||
SRC1_COLOR,
|
||||
ONE_MINUS_SRC1_COLOR,
|
||||
SRC1_ALPHA,
|
||||
ONE_MINUS_SRC1_ALPHA,
|
||||
};
|
||||
|
||||
enum class BlendOp
|
||||
{
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
REVERSE_SUBTRACT,
|
||||
MIN,
|
||||
MAX
|
||||
};
|
||||
|
||||
struct BlendStateDesc
|
||||
{
|
||||
bool enabled;
|
||||
BlendFactor srcColorBlendFactor;
|
||||
BlendFactor dstColorBlendFactor;
|
||||
BlendOp colorBlendOp;
|
||||
BlendFactor srcAlphaBlendFactor;
|
||||
BlendFactor dstAlphaBlendFactor;
|
||||
BlendOp alphaBlendOp;
|
||||
CColor constant;
|
||||
};
|
||||
|
||||
// TODO: Add a shader program to the graphics pipeline state.
|
||||
struct GraphicsPipelineStateDesc
|
||||
{
|
||||
BlendStateDesc blendState;
|
||||
};
|
||||
|
||||
// We don't provide additional helpers intentionally because all custom states
|
||||
// should be described with a related shader and should be switched together.
|
||||
GraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc();
|
||||
|
||||
BlendFactor ParseBlendFactor(const CStr& str);
|
||||
BlendOp ParseBlendOp(const CStr& str);
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
#endif // INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
/* Copyright (C) 2022 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 0 A.D. is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
#define INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
|
||||
#include "graphics/Color.h"
|
||||
|
||||
class CStr;
|
||||
|
||||
namespace Renderer
|
||||
{
|
||||
|
||||
namespace Backend
|
||||
{
|
||||
|
||||
// TODO: add per constant description.
|
||||
|
||||
enum class BlendFactor
|
||||
{
|
||||
ZERO,
|
||||
ONE,
|
||||
SRC_COLOR,
|
||||
ONE_MINUS_SRC_COLOR,
|
||||
DST_COLOR,
|
||||
ONE_MINUS_DST_COLOR,
|
||||
SRC_ALPHA,
|
||||
ONE_MINUS_SRC_ALPHA,
|
||||
DST_ALPHA,
|
||||
ONE_MINUS_DST_ALPHA,
|
||||
CONSTANT_COLOR,
|
||||
ONE_MINUS_CONSTANT_COLOR,
|
||||
CONSTANT_ALPHA,
|
||||
ONE_MINUS_CONSTANT_ALPHA,
|
||||
SRC_ALPHA_SATURATE,
|
||||
SRC1_COLOR,
|
||||
ONE_MINUS_SRC1_COLOR,
|
||||
SRC1_ALPHA,
|
||||
ONE_MINUS_SRC1_ALPHA,
|
||||
};
|
||||
|
||||
enum class BlendOp
|
||||
{
|
||||
ADD,
|
||||
SUBTRACT,
|
||||
REVERSE_SUBTRACT,
|
||||
MIN,
|
||||
MAX
|
||||
};
|
||||
|
||||
struct BlendStateDesc
|
||||
{
|
||||
bool enabled;
|
||||
BlendFactor srcColorBlendFactor;
|
||||
BlendFactor dstColorBlendFactor;
|
||||
BlendOp colorBlendOp;
|
||||
BlendFactor srcAlphaBlendFactor;
|
||||
BlendFactor dstAlphaBlendFactor;
|
||||
BlendOp alphaBlendOp;
|
||||
CColor constant;
|
||||
};
|
||||
|
||||
enum class CullMode
|
||||
{
|
||||
NONE,
|
||||
FRONT,
|
||||
BACK
|
||||
};
|
||||
|
||||
enum class FrontFace
|
||||
{
|
||||
COUNTER_CLOCKWISE,
|
||||
CLOCKWISE
|
||||
};
|
||||
|
||||
struct RasterizationStateDesc
|
||||
{
|
||||
CullMode cullMode;
|
||||
FrontFace frontFace;
|
||||
};
|
||||
|
||||
// TODO: Add a shader program to the graphics pipeline state.
|
||||
struct GraphicsPipelineStateDesc
|
||||
{
|
||||
BlendStateDesc blendState;
|
||||
RasterizationStateDesc rasterizationState;
|
||||
};
|
||||
|
||||
// We don't provide additional helpers intentionally because all custom states
|
||||
// should be described with a related shader and should be switched together.
|
||||
GraphicsPipelineStateDesc MakeDefaultGraphicsPipelineStateDesc();
|
||||
|
||||
BlendFactor ParseBlendFactor(const CStr& str);
|
||||
BlendOp ParseBlendOp(const CStr& str);
|
||||
|
||||
CullMode ParseCullMode(const CStr& str);
|
||||
FrontFace ParseFrontFace(const CStr& str);
|
||||
|
||||
} // namespace Backend
|
||||
|
||||
} // namespace Renderer
|
||||
|
||||
#endif // INCLUDED_RENDERER_BACKEND_PIPELINESTATE
|
||||
|
||||
Reference in New Issue
Block a user