Share retained stroke sample and mix helpers
This commit is contained in:
@@ -535,25 +535,11 @@ glm::vec4 Canvas::stroke_draw_samples(
|
||||
std::vector<vertex_t>& P,
|
||||
bool copy_stroke_destination)
|
||||
{
|
||||
if (P.size() != 3 && P.size() != 4) {
|
||||
P = triangulate_simple(P);
|
||||
}
|
||||
|
||||
std::vector<pp::paint_renderer::CanvasStrokePoint> sample_points;
|
||||
sample_points.reserve(P.size());
|
||||
for (const auto& vertex : P) {
|
||||
sample_points.push_back(pp::paint_renderer::CanvasStrokePoint {
|
||||
.x = vertex.pos.x,
|
||||
.y = vertex.pos.y,
|
||||
});
|
||||
}
|
||||
|
||||
const auto result = pp::panopainter::execute_legacy_canvas_stroke_sample(
|
||||
pp::panopainter::LegacyStrokeSampleExecutionRequest {
|
||||
const auto result = pp::panopainter::execute_legacy_canvas_stroke_sample_polygon(
|
||||
pp::panopainter::LegacyStrokeSamplePolygonExecutionRequest {
|
||||
.context = "Canvas::stroke_draw_samples",
|
||||
.target_size = { m_width, m_height },
|
||||
.vertices = P,
|
||||
.sample_points = sample_points,
|
||||
.polygon_vertices = P,
|
||||
.copy_stroke_destination = copy_stroke_destination,
|
||||
.bind_destination_texture = [&] {
|
||||
set_active_texture_unit(1);
|
||||
|
||||
@@ -37,6 +37,18 @@ struct LegacyStrokeSampleExecutionResult {
|
||||
glm::vec4 dirty_bounds {};
|
||||
};
|
||||
|
||||
struct LegacyStrokeSamplePolygonExecutionRequest {
|
||||
std::string_view context;
|
||||
glm::vec2 target_size {};
|
||||
std::span<const vertex_t> polygon_vertices;
|
||||
bool copy_stroke_destination = false;
|
||||
std::function<void()> bind_destination_texture;
|
||||
std::function<void(int, int, int, int, int, int)> copy_framebuffer_to_destination_texture;
|
||||
std::function<void()> unbind_destination_texture;
|
||||
std::function<void(std::span<const vertex_t>)> upload_brush_vertices;
|
||||
std::function<void()> draw_brush_shape;
|
||||
};
|
||||
|
||||
enum class LegacyCanvasStrokeTextureInput {
|
||||
brush_tip,
|
||||
stroke_destination,
|
||||
@@ -236,6 +248,7 @@ std::size_t execute_legacy_canvas_stroke_frame_faces(
|
||||
}
|
||||
|
||||
template <typename BindTextureInput, std::size_t BindingCount>
|
||||
requires std::invocable<BindTextureInput&, LegacyCanvasStrokeTextureInput, int>
|
||||
inline void bind_legacy_canvas_stroke_texture_inputs(
|
||||
const std::array<LegacyCanvasStrokeTextureBinding, BindingCount>& bindings,
|
||||
BindTextureInput&& bind_texture_input)
|
||||
@@ -246,6 +259,7 @@ inline void bind_legacy_canvas_stroke_texture_inputs(
|
||||
}
|
||||
|
||||
template <typename UnbindTextureInput, std::size_t BindingCount>
|
||||
requires std::invocable<UnbindTextureInput&, LegacyCanvasStrokeTextureInput, int>
|
||||
inline void unbind_legacy_canvas_stroke_texture_inputs(
|
||||
const std::array<LegacyCanvasStrokeTextureBinding, BindingCount>& bindings,
|
||||
UnbindTextureInput&& unbind_texture_input)
|
||||
@@ -874,4 +888,39 @@ template <typename ExecuteSample, typename BeginFace, typename PrepareDirtyReque
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] inline LegacyStrokeSampleExecutionResult execute_legacy_canvas_stroke_sample_polygon(
|
||||
const LegacyStrokeSamplePolygonExecutionRequest& request)
|
||||
{
|
||||
std::vector<vertex_t> sample_vertices(
|
||||
request.polygon_vertices.begin(),
|
||||
request.polygon_vertices.end());
|
||||
if (sample_vertices.size() != 3 && sample_vertices.size() != 4) {
|
||||
sample_vertices = triangulate_simple(sample_vertices);
|
||||
}
|
||||
|
||||
std::vector<pp::paint_renderer::CanvasStrokePoint> sample_points;
|
||||
sample_points.reserve(sample_vertices.size());
|
||||
for (const auto& vertex : sample_vertices) {
|
||||
sample_points.push_back(pp::paint_renderer::CanvasStrokePoint {
|
||||
.x = vertex.pos.x,
|
||||
.y = vertex.pos.y,
|
||||
});
|
||||
}
|
||||
|
||||
return execute_legacy_canvas_stroke_sample(
|
||||
LegacyStrokeSampleExecutionRequest {
|
||||
.context = request.context,
|
||||
.target_size = request.target_size,
|
||||
.vertices = sample_vertices,
|
||||
.sample_points = sample_points,
|
||||
.copy_stroke_destination = request.copy_stroke_destination,
|
||||
.bind_destination_texture = request.bind_destination_texture,
|
||||
.copy_framebuffer_to_destination_texture =
|
||||
request.copy_framebuffer_to_destination_texture,
|
||||
.unbind_destination_texture = request.unbind_destination_texture,
|
||||
.upload_brush_vertices = request.upload_brush_vertices,
|
||||
.draw_brush_shape = request.draw_brush_shape,
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
|
||||
@@ -124,6 +124,52 @@ struct StrokePreviewCompositePassInputs {
|
||||
std::function<void()> draw_composite;
|
||||
};
|
||||
|
||||
struct StrokePreviewMixPassInputs {
|
||||
glm::vec2 scissor_min;
|
||||
glm::vec2 scissor_size;
|
||||
RTT& mixer_rtt;
|
||||
Texture2D& background_texture;
|
||||
RTT& stroke_rtt;
|
||||
Texture2D& dual_texture;
|
||||
const Brush& brush;
|
||||
Sampler& linear_sampler;
|
||||
std::function<void()> draw_mix;
|
||||
};
|
||||
|
||||
void execute_stroke_preview_mix_pass(const StrokePreviewMixPassInputs& inputs)
|
||||
{
|
||||
gl_state gl;
|
||||
gl.save();
|
||||
|
||||
inputs.mixer_rtt.bindFramebuffer();
|
||||
|
||||
apply_stroke_preview_viewport(0, 0, inputs.mixer_rtt.getWidth(), inputs.mixer_rtt.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<int>(inputs.scissor_min.x),
|
||||
static_cast<int>(inputs.scissor_min.y),
|
||||
static_cast<int>(inputs.scissor_size.x),
|
||||
static_cast<int>(inputs.scissor_size.y));
|
||||
|
||||
inputs.linear_sampler.bind(stroke_preview_composite_slots::kBackground);
|
||||
set_active_texture_unit(stroke_preview_composite_slots::kBackground);
|
||||
inputs.background_texture.bind();
|
||||
set_active_texture_unit(stroke_preview_composite_slots::kStroke);
|
||||
inputs.stroke_rtt.bindTexture();
|
||||
set_active_texture_unit(stroke_preview_composite_slots::kDual);
|
||||
inputs.dual_texture.bind();
|
||||
set_active_texture_unit(stroke_preview_composite_slots::kPattern);
|
||||
inputs.brush.m_pattern_texture ?
|
||||
inputs.brush.m_pattern_texture->bind() :
|
||||
unbind_texture_2d();
|
||||
inputs.draw_mix();
|
||||
|
||||
inputs.mixer_rtt.unbindFramebuffer();
|
||||
gl.restore();
|
||||
}
|
||||
|
||||
void execute_stroke_preview_final_composite_pass(const StrokePreviewCompositePassInputs& inputs)
|
||||
{
|
||||
pp::panopainter::execute_legacy_stroke_preview_final_composite(
|
||||
@@ -504,22 +550,6 @@ void NodeStrokePreview::clear_context()
|
||||
|
||||
void NodeStrokePreview::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2& bb_sz)
|
||||
{
|
||||
gl_state gl;
|
||||
gl.save();
|
||||
|
||||
m_rtt_mixer.bindFramebuffer();
|
||||
|
||||
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<int>(bb_min.x),
|
||||
static_cast<int>(bb_min.y),
|
||||
static_cast<int>(bb_sz.x),
|
||||
static_cast<int>(bb_sz.y));
|
||||
|
||||
const auto& b = m_brush;
|
||||
glm::vec2 patt_scale = glm::vec2(b->m_pattern_scale);
|
||||
if (b->m_pattern_flipx) patt_scale.x *= -1.f;
|
||||
@@ -550,21 +580,20 @@ void NodeStrokePreview::stroke_draw_mix(const glm::vec2& bb_min, const glm::vec2
|
||||
.use_pattern = material.composite_pass.use_pattern,
|
||||
});
|
||||
|
||||
m_sampler_linear.bind(0);
|
||||
set_active_texture_unit(0U);
|
||||
m_tex_background.bind();
|
||||
set_active_texture_unit(1U);
|
||||
m_rtt.bindTexture();
|
||||
set_active_texture_unit(3U);
|
||||
m_tex_dual.bind();
|
||||
set_active_texture_unit(4U);
|
||||
b->m_pattern_texture ?
|
||||
b->m_pattern_texture->bind() :
|
||||
unbind_texture_2d();
|
||||
m_plane.draw_fill();
|
||||
|
||||
m_rtt_mixer.unbindFramebuffer();
|
||||
gl.restore();
|
||||
execute_stroke_preview_mix_pass(
|
||||
StrokePreviewMixPassInputs {
|
||||
.scissor_min = bb_min,
|
||||
.scissor_size = bb_sz,
|
||||
.mixer_rtt = m_rtt_mixer,
|
||||
.background_texture = m_tex_background,
|
||||
.stroke_rtt = m_rtt,
|
||||
.dual_texture = m_tex_dual,
|
||||
.brush = *b,
|
||||
.linear_sampler = m_sampler_linear,
|
||||
.draw_mix = [&] {
|
||||
m_plane.draw_fill();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
glm::vec4 NodeStrokePreview::stroke_draw_samples(
|
||||
|
||||
Reference in New Issue
Block a user