28GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::_registry =
nullptr;
34GeomVertexArrayFormat::
35GeomVertexArrayFormat() :
36 _is_registered(false),
41 _columns_unsorted(false)
48GeomVertexArrayFormat::
50 GeomVertexArrayFormat::NumericType numeric_type0,
51 GeomVertexArrayFormat::Contents contents0) :
52 _is_registered(false),
57 _columns_unsorted(false)
59 add_column(move(name0), num_components0, numeric_type0, contents0);
65GeomVertexArrayFormat::
67 GeomVertexArrayFormat::NumericType numeric_type0,
68 GeomVertexArrayFormat::Contents contents0,
70 GeomVertexArrayFormat::NumericType numeric_type1,
71 GeomVertexArrayFormat::Contents contents1) :
72 _is_registered(false),
77 _columns_unsorted(false)
79 add_column(move(name0), num_components0, numeric_type0, contents0);
80 add_column(move(name1), num_components1, numeric_type1, contents1);
86GeomVertexArrayFormat::
88 GeomVertexArrayFormat::NumericType numeric_type0,
89 GeomVertexArrayFormat::Contents contents0,
91 GeomVertexArrayFormat::NumericType numeric_type1,
92 GeomVertexArrayFormat::Contents contents1,
94 GeomVertexArrayFormat::NumericType numeric_type2,
95 GeomVertexArrayFormat::Contents contents2) :
96 _is_registered(false),
101 _columns_unsorted(false)
103 add_column(move(name0), num_components0, numeric_type0, contents0);
104 add_column(move(name1), num_components1, numeric_type1, contents1);
105 add_column(move(name2), num_components2, numeric_type2, contents2);
111GeomVertexArrayFormat::
113 GeomVertexArrayFormat::NumericType numeric_type0,
114 GeomVertexArrayFormat::Contents contents0,
116 GeomVertexArrayFormat::NumericType numeric_type1,
117 GeomVertexArrayFormat::Contents contents1,
119 GeomVertexArrayFormat::NumericType numeric_type2,
120 GeomVertexArrayFormat::Contents contents2,
122 GeomVertexArrayFormat::NumericType numeric_type3,
123 GeomVertexArrayFormat::Contents contents3) :
124 _is_registered(false),
129 _columns_unsorted(false)
131 add_column(move(name0), num_components0, numeric_type0, contents0);
132 add_column(move(name1), num_components1, numeric_type1, contents1);
133 add_column(move(name2), num_components2, numeric_type2, contents2);
134 add_column(move(name3), num_components3, numeric_type3, contents3);
140GeomVertexArrayFormat::
142 _is_registered(false),
143 _stride(copy._stride),
144 _total_bytes(copy._total_bytes),
145 _pad_to(copy._pad_to),
146 _divisor(copy._divisor),
147 _columns_unsorted(copy._columns_unsorted)
149 Columns::const_iterator dti;
150 for (dti = copy._columns.begin(); dti != copy._columns.end(); ++dti) {
158void GeomVertexArrayFormat::
160 nassertv(!_is_registered);
161 _stride = copy._stride;
162 _total_bytes = copy._total_bytes;
163 _pad_to = copy._pad_to;
164 _divisor = copy._divisor;
167 _columns_by_name.clear();
168 _columns_unsorted =
false;
169 Columns::const_iterator dti;
170 for (dti = copy._columns.begin(); dti != copy._columns.end(); ++dti) {
178GeomVertexArrayFormat::
179~GeomVertexArrayFormat() {
183 Columns::iterator ci;
184 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
195 Registry *registry = get_registry();
219 GeomVertexArrayFormat::NumericType numeric_type,
220 GeomVertexArrayFormat::Contents contents,
int start,
221 int column_alignment) {
223 start = _total_bytes;
227 start, column_alignment));
243 nassertr(!_is_registered, -1);
250 while (orig_column !=
nullptr) {
257 _stride = max(_stride, _total_bytes);
259 _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
264 if (!_columns.empty() && *new_column < *_columns.back()) {
265 _columns_unsorted =
true;
268 int new_index = (int)_columns.size();
269 _columns.push_back(new_column);
270 _columns_by_name.insert(ColumnsByName::value_type(new_column->
get_name(), new_column));
281 nassertv(!_is_registered);
282 ColumnsByName::iterator ni;
283 ni = _columns_by_name.find(name);
284 if (ni != _columns_by_name.end()) {
286 _columns_by_name.erase(ni);
288 Columns::iterator ci;
289 ci = find(_columns.begin(), _columns.end(), column);
290 nassertv(ci != _columns.end());
297 if (_columns.empty()) {
300 consider_sort_columns();
313 nassertv(!_is_registered);
316 _columns_by_name.clear();
317 _columns_unsorted =
false;
328 nassertv(!_is_registered);
331 orig_columns.swap(_columns);
334 Columns::const_iterator ci;
335 for (ci = orig_columns.begin(); ci != orig_columns.end(); ++ci) {
352 nassertv(!_is_registered);
355 orig_columns.swap(_columns);
358 Columns::const_iterator ci;
359 for (ci = orig_columns.begin(); ci != orig_columns.end(); ++ci) {
383 ColumnsByName::const_iterator ni;
384 ni = _columns_by_name.find(name);
385 if (ni != _columns_by_name.end()) {
396get_column(
int start_byte,
int num_bytes)
const {
397 consider_sort_columns();
398 Columns::const_iterator ci;
399 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
417 if (_columns.size() > other._columns.size() ||
422 consider_sort_columns();
423 other.consider_sort_columns();
426 while (i < _columns.size() && j < other._columns.size()) {
427 if (*_columns[i] == *other._columns[j]) {
434 return (i == _columns.size());
442 consider_sort_columns();
444 int unused_space = 0;
447 Columns::const_iterator ci;
448 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
451 unused_space += (column->
get_start() - last_pos);
456 if (_stride > last_pos) {
457 unused_space += (_stride - last_pos);
466void GeomVertexArrayFormat::
467output(std::ostream &out)
const {
468 Columns::const_iterator ci;
471 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
474 out <<
" (..." << (column->
get_start() - last_pos) <<
"...)";
476 out <<
" " << *column;
477 last_pos = column->
get_start() + column->get_total_bytes();
480 if (_stride > last_pos) {
481 out <<
" ..." << (_stride - last_pos) <<
"...";
490void GeomVertexArrayFormat::
491write(std::ostream &out,
int indent_level)
const {
493 <<
"Array format (stride = " <<
get_stride() <<
"):\n";
494 consider_sort_columns();
495 Columns::const_iterator ci;
496 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
498 indent(out, indent_level + 2)
502 <<
" start at " << column->
get_start() <<
"\n";
509void GeomVertexArrayFormat::
510write_with_data(std::ostream &out,
int indent_level,
512 consider_sort_columns();
517 for (
int i = 0; i < num_rows; i++) {
519 <<
"row " << i <<
":\n";
520 reader.set_row_unsafe(i);
521 Columns::const_iterator ci;
522 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
525 reader.set_column(0, column);
526 const LVecBase4f &d = reader.get_data4f();
528 indent(out, indent_level + 2)
530 for (
int v = 0; v < num_values; v++) {
545 consider_sort_columns();
555 char *fmt = (
char*) malloc(row_size + 1);
556 memset((
void*) fmt, 0, row_size + 1);
561 if (offset < column->get_start()) {
564 memset((
void*) (fmt + fi),
'x', pad);
615 if (offset < row_size) {
617 int pad = row_size - offset;
618 memset((
void*) (fmt + fi),
'x', pad);
621 std::string fmt_string (fmt);
629int GeomVertexArrayFormat::
631 if (_stride != other._stride) {
632 return _stride - other._stride;
634 if (_total_bytes != other._total_bytes) {
635 return _total_bytes - other._total_bytes;
637 if (_pad_to != other._pad_to) {
638 return _pad_to - other._pad_to;
640 if (_divisor != other._divisor) {
641 return _divisor - other._divisor;
643 if (_columns.size() != other._columns.size()) {
644 return (
int)_columns.size() - (int)other._columns.size();
646 consider_sort_columns();
647 other.consider_sort_columns();
648 for (
size_t i = 0; i < _columns.size(); i++) {
649 int compare = _columns[i]->compare_to(*other._columns[i]);
662void GeomVertexArrayFormat::
670void GeomVertexArrayFormat::
672 if (_registry ==
nullptr) {
673 _registry =
new Registry;
680void GeomVertexArrayFormat::
682 nassertv(!_is_registered);
683 _is_registered =
true;
689void GeomVertexArrayFormat::
691 nassertv(_is_registered);
692 _is_registered =
false;
719 consider_sort_columns();
722 Columns::iterator ci;
723 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
737 Columns::iterator ci;
738 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
757 _columns_by_name.clear();
758 Columns::iterator ci;
759 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
761 _columns_by_name.insert(ColumnsByName::value_type(column->
get_name(), column));
777 object->fillin(scan, manager);
787void GeomVertexArrayFormat::
790 nassertv(!_is_registered);
802 _columns.reserve(num_columns);
803 for (
int i = 0; i < num_columns; ++i) {
805 column->
fillin(scan, manager);
806 _columns.push_back(column);
808 _columns_unsorted =
false;
814GeomVertexArrayFormat::Registry::
842 ArrayFormats::iterator fi = _formats.insert(format).first;
845 new_format->do_register();
858void GeomVertexArrayFormat::Registry::
861 ArrayFormats::iterator fi = _formats.find(format);
862 nassertv(fi != _formats.end());
864 format->do_unregister();
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
A class to retrieve the individual data elements previously stored in a Datagram.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
This is the data for one array of a GeomVertexData structure.
int get_num_rows() const
Returns the number of rows stored in the array, based on the number of bytes and the stride.
This defines how a single column is interleaved within a vertex array stored within a Geom.
int get_num_values() const
Returns the number of numeric values of the column: the number of distinct numeric values that go int...
void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
int get_start() const
Returns the byte within the array record at which this column starts.
NumericType get_numeric_type() const
Returns the token representing the numeric type of the data storage.
void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
int get_column_alignment() const
Returns the alignment requirements for this column.
bool overlaps_with(int start_byte, int num_bytes) const
Returns true if this column overlaps with any of the bytes in the indicated range,...
int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
Contents get_contents() const
Returns the token representing the semantic meaning of the stored value.
int get_total_bytes() const
Returns the number of bytes used by each element of the column: component_bytes * num_components.
int get_num_components() const
Returns the number of components of the column: the number of instances of the NumericType in each el...
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
Encodes a string name in a hash table, mapping it to a pointer.
Similar to MutexHolder, but for a light mutex.
virtual bool unref() const
Explicitly decrements the reference count.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.