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();