Route UI capability queries through GL backend
This commit is contained in:
@@ -21,11 +21,22 @@ void disable_opengl_state(std::uint32_t state) noexcept
|
||||
glDisable(static_cast<GLenum>(state));
|
||||
}
|
||||
|
||||
std::uint8_t is_opengl_state_enabled(std::uint32_t state) noexcept
|
||||
{
|
||||
return static_cast<std::uint8_t>(glIsEnabled(static_cast<GLenum>(state)));
|
||||
}
|
||||
|
||||
void set_opengl_active_texture(std::uint32_t texture_unit) noexcept
|
||||
{
|
||||
glActiveTexture(static_cast<GLenum>(texture_unit));
|
||||
}
|
||||
|
||||
void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept
|
||||
{
|
||||
static_assert(sizeof(GLint) == sizeof(std::int32_t));
|
||||
glGetIntegerv(static_cast<GLenum>(name), reinterpret_cast<GLint*>(values));
|
||||
}
|
||||
|
||||
void set_opengl_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept
|
||||
{
|
||||
glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
|
||||
@@ -54,6 +65,20 @@ void apply_grid_capability(std::uint32_t state, bool enabled)
|
||||
LOG("Grid capability dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
bool query_grid_capability(std::uint32_t state)
|
||||
{
|
||||
const auto result = pp::renderer::gl::query_opengl_capability_state(
|
||||
state,
|
||||
pp::renderer::gl::OpenGlCapabilityStateQueryDispatch {
|
||||
.is_enabled = is_opengl_state_enabled,
|
||||
});
|
||||
if (!result.ok()) {
|
||||
LOG("Grid capability query failed because: %s", result.status().message);
|
||||
return false;
|
||||
}
|
||||
return result.value();
|
||||
}
|
||||
|
||||
void set_grid_active_texture_unit(std::uint32_t unit_index)
|
||||
{
|
||||
const auto status = pp::renderer::gl::activate_opengl_texture_unit(
|
||||
@@ -81,6 +106,18 @@ void apply_grid_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std
|
||||
LOG("Grid viewport dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
pp::renderer::gl::OpenGlViewportRect query_grid_viewport()
|
||||
{
|
||||
const auto result = pp::renderer::gl::query_opengl_viewport(
|
||||
pp::renderer::gl::OpenGlViewportQueryDispatch {
|
||||
.get_integer = get_opengl_integer,
|
||||
});
|
||||
if (!result.ok()) {
|
||||
LOG("Grid viewport query failed because: %s", result.status().message);
|
||||
}
|
||||
return result.value();
|
||||
}
|
||||
|
||||
void clear_grid_depth_buffer()
|
||||
{
|
||||
const auto status = pp::renderer::gl::clear_opengl_buffers(
|
||||
@@ -308,7 +345,7 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
assert(App::I->is_render_thread());
|
||||
if (m_groud_opacity->get_value() > 0.f)
|
||||
{
|
||||
bool depth = glIsEnabled(pp::renderer::gl::depth_test_state());
|
||||
const bool depth = query_grid_capability(pp::renderer::gl::depth_test_state());
|
||||
apply_grid_capability(pp::renderer::gl::depth_test_state(), true);
|
||||
clear_grid_depth_buffer();
|
||||
|
||||
@@ -399,9 +436,8 @@ void NodePanelGrid::draw_heightmap(const glm::mat4& proj, const glm::mat4& camer
|
||||
if (c.w > 0)
|
||||
{
|
||||
auto p2d = xy(c) / c.z;
|
||||
GLint vp[4];
|
||||
glGetIntegerv(pp::renderer::gl::viewport_query(), vp);
|
||||
auto aspect_ratio = (float)vp[3] / (float)vp[2];
|
||||
const auto viewport = query_grid_viewport();
|
||||
auto aspect_ratio = static_cast<float>(viewport.height) / static_cast<float>(viewport.width);
|
||||
apply_grid_capability(pp::renderer::gl::blend_state(), true);
|
||||
apply_grid_capability(pp::renderer::gl::depth_test_state(), false);
|
||||
ShaderManager::use(kShader::Texture);
|
||||
|
||||
Reference in New Issue
Block a user