Extract draw merge branch dispatch helpers

This commit is contained in:
2026-06-14 00:26:24 +02:00
parent 61a3ee5f34
commit 27d34f2fba

View File

@@ -537,42 +537,12 @@ static void execute_canvas_draw_merge_branch_body(
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_canvas_draw_merge_temporary_erase_dispatch(
canvas,
plane_index,
layer_index,
layer,
ortho);
},
.execute_temporary_paint = [&] {
canvas.draw_merge_temporary_paint_branch(
@@ -592,21 +562,10 @@ static void execute_canvas_draw_merge_branch_body(
.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();
},
});
make_canvas_draw_merge_layer_texture_dispatch(
canvas,
plane_index,
layer_index));
},
.execute_layer_blend = [&] {
execute_canvas_draw_merge_layer_blend(
@@ -621,41 +580,113 @@ static void execute_canvas_draw_merge_branch_body(
},
.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();
},
});
make_canvas_draw_merge_layer_blend_dispatch(
canvas));
},
});
}
static auto make_canvas_draw_merge_temporary_erase_dispatch(
Canvas& canvas,
int plane_index,
int layer_index,
const std::shared_ptr<Layer>& layer,
const glm::mat4& ortho)
{
return 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();
});
}
static auto make_canvas_draw_merge_layer_texture_dispatch(
Canvas& canvas,
int plane_index,
int layer_index)
{
return 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();
},
};
}
static auto make_canvas_draw_merge_layer_blend_dispatch(Canvas& canvas)
{
return 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(
Canvas& canvas,
const std::array<bool, 6>& faces,