[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45296] trunk/blender/source/blender/bmesh /intern: Add BMO function to append to a buffer slot.

Nicholas Bishop nicholasbishop at gmail.com
Fri Mar 30 19:30:29 CEST 2012


Revision: 45296
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45296
Author:   nicholasbishop
Date:     2012-03-30 17:30:24 +0000 (Fri, 30 Mar 2012)
Log Message:
-----------
Add BMO function to append to a buffer slot.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
    trunk/blender/source/blender/bmesh/intern/bmesh_operators.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h	2012-03-30 16:09:12 UTC (rev 45295)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h	2012-03-30 17:30:24 UTC (rev 45296)
@@ -289,6 +289,10 @@
 
 void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *op, const char htype, const short oflag);
 
+/* copies the values from another slot to the end of the output slot */
+void BMO_slot_buffer_append(BMOperator *output_op, const char *output_op_slot,
+							BMOperator *other_op, const char *other_op_slot);
+
 /* puts every element of type type (which is a bitmask) with tool flag flag,
  * into a slot. */
 void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-30 16:09:12 UTC (rev 45295)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-30 17:30:24 UTC (rev 45296)
@@ -725,6 +725,38 @@
 }
 
 /**
+ * Copies the values from another slot to the end of the output slot.
+ */
+void BMO_slot_buffer_append(BMOperator *output_op, const char *output_slot_name,
+							BMOperator *other_op, const char *other_slot_name)
+{
+	BMOpSlot *output_slot = BMO_slot_get(output_op, output_slot_name);
+	BMOpSlot *other_slot = BMO_slot_get(other_op, other_slot_name);
+
+	BLI_assert(output_slot->slottype == BMO_OP_SLOT_ELEMENT_BUF &&
+			   other_slot->slottype == BMO_OP_SLOT_ELEMENT_BUF);
+
+	if (output_slot->len == 0) {
+		/* output slot is empty, copy rather than append */
+		BMO_slot_copy(other_op, output_op, other_slot_name, output_slot_name);
+	}
+	else if (other_slot->len != 0) {
+		int elem_size = BMO_OPSLOT_TYPEINFO[output_slot->slottype];
+		int alloc_size = elem_size * (output_slot->len + other_slot->len);
+		/* allocate new buffer */
+		void *buf = BLI_memarena_alloc(output_op->arena, alloc_size);
+
+		/* copy slot data */
+		memcpy(buf, output_slot->data.buf, elem_size * output_slot->len);
+		memcpy(((char*)buf) + elem_size * output_slot->len,
+			   other_slot->data.buf, elem_size * other_slot->len);
+
+		output_slot->data.buf = buf;
+		output_slot->len += other_slot->len;
+	}
+}
+
+/**
  * \brief BMO_FLAG_TO_SLOT
  *
  * Copies elements of a certain type, which have a certain flag set




More information about the Bf-blender-cvs mailing list