Extract Canvas draw_merge final plane composite helper

This commit is contained in:
2026-06-13 11:33:56 +02:00
parent 3ec4f25889
commit 67c594129d
5 changed files with 89 additions and 26 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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(...)`;

View File

@@ -1581,37 +1581,45 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> 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();

View File

@@ -80,6 +80,22 @@ struct LegacyCanvasDrawMergeLayerBlendExecution {
std::function<void()> unbind_merge_texture;
};
struct LegacyCanvasDrawMergeFinalPlaneCompositeUniforms {
LegacyCanvasDrawMergeCheckerboardUniforms checkerboard;
LegacyCanvasDrawMergeTextureUniforms texture;
bool draw_checkerboard = false;
};
struct LegacyCanvasDrawMergeFinalPlaneCompositeExecution {
std::function<void()> bind_merged_texture_copy_target;
std::function<void()> copy_merged_framebuffer;
std::function<void()> enable_blend;
std::function<void()> draw;
std::function<void()> bind_sampler;
std::function<void()> bind_merged_texture;
std::function<void()> 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