GeomVertexData::unclean_set_format() and related methods

This commit is contained in:
David Rose 2013-01-08 00:19:35 +00:00
parent 6d835868c1
commit 8dff4f69e5
5 changed files with 132 additions and 3 deletions

View File

@ -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::

View File

@ -31,9 +31,84 @@ operator = (const GeomVertexColumn &copy) {
_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;
}

View File

@ -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:

View File

@ -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

View File

@ -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;