Apply startup GL state through renderer GL
This commit is contained in:
41
src/app.cpp
41
src/app.cpp
@@ -50,6 +50,26 @@ namespace {
|
||||
return static_cast<GLenum>(pp::renderer::gl::scissor_test_state());
|
||||
}
|
||||
|
||||
void enable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glEnable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
void disable_opengl_state(std::uint32_t state) noexcept
|
||||
{
|
||||
glDisable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
void set_opengl_blend_func(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept
|
||||
{
|
||||
glBlendFunc(static_cast<GLenum>(source_factor), static_cast<GLenum>(destination_factor));
|
||||
}
|
||||
|
||||
void set_opengl_blend_equation_separate(std::uint32_t color_equation, std::uint32_t alpha_equation) noexcept
|
||||
{
|
||||
glBlendEquationSeparate(static_cast<GLenum>(color_equation), static_cast<GLenum>(alpha_equation));
|
||||
}
|
||||
|
||||
[[nodiscard]] GLint rgba8_internal_format() noexcept
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
|
||||
@@ -389,19 +409,16 @@ void App::init()
|
||||
// }
|
||||
//}
|
||||
|
||||
const auto initial_state = pp::renderer::gl::panopainter_initial_state();
|
||||
if (initial_state.depth_test_enabled)
|
||||
glEnable(static_cast<GLenum>(initial_state.depth_test_state));
|
||||
else
|
||||
glDisable(static_cast<GLenum>(initial_state.depth_test_state));
|
||||
|
||||
App::I->apply_render_platform_hints();
|
||||
glBlendFunc(
|
||||
static_cast<GLenum>(initial_state.source_color_factor),
|
||||
static_cast<GLenum>(initial_state.destination_color_factor));
|
||||
glBlendEquationSeparate(
|
||||
static_cast<GLenum>(initial_state.color_equation),
|
||||
static_cast<GLenum>(initial_state.alpha_equation));
|
||||
const auto startup_state_status = pp::renderer::gl::apply_panopainter_initial_state(
|
||||
pp::renderer::gl::OpenGlStateDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
.blend_func = set_opengl_blend_func,
|
||||
.blend_equation_separate = set_opengl_blend_equation_separate,
|
||||
});
|
||||
if (!startup_state_status.ok())
|
||||
LOG("OpenGL startup state failed: %s", startup_state_status.message);
|
||||
});
|
||||
|
||||
int run_counter = Settings::value<Serializer::Integer>("run_counter") + 1;
|
||||
|
||||
@@ -224,6 +224,27 @@ OpenGlInitialState panopainter_initial_state() noexcept
|
||||
};
|
||||
}
|
||||
|
||||
pp::foundation::Status apply_panopainter_initial_state(OpenGlStateDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.enable == nullptr
|
||||
|| dispatch.disable == nullptr
|
||||
|| dispatch.blend_func == nullptr
|
||||
|| dispatch.blend_equation_separate == nullptr)
|
||||
{
|
||||
return pp::foundation::Status::invalid_argument("OpenGL state dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
const auto state = panopainter_initial_state();
|
||||
if (state.depth_test_enabled)
|
||||
dispatch.enable(state.depth_test_state);
|
||||
else
|
||||
dispatch.disable(state.depth_test_state);
|
||||
|
||||
dispatch.blend_func(state.source_color_factor, state.destination_color_factor);
|
||||
dispatch.blend_equation_separate(state.color_equation, state.alpha_equation);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
std::uint32_t extension_count_query() noexcept
|
||||
{
|
||||
return gl_num_extensions;
|
||||
|
||||
@@ -124,12 +124,24 @@ struct OpenGlInitialState {
|
||||
std::uint32_t alpha_equation = 0;
|
||||
};
|
||||
|
||||
using OpenGlCapabilityFn = void (*)(std::uint32_t state) noexcept;
|
||||
using OpenGlBlendFuncFn = void (*)(std::uint32_t source_factor, std::uint32_t destination_factor) noexcept;
|
||||
using OpenGlBlendEquationSeparateFn = void (*)(std::uint32_t color_equation, std::uint32_t alpha_equation) noexcept;
|
||||
|
||||
struct OpenGlStateDispatch {
|
||||
OpenGlCapabilityFn enable = nullptr;
|
||||
OpenGlCapabilityFn disable = nullptr;
|
||||
OpenGlBlendFuncFn blend_func = nullptr;
|
||||
OpenGlBlendEquationSeparateFn blend_equation_separate = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
[[nodiscard]] pp::renderer::RenderDeviceFeatures render_device_features(
|
||||
OpenGlCapabilities capabilities) noexcept;
|
||||
[[nodiscard]] OpenGlInitialState panopainter_initial_state() noexcept;
|
||||
[[nodiscard]] pp::foundation::Status apply_panopainter_initial_state(OpenGlStateDispatch dispatch) noexcept;
|
||||
|
||||
[[nodiscard]] std::uint32_t extension_count_query() noexcept;
|
||||
[[nodiscard]] std::uint32_t extension_string_name() noexcept;
|
||||
|
||||
Reference in New Issue
Block a user