From 5dc0bc7342b5737f6f5bcf4853ab249ec5e646ae Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 13 Jun 2026 09:28:51 +0200 Subject: [PATCH] Route stroke face sample ordering through helper --- docs/modernization/debt.md | 4 +++ docs/modernization/roadmap.md | 4 +++ docs/modernization/tasks.md | 7 ++++ src/canvas.cpp | 32 +++++++++---------- src/legacy_canvas_stroke_execution_services.h | 26 +++++++++++++++ 5 files changed, 57 insertions(+), 16 deletions(-) diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index b4d7d51..9c9111a 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -18,6 +18,10 @@ agent or engineer to remove them without reconstructing context from chat. ## Recent Reductions +- 2026-06-13: DEBT-0036 was narrowed again. `Canvas::stroke_draw` current and + dual stroke per-face framebuffer/sample callback ordering now routes through + the retained stroke execution helper; framebuffer ownership, shader uniform + timing, sampler/texture binding, and live draw execution remain retained. - 2026-06-13: DEBT-0036 was narrowed again. `Canvas::stroke_draw` current and dual stroke dirty-box mutation now routes through the retained stroke execution helper; framebuffer binding, shader uniform timing, sampler/texture diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 4d6a376..2205e12 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -3104,6 +3104,10 @@ Results: the retained stroke execution helper, while framebuffer binding, shader uniform timing, sampler/texture binding, and live draw execution remain retained. +- `Canvas::stroke_draw` current and dual stroke per-face framebuffer/sample + callback ordering now shares the retained stroke execution helper, while + framebuffer ownership, shader uniform timing, sampler/texture binding, and + live draw execution remain retained. - Remaining simple color, hue, color-quad, grid heightmap, and pen/line preview shader setup in UI nodes and canvas modes now shares retained helper surfaces, while geometry, texture/sampler binding, blend/depth state, diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 8883e4f..15abc21 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -509,6 +509,13 @@ Done Checks: Progress Notes: +- 2026-06-13: `Canvas::stroke_draw` current and dual stroke per-face + framebuffer/sample callback ordering now routes through + `legacy_canvas_stroke_execution_services.h`; framebuffer ownership, shader + uniform timing, sampler/texture binding, and draw execution remain local to + Canvas. Next slice should target the remaining per-face retained state around + sample execution without reopening the new pad-pass, dirty-mutation, or + commit executors. - 2026-06-13: `Canvas::stroke_draw` current and dual stroke dirty-box mutation now routes through `legacy_canvas_stroke_execution_services.h`; framebuffer binding, shader uniform timing, sampler/texture binding, and draw execution diff --git a/src/canvas.cpp b/src/canvas.cpp index 945147e..8fcf762 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -690,7 +690,7 @@ void Canvas::stroke_draw() std::array box_face = SIXPLETTE(glm::vec4(m_size, 0, 0)); std::array box_dirty = SIXPLETTE(false); glm::vec4 pad_color; - pp::panopainter::execute_legacy_canvas_stroke_frame_faces( + pp::panopainter::execute_legacy_canvas_stroke_frame_samples( frames, [&](auto& f) { if (brush->m_tip_mix > 0.f) @@ -698,13 +698,13 @@ void Canvas::stroke_draw() stroke_draw_mix(xy(f.m_mixer_rect), zw(f.m_mixer_rect)); } }, - [&](auto& f, int i, auto& P) { + [&](auto&, int i, auto&) { m_dirty_face[i] = true; merge_faces[i] = true; box_dirty[i] = true; - m_tmp[i].bindFramebuffer(); - + }, + [&](auto& f, int i, auto& P) { pp::panopainter::use_legacy_stroke_shader(); pp::panopainter::apply_legacy_stroke_sample_uniforms( pp::panopainter::LegacyStrokeSampleUniforms { @@ -712,11 +712,11 @@ void Canvas::stroke_draw() .alpha = f.flow, .opacity = f.opacity, }); - auto box_sample = stroke_draw_samples(i, P, copy_stroke_destination); - + return stroke_draw_samples(i, P, copy_stroke_destination); + }, + [&](auto& f, int i, glm::vec4 box_sample) { m_tmp[i].unbindFramebuffer(); - - const auto dirty_update = pp::panopainter::apply_legacy_canvas_stroke_face_dirty_update( + [[maybe_unused]] const auto dirty_update = pp::panopainter::apply_legacy_canvas_stroke_face_dirty_update( pp::panopainter::LegacyCanvasStrokeFaceDirtyRequest { .extent = stroke_extent, .previous_accumulated_dirty_box = m_dirty_box[i], @@ -726,7 +726,6 @@ void Canvas::stroke_draw() }, m_dirty_box[i], &box_face[i]); - // TODO: maybe average color? pad_color = f.col; }); @@ -804,7 +803,7 @@ void Canvas::stroke_draw() dual_brush->m_tip_texture->bind() : unbind_texture_2d(); auto frames_dual = stroke_draw_compute(*m_dual_stroke); - pp::panopainter::execute_legacy_canvas_stroke_frame_faces( + pp::panopainter::execute_legacy_canvas_stroke_frame_samples( frames_dual, [&](auto& f) { pp::panopainter::apply_legacy_stroke_sample_uniforms( @@ -814,14 +813,15 @@ void Canvas::stroke_draw() .opacity = f.opacity, }); }, - [&](auto&, int i, auto& P) { + [&](auto&, int i, auto&) { m_tmp_dual[i].bindFramebuffer(); - auto box_sample = stroke_draw_samples(i, P, copy_stroke_destination); + }, + [&](auto&, int i, auto& P) { + return stroke_draw_samples(i, P, copy_stroke_destination); + }, + [&](auto&, int i, glm::vec4 box_sample) { m_tmp_dual[i].unbindFramebuffer(); - - // this mode overflows the main brush boundries - [[maybe_unused]] const auto dirty_update = - pp::panopainter::apply_legacy_canvas_stroke_face_dirty_update( + [[maybe_unused]] const auto dirty_update = pp::panopainter::apply_legacy_canvas_stroke_face_dirty_update( pp::panopainter::LegacyCanvasStrokeFaceDirtyRequest { .extent = stroke_extent, .previous_accumulated_dirty_box = m_dirty_box[i], diff --git a/src/legacy_canvas_stroke_execution_services.h b/src/legacy_canvas_stroke_execution_services.h index a39e472..901fa20 100644 --- a/src/legacy_canvas_stroke_execution_services.h +++ b/src/legacy_canvas_stroke_execution_services.h @@ -192,6 +192,32 @@ std::size_t execute_legacy_canvas_stroke_frame_faces( return executed_faces; } +template +std::size_t execute_legacy_canvas_stroke_frame_samples( + Frames&& frames, + BeginFrame&& begin_frame, + BeginFace&& begin_face, + ExecuteSample&& execute_sample, + FinishFace&& finish_face) +{ + std::size_t executed_faces = 0; + for (auto& frame : frames) { + begin_frame(frame); + for (int face_index = 0; face_index < 6; ++face_index) { + auto& vertices = frame.shapes[face_index]; + if (vertices.size() < 3) { + continue; + } + + begin_face(frame, face_index, vertices); + auto sample_dirty_box = execute_sample(frame, face_index, vertices); + finish_face(frame, face_index, sample_dirty_box); + ++executed_faces; + } + } + return executed_faces; +} + [[nodiscard]] inline pp::paint_renderer::CanvasStrokeBox legacy_canvas_stroke_box(glm::vec4 box) noexcept { return pp::paint_renderer::CanvasStrokeBox {