GPv3: Add Compound Shapes Rendering (i.e. Hole rendering) #12

Closed
casey-bianco-davis wants to merge 8 commits from GPv3-Compound-Shapes-2 into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
6 changed files with 388 additions and 164 deletions
Showing only changes of commit 2f5dbf76f5 - Show all commits

View File

@ -86,6 +86,9 @@ class Drawing : public ::GreasePencilDrawing {
const bke::CurvesGeometry &strokes() const;
bke::CurvesGeometry &strokes_for_write();
Array<IndexMask> get_shapes_index_masks(IndexMaskMemory &memory) const;
/**
* The triangles for all the fills in the geometry.
*/

View File

@ -29,6 +29,7 @@
#include "BKE_object_types.hh"
#include "BLI_bounds.hh"
#include "BLI_delaunay_2d.hh"
#include "BLI_enumerable_thread_specific.hh"
#include "BLI_map.hh"
#include "BLI_math_euler_types.hh"
@ -366,61 +367,234 @@ Drawing::~Drawing()
this->runtime = nullptr;
}
Span<Vector<uint3>> Drawing::triangles() const
Array<IndexMask> Drawing::get_shapes_index_masks(IndexMaskMemory &memory) const
{
struct LocalMemArena {
MemArena *pf_arena = nullptr;
LocalMemArena() : pf_arena(BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "Drawing::triangles")) {}
const CurvesGeometry &curves = this->strokes();
const bke::AttributeAccessor attributes = curves.attributes();
~LocalMemArena()
{
if (pf_arena != nullptr) {
BLI_memarena_free(pf_arena);
const int num_curves = curves.curves_num();
const VArray<int> shape_ids = *attributes.lookup<int>("shape_id", bke::AttrDomain::Curve);
if (!shape_ids) {
/* If the attribute does not exist then the default is each shape containing one curve. */
Array<IndexMask> data(num_curves);
IndexMask::from_groups<int>(
IndexMask(num_curves), memory, [&](const int i) { return i; }, data);
return data;
}
const int max_shape_id = *std::max_element(shape_ids.get_internal_span().begin(),
shape_ids.get_internal_span().end());
Array<IndexMask> data(max_shape_id + 1);
IndexMask::from_groups<int>(
IndexRange(num_curves), memory, [&](const int i) { return shape_ids[i]; }, data);
return data;
}
static bool check_self_intersections(Span<float2> projverts)
{
std::atomic<bool> intersect = false;
threading::parallel_for(projverts.index_range(), 512, [&](const IndexRange range) {
for (const int e2_id : range) {
if (intersect) {
return;
}
for (const int e1_id : projverts.index_range().drop_front(e2_id)) {
const int p1 = e1_id;
const int p2 = (e1_id + 1) % projverts.size();
const int p3 = e2_id;
const int p4 = (e2_id + 1) % projverts.size();
if (p1 == p4) {
continue;
}
if (p2 == p3) {
continue;
}
if (isect_seg_seg_v2_simple(projverts[p1], projverts[p2], projverts[p3], projverts[p4])) {
intersect.store(true, std::memory_order_relaxed);
return;
}
}
};
});
return intersect;
}
static bool check_other_intersections(Span<float2> projverts1, Span<float2> projverts2)
{
std::atomic<bool> intersect = false;
threading::parallel_for(projverts1.index_range(), 512, [&](const IndexRange range) {
for (const int e1_id : range) {
for (const int e2_id : projverts2.index_range()) {
const int p11 = e1_id;
const int p12 = (e1_id + 1) % projverts1.size();
const int p21 = e2_id;
const int p22 = (e2_id + 1) % projverts2.size();
if (isect_seg_seg_v2_simple(
projverts1[p11], projverts1[p12], projverts2[p21], projverts2[p22]))
{
intersect.store(true, std::memory_order_relaxed);
return;
}
}
}
};
});
return intersect;
}
static bool check_valid_curves(Span<float2> projverts, const OffsetIndices<int> points_by_group)
{
std::atomic<bool> intersect = false;
/* Check for self intersections. */
threading::parallel_for(points_by_group.index_range(), 512, [&](const IndexRange range) {
for (const int pos : range) {
if (intersect) {
return;
}
const IndexRange point_group = points_by_group[pos];
if (check_self_intersections(projverts.slice(point_group))) {
intersect.store(true, std::memory_order_relaxed);
return;
}
}
});
if (intersect) {
return false;
}
/* Check if other intersect. */
threading::parallel_for(points_by_group.index_range(), 512, [&](const IndexRange range1) {
for (const int pos1 : range1) {
if (intersect) {
return;
}
const IndexRange point_group1 = points_by_group[pos1];
threading::parallel_for(points_by_group.index_range(), 512, [&](const IndexRange range2) {
for (const int pos2 : range2) {
if (intersect) {
return;
}
const IndexRange point_group2 = points_by_group[pos2];
if (pos2 >= pos1) {
return;
}
if (check_other_intersections(projverts.slice(point_group1),
projverts.slice(point_group2)))
{
intersect.store(true, std::memory_order_relaxed);
return;
}
}
});
}
});
if (intersect) {
return false;
}
return true;
}
Span<Vector<uint3>> Drawing::triangles() const
{
this->runtime->triangles_cache.ensure([&](Vector<Vector<uint3>> &r_data) {
const CurvesGeometry &curves = this->strokes();
const Span<float3> positions = curves.evaluated_positions();
const Span<float3> normals = this->curve_plane_normals();
const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
const Array<int> point_to_curve_map = curves.point_to_curve_map();
r_data.resize(curves.curves_num());
IndexMaskMemory memory;
const Array<IndexMask> groups = this->get_shapes_index_masks(memory);
r_data.resize(groups.size() + 1);
// r_data.resize(curves.curves_num());
MutableSpan<Vector<uint3>> strokes_triangles = r_data.as_mutable_span();
threading::EnumerableThreadSpecific<LocalMemArena> all_local_mem_arenas;
threading::parallel_for(curves.curves_range(), 32, [&](const IndexRange range) {
MemArena *pf_arena = all_local_mem_arenas.local().pf_arena;
for (const int curve_i : range) {
const IndexRange points = points_by_curve[curve_i];
if (points.size() < 3) {
threading::parallel_for(groups.index_range(), 32, [&](const IndexRange group_range) {
for (const int group_id : group_range) {
const IndexMask &group = groups[group_id];
float3x3 axis_mat;
axis_dominant_v3_to_m3(axis_mat.ptr(), normals[group.first()]);
Array<int> offsets_data(group.size() + 1);
offset_indices::gather_group_sizes(
points_by_curve, group, offsets_data.as_mutable_span().drop_back(1));
offset_indices::accumulate_counts_to_offsets(offsets_data);
const OffsetIndices<int> points_by_group = OffsetIndices<int>(offsets_data);
const int num_points = points_by_group.total_size();
Array<float2> projverts2(num_points);
group.foreach_index(GrainSize(256), [&](const int64_t curve_i, const int64_t pos) {
const IndexRange point_group = points_by_group[pos];
const IndexRange points = points_by_curve[curve_i];
threading::parallel_for(points.index_range(), 512, [&](const IndexRange range) {
for (const int p_id : range) {
mul_v2_m3v3(projverts2[point_group[p_id]], axis_mat.ptr(), positions[points[p_id]]);
}
});
});
if (!check_valid_curves(projverts2, points_by_group)) {
continue;
}
const int num_triangles = points.size() - 2;
strokes_triangles[curve_i].resize(num_triangles);
MutableSpan<uint3> r_tris = strokes_triangles[curve_i];
Array<double2> verts(num_points);
Array<std::pair<int, int>> edges(num_points);
Array<Vector<int>> faces(group.size());
float(*projverts)[2] = static_cast<float(*)[2]>(
BLI_memarena_alloc(pf_arena, sizeof(*projverts) * size_t(points.size())));
Array<int> vert_to_point_map(num_points);
float3x3 axis_mat;
axis_dominant_v3_to_m3(axis_mat.ptr(), normals[curve_i]);
group.foreach_index(GrainSize(256), [&](const int64_t curve_i, const int64_t pos) {
const IndexRange point_group = points_by_group[pos];
const IndexRange points = points_by_curve[curve_i];
faces[pos].resize(points.size());
threading::parallel_for(points.index_range(), 512, [&](const IndexRange range) {
for (const int p_id : range) {
vert_to_point_map[point_group[p_id]] = points[p_id];
verts[point_group[p_id]] = double2(projverts2[point_group[p_id]]);
edges[point_group[p_id]] = std::pair<int, int>(
point_group[p_id], point_group[(p_id + 1) % points.size()]);
faces[pos][p_id] = point_group[p_id];
}
});
});
for (const int i : points.index_range()) {
mul_v2_m3v3(projverts[i], axis_mat.ptr(), positions[points[i]]);
}
meshintersect::CDT_input<double> input;
input.vert = verts;
input.edge = edges;
input.face = faces;
input.need_ids = false;
BLI_polyfill_calc_arena(projverts,
points.size(),
0,
reinterpret_cast<uint32_t(*)[3]>(r_tris.data()),
pf_arena);
meshintersect::CDT_result<double> result = delaunay_2d_calc(input, CDT_INSIDE_WITH_HOLES);
for (const int i : r_tris.index_range()) {
r_tris[i] += uint3(points.first());
}
strokes_triangles[group_id].resize(result.face.size());
MutableSpan<uint3> r_tris = strokes_triangles[group_id];
BLI_memarena_clear(pf_arena);
threading::parallel_for(result.face.index_range(), 512, [&](const IndexRange range) {
for (const int i : range) {
BLI_assert(result.face[i].size() == 3);
r_tris[i] = uint3(vert_to_point_map[result.face[i][0]],
vert_to_point_map[result.face[i][1]],
vert_to_point_map[result.face[i][2]]);
}
});
}
});
});

View File

@ -725,24 +725,32 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
/* Precompute all the triangle and vertex counts.
* In case the drawing should not be rendered, we need to compute the offset where the next
* drawing begins. */
Array<int> num_triangles_per_stroke(visible_strokes.size());
Array<int> num_triangles_per_stroke(groups.size());
Array<int> num_vertices_per_stroke(visible_strokes.size());
int total_num_triangles = 0;
int total_num_vertices = 0;
visible_strokes.foreach_index([&](const int stroke_i, const int pos) {
const IndexRange points = points_by_curve[stroke_i];
const int num_stroke_triangles = triangles[stroke_i].size();
const int num_stroke_vertices = (points.size() +
int(cyclic[stroke_i] && (points.size() >= 3)));
num_triangles_per_stroke[pos] = num_stroke_triangles;
num_vertices_per_stroke[pos] = num_stroke_vertices;
int current_curve = 0;
for (const int group_id : groups.index_range()) {
const IndexMask &group = groups[group_id];
const int num_stroke_triangles = triangles[group_id].size();
num_triangles_per_stroke[group_id] = num_stroke_triangles;
total_num_triangles += num_stroke_triangles;
total_num_vertices += num_stroke_vertices;
});
group.foreach_index([&](const int curve_i) {
const IndexRange points = points_by_curve[curve_i];
const int num_stroke_vertices = (points.size() +
int(cyclic[curve_i] && (points.size() >= 3)));
num_vertices_per_stroke[current_curve] = num_stroke_vertices;
total_num_vertices += num_stroke_vertices;
current_curve++;
});
}
bool is_layer_used_as_mask = false;
const bool show_drawing_in_render = use_layer_in_render(
@ -789,17 +797,21 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
info.frame_number != pd->cfra && pd->use_multiedit_lines_only;
const bool is_onion = info.onion_id != 0;
visible_strokes.foreach_index([&](const int stroke_i, const int pos) {
const IndexRange points = points_by_curve[stroke_i];
current_curve = 0;
for (const int group_id : groups.index_range()) {
const IndexMask &group = groups[group_id];
const int curve_i = group.first();
/* The material index is allowed to be negative as it's stored as a generic attribute. We
* clamp it here to avoid crashing in the rendering code. Any stroke with a material < 0 will
* use the first material in the first material slot.*/
const int material_index = std::max(stroke_materials[stroke_i], 0);
* clamp it here to avoid crashing in the rendering code. Any stroke with a material < 0
* will use the first material in the first material slot.*/
const int material_index = std::max(stroke_materials[curve_i], 0);
const MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, material_index + 1);
const bool hide_material = (gp_style->flag & GP_MATERIAL_HIDE) != 0;
const bool show_stroke = ((gp_style->flag & GP_MATERIAL_STROKE_SHOW) != 0);
const bool show_fill = (points.size() >= 3) &&
const bool show_fill = (!triangles[group_id].is_empty()) &&
((gp_style->flag & GP_MATERIAL_FILL_SHOW) != 0) &&
(!pd->simplify_fill);
const bool hide_onion = is_onion && ((gp_style->flag & GP_MATERIAL_HIDE_ONIONSKIN) != 0 ||
@ -808,9 +820,12 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
(only_lines && !is_onion) || hide_onion;
if (skip_stroke) {
t_offset += num_triangles_per_stroke[pos];
t_offset += num_vertices_per_stroke[pos] * 2;
return;
t_offset += num_triangles_per_stroke[group_id];
for (const int i : group.index_range()) {
t_offset += num_vertices_per_stroke[current_curve + i] * 2;
};
current_curve += group.size();
continue;
}
GPUUniformBuf *new_ubo_mat;
@ -855,20 +870,25 @@ static GPENCIL_tObject *grease_pencil_object_cache_populate(GPENCIL_PrivateData
if (show_fill) {
const int v_first = t_offset * 3;
const int v_count = num_triangles_per_stroke[pos] * 3;
const int v_count = num_triangles_per_stroke[group_id] * 3;
drawcall_add(geom, v_first, v_count);
}
t_offset += num_triangles_per_stroke[pos];
t_offset += num_triangles_per_stroke[group_id];
if (show_stroke) {
const int v_first = t_offset * 3;
const int v_count = num_vertices_per_stroke[pos] * 2 * 3;
drawcall_add(geom, v_first, v_count);
}
group.foreach_index([&](const int curve_i) {
const IndexRange points = points_by_curve[curve_i];
t_offset += num_vertices_per_stroke[pos] * 2;
});
if (show_stroke) {
const int v_first = t_offset * 3;
const int v_count = num_vertices_per_stroke[current_curve] * 2 * 3;
drawcall_add(geom, v_first, v_count);
}
t_offset += num_vertices_per_stroke[current_curve] * 2;
current_curve++;
});
}
}
drawcall_flush();

View File

@ -89,33 +89,32 @@ class GreasePencil {
IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Span<Vector<uint3>> triangles = info.drawing.triangles();
visible_strokes.foreach_index([&](const int stroke_i) {
const IndexRange points = points_by_curve[stroke_i];
const int material_index = stroke_materials[stroke_i];
const bool hide_onion = info.onion_id != 0;
for (const int group_id : groups.index_range()) {
const IndexMask &group = groups[group_id];
const int material_index = stroke_materials[group.first()];
MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, material_index + 1);
const bool hide_onion = info.onion_id != 0;
const bool hide_material = (gp_style->flag & GP_MATERIAL_HIDE) != 0;
const int num_stroke_triangles = triangles[stroke_i].size();
const int num_stroke_vertices = (points.size() +
int(cyclic[stroke_i] && (points.size() >= 3)));
const int num_stroke_triangles = triangles[group_id].size();
if (hide_material || hide_onion) {
t_offset += num_stroke_triangles;
t_offset += num_stroke_vertices * 2;
return;
}
blender::gpu::Batch *geom = draw::DRW_cache_grease_pencil_get(scene, ob);
const bool show_stroke = (gp_style->flag & GP_MATERIAL_STROKE_SHOW) != 0;
const bool show_fill = (points.size() >= 3) &&
const bool show_fill = (num_stroke_triangles != 0) &&
(gp_style->flag & GP_MATERIAL_FILL_SHOW) != 0;
blender::gpu::Batch *geom = draw::DRW_cache_grease_pencil_get(scene, ob);
if (show_fill) {
int v_first = t_offset * 3;
int v_count = num_stroke_triangles * 3;
@ -124,13 +123,25 @@ class GreasePencil {
t_offset += num_stroke_triangles;
if (show_stroke) {
int v_first = t_offset * 3;
int v_count = num_stroke_vertices * 2 * 3;
pass.draw(geom, 1, v_count, v_first, res_handle);
}
t_offset += num_stroke_vertices * 2;
});
group.foreach_index([&](const int curve_i) {
const IndexRange points = points_by_curve[curve_i];
const int num_stroke_vertices = (points.size() +
int(cyclic[curve_i] && (points.size() >= 3)));
if (hide_material || hide_onion) {
t_offset += num_stroke_vertices * 2;
return;
}
if (show_stroke) {
int v_first = t_offset * 3;
int v_count = num_stroke_vertices * 2 * 3;
pass.draw(geom, 1, v_count, v_first, res_handle);
}
t_offset += num_stroke_vertices * 2;
});
}
}
}

View File

@ -323,31 +323,26 @@ static void OVERLAY_outline_grease_pencil(OVERLAY_PrivateData *pd, Scene *scene,
IndexMaskMemory memory;
const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes(
*ob, info.drawing, memory);
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Span<Vector<uint3>> triangles = info.drawing.triangles();
visible_strokes.foreach_index([&](const int stroke_i) {
const IndexRange points = points_by_curve[stroke_i];
const int material_index = stroke_materials[stroke_i];
for (const int group_id : groups.index_range()) {
const IndexMask &group = groups[group_id];
const int material_index = stroke_materials[group.first()];
MaterialGPencilStyle *gp_style = BKE_gpencil_material_settings(ob, material_index + 1);
const bool hide_onion = info.onion_id != 0;
const bool hide_material = (gp_style->flag & GP_MATERIAL_HIDE) != 0;
const int num_stroke_triangles = triangles[stroke_i].size();
const int num_stroke_vertices = (points.size() +
int(cyclic[stroke_i] && (points.size() >= 3)));
if (hide_material || hide_onion) {
t_offset += num_stroke_triangles;
t_offset += num_stroke_vertices * 2;
return;
}
blender::gpu::Batch *geom = draw::DRW_cache_grease_pencil_get(scene, ob);
const int num_stroke_triangles = triangles[group_id].size();
const bool show_stroke = (gp_style->flag & GP_MATERIAL_STROKE_SHOW) != 0;
const bool show_fill = (points.size() >= 3) && (gp_style->flag & GP_MATERIAL_FILL_SHOW) != 0;
const bool show_fill = (num_stroke_triangles != 0) &&
(gp_style->flag & GP_MATERIAL_FILL_SHOW) != 0;
blender::gpu::Batch *geom = draw::DRW_cache_grease_pencil_get(scene, ob);
if (show_fill) {
int v_first = t_offset * 3;
@ -357,13 +352,24 @@ static void OVERLAY_outline_grease_pencil(OVERLAY_PrivateData *pd, Scene *scene,
t_offset += num_stroke_triangles;
if (show_stroke) {
int v_first = t_offset * 3;
int v_count = num_stroke_vertices * 2 * 3;
DRW_shgroup_call_range(grp, ob, geom, v_first, v_count);
}
t_offset += num_stroke_vertices * 2;
});
group.foreach_index([&](const int curve_i) {
const IndexRange points = points_by_curve[curve_i];
const int num_stroke_vertices = (points.size() +
int(cyclic[curve_i] && (points.size() >= 3)));
if (hide_material || hide_onion) {
t_offset += num_stroke_vertices * 2;
return;
}
if (show_stroke) {
int v_first = t_offset * 3;
int v_count = num_stroke_vertices * 2 * 3;
DRW_shgroup_call_range(grp, ob, geom, v_first, v_count);
}
t_offset += num_stroke_vertices * 2;
});
}
}
}

View File

@ -1075,8 +1075,8 @@ static void grease_pencil_geom_batch_ensure(Object &object,
total_verts_num += num_points + num_cyclic + num_curves * 2;
total_triangles_num += (num_points + num_cyclic) * 2;
for (const int curve_i : curves.curves_range()) {
total_triangles_num += info.drawing.triangles()[curve_i].size();
for (const int group_id : info.drawing.triangles().index_range()) {
total_triangles_num += info.drawing.triangles()[group_id].size();
}
verts_start_offsets_per_visible_drawing.append(std::move(verts_start_offsets));
@ -1194,70 +1194,80 @@ static void grease_pencil_geom_batch_ensure(Object &object,
GPU_indexbuf_add_tri_verts(&ibo, v_mat + 2, v_mat + 1, v_mat + 3);
};
visible_strokes.foreach_index([&](const int curve_i, const int pos) {
const IndexRange points = points_by_curve[curve_i];
const bool is_cyclic = cyclic[curve_i] && (points.size() > 2);
const int verts_start_offset = verts_start_offsets[pos];
const int num_verts = 1 + points.size() + (is_cyclic ? 1 : 0) + 1;
const IndexRange verts_range = IndexRange(verts_start_offset, num_verts);
MutableSpan<GreasePencilStrokeVert> verts_slice = verts.slice(verts_range);
MutableSpan<GreasePencilColorVert> cols_slice = cols.slice(verts_range);
const float4x2 texture_matrix = texture_matrices[curve_i] * object_space_to_layer_space;
const Array<IndexMask> groups = info.drawing.get_shapes_index_masks(memory);
const Array<int> point_to_curve_map = curves.point_to_curve_map();
const Span<float> lengths = curves.evaluated_lengths_for_curve(curve_i, cyclic[curve_i]);
auto point_to_id = [&](uint32_t p) {
const int curve_ = point_to_curve_map[p];
const IndexRange points_ = points_by_curve[curve_];
return (1 + (p - points_.first()) + verts_start_offsets[curve_]) << GP_VERTEX_ID_SHIFT;
};
/* First vertex is not drawn. */
verts_slice.first().mat = -1;
for (const int group_id : groups.index_range()) {
const IndexMask &group = groups[group_id];
const Span<uint3> tris_slice = triangles[group_id];
/* If the stroke has more than 2 points, add the triangle indices to the index buffer. */
if (points.size() >= 3) {
const Span<uint3> tris_slice = triangles[curve_i];
for (const uint3 tri : tris_slice) {
GPU_indexbuf_add_tri_verts(
&ibo,
(verts_range.first() + tri.x - points.first() + 1) << GP_VERTEX_ID_SHIFT,
(verts_range.first() + tri.y - points.first() + 1) << GP_VERTEX_ID_SHIFT,
(verts_range.first() + tri.z - points.first() + 1) << GP_VERTEX_ID_SHIFT);
/* Add the triangle indices to the index buffer. */
// if (tris_slice.size() != 0) {
for (const uint3 tri : tris_slice) {
const uint3 tri_verts = uint3(point_to_id(tri.x), point_to_id(tri.y), point_to_id(tri.z));
GPU_indexbuf_add_tri_verts(&ibo, tri_verts.x, tri_verts.y, tri_verts.z);
}
// }
group.foreach_index([&](const int curve_i) {
const IndexRange points = points_by_curve[curve_i];
const bool is_cyclic = cyclic[curve_i] && (points.size() > 2);
const int verts_start_offset = verts_start_offsets[curve_i];
const int num_verts = 1 + points.size() + (is_cyclic ? 1 : 0) + 1;
const IndexRange verts_range = IndexRange(verts_start_offset, num_verts);
MutableSpan<GreasePencilStrokeVert> verts_slice = verts.slice(verts_range);
MutableSpan<GreasePencilColorVert> cols_slice = cols.slice(verts_range);
const float4x2 texture_matrix = texture_matrices[curve_i] * object_space_to_layer_space;
const Span<float> lengths = curves.evaluated_lengths_for_curve(curve_i, cyclic[curve_i]);
/* First vertex is not drawn. */
verts_slice.first().mat = -1;
/* Write all the point attributes to the vertex buffers. Create a quad for each point. */
const float u_scale = u_scales[curve_i];
const float u_translation = u_translations[curve_i];
for (const int i : IndexRange(points.size())) {
const int idx = i + 1;
const float u_stroke = u_scale * (i > 0 ? lengths[i - 1] : 0.0f) + u_translation;
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[i],
idx,
u_stroke,
texture_matrix,
verts_slice[idx],
cols_slice[idx]);
}
}
/* Write all the point attributes to the vertex buffers. Create a quad for each point. */
const float u_scale = u_scales[curve_i];
const float u_translation = u_translations[curve_i];
for (const int i : IndexRange(points.size())) {
const int idx = i + 1;
const float u_stroke = u_scale * (i > 0 ? lengths[i - 1] : 0.0f) + u_translation;
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[i],
idx,
u_stroke,
texture_matrix,
verts_slice[idx],
cols_slice[idx]);
}
if (is_cyclic) {
const int idx = points.size() + 1;
const float u = points.size() > 1 ? lengths[points.size() - 1] : 0.0f;
const float u_stroke = u_scale * u + u_translation;
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[0],
idx,
u_stroke,
texture_matrix,
verts_slice[idx],
cols_slice[idx]);
}
if (is_cyclic) {
const int idx = points.size() + 1;
const float u = points.size() > 1 ? lengths[points.size() - 1] : 0.0f;
const float u_stroke = u_scale * u + u_translation;
populate_point(verts_range,
curve_i,
start_caps[curve_i],
end_caps[curve_i],
points[0],
idx,
u_stroke,
texture_matrix,
verts_slice[idx],
cols_slice[idx]);
}
/* Last vertex is not drawn. */
verts_slice.last().mat = -1;
});
/* Last vertex is not drawn. */
verts_slice.last().mat = -1;
});
}
}
/* Mark last 2 verts as invalid. */