Route paint render state through GL backend
This commit is contained in:
@@ -72,6 +72,74 @@ void unbind_texture_2d()
|
||||
LOG("NodeStrokePreview texture unbind dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
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_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_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(
|
||||
pp::renderer::gl::OpenGlViewportRect {
|
||||
.x = x,
|
||||
.y = y,
|
||||
.width = width,
|
||||
.height = height,
|
||||
},
|
||||
pp::renderer::gl::OpenGlViewportDispatch {
|
||||
.viewport = set_opengl_viewport,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("NodeStrokePreview viewport 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(
|
||||
pp::renderer::gl::OpenGlScissorRect {
|
||||
.enabled = 1U,
|
||||
.x = x,
|
||||
.y = y,
|
||||
.width = width,
|
||||
.height = height,
|
||||
},
|
||||
pp::renderer::gl::OpenGlScissorDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
.scissor = set_opengl_scissor,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("NodeStrokePreview scissor dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
void apply_stroke_preview_capability(std::uint32_t state, bool enabled)
|
||||
{
|
||||
const auto status = pp::renderer::gl::apply_opengl_capability(
|
||||
state,
|
||||
enabled,
|
||||
pp::renderer::gl::OpenGlCapabilityDispatch {
|
||||
.enable = enable_opengl_state,
|
||||
.disable = disable_opengl_state,
|
||||
});
|
||||
if (!status.ok())
|
||||
LOG("NodeStrokePreview capability dispatch failed because: %s", status.message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::atomic_int NodeStrokePreview::s_instances{ 0 };
|
||||
@@ -155,12 +223,12 @@ void NodeStrokePreview::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2
|
||||
|
||||
m_rtt_mixer.bindFramebuffer();
|
||||
|
||||
glViewport(0, 0, m_rtt_mixer.getWidth(), m_rtt_mixer.getHeight());
|
||||
glDisable(pp::renderer::gl::depth_test_state());
|
||||
glEnable(pp::renderer::gl::scissor_test_state());
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
apply_stroke_preview_viewport(0, 0, m_rtt_mixer.getWidth(), m_rtt_mixer.getHeight());
|
||||
apply_stroke_preview_capability(pp::renderer::gl::depth_test_state(), false);
|
||||
apply_stroke_preview_capability(pp::renderer::gl::scissor_test_state(), true);
|
||||
apply_stroke_preview_capability(pp::renderer::gl::blend_state(), false);
|
||||
|
||||
glScissor(
|
||||
apply_stroke_preview_scissor(
|
||||
static_cast<int>(bb_min.x),
|
||||
static_cast<int>(bb_min.y),
|
||||
static_cast<int>(bb_sz.x),
|
||||
@@ -339,7 +407,7 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
|
||||
glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() };
|
||||
glm::mat4 ortho_proj = glm::ortho<float>(0, size.x, 0, size.y, -1, 1);
|
||||
glViewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight());
|
||||
apply_stroke_preview_viewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight());
|
||||
m_rtt.bindFramebuffer();
|
||||
m_rtt.clear();
|
||||
m_sampler_mipmap.bind(0);
|
||||
@@ -418,7 +486,7 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
if (b->m_pattern_flipx) patt_scale.x *= -1.f;
|
||||
if (b->m_pattern_flipy) patt_scale.y *= -1.f;
|
||||
|
||||
glDisable(pp::renderer::gl::blend_state());
|
||||
apply_stroke_preview_capability(pp::renderer::gl::blend_state(), false);
|
||||
ShaderManager::use(kShader::Stroke);
|
||||
ShaderManager::u_int(kShaderUniform::Tex, 0); // brush
|
||||
const auto stroke_feedback = stroke_preview_destination_feedback_plan(m_rtt.getWidth(), m_rtt.getHeight());
|
||||
@@ -600,7 +668,7 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
|
||||
m_rtt.unbindFramebuffer();
|
||||
|
||||
glViewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
apply_stroke_preview_viewport(vp[0], vp[1], vp[2], vp[3]);
|
||||
glClearColor(cc[0], cc[1], cc[2], cc[3]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user