[Bf-blender-cvs] [18def163f89] master: Cleanup: Simplify syntax in curves draw cache file

Hans Goudey noreply at git.blender.org
Fri Jun 17 15:11:50 CEST 2022


Commit: 18def163f89374cc0f594c1ab7917c5bbde4f074
Author: Hans Goudey
Date:   Fri Jun 17 15:11:10 2022 +0200
Branches: master
https://developer.blender.org/rB18def163f89374cc0f594c1ab7917c5bbde4f074

Cleanup: Simplify syntax in curves draw cache file

Also remove some unnecessary logic and change a variable name.

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

M	release/datafiles/locale
M	release/scripts/addons
M	source/blender/draw/intern/draw_cache_impl_curves.cc

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

diff --git a/release/datafiles/locale b/release/datafiles/locale
index 915744ad8e2..9a85b137951 160000
--- a/release/datafiles/locale
+++ b/release/datafiles/locale
@@ -1 +1 @@
-Subproject commit 915744ad8e255d1723d77671a6c6b074773c2199
+Subproject commit 9a85b13795157560b319235c63f5a13b0107ba41
diff --git a/release/scripts/addons b/release/scripts/addons
index c51e0bb1793..bdf75cb276d 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit c51e0bb1793c44c7a1b7435593dd5022cf7c8eec
+Subproject commit bdf75cb276dfd3b5266c909de4c099c00c68a659
diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc
index 8399f5c9650..68ca1153c96 100644
--- a/source/blender/draw/intern/draw_cache_impl_curves.cc
+++ b/source/blender/draw/intern/draw_cache_impl_curves.cc
@@ -87,13 +87,13 @@ static void curves_batch_cache_init(Curves &curves)
 
 static void curves_discard_attributes(CurvesEvalCache &curves_cache)
 {
-  for (int i = 0; i < GPU_MAX_ATTR; i++) {
+  for (const int i : IndexRange(GPU_MAX_ATTR)) {
     GPU_VERTBUF_DISCARD_SAFE(curves_cache.proc_attributes_buf[i]);
     DRW_TEXTURE_FREE_SAFE(curves_cache.proc_attributes_tex[i]);
   }
 
-  for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
-    for (int j = 0; j < GPU_MAX_ATTR; j++) {
+  for (const int i : IndexRange(MAX_HAIR_SUBDIV)) {
+    for (const int j : IndexRange(GPU_MAX_ATTR)) {
       GPU_VERTBUF_DISCARD_SAFE(curves_cache.final[i].attributes_buf[j]);
       DRW_TEXTURE_FREE_SAFE(curves_cache.final[i].attributes_tex[j]);
     }
@@ -115,10 +115,10 @@ static void curves_batch_cache_clear_data(CurvesEvalCache &curves_cache)
   DRW_TEXTURE_FREE_SAFE(curves_cache.strand_tex);
   DRW_TEXTURE_FREE_SAFE(curves_cache.strand_seg_tex);
 
-  for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
+  for (const int i : IndexRange(MAX_HAIR_SUBDIV)) {
     GPU_VERTBUF_DISCARD_SAFE(curves_cache.final[i].proc_buf);
     DRW_TEXTURE_FREE_SAFE(curves_cache.final[i].proc_tex);
-    for (int j = 0; j < MAX_THICKRES; j++) {
+    for (const int j : IndexRange(MAX_THICKRES)) {
       GPU_BATCH_DISCARD_SAFE(curves_cache.final[i].proc_hairs[j]);
     }
   }
@@ -184,7 +184,7 @@ void DRW_curves_batch_cache_free_old(Curves *curves, int ctime)
 
   bool do_discard = false;
 
-  for (int i = 0; i < MAX_HAIR_SUBDIV; i++) {
+  for (const int i : IndexRange(MAX_HAIR_SUBDIV)) {
     CurvesEvalFinalCache &final_cache = cache->curves_cache.final[i];
 
     if (drw_attributes_overlap(&final_cache.attr_used_over_time, &final_cache.attr_used)) {
@@ -515,14 +515,14 @@ static bool curves_ensure_attributes(const Curves &curves,
   ListBase gpu_attrs = GPU_material_attributes(gpu_material);
   LISTBASE_FOREACH (GPUMaterialAttribute *, gpu_attr, &gpu_attrs) {
     const char *name = gpu_attr->name;
-    eCustomDataType type = static_cast<eCustomDataType>(gpu_attr->type);
-    int layer = -1;
-    eAttrDomain domain;
 
-    if (drw_custom_data_match_attribute(cd_curve, name, &layer, &type)) {
+    int layer_index;
+    eCustomDataType type;
+    eAttrDomain domain;
+    if (drw_custom_data_match_attribute(cd_curve, name, &layer_index, &type)) {
       domain = ATTR_DOMAIN_CURVE;
     }
-    else if (drw_custom_data_match_attribute(cd_point, name, &layer, &type)) {
+    else if (drw_custom_data_match_attribute(cd_point, name, &layer_index, &type)) {
       domain = ATTR_DOMAIN_POINT;
     }
     else {
@@ -537,13 +537,12 @@ static bool curves_ensure_attributes(const Curves &curves,
       case CD_PROP_FLOAT2:
       case CD_PROP_FLOAT3:
       case CD_PROP_COLOR: {
-        if (layer != -1) {
-          DRW_AttributeRequest *req = drw_attributes_add_request(
-              &attrs_needed, (eCustomDataType)type, layer, domain);
-          if (req) {
-            BLI_strncpy(req->attribute_name, name, sizeof(req->attribute_name));
-          }
+        DRW_AttributeRequest *request = drw_attributes_add_request(
+            &attrs_needed, type, layer_index, domain);
+        if (request) {
+          BLI_strncpy(request->attribute_name, name, sizeof(request->attribute_name));
         }
+
         break;
       }
       default:
@@ -553,10 +552,9 @@ static bool curves_ensure_attributes(const Curves &curves,
 
   CurvesEvalFinalCache &final_cache = cache.curves_cache.final[subdiv];
 
-  const bool attr_overlap = drw_attributes_overlap(&final_cache.attr_used, &attrs_needed);
-  if (attr_overlap == false) {
+  if (!drw_attributes_overlap(&final_cache.attr_used, &attrs_needed)) {
     /* Some new attributes have been added, free all and start over. */
-    for (int i = 0; i < GPU_MAX_ATTR; i++) {
+    for (const int i : IndexRange(GPU_MAX_ATTR)) {
       GPU_VERTBUF_DISCARD_SAFE(cache.curves_cache.proc_attributes_buf[i]);
       DRW_TEXTURE_FREE_SAFE(cache.curves_cache.proc_attributes_tex[i]);
     }
@@ -566,7 +564,7 @@ static bool curves_ensure_attributes(const Curves &curves,
 
   bool need_tf_update = false;
 
-  for (int i = 0; i < final_cache.attr_used.num_requests; i++) {
+  for (const int i : IndexRange(final_cache.attr_used.num_requests)) {
     const DRW_AttributeRequest &request = final_cache.attr_used.requests[i];
 
     if (cache.curves_cache.proc_attributes_buf[i] != nullptr) {



More information about the Bf-blender-cvs mailing list