Share retained stroke frame execution helpers
This commit is contained in:
@@ -289,61 +289,40 @@ glm::vec4 NodeStrokePreview::stroke_draw_samples(
|
||||
|
||||
std::vector<NodeStrokePreview::StrokeFrame> NodeStrokePreview::stroke_draw_compute(Stroke& stroke, float zoom) const
|
||||
{
|
||||
std::vector<StrokeFrame> ret;
|
||||
StrokeSample prev = stroke.m_prev_sample;
|
||||
auto samples = stroke.compute_samples();
|
||||
std::array<vertex_t, 4> B = {
|
||||
vertex_t{ {0, 0, 1, 1}, {0, 0}, {0, 0} },
|
||||
vertex_t{ {0, 0, 1, 1}, {0, 1}, {0, 1} },
|
||||
vertex_t{ {0, 0, 1, 1}, {1, 1}, {1, 1} },
|
||||
vertex_t{ {0, 0, 1, 1}, {1, 0}, {1, 0} },
|
||||
};
|
||||
for (const auto& s : samples)
|
||||
{
|
||||
if (!s.valid())
|
||||
continue;
|
||||
|
||||
ret.emplace_back();
|
||||
auto& f = ret.back();
|
||||
|
||||
glm::vec2 dx_mix(prev.size * 0.5f, 0), dy_mix(0, prev.size * 0.5f);
|
||||
glm::vec2 off_mix[4] = {
|
||||
-dx_mix - dy_mix, // A - bottom-left
|
||||
-dx_mix + dy_mix, // B - top-left
|
||||
+dx_mix + dy_mix, // C - top-right
|
||||
+dx_mix - dy_mix, // D - bottom-right
|
||||
};
|
||||
// P is the initial square centered at the cursor location
|
||||
glm::vec2 dx(s.size * 0.5f, 0), dy(0, s.size * 0.5f);
|
||||
glm::vec2 off[4] = {
|
||||
-dx - dy, // A - bottom-left
|
||||
-dx + dy, // B - top-left
|
||||
+dx + dy, // C - top-right
|
||||
+dx - dy, // D - bottom-right
|
||||
};
|
||||
|
||||
glm::vec2 mixer_sz(m_rtt.getWidth(), m_rtt.getHeight());
|
||||
glm::vec2 mixer_bb_min(mixer_sz);
|
||||
glm::vec2 mixer_bb_max(0, 0);
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
auto p = (xy(prev.pos) + zoom * s.scale * off_mix[j] * glm::orientate2(-s.angle));
|
||||
mixer_bb_min = glm::max({ 0, 0 }, glm::min(mixer_bb_min, p));
|
||||
mixer_bb_max = glm::min(mixer_sz, glm::max(mixer_bb_max, p));
|
||||
|
||||
B[j].pos = glm::vec4(xy(s.pos) + zoom * s.scale * off[j] * glm::orientate2(-s.angle) - glm::vec2(0, 1), 1, 1);
|
||||
B[j].uvs2 = p / mixer_sz;
|
||||
}
|
||||
|
||||
f.m_mixer_rect = { glm::floor(mixer_bb_min), glm::ceil(mixer_bb_max - mixer_bb_min) };
|
||||
f.col = glm::vec4(s.col, 1);
|
||||
f.flow = s.flow;
|
||||
f.opacity = s.opacity;
|
||||
f.shapes = B;
|
||||
|
||||
prev = s;
|
||||
StrokeSample previous_sample = stroke.m_prev_sample;
|
||||
previous_sample.size *= zoom;
|
||||
for (auto& sample : samples) {
|
||||
sample.size *= zoom;
|
||||
}
|
||||
return ret;
|
||||
|
||||
return pp::panopainter::plan_legacy_canvas_stroke_frames(
|
||||
pp::panopainter::LegacyCanvasStrokeComputeRequest {
|
||||
.previous_sample = previous_sample,
|
||||
.samples = samples,
|
||||
.zoom = 1.0f,
|
||||
.mixer_size = glm::vec2(m_rtt.getWidth(), m_rtt.getHeight()),
|
||||
},
|
||||
[](
|
||||
std::array<vertex_t, 4>& brush_quad,
|
||||
bool /*project_3d*/,
|
||||
glm::mat4 /*model_view*/) {
|
||||
return brush_quad;
|
||||
},
|
||||
[](
|
||||
glm::vec4 mixer_rect,
|
||||
glm::vec4 color,
|
||||
float flow,
|
||||
float opacity,
|
||||
std::array<vertex_t, 4>&& shapes) {
|
||||
return StrokeFrame {
|
||||
.col = color,
|
||||
.flow = flow,
|
||||
.opacity = opacity,
|
||||
.shapes = std::move(shapes),
|
||||
.m_mixer_rect = mixer_rect,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
void NodeStrokePreview::draw_stroke_immediate()
|
||||
|
||||
Reference in New Issue
Block a user