Route paint UI clear state through GL backend
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "util.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
@@ -92,6 +93,26 @@ void set_opengl_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std:
|
||||
glScissor(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
|
||||
}
|
||||
|
||||
void set_opengl_clear_color(float r, float g, float b, float a) noexcept
|
||||
{
|
||||
glClearColor(r, g, b, a);
|
||||
}
|
||||
|
||||
void get_opengl_integer(std::uint32_t name, std::int32_t* values) noexcept
|
||||
{
|
||||
GLint raw_values[4] {};
|
||||
glGetIntegerv(static_cast<GLenum>(name), raw_values);
|
||||
values[0] = static_cast<std::int32_t>(raw_values[0]);
|
||||
values[1] = static_cast<std::int32_t>(raw_values[1]);
|
||||
values[2] = static_cast<std::int32_t>(raw_values[2]);
|
||||
values[3] = static_cast<std::int32_t>(raw_values[3]);
|
||||
}
|
||||
|
||||
void get_opengl_float(std::uint32_t name, float* values) noexcept
|
||||
{
|
||||
glGetFloatv(static_cast<GLenum>(name), values);
|
||||
}
|
||||
|
||||
void apply_stroke_preview_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_viewport(
|
||||
@@ -108,6 +129,41 @@ void apply_stroke_preview_viewport(std::int32_t x, std::int32_t y, std::int32_t
|
||||
LOG("NodeStrokePreview viewport dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
pp::renderer::gl::OpenGlViewportRect query_stroke_preview_viewport()
|
||||
{
|
||||
const auto result = pp::renderer::gl::query_opengl_viewport(
|
||||
pp::renderer::gl::OpenGlViewportQueryDispatch {
|
||||
.get_integer = get_opengl_integer,
|
||||
});
|
||||
if (!result.ok()) {
|
||||
LOG("NodeStrokePreview viewport query dispatch failed because: %s", result.status().message);
|
||||
}
|
||||
return result.value();
|
||||
}
|
||||
|
||||
std::array<float, 4> query_stroke_preview_clear_color()
|
||||
{
|
||||
const auto result = pp::renderer::gl::query_opengl_clear_color(
|
||||
pp::renderer::gl::OpenGlClearColorQueryDispatch {
|
||||
.get_float = get_opengl_float,
|
||||
});
|
||||
if (!result.ok()) {
|
||||
LOG("NodeStrokePreview clear-color query dispatch failed because: %s", result.status().message);
|
||||
}
|
||||
return result.value();
|
||||
}
|
||||
|
||||
void apply_stroke_preview_clear_color(std::array<float, 4> color)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_clear_color(
|
||||
color,
|
||||
pp::renderer::gl::OpenGlClearColorDispatch {
|
||||
.clear_color = set_opengl_clear_color,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("NodeStrokePreview clear-color dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
void apply_stroke_preview_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_scissor_rect(
|
||||
@@ -398,10 +454,8 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
if (m_size.x == 0 || m_size.y == 0)
|
||||
return;
|
||||
|
||||
GLint vp[4];
|
||||
GLfloat cc[4];
|
||||
glGetIntegerv(pp::renderer::gl::viewport_query(), vp);
|
||||
glGetFloatv(pp::renderer::gl::color_clear_value_query(), cc);
|
||||
const auto vp = query_stroke_preview_viewport();
|
||||
const auto cc = query_stroke_preview_clear_color();
|
||||
|
||||
float zoom = root()->m_zoom;
|
||||
|
||||
@@ -668,8 +722,8 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
|
||||
m_rtt.unbindFramebuffer();
|
||||
|
||||
apply_stroke_preview_viewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
apply_stroke_preview_viewport(vp.x, vp.y, vp.width, vp.height);
|
||||
apply_stroke_preview_clear_color(cc);
|
||||
}
|
||||
|
||||
Image NodeStrokePreview::render_to_image()
|
||||
|
||||
Reference in New Issue
Block a user