Refactor: GPv3: Use int3 for triangle data type
These were `uint3` before, but they should just be `int3`s. Also uses `array_utils::copy_group_to_group` with new cpptype `int3`. Pull Request: https://projects.blender.org/blender/blender/pulls/129166
This commit is contained in:
@@ -58,7 +58,7 @@ class DrawingRuntime {
|
||||
/**
|
||||
* Triangle cache for all the strokes in the drawing.
|
||||
*/
|
||||
mutable SharedCache<Vector<uint3>> triangles_cache;
|
||||
mutable SharedCache<Vector<int3>> triangles_cache;
|
||||
|
||||
/**
|
||||
* Normal vector cache for every stroke. Computed using Newell's method.
|
||||
@@ -93,7 +93,7 @@ class Drawing : public ::GreasePencilDrawing {
|
||||
/**
|
||||
* The triangles for fill geometry. Grouped by each stroke.
|
||||
*/
|
||||
Span<uint3> triangles() const;
|
||||
Span<int3> triangles() const;
|
||||
/**
|
||||
* Normal vectors for a plane that fits the stroke.
|
||||
*/
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
using blender::float3;
|
||||
using blender::int3;
|
||||
using blender::Span;
|
||||
using blender::uint3;
|
||||
using blender::VectorSet;
|
||||
|
||||
static const char *ATTR_POSITION = "position";
|
||||
@@ -396,7 +396,7 @@ static void update_triangle_cache(const Span<float3> positions,
|
||||
const OffsetIndices<int> points_by_curve,
|
||||
const OffsetIndices<int> triangle_offsets,
|
||||
const IndexMask &curve_mask,
|
||||
MutableSpan<uint3> triangles)
|
||||
MutableSpan<int3> triangles)
|
||||
{
|
||||
struct LocalMemArena {
|
||||
MemArena *pf_arena = nullptr;
|
||||
@@ -417,7 +417,7 @@ static void update_triangle_cache(const Span<float3> positions,
|
||||
if (points.size() < 3) {
|
||||
continue;
|
||||
}
|
||||
MutableSpan<uint3> r_tris = triangles.slice(triangle_offsets[curve_i]);
|
||||
MutableSpan<int3> r_tris = triangles.slice(triangle_offsets[curve_i]);
|
||||
|
||||
float(*projverts)[2] = static_cast<float(*)[2]>(
|
||||
BLI_memarena_alloc(pf_arena, sizeof(*projverts) * size_t(points.size())));
|
||||
@@ -436,11 +436,11 @@ static void update_triangle_cache(const Span<float3> positions,
|
||||
});
|
||||
}
|
||||
|
||||
Span<uint3> Drawing::triangles() const
|
||||
Span<int3> Drawing::triangles() const
|
||||
{
|
||||
const CurvesGeometry &curves = this->strokes();
|
||||
const OffsetIndices<int> triangle_offsets = this->triangle_offsets();
|
||||
this->runtime->triangles_cache.ensure([&](Vector<uint3> &r_data) {
|
||||
this->runtime->triangles_cache.ensure([&](Vector<int3> &r_data) {
|
||||
const int total_triangles = triangle_offsets.total_size();
|
||||
r_data.resize(total_triangles);
|
||||
|
||||
@@ -810,7 +810,7 @@ void Drawing::tag_positions_changed(const IndexMask &changed_curves)
|
||||
update_curve_plane_normal_cache(
|
||||
curves.positions(), curves.points_by_curve(), changed_curves, normals);
|
||||
});
|
||||
this->runtime->triangles_cache.update([&](Vector<uint3> &triangles) {
|
||||
this->runtime->triangles_cache.update([&](Vector<int3> &triangles) {
|
||||
const CurvesGeometry &curves = this->strokes();
|
||||
update_triangle_cache(curves.evaluated_positions(),
|
||||
this->curve_plane_normals(),
|
||||
@@ -865,21 +865,20 @@ void Drawing::tag_topology_changed(const IndexMask &changed_curves)
|
||||
* triangle offsets. */
|
||||
this->runtime->triangle_offsets_cache.tag_dirty();
|
||||
|
||||
this->runtime->triangles_cache.update([&](Vector<uint3> &triangles) {
|
||||
this->runtime->triangles_cache.update([&](Vector<int3> &triangles) {
|
||||
const CurvesGeometry &curves = this->strokes();
|
||||
const OffsetIndices<int> dst_triangle_offsets = this->triangle_offsets();
|
||||
|
||||
IndexMaskMemory memory;
|
||||
const IndexMask curves_to_copy = changed_curves.complement(curves.curves_range(), memory);
|
||||
|
||||
const Vector<uint3> src_triangles(triangles);
|
||||
const Vector<int3> src_triangles(triangles);
|
||||
triangles.reinitialize(dst_triangle_offsets.total_size());
|
||||
/* Copy groups to groups. */
|
||||
curves_to_copy.foreach_index(GrainSize(1024), [&](const int i) {
|
||||
triangles.as_mutable_span()
|
||||
.slice(dst_triangle_offsets[i])
|
||||
.copy_from(src_triangles.as_span().slice(src_triangle_offsets[i]));
|
||||
});
|
||||
array_utils::copy_group_to_group(src_triangle_offsets,
|
||||
dst_triangle_offsets,
|
||||
curves_to_copy,
|
||||
src_triangles.as_span(),
|
||||
triangles.as_mutable_span());
|
||||
|
||||
update_triangle_cache(curves.evaluated_positions(),
|
||||
this->curve_plane_normals(),
|
||||
|
||||
@@ -57,6 +57,7 @@ BLI_CPP_TYPE_MAKE(int8_t, CPPTypeFlags::BasicType)
|
||||
BLI_CPP_TYPE_MAKE(int16_t, CPPTypeFlags::BasicType)
|
||||
BLI_CPP_TYPE_MAKE(int32_t, CPPTypeFlags::BasicType)
|
||||
BLI_CPP_TYPE_MAKE(blender::int2, CPPTypeFlags::BasicType)
|
||||
BLI_CPP_TYPE_MAKE(blender::int3, CPPTypeFlags::BasicType)
|
||||
BLI_CPP_TYPE_MAKE(int64_t, CPPTypeFlags::BasicType)
|
||||
|
||||
BLI_CPP_TYPE_MAKE(uint8_t, CPPTypeFlags::BasicType)
|
||||
@@ -89,6 +90,7 @@ void register_cpp_types()
|
||||
BLI_CPP_TYPE_REGISTER(int16_t);
|
||||
BLI_CPP_TYPE_REGISTER(int32_t);
|
||||
BLI_CPP_TYPE_REGISTER(blender::int2);
|
||||
BLI_CPP_TYPE_REGISTER(blender::int3);
|
||||
BLI_CPP_TYPE_REGISTER(int64_t);
|
||||
|
||||
BLI_CPP_TYPE_REGISTER(uint8_t);
|
||||
|
||||
@@ -1168,7 +1168,7 @@ static void grease_pencil_geom_batch_ensure(Object &object,
|
||||
const VArray<float> fill_opacities = *attributes.lookup_or_default<float>(
|
||||
"fill_opacity", bke::AttrDomain::Curve, 1.0f);
|
||||
|
||||
const Span<uint3> triangles = info.drawing.triangles();
|
||||
const Span<int3> triangles = info.drawing.triangles();
|
||||
const Span<float4x2> texture_matrices = info.drawing.texture_matrices();
|
||||
const Span<int> verts_start_offsets = verts_start_offsets_per_visible_drawing[drawing_i];
|
||||
const Span<int> tris_start_offsets = tris_start_offsets_per_visible_drawing[drawing_i];
|
||||
@@ -1235,8 +1235,8 @@ static void grease_pencil_geom_batch_ensure(Object &object,
|
||||
|
||||
/* 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.slice(tris_start_offset, points.size() - 2);
|
||||
for (const uint3 tri : tris_slice) {
|
||||
const Span<int3> tris_slice = triangles.slice(tris_start_offset, points.size() - 2);
|
||||
for (const int3 tri : tris_slice) {
|
||||
GPU_indexbuf_add_tri_verts(&ibo,
|
||||
(verts_range[1] + tri.x) << GP_VERTEX_ID_SHIFT,
|
||||
(verts_range[1] + tri.y) << GP_VERTEX_ID_SHIFT,
|
||||
|
||||
Reference in New Issue
Block a user