[Bf-blender-cvs] [8466fd4bd1f] master: Cleanup: Curves draw cache renaming, use references

Hans Goudey noreply at git.blender.org
Thu Mar 31 01:25:26 CEST 2022


Commit: 8466fd4bd1fe0f07b272e6d54b0b3404448a92b4
Author: Hans Goudey
Date:   Wed Mar 30 18:25:06 2022 -0500
Branches: master
https://developer.blender.org/rB8466fd4bd1fe0f07b272e6d54b0b3404448a92b4

Cleanup: Curves draw cache renaming, use references

Also change some remaining cases of "hair object" to "curves object".

===================================================================

M	release/scripts/startup/bl_operators/geometry_nodes.py
M	source/blender/blenkernel/intern/object.cc
M	source/blender/draw/intern/draw_cache_impl_curves.cc
M	source/blender/draw/intern/draw_hair.c
M	source/blender/draw/intern/draw_hair_private.h

===================================================================

diff --git a/release/scripts/startup/bl_operators/geometry_nodes.py b/release/scripts/startup/bl_operators/geometry_nodes.py
index 746b1800757..c3892e988c5 100644
--- a/release/scripts/startup/bl_operators/geometry_nodes.py
+++ b/release/scripts/startup/bl_operators/geometry_nodes.py
@@ -26,7 +26,7 @@ def geometry_node_group_empty_new():
 def geometry_modifier_poll(context):
     ob = context.object
 
-    # Test object support for geometry node modifier (No hair object support yet)
+    # Test object support for geometry node modifier (No curves object support yet)
     if not ob or ob.type not in {'MESH', 'POINTCLOUD', 'VOLUME', 'CURVE', 'FONT'}:
         return False
 
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 84d9002f4d2..833cdb74067 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -4000,7 +4000,7 @@ void BKE_object_foreach_display_point(Object *ob,
                                       void (*func_cb)(const float[3], void *),
                                       void *user_data)
 {
-  /* TODO: pointcloud and hair objects support */
+  /* TODO: pointcloud and curves object support */
   const Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
   float co[3];
 
diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc
index a21a6409ca5..0b8913402e6 100644
--- a/source/blender/draw/intern/draw_cache_impl_curves.cc
+++ b/source/blender/draw/intern/draw_cache_impl_curves.cc
@@ -4,7 +4,7 @@
 /** \file
  * \ingroup draw
  *
- * \brief Hair API for render engines
+ * \brief Curves API for render engines
  */
 
 #include <cstring>
@@ -35,33 +35,29 @@ using blender::float3;
 using blender::IndexRange;
 using blender::Span;
 
-static void curves_batch_cache_clear(Curves *curves);
-
 /* ---------------------------------------------------------------------- */
-/* Hair GPUBatch Cache */
+/* Curves GPUBatch Cache */
 
-struct HairBatchCache {
+struct CurvesBatchCache {
   ParticleHairCache hair;
 
-  /* settings to determine if cache is invalid */
+  /* To determine if cache is invalid. */
   bool is_dirty;
 };
 
-/* GPUBatch cache management. */
-
-static bool curves_batch_cache_valid(Curves *curves)
+static bool curves_batch_cache_valid(const Curves &curves)
 {
-  HairBatchCache *cache = static_cast<HairBatchCache *>(curves->batch_cache);
+  const CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache);
   return (cache && cache->is_dirty == false);
 }
 
-static void curves_batch_cache_init(Curves *curves)
+static void curves_batch_cache_init(Curves &curves)
 {
-  HairBatchCache *cache = static_cast<HairBatchCache *>(curves->batch_cache);
+  CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache);
 
   if (!cache) {
-    cache = MEM_cnew<HairBatchCache>(__func__);
-    curves->batch_cache = cache;
+    cache = MEM_cnew<CurvesBatchCache>(__func__);
+    curves.batch_cache = cache;
   }
   else {
     memset(cache, 0, sizeof(*cache));
@@ -70,23 +66,33 @@ static void curves_batch_cache_init(Curves *curves)
   cache->is_dirty = false;
 }
 
+static void curves_batch_cache_clear(Curves &curves)
+{
+  CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves.batch_cache);
+  if (!cache) {
+    return;
+  }
+
+  particle_batch_cache_clear_hair(&cache->hair);
+}
+
 void DRW_curves_batch_cache_validate(Curves *curves)
 {
-  if (!curves_batch_cache_valid(curves)) {
-    curves_batch_cache_clear(curves);
-    curves_batch_cache_init(curves);
+  if (!curves_batch_cache_valid(*curves)) {
+    curves_batch_cache_clear(*curves);
+    curves_batch_cache_init(*curves);
   }
 }
 
-static HairBatchCache *curves_batch_cache_get(Curves *curves)
+static CurvesBatchCache &curves_batch_cache_get(Curves &curves)
 {
-  DRW_curves_batch_cache_validate(curves);
-  return static_cast<HairBatchCache *>(curves->batch_cache);
+  DRW_curves_batch_cache_validate(&curves);
+  return *static_cast<CurvesBatchCache *>(curves.batch_cache);
 }
 
 void DRW_curves_batch_cache_dirty_tag(Curves *curves, int mode)
 {
-  HairBatchCache *cache = static_cast<HairBatchCache *>(curves->batch_cache);
+  CurvesBatchCache *cache = static_cast<CurvesBatchCache *>(curves->batch_cache);
   if (cache == nullptr) {
     return;
   }
@@ -99,52 +105,42 @@ void DRW_curves_batch_cache_dirty_tag(Curves *curves, int mode)
   }
 }
 
-static void curves_batch_cache_clear(Curves *curves)
-{
-  HairBatchCache *cache = static_cast<HairBatchCache *>(curves->batch_cache);
-  if (!cache) {
-    return;
-  }
-
-  particle_batch_cache_clear_hair(&cache->hair);
-}
-
 void DRW_curves_batch_cache_free(Curves *curves)
 {
-  curves_batch_cache_clear(curves);
+  curves_batch_cache_clear(*curves);
   MEM_SAFE_FREE(curves->batch_cache);
 }
 
-static void ensure_seg_pt_count(Curves *curves, ParticleHairCache *curves_cache)
+static void ensure_seg_pt_count(const Curves &curves, ParticleHairCache &curves_cache)
 {
-  if ((curves_cache->pos != nullptr && curves_cache->indices != nullptr) ||
-      (curves_cache->proc_point_buf != nullptr)) {
+  if ((curves_cache.pos != nullptr && curves_cache.indices != nullptr) ||
+      (curves_cache.proc_point_buf != nullptr)) {
     return;
   }
 
-  curves_cache->strands_len = curves->geometry.curve_size;
-  curves_cache->elems_len = curves->geometry.point_size + curves->geometry.curve_size;
-  curves_cache->point_len = curves->geometry.point_size;
+  curves_cache.strands_len = curves.geometry.curve_size;
+  curves_cache.elems_len = curves.geometry.point_size + curves.geometry.curve_size;
+  curves_cache.point_len = curves.geometry.point_size;
 }
 
-static void curves_batch_cache_fill_segments_proc_pos(Curves *curves,
-                                                      GPUVertBufRaw *attr_step,
-                                                      GPUVertBufRaw *length_step)
+static void curves_batch_cache_fill_segments_proc_pos(const Curves &curves_id,
+                                                      GPUVertBufRaw &attr_step,
+                                                      GPUVertBufRaw &length_step)
 {
   /* TODO: use hair radius layer if available. */
-  const int curve_size = curves->geometry.curve_size;
-  const blender::bke::CurvesGeometry &geometry = blender::bke::CurvesGeometry::wrap(
-      curves->geometry);
-  Span<float3> positions = geometry.positions();
+  const int curve_size = curves_id.geometry.curve_size;
+  const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(
+      curves_id.geometry);
+  Span<float3> positions = curves.positions();
 
   for (const int i : IndexRange(curve_size)) {
-    const IndexRange curve_range = geometry.points_for_curve(i);
+    const IndexRange curve_range = curves.points_for_curve(i);
 
     Span<float3> curve_positions = positions.slice(curve_range);
     float total_len = 0.0f;
     float *seg_data_first;
     for (const int i_curve : curve_positions.index_range()) {
-      float *seg_data = (float *)GPU_vertbuf_raw_step(attr_step);
+      float *seg_data = (float *)GPU_vertbuf_raw_step(&attr_step);
       copy_v3_v3(seg_data, curve_positions[i_curve]);
       if (i_curve == 0) {
         seg_data_first = seg_data;
@@ -156,7 +152,7 @@ static void curves_batch_cache_fill_segments_proc_pos(Curves *curves,
       seg_data[3] = total_len;
     }
     /* Assign length value. */
-    *(float *)GPU_vertbuf_raw_step(length_step) = total_len;
+    *(float *)GPU_vertbuf_raw_step(&length_step) = total_len;
     if (total_len > 0.0f) {
       /* Divide by total length to have a [0-1] number. */
       for ([[maybe_unused]] const int i_curve : curve_positions.index_range()) {
@@ -167,67 +163,67 @@ static void curves_batch_cache_fill_segments_proc_pos(Curves *curves,
   }
 }
 
-static void curves_batch_cache_ensure_procedural_pos(Curves *curves,
-                                                     ParticleHairCache *cache,
+static void curves_batch_cache_ensure_procedural_pos(Curves &curves,
+                                                     ParticleHairCache &cache,
                                                      GPUMaterial *gpu_material)
 {
-  if (cache->proc_point_buf == nullptr) {
-    /* initialize vertex format */
+  if (cache.proc_point_buf == nullptr) {
+    /* Initialize vertex format. */
     GPUVertFormat format = {0};
     uint pos_id = GPU_vertformat_attr_add(&format, "posTime", GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
 
-    cache->proc_point_buf = GPU_vertbuf_create_with_format(&format);
-    GPU_vertbuf_data_alloc(cache->proc_point_buf, cache->point_len);
+    cache.proc_point_buf = GPU_vertbuf_create_with_format(&format);
+    GPU_vertbuf_data_alloc(cache.proc_point_buf, cache.point_len);
 
     GPUVertBufRaw point_step;
-    GPU_vertbuf_attr_get_raw_data(cache->proc_point_buf, pos_id, &point_step);
+    GPU_vertbuf_attr_get_raw_data(cache.proc_point_buf, pos_id, &point_step);
 
     GPUVertFormat length_format = {0};
     uint length_id = GPU_vertformat_attr_add(
         &length_format, "hairLength", GPU_COMP_F32, 1, GPU_FETCH_FLOAT);
 
-    cache->proc_length_buf = GPU_vertbuf_create_with_format(&length_format);
-    GPU_vertbuf_data_alloc(cache->proc_length_buf, cache->strands_len);
+    cache.proc_length_buf = GPU_vertbuf_create_with_format(&length_format);
+    GPU_vertbuf_data_alloc(cache.proc_length_buf, cache.strands_len);
 
     GPUVertBufRaw length_step;
-    GPU_vertbuf_attr_get_raw_data(cache->proc_length_buf, length_id, &length_step);
+    GPU_vertbuf_attr_get_raw_data(cache.proc_length_buf, length_id, &length_step);
 
-    curves_batch_cache_fill_segments_proc_pos(curves, &point_step, &length_step);
+    curves_batch_cache_fill_segments_proc_pos(curves, point_step, length_step);
 
     /* Create vbo immediately to bind to texture buffer. */
-    GPU_vertbuf_use(cache->proc_point_buf);
-    cache->point_tex = GPU_texture_create_from_vertbuf("hair_point", cache->proc_point_buf);
+    GPU_vertbuf_use(cache.proc_point_buf);
+    cache.point_tex = GPU_texture_create_from_vertbuf("hair_point", cache.proc_point_buf);
   }
 
-  if (gpu_material && cache->

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list