Narrow retained stroke preview execution

This commit is contained in:
2026-06-13 10:01:19 +02:00
parent 3f98e4e0c5
commit 7b99dabb33
4 changed files with 104 additions and 27 deletions

View File

@@ -96,6 +96,25 @@ void apply_stroke_preview_capability(std::uint32_t state, bool enabled)
pp::legacy::ui_gl::set_capability(state, enabled, "NodeStrokePreview");
}
template <typename Frames, typename BeforeFrame, typename DrawSample>
void execute_stroke_preview_frames(
Frames& frames,
BeforeFrame&& before_frame,
DrawSample&& draw_sample)
{
for (auto& frame : frames) {
before_frame(frame);
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = frame.col,
.alpha = frame.flow,
.opacity = frame.opacity,
});
draw_sample(frame);
}
}
}
std::atomic_int NodeStrokePreview::s_instances{ 0 };
@@ -456,16 +475,14 @@ void NodeStrokePreview::draw_stroke_immediate()
dual_brush->m_tip_texture->bind() :
unbind_texture_2d();
auto frames_dual = stroke_draw_compute(m_dual_stroke, zoom);
for (auto& f : frames_dual)
{
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = { 0, 0, 0, 1 },
.alpha = f.flow,
.opacity = f.opacity,
});
/*auto rect =*/ stroke_draw_samples(f.shapes, m_tex_dual, copy_stroke_destination);
}
execute_stroke_preview_frames(
frames_dual,
[](auto& frame) {
frame.col = { 0, 0, 0, 1 };
},
[&](auto& frame) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, m_tex_dual, copy_stroke_destination);
});
// copy raw stroke to tex
set_active_texture_unit(1U);
@@ -536,24 +553,22 @@ void NodeStrokePreview::draw_stroke_immediate()
preview_composite_plan.uses_mixer ? m_rtt_mixer.bindTexture() : unbind_texture_2d();
auto frames = stroke_draw_compute(m_stroke, zoom);
m_rtt.clear();
for (auto& f : frames)
{
if (b->m_tip_mix > 0.f)
{
stroke_draw_mix(xy(f.m_mixer_rect), zw(f.m_mixer_rect));
}
execute_stroke_preview_frames(
frames,
[&](auto& frame) {
if (b->m_tip_mix > 0.f)
{
stroke_draw_mix(xy(frame.m_mixer_rect), zw(frame.m_mixer_rect));
}
pp::panopainter::use_legacy_stroke_shader();
pp::panopainter::apply_legacy_stroke_sample_uniforms(
pp::panopainter::LegacyStrokeSampleUniforms {
.color = b->m_blend_mode != 0 || b->m_tip_mix > 0.f ?
glm::vec4 { .7, .4, .1, 1 } /*f.col*/ :
glm::vec4 { 0, 0, 0, 1 } /*f.col*/,
.alpha = glm::max(f.flow, m_min_flow),
.opacity = f.opacity,
});
/*auto rect =*/ stroke_draw_samples(f.shapes, m_tex, copy_stroke_destination);
}
frame.col = b->m_blend_mode != 0 || b->m_tip_mix > 0.f ?
glm::vec4 { .7, .4, .1, 1 } :
glm::vec4 { 0, 0, 0, 1 };
frame.flow = glm::max(frame.flow, m_min_flow);
},
[&](auto& frame) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, m_tex, copy_stroke_destination);
});
set_active_texture_unit(3U);
m_rtt_mixer.unbindTexture();