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;
|
||||
|
||||
@@ -281,6 +281,51 @@ pp::foundation::Status clear_panopainter_default_target(OpenGlClearDispatch disp
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status apply_opengl_viewport(
|
||||
OpenGlViewportRect viewport,
|
||||
OpenGlViewportDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.viewport == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL viewport dispatch callback must not be null");
|
||||
}
|
||||
|
||||
dispatch.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status apply_opengl_scissor_rect(
|
||||
OpenGlScissorRect scissor,
|
||||
OpenGlScissorDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.enable == nullptr || dispatch.disable == nullptr || dispatch.scissor == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL scissor dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
if (scissor.enabled != 0U) {
|
||||
dispatch.enable(scissor_test_state());
|
||||
dispatch.scissor(scissor.x, scissor.y, scissor.width, scissor.height);
|
||||
} else {
|
||||
dispatch.disable(scissor_test_state());
|
||||
}
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
pp::foundation::Status apply_opengl_scissor_test(
|
||||
bool enabled,
|
||||
OpenGlScissorTestDispatch dispatch) noexcept
|
||||
{
|
||||
if (dispatch.enable == nullptr || dispatch.disable == nullptr) {
|
||||
return pp::foundation::Status::invalid_argument("OpenGL scissor test dispatch callbacks must not be null");
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
dispatch.enable(scissor_test_state());
|
||||
} else {
|
||||
dispatch.disable(scissor_test_state());
|
||||
}
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
std::uint32_t extension_count_query() noexcept
|
||||
{
|
||||
return gl_num_extensions;
|
||||
|
||||
@@ -155,12 +155,29 @@ struct OpenGlDefaultClear {
|
||||
|
||||
using OpenGlClearColorFn = void (*)(float r, float g, float b, float a) noexcept;
|
||||
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;
|
||||
|
||||
struct OpenGlClearDispatch {
|
||||
OpenGlClearColorFn clear_color = nullptr;
|
||||
OpenGlClearFn clear = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlViewportDispatch {
|
||||
OpenGlViewportFn viewport = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlScissorDispatch {
|
||||
OpenGlCapabilityFn enable = nullptr;
|
||||
OpenGlCapabilityFn disable = nullptr;
|
||||
OpenGlScissorFn scissor = nullptr;
|
||||
};
|
||||
|
||||
struct OpenGlScissorTestDispatch {
|
||||
OpenGlCapabilityFn enable = nullptr;
|
||||
OpenGlCapabilityFn disable = nullptr;
|
||||
};
|
||||
|
||||
[[nodiscard]] OpenGlCapabilities detect_opengl_capabilities(
|
||||
std::span<const std::string_view> extensions,
|
||||
OpenGlRuntime runtime) noexcept;
|
||||
@@ -172,6 +189,15 @@ struct OpenGlClearDispatch {
|
||||
OpenGlRuntimeInfoDispatch dispatch) noexcept;
|
||||
[[nodiscard]] OpenGlDefaultClear panopainter_default_clear() noexcept;
|
||||
[[nodiscard]] pp::foundation::Status clear_panopainter_default_target(OpenGlClearDispatch dispatch) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status apply_opengl_viewport(
|
||||
OpenGlViewportRect viewport,
|
||||
OpenGlViewportDispatch dispatch) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status apply_opengl_scissor_rect(
|
||||
OpenGlScissorRect scissor,
|
||||
OpenGlScissorDispatch dispatch) noexcept;
|
||||
[[nodiscard]] pp::foundation::Status apply_opengl_scissor_test(
|
||||
bool enabled,
|
||||
OpenGlScissorTestDispatch 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