Extract stroke dual pass boundary

This commit is contained in:
2026-06-13 16:49:31 +02:00
parent 3986bd3c70
commit 43bdc85c11
3 changed files with 99 additions and 52 deletions

View File

@@ -509,6 +509,12 @@ Done Checks:
Progress Notes: Progress Notes:
- 2026-06-13: `Canvas::stroke_draw()` dual-brush replay now routes shader
setup, brush-tip texture binding, live-pass execution, and brush-tip
unbinding through `execute_legacy_canvas_stroke_dual_pass(...)`; the live
adapter still owns the concrete texture callbacks and face-frame replay.
Next slice should target another narrow `stroke_draw()` seam without
reopening landed pad or sample helpers.
- 2026-06-13: `Canvas::stroke_draw()` now routes the pad-stroke destination - 2026-06-13: `Canvas::stroke_draw()` now routes the pad-stroke destination
texture dispatch through a local helper lambda, so the repeated bind/unbind texture dispatch through a local helper lambda, so the repeated bind/unbind
callback construction is centralized while the pad executor still owns the callback construction is centralized while the pad executor still owns the

View File

@@ -906,67 +906,75 @@ void Canvas::stroke_draw()
if (stroke_material.dual_pass.enabled && m_dual_stroke) if (stroke_material.dual_pass.enabled && m_dual_stroke)
{ {
const auto& dual_brush = m_dual_stroke->m_brush; const auto& dual_brush = m_dual_stroke->m_brush;
pp::panopainter::setup_legacy_stroke_dual_shader(stroke_material.dual_pass.uses_pattern);
constexpr std::array dual_pass_texture_bindings { constexpr std::array dual_pass_texture_bindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding { pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip, .input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
.slot = 0, .slot = 0,
}, },
}; };
pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(
dual_pass_texture_bindings,
pp::panopainter::LegacyCanvasStrokeTextureInputDispatch {
.activate_texture_unit = [&](int texture_slot) {
set_active_texture_unit(texture_slot);
},
.bind_brush_tip = [&] {
dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->bind() :
unbind_texture_2d();
},
.unbind_brush_tip = [&] {
dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->unbind() :
unbind_texture_2d();
},
});
auto frames_dual = stroke_draw_compute(*m_dual_stroke); auto frames_dual = stroke_draw_compute(*m_dual_stroke);
const std::array<bool, 6> include_dual_dirty = const std::array<bool, 6> include_dual_dirty =
SIXPLETTE(stroke_material.composite_pass.dual_blend_mode == 0); SIXPLETTE(stroke_material.composite_pass.dual_blend_mode == 0);
pp::panopainter::execute_legacy_canvas_stroke_live_pass_with_face_framebuffers( [[maybe_unused]] const auto dual_result =
frames_dual, pp::panopainter::execute_legacy_canvas_stroke_dual_pass(
stroke_extent, pp::panopainter::LegacyCanvasStrokeDualPassRequest {
std::span<glm::vec4>(m_dirty_box), .context = "Canvas::stroke_draw",
std::span<glm::vec4>(), .planes = dual_pass_texture_bindings,
std::span<const bool>(include_dual_dirty), .setup_dual_shader = [&] {
[&](auto& f) { pp::panopainter::setup_legacy_stroke_dual_shader(
pp::panopainter::apply_legacy_stroke_sample_uniforms( stroke_material.dual_pass.uses_pattern);
pp::panopainter::LegacyStrokeSampleUniforms { },
.color = f.col, .bind_brush_tip = [&] {
.alpha = f.flow, pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(
.opacity = f.opacity, dual_pass_texture_bindings,
}); pp::panopainter::LegacyCanvasStrokeTextureInputDispatch {
}, .activate_texture_unit = [&](int texture_slot) {
[](auto&, int, auto&) {}, set_active_texture_unit(texture_slot);
[&](auto&, int i, auto& P) { },
return stroke_draw_samples(i, P, copy_stroke_destination); .bind_brush_tip = [&] {
}, dual_brush->m_tip_texture ?
m_tmp_dual, dual_brush->m_tip_texture->bind() :
true); unbind_texture_2d();
},
pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs( });
dual_pass_texture_bindings, },
pp::panopainter::LegacyCanvasStrokeTextureInputDispatch { .execute_frame_pass = [&] {
.activate_texture_unit = [&](int texture_slot) { pp::panopainter::execute_legacy_canvas_stroke_live_pass_with_face_framebuffers(
set_active_texture_unit(texture_slot); frames_dual,
}, stroke_extent,
.unbind_brush_tip = [&] { std::span<glm::vec4>(m_dirty_box),
dual_brush->m_tip_texture ? std::span<glm::vec4>(),
dual_brush->m_tip_texture->unbind() : std::span<const bool>(include_dual_dirty),
unbind_texture_2d(); [&](auto& f) {
}, pp::panopainter::apply_legacy_stroke_sample_uniforms(
}); pp::panopainter::LegacyStrokeSampleUniforms {
.color = f.col,
.alpha = f.flow,
.opacity = f.opacity,
});
},
[](auto&, int, auto&) {},
[&](auto&, int i, auto& P) {
return stroke_draw_samples(i, P, copy_stroke_destination);
},
m_tmp_dual,
true);
},
.unbind_brush_tip = [&] {
pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs(
dual_pass_texture_bindings,
pp::panopainter::LegacyCanvasStrokeTextureInputDispatch {
.activate_texture_unit = [&](int texture_slot) {
set_active_texture_unit(texture_slot);
},
.unbind_brush_tip = [&] {
dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->unbind() :
unbind_texture_2d();
},
});
},
});
} }
pp::panopainter::unbind_legacy_canvas_stroke_sampler_inputs( pp::panopainter::unbind_legacy_canvas_stroke_sampler_inputs(

View File

@@ -179,9 +179,42 @@ struct LegacyCanvasStrokeMixPassResult {
std::size_t composed_planes = 0; std::size_t composed_planes = 0;
}; };
struct LegacyCanvasStrokeDualPassRequest {
std::string_view context;
std::span<const LegacyCanvasStrokeMixPassPlane> planes;
std::function<void()> bind_brush_tip;
std::function<void()> unbind_brush_tip;
std::function<void()> setup_dual_shader;
std::function<void()> execute_frame_pass;
};
struct LegacyCanvasStrokeDualPassResult {
bool ok = false;
std::size_t composed_planes = 0;
};
[[nodiscard]] inline LegacyCanvasStrokeMixPassResult execute_legacy_canvas_stroke_mix_pass( [[nodiscard]] inline LegacyCanvasStrokeMixPassResult execute_legacy_canvas_stroke_mix_pass(
const LegacyCanvasStrokeMixPassRequest& request); const LegacyCanvasStrokeMixPassRequest& request);
[[nodiscard]] inline LegacyCanvasStrokeDualPassResult execute_legacy_canvas_stroke_dual_pass(
const LegacyCanvasStrokeDualPassRequest& request)
{
LegacyCanvasStrokeDualPassResult result;
if (!request.setup_dual_shader ||
!request.bind_brush_tip ||
!request.unbind_brush_tip ||
!request.execute_frame_pass) {
return result;
}
request.setup_dual_shader();
request.bind_brush_tip();
request.execute_frame_pass();
request.unbind_brush_tip();
result.ok = true;
return result;
}
template <std::size_t PlaneCount, typename HasTarget> template <std::size_t PlaneCount, typename HasTarget>
[[nodiscard]] inline std::array<LegacyCanvasStrokeMixPassPlane, PlaneCount> [[nodiscard]] inline std::array<LegacyCanvasStrokeMixPassPlane, PlaneCount>
plan_legacy_canvas_stroke_mix_pass_planes( plan_legacy_canvas_stroke_mix_pass_planes(