mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 22:28:32 +09:00
[Chore] (MG_Backend/DirectVulkan): move enum conversion to MG_Utils
This commit is contained in:
@@ -13,6 +13,7 @@
|
|||||||
#include "MG_State/GLState/Core.h"
|
#include "MG_State/GLState/Core.h"
|
||||||
#include "MG_State/GLState/ProgramState/ProgramObject.h"
|
#include "MG_State/GLState/ProgramState/ProgramObject.h"
|
||||||
#include "MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h"
|
#include "MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h"
|
||||||
|
#include "MG_Util/Converters/MGToVk/RenderStateEnumConverter.h"
|
||||||
#include <vulkan/vulkan_core.h>
|
#include <vulkan/vulkan_core.h>
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
@@ -335,82 +336,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
const MG_State::GLState::ProgramObject& program,
|
const MG_State::GLState::ProgramObject& program,
|
||||||
const MG_State::GLState::VertexArrayObject& vao,
|
const MG_State::GLState::VertexArrayObject& vao,
|
||||||
const MG_State::GLState::FramebufferObject& drawFbo) {
|
const MG_State::GLState::FramebufferObject& drawFbo) {
|
||||||
auto toVkTopology = [](GLenum mode) -> VkPrimitiveTopology {
|
|
||||||
switch (mode) {
|
|
||||||
case GL_POINTS:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
|
|
||||||
case GL_LINES:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
|
||||||
case GL_LINE_STRIP:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
|
|
||||||
case GL_TRIANGLES:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
|
||||||
case GL_TRIANGLE_STRIP:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
|
||||||
case GL_TRIANGLE_FAN:
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
|
|
||||||
case GL_LINE_LOOP:
|
|
||||||
default:
|
|
||||||
MGLOG_W("Unrecognized primitive topology");
|
|
||||||
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
auto toVkCompareOp = [](DepthTestFunc func) -> VkCompareOp {
|
|
||||||
switch (func) {
|
|
||||||
case DepthTestFunc::Never:
|
|
||||||
return VK_COMPARE_OP_NEVER;
|
|
||||||
case DepthTestFunc::Less:
|
|
||||||
return VK_COMPARE_OP_LESS;
|
|
||||||
case DepthTestFunc::Equal:
|
|
||||||
return VK_COMPARE_OP_EQUAL;
|
|
||||||
case DepthTestFunc::LessEqual:
|
|
||||||
return VK_COMPARE_OP_LESS_OR_EQUAL;
|
|
||||||
case DepthTestFunc::Greater:
|
|
||||||
return VK_COMPARE_OP_GREATER;
|
|
||||||
case DepthTestFunc::NotEqual:
|
|
||||||
return VK_COMPARE_OP_NOT_EQUAL;
|
|
||||||
case DepthTestFunc::GreaterEqual:
|
|
||||||
return VK_COMPARE_OP_GREATER_OR_EQUAL;
|
|
||||||
case DepthTestFunc::Always:
|
|
||||||
default:
|
|
||||||
return VK_COMPARE_OP_ALWAYS;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
auto toVkBlendFactor = [](BlendFactor factor) -> VkBlendFactor {
|
|
||||||
switch (factor) {
|
|
||||||
case BlendFactor::Zero:
|
|
||||||
return VK_BLEND_FACTOR_ZERO;
|
|
||||||
case BlendFactor::One:
|
|
||||||
return VK_BLEND_FACTOR_ONE;
|
|
||||||
case BlendFactor::SrcColor:
|
|
||||||
return VK_BLEND_FACTOR_SRC_COLOR;
|
|
||||||
case BlendFactor::OneMinusSrcColor:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
|
|
||||||
case BlendFactor::DstColor:
|
|
||||||
return VK_BLEND_FACTOR_DST_COLOR;
|
|
||||||
case BlendFactor::OneMinusDstColor:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
|
|
||||||
case BlendFactor::SrcAlpha:
|
|
||||||
return VK_BLEND_FACTOR_SRC_ALPHA;
|
|
||||||
case BlendFactor::OneMinusSrcAlpha:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
|
||||||
case BlendFactor::DstAlpha:
|
|
||||||
return VK_BLEND_FACTOR_DST_ALPHA;
|
|
||||||
case BlendFactor::OneMinusDstAlpha:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
|
|
||||||
case BlendFactor::ConstantColor:
|
|
||||||
return VK_BLEND_FACTOR_CONSTANT_COLOR;
|
|
||||||
case BlendFactor::OneMinusConstantColor:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
|
|
||||||
case BlendFactor::ConstantAlpha:
|
|
||||||
return VK_BLEND_FACTOR_CONSTANT_ALPHA;
|
|
||||||
case BlendFactor::OneMinusConstantAlpha:
|
|
||||||
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA;
|
|
||||||
default:
|
|
||||||
return VK_BLEND_FACTOR_ONE;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ProgramFactory::CompileOptionFlags transformFlags = GetShaderTransformFlags(m_swapchainObject.GetPreTransform());
|
ProgramFactory::CompileOptionFlags transformFlags = GetShaderTransformFlags(m_swapchainObject.GetPreTransform());
|
||||||
auto& stages = m_programFactory->GetOrCreatePipelineShaderStages(program, transformFlags);
|
auto& stages = m_programFactory->GetOrCreatePipelineShaderStages(program, transformFlags);
|
||||||
if (stages.empty()) {
|
if (stages.empty()) {
|
||||||
@@ -437,15 +362,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
.pipelineLayout = pipelineLayout,
|
.pipelineLayout = pipelineLayout,
|
||||||
.renderPass = renderPassEntry.renderPass,
|
.renderPass = renderPassEntry.renderPass,
|
||||||
.subpass = 0,
|
.subpass = 0,
|
||||||
.topology = toVkTopology(mode),
|
.topology = MG_Util::ConvertPrimitiveModeToVkEnum(mode),
|
||||||
.depthTestEnable = depthTestEnabled,
|
.depthTestEnable = depthTestEnabled,
|
||||||
.depthWriteEnable = depthTestEnabled && MG_State::pGLContext->GetDepthMask(),
|
.depthWriteEnable = depthTestEnabled && MG_State::pGLContext->GetDepthMask(),
|
||||||
.depthCompareOp = toVkCompareOp(MG_State::pGLContext->GetDepthFunc()),
|
.depthCompareOp = MG_Util::ConvertDepthTestFuncToVkEnum(MG_State::pGLContext->GetDepthFunc()),
|
||||||
.blendEnable = MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::Blend),
|
.blendEnable = MG_State::pGLContext->IsCapabilityEnabled(CapabilityInput::Blend),
|
||||||
.srcColorBlendFactor = toVkBlendFactor(srcRGB),
|
.srcColorBlendFactor = MG_Util::ConvertBlendFactorToVkEnum(srcRGB),
|
||||||
.dstColorBlendFactor = toVkBlendFactor(dstRGB),
|
.dstColorBlendFactor = MG_Util::ConvertBlendFactorToVkEnum(dstRGB),
|
||||||
.srcAlphaBlendFactor = toVkBlendFactor(srcAlpha),
|
.srcAlphaBlendFactor = MG_Util::ConvertBlendFactorToVkEnum(srcAlpha),
|
||||||
.dstAlphaBlendFactor = toVkBlendFactor(dstAlpha),
|
.dstAlphaBlendFactor = MG_Util::ConvertBlendFactorToVkEnum(dstAlpha),
|
||||||
.colorWriteMask = (
|
.colorWriteMask = (
|
||||||
(mask.r() ? VK_COLOR_COMPONENT_R_BIT : 0u) |
|
(mask.r() ? VK_COLOR_COMPONENT_R_BIT : 0u) |
|
||||||
(mask.g() ? VK_COLOR_COMPONENT_G_BIT : 0u) |
|
(mask.g() ? VK_COLOR_COMPONENT_G_BIT : 0u) |
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Util/Converters/MGToVk/RenderStateEnumConverter.cpp
|
||||||
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||||
|
// Licensed under the GNU Lesser General Public License v3.0:
|
||||||
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||||||
|
// End of Source File Header
|
||||||
|
|
||||||
|
#include "RenderStateEnumConverter.h"
|
||||||
|
|
||||||
|
namespace MobileGL {
|
||||||
|
namespace MG_Util {
|
||||||
|
VkPrimitiveTopology ConvertPrimitiveModeToVkEnum(GLenum mode) {
|
||||||
|
switch (mode) {
|
||||||
|
case GL_POINTS:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
|
||||||
|
case GL_LINES:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
|
||||||
|
case GL_LINE_STRIP:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
|
||||||
|
case GL_TRIANGLES:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
|
case GL_TRIANGLE_STRIP:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
|
||||||
|
case GL_TRIANGLE_FAN:
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN;
|
||||||
|
case GL_LINE_LOOP:
|
||||||
|
default:
|
||||||
|
MGLOG_W("Unrecognized primitive topology");
|
||||||
|
return VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkCompareOp ConvertDepthTestFuncToVkEnum(DepthTestFunc v) {
|
||||||
|
switch (v) {
|
||||||
|
case DepthTestFunc::Never:
|
||||||
|
return VK_COMPARE_OP_NEVER;
|
||||||
|
case DepthTestFunc::Less:
|
||||||
|
return VK_COMPARE_OP_LESS;
|
||||||
|
case DepthTestFunc::Equal:
|
||||||
|
return VK_COMPARE_OP_EQUAL;
|
||||||
|
case DepthTestFunc::LessEqual:
|
||||||
|
return VK_COMPARE_OP_LESS_OR_EQUAL;
|
||||||
|
case DepthTestFunc::Greater:
|
||||||
|
return VK_COMPARE_OP_GREATER;
|
||||||
|
case DepthTestFunc::NotEqual:
|
||||||
|
return VK_COMPARE_OP_NOT_EQUAL;
|
||||||
|
case DepthTestFunc::GreaterEqual:
|
||||||
|
return VK_COMPARE_OP_GREATER_OR_EQUAL;
|
||||||
|
case DepthTestFunc::Always:
|
||||||
|
default:
|
||||||
|
return VK_COMPARE_OP_ALWAYS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkBlendFactor ConvertBlendFactorToVkEnum(BlendFactor v) {
|
||||||
|
switch (v) {
|
||||||
|
case BlendFactor::Zero:
|
||||||
|
return VK_BLEND_FACTOR_ZERO;
|
||||||
|
case BlendFactor::One:
|
||||||
|
return VK_BLEND_FACTOR_ONE;
|
||||||
|
case BlendFactor::SrcColor:
|
||||||
|
return VK_BLEND_FACTOR_SRC_COLOR;
|
||||||
|
case BlendFactor::OneMinusSrcColor:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR;
|
||||||
|
case BlendFactor::DstColor:
|
||||||
|
return VK_BLEND_FACTOR_DST_COLOR;
|
||||||
|
case BlendFactor::OneMinusDstColor:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR;
|
||||||
|
case BlendFactor::SrcAlpha:
|
||||||
|
return VK_BLEND_FACTOR_SRC_ALPHA;
|
||||||
|
case BlendFactor::OneMinusSrcAlpha:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
|
||||||
|
case BlendFactor::DstAlpha:
|
||||||
|
return VK_BLEND_FACTOR_DST_ALPHA;
|
||||||
|
case BlendFactor::OneMinusDstAlpha:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA;
|
||||||
|
case BlendFactor::ConstantColor:
|
||||||
|
return VK_BLEND_FACTOR_CONSTANT_COLOR;
|
||||||
|
case BlendFactor::OneMinusConstantColor:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR;
|
||||||
|
case BlendFactor::ConstantAlpha:
|
||||||
|
return VK_BLEND_FACTOR_CONSTANT_ALPHA;
|
||||||
|
case BlendFactor::OneMinusConstantAlpha:
|
||||||
|
return VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA;
|
||||||
|
default:
|
||||||
|
return VK_BLEND_FACTOR_ONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace MG_Util
|
||||||
|
} // namespace MobileGL
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// MobileGL - MobileGL/MG_Util/Converters/MGToVk/RenderStateEnumConverter.h
|
||||||
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||||
|
// Licensed under the GNU Lesser General Public License v3.0:
|
||||||
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||||
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-only
|
||||||
|
// End of Source File Header
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <Includes.h>
|
||||||
|
#include <MG_State/GLState/RenderState/RenderState.h>
|
||||||
|
|
||||||
|
namespace MobileGL {
|
||||||
|
namespace MG_Util {
|
||||||
|
VkPrimitiveTopology ConvertPrimitiveModeToVkEnum(GLenum mode);
|
||||||
|
VkCompareOp ConvertDepthTestFuncToVkEnum(DepthTestFunc value);
|
||||||
|
VkBlendFactor ConvertBlendFactorToVkEnum(BlendFactor value);
|
||||||
|
} // namespace MG_Util
|
||||||
|
} // namespace MobileGL
|
||||||
Reference in New Issue
Block a user