Extract dialog, VR, and canvas draw helpers

This commit is contained in:
2026-06-16 11:40:00 +02:00
parent 18665bdffc
commit d2a841f348
9 changed files with 566 additions and 377 deletions

View File

@@ -475,14 +475,62 @@ void NodeCanvas::draw()
plane_index,
m_canvas->m_layers[layer_index]->m_opacity);
pp::panopainter::execute_legacy_canvas_draw_merge_layer_path(
m_canvas->m_current_stroke && m_canvas->m_current_mode == kCanvasMode::Erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index,
m_canvas->m_current_stroke && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index,
use_blend,
visit.first_frame,
visit.last_frame,
[&](int frame) {
return pp::app::animation_onion_frame_alpha(onion_range, frame);
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;
const auto layer_path_execution = pp::panopainter::make_legacy_canvas_draw_merge_layer_path_gl_execution(
{
.temporary_erase = {
.mvp = plane_mvp_z,
.texture_slot = 0,
.stroke_texture_slot = 1,
.mask_texture_slot = 2,
.mask_enabled = m_canvas->m_smask_active,
},
.temporary_paint = {
.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 = plane_mvp_z,
.layer_alpha = 1.0f,
.alpha_lock = m_canvas->m_layers[layer_index]->m_alpha_locked,
.mask_enabled = m_canvas->m_smask_active,
.use_fragcoord = false,
.blend_mode = b->m_blend_mode,
.use_dual = b->m_dual_enabled,
.dual_blend_mode = b->m_dual_blend_mode,
.dual_alpha = b->m_dual_opacity,
.use_pattern = b->m_pattern_enabled && !b->m_pattern_eachsample,
},
.layer_texture = {
.mvp = plane_mvp_z,
.texture_slot = 0,
.alpha = 1.f,
.highlight = m_canvas->m_layers[layer_index]->m_hightlight,
},
.blend = {
.shader = {
.mvp = glm::ortho(-1, 1, -1, 1),
.texture_slot = 0,
.destination_texture_slot = 2,
.use_destination_texture = copy_blend_destination,
.blend_mode = m_canvas->m_layers[layer_index]->m_blend_mode,
.alpha = 1.f,
},
.copy_destination = copy_blend_destination,
},
.use_nearest_sampler = m_canvas->m_cam_fov < 20.f,
.use_dual_texture = b->m_dual_enabled,
},
{
.bind_blender_framebuffer = [&] {
@@ -494,139 +542,65 @@ void NodeCanvas::draw()
.unbind_blender_framebuffer = [&] {
m_blender_rtt.unbindFramebuffer();
},
.prepare_temporary_erase = [&] {
m_sampler.bind(0);
m_sampler.bind(1);
m_sampler.bind(2);
//ShaderManager::u_vec2(kShaderUniform::Resolution, zw(m_canvas->m_box) / zoom);
//ShaderManager::u_int(kShaderUniform::Lock, m_canvas->m_layers[layer_index]->m_alpha_locked);
pp::panopainter::setup_legacy_stroke_erase_shader(
pp::panopainter::LegacyStrokeEraseUniforms {
.mvp = plane_mvp_z,
.texture_slot = 0,
.stroke_texture_slot = 1,
.mask_texture_slot = 2,
.mask_enabled = m_canvas->m_smask_active,
});
set_active_texture_unit(1);
m_canvas->m_tmp[plane_index].bindTexture();
set_active_texture_unit(2);
m_canvas->m_smask.rtt(plane_index).bindTexture();
.bind_sampler = [&](int unit) {
m_sampler.bind(unit);
},
.cleanup_temporary_erase = [&] {
set_active_texture_unit(2);
m_canvas->m_smask.rtt(plane_index).unbindTexture();
set_active_texture_unit(1);
.bind_nearest_sampler = [&](int unit) {
m_sampler_nearest.bind(unit);
},
.bind_stencil_sampler = [&](int unit) {
m_sampler_stencil.bind(unit);
},
.set_active_texture_unit = [&](int unit) {
set_active_texture_unit(unit);
},
.bind_temporary_texture = [&] {
m_canvas->m_tmp[plane_index].bindTexture();
},
.unbind_temporary_texture = [&] {
m_canvas->m_tmp[plane_index].unbindTexture();
},
.prepare_temporary_paint = [&] {
m_sampler.bind(0);
m_sampler.bind(1);
m_sampler.bind(2);
m_sampler.bind(3);
m_sampler_stencil.bind(4);
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 = plane_mvp_z,
.layer_alpha = 1.0f,
.alpha_lock = m_canvas->m_layers[layer_index]->m_alpha_locked,
.mask_enabled = m_canvas->m_smask_active,
.use_fragcoord = false,
.blend_mode = b->m_blend_mode,
.use_dual = b->m_dual_enabled,
.dual_blend_mode = b->m_dual_blend_mode,
.dual_alpha = b->m_dual_opacity,
.use_pattern = b->m_pattern_enabled && !b->m_pattern_eachsample,
});
set_active_texture_unit(1);
m_canvas->m_tmp[plane_index].bindTexture();
set_active_texture_unit(2);
.bind_smask_texture = [&] {
m_canvas->m_smask.rtt(plane_index).bindTexture();
set_active_texture_unit(3);
if (b->m_dual_enabled)
m_canvas->m_tmp_dual[plane_index].bindTexture();
set_active_texture_unit(4);
},
.unbind_smask_texture = [&] {
m_canvas->m_smask.rtt(plane_index).unbindTexture();
},
.bind_temporary_dual_texture = [&] {
m_canvas->m_tmp_dual[plane_index].bindTexture();
},
.unbind_temporary_dual_texture = [&] {
m_canvas->m_tmp_dual[plane_index].unbindTexture();
},
.bind_pattern_texture = [&] {
b->m_pattern_texture ?
b->m_pattern_texture->bind() :
unbind_texture_2d();
},
.cleanup_temporary_paint = [&] {
set_active_texture_unit(3);
if (b->m_dual_enabled)
m_canvas->m_tmp_dual[plane_index].unbindTexture();
set_active_texture_unit(2);
m_canvas->m_smask.rtt(plane_index).unbindTexture();
set_active_texture_unit(1);
m_canvas->m_tmp[plane_index].unbindTexture();
},
.prepare_layer_texture = [&] {
m_canvas->m_cam_fov < 20.f ? m_sampler_nearest.bind(0) : m_sampler.bind(0);
pp::panopainter::setup_legacy_canvas_draw_merge_texture_alpha_shader(
pp::panopainter::LegacyCanvasDrawMergeTextureAlphaUniforms {
.mvp = plane_mvp_z,
.texture_slot = 0,
.alpha = 1.f,
.highlight = m_canvas->m_layers[layer_index]->m_hightlight,
});
},
.cleanup_layer_texture = [&] {
},
.draw_blend = [&] {
m_sampler.bind(0);
m_sampler.bind(2);
pp::panopainter::setup_legacy_canvas_draw_merge_texture_blend_shader(
pp::panopainter::LegacyCanvasDrawMergeTextureBlendUniforms {
.mvp = glm::ortho(-1, 1, -1, 1),
.texture_slot = 0,
.destination_texture_slot = 2,
.use_destination_texture = copy_blend_destination,
.blend_mode = m_canvas->m_layers[layer_index]->m_blend_mode,
.alpha = 1.f,
});
set_active_texture_unit(0);
m_blender_rtt.bindTexture();
if (copy_blend_destination)
{
set_active_texture_unit(2);
m_blender_bg.bind();
copy_framebuffer_to_texture_2d(
0,
0,
0,
0,
m_blender_bg.size().x,
m_blender_bg.size().y);
}
.draw_face = [&] {
m_face_plane.draw_fill();
if (copy_blend_destination)
{
set_active_texture_unit(2);
m_blender_bg.unbind();
}
set_active_texture_unit(0);
},
.bind_blender_texture = [&] {
m_blender_rtt.bindTexture();
},
.unbind_blender_texture = [&] {
m_blender_rtt.unbindTexture();
},
.bind_destination_texture = [&] {
m_blender_bg.bind();
},
.unbind_destination_texture = [&] {
m_blender_bg.unbind();
},
.copy_destination_framebuffer = [&] {
copy_framebuffer_to_texture_2d(
0,
0,
0,
0,
m_blender_bg.size().x,
m_blender_bg.size().y);
},
.draw_debug_outline =
#ifdef _DEBUG
[&] {
@@ -648,6 +622,17 @@ void NodeCanvas::draw()
#endif
.draw_frame = draw_layer_frame,
});
pp::panopainter::execute_legacy_canvas_draw_merge_layer_path(
m_canvas->m_current_stroke && m_canvas->m_current_mode == kCanvasMode::Erase && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index,
m_canvas->m_current_stroke && m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index,
use_blend,
visit.first_frame,
visit.last_frame,
[&](int frame) {
return pp::app::animation_onion_frame_alpha(onion_range, frame);
},
layer_path_execution);
},
[&](const char* message) {
LOG("NodeCanvas onion frame range failed: %s", message);