Extract node canvas events and preview/node geometry shells
This commit is contained in:
@@ -2,118 +2,14 @@
|
||||
#include "log.h"
|
||||
#include "node_stroke_preview.h"
|
||||
#include "texture.h"
|
||||
#include "shader.h"
|
||||
#include "canvas.h"
|
||||
#include "app.h"
|
||||
#include "legacy_canvas_stroke_shader_services.h"
|
||||
#include "legacy_node_stroke_preview_execution_services.h"
|
||||
#include "legacy_node_stroke_preview_runtime_services.h"
|
||||
#include "legacy_node_stroke_preview_sample_services.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "renderer_gl/opengl_capabilities.h"
|
||||
#include "util.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace {
|
||||
|
||||
pp::renderer::RenderDeviceFeatures stroke_preview_render_device_features() noexcept
|
||||
{
|
||||
return ShaderManager::render_device_features();
|
||||
}
|
||||
|
||||
void set_active_texture_unit(std::uint32_t unit_index)
|
||||
{
|
||||
pp::legacy::ui_gl::activate_texture_unit(unit_index, "NodeStrokePreview");
|
||||
}
|
||||
|
||||
void unbind_texture_2d()
|
||||
{
|
||||
pp::legacy::ui_gl::unbind_texture_2d("NodeStrokePreview");
|
||||
}
|
||||
|
||||
void apply_stroke_preview_viewport(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
|
||||
{
|
||||
pp::legacy::ui_gl::apply_viewport(x, y, width, height, "NodeStrokePreview");
|
||||
}
|
||||
|
||||
pp::renderer::gl::OpenGlViewportRect query_stroke_preview_viewport()
|
||||
{
|
||||
return pp::legacy::ui_gl::query_viewport_rect("NodeStrokePreview");
|
||||
}
|
||||
|
||||
std::array<float, 4> query_stroke_preview_clear_color()
|
||||
{
|
||||
return pp::legacy::ui_gl::query_clear_color("NodeStrokePreview");
|
||||
}
|
||||
|
||||
void apply_stroke_preview_clear_color(std::array<float, 4> color)
|
||||
{
|
||||
pp::legacy::ui_gl::set_clear_color(color, "NodeStrokePreview");
|
||||
}
|
||||
|
||||
void apply_stroke_preview_scissor(std::int32_t x, std::int32_t y, std::int32_t width, std::int32_t height)
|
||||
{
|
||||
pp::legacy::ui_gl::apply_scissor_rect(x, y, width, height, "NodeStrokePreview");
|
||||
}
|
||||
|
||||
void apply_stroke_preview_capability(std::uint32_t state, bool enabled)
|
||||
{
|
||||
pp::legacy::ui_gl::set_capability(state, enabled, "NodeStrokePreview");
|
||||
}
|
||||
|
||||
namespace stroke_preview_live_slots {
|
||||
constexpr std::uint32_t kTip = 0U;
|
||||
constexpr std::uint32_t kDestination = 1U;
|
||||
constexpr std::uint32_t kPattern = 2U;
|
||||
constexpr std::uint32_t kMixer = 3U;
|
||||
constexpr std::uint32_t kReservedLinear = 4U;
|
||||
}
|
||||
|
||||
void bind_stroke_preview_live_samplers(
|
||||
Sampler& mipmap_sampler,
|
||||
Sampler& linear_sampler,
|
||||
Sampler& repeat_sampler)
|
||||
{
|
||||
mipmap_sampler.bind(stroke_preview_live_slots::kTip);
|
||||
linear_sampler.bind(stroke_preview_live_slots::kDestination);
|
||||
repeat_sampler.bind(stroke_preview_live_slots::kPattern);
|
||||
linear_sampler.bind(stroke_preview_live_slots::kMixer);
|
||||
linear_sampler.bind(stroke_preview_live_slots::kReservedLinear);
|
||||
}
|
||||
|
||||
void bind_stroke_preview_dual_pass_textures(const Brush& dual_brush)
|
||||
{
|
||||
set_active_texture_unit(stroke_preview_live_slots::kTip);
|
||||
dual_brush.m_tip_texture ?
|
||||
dual_brush.m_tip_texture->bind() :
|
||||
unbind_texture_2d();
|
||||
}
|
||||
|
||||
void bind_stroke_preview_destination_texture(Texture2D& texture)
|
||||
{
|
||||
set_active_texture_unit(stroke_preview_live_slots::kDestination);
|
||||
texture.bind();
|
||||
}
|
||||
|
||||
void unbind_stroke_preview_destination_texture(Texture2D& texture)
|
||||
{
|
||||
set_active_texture_unit(stroke_preview_live_slots::kDestination);
|
||||
texture.unbind();
|
||||
}
|
||||
|
||||
void copy_stroke_preview_destination_texture_region(
|
||||
int src_x,
|
||||
int src_y,
|
||||
int dst_x,
|
||||
int dst_y,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
copy_framebuffer_to_texture_2d(src_x, src_y, dst_x, dst_y, width, height);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Node* NodeStrokePreview::clone_instantiate() const
|
||||
{
|
||||
@@ -176,7 +72,7 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(
|
||||
.brush_shape = m_brush_shape,
|
||||
.copy_stroke_destination = copy_stroke_destination,
|
||||
.bind_destination_texture = [&] {
|
||||
bind_stroke_preview_destination_texture(blend_tex);
|
||||
pp::panopainter::bind_legacy_node_stroke_preview_destination_texture(blend_tex);
|
||||
},
|
||||
.copy_framebuffer_to_destination_texture = [](
|
||||
int src_x,
|
||||
@@ -185,7 +81,7 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(
|
||||
int dst_y,
|
||||
int width,
|
||||
int height) {
|
||||
copy_stroke_preview_destination_texture_region(
|
||||
pp::panopainter::copy_legacy_node_stroke_preview_destination_texture_region(
|
||||
src_x,
|
||||
src_y,
|
||||
dst_x,
|
||||
@@ -194,7 +90,7 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(
|
||||
height);
|
||||
},
|
||||
.unbind_destination_texture = [&] {
|
||||
unbind_stroke_preview_destination_texture(blend_tex);
|
||||
pp::panopainter::unbind_legacy_node_stroke_preview_destination_texture(blend_tex);
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -227,8 +123,8 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
return;
|
||||
}
|
||||
|
||||
const auto vp = query_stroke_preview_viewport();
|
||||
const auto cc = query_stroke_preview_clear_color();
|
||||
const auto vp = pp::panopainter::query_legacy_node_stroke_preview_viewport();
|
||||
const auto cc = pp::panopainter::query_legacy_node_stroke_preview_clear_color();
|
||||
const glm::vec2 size = { m_rtt.getWidth(), m_rtt.getHeight() };
|
||||
const float zoom = root()->m_zoom;
|
||||
const bool sequence_ok = pp::panopainter::execute_legacy_node_stroke_preview_immediate_runtime(
|
||||
@@ -241,7 +137,7 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
.pad_override = m_pad_override,
|
||||
.camera_fov = Canvas::I->m_cam_fov,
|
||||
.camera_rot = Canvas::I->m_cam_rot,
|
||||
.render_device_features = stroke_preview_render_device_features(),
|
||||
.render_device_features = pp::panopainter::stroke_preview_render_device_features(),
|
||||
.preview_rtt = m_rtt,
|
||||
.preview_rtt_mixer = m_rtt_mixer,
|
||||
.preview_stroke_texture = m_tex,
|
||||
@@ -251,10 +147,10 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
.linear_sampler = m_sampler_linear,
|
||||
.repeat_sampler = m_sampler_linear_repeat,
|
||||
.prepare_render_target = [&] {
|
||||
apply_stroke_preview_viewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight());
|
||||
pp::panopainter::apply_legacy_node_stroke_preview_viewport(0, 0, m_rtt.getWidth(), m_rtt.getHeight());
|
||||
m_rtt.bindFramebuffer();
|
||||
m_rtt.clear();
|
||||
bind_stroke_preview_live_samplers(
|
||||
pp::panopainter::bind_legacy_node_stroke_preview_live_samplers(
|
||||
m_sampler_mipmap,
|
||||
m_sampler_linear,
|
||||
m_sampler_linear_repeat);
|
||||
@@ -263,13 +159,13 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
m_rtt.unbindFramebuffer();
|
||||
},
|
||||
.set_blend_enabled = [&](bool enabled) {
|
||||
apply_stroke_preview_capability(pp::renderer::gl::blend_state(), enabled);
|
||||
pp::panopainter::apply_legacy_node_stroke_preview_capability(pp::renderer::gl::blend_state(), enabled);
|
||||
},
|
||||
.setup_stroke_shader = [](const pp::panopainter::LegacyStrokeShaderSetupUniforms& uniforms) {
|
||||
pp::panopainter::setup_legacy_stroke_shader(uniforms);
|
||||
},
|
||||
.bind_dual_pass_textures = [](const Brush& dual_brush) {
|
||||
bind_stroke_preview_dual_pass_textures(dual_brush);
|
||||
pp::panopainter::bind_legacy_node_stroke_preview_dual_pass_textures(dual_brush);
|
||||
},
|
||||
.capture_background = [&](bool colorize) {
|
||||
pp::panopainter::execute_legacy_node_stroke_preview_background_capture_pass(
|
||||
@@ -292,11 +188,10 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
stroke_draw_mix(bb_min, bb_sz);
|
||||
},
|
||||
.unbind_mixer_texture = [&] {
|
||||
set_active_texture_unit(3U);
|
||||
m_rtt_mixer.unbindTexture();
|
||||
pp::panopainter::unbind_legacy_node_stroke_preview_mixer_texture(m_rtt_mixer);
|
||||
},
|
||||
.bind_pattern_texture = [&] {
|
||||
m_brush->m_pattern_texture ? m_brush->m_pattern_texture->bind() : unbind_texture_2d();
|
||||
pp::panopainter::bind_legacy_node_stroke_preview_pattern_texture(*m_brush);
|
||||
},
|
||||
.draw_composite = [&] {
|
||||
m_plane.draw_fill();
|
||||
@@ -304,6 +199,6 @@ void NodeStrokePreview::draw_stroke_immediate()
|
||||
});
|
||||
assert(sequence_ok);
|
||||
|
||||
apply_stroke_preview_viewport(vp.x, vp.y, vp.width, vp.height);
|
||||
apply_stroke_preview_clear_color(cc);
|
||||
pp::panopainter::apply_legacy_node_stroke_preview_viewport(vp.x, vp.y, vp.width, vp.height);
|
||||
pp::panopainter::apply_legacy_node_stroke_preview_clear_color(cc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user