Map renderer blend state to OpenGL

This commit is contained in:
2026-06-02 20:26:55 +02:00
parent 36f9e73dd4
commit 728116da8f
5 changed files with 114 additions and 8 deletions

View File

@@ -813,6 +813,33 @@ OpenGlEnumMapping blend_equation_for_renderer_op(pp::renderer::BlendOp op) noexc
}
}
OpenGlBlendState blend_state_for_renderer_blend_state(pp::renderer::BlendState state) noexcept
{
const auto source_color = blend_factor_for_renderer_factor(state.source_color);
const auto destination_color = blend_factor_for_renderer_factor(state.destination_color);
const auto color_op = blend_equation_for_renderer_op(state.color_op);
const auto source_alpha = blend_factor_for_renderer_factor(state.source_alpha);
const auto destination_alpha = blend_factor_for_renderer_factor(state.destination_alpha);
const auto alpha_op = blend_equation_for_renderer_op(state.alpha_op);
return OpenGlBlendState {
.enabled = state.enabled ? gl_boolean_true : gl_boolean_false,
.source_color_factor = source_color.value,
.destination_color_factor = destination_color.value,
.color_equation = color_op.value,
.source_alpha_factor = source_alpha.value,
.destination_alpha_factor = destination_alpha.value,
.alpha_equation = alpha_op.value,
.color_write_mask = color_write_mask_for_renderer_blend_state(state),
.supported = source_color.supported
&& destination_color.supported
&& color_op.supported
&& source_alpha.supported
&& destination_alpha.supported
&& alpha_op.supported,
};
}
std::uint32_t rgba8_internal_format() noexcept
{
return gl_rgba8;

View File

@@ -46,6 +46,18 @@ struct OpenGlColorWriteMask {
std::uint8_t a = 0;
};
struct OpenGlBlendState {
std::uint8_t enabled = 0;
std::uint32_t source_color_factor = 0;
std::uint32_t destination_color_factor = 0;
std::uint32_t color_equation = 0;
std::uint32_t source_alpha_factor = 0;
std::uint32_t destination_alpha_factor = 0;
std::uint32_t alpha_equation = 0;
OpenGlColorWriteMask color_write_mask;
bool supported = false;
};
struct OpenGlDepthState {
std::uint8_t test_enabled = 0;
std::uint8_t write_enabled = 0;
@@ -169,6 +181,8 @@ struct OpenGlWindowsWglContextConfig {
pp::renderer::BlendFactor factor) noexcept;
[[nodiscard]] OpenGlEnumMapping blend_equation_for_renderer_op(
pp::renderer::BlendOp op) noexcept;
[[nodiscard]] OpenGlBlendState blend_state_for_renderer_blend_state(
pp::renderer::BlendState state) noexcept;
[[nodiscard]] std::uint32_t rgba8_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba16f_internal_format() noexcept;
[[nodiscard]] std::uint32_t rgba32f_internal_format() noexcept;