From 2cf5838b870048e0029c19ce0d89d6f37d2a0aca Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 3 Mar 2025 12:25:50 -0500 Subject: [PATCH] Grease Pencil: Slightly optimize IndexMask usage in draw extraction Instead of computing an index mask for all curves, then returning an intersection with the visible curves, just use the visible curves as a universe for the original calculation. Also add another early out for when there are no NURBS curves. --- .../intern/draw_cache_impl_grease_pencil.cc | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc b/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc index 0e25912b513..d7126e28da5 100644 --- a/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc +++ b/source/blender/draw/intern/draw_cache_impl_grease_pencil.cc @@ -450,18 +450,15 @@ static IndexMask grease_pencil_get_visible_nurbs_curves(Object &object, return IndexMask(0); } - const VArray types = curves.curve_types(); - const IndexMask selected_editable_strokes = ed::greasepencil::retrieve_editable_and_selected_strokes( object, drawing, layer_index, memory); - const IndexMask nurbs_curves = IndexMask::from_predicate( - curves.curves_range(), GrainSize(4096), memory, [&](const int64_t curve_i) { + const VArray types = curves.curve_types(); + return IndexMask::from_predicate( + selected_editable_strokes, GrainSize(4096), memory, [&](const int64_t curve_i) { return types[curve_i] == CURVE_TYPE_NURBS; }); - - return IndexMask::from_intersection(selected_editable_strokes, nurbs_curves, memory); } static IndexMask grease_pencil_get_visible_non_nurbs_curves( @@ -470,14 +467,15 @@ static IndexMask grease_pencil_get_visible_non_nurbs_curves( const bke::CurvesGeometry &curves = drawing.strokes(); const IndexMask visible_strokes = ed::greasepencil::retrieve_visible_strokes( object, drawing, memory); + if (!curves.has_curve_with_type(CURVE_TYPE_NURBS)) { + return visible_strokes; + } const VArray types = curves.curve_types(); - const IndexMask non_nurbs_curves = IndexMask::from_predicate( - curves.curves_range(), GrainSize(4096), memory, [&](const int64_t curve_i) { - return types[curve_i] != CURVE_TYPE_NURBS; + return IndexMask::from_predicate( + visible_strokes, GrainSize(4096), memory, [&](const int64_t curve) { + return types[curve] != CURVE_TYPE_NURBS; }); - - return IndexMask::from_intersection(visible_strokes, non_nurbs_curves, memory); } static void grease_pencil_cache_add_nurbs(Object &object,