Extract final canvas wrappers and preview mix pass

This commit is contained in:
2026-06-16 23:02:05 +02:00
parent 5f76716732
commit a8e4e02e94
14 changed files with 458 additions and 604 deletions

View File

@@ -7,7 +7,6 @@
#include "canvas.h"
#include "app.h"
#include "legacy_canvas_draw_merge_services.h"
#include "legacy_canvas_stroke_composite_services.h"
#include "legacy_canvas_stroke_execution_services.h"
#include "legacy_canvas_stroke_preview_services.h"
#include "legacy_canvas_stroke_shader_services.h"
@@ -69,13 +68,6 @@ void apply_stroke_preview_capability(std::uint32_t state, bool enabled)
pp::legacy::ui_gl::set_capability(state, enabled, "NodeStrokePreview");
}
namespace stroke_preview_composite_slots {
constexpr std::uint32_t kBackground = 0U;
constexpr std::uint32_t kStroke = 1U;
constexpr std::uint32_t kDual = 3U;
constexpr std::uint32_t kPattern = 4U;
}
namespace stroke_preview_live_slots {
constexpr std::uint32_t kTip = 0U;
constexpr std::uint32_t kDestination = 1U;
@@ -84,122 +76,6 @@ constexpr std::uint32_t kMixer = 3U;
constexpr std::uint32_t kReservedLinear = 4U;
}
pp::panopainter::LegacyNodeStrokePreviewMixPassRequest make_stroke_preview_mix_pass_request(
const Brush& brush,
glm::vec2 resolution) noexcept
{
return {
.resolution = resolution,
.pattern_scale = brush.m_pattern_scale,
.pattern_flipx = brush.m_pattern_flipx,
.pattern_flipy = brush.m_pattern_flipy,
.pattern_invert = brush.m_pattern_invert,
.pattern_brightness = brush.m_pattern_brightness,
.pattern_contrast = brush.m_pattern_contrast,
.pattern_depth = brush.m_pattern_depth,
.pattern_rand_offset = brush.m_pattern_rand_offset,
.pattern_enabled = brush.m_pattern_enabled,
.pattern_eachsample = brush.m_pattern_eachsample,
.tip_wet = brush.m_tip_wet,
.tip_mix = brush.m_tip_mix,
.tip_noise = brush.m_tip_noise,
.dual_enabled = brush.m_dual_enabled,
.dual_blend_mode = brush.m_dual_blend_mode,
.pattern_blend_mode = brush.m_pattern_blend_mode,
.dual_opacity = brush.m_dual_opacity,
.blend_mode = brush.m_blend_mode,
};
}
pp::panopainter::LegacyStrokeCompositeUniforms make_stroke_preview_mix_composite_uniforms(
const pp::panopainter::LegacyNodeStrokePreviewMixPassPlan::ShaderPlan& shader_plan) noexcept
{
return {
.resolution = shader_plan.resolution,
.pattern = {
.scale = shader_plan.pattern_scale,
.invert = shader_plan.pattern_invert,
.brightness = shader_plan.pattern_brightness,
.contrast = shader_plan.pattern_contrast,
.depth = shader_plan.pattern_depth,
.blend_mode = shader_plan.pattern_blend_mode,
.offset = shader_plan.pattern_offset,
},
.mvp = glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f),
.layer_alpha = 1.0f,
.alpha_lock = false,
.mask_enabled = false,
.use_fragcoord = false,
.blend_mode = shader_plan.blend_mode,
.use_dual = shader_plan.use_dual,
.dual_blend_mode = shader_plan.dual_blend_mode,
.dual_alpha = shader_plan.dual_alpha,
.use_pattern = shader_plan.use_pattern,
};
}
pp::panopainter::LegacyCanvasStrokeMixPassRequest make_stroke_preview_mix_pass_execution_request(
const pp::panopainter::LegacyNodeStrokePreviewMixPassPlan::ShaderPlan& shader,
RTT& mixer_rtt,
const Brush& brush,
Sampler& linear_sampler,
Texture2D& background_texture,
Texture2D& stroke_texture,
Texture2D& dual_texture,
std::span<const pp::panopainter::LegacyCanvasStrokeMixPassPlane> mix_planes,
std::function<void()> draw_mix)
{
return pp::panopainter::make_legacy_canvas_stroke_mix_pass_request(
"NodeStrokePreview::stroke_draw_mix",
glm::vec2(static_cast<float>(mixer_rtt.getWidth()), static_cast<float>(mixer_rtt.getHeight())),
mix_planes,
[&] {
linear_sampler.bind(stroke_preview_composite_slots::kBackground);
linear_sampler.bind(stroke_preview_composite_slots::kStroke);
linear_sampler.bind(stroke_preview_composite_slots::kDual);
linear_sampler.bind(stroke_preview_composite_slots::kPattern);
set_active_texture_unit(stroke_preview_composite_slots::kBackground);
background_texture.bind();
set_active_texture_unit(stroke_preview_composite_slots::kStroke);
stroke_texture.bind();
set_active_texture_unit(stroke_preview_composite_slots::kDual);
dual_texture.bind();
set_active_texture_unit(stroke_preview_composite_slots::kPattern);
brush.m_pattern_texture ? brush.m_pattern_texture->bind() : unbind_texture_2d();
},
[] {},
[&](int, const glm::mat4& plane_mvp) {
auto uniforms = make_stroke_preview_mix_composite_uniforms(shader);
uniforms.mvp = plane_mvp;
pp::panopainter::setup_legacy_stroke_composite_shader(uniforms);
},
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kBackground);
background_texture.bind();
},
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kStroke);
stroke_texture.bind();
},
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kDual);
dual_texture.bind();
},
std::move(draw_mix),
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kDual);
dual_texture.unbind();
},
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kStroke);
stroke_texture.unbind();
},
[&](int) {
set_active_texture_unit(stroke_preview_composite_slots::kBackground);
background_texture.unbind();
});
}
void bind_stroke_preview_live_samplers(
Sampler& mipmap_sampler,
Sampler& linear_sampler,
@@ -308,49 +184,22 @@ void NodeStrokePreview::init_controls()
void NodeStrokePreview::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
{
const auto& b = m_brush;
const auto mix_pass = pp::panopainter::plan_legacy_node_stroke_preview_mix_pass(
make_stroke_preview_mix_pass_request(*b, m_size));
const auto mix_planes = std::array {
pp::panopainter::LegacyCanvasStrokeMixPassPlane {
.index = 0,
.visible = true,
.has_target = true,
.opacity = 1.0f,
.mvp = glm::ortho(-.5f, .5f, -.5f, .5f, -1.f, 1.f),
},
};
gl_state gl;
const auto mix_result = pp::panopainter::execute_legacy_canvas_stroke_mix_pass_with_setup(
[&] {
apply_stroke_preview_viewport(0, 0, m_rtt_mixer.getWidth(), m_rtt_mixer.getHeight());
apply_stroke_preview_capability(pp::renderer::gl::depth_test_state(), false);
apply_stroke_preview_capability(pp::renderer::gl::scissor_test_state(), true);
apply_stroke_preview_capability(pp::renderer::gl::blend_state(), false);
apply_stroke_preview_scissor(
static_cast<std::int32_t>(bb_min.x),
static_cast<std::int32_t>(bb_min.y),
static_cast<std::int32_t>(bb_sz.x),
static_cast<std::int32_t>(bb_sz.y));
gl.save();
m_rtt_mixer.bindFramebuffer();
},
[&] {
m_rtt_mixer.unbindFramebuffer();
gl.restore();
},
make_stroke_preview_mix_pass_execution_request(
mix_pass.shader,
m_rtt_mixer,
*m_brush,
m_sampler_linear,
m_tex_background,
m_tex,
m_tex_dual,
mix_planes,
[this] {
const bool mix_ok = pp::panopainter::execute_legacy_node_stroke_preview_mix_pass(
pp::panopainter::LegacyNodeStrokePreviewMixPassExecutionRequest {
.brush = *b,
.preview_size = m_size,
.mixer_rtt = m_rtt_mixer,
.bb_min = bb_min,
.bb_sz = bb_sz,
.linear_sampler = m_sampler_linear,
.background_texture = m_tex_background,
.stroke_texture = m_tex,
.dual_texture = m_tex_dual,
.draw_mix = [this] {
m_plane.draw_fill();
}));
assert(mix_result.ok);
},
});
assert(mix_ok);
}
glm::vec4 NodeStrokePreview::stroke_draw_samples(