Extract draw merge branch body helper

This commit is contained in:
2026-06-14 00:20:25 +02:00
parent 1e4a6814be
commit 85f8af42d1

View File

@@ -514,6 +514,148 @@ static void execute_canvas_draw_merge_plane_final_composite(
bool draw_checkerboard, bool draw_checkerboard,
bool use_blend); bool use_blend);
static void execute_canvas_draw_merge_branch_body(
Canvas& canvas,
int plane_index,
int layer_index,
const std::shared_ptr<Layer>& layer,
const Brush& brush,
const glm::mat4& ortho,
bool use_blend,
bool copy_blend_destination,
bool draw_checkerboard)
{
if (use_blend)
{
canvas.m_merge_rtt.bindFramebuffer();
canvas.m_merge_rtt.clear();
}
execute_canvas_draw_merge_layer_composite(
canvas.m_current_stroke && canvas.m_current_mode == kCanvasMode::Erase && canvas.m_show_tmp && canvas.m_current_layer_idx == layer_index,
canvas.m_current_stroke && canvas.m_show_tmp && canvas.m_current_layer_idx == layer_index,
use_blend,
pp::panopainter::LegacyCanvasDrawMergeLayerCompositeExecution {
.execute_temporary_erase = [&] {
pp::panopainter::execute_legacy_canvas_draw_merge_temporary_composite(
pp::panopainter::make_legacy_canvas_draw_merge_temporary_erase_composite(
[&] {
pp::panopainter::setup_legacy_stroke_erase_shader(
pp::panopainter::LegacyStrokeEraseUniforms {
.mvp = ortho,
.texture_slot = 0,
.stroke_texture_slot = 1,
.mask_texture_slot = 2,
.alpha = layer->m_opacity,
.mask_enabled = canvas.m_smask_active,
});
},
[&] {
canvas.m_sampler.bind(0);
canvas.m_sampler.bind(1);
canvas.m_sampler.bind(2);
},
[&] {
set_active_texture_unit(0);
canvas.m_layers[layer_index]->rtt(plane_index).bindTexture();
set_active_texture_unit(1);
canvas.m_tmp[plane_index].bindTexture();
set_active_texture_unit(2);
canvas.m_smask.rtt(plane_index).bindTexture();
},
[&] {
canvas.m_plane.draw_fill();
},
[&] {
canvas.m_smask.rtt(plane_index).unbindTexture();
set_active_texture_unit(1);
canvas.m_tmp[plane_index].unbindTexture();
set_active_texture_unit(0);
canvas.m_layers[layer_index]->rtt(plane_index).unbindTexture();
}));
},
.execute_temporary_paint = [&] {
canvas.draw_merge_temporary_paint_branch(
layer_index,
plane_index,
layer,
brush,
ortho,
copy_blend_destination,
draw_checkerboard);
},
.execute_layer_texture = [&] {
execute_canvas_draw_merge_layer_texture(
pp::panopainter::LegacyCanvasDrawMergeTextureAlphaUniforms {
.mvp = ortho,
.texture_slot = 0,
.alpha = layer->m_opacity,
.highlight = layer->m_hightlight,
},
pp::panopainter::LegacyCanvasDrawMergeLayerTextureExecution {
.bind_sampler = [&] {
canvas.m_cam_fov < 20.f ? canvas.m_sampler_nearest.bind(0) : canvas.m_sampler.bind(0);
},
.bind_layer_texture = [&] {
set_active_texture_unit(0);
canvas.m_layers[layer_index]->rtt(plane_index).bindTexture();
},
.draw = [&] {
canvas.m_plane.draw_fill();
},
.unbind_layer_texture = [&] {
canvas.m_layers[layer_index]->rtt(plane_index).unbindTexture();
},
});
},
.execute_layer_blend = [&] {
execute_canvas_draw_merge_layer_blend(
pp::panopainter::LegacyCanvasDrawMergeLayerBlendUniforms {
.shader = {
.mvp = ortho,
.texture_slot = 0,
.destination_texture_slot = 2,
.use_destination_texture = copy_blend_destination,
.blend_mode = layer->m_blend_mode,
.alpha = 1.f,
},
.copy_destination = copy_blend_destination,
},
pp::panopainter::LegacyCanvasDrawMergeLayerBlendExecution {
.unbind_merge_framebuffer = [&] {
canvas.m_merge_rtt.unbindFramebuffer();
},
.bind_samplers = [&] {
canvas.m_sampler.bind(0);
canvas.m_sampler.bind(2);
},
.bind_merge_texture = [&] {
set_active_texture_unit(0);
canvas.m_merge_rtt.bindTexture();
},
.bind_destination_texture = [&] {
set_active_texture_unit(2);
canvas.m_merge_tex.bind();
},
.copy_destination_framebuffer = [&] {
copy_framebuffer_to_texture_2d(0, 0, 0, 0, canvas.m_width, canvas.m_height);
},
.draw = [&] {
canvas.m_plane.draw_fill();
},
.unbind_destination_texture = [&] {
set_active_texture_unit(2);
canvas.m_merge_tex.unbind();
},
.unbind_merge_texture = [&] {
set_active_texture_unit(0);
canvas.m_merge_rtt.unbindTexture();
},
});
},
});
}
static void execute_canvas_draw_merge_plane_iteration( static void execute_canvas_draw_merge_plane_iteration(
Canvas& canvas, Canvas& canvas,
const std::array<bool, 6>& faces, const std::array<bool, 6>& faces,
@@ -1170,136 +1312,16 @@ void Canvas::draw_merge_branch_orchestration(
layer->m_opacity == .0f || layer->m_opacity == .0f ||
!layer->face(plane_index))) !layer->face(plane_index)))
return; return;
execute_canvas_draw_merge_branch_body(
if (use_blend) *this,
{
m_merge_rtt.bindFramebuffer();
m_merge_rtt.clear();
}
execute_canvas_draw_merge_layer_composite(
m_current_stroke && m_current_mode == kCanvasMode::Erase && m_show_tmp && m_current_layer_idx == layer_index,
m_current_stroke && m_show_tmp && m_current_layer_idx == layer_index,
use_blend,
pp::panopainter::LegacyCanvasDrawMergeLayerCompositeExecution {
.execute_temporary_erase = [&] {
pp::panopainter::execute_legacy_canvas_draw_merge_temporary_composite(
pp::panopainter::make_legacy_canvas_draw_merge_temporary_erase_composite(
[&] {
pp::panopainter::setup_legacy_stroke_erase_shader(
pp::panopainter::LegacyStrokeEraseUniforms {
.mvp = ortho,
.texture_slot = 0,
.stroke_texture_slot = 1,
.mask_texture_slot = 2,
.alpha = layer->m_opacity,
.mask_enabled = m_smask_active,
});
},
[&] {
m_sampler.bind(0);
m_sampler.bind(1);
m_sampler.bind(2);
},
[&] {
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();
},
[&] {
m_plane.draw_fill();
},
[&] {
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();
}));
},
.execute_temporary_paint = [&] {
draw_merge_temporary_paint_branch(
layer_index,
plane_index, plane_index,
layer_index,
layer, layer,
brush, brush,
ortho, ortho,
use_blend,
copy_blend_destination, copy_blend_destination,
draw_checkerboard); draw_checkerboard);
},
.execute_layer_texture = [&] {
execute_canvas_draw_merge_layer_texture(
pp::panopainter::LegacyCanvasDrawMergeTextureAlphaUniforms {
.mvp = ortho,
.texture_slot = 0,
.alpha = layer->m_opacity,
.highlight = layer->m_hightlight,
},
pp::panopainter::LegacyCanvasDrawMergeLayerTextureExecution {
.bind_sampler = [&] {
m_cam_fov < 20.f ? m_sampler_nearest.bind(0) : m_sampler.bind(0);
},
.bind_layer_texture = [&] {
set_active_texture_unit(0);
m_layers[layer_index]->rtt(plane_index).bindTexture();
},
.draw = [&] {
m_plane.draw_fill();
},
.unbind_layer_texture = [&] {
m_layers[layer_index]->rtt(plane_index).unbindTexture();
},
});
},
.execute_layer_blend = [&] {
execute_canvas_draw_merge_layer_blend(
pp::panopainter::LegacyCanvasDrawMergeLayerBlendUniforms {
.shader = {
.mvp = ortho,
.texture_slot = 0,
.destination_texture_slot = 2,
.use_destination_texture = copy_blend_destination,
.blend_mode = layer->m_blend_mode,
.alpha = 1.f,
},
.copy_destination = copy_blend_destination,
},
pp::panopainter::LegacyCanvasDrawMergeLayerBlendExecution {
.unbind_merge_framebuffer = [&] {
m_merge_rtt.unbindFramebuffer();
},
.bind_samplers = [&] {
m_sampler.bind(0);
m_sampler.bind(2);
},
.bind_merge_texture = [&] {
set_active_texture_unit(0);
m_merge_rtt.bindTexture();
},
.bind_destination_texture = [&] {
set_active_texture_unit(2);
m_merge_tex.bind();
},
.copy_destination_framebuffer = [&] {
copy_framebuffer_to_texture_2d(0, 0, 0, 0, m_width, m_height);
},
.draw = [&] {
m_plane.draw_fill();
},
.unbind_destination_texture = [&] {
set_active_texture_unit(2);
m_merge_tex.unbind();
},
.unbind_merge_texture = [&] {
set_active_texture_unit(0);
m_merge_rtt.unbindTexture();
},
});
},
});
} }
void Canvas::draw_merge_final_plane_composite( void Canvas::draw_merge_final_plane_composite(