Move convert GL state into renderer backend
This commit is contained in:
@@ -1,43 +1,49 @@
|
||||
#include "pch.h"
|
||||
#include "app.h"
|
||||
#include "canvas.h"
|
||||
#include "log.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] GLenum depth_test_state() noexcept
|
||||
void enable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::depth_test_state());
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum program_point_size_state() noexcept
|
||||
void disable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::program_point_size_state());
|
||||
glDisable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum source_alpha_blend_factor() noexcept
|
||||
void set_opengl_blend_func(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::source_alpha_blend_factor());
|
||||
glBlendFunc(static_cast<GLenum>(source_factor), static_cast<GLenum>(destination_factor));
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum one_minus_source_alpha_blend_factor() noexcept
|
||||
void set_opengl_blend_equation(std::uint32_t equation) noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::one_minus_source_alpha_blend_factor());
|
||||
glBlendEquation(static_cast<GLenum>(equation));
|
||||
}
|
||||
|
||||
[[nodiscard]] GLenum add_blend_equation() noexcept
|
||||
void apply_convert_command_state()
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::add_blend_equation());
|
||||
const auto status = pp::renderer::gl::apply_panopainter_convert_command_state(
|
||||
pp::renderer::gl::OpenGlConvertCommandStateDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
.blend_func = set_opengl_blend_func,
|
||||
.blend_equation = set_opengl_blend_equation,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL convert command state failed: %s", status.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void App::cmd_convert(std::string pano_path, std::string out_path)
|
||||
{
|
||||
glDisable(depth_test_state());
|
||||
glEnable(program_point_size_state());
|
||||
glBlendFunc(source_alpha_blend_factor(), one_minus_source_alpha_blend_factor());
|
||||
glBlendEquation(add_blend_equation());
|
||||
apply_convert_command_state();
|
||||
|
||||
Canvas* command_canvas = new Canvas;
|
||||
const int canvas_resolution = default_canvas_resolution();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "app.h"
|
||||
#include "app_core/document_platform_io.h"
|
||||
#include "log.h"
|
||||
#include "platform_api/network_tls_policy.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
|
||||
@@ -57,6 +58,11 @@ void invoke_picked_path_if_selected(
|
||||
callback(path);
|
||||
}
|
||||
|
||||
void enable_gl_capability(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
// DEBT-0017: fallback for platforms that do not inject PlatformServices yet.
|
||||
class LegacyPlatformServices final : public pp::platform::PlatformServices {
|
||||
public:
|
||||
@@ -259,8 +265,12 @@ public:
|
||||
void apply_render_platform_hints() override
|
||||
{
|
||||
#if defined(__OSX__)
|
||||
glEnable(static_cast<GLenum>(pp::renderer::gl::program_point_size_state()));
|
||||
glEnable(static_cast<GLenum>(pp::renderer::gl::line_smooth_state()));
|
||||
const auto status = pp::renderer::gl::apply_opengl_render_platform_hints(
|
||||
pp::renderer::gl::OpenGlRenderPlatformHintDispatch {
|
||||
.enable = enable_gl_capability,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL legacy render platform hints failed: %s", status.message);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user