Share retained stroke temporary composite helper

This commit is contained in:
2026-06-13 11:08:02 +02:00
parent fae108d520
commit cf3b8e856d
6 changed files with 121 additions and 52 deletions

View File

@@ -1438,64 +1438,73 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> faces /*= SI
}
else if (m_current_stroke && m_show_tmp && m_current_layer_idx == layer_index)
{
m_sampler.bind(0);
m_sampler.bind(1);
m_sampler.bind(2);
m_sampler.bind(3);
m_sampler_stencil.bind(4);
const auto stroke_material = canvas_stroke_material_plan(*b, false);
glm::vec2 patt_scale = glm::vec2(b->m_pattern_scale);
if (b->m_pattern_flipx) patt_scale.x *= -1.f;
if (b->m_pattern_flipy) patt_scale.y *= -1.f;
pp::panopainter::setup_legacy_stroke_composite_shader(
pp::panopainter::LegacyStrokeCompositeUniforms {
.resolution = Canvas::I->m_size,
.pattern = {
.scale = patt_scale,
.invert = static_cast<float>(b->m_pattern_invert),
.brightness = b->m_pattern_brightness,
.contrast = b->m_pattern_contrast,
.depth = b->m_pattern_depth,
.blend_mode = b->m_pattern_blend_mode,
.offset = Canvas::I->m_pattern_offset,
},
.mvp = ortho,
.layer_alpha = m_layers[layer_index]->m_opacity,
.alpha_lock = m_layers[layer_index]->m_alpha_locked,
.mask_enabled = m_smask_active,
.use_fragcoord = false,
.blend_mode = b->m_blend_mode,
.use_dual = stroke_material.composite_pass.use_dual,
.dual_blend_mode = stroke_material.composite_pass.dual_blend_mode,
.dual_alpha = stroke_material.composite_pass.dual_alpha,
.use_pattern = stroke_material.composite_pass.use_pattern,
pp::panopainter::execute_legacy_canvas_stroke_temporary_composite(
[&] {
pp::panopainter::setup_legacy_stroke_composite_shader(
pp::panopainter::LegacyStrokeCompositeUniforms {
.resolution = Canvas::I->m_size,
.pattern = {
.scale = patt_scale,
.invert = static_cast<float>(b->m_pattern_invert),
.brightness = b->m_pattern_brightness,
.contrast = b->m_pattern_contrast,
.depth = b->m_pattern_depth,
.blend_mode = b->m_pattern_blend_mode,
.offset = Canvas::I->m_pattern_offset,
},
.mvp = ortho,
.layer_alpha = m_layers[layer_index]->m_opacity,
.alpha_lock = m_layers[layer_index]->m_alpha_locked,
.mask_enabled = m_smask_active,
.use_fragcoord = false,
.blend_mode = b->m_blend_mode,
.use_dual = stroke_material.composite_pass.use_dual,
.dual_blend_mode = stroke_material.composite_pass.dual_blend_mode,
.dual_alpha = stroke_material.composite_pass.dual_alpha,
.use_pattern = stroke_material.composite_pass.use_pattern,
});
},
[&] {
m_sampler.bind(0);
m_sampler.bind(1);
m_sampler.bind(2);
m_sampler.bind(3);
m_sampler_stencil.bind(4);
},
[&] {
set_active_texture_unit(0);
m_layers[layer_index]->rtt(plane_index).bindTexture();
set_active_texture_unit(1);
m_tmp[plane_index].bindTexture();
set_active_texture_unit(2);
m_smask.rtt(plane_index).bindTexture();
set_active_texture_unit(3);
if (stroke_material.composite_pass.use_dual)
m_tmp_dual[plane_index].bindTexture();
set_active_texture_unit(4);
b->m_pattern_texture ?
b->m_pattern_texture->bind() :
unbind_texture_2d();
},
[&] {
m_plane.draw_fill();
},
[&] {
set_active_texture_unit(3);
if (stroke_material.composite_pass.use_dual)
m_tmp_dual[plane_index].unbindTexture();
set_active_texture_unit(2);
m_smask.rtt(plane_index).unbindTexture();
set_active_texture_unit(1);
m_tmp[plane_index].unbindTexture();
set_active_texture_unit(0);
m_layers[layer_index]->rtt(plane_index).unbindTexture();
});
set_active_texture_unit(0);
m_layers[layer_index]->rtt(plane_index).bindTexture();
set_active_texture_unit(1);
m_tmp[plane_index].bindTexture();
set_active_texture_unit(2);
m_smask.rtt(plane_index).bindTexture();
set_active_texture_unit(3);
if (stroke_material.composite_pass.use_dual)
m_tmp_dual[plane_index].bindTexture();
set_active_texture_unit(4);
b->m_pattern_texture ?
b->m_pattern_texture->bind() :
unbind_texture_2d();
m_plane.draw_fill();
set_active_texture_unit(3);
if (stroke_material.composite_pass.use_dual)
m_tmp_dual[plane_index].unbindTexture();
set_active_texture_unit(2);
m_smask.rtt(plane_index).unbindTexture();
set_active_texture_unit(1);
m_tmp[plane_index].unbindTexture();
set_active_texture_unit(0);
m_layers[layer_index]->rtt(plane_index).unbindTexture();
}
else
{

View File

@@ -656,6 +656,26 @@ std::size_t execute_legacy_canvas_stroke_live_pass_with_face_framebuffers(
pass_dirty_faces);
}
template <
typename SetupCompositeShader,
typename BindCompositeSamplers,
typename BindCompositeTextures,
typename DrawComposite,
typename UnbindCompositeTextures>
void execute_legacy_canvas_stroke_temporary_composite(
SetupCompositeShader&& setup_composite_shader,
BindCompositeSamplers&& bind_composite_samplers,
BindCompositeTextures&& bind_composite_textures,
DrawComposite&& draw_composite,
UnbindCompositeTextures&& unbind_composite_textures)
{
setup_composite_shader();
bind_composite_samplers();
bind_composite_textures();
draw_composite();
unbind_composite_textures();
}
[[nodiscard]] inline pp::paint_renderer::CanvasStrokeBox legacy_canvas_stroke_box(glm::vec4 box) noexcept
{
return pp::paint_renderer::CanvasStrokeBox {