瀏覽代碼

GeomVertexFormat::remove_data_type()

David Rose 21 年之前
父節點
當前提交
7261a2e4b9
共有 2 個文件被更改,包括 65 次插入2 次删除
  1. 63 2
      panda/src/gobj/qpgeomVertexFormat.cxx
  2. 2 0
      panda/src/gobj/qpgeomVertexFormat.h

+ 63 - 2
panda/src/gobj/qpgeomVertexFormat.cxx

@@ -94,6 +94,9 @@ qpGeomVertexFormat::
 //  Description: Returns a modifiable pointer to the indicated array.
 //  Description: Returns a modifiable pointer to the indicated array.
 //               This means duplicating it if it is shared or
 //               This means duplicating it if it is shared or
 //               registered.
 //               registered.
+//
+//               This may not be called once the format has been
+//               registered.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 qpGeomVertexArrayFormat *qpGeomVertexFormat::
 qpGeomVertexArrayFormat *qpGeomVertexFormat::
 modify_array(int array) {
 modify_array(int array) {
@@ -112,6 +115,9 @@ modify_array(int array) {
 //     Function: qpGeomVertexFormat::set_array
 //     Function: qpGeomVertexFormat::set_array
 //       Access: Published
 //       Access: Published
 //  Description: Replaces the definition of the indicated array.
 //  Description: Replaces the definition of the indicated array.
+//
+//               This may not be called once the format has been
+//               registered.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void qpGeomVertexFormat::
 void qpGeomVertexFormat::
 set_array(int array, qpGeomVertexArrayFormat *format) {
 set_array(int array, qpGeomVertexArrayFormat *format) {
@@ -124,6 +130,9 @@ set_array(int array, qpGeomVertexArrayFormat *format) {
 //     Function: qpGeomVertexFormat::remove_array
 //     Function: qpGeomVertexFormat::remove_array
 //       Access: Published
 //       Access: Published
 //  Description: Removes the nth array from the format.
 //  Description: Removes the nth array from the format.
+//
+//               This may not be called once the format has been
+//               registered.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void qpGeomVertexFormat::
 void qpGeomVertexFormat::
 remove_array(int array) {
 remove_array(int array) {
@@ -140,6 +149,9 @@ remove_array(int array) {
 //               arrays included within this vertex format definition.
 //               arrays included within this vertex format definition.
 //               The return value is the index number of the new
 //               The return value is the index number of the new
 //               array.
 //               array.
+//
+//               This may not be called once the format has been
+//               registered.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 int qpGeomVertexFormat::
 int qpGeomVertexFormat::
 add_array(qpGeomVertexArrayFormat *array_format) {
 add_array(qpGeomVertexArrayFormat *array_format) {
@@ -155,6 +167,9 @@ add_array(qpGeomVertexArrayFormat *array_format) {
 //       Access: Published
 //       Access: Published
 //  Description: Removes all of the array definitions from the format
 //  Description: Removes all of the array definitions from the format
 //               and starts over.
 //               and starts over.
+//
+//               This may not be called once the format has been
+//               registered.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void qpGeomVertexFormat::
 void qpGeomVertexFormat::
 clear_arrays() {
 clear_arrays() {
@@ -278,6 +293,53 @@ get_data_type(const InternalName *name) const {
   return NULL;
   return NULL;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: qpGeomVertexFormat::remove_data_type
+//       Access: Published
+//  Description: Removes the named data type from the format, from
+//               whichever array it exists in.  If there are other
+//               data types remaining in the array, the array is left
+//               with a gap where the data type used to be; if this
+//               was the only data type in the array, the array is
+//               removed.
+//
+//               This may not be called once the format has been
+//               registered.
+////////////////////////////////////////////////////////////////////
+void qpGeomVertexFormat::
+remove_data_type(const InternalName *name) {
+  nassertv(!_is_registered);
+
+  // Since the format's not registered, it doesn't yet have an index
+  // of data types--so we have to search all of the arrays, one at a
+  // time, until we find it.
+  for (int array = 0; array < (int)_arrays.size(); ++array) {
+    qpGeomVertexArrayFormat *array_format = _arrays[array];
+
+    if (array_format->get_data_type(name) != (qpGeomVertexDataType *)NULL) {
+      // Here's the array with the named data type!
+      if (array_format->is_registered() ||
+          array_format->get_ref_count() > 1) {
+        // Get a safe-to-modify copy of the array format.
+        _arrays[array] = new qpGeomVertexArrayFormat(*array_format);
+        array_format = _arrays[array];
+      }
+
+      array_format->remove_data_type(name);
+
+      // Are there any data types remaining in the array?
+      if (array_format->get_num_data_types() == 0) {
+        // Remove the whole array.
+        remove_array(array);
+      }
+      return;
+    }
+  }
+
+  // It appears that data type wasn't part of the format anyway.  No
+  // problem; quietly return.
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: qpGeomVertexFormat::output
 //     Function: qpGeomVertexFormat::output
 //       Access: Published
 //       Access: Published
@@ -402,8 +464,7 @@ do_register() {
   nassertv(_data_types_by_name.empty());
   nassertv(_data_types_by_name.empty());
   nassertv(_mungers.empty());
   nassertv(_mungers.empty());
 
 
-  int array = 0;
-  for (array = 0; array < (int)_arrays.size(); ++array) {
+  for (int array = 0; array < (int)_arrays.size(); ++array) {
     const qpGeomVertexArrayFormat *array_format = _arrays[array];
     const qpGeomVertexArrayFormat *array_format = _arrays[array];
     if (!array_format->is_registered()) {
     if (!array_format->is_registered()) {
       ((qpGeomVertexArrayFormat *)array_format)->do_register();
       ((qpGeomVertexArrayFormat *)array_format)->do_register();

+ 2 - 0
panda/src/gobj/qpgeomVertexFormat.h

@@ -81,6 +81,8 @@ PUBLISHED:
   int get_array_with(const InternalName *name) const;
   int get_array_with(const InternalName *name) const;
   const qpGeomVertexDataType *get_data_type(const InternalName *name) const;
   const qpGeomVertexDataType *get_data_type(const InternalName *name) const;
 
 
+  void remove_data_type(const InternalName *name);
+
   void output(ostream &out) const;
   void output(ostream &out) const;
   void write(ostream &out, int indent_level = 0) const;
   void write(ostream &out, int indent_level = 0) const;
   void write_with_data(ostream &out, int indent_level, 
   void write_with_data(ostream &out, int indent_level,