Move convert GL state into renderer backend

This commit is contained in:
2026-06-04 20:27:43 +02:00
parent 51601adf6d
commit 967a15f15f
8 changed files with 172 additions and 25 deletions

View File

@@ -273,6 +273,47 @@ pp::foundation::Status apply_panopainter_initial_state(OpenGlStateDispatch dispa
return pp::foundation::Status::success();
}
OpenGlConvertCommandState panopainter_convert_command_state() noexcept
{
return OpenGlConvertCommandState {
.depth_test_enabled = false,
.program_point_size_enabled = true,
.depth_test_state = depth_test_state(),
.program_point_size_state = program_point_size_state(),
.source_color_factor = source_alpha_blend_factor(),
.destination_color_factor = one_minus_source_alpha_blend_factor(),
.blend_equation = add_blend_equation(),
};
}
pp::foundation::Status apply_panopainter_convert_command_state(
OpenGlConvertCommandStateDispatch dispatch) noexcept
{
if (dispatch.enable == nullptr
|| dispatch.disable == nullptr
|| dispatch.blend_func == nullptr
|| dispatch.blend_equation == nullptr)
{
return pp::foundation::Status::invalid_argument(
"OpenGL convert command state dispatch callbacks must not be null");
}
const auto state = panopainter_convert_command_state();
if (state.depth_test_enabled)
dispatch.enable(state.depth_test_state);
else
dispatch.disable(state.depth_test_state);
if (state.program_point_size_enabled)
dispatch.enable(state.program_point_size_state);
else
dispatch.disable(state.program_point_size_state);
dispatch.blend_func(state.source_color_factor, state.destination_color_factor);
dispatch.blend_equation(state.blend_equation);
return pp::foundation::Status::success();
}
pp::foundation::Result<OpenGlSavedState> snapshot_opengl_state(OpenGlStateSnapshotDispatch dispatch) noexcept
{
if (dispatch.is_enabled == nullptr

View File

@@ -272,6 +272,16 @@ struct OpenGlInitialState {
std::uint32_t alpha_equation = 0;
};
struct OpenGlConvertCommandState {
bool depth_test_enabled = false;
bool program_point_size_enabled = false;
std::uint32_t depth_test_state = 0;
std::uint32_t program_point_size_state = 0;
std::uint32_t source_color_factor = 0;
std::uint32_t destination_color_factor = 0;
std::uint32_t blend_equation = 0;
};
struct OpenGlSavedState {
std::uint8_t blend_enabled = 0;
std::uint8_t depth_test_enabled = 0;
@@ -297,6 +307,7 @@ using OpenGlClearFn = void (*)(std::uint32_t mask) noexcept;
using OpenGlViewportFn = void (*)(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept;
using OpenGlScissorFn = void (*)(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept;
using OpenGlBlendFuncFn = void (*)(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept;
using OpenGlBlendEquationFn = void (*)(std::uint32_t equation) noexcept;
using OpenGlBlendEquationSeparateFn = void (*)(std::uint32_t color_equation, std::uint32_t alpha_equation) noexcept;
using OpenGlUseProgramFn = void (*)(std::uint32_t program) noexcept;
using OpenGlDeleteProgramFn = void (*)(std::uint32_t program) noexcept;
@@ -444,6 +455,13 @@ struct OpenGlStateDispatch {
OpenGlBlendEquationSeparateFn blend_equation_separate = nullptr;
};
struct OpenGlConvertCommandStateDispatch {
OpenGlCapabilityFn enable = nullptr;
OpenGlCapabilityFn disable = nullptr;
OpenGlBlendFuncFn blend_func = nullptr;
OpenGlBlendEquationFn blend_equation = nullptr;
};
struct OpenGlStateSnapshotDispatch {
OpenGlIsEnabledFn is_enabled = nullptr;
OpenGlGetIntegerFn get_integer = nullptr;
@@ -715,6 +733,9 @@ struct OpenGlMeshDeleteDispatch {
OpenGlRuntime runtime);
[[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept;
[[nodiscard]] pp::foundation::Status apply_panopainter_initial_state(OpenGlStateDispatch dispatch) noexcept;
[[nodiscard]] OpenGlConvertCommandState panopainter_convert_command_state() noexcept;
[[nodiscard]] pp::foundation::Status apply_panopainter_convert_command_state(
OpenGlConvertCommandStateDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Result<OpenGlSavedState> snapshot_opengl_state(
OpenGlStateSnapshotDispatch dispatch) noexcept;
[[nodiscard]] pp::foundation::Status restore_opengl_state(