From 83a4677088257a952856328d1a7b686652517aad Mon Sep 17 00:00:00 2001 From: omigamedev Date: Sat, 13 Jun 2026 23:34:37 +0200 Subject: [PATCH] Extract remaining draw merge branch orchestration --- src/canvas.cpp | 293 ++++++++++++++++++++++++++----------------------- src/canvas.h | 9 ++ 2 files changed, 165 insertions(+), 137 deletions(-) diff --git a/src/canvas.cpp b/src/canvas.cpp index d26af98..a2ad04f 100644 --- a/src/canvas.cpp +++ b/src/canvas.cpp @@ -1009,6 +1009,153 @@ void Canvas::draw_merge_temporary_paint_branch( pp::panopainter::execute_legacy_canvas_draw_merge_temporary_composite(execution); } +void Canvas::draw_merge_branch_orchestration( + int plane_index, + int layer_index, + const std::shared_ptr& layer, + const Brush& brush, + const glm::mat4& ortho, + bool use_blend, + bool copy_blend_destination, + bool draw_checkerboard) +{ + if (!(m_show_tmp && m_current_layer_idx == layer_index) && + (!layer->m_visible || + layer->m_opacity == .0f || + !layer->face(plane_index))) + return; + + if (use_blend) + { + 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, + 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 = [&] { + 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::stroke_draw_dual_pass( const std::vector& frames_dual, const std::array& dual_pass_texture_bindings, @@ -1579,143 +1726,15 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array faces /*= SI for (int layer_index = 0; layer_index < m_layers.size(); layer_index++) { - if (!(m_show_tmp && m_current_layer_idx == layer_index) && - (!m_layers[layer_index]->m_visible || - m_layers[layer_index]->m_opacity == .0f || - !m_layers[layer_index]->face(plane_index))) - continue; - - if (use_blend) - { - 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( - [&] { - //ShaderManager::u_vec2(kShaderUniform::Resolution, zw(m_box) / zoom); - //ShaderManager::u_int(kShaderUniform::Lock, m_layers[layer_index]->m_alpha_locked); - pp::panopainter::setup_legacy_stroke_erase_shader( - pp::panopainter::LegacyStrokeEraseUniforms { - .mvp = ortho, - .texture_slot = 0, - .stroke_texture_slot = 1, - .mask_texture_slot = 2, - .alpha = m_layers[layer_index]->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, - m_layers[layer_index], - *b, - ortho, - copy_blend_destination, - draw_checkerboard); - }, - .execute_layer_texture = [&] { - execute_canvas_draw_merge_layer_texture( - pp::panopainter::LegacyCanvasDrawMergeTextureAlphaUniforms { - .mvp = ortho, - .texture_slot = 0, - .alpha = m_layers[layer_index]->m_opacity, - .highlight = m_layers[layer_index]->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 = m_layers[layer_index]->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(); - }, - }); - }, - }); + draw_merge_branch_orchestration( + plane_index, + layer_index, + m_layers[layer_index], + *b, + ortho, + use_blend, + copy_blend_destination, + draw_checkerboard); } if (use_blend) diff --git a/src/canvas.h b/src/canvas.h index fc5d417..e54a115 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -267,6 +267,15 @@ private: const glm::mat4& ortho, bool copy_blend_destination, bool draw_checkerboard); + void draw_merge_branch_orchestration( + int plane_index, + int layer_index, + const std::shared_ptr& layer, + const Brush& brush, + const glm::mat4& ortho, + bool use_blend, + bool copy_blend_destination, + bool draw_checkerboard); void stroke_draw_dual_pass( const std::vector& frames_dual, const std::array& dual_pass_texture_bindings,