28 GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::_registry =
nullptr;
29 TypeHandle GeomVertexArrayFormat::_type_handle;
34 GeomVertexArrayFormat::
35 GeomVertexArrayFormat() :
36 _is_registered(false),
41 _columns_unsorted(false)
48 GeomVertexArrayFormat::
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);
65 GeomVertexArrayFormat::
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);
86 GeomVertexArrayFormat::
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);
111 GeomVertexArrayFormat::
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);
140 GeomVertexArrayFormat::
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) {
158 void 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) {
178 GeomVertexArrayFormat::
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()) {
396 get_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);
466 void GeomVertexArrayFormat::
467 output(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) <<
"...";
490 void GeomVertexArrayFormat::
491 write(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";
509 void GeomVertexArrayFormat::
510 write_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);
629 int 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]);
662 void GeomVertexArrayFormat::
670 void GeomVertexArrayFormat::
672 if (_registry ==
nullptr) {
673 _registry =
new Registry;
680 void GeomVertexArrayFormat::
682 nassertv(!_is_registered);
683 _is_registered =
true;
689 void 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);
787 void 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;
814 GeomVertexArrayFormat::Registry::
842 ArrayFormats::iterator fi = _formats.insert(format).first;
845 new_format->do_register();
858 void GeomVertexArrayFormat::Registry::
861 ArrayFormats::iterator fi = _formats.find(format);
862 nassertv(fi != _formats.end());
864 format->do_unregister();
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
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,...
Contents get_contents() const
Returns the token representing the semantic meaning of the stored value.
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
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...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
NumericType get_numeric_type() const
Returns the token representing the numeric type of the data storage.
Base class for objects that can be written to and read from Bam files.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
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_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
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...
This defines how a single column is interleaved within a vertex array stored within a Geom.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
An STL function object class, this is intended to be used on any ordered collection of pointers to cl...
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Similar to MutexHolder, but for a light mutex.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
int get_num_values() const
Returns the number of numeric values of the column: the number of distinct numeric values that go int...
int get_column_alignment() const
Returns the alignment requirements for this column.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
void register_finalize(TypedWritable *whom)
Should be called by an object reading itself from the Bam file to indicate that this particular objec...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Encodes a string name in a hash table, mapping it to a pointer.
int get_start() const
Returns the byte within the array record at which this column starts.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_num_rows() const
Returns the number of rows stored in the array, based on the number of bytes and the stride.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
A class to retrieve the individual data elements previously stored in a Datagram.
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
int get_total_bytes() const
Returns the number of bytes used by each element of the column: component_bytes * num_components.
TypeHandle is the identifier used to differentiate C++ class types.
int get_num_components() const
Returns the number of components of the column: the number of instances of the NumericType in each el...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool unref() const
Explicitly decrements the reference count.
This is the data for one array of a GeomVertexData structure.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.