Reduce retained stroke preview helper surface

This commit is contained in:
2026-06-15 19:28:29 +02:00
parent 565564c061
commit e1e686d3f7
7 changed files with 245 additions and 474 deletions

View File

@@ -1741,18 +1741,79 @@ void Canvas::stroke_draw_dual_pass(
}
pp::panopainter::LegacyCanvasStrokeMainPassExecutionRequest Canvas::make_stroke_draw_main_pass_request(
const Brush& brush,
std::function<void()> bind_samplers,
std::function<void()> bind_textures,
std::function<void()> execute_frame_pass,
std::function<void()> unbind_textures,
std::function<void()> unbind_samplers)
{
constexpr std::array main_pass_texture_bindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
.slot = 0,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::stroke_destination,
.slot = 1,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::pattern,
.slot = 2,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::mixer,
.slot = 3,
},
};
constexpr std::array main_pass_texture_unbindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::mixer,
.slot = 3,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::stroke_destination,
.slot = 1,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
.slot = 0,
},
};
const auto main_pass_texture_dispatch = pp::panopainter::make_legacy_canvas_stroke_main_pass_texture_dispatch(
[&](int texture_slot) {
set_active_texture_unit(texture_slot);
},
[&] {
brush.m_tip_texture->bind();
},
[&] {
brush.m_tip_texture->unbind();
},
[&] {
brush.m_pattern_texture ?
brush.m_pattern_texture->bind() :
unbind_texture_2d();
},
[&] {
m_mixer.bindTexture();
},
[&] {
m_mixer.unbindTexture();
});
return pp::panopainter::make_legacy_canvas_stroke_main_pass_execution_request(
"Canvas::stroke_draw",
std::move(bind_samplers),
std::move(bind_textures),
[&] {
pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(
main_pass_texture_bindings,
main_pass_texture_dispatch);
},
std::move(execute_frame_pass),
std::move(unbind_textures),
[&] {
pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs(
main_pass_texture_unbindings,
main_pass_texture_dispatch);
},
std::move(unbind_samplers));
}
@@ -1872,20 +1933,6 @@ void Canvas::stroke_draw()
});
// DRAW MAIN BRUSH
constexpr std::array main_pass_texture_bindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
.slot = 0,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::pattern,
.slot = 2,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::mixer,
.slot = 3,
},
};
constexpr std::array live_pass_sampler_bindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
@@ -1904,16 +1951,6 @@ void Canvas::stroke_draw()
.slot = 3,
},
};
constexpr std::array main_pass_texture_unbindings {
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::mixer,
.slot = 3,
},
pp::panopainter::LegacyCanvasStrokeTextureBinding {
.input = pp::panopainter::LegacyCanvasStrokeTextureInput::brush_tip,
.slot = 0,
},
};
const pp::panopainter::LegacyCanvasStrokeSamplerDispatch live_pass_sampler_dispatch =
pp::panopainter::make_legacy_canvas_stroke_live_pass_sampler_dispatch(
[&](int slot) {
@@ -1937,30 +1974,9 @@ void Canvas::stroke_draw()
[&](int slot) {
m_sampler.bind(slot);
},
[&] {
m_sampler.unbind();
});
const auto main_pass_texture_dispatch = pp::panopainter::make_legacy_canvas_stroke_main_pass_texture_dispatch(
[&](int texture_slot) {
set_active_texture_unit(texture_slot);
},
[&] {
brush->m_tip_texture->bind();
},
[&] {
brush->m_tip_texture->unbind();
},
[&] {
brush->m_pattern_texture ?
brush->m_pattern_texture->bind() :
unbind_texture_2d();
},
[&] {
m_mixer.bindTexture();
},
[&] {
m_mixer.unbindTexture();
});
[&] {
m_sampler.unbind();
});
auto frames = stroke_draw_compute(*m_current_stroke);
std::array<glm::vec4, 6> box_face = SIXPLETTE(glm::vec4(m_size, 0, 0));
@@ -1970,16 +1986,12 @@ void Canvas::stroke_draw()
[[maybe_unused]] const auto main_pass_result =
pp::panopainter::execute_legacy_canvas_stroke_main_pass(
make_stroke_draw_main_pass_request(
*brush,
[&] {
pp::panopainter::bind_legacy_canvas_stroke_sampler_inputs(
live_pass_sampler_bindings,
live_pass_sampler_dispatch);
},
[&] {
pp::panopainter::bind_legacy_canvas_stroke_texture_inputs(
main_pass_texture_bindings,
main_pass_texture_dispatch);
},
[&] {
pp::panopainter::execute_legacy_canvas_stroke_main_pass_frame_callbacks(
frames,
@@ -2010,11 +2022,6 @@ void Canvas::stroke_draw()
},
m_tmp);
},
[&] {
pp::panopainter::unbind_legacy_canvas_stroke_texture_inputs(
main_pass_texture_unbindings,
main_pass_texture_dispatch);
},
[&] {
pp::panopainter::unbind_legacy_canvas_stroke_sampler_inputs(
live_pass_sampler_bindings,