Route app viewport scissor through renderer GL
This commit is contained in:
79
src/app.cpp
79
src/app.cpp
@@ -25,11 +25,6 @@ std::condition_variable App::render_cv;
|
||||
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] GLenum scissor_test_state() noexcept
|
||||
{
|
||||
return static_cast<GLenum>(pp::renderer::gl::scissor_test_state());
|
||||
}
|
||||
|
||||
[[nodiscard]] const char* query_opengl_string(std::uint32_t name) noexcept
|
||||
{
|
||||
return reinterpret_cast<const char*>(glGetString(static_cast<GLenum>(name)));
|
||||
@@ -65,6 +60,52 @@ void clear_opengl_buffers(std::uint32_t mask) noexcept
|
||||
glClear(static_cast<GLbitfield>(mask));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void set_opengl_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height) noexcept
|
||||
{
|
||||
glScissor(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
|
||||
}
|
||||
|
||||
void apply_app_viewport(pp::renderer::gl::OpenGlViewportRect viewport)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_viewport(
|
||||
viewport,
|
||||
pp::renderer::gl::OpenGlViewportDispatch {
|
||||
.viewport = set_opengl_viewport,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL viewport failed: %s", status.message);
|
||||
}
|
||||
|
||||
void apply_app_scissor(pp::renderer::gl::OpenGlScissorRect scissor)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_scissor_rect(
|
||||
scissor,
|
||||
pp::renderer::gl::OpenGlScissorDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
.scissor = set_opengl_scissor,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL scissor failed: %s", status.message);
|
||||
}
|
||||
|
||||
void apply_app_scissor_test(bool enabled)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_scissor_test(
|
||||
enabled,
|
||||
pp::renderer::gl::OpenGlScissorTestDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("OpenGL scissor test failed: %s", status.message);
|
||||
}
|
||||
|
||||
[[nodiscard]] GLint rgba8_internal_format() noexcept
|
||||
{
|
||||
return static_cast<GLint>(pp::renderer::gl::rgba8_internal_format());
|
||||
@@ -512,7 +553,13 @@ bool App::update_ui_observer(Node *n)
|
||||
n->m_on_screen = true;
|
||||
}
|
||||
glm::ivec4 c = glm::vec4(box.x - 1, (height / zoom - box.y - box.w - 1), box.z + 2, box.w + 2) * zoom;
|
||||
glScissor(floorf(c.x + off_x), floorf(c.y + off_y), ceilf(c.z), ceilf(c.w));
|
||||
apply_app_scissor(pp::renderer::gl::OpenGlScissorRect {
|
||||
.enabled = 1U,
|
||||
.x = static_cast<std::int32_t>(floorf(c.x + off_x)),
|
||||
.y = static_cast<std::int32_t>(floorf(c.y + off_y)),
|
||||
.width = static_cast<std::int32_t>(ceilf(c.z)),
|
||||
.height = static_cast<std::int32_t>(ceilf(c.w)),
|
||||
});
|
||||
n->draw();
|
||||
return true;
|
||||
}
|
||||
@@ -531,28 +578,36 @@ void App::draw(float dt)
|
||||
{
|
||||
uirtt.bindFramebuffer();
|
||||
uirtt.clear();
|
||||
glViewport(0, 0, uirtt.getWidth(), uirtt.getHeight());
|
||||
glEnable(scissor_test_state());
|
||||
apply_app_viewport(pp::renderer::gl::OpenGlViewportRect {
|
||||
.width = static_cast<std::int32_t>(uirtt.getWidth()),
|
||||
.height = static_cast<std::int32_t>(uirtt.getHeight()),
|
||||
});
|
||||
apply_app_scissor_test(true);
|
||||
for (int i = 1; i < layout[main_id]->m_children.size(); i++)
|
||||
layout[main_id]->m_children[i]->watch(observer);
|
||||
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
|
||||
layout_designer[main_id]->m_children[i]->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(scissor_test_state());
|
||||
apply_app_scissor_test(false);
|
||||
uirtt.unbindFramebuffer();
|
||||
}
|
||||
|
||||
if (!vr_only)
|
||||
{
|
||||
bind_main_render_target();
|
||||
glViewport(off_x, off_y, (GLsizei)width, (GLsizei)height);
|
||||
glEnable(scissor_test_state());
|
||||
apply_app_viewport(pp::renderer::gl::OpenGlViewportRect {
|
||||
.x = static_cast<std::int32_t>(off_x),
|
||||
.y = static_cast<std::int32_t>(off_y),
|
||||
.width = static_cast<std::int32_t>(width),
|
||||
.height = static_cast<std::int32_t>(height),
|
||||
});
|
||||
apply_app_scissor_test(true);
|
||||
for (int i = 0; i < layout[main_id]->m_children.size(); i++)
|
||||
layout[main_id]->m_children[i]->watch(observer);
|
||||
for (int i = 0; layout_designer.get(main_id) && i < layout_designer[main_id]->m_children.size(); i++)
|
||||
layout_designer[main_id]->m_children[i]->watch(observer);
|
||||
//msgbox->watch(observer);
|
||||
glDisable(scissor_test_state());
|
||||
apply_app_scissor_test(false);
|
||||
}
|
||||
|
||||
redraw = false;
|
||||
|
||||
Reference in New Issue
Block a user