Extract remaining draw merge branch orchestration
This commit is contained in:
293
src/canvas.cpp
293
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>& 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<StrokeFrame>& frames_dual,
|
||||
const std::array<pp::panopainter::LegacyCanvasStrokeTextureBinding, 1>& dual_pass_texture_bindings,
|
||||
@@ -1579,143 +1726,15 @@ void Canvas::draw_merge(bool draw_checkerboard, std::array<bool, 6> 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)
|
||||
|
||||
Reference in New Issue
Block a user