Isolate legacy stroke sample execution

This commit is contained in:
2026-06-12 22:25:02 +02:00
parent d69869f720
commit 33f21e0a1b
5 changed files with 190 additions and 96 deletions

View File

@@ -6,6 +6,7 @@
#include "bezier.h"
#include "canvas.h"
#include "app.h"
#include "legacy_canvas_stroke_execution_services.h"
#include "legacy_canvas_stroke_services.h"
#include "legacy_ui_gl_dispatch.h"
#include "paint_renderer/compositor.h"
@@ -249,52 +250,42 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(
Texture2D& blend_tex,
bool copy_stroke_destination)
{
if (copy_stroke_destination)
{
set_active_texture_unit(1U);
blend_tex.bind(); // bg, copy of framebuffer (copied before drawing)
}
const glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() };
const auto result = pp::panopainter::execute_legacy_canvas_stroke_sample(
pp::panopainter::LegacyStrokeSampleExecutionRequest {
.context = "NodeStrokePreview::stroke_draw_samples",
.target_size = size,
.vertices = P,
.copy_stroke_destination = copy_stroke_destination,
.bind_destination_texture = [&] {
set_active_texture_unit(1U);
blend_tex.bind(); // bg, copy of framebuffer (copied before drawing)
},
.copy_framebuffer_to_destination_texture = [](
int src_x,
int src_y,
int dst_x,
int dst_y,
int width,
int height) {
// this is also used by the mixer
copy_framebuffer_to_texture_2d(src_x, src_y, dst_x, dst_y, width, height);
},
.unbind_destination_texture = [&] {
set_active_texture_unit(1U);
blend_tex.unbind();
},
.upload_brush_vertices = [&](std::span<const vertex_t> vertices) {
m_brush_shape.update_vertices(
const_cast<vertex_t*>(vertices.data()),
static_cast<int>(vertices.size()));
},
.draw_brush_shape = [&] {
m_brush_shape.draw_fill();
},
});
glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() };
glm::vec2 bb_min(size);
glm::vec2 bb_max(0, 0);
for (int j = 0; j < P.size(); j++)
{
bb_min = glm::max({ 0, 0 }, glm::min(bb_min, xy(P[j].pos)));
bb_max = glm::min(size, glm::max(bb_max, xy(P[j].pos)));
}
auto bb_sz = bb_max - bb_min;
glm::vec2 pad(1);
glm::ivec2 tex_pos = glm::clamp(glm::floor(bb_min) - pad, { 0, 0 }, size);
glm::ivec2 tex_sz = glm::clamp(glm::ceil(bb_sz) + pad * 2.f, { 0, 0 }, (glm::vec2)(glm::ivec2(size) - tex_pos));
if (copy_stroke_destination)
{
// this is also used by the mixer
copy_framebuffer_to_texture_2d(tex_pos.x, tex_pos.y, tex_pos.x, tex_pos.y, tex_sz.x, tex_sz.y);
}
if (P.size() == 4)
{
static vertex_t rect[6];
rect[0] = P[0];
rect[1] = P[1];
rect[2] = P[2];
rect[3] = P[0];
rect[4] = P[2];
rect[5] = P[3];
m_brush_shape.update_vertices(rect, 6);
}
m_brush_shape.draw_fill();
if (copy_stroke_destination)
{
set_active_texture_unit(1U);
blend_tex.unbind();
}
return glm::vec4(tex_pos, tex_pos + tex_sz);
return result.dirty_bounds;
}
std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compute(Stroke& stroke, float zoom) const