Isolate legacy stroke sample execution
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "canvas.h"
|
||||
#include "app.h"
|
||||
#include "legacy_gl_renderbuffer_dispatch.h"
|
||||
#include "legacy_canvas_stroke_execution_services.h"
|
||||
#include "legacy_canvas_stroke_services.h"
|
||||
#include "legacy_ui_gl_dispatch.h"
|
||||
#include "legacy_ui_overlay_services.h"
|
||||
@@ -522,58 +523,44 @@ glm::vec4 Canvas::stroke_draw_samples(
|
||||
std::vector<vertex_t>& P,
|
||||
bool copy_stroke_destination)
|
||||
{
|
||||
if (copy_stroke_destination)
|
||||
{
|
||||
set_active_texture_unit(1);
|
||||
m_tex[i].bind(); // bg, copy of framebuffer (copied before drawing)
|
||||
}
|
||||
|
||||
glm::vec2 bb_min(m_width, m_height);
|
||||
glm::vec2 bb_max(0, 0);
|
||||
for (int j = 0; j < P.size(); j++)
|
||||
{
|
||||
bb_min = glm::max({ 0, 0 }, glm::min(bb_min, xy(P[j].pos)));
|
||||
bb_max = glm::min({ m_width, m_height }, glm::max(bb_max, xy(P[j].pos)));
|
||||
}
|
||||
auto bb_sz = bb_max - bb_min;
|
||||
|
||||
glm::vec2 pad(1);
|
||||
glm::ivec2 tex_pos = glm::clamp(glm::floor(bb_min) - pad, { 0, 0 }, { m_width, m_height });
|
||||
glm::ivec2 tex_sz = glm::clamp(glm::ceil(bb_sz) + pad * 2.f, { 0, 0 }, (glm::vec2)(glm::ivec2(m_width, m_height) - tex_pos));
|
||||
if (copy_stroke_destination)
|
||||
{
|
||||
copy_framebuffer_to_texture_2d(tex_pos.x, tex_pos.y, tex_pos.x, tex_pos.y, tex_sz.x, tex_sz.y);
|
||||
}
|
||||
|
||||
if (P.size() == 4)
|
||||
{
|
||||
static vertex_t rect[6];
|
||||
rect[0] = P[0];
|
||||
rect[1] = P[1];
|
||||
rect[2] = P[2];
|
||||
rect[3] = P[0];
|
||||
rect[4] = P[2];
|
||||
rect[5] = P[3];
|
||||
m_brush_shape.update_vertices(rect, 6);
|
||||
}
|
||||
else if (P.size() == 3)
|
||||
{
|
||||
m_brush_shape.update_vertices(P.data(), (int)P.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (P.size() != 3 && P.size() != 4) {
|
||||
P = triangulate_simple(P);
|
||||
m_brush_shape.update_vertices(P.data(), (int)P.size());
|
||||
}
|
||||
m_brush_shape.draw_fill();
|
||||
|
||||
if (copy_stroke_destination)
|
||||
{
|
||||
set_active_texture_unit(1);
|
||||
m_tex[i].unbind();
|
||||
}
|
||||
|
||||
return glm::vec4(tex_pos, tex_pos + tex_sz);
|
||||
const auto result = pp::panopainter::execute_legacy_canvas_stroke_sample(
|
||||
pp::panopainter::LegacyStrokeSampleExecutionRequest {
|
||||
.context = "Canvas::stroke_draw_samples",
|
||||
.target_size = { m_width, m_height },
|
||||
.vertices = P,
|
||||
.copy_stroke_destination = copy_stroke_destination,
|
||||
.bind_destination_texture = [&] {
|
||||
set_active_texture_unit(1);
|
||||
m_tex[i].bind(); // bg, copy of framebuffer (copied before drawing)
|
||||
},
|
||||
.copy_framebuffer_to_destination_texture = [](
|
||||
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);
|
||||
},
|
||||
.unbind_destination_texture = [&] {
|
||||
set_active_texture_unit(1);
|
||||
m_tex[i].unbind();
|
||||
},
|
||||
.upload_brush_vertices = [&](std::span<const vertex_t> vertices) {
|
||||
m_brush_shape.update_vertices(
|
||||
const_cast<vertex_t*>(vertices.data()),
|
||||
static_cast<int>(vertices.size()));
|
||||
},
|
||||
.draw_brush_shape = [&] {
|
||||
m_brush_shape.draw_fill();
|
||||
},
|
||||
});
|
||||
|
||||
return result.dirty_bounds;
|
||||
}
|
||||
|
||||
std::vector<Canvas::StrokeFrame> Canvas::stroke_draw_compute(Stroke& stroke) const
|
||||
|
||||
Reference in New Issue
Block a user