Share retained stroke preview live pass helper

This commit is contained in:
2026-06-13 10:24:06 +02:00
parent 084f58573f
commit 65b24d9516
4 changed files with 80 additions and 34 deletions

View File

@@ -187,6 +187,46 @@ void execute_stroke_preview_frames(
}
}
void copy_stroke_preview_framebuffer_to_texture(
Texture2D& texture,
glm::vec2 size,
std::uint32_t texture_unit)
{
set_active_texture_unit(texture_unit);
texture.bind();
copy_framebuffer_to_texture_2d(
0,
0,
0,
0,
static_cast<int>(size.x),
static_cast<int>(size.y));
}
template <typename ClearTarget, typename ComputeFrames, typename BeforeFrame, typename DrawSample>
void execute_stroke_preview_live_pass(
Texture2D& output_texture,
glm::vec2 size,
bool copy_stroke_destination,
ClearTarget&& clear_target,
ComputeFrames&& compute_frames,
BeforeFrame&& before_frame,
DrawSample&& draw_sample)
{
auto frames = compute_frames();
clear_target();
execute_stroke_preview_frames(
frames,
std::forward<BeforeFrame>(before_frame),
[&](auto& frame) {
draw_sample(frame, output_texture, copy_stroke_destination);
});
copy_stroke_preview_framebuffer_to_texture(
output_texture,
size,
stroke_preview_composite_slots::kStroke);
}
}
std::atomic_int NodeStrokePreview::s_instances{ 0 };
@@ -540,32 +580,27 @@ void NodeStrokePreview::draw_stroke_immediate()
if (material.dual_pass.enabled)
{
m_rtt.clear();
pp::panopainter::setup_legacy_stroke_dual_shader(material.dual_pass.uses_pattern);
set_active_texture_unit(0U);
dual_brush->m_tip_texture ?
dual_brush->m_tip_texture->bind() :
unbind_texture_2d();
auto frames_dual = stroke_draw_compute(m_dual_stroke, zoom);
execute_stroke_preview_frames(
frames_dual,
execute_stroke_preview_live_pass(
m_tex_dual,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
},
[&] {
return stroke_draw_compute(m_dual_stroke, zoom);
},
[](auto& frame) {
frame.col = { 0, 0, 0, 1 };
},
[&](auto& frame) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, m_tex_dual, copy_stroke_destination);
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
// copy raw stroke to tex
set_active_texture_unit(1U);
m_tex_dual.bind();
copy_framebuffer_to_texture_2d(
0,
0,
0,
0,
static_cast<int>(size.x),
static_cast<int>(size.y));
}
// CHEKCERBOARD
@@ -623,10 +658,16 @@ void NodeStrokePreview::draw_stroke_immediate()
unbind_texture_2d();
set_active_texture_unit(3U);
preview_composite_plan.uses_mixer ? m_rtt_mixer.bindTexture() : unbind_texture_2d();
auto frames = stroke_draw_compute(m_stroke, zoom);
m_rtt.clear();
execute_stroke_preview_frames(
frames,
execute_stroke_preview_live_pass(
m_tex,
size,
copy_stroke_destination,
[&] {
m_rtt.clear();
},
[&] {
return stroke_draw_compute(m_stroke, zoom);
},
[&](auto& frame) {
if (b->m_tip_mix > 0.f)
{
@@ -638,23 +679,12 @@ void NodeStrokePreview::draw_stroke_immediate()
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);
[&](auto& frame, Texture2D& blend_texture, bool copy_destination) {
/*auto rect =*/ stroke_draw_samples(frame.shapes, blend_texture, copy_destination);
});
set_active_texture_unit(3U);
m_rtt_mixer.unbindTexture();
// copy raw stroke to tex
set_active_texture_unit(1U);
m_tex.bind();
copy_framebuffer_to_texture_2d(
0,
0,
0,
0,
static_cast<int>(size.x),
static_cast<int>(size.y));
// COMPOSITE
execute_stroke_preview_final_composite_pass(