Extract pad destination texture dispatch helper

This commit is contained in:
2026-06-13 17:38:48 +02:00
parent 384db00015
commit 5c03b13078
3 changed files with 75 additions and 12 deletions

View File

@@ -847,17 +847,16 @@ void Canvas::stroke_draw()
}, },
}; };
const auto make_pad_destination_texture_dispatch = [&](int face_index) { const auto make_pad_destination_texture_dispatch = [&](int face_index) {
return pp::panopainter::LegacyCanvasStrokeTextureInputDispatch { return pp::panopainter::make_legacy_canvas_stroke_pad_destination_texture_dispatch(
.activate_texture_unit = [&](int texture_slot) { [&](int texture_slot) {
set_active_texture_unit(texture_slot); set_active_texture_unit(texture_slot);
}, },
.bind_stroke_destination = [&] { [&] {
m_tex[face_index].bind(); m_tex[face_index].bind();
}, },
.unbind_stroke_destination = [&] { [&] {
m_tex[face_index].unbind(); m_tex[face_index].unbind();
}, });
};
}; };
[[maybe_unused]] const auto pad_result = pp::panopainter::execute_legacy_canvas_stroke_pad_faces( [[maybe_unused]] const auto pad_result = pp::panopainter::execute_legacy_canvas_stroke_pad_faces(
pp::panopainter::LegacyCanvasStrokePadExecutionRequest { pp::panopainter::LegacyCanvasStrokePadExecutionRequest {

View File

@@ -116,6 +116,18 @@ struct LegacyCanvasStrokeTextureInputDispatch {
}; };
} }
[[nodiscard]] inline LegacyCanvasStrokeTextureInputDispatch make_legacy_canvas_stroke_pad_destination_texture_dispatch(
std::function<void(int)> activate_texture_unit,
std::function<void()> bind_stroke_destination,
std::function<void()> 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 { struct LegacyCanvasStrokeSamplerDispatch {
std::function<void(int)> bind_brush_tip_sampler; std::function<void(int)> bind_brush_tip_sampler;
std::function<void()> unbind_brush_tip_sampler; std::function<void()> unbind_brush_tip_sampler;

View File

@@ -271,12 +271,10 @@ void retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_
[&] { events.emplace_back("bind:mixer"); }, [&] { events.emplace_back("bind:mixer"); },
[&] { events.emplace_back("unbind:mixer"); }); [&] { events.emplace_back("unbind:mixer"); });
pp::panopainter::bind_legacy_canvas_stroke_texture_input( dispatch.activate_texture_unit(2);
LegacyCanvasStrokeTextureInput::pattern, dispatch.bind_pattern();
dispatch); dispatch.activate_texture_unit(3);
pp::panopainter::unbind_legacy_canvas_stroke_texture_input( dispatch.unbind_mixer();
LegacyCanvasStrokeTextureInput::mixer,
dispatch);
const std::vector<std::string> expected_events { const std::vector<std::string> expected_events {
"activate:2", "activate:2",
@@ -287,6 +285,30 @@ void retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_
PP_EXPECT(h, events == expected_events); 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<LegacyCanvasStrokeTextureBinding, 1> bindings {
LegacyCanvasStrokeTextureBinding { .input = LegacyCanvasStrokeTextureInput::brush_tip, .slot = 0 },
};
std::vector<std::string> 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<std::string> 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) void retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring(pp::tests::Harness& h)
{ {
std::vector<std::string> events; std::vector<std::string> events;
@@ -315,6 +337,30 @@ void retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_
PP_EXPECT(h, events == expected_events); 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<LegacyCanvasStrokeTextureBinding, 1> bindings {
LegacyCanvasStrokeTextureBinding { .input = LegacyCanvasStrokeTextureInput::stroke_destination, .slot = 1 },
};
std::vector<std::string> 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<std::string> 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) void retained_stroke_sample_executor_copies_destination_and_expands_quads(pp::tests::Harness& h)
{ {
const auto vertices = make_quad_vertices(); const auto vertices = make_quad_vertices();
@@ -1398,6 +1444,12 @@ int main()
harness.run( harness.run(
"retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_wiring", "retained_stroke_main_pass_texture_dispatch_helper_builds_expected_callback_wiring",
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( harness.run(
"retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring", "retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring",
retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring); retained_stroke_live_pass_sampler_dispatch_helper_builds_expected_callback_wiring);