diff --git a/src/canvas.cpp b/src/canvas.cpp index 91f7b50..a258a65 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -847,17 +847,16 @@ void Canvas::stroke_draw() }, }; const auto make_pad_destination_texture_dispatch = [&](int face_index) { - return pp::panopainter::LegacyCanvasStrokeTextureInputDispatch { - .activate_texture_unit = [&](int texture_slot) { + return pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( + [&](int texture_slot) { set_active_texture_unit(texture_slot); }, - .bind_stroke_destination = [&] { + [&] { m_tex[face_index].bind(); }, - .unbind_stroke_destination = [&] { + [&] { m_tex[face_index].unbind(); - }, - }; + }); }; [[maybe_unused]] const auto pad_result = pp::panopainter::execute_legacy_canvas_stroke_pad_faces( pp::panopainter::LegacyCanvasStrokePadExecutionRequest { diff --git a/src/legacy_canvas_stroke_execution_services.h b/src/legacy_canvas_stroke_execution_services.h index 3ce6218..6b897ea 100644 --- a/src/legacy_canvas_stroke_execution_services.h +++ b/src/legacy_canvas_stroke_execution_services.h @@ -116,6 +116,18 @@ struct LegacyCanvasStrokeTextureInputDispatch { }; } +[[nodiscard]] inline LegacyCanvasStrokeTextureInputDispatch make_legacy_canvas_stroke_pad_destination_texture_dispatch( + std::function activate_texture_unit, + std::function bind_stroke_destination, + std::function unbind_stroke_destination) +{ + return LegacyCanvasStrokeTextureInputDispatch { + .activate_texture_unit = std::move(activate_texture_unit), + .bind_stroke_destination = std::move(bind_stroke_destination), + .unbind_stroke_destination = std::move(unbind_stroke_destination), + }; +} + struct LegacyCanvasStrokeSamplerDispatch { std::function bind_brush_tip_sampler; std::function unbind_brush_tip_sampler; diff --git a/tests/paint_renderer/stroke_execution_tests.cpp b/tests/paint_renderer/stroke_execution_tests.cpp index dcc7b01..6d168d1 100644 --- a/tests/paint_renderer/stroke_execution_tests.cpp +++ b/tests/paint_renderer/stroke_execution_tests.cpp @@ -271,12 +271,10 @@ void retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_ [&] { events.emplace_back("bind:mixer"); }, [&] { events.emplace_back("unbind:mixer"); }); - pp::panopainter::bind_legacy_canvas_stroke_texture_input( - LegacyCanvasStrokeTextureInput::pattern, - dispatch); - pp::panopainter::unbind_legacy_canvas_stroke_texture_input( - LegacyCanvasStrokeTextureInput::mixer, - dispatch); + dispatch.activate_texture_unit(2); + dispatch.bind_pattern(); + dispatch.activate_texture_unit(3); + dispatch.unbind_mixer(); const std::vector expected_events { "activate:2", @@ -287,6 +285,30 @@ void retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_ PP_EXPECT(h, events == expected_events); } +void retained_stroke_brush_tip_texture_dispatch_helper_builds_expected_callback_wiring(pp::tests::Harness& h) +{ + const std::array bindings { + LegacyCanvasStrokeTextureBinding { .input = LegacyCanvasStrokeTextureInput::brush_tip, .slot = 0 }, + }; + + std::vector events; + const auto dispatch = pp::panopainter::make_legacy_canvas_stroke_brush_tip_texture_dispatch( + [&](int slot) { events.emplace_back("activate:" + std::to_string(slot)); }, + [&] { events.emplace_back("bind:brush_tip"); }, + [&] { events.emplace_back("unbind:brush_tip"); }); + + pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(bindings, dispatch); + pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs(bindings, dispatch); + + const std::vector expected_events { + "activate:0", + "bind:brush_tip", + "activate:0", + "unbind:brush_tip", + }; + PP_EXPECT(h, events == expected_events); +} + void retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring(pp::tests::Harness& h) { std::vector events; @@ -315,6 +337,30 @@ void retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_ PP_EXPECT(h, events == expected_events); } +void retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_callback_wiring(pp::tests::Harness& h) +{ + const std::array bindings { + LegacyCanvasStrokeTextureBinding { .input = LegacyCanvasStrokeTextureInput::stroke_destination, .slot = 1 }, + }; + + std::vector events; + const auto dispatch = pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch( + [&](int slot) { events.emplace_back("activate:" + std::to_string(slot)); }, + [&] { events.emplace_back("bind:destination"); }, + [&] { events.emplace_back("unbind:destination"); }); + + pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(bindings, dispatch); + pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs(bindings, dispatch); + + const std::vector expected_events { + "activate:1", + "bind:destination", + "activate:1", + "unbind:destination", + }; + PP_EXPECT(h, events == expected_events); +} + void retained_stroke_sample_executor_copies_destination_and_expands_quads(pp::tests::Harness& h) { const auto vertices = make_quad_vertices(); @@ -1398,6 +1444,12 @@ int main() harness.run( "retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_wiring", retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_wiring); + harness.run( + "retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_callback_wiring", + retained_stroke_pad_destination_texture_dispatch_helper_builds_expected_callback_wiring); + harness.run( + "retained_stroke_brush_tip_texture_dispatch_helper_builds_expected_callback_wiring", + retained_stroke_brush_tip_texture_dispatch_helper_builds_expected_callback_wiring); harness.run( "retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring", retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring);