[Bf-blender-cvs] [f9f6042bcf9] eevee-motionblur-object: GPUVertexFormat: Add Rename function

Clément Foucault noreply at git.blender.org
Tue Apr 14 19:09:14 CEST 2020


Commit: f9f6042bcf9b8d180ada5c713ed55c8114399f2a
Author: Clément Foucault
Date:   Mon Apr 6 15:07:02 2020 +0200
Branches: eevee-motionblur-object
https://developer.blender.org/rBf9f6042bcf9b8d180ada5c713ed55c8114399f2a

GPUVertexFormat: Add Rename function

This is needed for motion blur.

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

M	source/blender/gpu/GPU_vertex_format.h
M	source/blender/gpu/intern/gpu_vertex_format.c

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

diff --git a/source/blender/gpu/GPU_vertex_format.h b/source/blender/gpu/GPU_vertex_format.h
index 7e384d0a692..ae7d072298a 100644
--- a/source/blender/gpu/GPU_vertex_format.h
+++ b/source/blender/gpu/GPU_vertex_format.h
@@ -125,6 +125,10 @@ BLI_INLINE const char *GPU_vertformat_attr_name_get(const GPUVertFormat *format,
   return format->names + attr->names[n_idx];
 }
 
+/* WARNING: Can only rename using a string with same character count.
+ * WARNING: This removes all other aliases of this attrib */
+void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name);
+
 void GPU_vertformat_safe_attrib_name(const char *attrib_name, char *r_safe_name, uint max_len);
 
 /* format conversion */
diff --git a/source/blender/gpu/intern/gpu_vertex_format.c b/source/blender/gpu/intern/gpu_vertex_format.c
index 8370bcf4beb..f15770fb51f 100644
--- a/source/blender/gpu/intern/gpu_vertex_format.c
+++ b/source/blender/gpu/intern/gpu_vertex_format.c
@@ -261,6 +261,20 @@ int GPU_vertformat_attr_id_get(const GPUVertFormat *format, const char *name)
   return -1;
 }
 
+void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr_id, const char *new_name)
+{
+  BLI_assert(attr_id > -1 && attr_id < format->attr_len);
+  GPUVertAttr *attr = &format->attrs[attr_id];
+  char *attr_name = (char *)GPU_vertformat_attr_name_get(format, attr, 0);
+  BLI_assert(strlen(attr_name) == strlen(new_name));
+  int i = 0;
+  while (attr_name[i] != '\0') {
+    attr_name[i] = new_name[i];
+    i++;
+  }
+  attr->name_len = 1;
+}
+
 /* Encode 8 original bytes into 11 safe bytes. */
 static void safe_bytes(char out[11], const char data[8])
 {



More information about the Bf-blender-cvs mailing list