27GeomVertexArrayFormat::Registry *GeomVertexArrayFormat::_registry =
nullptr;
33GeomVertexArrayFormat::
34GeomVertexArrayFormat() :
35 _is_registered(false),
40 _columns_unsorted(false)
47GeomVertexArrayFormat::
49 GeomVertexArrayFormat::NumericType numeric_type0,
50 GeomVertexArrayFormat::Contents contents0) :
51 _is_registered(false),
56 _columns_unsorted(false)
58 add_column(std::move(name0), num_components0, numeric_type0, contents0);
64GeomVertexArrayFormat::
66 GeomVertexArrayFormat::NumericType numeric_type0,
67 GeomVertexArrayFormat::Contents contents0,
69 GeomVertexArrayFormat::NumericType numeric_type1,
70 GeomVertexArrayFormat::Contents contents1) :
71 _is_registered(false),
76 _columns_unsorted(false)
78 add_column(std::move(name0), num_components0, numeric_type0, contents0);
79 add_column(std::move(name1), num_components1, numeric_type1, contents1);
85GeomVertexArrayFormat::
87 GeomVertexArrayFormat::NumericType numeric_type0,
88 GeomVertexArrayFormat::Contents contents0,
90 GeomVertexArrayFormat::NumericType numeric_type1,
91 GeomVertexArrayFormat::Contents contents1,
93 GeomVertexArrayFormat::NumericType numeric_type2,
94 GeomVertexArrayFormat::Contents contents2) :
95 _is_registered(false),
100 _columns_unsorted(false)
102 add_column(std::move(name0), num_components0, numeric_type0, contents0);
103 add_column(std::move(name1), num_components1, numeric_type1, contents1);
104 add_column(std::move(name2), num_components2, numeric_type2, contents2);
110GeomVertexArrayFormat::
112 GeomVertexArrayFormat::NumericType numeric_type0,
113 GeomVertexArrayFormat::Contents contents0,
115 GeomVertexArrayFormat::NumericType numeric_type1,
116 GeomVertexArrayFormat::Contents contents1,
118 GeomVertexArrayFormat::NumericType numeric_type2,
119 GeomVertexArrayFormat::Contents contents2,
121 GeomVertexArrayFormat::NumericType numeric_type3,
122 GeomVertexArrayFormat::Contents contents3) :
123 _is_registered(false),
128 _columns_unsorted(false)
130 add_column(std::move(name0), num_components0, numeric_type0, contents0);
131 add_column(std::move(name1), num_components1, numeric_type1, contents1);
132 add_column(std::move(name2), num_components2, numeric_type2, contents2);
133 add_column(std::move(name3), num_components3, numeric_type3, contents3);
139GeomVertexArrayFormat::
141 _is_registered(false),
142 _stride(copy._stride),
143 _total_bytes(copy._total_bytes),
144 _pad_to(copy._pad_to),
145 _divisor(copy._divisor),
146 _columns_unsorted(copy._columns_unsorted)
148 Columns::const_iterator dti;
149 for (dti = copy._columns.begin(); dti != copy._columns.end(); ++dti) {
157void GeomVertexArrayFormat::
159 nassertv(!_is_registered);
160 _stride = copy._stride;
161 _total_bytes = copy._total_bytes;
162 _pad_to = copy._pad_to;
163 _divisor = copy._divisor;
166 _columns_by_name.clear();
167 _columns_unsorted =
false;
168 Columns::const_iterator dti;
169 for (dti = copy._columns.begin(); dti != copy._columns.end(); ++dti) {
177GeomVertexArrayFormat::
178~GeomVertexArrayFormat() {
182 Columns::iterator ci;
183 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
194 Registry *registry = get_registry();
218 GeomVertexArrayFormat::NumericType numeric_type,
219 GeomVertexArrayFormat::Contents contents,
int start,
220 int column_alignment) {
222 start = _total_bytes;
226 start, column_alignment));
242 nassertr(!_is_registered, -1);
249 while (orig_column !=
nullptr) {
256 _stride = max(_stride, _total_bytes);
258 _stride = ((_stride + _pad_to - 1) / _pad_to) * _pad_to;
263 if (!_columns.empty() && *new_column < *_columns.back()) {
264 _columns_unsorted =
true;
267 int new_index = (int)_columns.size();
268 _columns.push_back(new_column);
269 _columns_by_name.insert(ColumnsByName::value_type(new_column->
get_name(), new_column));
280 nassertv(!_is_registered);
281 ColumnsByName::iterator ni;
282 ni = _columns_by_name.find(name);
283 if (ni != _columns_by_name.end()) {
285 _columns_by_name.erase(ni);
287 Columns::iterator ci;
288 ci = find(_columns.begin(), _columns.end(), column);
289 nassertv(ci != _columns.end());
296 if (_columns.empty()) {
299 consider_sort_columns();
312 nassertv(!_is_registered);
315 _columns_by_name.clear();
316 _columns_unsorted =
false;
327 nassertv(!_is_registered);
330 orig_columns.swap(_columns);
333 Columns::const_iterator ci;
334 for (ci = orig_columns.begin(); ci != orig_columns.end(); ++ci) {
351 nassertv(!_is_registered);
354 orig_columns.swap(_columns);
357 Columns::const_iterator ci;
358 for (ci = orig_columns.begin(); ci != orig_columns.end(); ++ci) {
382 ColumnsByName::const_iterator ni;
383 ni = _columns_by_name.find(name);
384 if (ni != _columns_by_name.end()) {
395get_column(
int start_byte,
int num_bytes)
const {
396 consider_sort_columns();
397 Columns::const_iterator ci;
398 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
416 if (_columns.size() > other._columns.size() ||
421 consider_sort_columns();
422 other.consider_sort_columns();
425 while (i < _columns.size() && j < other._columns.size()) {
426 if (*_columns[i] == *other._columns[j]) {
433 return (i == _columns.size());
441 consider_sort_columns();
443 int unused_space = 0;
446 Columns::const_iterator ci;
447 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
450 unused_space += (column->
get_start() - last_pos);
455 if (_stride > last_pos) {
456 unused_space += (_stride - last_pos);
465void GeomVertexArrayFormat::
466output(std::ostream &out)
const {
467 Columns::const_iterator ci;
470 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
473 out <<
" (..." << (column->
get_start() - last_pos) <<
"...)";
475 out <<
" " << *column;
476 last_pos = column->
get_start() + column->get_total_bytes();
479 if (_stride > last_pos) {
480 out <<
" ..." << (_stride - last_pos) <<
"...";
489void GeomVertexArrayFormat::
490write(std::ostream &out,
int indent_level)
const {
492 <<
"Array format (stride = " <<
get_stride() <<
"):\n";
493 consider_sort_columns();
494 Columns::const_iterator ci;
495 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
497 indent(out, indent_level + 2)
501 <<
" start at " << column->
get_start() <<
"\n";
508void GeomVertexArrayFormat::
509write_with_data(std::ostream &out,
int indent_level,
511 consider_sort_columns();
516 for (
int i = 0; i < num_rows; i++) {
518 <<
"row " << i <<
":\n";
519 reader.set_row_unsafe(i);
520 Columns::const_iterator ci;
521 for (ci = _columns.begin(); ci != _columns.end(); ++ci) {
524 reader.set_column(0, column);
525 const LVecBase4f &d = reader.get_data4f();
527 indent(out, indent_level + 2)
529 for (
int v = 0; v < num_values; v++) {
544 consider_sort_columns();
554 char *fmt = (
char *)alloca(row_size + 1);
555 memset((
void *)fmt, 0, row_size + 1);
560 if (offset < column->get_start()) {
563 memset((
void*) (fmt + fi),
'x', pad);
582 case NT_packed_ufloat:
611 memset((
void*) (fmt + fi), fmt_code, num_components);
613 fi += num_components;
616 if (offset < row_size) {
618 int pad = row_size - offset;
619 memset((
void *)(fmt + fi),
'x', pad);
623 return std::string(fmt, (
size_t)fi);
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.
int get_component_bytes() const
Returns the number of bytes used by each component (that is, by one element of the numeric type).
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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.