diff --git a/panda/src/gobj/geomVertexColumn.I b/panda/src/gobj/geomVertexColumn.I index b7d585f092..e74e47d7d2 100644 --- a/panda/src/gobj/geomVertexColumn.I +++ b/panda/src/gobj/geomVertexColumn.I @@ -16,7 +16,7 @@ //////////////////////////////////////////////////////////////////// // Function: GeomVertexColumn::Default Constructor // Access: Private -// Description: Creates an invalid column. Used on when constructing +// Description: Creates an invalid column. Used only when constructing // from a bam file. //////////////////////////////////////////////////////////////////// INLINE GeomVertexColumn:: diff --git a/panda/src/gobj/geomVertexColumn.cxx b/panda/src/gobj/geomVertexColumn.cxx index 5668dd7b98..0c272ad477 100644 --- a/panda/src/gobj/geomVertexColumn.cxx +++ b/panda/src/gobj/geomVertexColumn.cxx @@ -31,9 +31,84 @@ operator = (const GeomVertexColumn ©) { _start = copy._start; _column_alignment = copy._column_alignment; - delete _packer; - _packer = NULL; + setup(); +} +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_name +// Access: Published +// Description: Replaces the name of an existing column. This is +// only legal on an unregistered format (i.e. when +// constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_name(InternalName *name) { + _name = name; + setup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_num_components +// Access: Published +// Description: Changes the number of components of an existing +// column. This is only legal on an unregistered format +// (i.e. when constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_num_components(int num_components) { + _num_components = num_components; + setup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_numeric_type +// Access: Published +// Description: Changes the numeric type an existing column. This is +// only legal on an unregistered format (i.e. when +// constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_numeric_type(NumericType numeric_type) { + _numeric_type = numeric_type; + setup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_contents +// Access: Published +// Description: Changes the semantic meaning of an existing column. +// This is only legal on an unregistered format +// (i.e. when constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_contents(Contents contents) { + _contents = contents; + setup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_start +// Access: Published +// Description: Changes the start byte of an existing column. +// This is only legal on an unregistered format +// (i.e. when constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_start(int start) { + _start = start; + setup(); +} + +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexColumn::set_column_alignment +// Access: Published +// Description: Changes the column alignment of an existing column. +// This is only legal on an unregistered format +// (i.e. when constructing the format initially). +//////////////////////////////////////////////////////////////////// +void GeomVertexColumn:: +set_column_alignment(int column_alignment) { + _column_alignment = column_alignment; setup(); } @@ -146,6 +221,10 @@ setup() { _total_bytes = _component_bytes * _num_components; + if (_packer != NULL) { + delete _packer; + } + _packer = make_packer(); _packer->_column = this; } diff --git a/panda/src/gobj/geomVertexColumn.h b/panda/src/gobj/geomVertexColumn.h index 1794ab3d9a..09510a3e89 100644 --- a/panda/src/gobj/geomVertexColumn.h +++ b/panda/src/gobj/geomVertexColumn.h @@ -63,6 +63,13 @@ PUBLISHED: INLINE bool overlaps_with(int start_byte, int num_bytes) const; INLINE bool is_bytewise_equivalent(const GeomVertexColumn &other) const; + void set_name(InternalName *name); + void set_num_components(int num_components); + void set_numeric_type(NumericType numeric_type); + void set_contents(Contents contents); + void set_start(int start); + void set_column_alignment(int column_alignment); + void output(ostream &out) const; public: diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index 0da6a17266..b2fee3e7c0 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -331,6 +331,48 @@ set_format(const GeomVertexFormat *format) { cdataw->_animated_vertices.clear(); } +//////////////////////////////////////////////////////////////////// +// Function: GeomVertexData::unclean_set_format +// Access: Published +// Description: Changes the format of the vertex data, without +// reformatting the data to match. The data is exactly +// the same after this operation, but will be +// reinterpreted according to the new format. This +// assumes that the new format is fundamentally +// compatible with the old format; in particular, it +// must have the same number of arrays with the same +// stride in each one. No checking is performed that +// the data remains sensible. +//////////////////////////////////////////////////////////////////// +void GeomVertexData:: +unclean_set_format(const GeomVertexFormat *format) { + Thread *current_thread = Thread::get_current_thread(); + nassertv(format->is_registered()); + + CDLockedReader cdata(_cycler, current_thread); + + if (format == cdata->_format) { + // Trivially no-op. + return; + } + +#ifndef NDEBUG + nassertv(format->get_num_arrays() == cdata->_format->get_num_arrays()); + for (int ai = 0; ai < format->get_num_arrays(); ++ai) { + nassertv(format->get_array(ai)->get_stride() == cdata->_format->get_array(ai)->get_stride()); + } +#endif // NDEBUG + + CDWriter cdataw(_cycler, cdata, true); + + // Assign the new format. + cdataw->_format = format; + + clear_cache_stage(); + cdataw->_modified = Geom::get_next_modified(); + cdataw->_animated_vertices.clear(); +} + //////////////////////////////////////////////////////////////////// // Function: GeomVertexData::clear_rows // Access: Published diff --git a/panda/src/gobj/geomVertexData.h b/panda/src/gobj/geomVertexData.h index 335e834e84..152446878d 100644 --- a/panda/src/gobj/geomVertexData.h +++ b/panda/src/gobj/geomVertexData.h @@ -100,6 +100,7 @@ PUBLISHED: INLINE const GeomVertexFormat *get_format() const; void set_format(const GeomVertexFormat *format); + void unclean_set_format(const GeomVertexFormat *format); INLINE bool has_column(const InternalName *name) const;