From 67c594129ded8047c676f747c4e4da1b2afc77ca Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 13 Jun 2026 11:33:56 +0200 Subject: [PATCH] Extract Canvas draw_merge final plane composite helper --- docs/modernization/debt.md | 6 +++ docs/modernization/roadmap.md | 5 +++ docs/modernization/tasks.md | 7 +++ src/canvas.cpp | 60 ++++++++++++++----------- src/legacy_canvas_draw_merge_services.h | 37 +++++++++++++++ 5 files changed, 89 insertions(+), 26 deletions(-) diff --git a/docs/modernization/debt.md b/docs/modernization/debt.md index 443f506..334546f 100644 --- a/docs/modernization/debt.md +++ b/docs/modernization/debt.md @@ -301,6 +301,12 @@ agent or engineer to remove them without reconstructing context from chat. through `legacy_canvas_draw_merge_services.h`. The retained Canvas path still owns draw-merge layer iteration, blend-gate branching, framebuffer copies, sampler/texture binding, and draw ordering. +- 2026-06-13: DEBT-0036 was narrowed again. `Canvas::draw_merge` end-of-plane + merged-texture copy, optional checkerboard redraw, and final merged-texture + composite ordering now route through + `execute_legacy_canvas_draw_merge_final_plane_composite(...)`; the retained + Canvas path still owns per-plane iteration plus the concrete framebuffer, + sampler, texture, and draw callbacks. - 2026-06-13: DEBT-0036 was narrowed again. `Canvas::layer_merge` now reuses `legacy_canvas_stroke_composite_services.h` for retained layer-merge `kShader::CompDraw` binding and source/destination blend uniform writes. diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index 52acc29..693cefd 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -3150,6 +3150,11 @@ Results: ordering through `execute_legacy_canvas_draw_merge_layer_blend(...)`, while temporary-stroke branch selection, framebuffer copies, and final merged-plane ownership remain in the legacy Canvas path. +- `Canvas::draw_merge()` end-of-plane merged-texture copy plus optional + checkerboard/final-texture redraw ordering now routes through + `execute_legacy_canvas_draw_merge_final_plane_composite(...)`, while + per-plane iteration and the concrete framebuffer, sampler, texture, and draw + callbacks remain in the legacy Canvas path. - `NodeStrokePreview::draw_stroke_immediate()` now shares `execute_legacy_node_stroke_preview_pass_sequence(...)` for dual-pass/background/main-pass/final-composite/copy-back ordering, while the diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 2008393..085aa02 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -528,6 +528,13 @@ Progress Notes: merged-texture copy/grid/final-redraw seam or another similarly narrow final composite boundary without reopening landed temporary-composite or per-layer blend helpers. +- 2026-06-13: `Canvas::draw_merge()` end-of-plane merged-texture copy, + optional checkerboard redraw, and final merged-texture composite ordering now + route through `execute_legacy_canvas_draw_merge_final_plane_composite(...)`; + per-plane iteration and concrete framebuffer, sampler, texture, and draw + callbacks remain local to `Canvas`. Next slice should target another narrow + retained draw-merge boundary without reopening landed temporary-composite, + layer-blend, or final-plane helpers. - 2026-06-13: `Canvas::draw_merge()` erase live temporary-stroke composite now routes retained setup, sampler bind, texture bind, draw, and texture unbind ordering through `execute_legacy_canvas_stroke_temporary_composite(...)`; diff --git a/src/canvas.cpp b/src/canvas.cpp index f3355f9..b3d44be 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -1581,37 +1581,45 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI } } - set_active_texture_unit(2); - m_merge_tex.bind(); - copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height); - - // draw the grid behind the layers using a temporary copy if (use_blend) { - apply_canvas_capability(blend_state(), true); - - //draw the grid - if (draw_checkerboard) - { - pp::panopainter::setup_legacy_canvas_draw_merge_checkerboard_shader( - pp::panopainter::LegacyCanvasDrawMergeCheckerboardUniforms { + pp::panopainter::execute_legacy_canvas_draw_merge_final_plane_composite( + pp::panopainter::LegacyCanvasDrawMergeFinalPlaneCompositeUniforms { + .checkerboard = { .mvp = ortho, .colorize = false, - }); - m_plane.draw_fill(); - } - - // draw the layers - m_sampler.bind(0); - set_active_texture_unit(0); - m_merge_tex.bind(); - pp::panopainter::setup_legacy_canvas_draw_merge_texture_shader( - pp::panopainter::LegacyCanvasDrawMergeTextureUniforms { - .mvp = ortho, - .texture_slot = 0, + }, + .texture = { + .mvp = ortho, + .texture_slot = 0, + }, + .draw_checkerboard = draw_checkerboard, + }, + pp::panopainter::LegacyCanvasDrawMergeFinalPlaneCompositeExecution { + .bind_merged_texture_copy_target = [&] { + set_active_texture_unit(2); + m_merge_tex.bind(); + }, + .copy_merged_framebuffer = [&] { + copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height); + }, + .enable_blend = [&] { + apply_canvas_capability(blend_state(), true); + }, + .draw = [&] { + m_plane.draw_fill(); + }, + .bind_sampler = [&] { + m_sampler.bind(0); + }, + .bind_merged_texture = [&] { + set_active_texture_unit(0); + m_merge_tex.bind(); + }, + .unbind_merged_texture = [&] { + m_merge_tex.unbind(); + }, }); - m_plane.draw_fill(); - m_merge_tex.unbind(); } m_layers_merge.rtt(plane_index).unbindFramebuffer(); diff --git a/src/legacy_canvas_draw_merge_services.h b/src/legacy_canvas_draw_merge_services.h index 045378d..867aca4 100644 --- a/src/legacy_canvas_draw_merge_services.h +++ b/src/legacy_canvas_draw_merge_services.h @@ -80,6 +80,22 @@ struct LegacyCanvasDrawMergeLayerBlendExecution { std::function unbind_merge_texture; }; +struct LegacyCanvasDrawMergeFinalPlaneCompositeUniforms { + LegacyCanvasDrawMergeCheckerboardUniforms checkerboard; + LegacyCanvasDrawMergeTextureUniforms texture; + bool draw_checkerboard = false; +}; + +struct LegacyCanvasDrawMergeFinalPlaneCompositeExecution { + std::function bind_merged_texture_copy_target; + std::function copy_merged_framebuffer; + std::function enable_blend; + std::function draw; + std::function bind_sampler; + std::function bind_merged_texture; + std::function unbind_merged_texture; +}; + [[nodiscard]] inline LegacyCanvasDrawMergeShaderExecution legacy_shader_manager_draw_merge_execution() noexcept { return { @@ -257,4 +273,25 @@ inline void execute_legacy_canvas_draw_merge_layer_blend( execution.unbind_merge_texture(); } +inline void execute_legacy_canvas_draw_merge_final_plane_composite( + const LegacyCanvasDrawMergeFinalPlaneCompositeUniforms& uniforms, + const LegacyCanvasDrawMergeFinalPlaneCompositeExecution& execution) +{ + execution.bind_merged_texture_copy_target(); + execution.copy_merged_framebuffer(); + + execution.enable_blend(); + + if (uniforms.draw_checkerboard) { + setup_legacy_canvas_draw_merge_checkerboard_shader(uniforms.checkerboard); + execution.draw(); + } + + execution.bind_sampler(); + execution.bind_merged_texture(); + setup_legacy_canvas_draw_merge_texture_shader(uniforms.texture); + execution.draw(); + execution.unbind_merged_texture(); +} + } // namespace pp::panopainter