Panda3D

geomVertexColumn.cxx
Go to the documentation of this file.
1 /**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file geomVertexColumn.cxx
10 * @author drose
11 * @date 2005-03-06
12 */
13
14 #include "geomVertexColumn.h"
15 #include "geomVertexData.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18
19 using std::max;
20 using std::min;
21
22 /**
23 *
24 */
25 void GeomVertexColumn::
26 operator = (const GeomVertexColumn &copy) {
27 _name = copy._name;
28 _num_components = copy._num_components;
29 _numeric_type = copy._numeric_type;
30 _contents = copy._contents;
31 _start = copy._start;
32 _column_alignment = copy._column_alignment;
33 _num_elements = copy._num_elements;
34 _element_stride = copy._element_stride;
35
36 setup();
37 }
38
39 /**
40 * Replaces the name of an existing column. This is only legal on an
41 * unregistered format (i.e. when constructing the format initially).
42 */
43 void GeomVertexColumn::
44 set_name(InternalName *name) {
45 _name = name;
46 setup();
47 }
48
49 /**
50 * Changes the number of components of an existing column. This is only legal
51 * on an unregistered format (i.e. when constructing the format initially).
52 */
53 void GeomVertexColumn::
54 set_num_components(int num_components) {
55 _num_components = num_components;
56 setup();
57 }
58
59 /**
60 * Changes the numeric type an existing column. This is only legal on an
61 * unregistered format (i.e. when constructing the format initially).
62 */
63 void GeomVertexColumn::
64 set_numeric_type(NumericType numeric_type) {
65 _numeric_type = numeric_type;
66 setup();
67 }
68
69 /**
70 * Changes the semantic meaning of an existing column. This is only legal on
71 * an unregistered format (i.e. when constructing the format initially).
72 */
73 void GeomVertexColumn::
74 set_contents(Contents contents) {
75 _contents = contents;
76 setup();
77 }
78
79 /**
80 * Changes the start byte of an existing column. This is only legal on an
81 * unregistered format (i.e. when constructing the format initially).
82 */
83 void GeomVertexColumn::
84 set_start(int start) {
85 _start = start;
86 setup();
87 }
88
89 /**
90 * Changes the column alignment of an existing column. This is only legal on
91 * an unregistered format (i.e. when constructing the format initially).
92 */
93 void GeomVertexColumn::
94 set_column_alignment(int column_alignment) {
95 _column_alignment = column_alignment;
96 setup();
97 }
98
99 /**
100 *
101 */
102 void GeomVertexColumn::
103 output(std::ostream &out) const {
104 out << *get_name() << "(" << get_num_components();
105 switch (get_numeric_type()) {
106 case NT_uint8:
107 case NT_int8:
108 out << "b";
109 break;
110
111 case NT_uint16:
112 case NT_int16:
113 out << "s";
114 break;
115
116 case NT_uint32:
117 case NT_int32:
118 out << "l";
119 break;
120
121 case NT_packed_dcba:
122 out << "p-";
123 break;
124
125 case NT_packed_dabc:
126 out << "p";
127 break;
128
129 case NT_float32:
130 out << "f";
131 break;
132
133 case NT_float64:
134 out << "d";
135 break;
136
137 case NT_stdfloat:
138 case NT_packed_ufloat:
139 out << "?";
140 break;
141 }
142
143 out << ")";
144
145 if (_num_elements > 1) {
146 out << "[" << _num_elements << "]";
147 }
148 }
149
150 /**
151 * Called once at construction time (or at bam-reading time) to initialize the
152 * internal dependent values.
153 */
154 void GeomVertexColumn::
155 setup() {
156 nassertv(_num_components > 0 && _start >= 0);
157
158 _num_values = _num_components;
159
160 if (_numeric_type == NT_stdfloat) {
161 if (vertices_float64) {
162 _numeric_type = NT_float64;
163 } else {
164 _numeric_type = NT_float32;
165 }
166 }
167
168 switch (_numeric_type) {
169 case NT_uint16:
170 case NT_int16:
171 _component_bytes = 2; // sizeof(uint16_t)
172 break;
173
174 case NT_uint32:
175 case NT_int32:
176 _component_bytes = 4; // sizeof(uint32_t)
177 break;
178
179 case NT_uint8:
180 case NT_int8:
181 _component_bytes = 1;
182 break;
183
184 case NT_packed_dcba:
185 case NT_packed_dabc:
186 _component_bytes = 4; // sizeof(uint32_t)
187 _num_values *= 4;
188 break;
189
190 case NT_float32:
191 _component_bytes = 4; // sizeof(PN_float32)
192 break;
193
194 case NT_float64:
195 _component_bytes = 8; // sizeof(PN_float64)
196 break;
197
198 case NT_stdfloat:
199 nassertv(false);
200 break;
201
202 case NT_packed_ufloat:
203 _component_bytes = 4; // sizeof(uint32_t)
204 _num_values *= 3;
205 break;
206 }
207
208 if (_num_elements == 0) {
209 // Matrices are assumed to be square.
210 if (_contents == C_matrix) {
211 _num_elements = _num_components;
212 } else {
213 _num_elements = 1;
214 }
215 }
216
217 if (_column_alignment < 1) {
218 // The default column alignment is to align to the individual numeric
219 // components, or to vertex_column_alignment, whichever is greater.
220 _column_alignment = max(_component_bytes, (int)vertex_column_alignment);
221 }
222
223 // Enforce the column alignment requirements on the _start byte.
224 _start = ((_start + _column_alignment - 1) / _column_alignment) * _column_alignment;
225
226 if (_element_stride < 1) {
227 _element_stride = _component_bytes * _num_components;
228 }
229 _total_bytes = _element_stride * _num_elements;
230
231 if (_packer != nullptr) {
232 delete _packer;
233 }
234
235 _packer = make_packer();
236 _packer->_column = this;
237 }
238
239 /**
240 * Returns a newly-allocated Packer object suitable for packing and unpacking
241 * this column. The _column member of the packer is not filled in.
242 */
243 GeomVertexColumn::Packer *GeomVertexColumn::
244 make_packer() const {
245 switch (get_contents()) {
246 case C_point:
247 case C_clip_point:
248 case C_texcoord:
249 // These types are read as a 4-d homogeneous point.
250 switch (get_numeric_type()) {
251 case NT_float32:
252 if (sizeof(float) == sizeof(PN_float32)) {
253 // Use the native float type implementation for a tiny bit more
254 // optimization.
255 switch (get_num_components()) {
256 case 2:
257 return new Packer_point_nativefloat_2;
258 case 3:
259 return new Packer_point_nativefloat_3;
260 case 4:
261 // Reader may assume 16-byte alignment.
262 if ((get_start() & 0xf) == 0) {
263 return new Packer_point_nativefloat_4;
264 } else {
265 return new Packer_point_float32_4;
266 }
267 }
268 } else {
269 switch (get_num_components()) {
270 case 2:
271 return new Packer_point_float32_2;
272 case 3:
273 return new Packer_point_float32_3;
274 case 4:
275 return new Packer_point_float32_4;
276 }
277 }
278 break;
279 case NT_float64:
280 if (sizeof(double) == sizeof(PN_float64)) {
281 // Use the native float type implementation for a tiny bit more
282 // optimization.
283 switch (get_num_components()) {
284 case 2:
285 return new Packer_point_nativedouble_2;
286 case 3:
287 return new Packer_point_nativedouble_3;
288 case 4:
289 return new Packer_point_nativedouble_4;
290 }
291 } else {
292 switch (get_num_components()) {
293 case 2:
294 return new Packer_point_float64_2;
295 case 3:
296 return new Packer_point_float64_3;
297 case 4:
298 return new Packer_point_float64_4;
299 }
300 }
301 break;
302 default:
303 break;
304 }
305 return new Packer_point;
306
307 case C_color:
308 if (get_num_values() == 4) {
309 switch (get_numeric_type()) {
310 case NT_uint8:
311 return new Packer_rgba_uint8_4;
312
313 case NT_packed_dabc:
314 return new Packer_argb_packed;
315
316 case NT_float32:
317 if (sizeof(float) == sizeof(PN_float32) &&
318 (get_start() & 0xf) == 0) {
319 // Use the native float type implementation for a tiny bit more
320 // optimization.
321 return new Packer_rgba_nativefloat_4;
322 } else {
323 return new Packer_rgba_float32_4;
324 }
325
326 default:
327 break;
328 }
329 } else if (get_num_values() != 3) {
330 gobj_cat.error()
331 << "GeomVertexColumn with contents C_color must have 3 or 4 components!\n";
332 }
333 return new Packer_color;
334
335 case C_normal:
336 if (get_num_values() != 3 && get_num_values() != 4) {
337 gobj_cat.error()
338 << "GeomVertexColumn with contents C_normal must have 3 or 4 components!\n";
339 }
340
341 default:
342 // Otherwise, we just read it as a generic value.
343 switch (get_numeric_type()) {
344 case NT_float32:
345 switch (get_num_components()) {
346 case 3:
347 if (sizeof(float) == sizeof(PN_float32)) {
348 // Use the native float type implementation for a tiny bit more
349 // optimization.
350 return new Packer_nativefloat_3;
351 } else {
352 return new Packer_float32_3;
353 }
354
355 default:
356 break;
357 }
358 break;
359 case NT_float64:
360 switch (get_num_components()) {
361 case 3:
362 if (sizeof(double) == sizeof(PN_float64)) {
363 // Use the native float type implementation for a tiny bit more
364 // optimization.
365 return new Packer_nativedouble_3;
366 } else {
367 return new Packer_float64_3;
368 }
369
370 default:
371 break;
372 }
373 break;
374 default:
375 break;
376 }
377 return new Packer;
378 }
379 }
380
381 /**
382 * Writes the contents of this object to the datagram for shipping out to a
383 * Bam file.
384 */
385 void GeomVertexColumn::
386 write_datagram(BamWriter *manager, Datagram &dg) {
387 manager->write_pointer(dg, _name);
388 dg.add_uint8(_num_components);
389 dg.add_uint8(_numeric_type);
390
391 if (_contents == C_normal && manager->get_file_minor_ver() < 38) {
392 // Panda 1.9 did not have C_normal.
393 dg.add_uint8(C_vector);
394 } else {
395 dg.add_uint8(_contents);
396 }
397
398 dg.add_uint16(_start);
399
400 if (manager->get_file_minor_ver() >= 29) {
401 dg.add_uint8(_column_alignment);
402 }
403 }
404
405 /**
406 * Receives an array of pointers, one for each time manager->read_pointer()
407 * was called in fillin(). Returns the number of pointers processed.
408 */
409 int GeomVertexColumn::
410 complete_pointers(TypedWritable **p_list, BamReader *manager) {
411 int pi = 0;
412
413 _name = DCAST(InternalName, p_list[pi++]);
414
415 // Make sure that old .bam files are corrected to have C_normal normal
416 // columns rather than C_vector.
417 if (manager->get_file_minor_ver() < 38 &&
418 _name == InternalName::get_normal() && _contents == C_vector) {
419 _contents = C_normal;
420 }
421
422 return pi;
423 }
424
425 /**
426 * This internal function is called by make_from_bam to read in all of the
427 * relevant data from the BamFile for the new GeomVertexColumn.
428 */
429 void GeomVertexColumn::
430 fillin(DatagramIterator &scan, BamReader *manager) {
431 manager->read_pointer(scan);
432
433 _num_components = scan.get_uint8();
434 _numeric_type = (NumericType)scan.get_uint8();
435 _contents = (Contents)scan.get_uint8();
436 _start = scan.get_uint16();
437
438 _column_alignment = 1;
439 if (manager->get_file_minor_ver() >= 29) {
440 _column_alignment = scan.get_uint8();
441 }
442
443 _num_elements = 0;
444 _element_stride = 0;
445
446 setup();
447 }
448
449 /**
450 *
451 */
452 GeomVertexColumn::Packer::
453 ~Packer() {
454 }
455
456 /**
457 *
458 */
459 float GeomVertexColumn::Packer::
460 get_data1f(const unsigned char *pointer) {
461 switch (_column->get_numeric_type()) {
462 case NT_uint8:
463 return *(const uint8_t *)pointer;
464
465 case NT_uint16:
466 return *(const uint16_t *)pointer;
467
468 case NT_uint32:
469 return *(const uint32_t *)pointer;
470
471 case NT_packed_dcba:
472 {
473 uint32_t dword = *(const uint32_t *)pointer;
474 return GeomVertexData::unpack_abcd_d(dword);
475 }
476
477 case NT_packed_dabc:
478 {
479 uint32_t dword = *(const uint32_t *)pointer;
480 return GeomVertexData::unpack_abcd_b(dword);
481 }
482
483 case NT_float32:
484 return *(const PN_float32 *)pointer;
485
486 case NT_float64:
487 return *(const PN_float64 *)pointer;
488
489 case NT_int8:
490 return *(const int8_t *)pointer;
491
492 case NT_int16:
493 return *(const int16_t *)pointer;
494
495 case NT_int32:
496 return *(const int32_t *)pointer;
497
498 case NT_packed_ufloat:
499 {
500 uint32_t dword = *(const uint32_t *)pointer;
501 return GeomVertexData::unpack_ufloat_a(dword);
502 }
503
504 default:
505 nassertr(false, 0.0f);
506 }
507
508 return 0.0f;
509 }
510
511 /**
512 *
513 */
514 const LVecBase2f &GeomVertexColumn::Packer::
515 get_data2f(const unsigned char *pointer) {
516 if (_column->get_num_values() == 1) {
517 _v2.set(get_data1f(pointer), 0.0f);
518 return _v2;
519
520 } else {
521 switch (_column->get_numeric_type()) {
522 case NT_uint8:
523 {
524 const uint8_t *pi = (const uint8_t *)pointer;
525 _v2.set(pi[0], pi[1]);
526 }
527 return _v2;
528
529 case NT_uint16:
530 {
531 const uint16_t *pi = (const uint16_t *)pointer;
532 _v2.set(pi[0], pi[1]);
533 }
534 return _v2;
535
536 case NT_uint32:
537 {
538 const uint32_t *pi = (const uint32_t *)pointer;
539 _v2.set(pi[0], pi[1]);
540 }
541 return _v2;
542
543 case NT_packed_dcba:
544 {
545 uint32_t dword = *(const uint32_t *)pointer;
546 _v2.set(GeomVertexData::unpack_abcd_d(dword),
547 GeomVertexData::unpack_abcd_c(dword));
548 }
549 return _v2;
550
551 case NT_packed_dabc:
552 {
553 uint32_t dword = *(const uint32_t *)pointer;
554 _v2.set(GeomVertexData::unpack_abcd_b(dword),
555 GeomVertexData::unpack_abcd_c(dword));
556 }
557 return _v2;
558
559 case NT_float32:
560 {
561 const PN_float32 *pi = (const PN_float32 *)pointer;
562 _v2.set(pi[0], pi[1]);
563 }
564 return _v2;
565
566 case NT_float64:
567 {
568 const PN_float64 *pi = (const PN_float64 *)pointer;
569 _v2.set(pi[0], pi[1]);
570 }
571 return _v2;
572
573 case NT_stdfloat:
574 nassertr(false, _v2);
575 return _v2;
576
577 case NT_int8:
578 {
579 const int8_t *pi = (const int8_t *)pointer;
580 _v2.set(pi[0], pi[1]);
581 }
582 return _v2;
583
584 case NT_int16:
585 {
586 const int16_t *pi = (const int16_t *)pointer;
587 _v2.set(pi[0], pi[1]);
588 }
589 return _v2;
590
591 case NT_int32:
592 {
593 const int32_t *pi = (const int32_t *)pointer;
594 _v2.set(pi[0], pi[1]);
595 }
596 return _v2;
597
598 case NT_packed_ufloat:
599 nassertr(false, _v2);
600 return _v2;
601 }
602 }
603
604 return _v2;
605 }
606
607 /**
608 *
609 */
610 const LVecBase3f &GeomVertexColumn::Packer::
611 get_data3f(const unsigned char *pointer) {
612 switch (_column->get_num_values()) {
613 case 1:
614 _v3.set(get_data1f(pointer), 0.0f, 0.0f);
615 return _v3;
616
617 case 2:
618 {
619 const LVecBase2f &v2 = get_data2f(pointer);
620 _v3.set(v2[0], v2[1], 0.0f);
621 }
622 return _v3;
623
624 default:
625 switch (_column->get_numeric_type()) {
626 case NT_uint8:
627 {
628 const uint8_t *pi = (const uint8_t *)pointer;
629 _v3.set(pi[0], pi[1], pi[2]);
630 }
631 return _v3;
632
633 case NT_uint16:
634 {
635 const uint16_t *pi = (const uint16_t *)pointer;
636 _v3.set(pi[0], pi[1], pi[2]);
637 }
638 return _v3;
639
640 case NT_uint32:
641 {
642 const uint32_t *pi = (const uint32_t *)pointer;
643 _v3.set(pi[0], pi[1], pi[2]);
644 }
645 return _v3;
646
647 case NT_packed_dcba:
648 {
649 uint32_t dword = *(const uint32_t *)pointer;
650 _v3.set(GeomVertexData::unpack_abcd_d(dword),
651 GeomVertexData::unpack_abcd_c(dword),
652 GeomVertexData::unpack_abcd_b(dword));
653 }
654 return _v3;
655
656 case NT_packed_dabc:
657 {
658 uint32_t dword = *(const uint32_t *)pointer;
659 _v3.set(GeomVertexData::unpack_abcd_b(dword),
660 GeomVertexData::unpack_abcd_c(dword),
661 GeomVertexData::unpack_abcd_d(dword));
662 }
663 return _v3;
664
665 case NT_float32:
666 {
667 const PN_float32 *pi = (const PN_float32 *)pointer;
668 _v3.set(pi[0], pi[1], pi[2]);
669 }
670 return _v3;
671
672 case NT_float64:
673 {
674 const PN_float64 *pi = (const PN_float64 *)pointer;
675 _v3.set(pi[0], pi[1], pi[2]);
676 }
677 return _v3;
678
679 case NT_stdfloat:
680 nassertr(false, _v3);
681 return _v3;
682
683 case NT_int8:
684 {
685 const int8_t *pi = (const int8_t *)pointer;
686 _v3.set(pi[0], pi[1], pi[2]);
687 }
688 return _v3;
689
690 case NT_int16:
691 {
692 const int16_t *pi = (const int16_t *)pointer;
693 _v3.set(pi[0], pi[1], pi[2]);
694 }
695 return _v3;
696
697 case NT_int32:
698 {
699 const int32_t *pi = (const int32_t *)pointer;
700 _v3.set(pi[0], pi[1], pi[2]);
701 }
702 return _v3;
703
704 case NT_packed_ufloat:
705 {
706 uint32_t dword = *(const uint32_t *)pointer;
707 _v3.set(GeomVertexData::unpack_ufloat_a(dword),
708 GeomVertexData::unpack_ufloat_b(dword),
709 GeomVertexData::unpack_ufloat_c(dword));
710 }
711 return _v3;
712 }
713 }
714
715 return _v3;
716 }
717
718 /**
719 *
720 */
721 const LVecBase4f &GeomVertexColumn::Packer::
722 get_data4f(const unsigned char *pointer) {
723 switch (_column->get_num_values()) {
724 case 1:
725 _v4.set(get_data1f(pointer), 0.0f, 0.0f, 0.0f);
726 return _v4;
727
728 case 2:
729 {
730 const LVecBase2f &v2 = get_data2f(pointer);
731 _v4.set(v2[0], v2[1], 0.0f, 0.0f);
732 }
733 return _v4;
734
735 case 3:
736 {
737 const LVecBase3f &v3 = get_data3f(pointer);
738 _v4.set(v3[0], v3[1], v3[2], 0.0f);
739 }
740 return _v4;
741
742 default:
743 switch (_column->get_numeric_type()) {
744 case NT_uint8:
745 {
746 const uint8_t *pi = (const uint8_t *)pointer;
747 _v4.set(pi[0], pi[1], pi[2], pi[3]);
748 }
749 return _v4;
750
751 case NT_uint16:
752 {
753 const uint16_t *pi = (const uint16_t *)pointer;
754 _v4.set(pi[0], pi[1], pi[2], pi[3]);
755 }
756 return _v4;
757
758 case NT_uint32:
759 {
760 const uint32_t *pi = (const uint32_t *)pointer;
761 _v4.set(pi[0], pi[1], pi[2], pi[3]);
762 }
763 return _v4;
764
765 case NT_packed_dcba:
766 {
767 uint32_t dword = *(const uint32_t *)pointer;
768 _v4.set(GeomVertexData::unpack_abcd_d(dword),
769 GeomVertexData::unpack_abcd_c(dword),
770 GeomVertexData::unpack_abcd_b(dword),
771 GeomVertexData::unpack_abcd_a(dword));
772 }
773 return _v4;
774
775 case NT_packed_dabc:
776 {
777 uint32_t dword = *(const uint32_t *)pointer;
778 _v4.set(GeomVertexData::unpack_abcd_b(dword),
779 GeomVertexData::unpack_abcd_c(dword),
780 GeomVertexData::unpack_abcd_d(dword),
781 GeomVertexData::unpack_abcd_a(dword));
782 }
783 return _v4;
784
785 case NT_float32:
786 {
787 const PN_float32 *pi = (const PN_float32 *)pointer;
788 _v4.set(pi[0], pi[1], pi[2], pi[3]);
789 }
790 return _v4;
791
792 case NT_float64:
793 {
794 const PN_float64 *pi = (const PN_float64 *)pointer;
795 _v4.set(pi[0], pi[1], pi[2], pi[3]);
796 }
797 return _v4;
798
799 case NT_stdfloat:
800 nassertr(false, _v4);
801 break;
802
803 case NT_int8:
804 {
805 const int8_t *pi = (const int8_t *)pointer;
806 _v4.set(pi[0], pi[1], pi[2], pi[3]);
807 }
808 return _v4;
809
810 case NT_int16:
811 {
812 const int16_t *pi = (const int16_t *)pointer;
813 _v4.set(pi[0], pi[1], pi[2], pi[3]);
814 }
815 return _v4;
816
817 case NT_int32:
818 {
819 const int32_t *pi = (const int32_t *)pointer;
820 _v4.set(pi[0], pi[1], pi[2], pi[3]);
821 }
822 return _v4;
823
824 case NT_packed_ufloat:
825 nassertr(false, _v4);
826 break;
827 }
828 }
829
830 return _v4;
831 }
832
833 /**
834 *
835 */
836 double GeomVertexColumn::Packer::
837 get_data1d(const unsigned char *pointer) {
838 switch (_column->get_numeric_type()) {
839 case NT_uint8:
840 return *(const uint8_t *)pointer;
841
842 case NT_uint16:
843 return *(const uint16_t *)pointer;
844
845 case NT_uint32:
846 return *(const uint32_t *)pointer;
847
848 case NT_packed_dcba:
849 {
850 uint32_t dword = *(const uint32_t *)pointer;
851 return GeomVertexData::unpack_abcd_d(dword);
852 }
853
854 case NT_packed_dabc:
855 {
856 uint32_t dword = *(const uint32_t *)pointer;
857 return GeomVertexData::unpack_abcd_b(dword);
858 }
859
860 case NT_float32:
861 return *(const PN_float32 *)pointer;
862
863 case NT_float64:
864 return *(const PN_float64 *)pointer;
865
866 case NT_stdfloat:
867 nassertr(false, 0.0);
868 return 0.0;
869
870 case NT_int8:
871 return *(const int8_t *)pointer;
872
873 case NT_int16:
874 return *(const int16_t *)pointer;
875
876 case NT_int32:
877 return *(const int32_t *)pointer;
878
879 case NT_packed_ufloat:
880 {
881 uint32_t dword = *(const uint32_t *)pointer;
882 return GeomVertexData::unpack_ufloat_a(dword);
883 }
884 }
885
886 return 0.0;
887 }
888
889 /**
890 *
891 */
892 const LVecBase2d &GeomVertexColumn::Packer::
893 get_data2d(const unsigned char *pointer) {
894 if (_column->get_num_values() == 1) {
895 _v2d.set(get_data1d(pointer), 0.0f);
896 return _v2d;
897
898 } else {
899 switch (_column->get_numeric_type()) {
900 case NT_uint8:
901 {
902 const uint8_t *pi = (const uint8_t *)pointer;
903 _v2d.set(pi[0], pi[1]);
904 }
905 return _v2d;
906
907 case NT_uint16:
908 {
909 const uint16_t *pi = (const uint16_t *)pointer;
910 _v2d.set(pi[0], pi[1]);
911 }
912 return _v2d;
913
914 case NT_uint32:
915 {
916 const uint32_t *pi = (const uint32_t *)pointer;
917 _v2d.set(pi[0], pi[1]);
918 }
919 return _v2d;
920
921 case NT_packed_dcba:
922 {
923 uint32_t dword = *(const uint32_t *)pointer;
924 _v2d.set(GeomVertexData::unpack_abcd_d(dword),
925 GeomVertexData::unpack_abcd_c(dword));
926 }
927 return _v2d;
928
929 case NT_packed_dabc:
930 {
931 uint32_t dword = *(const uint32_t *)pointer;
932 _v2d.set(GeomVertexData::unpack_abcd_b(dword),
933 GeomVertexData::unpack_abcd_c(dword));
934 }
935 return _v2d;
936
937 case NT_float32:
938 {
939 const PN_float32 *pi = (const PN_float32 *)pointer;
940 _v2d.set(pi[0], pi[1]);
941 }
942 return _v2d;
943
944 case NT_float64:
945 {
946 const PN_float64 *pi = (const PN_float64 *)pointer;
947 _v2d.set(pi[0], pi[1]);
948 }
949 return _v2d;
950
951 case NT_stdfloat:
952 nassertr(false, _v2d);
953 return _v2d;
954
955 case NT_int8:
956 {
957 const int8_t *pi = (const int8_t *)pointer;
958 _v2d.set(pi[0], pi[1]);
959 }
960 return _v2d;
961
962 case NT_int16:
963 {
964 const int16_t *pi = (const int16_t *)pointer;
965 _v2d.set(pi[0], pi[1]);
966 }
967 return _v2d;
968
969 case NT_int32:
970 {
971 const int32_t *pi = (const int32_t *)pointer;
972 _v2d.set(pi[0], pi[1]);
973 }
974 return _v2d;
975
976 case NT_packed_ufloat:
977 nassertr(false, _v2d);
978 break;
979 }
980 }
981
982 return _v2d;
983 }
984
985 /**
986 *
987 */
988 const LVecBase3d &GeomVertexColumn::Packer::
989 get_data3d(const unsigned char *pointer) {
990 switch (_column->get_num_values()) {
991 case 1:
992 _v3d.set(get_data1d(pointer), 0.0f, 0.0f);
993 return _v3d;
994
995 case 2:
996 {
997 const LVecBase2d &v2 = get_data2d(pointer);
998 _v3d.set(v2[0], v2[1], 0.0f);
999 }
1000 return _v3d;
1001
1002 default:
1003 switch (_column->get_numeric_type()) {
1004 case NT_uint8:
1005 {
1006 const uint8_t *pi = (const uint8_t *)pointer;
1007 _v3d.set(pi[0], pi[1], pi[2]);
1008 }
1009 return _v3d;
1010
1011 case NT_uint16:
1012 {
1013 const uint16_t *pi = (const uint16_t *)pointer;
1014 _v3d.set(pi[0], pi[1], pi[2]);
1015 }
1016 return _v3d;
1017
1018 case NT_uint32:
1019 {
1020 const uint32_t *pi = (const uint32_t *)pointer;
1021 _v3d.set(pi[0], pi[1], pi[2]);
1022 }
1023 return _v3d;
1024
1025 case NT_packed_dcba:
1026 {
1027 uint32_t dword = *(const uint32_t *)pointer;
1028 _v3d.set(GeomVertexData::unpack_abcd_d(dword),
1029 GeomVertexData::unpack_abcd_c(dword),
1030 GeomVertexData::unpack_abcd_b(dword));
1031 }
1032 return _v3d;
1033
1034 case NT_packed_dabc:
1035 {
1036 uint32_t dword = *(const uint32_t *)pointer;
1037 _v3d.set(GeomVertexData::unpack_abcd_b(dword),
1038 GeomVertexData::unpack_abcd_c(dword),
1039 GeomVertexData::unpack_abcd_d(dword));
1040 }
1041 return _v3d;
1042
1043 case NT_float32:
1044 {
1045 const PN_float32 *pi = (const PN_float32 *)pointer;
1046 _v3d.set(pi[0], pi[1], pi[2]);
1047 }
1048 return _v3d;
1049
1050 case NT_float64:
1051 {
1052 const PN_float64 *pi = (const PN_float64 *)pointer;
1053 _v3d.set(pi[0], pi[1], pi[2]);
1054 }
1055 return _v3d;
1056
1057 case NT_stdfloat:
1058 nassertr(false, _v3d);
1059 return _v3d;
1060
1061 case NT_int8:
1062 {
1063 const int8_t *pi = (const int8_t *)pointer;
1064 _v3d.set(pi[0], pi[1], pi[2]);
1065 }
1066 return _v3d;
1067
1068 case NT_int16:
1069 {
1070 const int16_t *pi = (const int16_t *)pointer;
1071 _v3d.set(pi[0], pi[1], pi[2]);
1072 }
1073 return _v3d;
1074
1075 case NT_int32:
1076 {
1077 const int32_t *pi = (const int32_t *)pointer;
1078 _v3d.set(pi[0], pi[1], pi[2]);
1079 }
1080 return _v3d;
1081
1082 case NT_packed_ufloat:
1083 {
1084 uint32_t dword = *(const uint32_t *)pointer;
1085 _v3d.set(GeomVertexData::unpack_ufloat_a(dword),
1086 GeomVertexData::unpack_ufloat_b(dword),
1087 GeomVertexData::unpack_ufloat_c(dword));
1088 }
1089 return _v3d;
1090 }
1091 }
1092
1093 return _v3d;
1094 }
1095
1096 /**
1097 *
1098 */
1099 const LVecBase4d &GeomVertexColumn::Packer::
1100 get_data4d(const unsigned char *pointer) {
1101 switch (_column->get_num_values()) {
1102 case 1:
1103 _v4d.set(get_data1d(pointer), 0.0f, 0.0f, 0.0f);
1104 return _v4d;
1105
1106 case 2:
1107 {
1108 const LVecBase2d &v2 = get_data2d(pointer);
1109 _v4d.set(v2[0], v2[1], 0.0f, 0.0f);
1110 }
1111 return _v4d;
1112
1113 case 3:
1114 {
1115 const LVecBase3d &v3 = get_data3d(pointer);
1116 _v4d.set(v3[0], v3[1], v3[2], 0.0f);
1117 }
1118 return _v4d;
1119
1120 default:
1121 switch (_column->get_numeric_type()) {
1122 case NT_uint8:
1123 {
1124 const uint8_t *pi = (const uint8_t *)pointer;
1125 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1126 }
1127 return _v4d;
1128
1129 case NT_uint16:
1130 {
1131 const uint16_t *pi = (const uint16_t *)pointer;
1132 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1133 }
1134 return _v4d;
1135
1136 case NT_uint32:
1137 {
1138 const uint32_t *pi = (const uint32_t *)pointer;
1139 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1140 }
1141 return _v4d;
1142
1143 case NT_packed_dcba:
1144 {
1145 uint32_t dword = *(const uint32_t *)pointer;
1146 _v4d.set(GeomVertexData::unpack_abcd_d(dword),
1147 GeomVertexData::unpack_abcd_c(dword),
1148 GeomVertexData::unpack_abcd_b(dword),
1149 GeomVertexData::unpack_abcd_a(dword));
1150 }
1151 return _v4d;
1152
1153 case NT_packed_dabc:
1154 {
1155 uint32_t dword = *(const uint32_t *)pointer;
1156 _v4d.set(GeomVertexData::unpack_abcd_b(dword),
1157 GeomVertexData::unpack_abcd_c(dword),
1158 GeomVertexData::unpack_abcd_d(dword),
1159 GeomVertexData::unpack_abcd_a(dword));
1160 }
1161 return _v4d;
1162
1163 case NT_float32:
1164 {
1165 const PN_float32 *pi = (const PN_float32 *)pointer;
1166 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1167 }
1168 return _v4d;
1169
1170 case NT_float64:
1171 {
1172 const PN_float64 *pi = (const PN_float64 *)pointer;
1173 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1174 }
1175 return _v4d;
1176
1177 case NT_stdfloat:
1178 nassertr(false, _v4d);
1179 break;
1180
1181 case NT_int8:
1182 {
1183 const int8_t *pi = (const int8_t *)pointer;
1184 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1185 }
1186 return _v4d;
1187
1188 case NT_int16:
1189 {
1190 const int16_t *pi = (const int16_t *)pointer;
1191 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1192 }
1193 return _v4d;
1194
1195 case NT_int32:
1196 {
1197 const int32_t *pi = (const int32_t *)pointer;
1198 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
1199 }
1200 return _v4d;
1201
1202 case NT_packed_ufloat:
1203 nassertr(false, _v4d);
1204 break;
1205 }
1206 }
1207
1208 return _v4d;
1209 }
1210
1211 /**
1212 *
1213 */
1214 int GeomVertexColumn::Packer::
1215 get_data1i(const unsigned char *pointer) {
1216 switch (_column->get_numeric_type()) {
1217 case NT_uint8:
1218 return *pointer;
1219
1220 case NT_uint16:
1221 return *(const uint16_t *)pointer;
1222
1223 case NT_uint32:
1224 return *(const uint32_t *)pointer;
1225
1226 case NT_packed_dcba:
1227 {
1228 uint32_t dword = *(const uint32_t *)pointer;
1229 return GeomVertexData::unpack_abcd_d(dword);
1230 }
1231
1232 case NT_packed_dabc:
1233 {
1234 uint32_t dword = *(const uint32_t *)pointer;
1235 return GeomVertexData::unpack_abcd_b(dword);
1236 }
1237
1238 case NT_float32:
1239 return (int)*(const PN_float32 *)pointer;
1240
1241 case NT_float64:
1242 return (int)*(const PN_float64 *)pointer;
1243
1244 case NT_stdfloat:
1245 nassertr(false, 0);
1246 break;
1247
1248 case NT_int8:
1249 return *(const int8_t *)pointer;
1250
1251 case NT_int16:
1252 return *(const int16_t *)pointer;
1253
1254 case NT_int32:
1255 return *(const int32_t *)pointer;
1256
1257 case NT_packed_ufloat:
1258 {
1259 uint32_t dword = *(const uint32_t *)pointer;
1260 return (int)GeomVertexData::unpack_ufloat_a(dword);
1261 }
1262 }
1263
1264 return 0;
1265 }
1266
1267 /**
1268 *
1269 */
1270 const LVecBase2i &GeomVertexColumn::Packer::
1271 get_data2i(const unsigned char *pointer) {
1272 switch (_column->get_num_values()) {
1273 case 1:
1274 _v2i.set(get_data1i(pointer), 0);
1275 return _v2i;
1276
1277 default:
1278 switch (_column->get_numeric_type()) {
1279 case NT_uint8:
1280 _v2i.set(pointer[0], pointer[1]);
1281 return _v2i;
1282
1283 case NT_uint16:
1284 {
1285 const uint16_t *pi = (const uint16_t *)pointer;
1286 _v2i.set(pi[0], pi[1]);
1287 }
1288 return _v2i;
1289
1290 case NT_uint32:
1291 {
1292 const uint32_t *pi = (const uint32_t *)pointer;
1293 _v2i.set(pi[0], pi[1]);
1294 }
1295 return _v2i;
1296
1297 case NT_packed_dcba:
1298 {
1299 uint32_t dword = *(const uint32_t *)pointer;
1300 _v2i.set(GeomVertexData::unpack_abcd_d(dword),
1301 GeomVertexData::unpack_abcd_c(dword));
1302 }
1303 return _v2i;
1304
1305 case NT_packed_dabc:
1306 {
1307 uint32_t dword = *(const uint32_t *)pointer;
1308 _v2i.set(GeomVertexData::unpack_abcd_b(dword),
1309 GeomVertexData::unpack_abcd_c(dword));
1310 }
1311 return _v2i;
1312
1313 case NT_float32:
1314 {
1315 const PN_float32 *pi = (const PN_float32 *)pointer;
1316 _v2i.set((int)pi[0], (int)pi[1]);
1317 }
1318 return _v2i;
1319
1320 case NT_float64:
1321 {
1322 const PN_float64 *pi = (const PN_float64 *)pointer;
1323 _v2i.set((int)pi[0], (int)pi[1]);
1324 }
1325 return _v2i;
1326
1327 case NT_stdfloat:
1328 nassertr(false, _v2i);
1329 break;
1330
1331 case NT_int8:
1332 {
1333 const int8_t *pi = (const int8_t *)pointer;
1334 _v2i.set(pi[0], pi[1]);
1335 }
1336 return _v2i;
1337
1338 case NT_int16:
1339 {
1340 const int16_t *pi = (const int16_t *)pointer;
1341 _v2i.set(pi[0], pi[1]);
1342 }
1343 return _v2i;
1344
1345 case NT_int32:
1346 {
1347 const int32_t *pi = (const int32_t *)pointer;
1348 _v2i.set(pi[0], pi[1]);
1349 }
1350 return _v2i;
1351
1352 case NT_packed_ufloat:
1353 nassertr(false, _v2i);
1354 break;
1355 }
1356 }
1357
1358 return _v2i;
1359 }
1360
1361 /**
1362 *
1363 */
1364 const LVecBase3i &GeomVertexColumn::Packer::
1365 get_data3i(const unsigned char *pointer) {
1366 switch (_column->get_num_values()) {
1367 case 1:
1368 _v3i.set(get_data1i(pointer), 0, 0);
1369 return _v3i;
1370
1371 case 2:
1372 {
1373 const LVecBase2i &v2 = get_data2i(pointer);
1374 _v3i.set(v2[0], v2[1], 0);
1375 }
1376 return _v3i;
1377
1378 default:
1379 switch (_column->get_numeric_type()) {
1380 case NT_uint8:
1381 _v3i.set(pointer[0], pointer[1], 0);
1382 return _v3i;
1383
1384 case NT_uint16:
1385 {
1386 const uint16_t *pi = (const uint16_t *)pointer;
1387 _v3i.set(pi[0], pi[1], pi[2]);
1388 }
1389 return _v3i;
1390
1391 case NT_uint32:
1392 {
1393 const uint32_t *pi = (const uint32_t *)pointer;
1394 _v3i.set(pi[0], pi[1], pi[2]);
1395 }
1396 return _v3i;
1397
1398 case NT_packed_dcba:
1399 {
1400 uint32_t dword = *(const uint32_t *)pointer;
1401 _v3i.set(GeomVertexData::unpack_abcd_d(dword),
1402 GeomVertexData::unpack_abcd_c(dword),
1403 GeomVertexData::unpack_abcd_b(dword));
1404 }
1405 return _v3i;
1406
1407 case NT_packed_dabc:
1408 {
1409 uint32_t dword = *(const uint32_t *)pointer;
1410 _v3i.set(GeomVertexData::unpack_abcd_b(dword),
1411 GeomVertexData::unpack_abcd_c(dword),
1412 GeomVertexData::unpack_abcd_d(dword));
1413 }
1414 return _v3i;
1415
1416 case NT_float32:
1417 {
1418 const PN_float32 *pi = (const PN_float32 *)pointer;
1419 _v3i.set((int)pi[0], (int)pi[1], (int)pi[2]);
1420 }
1421 return _v3i;
1422
1423 case NT_float64:
1424 {
1425 const PN_float64 *pi = (const PN_float64 *)pointer;
1426 _v3i.set((int)pi[0], (int)pi[1], (int)pi[2]);
1427 }
1428 return _v3i;
1429
1430 case NT_stdfloat:
1431 nassertr(false, _v3i);
1432 break;
1433
1434 case NT_int8:
1435 {
1436 const int8_t *pi = (const int8_t *)pointer;
1437 _v3i.set(pi[0], pi[1], pi[2]);
1438 }
1439 return _v3i;
1440
1441 case NT_int16:
1442 {
1443 const int16_t *pi = (const int16_t *)pointer;
1444 _v3i.set(pi[0], pi[1], pi[2]);
1445 }
1446 return _v3i;
1447
1448 case NT_int32:
1449 {
1450 const int32_t *pi = (const int32_t *)pointer;
1451 _v3i.set(pi[0], pi[1], pi[2]);
1452 }
1453 return _v3i;
1454
1455 case NT_packed_ufloat:
1456 {
1457 uint32_t dword = *(const uint32_t *)pointer;
1458 _v3i.set((int)GeomVertexData::unpack_ufloat_a(dword),
1459 (int)GeomVertexData::unpack_ufloat_b(dword),
1460 (int)GeomVertexData::unpack_ufloat_c(dword));
1461 }
1462 return _v3i;
1463 }
1464 }
1465
1466 return _v3i;
1467 }
1468
1469 /**
1470 *
1471 */
1472 const LVecBase4i &GeomVertexColumn::Packer::
1473 get_data4i(const unsigned char *pointer) {
1474 switch (_column->get_num_values()) {
1475 case 1:
1476 _v4i.set(get_data1i(pointer), 0, 0, 0);
1477 return _v4i;
1478
1479 case 2:
1480 {
1481 const LVecBase2i &v2 = get_data2i(pointer);
1482 _v4i.set(v2[0], v2[1], 0, 0);
1483 }
1484 return _v4i;
1485
1486 case 3:
1487 {
1488 const LVecBase3i &v3 = get_data3i(pointer);
1489 _v4i.set(v3[0], v3[1], v3[2], 0);
1490 }
1491 return _v4i;
1492
1493 default:
1494 switch (_column->get_numeric_type()) {
1495 case NT_uint8:
1496 _v4i.set(pointer[0], pointer[1], pointer[2], pointer[3]);
1497 return _v4i;
1498
1499 case NT_uint16:
1500 {
1501 const uint16_t *pi = (const uint16_t *)pointer;
1502 _v4i.set(pi[0], pi[1], pi[2], pi[3]);
1503 }
1504 return _v4i;
1505
1506 case NT_uint32:
1507 {
1508 const uint32_t *pi = (const uint32_t *)pointer;
1509 _v4i.set(pi[0], pi[1], pi[2], pi[3]);
1510 }
1511 return _v4i;
1512
1513 case NT_packed_dcba:
1514 {
1515 uint32_t dword = *(const uint32_t *)pointer;
1516 _v4i.set(GeomVertexData::unpack_abcd_d(dword),
1517 GeomVertexData::unpack_abcd_c(dword),
1518 GeomVertexData::unpack_abcd_b(dword),
1519 GeomVertexData::unpack_abcd_a(dword));
1520 }
1521 return _v4i;
1522
1523 case NT_packed_dabc:
1524 {
1525 uint32_t dword = *(const uint32_t *)pointer;
1526 _v4i.set(GeomVertexData::unpack_abcd_b(dword),
1527 GeomVertexData::unpack_abcd_c(dword),
1528 GeomVertexData::unpack_abcd_d(dword),
1529 GeomVertexData::unpack_abcd_a(dword));
1530 }
1531 return _v4i;
1532
1533 case NT_float32:
1534 {
1535 const PN_float32 *pi = (const PN_float32 *)pointer;
1536 _v4i.set((int)pi[0], (int)pi[1], (int)pi[2], (int)pi[3]);
1537 }
1538 return _v4i;
1539
1540 case NT_float64:
1541 {
1542 const PN_float64 *pi = (const PN_float64 *)pointer;
1543 _v4i.set((int)pi[0], (int)pi[1], (int)pi[2], (int)pi[3]);
1544 }
1545 return _v4i;
1546
1547 case NT_stdfloat:
1548 nassertr(false, _v4i);
1549 break;
1550
1551 case NT_int8:
1552 {
1553 const int8_t *pi = (const int8_t *)pointer;
1554 _v4i.set(pi[0], pi[1], pi[2], pi[3]);
1555 }
1556 return _v4i;
1557
1558 case NT_int16:
1559 {
1560 const int16_t *pi = (const int16_t *)pointer;
1561 _v4i.set(pi[0], pi[1], pi[2], pi[3]);
1562 }
1563 return _v4i;
1564
1565 case NT_int32:
1566 {
1567 const int32_t *pi = (const int32_t *)pointer;
1568 _v4i.set(pi[0], pi[1], pi[2], pi[3]);
1569 }
1570 return _v4i;
1571
1572 case NT_packed_ufloat:
1573 nassertr(false, _v4i);
1574 break;
1575 }
1576 }
1577
1578 return _v4i;
1579 }
1580
1581 /**
1582 *
1583 */
1584 void GeomVertexColumn::Packer::
1585 set_data1f(unsigned char *pointer, float data) {
1586 switch (_column->get_num_values()) {
1587 case 1:
1588 switch (_column->get_numeric_type()) {
1589 case NT_uint8:
1590 *(uint8_t *)pointer = (unsigned int)data;
1591 break;
1592
1593 case NT_uint16:
1594 *(uint16_t *)pointer = (unsigned int)data;
1595 break;
1596
1597 case NT_uint32:
1598 *(uint32_t *)pointer = (unsigned int)data;
1599 break;
1600
1601 case NT_packed_dcba:
1602 case NT_packed_dabc:
1603 nassertv(false);
1604 break;
1605
1606 case NT_float32:
1607 *(PN_float32 *)pointer = data;
1608 break;
1609
1610 case NT_float64:
1611 *(PN_float64 *)pointer = data;
1612 break;
1613
1614 case NT_stdfloat:
1615 nassertv(false);
1616 break;
1617
1618 case NT_int8:
1619 *(int8_t *)pointer = (int)data;
1620 break;
1621
1622 case NT_int16:
1623 *(int16_t *)pointer = (int)data;
1624 break;
1625
1626 case NT_int32:
1627 *(int32_t *)pointer = (int)data;
1628 break;
1629
1630 case NT_packed_ufloat:
1631 nassertv(false);
1632 break;
1633 }
1634 break;
1635
1636 case 2:
1637 set_data2f(pointer, LVecBase2f(data, 0.0f));
1638 break;
1639
1640 case 3:
1641 set_data3f(pointer, LVecBase3f(data, 0.0f, 0.0f));
1642 break;
1643
1644 case 4:
1645 set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 0.0f));
1646 break;
1647 }
1648 }
1649
1650 /**
1651 *
1652 */
1653 void GeomVertexColumn::Packer::
1654 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
1655 switch (_column->get_num_values()) {
1656 case 1:
1657 set_data1f(pointer, data[0]);
1658 break;
1659
1660 case 2:
1661 switch (_column->get_numeric_type()) {
1662 case NT_uint8:
1663 {
1664 uint8_t *pi = (uint8_t *)pointer;
1665 pi[0] = (unsigned int)data[0];
1666 pi[1] = (unsigned int)data[1];
1667 }
1668 break;
1669
1670 case NT_uint16:
1671 {
1672 uint16_t *pi = (uint16_t *)pointer;
1673 pi[0] = (unsigned int)data[0];
1674 pi[1] = (unsigned int)data[1];
1675 }
1676 break;
1677
1678 case NT_uint32:
1679 {
1680 uint32_t *pi = (uint32_t *)pointer;
1681 pi[0] = (unsigned int)data[0];
1682 pi[1] = (unsigned int)data[1];
1683 }
1684 break;
1685
1686 case NT_packed_dcba:
1687 case NT_packed_dabc:
1688 nassertv(false);
1689 break;
1690
1691 case NT_float32:
1692 {
1693 PN_float32 *pi = (PN_float32 *)pointer;
1694 pi[0] = data[0];
1695 pi[1] = data[1];
1696 }
1697 break;
1698
1699 case NT_float64:
1700 {
1701 PN_float64 *pi = (PN_float64 *)pointer;
1702 pi[0] = data[0];
1703 pi[1] = data[1];
1704 }
1705 break;
1706
1707 case NT_stdfloat:
1708 nassertv(false);
1709 break;
1710
1711 case NT_int8:
1712 {
1713 int8_t *pi = (int8_t *)pointer;
1714 pi[0] = (int)data[0];
1715 pi[1] = (int)data[1];
1716 }
1717 break;
1718
1719 case NT_int16:
1720 {
1721 int16_t *pi = (int16_t *)pointer;
1722 pi[0] = (int)data[0];
1723 pi[1] = (int)data[1];
1724 }
1725 break;
1726
1727 case NT_int32:
1728 {
1729 int32_t *pi = (int32_t *)pointer;
1730 pi[0] = (int)data[0];
1731 pi[1] = (int)data[1];
1732 }
1733 break;
1734
1735 case NT_packed_ufloat:
1736 nassertv(false);
1737 break;
1738 }
1739 break;
1740
1741 case 3:
1742 set_data3f(pointer, LVecBase3f(data[0], data[1], 0.0f));
1743 break;
1744
1745 default:
1746 set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 0.0f));
1747 break;
1748 }
1749 }
1750
1751 /**
1752 *
1753 */
1754 void GeomVertexColumn::Packer::
1755 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
1756 switch (_column->get_num_values()) {
1757 case 1:
1758 set_data1f(pointer, data[0]);
1759 break;
1760
1761 case 2:
1762 set_data2f(pointer, LVecBase2f(data[0], data[1]));
1763 break;
1764
1765 case 3:
1766 switch (_column->get_numeric_type()) {
1767 case NT_uint8:
1768 {
1769 uint8_t *pi = (uint8_t *)pointer;
1770 pi[0] = (unsigned int)data[0];
1771 pi[1] = (unsigned int)data[1];
1772 pi[2] = (unsigned int)data[2];
1773 }
1774 break;
1775
1776 case NT_uint16:
1777 {
1778 uint16_t *pi = (uint16_t *)pointer;
1779 pi[0] = (unsigned int)data[0];
1780 pi[1] = (unsigned int)data[1];
1781 pi[2] = (unsigned int)data[2];
1782 }
1783 break;
1784
1785 case NT_uint32:
1786 {
1787 uint32_t *pi = (uint32_t *)pointer;
1788 pi[0] = (unsigned int)data[0];
1789 pi[1] = (unsigned int)data[1];
1790 pi[2] = (unsigned int)data[2];
1791 }
1792 break;
1793
1794 case NT_packed_dcba:
1795 case NT_packed_dabc:
1796 nassertv(false);
1797 break;
1798
1799 case NT_float32:
1800 {
1801 PN_float32 *pi = (PN_float32 *)pointer;
1802 pi[0] = data[0];
1803 pi[1] = data[1];
1804 pi[2] = data[2];
1805 }
1806 break;
1807
1808 case NT_float64:
1809 {
1810 PN_float64 *pi = (PN_float64 *)pointer;
1811 pi[0] = data[0];
1812 pi[1] = data[1];
1813 pi[2] = data[2];
1814 }
1815 break;
1816
1817 case NT_stdfloat:
1818 nassertv(false);
1819 break;
1820
1821 case NT_int8:
1822 {
1823 int8_t *pi = (int8_t *)pointer;
1824 pi[0] = (int)data[0];
1825 pi[1] = (int)data[1];
1826 pi[2] = (int)data[2];
1827 }
1828 break;
1829
1830 case NT_int16:
1831 {
1832 int16_t *pi = (int16_t *)pointer;
1833 pi[0] = (int)data[0];
1834 pi[1] = (int)data[1];
1835 pi[2] = (int)data[2];
1836 }
1837 break;
1838
1839 case NT_int32:
1840 {
1841 int32_t *pi = (int32_t *)pointer;
1842 pi[0] = (int)data[0];
1843 pi[1] = (int)data[1];
1844 pi[2] = (int)data[2];
1845 }
1846 break;
1847
1848 case NT_packed_ufloat:
1849 *(uint32_t *)pointer = GeomVertexData::pack_ufloat(data[0], data[1], data[2]);
1850 break;
1851 }
1852 break;
1853
1854 default:
1855 set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 0.0f));
1856 break;
1857 }
1858 }
1859
1860 /**
1861 *
1862 */
1863 void GeomVertexColumn::Packer::
1864 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
1865 switch (_column->get_num_values()) {
1866 case 1:
1867 set_data1f(pointer, data[0]);
1868 break;
1869
1870 case 2:
1871 set_data2f(pointer, LVecBase2f(data[0], data[1]));
1872 break;
1873
1874 case 3:
1875 set_data3f(pointer, LVecBase3f(data[0], data[1], data[2]));
1876 break;
1877
1878 default:
1879 switch (_column->get_numeric_type()) {
1880 case NT_uint8:
1881 {
1882 uint8_t *pi = (uint8_t *)pointer;
1883 pi[0] = (unsigned int)data[0];
1884 pi[1] = (unsigned int)data[1];
1885 pi[2] = (unsigned int)data[2];
1886 pi[3] = (unsigned int)data[3];
1887 }
1888 break;
1889
1890 case NT_uint16:
1891 {
1892 uint16_t *pi = (uint16_t *)pointer;
1893 pi[0] = (unsigned int)data[0];
1894 pi[1] = (unsigned int)data[1];
1895 pi[2] = (unsigned int)data[2];
1896 pi[3] = (unsigned int)data[3];
1897 }
1898 break;
1899
1900 case NT_uint32:
1901 {
1902 uint32_t *pi = (uint32_t *)pointer;
1903 pi[0] = (unsigned int)data[0];
1904 pi[1] = (unsigned int)data[1];
1905 pi[2] = (unsigned int)data[2];
1906 pi[3] = (unsigned int)data[3];
1907 }
1908 break;
1909
1910 case NT_packed_dcba:
1911 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[2], data[1], data[0]);
1912 break;
1913
1914 case NT_packed_dabc:
1915 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[0], data[1], data[2]);
1916 break;
1917
1918 case NT_float32:
1919 {
1920 PN_float32 *pi = (PN_float32 *)pointer;
1921 pi[0] = data[0];
1922 pi[1] = data[1];
1923 pi[2] = data[2];
1924 pi[3] = data[3];
1925 }
1926 break;
1927
1928 case NT_float64:
1929 {
1930 PN_float64 *pi = (PN_float64 *)pointer;
1931 pi[0] = data[0];
1932 pi[1] = data[1];
1933 pi[2] = data[2];
1934 pi[3] = data[3];
1935 }
1936 break;
1937
1938 case NT_stdfloat:
1939 nassertv(false);
1940 break;
1941
1942 case NT_int8:
1943 {
1944 int8_t *pi = (int8_t *)pointer;
1945 pi[0] = (int)data[0];
1946 pi[1] = (int)data[1];
1947 pi[2] = (int)data[2];
1948 pi[3] = (int)data[3];
1949 }
1950 break;
1951
1952 case NT_int16:
1953 {
1954 int16_t *pi = (int16_t *)pointer;
1955 pi[0] = (int)data[0];
1956 pi[1] = (int)data[1];
1957 pi[2] = (int)data[2];
1958 pi[3] = (int)data[3];
1959 }
1960 break;
1961
1962 case NT_int32:
1963 {
1964 int32_t *pi = (int32_t *)pointer;
1965 pi[0] = (int)data[0];
1966 pi[1] = (int)data[1];
1967 pi[2] = (int)data[2];
1968 pi[3] = (int)data[3];
1969 }
1970 break;
1971
1972 case NT_packed_ufloat:
1973 nassertv(false);
1974 break;
1975 }
1976 break;
1977 }
1978 }
1979
1980 /**
1981 *
1982 */
1983 void GeomVertexColumn::Packer::
1984 set_data1d(unsigned char *pointer, double data) {
1985 switch (_column->get_num_values()) {
1986 case 1:
1987 switch (_column->get_numeric_type()) {
1988 case NT_uint8:
1989 *(uint8_t *)pointer = (unsigned int)data;
1990 break;
1991
1992 case NT_uint16:
1993 *(uint16_t *)pointer = (unsigned int)data;
1994 break;
1995
1996 case NT_uint32:
1997 *(uint32_t *)pointer = (unsigned int)data;
1998 break;
1999
2000 case NT_packed_dcba:
2001 case NT_packed_dabc:
2002 nassertv(false);
2003 break;
2004
2005 case NT_float32:
2006 *(PN_float32 *)pointer = data;
2007 break;
2008
2009 case NT_float64:
2010 *(PN_float64 *)pointer = data;
2011 break;
2012
2013 case NT_stdfloat:
2014 nassertv(false);
2015 break;
2016
2017 case NT_int8:
2018 *(int8_t *)pointer = (int)data;
2019 break;
2020
2021 case NT_int16:
2022 *(int16_t *)pointer = (int)data;
2023 break;
2024
2025 case NT_int32:
2026 *(int32_t *)pointer = (int)data;
2027 break;
2028
2029 case NT_packed_ufloat:
2030 nassertv(false);
2031 break;
2032 }
2033 break;
2034
2035 case 2:
2036 set_data2d(pointer, LVecBase2d(data, 0.0f));
2037 break;
2038
2039 case 3:
2040 set_data3d(pointer, LVecBase3d(data, 0.0f, 0.0f));
2041 break;
2042
2043 case 4:
2044 set_data4d(pointer, LVecBase4d(data, 0.0f, 0.0f, 0.0f));
2045 break;
2046 }
2047 }
2048
2049 /**
2050 *
2051 */
2052 void GeomVertexColumn::Packer::
2053 set_data2d(unsigned char *pointer, const LVecBase2d &data) {
2054 switch (_column->get_num_values()) {
2055 case 1:
2056 set_data1d(pointer, data[0]);
2057
2058 case 2:
2059 switch (_column->get_numeric_type()) {
2060 case NT_uint8:
2061 {
2062 uint8_t *pi = (uint8_t *)pointer;
2063 pi[0] = (unsigned int)data[0];
2064 pi[1] = (unsigned int)data[1];
2065 }
2066 break;
2067
2068 case NT_uint16:
2069 {
2070 uint16_t *pi = (uint16_t *)pointer;
2071 pi[0] = (unsigned int)data[0];
2072 pi[1] = (unsigned int)data[1];
2073 }
2074 break;
2075
2076 case NT_uint32:
2077 {
2078 uint32_t *pi = (uint32_t *)pointer;
2079 pi[0] = (unsigned int)data[0];
2080 pi[1] = (unsigned int)data[1];
2081 }
2082 break;
2083
2084 case NT_packed_dcba:
2085 case NT_packed_dabc:
2086 nassertv(false);
2087 break;
2088
2089 case NT_float32:
2090 {
2091 PN_float32 *pi = (PN_float32 *)pointer;
2092 pi[0] = data[0];
2093 pi[1] = data[1];
2094 }
2095 break;
2096
2097 case NT_float64:
2098 {
2099 PN_float64 *pi = (PN_float64 *)pointer;
2100 pi[0] = data[0];
2101 pi[1] = data[1];
2102 }
2103 break;
2104
2105 case NT_stdfloat:
2106 nassertv(false);
2107 break;
2108
2109 case NT_int8:
2110 {
2111 int8_t *pi = (int8_t *)pointer;
2112 pi[0] = (int)data[0];
2113 pi[1] = (int)data[1];
2114 }
2115 break;
2116
2117 case NT_int16:
2118 {
2119 int16_t *pi = (int16_t *)pointer;
2120 pi[0] = (int)data[0];
2121 pi[1] = (int)data[1];
2122 }
2123 break;
2124
2125 case NT_int32:
2126 {
2127 int32_t *pi = (int32_t *)pointer;
2128 pi[0] = (int)data[0];
2129 pi[1] = (int)data[1];
2130 }
2131 break;
2132
2133 case NT_packed_ufloat:
2134 nassertv(false);
2135 break;
2136 }
2137 break;
2138
2139 case 3:
2140 set_data3d(pointer, LVecBase3d(data[0], data[1], 0.0f));
2141 break;
2142
2143 default:
2144 set_data4d(pointer, LVecBase4d(data[0], data[1], 0.0f, 0.0f));
2145 break;
2146 }
2147 }
2148
2149 /**
2150 *
2151 */
2152 void GeomVertexColumn::Packer::
2153 set_data3d(unsigned char *pointer, const LVecBase3d &data) {
2154 switch (_column->get_num_values()) {
2155 case 1:
2156 set_data1d(pointer, data[0]);
2157 break;
2158
2159 case 2:
2160 set_data2d(pointer, LVecBase2d(data[0], data[1]));
2161 break;
2162
2163 case 3:
2164 switch (_column->get_numeric_type()) {
2165 case NT_uint8:
2166 {
2167 uint8_t *pi = (uint8_t *)pointer;
2168 pi[0] = (unsigned int)data[0];
2169 pi[1] = (unsigned int)data[1];
2170 pi[2] = (unsigned int)data[2];
2171 }
2172 break;
2173
2174 case NT_uint16:
2175 {
2176 uint16_t *pi = (uint16_t *)pointer;
2177 pi[0] = (unsigned int)data[0];
2178 pi[1] = (unsigned int)data[1];
2179 pi[2] = (unsigned int)data[2];
2180 }
2181 break;
2182
2183 case NT_uint32:
2184 {
2185 uint32_t *pi = (uint32_t *)pointer;
2186 pi[0] = (unsigned int)data[0];
2187 pi[1] = (unsigned int)data[1];
2188 pi[2] = (unsigned int)data[2];
2189 }
2190 break;
2191
2192 case NT_packed_dcba:
2193 case NT_packed_dabc:
2194 nassertv(false);
2195 break;
2196
2197 case NT_float32:
2198 {
2199 PN_float32 *pi = (PN_float32 *)pointer;
2200 pi[0] = data[0];
2201 pi[1] = data[1];
2202 pi[2] = data[2];
2203 }
2204 break;
2205
2206 case NT_float64:
2207 {
2208 PN_float64 *pi = (PN_float64 *)pointer;
2209 pi[0] = data[0];
2210 pi[1] = data[1];
2211 pi[2] = data[2];
2212 }
2213 break;
2214
2215 case NT_stdfloat:
2216 nassertv(false);
2217 break;
2218
2219 case NT_int8:
2220 {
2221 int8_t *pi = (int8_t *)pointer;
2222 pi[0] = (int)data[0];
2223 pi[1] = (int)data[1];
2224 pi[2] = (int)data[2];
2225 }
2226 break;
2227
2228 case NT_int16:
2229 {
2230 int16_t *pi = (int16_t *)pointer;
2231 pi[0] = (int)data[0];
2232 pi[1] = (int)data[1];
2233 pi[2] = (int)data[2];
2234 }
2235 break;
2236
2237 case NT_int32:
2238 {
2239 int32_t *pi = (int32_t *)pointer;
2240 pi[0] = (int)data[0];
2241 pi[1] = (int)data[1];
2242 pi[2] = (int)data[2];
2243 }
2244 break;
2245
2246 case NT_packed_ufloat:
2247 *(uint32_t *)pointer = GeomVertexData::pack_ufloat(data[0], data[1], data[2]);
2248 break;
2249 }
2250 break;
2251
2252 default:
2253 set_data4d(pointer, LVecBase4d(data[0], data[1], data[2], 0.0f));
2254 break;
2255 }
2256 }
2257
2258 /**
2259 *
2260 */
2261 void GeomVertexColumn::Packer::
2262 set_data4d(unsigned char *pointer, const LVecBase4d &data) {
2263 switch (_column->get_num_values()) {
2264 case 1:
2265 set_data1d(pointer, data[0]);
2266 break;
2267
2268 case 2:
2269 set_data2d(pointer, LVecBase2d(data[0], data[1]));
2270 break;
2271
2272 case 3:
2273 set_data3d(pointer, LVecBase3d(data[0], data[1], data[2]));
2274 break;
2275
2276 default:
2277 switch (_column->get_numeric_type()) {
2278 case NT_uint8:
2279 {
2280 uint8_t *pi = (uint8_t *)pointer;
2281 pi[0] = (unsigned int)data[0];
2282 pi[1] = (unsigned int)data[1];
2283 pi[2] = (unsigned int)data[2];
2284 pi[3] = (unsigned int)data[3];
2285 }
2286 break;
2287
2288 case NT_uint16:
2289 {
2290 uint16_t *pi = (uint16_t *)pointer;
2291 pi[0] = (unsigned int)data[0];
2292 pi[1] = (unsigned int)data[1];
2293 pi[2] = (unsigned int)data[2];
2294 pi[3] = (unsigned int)data[3];
2295 }
2296 break;
2297
2298 case NT_uint32:
2299 {
2300 uint32_t *pi = (uint32_t *)pointer;
2301 pi[0] = (unsigned int)data[0];
2302 pi[1] = (unsigned int)data[1];
2303 pi[2] = (unsigned int)data[2];
2304 pi[3] = (unsigned int)data[3];
2305 }
2306 break;
2307
2308 case NT_packed_dcba:
2309 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[2], data[1], data[0]);
2310 break;
2311
2312 case NT_packed_dabc:
2313 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[0], data[1], data[2]);
2314 break;
2315
2316 case NT_float32:
2317 {
2318 PN_float32 *pi = (PN_float32 *)pointer;
2319 pi[0] = data[0];
2320 pi[1] = data[1];
2321 pi[2] = data[2];
2322 pi[3] = data[3];
2323 }
2324 break;
2325
2326 case NT_float64:
2327 {
2328 PN_float64 *pi = (PN_float64 *)pointer;
2329 pi[0] = data[0];
2330 pi[1] = data[1];
2331 pi[2] = data[2];
2332 pi[3] = data[3];
2333 }
2334 break;
2335
2336 case NT_stdfloat:
2337 nassertv(false);
2338 break;
2339
2340 case NT_int8:
2341 {
2342 int8_t *pi = (int8_t *)pointer;
2343 pi[0] = (int)data[0];
2344 pi[1] = (int)data[1];
2345 pi[2] = (int)data[2];
2346 pi[3] = (int)data[3];
2347 }
2348 break;
2349
2350 case NT_int16:
2351 {
2352 int16_t *pi = (int16_t *)pointer;
2353 pi[0] = (int)data[0];
2354 pi[1] = (int)data[1];
2355 pi[2] = (int)data[2];
2356 pi[3] = (int)data[3];
2357 }
2358 break;
2359
2360 case NT_int32:
2361 {
2362 int32_t *pi = (int32_t *)pointer;
2363 pi[0] = (int)data[0];
2364 pi[1] = (int)data[1];
2365 pi[2] = (int)data[2];
2366 pi[3] = (int)data[3];
2367 }
2368 break;
2369
2370 case NT_packed_ufloat:
2371 nassertv(false);
2372 break;
2373 }
2374 break;
2375 }
2376 }
2377
2378 /**
2379 *
2380 */
2381 void GeomVertexColumn::Packer::
2382 set_data1i(unsigned char *pointer, int data) {
2383 switch (_column->get_num_values()) {
2384 case 1:
2385 switch (_column->get_numeric_type()) {
2386 case NT_uint8:
2387 *pointer = data;
2388 nassertv((*pointer) == data);
2389 break;
2390
2391 case NT_uint16:
2392 *(uint16_t *)pointer = data;
2393 nassertv(*(uint16_t *)pointer == data);
2394 break;
2395
2396 case NT_uint32:
2397 *(uint32_t *)pointer = data;
2398 break;
2399
2400 case NT_packed_dcba:
2401 case NT_packed_dabc:
2402 nassertv(false);
2403 break;
2404
2405 case NT_float32:
2406 *(PN_float32 *)pointer = (float)data;
2407 break;
2408
2409 case NT_float64:
2410 *(PN_float64 *)pointer = (double)data;
2411 break;
2412
2413 case NT_stdfloat:
2414 nassertv(false);
2415 break;
2416
2417 case NT_int8:
2418 *(int8_t *)pointer = data;
2419 nassertv(*(int8_t *)pointer == data);
2420 break;
2421
2422 case NT_int16:
2423 *(int16_t *)pointer = data;
2424 nassertv(*(int16_t *)pointer == data);
2425 break;
2426
2427 case NT_int32:
2428 *(int32_t *)pointer = data;
2429 break;
2430
2431 case NT_packed_ufloat:
2432 nassertv(false);
2433 break;
2434 }
2435 break;
2436
2437 case 2:
2438 set_data2i(pointer, LVecBase2i(data, 0));
2439 break;
2440
2441 case 3:
2442 set_data3i(pointer, LVecBase3i(data, 0, 0));
2443 break;
2444
2445 default:
2446 set_data4i(pointer, LVecBase4i(data, 0, 0, 0));
2447 break;
2448 }
2449 }
2450
2451 /**
2452 *
2453 */
2454 void GeomVertexColumn::Packer::
2455 set_data2i(unsigned char *pointer, const LVecBase2i &data) {
2456 switch (_column->get_num_values()) {
2457 case 1:
2458 set_data1i(pointer, data[0]);
2459 break;
2460
2461 case 2:
2462 switch (_column->get_numeric_type()) {
2463 case NT_uint8:
2464 pointer[0] = data[0];
2465 pointer[1] = data[1];
2466 break;
2467
2468 case NT_uint16:
2469 {
2470 uint16_t *pi = (uint16_t *)pointer;
2471 pi[0] = data[0];
2472 pi[1] = data[1];
2473 }
2474 break;
2475
2476 case NT_uint32:
2477 {
2478 uint32_t *pi = (uint32_t *)pointer;
2479 pi[0] = data[0];
2480 pi[1] = data[1];
2481 }
2482 break;
2483
2484 case NT_packed_dcba:
2485 case NT_packed_dabc:
2486 nassertv(false);
2487 break;
2488
2489 case NT_float32:
2490 {
2491 PN_float32 *pi = (PN_float32 *)pointer;
2492 pi[0] = data[0];
2493 pi[1] = data[1];
2494 }
2495 break;
2496
2497 case NT_float64:
2498 {
2499 PN_float64 *pi = (PN_float64 *)pointer;
2500 pi[0] = data[0];
2501 pi[1] = data[1];
2502 }
2503 break;
2504
2505 case NT_stdfloat:
2506 nassertv(false);
2507 break;
2508
2509 case NT_int8:
2510 {
2511 int8_t *pi = (int8_t *)pointer;
2512 pi[0] = data[0];
2513 pi[1] = data[1];
2514 }
2515 break;
2516
2517 case NT_int16:
2518 {
2519 int16_t *pi = (int16_t *)pointer;
2520 pi[0] = data[0];
2521 pi[1] = data[1];
2522 }
2523 break;
2524
2525 case NT_int32:
2526 {
2527 int32_t *pi = (int32_t *)pointer;
2528 pi[0] = data[0];
2529 pi[1] = data[1];
2530 }
2531 break;
2532
2533 case NT_packed_ufloat:
2534 nassertv(false);
2535 break;
2536 }
2537 break;
2538
2539 case 3:
2540 set_data3i(pointer, LVecBase3i(data[0], data[1], 0));
2541 break;
2542
2543 default:
2544 set_data4i(pointer, LVecBase4i(data[0], data[1], 0, 0));
2545 break;
2546 }
2547 }
2548
2549 /**
2550 *
2551 */
2552 void GeomVertexColumn::Packer::
2553 set_data3i(unsigned char *pointer, const LVecBase3i &data) {
2554 switch (_column->get_num_values()) {
2555 case 1:
2556 set_data1i(pointer, data[0]);
2557 break;
2558
2559 case 2:
2560 set_data2i(pointer, LVecBase2i(data[0], data[1]));
2561 break;
2562
2563 case 3:
2564 switch (_column->get_numeric_type()) {
2565 case NT_uint8:
2566 pointer[0] = data[0];
2567 pointer[1] = data[1];
2568 pointer[2] = data[2];
2569 break;
2570
2571 case NT_uint16:
2572 {
2573 uint16_t *pi = (uint16_t *)pointer;
2574 pi[0] = data[0];
2575 pi[1] = data[1];
2576 pi[2] = data[2];
2577 }
2578 break;
2579
2580 case NT_uint32:
2581 {
2582 uint32_t *pi = (uint32_t *)pointer;
2583 pi[0] = data[0];
2584 pi[1] = data[1];
2585 pi[2] = data[2];
2586 }
2587 break;
2588
2589 case NT_packed_dcba:
2590 case NT_packed_dabc:
2591 nassertv(false);
2592 break;
2593
2594 case NT_float32:
2595 {
2596 PN_float32 *pi = (PN_float32 *)pointer;
2597 pi[0] = data[0];
2598 pi[1] = data[1];
2599 pi[2] = data[2];
2600 }
2601 break;
2602
2603 case NT_float64:
2604 {
2605 PN_float64 *pi = (PN_float64 *)pointer;
2606 pi[0] = data[0];
2607 pi[1] = data[1];
2608 pi[2] = data[2];
2609 }
2610 break;
2611
2612 case NT_stdfloat:
2613 nassertv(false);
2614 break;
2615
2616 case NT_int8:
2617 {
2618 int8_t *pi = (int8_t *)pointer;
2619 pi[0] = data[0];
2620 pi[1] = data[1];
2621 pi[2] = data[2];
2622 }
2623 break;
2624
2625 case NT_int16:
2626 {
2627 int16_t *pi = (int16_t *)pointer;
2628 pi[0] = data[0];
2629 pi[1] = data[1];
2630 pi[2] = data[2];
2631 }
2632 break;
2633
2634 case NT_int32:
2635 {
2636 int32_t *pi = (int32_t *)pointer;
2637 pi[0] = data[0];
2638 pi[1] = data[1];
2639 pi[2] = data[2];
2640 }
2641 break;
2642
2643 case NT_packed_ufloat:
2644 *(uint32_t *)pointer = GeomVertexData::pack_ufloat(data[0], data[1], data[2]);
2645 break;
2646 }
2647 break;
2648
2649 default:
2650 set_data4i(pointer, LVecBase4i(data[0], data[1], data[2], 0));
2651 break;
2652 }
2653 }
2654
2655 /**
2656 *
2657 */
2658 void GeomVertexColumn::Packer::
2659 set_data4i(unsigned char *pointer, const LVecBase4i &data) {
2660 switch (_column->get_num_values()) {
2661 case 1:
2662 set_data1i(pointer, data[0]);
2663 break;
2664
2665 case 2:
2666 set_data2i(pointer, LVecBase2i(data[0], data[1]));
2667 break;
2668
2669 case 3:
2670 set_data3i(pointer, LVecBase3i(data[0], data[1], data[2]));
2671 break;
2672
2673 default:
2674 switch (_column->get_numeric_type()) {
2675 case NT_uint8:
2676 pointer[0] = data[0];
2677 pointer[1] = data[1];
2678 pointer[2] = data[2];
2679 pointer[3] = data[3];
2680 break;
2681
2682 case NT_uint16:
2683 {
2684 uint16_t *pi = (uint16_t *)pointer;
2685 pi[0] = data[0];
2686 pi[1] = data[1];
2687 pi[2] = data[2];
2688 pi[3] = data[3];
2689 }
2690 break;
2691
2692 case NT_uint32:
2693 {
2694 uint32_t *pi = (uint32_t *)pointer;
2695 pi[0] = data[0];
2696 pi[1] = data[1];
2697 pi[2] = data[2];
2698 pi[3] = data[3];
2699 }
2700 break;
2701
2702 case NT_packed_dcba:
2703 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[2], data[1], data[0]);
2704 break;
2705
2706 case NT_packed_dabc:
2707 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[0], data[1], data[2]);
2708 break;
2709
2710 case NT_float32:
2711 {
2712 PN_float32 *pi = (PN_float32 *)pointer;
2713 pi[0] = data[0];
2714 pi[1] = data[1];
2715 pi[2] = data[2];
2716 pi[3] = data[3];
2717 }
2718 break;
2719
2720 case NT_float64:
2721 {
2722 PN_float64 *pi = (PN_float64 *)pointer;
2723 pi[0] = data[0];
2724 pi[1] = data[1];
2725 pi[2] = data[2];
2726 pi[3] = data[3];
2727 }
2728 break;
2729
2730 case NT_stdfloat:
2731 nassertv(false);
2732 break;
2733
2734 case NT_int8:
2735 {
2736 int8_t *pi = (int8_t *)pointer;
2737 pi[0] = data[0];
2738 pi[1] = data[1];
2739 pi[2] = data[2];
2740 pi[3] = data[3];
2741 }
2742 break;
2743
2744 case NT_int16:
2745 {
2746 int16_t *pi = (int16_t *)pointer;
2747 pi[0] = data[0];
2748 pi[1] = data[1];
2749 pi[2] = data[2];
2750 pi[3] = data[3];
2751 }
2752 break;
2753
2754 case NT_int32:
2755 {
2756 int32_t *pi = (int32_t *)pointer;
2757 pi[0] = data[0];
2758 pi[1] = data[1];
2759 pi[2] = data[2];
2760 pi[3] = data[3];
2761 }
2762 break;
2763
2764 case NT_packed_ufloat:
2765 nassertv(false);
2766 break;
2767 }
2768 break;
2769 }
2770 }
2771
2772 /**
2773 *
2774 */
2775 float GeomVertexColumn::Packer_point::
2776 get_data1f(const unsigned char *pointer) {
2777 if (_column->get_num_values() == 4) {
2778 const LVecBase4f &v4 = get_data4f(pointer);
2779 return v4[0] / v4[3];
2780 } else {
2781 return Packer::get_data1f(pointer);
2782 }
2783 }
2784
2785 /**
2786 *
2787 */
2788 const LVecBase2f &GeomVertexColumn::Packer_point::
2789 get_data2f(const unsigned char *pointer) {
2790 if (_column->get_num_values() == 4) {
2791 const LVecBase4f &v4 = get_data4f(pointer);
2792 _v2.set(v4[0] / v4[3], v4[1] / v4[3]);
2793 return _v2;
2794 } else {
2795 return Packer::get_data2f(pointer);
2796 }
2797 }
2798
2799 /**
2800 *
2801 */
2802 const LVecBase3f &GeomVertexColumn::Packer_point::
2803 get_data3f(const unsigned char *pointer) {
2804 if (_column->get_num_values() == 4) {
2805 const LVecBase4f &v4 = get_data4f(pointer);
2806 _v3.set(v4[0] / v4[3], v4[1] / v4[3], v4[2] / v4[3]);
2807 return _v3;
2808 } else {
2809 return Packer::get_data3f(pointer);
2810 }
2811 }
2812
2813 /**
2814 *
2815 */
2816 const LVecBase4f &GeomVertexColumn::Packer_point::
2817 get_data4f(const unsigned char *pointer) {
2818 switch (_column->get_num_values()) {
2819 case 1:
2820 _v4.set(get_data1f(pointer), 0.0f, 0.0f, 1.0f);
2821 return _v4;
2822
2823 case 2:
2824 {
2825 const LVecBase2f &v2 = get_data2f(pointer);
2826 _v4.set(v2[0], v2[1], 0.0f, 1.0f);
2827 }
2828 return _v4;
2829
2830 case 3:
2831 {
2832 const LVecBase3f &v3 = get_data3f(pointer);
2833 _v4.set(v3[0], v3[1], v3[2], 1.0f);
2834 }
2835 return _v4;
2836
2837 default:
2838 switch (_column->get_numeric_type()) {
2839 case NT_uint8:
2840 {
2841 const uint8_t *pi = (const uint8_t *)pointer;
2842 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2843 }
2844 return _v4;
2845
2846 case NT_uint16:
2847 {
2848 const uint16_t *pi = (const uint16_t *)pointer;
2849 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2850 }
2851 return _v4;
2852
2853 case NT_uint32:
2854 {
2855 const uint32_t *pi = (const uint32_t *)pointer;
2856 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2857 }
2858 return _v4;
2859
2860 case NT_packed_dcba:
2861 {
2862 uint32_t dword = *(const uint32_t *)pointer;
2863 _v4.set(GeomVertexData::unpack_abcd_d(dword),
2864 GeomVertexData::unpack_abcd_c(dword),
2865 GeomVertexData::unpack_abcd_b(dword),
2866 GeomVertexData::unpack_abcd_a(dword));
2867 }
2868 return _v4;
2869
2870 case NT_packed_dabc:
2871 {
2872 uint32_t dword = *(const uint32_t *)pointer;
2873 _v4.set(GeomVertexData::unpack_abcd_b(dword),
2874 GeomVertexData::unpack_abcd_c(dword),
2875 GeomVertexData::unpack_abcd_d(dword),
2876 GeomVertexData::unpack_abcd_a(dword));
2877 }
2878 return _v4;
2879
2880 case NT_float32:
2881 {
2882 const PN_float32 *pi = (const PN_float32 *)pointer;
2883 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2884 }
2885 return _v4;
2886
2887 case NT_float64:
2888 {
2889 const PN_float64 *pi = (const PN_float64 *)pointer;
2890 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2891 }
2892 return _v4;
2893
2894 case NT_stdfloat:
2895 nassertr(false, _v4);
2896 break;
2897
2898 case NT_int8:
2899 {
2900 const int8_t *pi = (const int8_t *)pointer;
2901 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2902 }
2903 return _v4;
2904
2905 case NT_int16:
2906 {
2907 const int16_t *pi = (const int16_t *)pointer;
2908 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2909 }
2910 return _v4;
2911
2912 case NT_int32:
2913 {
2914 const int32_t *pi = (const int32_t *)pointer;
2915 _v4.set(pi[0], pi[1], pi[2], pi[3]);
2916 }
2917 return _v4;
2918
2919 case NT_packed_ufloat:
2920 nassertr(false, _v4);
2921 break;
2922 }
2923 }
2924
2925 return _v4;
2926 }
2927
2928 /**
2929 *
2930 */
2931 double GeomVertexColumn::Packer_point::
2932 get_data1d(const unsigned char *pointer) {
2933 if (_column->get_num_values() == 4) {
2934 const LVecBase4d &v4 = get_data4d(pointer);
2935 return v4[0] / v4[3];
2936 } else {
2937 return Packer::get_data1d(pointer);
2938 }
2939 }
2940
2941 /**
2942 *
2943 */
2944 const LVecBase2d &GeomVertexColumn::Packer_point::
2945 get_data2d(const unsigned char *pointer) {
2946 if (_column->get_num_values() == 4) {
2947 const LVecBase4d &v4 = get_data4d(pointer);
2948 _v2d.set(v4[0] / v4[3], v4[1] / v4[3]);
2949 return _v2d;
2950 } else {
2951 return Packer::get_data2d(pointer);
2952 }
2953 }
2954
2955 /**
2956 *
2957 */
2958 const LVecBase3d &GeomVertexColumn::Packer_point::
2959 get_data3d(const unsigned char *pointer) {
2960 if (_column->get_num_values() == 4) {
2961 const LVecBase4d &v4 = get_data4d(pointer);
2962 _v3d.set(v4[0] / v4[3], v4[1] / v4[3], v4[2] / v4[3]);
2963 return _v3d;
2964 } else {
2965 return Packer::get_data3d(pointer);
2966 }
2967 }
2968
2969 /**
2970 *
2971 */
2972 const LVecBase4d &GeomVertexColumn::Packer_point::
2973 get_data4d(const unsigned char *pointer) {
2974 switch (_column->get_num_values()) {
2975 case 1:
2976 _v4d.set(get_data1d(pointer), 0.0f, 0.0f, 1.0f);
2977 return _v4d;
2978
2979 case 2:
2980 {
2981 const LVecBase2d &v2 = get_data2d(pointer);
2982 _v4d.set(v2[0], v2[1], 0.0f, 1.0f);
2983 }
2984 return _v4d;
2985
2986 case 3:
2987 {
2988 const LVecBase3d &v3 = get_data3d(pointer);
2989 _v4d.set(v3[0], v3[1], v3[2], 1.0f);
2990 }
2991 return _v4d;
2992
2993 default:
2994 switch (_column->get_numeric_type()) {
2995 case NT_uint8:
2996 {
2997 const uint8_t *pi = (const uint8_t *)pointer;
2998 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
2999 }
3000 return _v4d;
3001
3002 case NT_uint16:
3003 {
3004 const uint16_t *pi = (const uint16_t *)pointer;
3005 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3006 }
3007 return _v4d;
3008
3009 case NT_uint32:
3010 {
3011 const uint32_t *pi = (const uint32_t *)pointer;
3012 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3013 }
3014 return _v4d;
3015
3016 case NT_packed_dcba:
3017 {
3018 uint32_t dword = *(const uint32_t *)pointer;
3019 _v4d.set(GeomVertexData::unpack_abcd_d(dword),
3020 GeomVertexData::unpack_abcd_c(dword),
3021 GeomVertexData::unpack_abcd_b(dword),
3022 GeomVertexData::unpack_abcd_a(dword));
3023 }
3024 return _v4d;
3025
3026 case NT_packed_dabc:
3027 {
3028 uint32_t dword = *(const uint32_t *)pointer;
3029 _v4d.set(GeomVertexData::unpack_abcd_b(dword),
3030 GeomVertexData::unpack_abcd_c(dword),
3031 GeomVertexData::unpack_abcd_d(dword),
3032 GeomVertexData::unpack_abcd_a(dword));
3033 }
3034 return _v4d;
3035
3036 case NT_float32:
3037 {
3038 const PN_float32 *pi = (const PN_float32 *)pointer;
3039 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3040 }
3041 return _v4d;
3042
3043 case NT_float64:
3044 {
3045 const PN_float64 *pi = (const PN_float64 *)pointer;
3046 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3047 }
3048 return _v4d;
3049
3050 case NT_stdfloat:
3051 nassertr(false, _v4d);
3052 break;
3053
3054 case NT_int8:
3055 {
3056 const int8_t *pi = (const int8_t *)pointer;
3057 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3058 }
3059 return _v4d;
3060
3061 case NT_int16:
3062 {
3063 const int16_t *pi = (const int16_t *)pointer;
3064 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3065 }
3066 return _v4d;
3067
3068 case NT_int32:
3069 {
3070 const int32_t *pi = (const int32_t *)pointer;
3071 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3072 }
3073 return _v4d;
3074
3075 case NT_packed_ufloat:
3076 nassertr(false, _v4d);
3077 break;
3078 }
3079 }
3080
3081 return _v4d;
3082 }
3083
3084 /**
3085 *
3086 */
3087 void GeomVertexColumn::Packer_point::
3088 set_data1f(unsigned char *pointer, float data) {
3089 if (_column->get_num_values() == 4) {
3090 set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 1.0f));
3091 } else {
3092 Packer::set_data1f(pointer, data);
3093 }
3094 }
3095
3096 /**
3097 *
3098 */
3099 void GeomVertexColumn::Packer_point::
3100 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
3101 if (_column->get_num_values() == 4) {
3102 set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 1.0f));
3103 } else {
3104 Packer::set_data2f(pointer, data);
3105 }
3106 }
3107
3108 /**
3109 *
3110 */
3111 void GeomVertexColumn::Packer_point::
3112 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
3113 if (_column->get_num_values() == 4) {
3114 set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 1.0f));
3115 } else {
3116 Packer::set_data3f(pointer, data);
3117 }
3118 }
3119
3120 /**
3121 *
3122 */
3123 void GeomVertexColumn::Packer_point::
3124 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
3125 switch (_column->get_num_values()) {
3126 case 1:
3127 set_data1f(pointer, data[0] / data[3]);
3128 break;
3129
3130 case 2:
3131 set_data2f(pointer, LVecBase2f(data[0] / data[3], data[1] / data[3]));
3132 break;
3133
3134 case 3:
3135 set_data3f(pointer, LVecBase3f(data[0] / data[3], data[1] / data[3], data[2] / data[3]));
3136 break;
3137
3138 default:
3139 switch (_column->get_numeric_type()) {
3140 case NT_uint8:
3141 {
3142 uint8_t *pi = (uint8_t *)pointer;
3143 pi[0] = (unsigned int)data[0];
3144 pi[1] = (unsigned int)data[1];
3145 pi[2] = (unsigned int)data[2];
3146 pi[3] = (unsigned int)data[3];
3147 }
3148 break;
3149
3150 case NT_uint16:
3151 {
3152 uint16_t *pi = (uint16_t *)pointer;
3153 pi[0] = (unsigned int)data[0];
3154 pi[1] = (unsigned int)data[1];
3155 pi[2] = (unsigned int)data[2];
3156 pi[3] = (unsigned int)data[3];
3157 }
3158 break;
3159
3160 case NT_uint32:
3161 {
3162 uint32_t *pi = (uint32_t *)pointer;
3163 pi[0] = (unsigned int)data[0];
3164 pi[1] = (unsigned int)data[1];
3165 pi[2] = (unsigned int)data[2];
3166 pi[3] = (unsigned int)data[3];
3167 }
3168 break;
3169
3170 case NT_packed_dcba:
3171 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[2], data[1], data[0]);
3172 break;
3173
3174 case NT_packed_dabc:
3175 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[0], data[1], data[2]);
3176 break;
3177
3178 case NT_float32:
3179 {
3180 PN_float32 *pi = (PN_float32 *)pointer;
3181 pi[0] = data[0];
3182 pi[1] = data[1];
3183 pi[2] = data[2];
3184 pi[3] = data[3];
3185 }
3186 break;
3187
3188 case NT_float64:
3189 {
3190 PN_float64 *pi = (PN_float64 *)pointer;
3191 pi[0] = data[0];
3192 pi[1] = data[1];
3193 pi[2] = data[2];
3194 pi[3] = data[3];
3195 }
3196 break;
3197
3198 case NT_stdfloat:
3199 nassertv(false);
3200 break;
3201
3202 case NT_int8:
3203 {
3204 int8_t *pi = (int8_t *)pointer;
3205 pi[0] = (int)data[0];
3206 pi[1] = (int)data[1];
3207 pi[2] = (int)data[2];
3208 pi[3] = (int)data[3];
3209 }
3210 break;
3211
3212 case NT_int16:
3213 {
3214 int16_t *pi = (int16_t *)pointer;
3215 pi[0] = (int)data[0];
3216 pi[1] = (int)data[1];
3217 pi[2] = (int)data[2];
3218 pi[3] = (int)data[3];
3219 }
3220 break;
3221
3222 case NT_int32:
3223 {
3224 int32_t *pi = (int32_t *)pointer;
3225 pi[0] = (int)data[0];
3226 pi[1] = (int)data[1];
3227 pi[2] = (int)data[2];
3228 pi[3] = (int)data[3];
3229 }
3230 break;
3231
3232 case NT_packed_ufloat:
3233 nassertv(false);
3234 break;
3235 }
3236 break;
3237 }
3238 }
3239
3240 /**
3241 *
3242 */
3243 void GeomVertexColumn::Packer_point::
3244 set_data1d(unsigned char *pointer, double data) {
3245 if (_column->get_num_values() == 4) {
3246 set_data4d(pointer, LVecBase4d(data, 0.0f, 0.0f, 1.0f));
3247 } else {
3248 Packer::set_data1d(pointer, data);
3249 }
3250 }
3251
3252 /**
3253 *
3254 */
3255 void GeomVertexColumn::Packer_point::
3256 set_data2d(unsigned char *pointer, const LVecBase2d &data) {
3257 if (_column->get_num_values() == 4) {
3258 set_data4d(pointer, LVecBase4d(data[0], data[1], 0.0f, 1.0f));
3259 } else {
3260 Packer::set_data2d(pointer, data);
3261 }
3262 }
3263
3264 /**
3265 *
3266 */
3267 void GeomVertexColumn::Packer_point::
3268 set_data3d(unsigned char *pointer, const LVecBase3d &data) {
3269 if (_column->get_num_values() == 4) {
3270 set_data4d(pointer, LVecBase4d(data[0], data[1], data[2], 1.0f));
3271 } else {
3272 Packer::set_data3d(pointer, data);
3273 }
3274 }
3275
3276 /**
3277 *
3278 */
3279 void GeomVertexColumn::Packer_point::
3280 set_data4d(unsigned char *pointer, const LVecBase4d &data) {
3281 switch (_column->get_num_values()) {
3282 case 1:
3283 set_data1d(pointer, data[0] / data[3]);
3284 break;
3285
3286 case 2:
3287 set_data2d(pointer, LVecBase2d(data[0] / data[3], data[1] / data[3]));
3288 break;
3289
3290 case 3:
3291 set_data3d(pointer, LVecBase3d(data[0] / data[3], data[1] / data[3], data[2] / data[3]));
3292 break;
3293
3294 default:
3295 switch (_column->get_numeric_type()) {
3296 case NT_uint8:
3297 {
3298 uint8_t *pi = (uint8_t *)pointer;
3299 pi[0] = (unsigned int)data[0];
3300 pi[1] = (unsigned int)data[1];
3301 pi[2] = (unsigned int)data[2];
3302 pi[3] = (unsigned int)data[3];
3303 }
3304 break;
3305
3306 case NT_uint16:
3307 {
3308 uint16_t *pi = (uint16_t *)pointer;
3309 pi[0] = (unsigned int)data[0];
3310 pi[1] = (unsigned int)data[1];
3311 pi[2] = (unsigned int)data[2];
3312 pi[3] = (unsigned int)data[3];
3313 }
3314 break;
3315
3316 case NT_uint32:
3317 {
3318 uint32_t *pi = (uint32_t *)pointer;
3319 pi[0] = (unsigned int)data[0];
3320 pi[1] = (unsigned int)data[1];
3321 pi[2] = (unsigned int)data[2];
3322 pi[3] = (unsigned int)data[3];
3323 }
3324 break;
3325
3326 case NT_packed_dcba:
3327 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[2], data[1], data[0]);
3328 break;
3329
3330 case NT_packed_dabc:
3331 *(uint32_t *)pointer = GeomVertexData::pack_abcd(data[3], data[0], data[1], data[2]);
3332 break;
3333
3334 case NT_float32:
3335 {
3336 PN_float32 *pi = (PN_float32 *)pointer;
3337 pi[0] = data[0];
3338 pi[1] = data[1];
3339 pi[2] = data[2];
3340 pi[3] = data[3];
3341 }
3342 break;
3343
3344 case NT_float64:
3345 {
3346 PN_float64 *pi = (PN_float64 *)pointer;
3347 pi[0] = data[0];
3348 pi[1] = data[1];
3349 pi[2] = data[2];
3350 pi[3] = data[3];
3351 }
3352 break;
3353
3354 case NT_stdfloat:
3355 nassertv(false);
3356 break;
3357
3358 case NT_int8:
3359 {
3360 int8_t *pi = (int8_t *)pointer;
3361 pi[0] = (int)data[0];
3362 pi[1] = (int)data[1];
3363 pi[2] = (int)data[2];
3364 pi[3] = (int)data[3];
3365 }
3366 break;
3367
3368 case NT_int16:
3369 {
3370 int16_t *pi = (int16_t *)pointer;
3371 pi[0] = (int)data[0];
3372 pi[1] = (int)data[1];
3373 pi[2] = (int)data[2];
3374 pi[3] = (int)data[3];
3375 }
3376 break;
3377
3378 case NT_int32:
3379 {
3380 int32_t *pi = (int32_t *)pointer;
3381 pi[0] = (int)data[0];
3382 pi[1] = (int)data[1];
3383 pi[2] = (int)data[2];
3384 pi[3] = (int)data[3];
3385 }
3386 break;
3387
3388 case NT_packed_ufloat:
3389 nassertv(false);
3390 break;
3391 }
3392 break;
3393 }
3394 }
3395
3396 /**
3397 *
3398 */
3399 float GeomVertexColumn::Packer_color::
3400 get_data1f(const unsigned char *pointer) {
3401 switch (_column->get_numeric_type()) {
3402 case NT_uint8:
3403 return (*(const uint8_t *)pointer) / 255.0f;
3404
3405 case NT_uint16:
3406 return (*(const uint16_t *)pointer) / 65535.0f;
3407
3408 case NT_uint32:
3409 return (*(const uint32_t *)pointer) / 4294967295.0f;
3410
3411 case NT_packed_dcba:
3412 {
3413 uint32_t dword = *(const uint32_t *)pointer;
3414 return GeomVertexData::unpack_abcd_d(dword) / 255.0f;
3415 }
3416
3417 case NT_packed_dabc:
3418 {
3419 uint32_t dword = *(const uint32_t *)pointer;
3420 return GeomVertexData::unpack_abcd_b(dword) / 255.0f;
3421 }
3422
3423 case NT_float32:
3424 return *(const PN_float32 *)pointer;
3425
3426 case NT_float64:
3427 return *(const PN_float64 *)pointer;
3428
3429 default:
3430 nassertr(false, 0.0f);
3431 }
3432
3433 return 0.0f;
3434 }
3435
3436 /**
3437 *
3438 */
3439 const LVecBase2f &GeomVertexColumn::Packer_color::
3440 get_data2f(const unsigned char *pointer) {
3441 if (_column->get_num_values() == 3) {
3442 const LVecBase3f &v3 = get_data3f(pointer);
3443 _v2.set(v3[0], v3[1]);
3444 return _v2;
3445 } else {
3446 const LVecBase4f &v4 = get_data4f(pointer);
3447 _v2.set(v4[0], v4[1]);
3448 return _v2;
3449 }
3450 }
3451
3452 /**
3453 *
3454 */
3455 const LVecBase3f &GeomVertexColumn::Packer_color::
3456 get_data3f(const unsigned char *pointer) {
3457 if (_column->get_num_values() == 3) {
3458 switch (_column->get_numeric_type()) {
3459 case NT_uint8:
3460 {
3461 const uint8_t *pi = (const uint8_t *)pointer;
3462 _v3.set(pi[0], pi[1], pi[2]);
3463 _v3 /= 255.0f;
3464 }
3465 return _v3;
3466
3467 case NT_uint16:
3468 {
3469 const uint16_t *pi = (const uint16_t *)pointer;
3470 _v3.set(pi[0], pi[1], pi[2]);
3471 _v3 /= 65535.0f;
3472 }
3473 return _v3;
3474
3475 case NT_uint32:
3476 {
3477 const uint32_t *pi = (const uint32_t *)pointer;
3478 _v3.set(pi[0], pi[1], pi[2]);
3479 _v3 /= 4294967295.0f;
3480 }
3481 return _v3;
3482
3483 case NT_packed_dcba:
3484 case NT_packed_dabc:
3485 nassertr(false, _v3);
3486 return _v3;
3487
3488 case NT_float32:
3489 {
3490 const PN_float32 *pi = (const PN_float32 *)pointer;
3491 _v3.set(pi[0], pi[1], pi[2]);
3492 }
3493 return _v3;
3494
3495 case NT_float64:
3496 {
3497 const PN_float64 *pi = (const PN_float64 *)pointer;
3498 _v3.set(pi[0], pi[1], pi[2]);
3499 }
3500 return _v3;
3501
3502 case NT_stdfloat:
3503 case NT_int8:
3504 case NT_int16:
3505 case NT_int32:
3506 nassertr(false, _v3);
3507 return _v3;
3508
3509 case NT_packed_ufloat:
3510 {
3511 uint32_t dword = *(const uint32_t *)pointer;
3512 _v3.set(GeomVertexData::unpack_ufloat_a(dword),
3513 GeomVertexData::unpack_ufloat_b(dword),
3514 GeomVertexData::unpack_ufloat_c(dword));
3515 }
3516 return _v3;
3517 }
3518 } else {
3519 const LVecBase4f &v4 = get_data4f(pointer);
3520 _v3.set(v4[0], v4[1], v4[2]);
3521 return _v3;
3522 }
3523
3524 return _v3;
3525 }
3526
3527 /**
3528 *
3529 */
3530 const LVecBase4f &GeomVertexColumn::Packer_color::
3531 get_data4f(const unsigned char *pointer) {
3532 if (_column->get_num_values() == 3) {
3533 const LVecBase3f &v3 = get_data3f(pointer);
3534 _v4.set(v3[0], v3[1], v3[2], 1.0f);
3535 return _v4;
3536 } else {
3537 switch (_column->get_numeric_type()) {
3538 case NT_uint8:
3539 {
3540 const uint8_t *pi = (const uint8_t *)pointer;
3541 _v4.set(pi[0], pi[1], pi[2], pi[3]);
3542 _v4 /= 255.0f;
3543 }
3544 return _v4;
3545
3546 case NT_uint16:
3547 {
3548 const uint16_t *pi = (const uint16_t *)pointer;
3549 _v4.set(pi[0], pi[1], pi[2], pi[3]);
3550 _v4 /= 65535.0f;
3551 }
3552 return _v4;
3553
3554 case NT_uint32:
3555 {
3556 const uint32_t *pi = (const uint32_t *)pointer;
3557 _v4.set(pi[0], pi[1], pi[2], pi[3]);
3558 _v4 /= 4294967295.0f;
3559 }
3560 return _v4;
3561
3562 case NT_packed_dcba:
3563 {
3564 uint32_t dword = *(const uint32_t *)pointer;
3565 _v4.set(GeomVertexData::unpack_abcd_d(dword),
3566 GeomVertexData::unpack_abcd_c(dword),
3567 GeomVertexData::unpack_abcd_b(dword),
3568 GeomVertexData::unpack_abcd_a(dword));
3569 _v4 /= 255.0f;
3570 }
3571 return _v4;
3572
3573 case NT_packed_dabc:
3574 {
3575 uint32_t dword = *(const uint32_t *)pointer;
3576 _v4.set(GeomVertexData::unpack_abcd_b(dword),
3577 GeomVertexData::unpack_abcd_c(dword),
3578 GeomVertexData::unpack_abcd_d(dword),
3579 GeomVertexData::unpack_abcd_a(dword));
3580 _v4 /= 255.0f;
3581 }
3582 return _v4;
3583
3584 case NT_float32:
3585 {
3586 const PN_float32 *pi = (const PN_float32 *)pointer;
3587 _v4.set(pi[0], pi[1], pi[2], pi[3]);
3588 }
3589 return _v4;
3590
3591 case NT_float64:
3592 {
3593 const PN_float64 *pi = (const PN_float64 *)pointer;
3594 _v4.set(pi[0], pi[1], pi[2], pi[3]);
3595 }
3596 return _v4;
3597
3598 case NT_stdfloat:
3599 case NT_int8:
3600 case NT_int16:
3601 case NT_int32:
3602 case NT_packed_ufloat:
3603 nassertr(false, _v4);
3604 return _v4;
3605 }
3606 }
3607
3608 return _v4;
3609 }
3610
3611 /**
3612 *
3613 */
3614 double GeomVertexColumn::Packer_color::
3615 get_data1d(const unsigned char *pointer) {
3616 switch (_column->get_numeric_type()) {
3617 case NT_uint8:
3618 return (*(const uint8_t *)pointer) / 255.0;
3619
3620 case NT_uint16:
3621 return (*(const uint16_t *)pointer) / 65535.0;
3622
3623 case NT_uint32:
3624 return (*(const uint32_t *)pointer) / 4294967295.0;
3625
3626 case NT_packed_dcba:
3627 {
3628 uint32_t dword = *(const uint32_t *)pointer;
3629 return GeomVertexData::unpack_abcd_d(dword) / 255.0;
3630 }
3631
3632 case NT_packed_dabc:
3633 {
3634 uint32_t dword = *(const uint32_t *)pointer;
3635 return GeomVertexData::unpack_abcd_b(dword) / 255.0;
3636 }
3637
3638 case NT_float32:
3639 return *(const PN_float32 *)pointer;
3640
3641 case NT_float64:
3642 return *(const PN_float64 *)pointer;
3643
3644 default:
3645 nassertr(false, 0.0);
3646 }
3647
3648 return 0.0;
3649 }
3650
3651 /**
3652 *
3653 */
3654 const LVecBase2d &GeomVertexColumn::Packer_color::
3655 get_data2d(const unsigned char *pointer) {
3656 if (_column->get_num_values() == 3) {
3657 const LVecBase3d &v3 = get_data3d(pointer);
3658 _v2d.set(v3[0], v3[1]);
3659 return _v2d;
3660 } else {
3661 const LVecBase4d &v4 = get_data4d(pointer);
3662 _v2d.set(v4[0], v4[1]);
3663 return _v2d;
3664 }
3665 }
3666
3667 /**
3668 *
3669 */
3670 const LVecBase3d &GeomVertexColumn::Packer_color::
3671 get_data3d(const unsigned char *pointer) {
3672 if (_column->get_num_values() == 3) {
3673 switch (_column->get_numeric_type()) {
3674 case NT_uint8:
3675 {
3676 const uint8_t *pi = (const uint8_t *)pointer;
3677 _v3d.set(pi[0], pi[1], pi[2]);
3678 _v3d /= 255.0;
3679 }
3680 return _v3d;
3681
3682 case NT_uint16:
3683 {
3684 const uint16_t *pi = (const uint16_t *)pointer;
3685 _v3d.set(pi[0], pi[1], pi[2]);
3686 _v3d /= 65535.0;
3687 }
3688 return _v3d;
3689
3690 case NT_uint32:
3691 {
3692 const uint32_t *pi = (const uint32_t *)pointer;
3693 _v3d.set(pi[0], pi[1], pi[2]);
3694 _v3d /= 4294967295.0;
3695 }
3696 return _v3d;
3697
3698 case NT_packed_dcba:
3699 case NT_packed_dabc:
3700 nassertr(false, _v3d);
3701 return _v3d;
3702
3703 case NT_float32:
3704 {
3705 const PN_float32 *pi = (const PN_float32 *)pointer;
3706 _v3d.set(pi[0], pi[1], pi[2]);
3707 }
3708 return _v3d;
3709
3710 case NT_float64:
3711 {
3712 const PN_float64 *pi = (const PN_float64 *)pointer;
3713 _v3d.set(pi[0], pi[1], pi[2]);
3714 }
3715 return _v3d;
3716
3717 case NT_stdfloat:
3718 case NT_int8:
3719 case NT_int16:
3720 case NT_int32:
3721 nassertr(false, _v3d);
3722 return _v3d;
3723
3724 case NT_packed_ufloat:
3725 {
3726 uint32_t dword = *(const uint32_t *)pointer;
3727 _v3d.set(GeomVertexData::unpack_ufloat_a(dword),
3728 GeomVertexData::unpack_ufloat_b(dword),
3729 GeomVertexData::unpack_ufloat_c(dword));
3730 }
3731 return _v3d;
3732 }
3733 } else {
3734 const LVecBase4d &v4 = get_data4d(pointer);
3735 _v3d.set(v4[0], v4[1], v4[2]);
3736 return _v3d;
3737 }
3738
3739 return _v3d;
3740 }
3741
3742 /**
3743 *
3744 */
3745 const LVecBase4d &GeomVertexColumn::Packer_color::
3746 get_data4d(const unsigned char *pointer) {
3747 if (_column->get_num_values() == 3) {
3748 const LVecBase3d &v3 = get_data3d(pointer);
3749 _v4d.set(v3[0], v3[1], v3[2], 1.0);
3750 return _v4d;
3751 } else {
3752 switch (_column->get_numeric_type()) {
3753 case NT_uint8:
3754 {
3755 const uint8_t *pi = (const uint8_t *)pointer;
3756 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3757 _v4d /= 255.0;
3758 }
3759 return _v4d;
3760
3761 case NT_uint16:
3762 {
3763 const uint16_t *pi = (const uint16_t *)pointer;
3764 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3765 _v4d /= 65535.0;
3766 }
3767 return _v4d;
3768
3769 case NT_uint32:
3770 {
3771 const uint32_t *pi = (const uint32_t *)pointer;
3772 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3773 _v4d /= 4294967295.0;
3774 }
3775 return _v4d;
3776
3777 case NT_packed_dcba:
3778 {
3779 uint32_t dword = *(const uint32_t *)pointer;
3780 _v4d.set(GeomVertexData::unpack_abcd_d(dword),
3781 GeomVertexData::unpack_abcd_c(dword),
3782 GeomVertexData::unpack_abcd_b(dword),
3783 GeomVertexData::unpack_abcd_a(dword));
3784 _v4d /= 255.0;
3785 }
3786 return _v4d;
3787
3788 case NT_packed_dabc:
3789 {
3790 uint32_t dword = *(const uint32_t *)pointer;
3791 _v4d.set(GeomVertexData::unpack_abcd_b(dword),
3792 GeomVertexData::unpack_abcd_c(dword),
3793 GeomVertexData::unpack_abcd_d(dword),
3794 GeomVertexData::unpack_abcd_a(dword));
3795 _v4d /= 255.0;
3796 }
3797 return _v4d;
3798
3799 case NT_float32:
3800 {
3801 const PN_float32 *pi = (const PN_float32 *)pointer;
3802 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3803 }
3804 return _v4d;
3805
3806 case NT_float64:
3807 {
3808 const PN_float64 *pi = (const PN_float64 *)pointer;
3809 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
3810 }
3811 return _v4d;
3812
3813 case NT_stdfloat:
3814 case NT_int8:
3815 case NT_int16:
3816 case NT_int32:
3817 case NT_packed_ufloat:
3818 nassertr(false, _v4d);
3819 return _v4d;
3820 }
3821 }
3822
3823 return _v4d;
3824 }
3825
3826 /**
3827 *
3828 */
3829 void GeomVertexColumn::Packer_color::
3830 set_data1f(unsigned char *pointer, float data) {
3831 if (_column->get_num_values() == 3) {
3832 set_data3f(pointer, LVecBase3f(data, 0.0f, 0.0f));
3833 } else {
3834 set_data4f(pointer, LVecBase4f(data, 0.0f, 0.0f, 1.0f));
3835 }
3836 }
3837
3838 /**
3839 *
3840 */
3841 void GeomVertexColumn::Packer_color::
3842 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
3843 if (_column->get_num_values() == 3) {
3844 set_data3f(pointer, LVecBase3f(data[0], data[1], 0.0f));
3845 } else {
3846 set_data4f(pointer, LVecBase4f(data[0], data[1], 0.0f, 1.0f));
3847 }
3848 }
3849
3850 /**
3851 *
3852 */
3853 void GeomVertexColumn::Packer_color::
3854 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
3855 if (_column->get_num_values() == 3) {
3856 switch (_column->get_numeric_type()) {
3857 case NT_uint8:
3858 {
3859 LVecBase3f scaled = data * 255.0f;
3860 uint8_t *pi = (uint8_t *)pointer;
3861 pi[0] = (unsigned int)scaled[0];
3862 pi[1] = (unsigned int)scaled[1];
3863 pi[2] = (unsigned int)scaled[2];
3864 }
3865 break;
3866
3867 case NT_uint16:
3868 {
3869 LVecBase3f scaled = data * 65535.0f;
3870 uint16_t *pi = (uint16_t *)pointer;
3871 pi[0] = (unsigned int)scaled[0];
3872 pi[1] = (unsigned int)scaled[1];
3873 pi[2] = (unsigned int)scaled[2];
3874 }
3875 break;
3876
3877 case NT_uint32:
3878 {
3879 LVecBase3f scaled = data * 4294967295.0f;
3880 uint32_t *pi = (uint32_t *)pointer;
3881 pi[0] = (unsigned int)scaled[0];
3882 pi[1] = (unsigned int)scaled[1];
3883 pi[2] = (unsigned int)scaled[2];
3884 }
3885 break;
3886
3887 case NT_packed_dcba:
3888 {
3889 LVecBase3f scaled = data * 255.0f;
3890 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
3891 1.0f, scaled[2], scaled[1], scaled[0]);
3892 }
3893 break;
3894
3895 case NT_packed_dabc:
3896 {
3897 LVecBase3f scaled = data * 255.0f;
3898 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
3899 1.0f, scaled[0], scaled[1], scaled[2]);
3900 }
3901 break;
3902
3903 case NT_float32:
3904 {
3905 PN_float32 *pi = (PN_float32 *)pointer;
3906 pi[0] = data[0];
3907 pi[1] = data[1];
3908 pi[2] = data[2];
3909 }
3910 break;
3911
3912 case NT_float64:
3913 {
3914 PN_float64 *pi = (PN_float64 *)pointer;
3915 pi[0] = data[0];
3916 pi[1] = data[1];
3917 pi[2] = data[2];
3918 }
3919 break;
3920
3921 case NT_stdfloat:
3922 case NT_int8:
3923 case NT_int16:
3924 case NT_int32:
3925 nassertv(false);
3926 break;
3927
3928 case NT_packed_ufloat:
3929 *(uint32_t *)pointer = GeomVertexData::pack_ufloat(data[0], data[1], data[2]);
3930 break;
3931 }
3932 } else {
3933 set_data4f(pointer, LVecBase4f(data[0], data[1], data[2], 1.0f));
3934 }
3935 }
3936
3937 /**
3938 *
3939 */
3940 void GeomVertexColumn::Packer_color::
3941 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
3942 if (_column->get_num_values() == 3) {
3943 set_data3f(pointer, LVecBase3f(data[0], data[1], data[2]));
3944 } else {
3945 switch (_column->get_numeric_type()) {
3946 case NT_uint8:
3947 {
3948 LVecBase4f scaled = data * 255.0f;
3949 uint8_t *pi = (uint8_t *)pointer;
3950 pi[0] = (unsigned int)scaled[0];
3951 pi[1] = (unsigned int)scaled[1];
3952 pi[2] = (unsigned int)scaled[2];
3953 pi[3] = (unsigned int)scaled[3];
3954 }
3955 break;
3956
3957 case NT_uint16:
3958 {
3959 LVecBase4f scaled = data * 65535.0f;
3960 uint16_t *pi = (uint16_t *)pointer;
3961 pi[0] = (unsigned int)scaled[0];
3962 pi[1] = (unsigned int)scaled[1];
3963 pi[2] = (unsigned int)scaled[2];
3964 pi[3] = (unsigned int)scaled[3];
3965 }
3966 break;
3967
3968 case NT_uint32:
3969 {
3970 LVecBase4f scaled = data * 4294967295.0f;
3971 uint32_t *pi = (uint32_t *)pointer;
3972 pi[0] = (unsigned int)scaled[0];
3973 pi[1] = (unsigned int)scaled[1];
3974 pi[2] = (unsigned int)scaled[2];
3975 pi[3] = (unsigned int)scaled[3];
3976 }
3977 break;
3978
3979 case NT_packed_dcba:
3980 {
3981 LVecBase4f scaled = data * 255.0f;
3982 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
3983 scaled[3], scaled[2], scaled[1], scaled[0]);
3984 }
3985 break;
3986
3987 case NT_packed_dabc:
3988 {
3989 LVecBase4f scaled = data * 255.0f;
3990 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
3991 scaled[3], scaled[0], scaled[1], scaled[2]);
3992 }
3993 break;
3994
3995 case NT_float32:
3996 {
3997 PN_float32 *pi = (PN_float32 *)pointer;
3998 pi[0] = data[0];
3999 pi[1] = data[1];
4000 pi[2] = data[2];
4001 pi[3] = data[3];
4002 }
4003 break;
4004
4005 case NT_float64:
4006 {
4007 PN_float64 *pi = (PN_float64 *)pointer;
4008 pi[0] = data[0];
4009 pi[1] = data[1];
4010 pi[2] = data[2];
4011 pi[3] = data[3];
4012 }
4013 break;
4014
4015 case NT_stdfloat:
4016 case NT_int8:
4017 case NT_int16:
4018 case NT_int32:
4019 nassertv(false);
4020 break;
4021
4022 case NT_packed_ufloat:
4023 nassertv(false);
4024 break;
4025 }
4026 }
4027 }
4028
4029 /**
4030 *
4031 */
4032 void GeomVertexColumn::Packer_color::
4033 set_data1d(unsigned char *pointer, double data) {
4034 if (_column->get_num_values() == 3) {
4035 set_data3d(pointer, LVecBase3d(data, 0.0, 0.0));
4036 } else {
4037 set_data4d(pointer, LVecBase4d(data, 0.0, 0.0, 1.0));
4038 }
4039 }
4040
4041 /**
4042 *
4043 */
4044 void GeomVertexColumn::Packer_color::
4045 set_data2d(unsigned char *pointer, const LVecBase2d &data) {
4046 if (_column->get_num_values() == 3) {
4047 set_data3d(pointer, LVecBase3d(data[0], data[1], 0.0));
4048 } else {
4049 set_data4d(pointer, LVecBase4d(data[0], data[1], 0.0, 1.0));
4050 }
4051 }
4052
4053 /**
4054 *
4055 */
4056 void GeomVertexColumn::Packer_color::
4057 set_data3d(unsigned char *pointer, const LVecBase3d &data) {
4058 if (_column->get_num_values() == 3) {
4059 switch (_column->get_numeric_type()) {
4060 case NT_uint8:
4061 {
4062 LVecBase3d scaled = data * 255.0;
4063 uint8_t *pi = (uint8_t *)pointer;
4064 pi[0] = (unsigned int)scaled[0];
4065 pi[1] = (unsigned int)scaled[1];
4066 pi[2] = (unsigned int)scaled[2];
4067 }
4068 break;
4069
4070 case NT_uint16:
4071 {
4072 LVecBase3d scaled = data * 65535.0;
4073 uint16_t *pi = (uint16_t *)pointer;
4074 pi[0] = (unsigned int)scaled[0];
4075 pi[1] = (unsigned int)scaled[1];
4076 pi[2] = (unsigned int)scaled[2];
4077 }
4078 break;
4079
4080 case NT_uint32:
4081 {
4082 LVecBase3d scaled = data * 4294967295.0;
4083 uint32_t *pi = (uint32_t *)pointer;
4084 pi[0] = (unsigned int)scaled[0];
4085 pi[1] = (unsigned int)scaled[1];
4086 pi[2] = (unsigned int)scaled[2];
4087 }
4088 break;
4089
4090 case NT_packed_dcba:
4091 {
4092 LVecBase3d scaled = data * 255.0;
4093 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
4094 1.0, scaled[2], scaled[1], scaled[0]);
4095 }
4096 break;
4097
4098 case NT_packed_dabc:
4099 {
4100 LVecBase3d scaled = data * 255.0;
4101 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
4102 1.0, scaled[0], scaled[1], scaled[2]);
4103 }
4104 break;
4105
4106 case NT_float32:
4107 {
4108 PN_float32 *pi = (PN_float32 *)pointer;
4109 pi[0] = data[0];
4110 pi[1] = data[1];
4111 pi[2] = data[2];
4112 }
4113 break;
4114
4115 case NT_float64:
4116 {
4117 PN_float64 *pi = (PN_float64 *)pointer;
4118 pi[0] = data[0];
4119 pi[1] = data[1];
4120 pi[2] = data[2];
4121 }
4122 break;
4123
4124 case NT_stdfloat:
4125 case NT_int8:
4126 case NT_int16:
4127 case NT_int32:
4128 nassertv(false);
4129 break;
4130
4131 case NT_packed_ufloat:
4132 *(uint32_t *)pointer = GeomVertexData::pack_ufloat(data[0], data[1], data[2]);
4133 break;
4134 }
4135 } else {
4136 set_data4d(pointer, LVecBase4d(data[0], data[1], data[2], 1.0f));
4137 }
4138 }
4139
4140 /**
4141 *
4142 */
4143 void GeomVertexColumn::Packer_color::
4144 set_data4d(unsigned char *pointer, const LVecBase4d &data) {
4145 if (_column->get_num_values() == 3) {
4146 set_data3d(pointer, LVecBase3d(data[0], data[1], data[2]));
4147 } else {
4148 switch (_column->get_numeric_type()) {
4149 case NT_uint8:
4150 {
4151 LVecBase4d scaled = data * 255.0;
4152 uint8_t *pi = (uint8_t *)pointer;
4153 pi[0] = (unsigned int)scaled[0];
4154 pi[1] = (unsigned int)scaled[1];
4155 pi[2] = (unsigned int)scaled[2];
4156 pi[3] = (unsigned int)scaled[3];
4157 }
4158 break;
4159
4160 case NT_uint16:
4161 {
4162 LVecBase4d scaled = data * 65535.0;
4163 uint16_t *pi = (uint16_t *)pointer;
4164 pi[0] = (unsigned int)scaled[0];
4165 pi[1] = (unsigned int)scaled[1];
4166 pi[2] = (unsigned int)scaled[2];
4167 pi[3] = (unsigned int)scaled[3];
4168 }
4169 break;
4170
4171 case NT_uint32:
4172 {
4173 LVecBase4d scaled = data * 4294967295.0;
4174 uint32_t *pi = (uint32_t *)pointer;
4175 pi[0] = (unsigned int)scaled[0];
4176 pi[1] = (unsigned int)scaled[1];
4177 pi[2] = (unsigned int)scaled[2];
4178 pi[3] = (unsigned int)scaled[3];
4179 }
4180 break;
4181
4182 case NT_packed_dcba:
4183 {
4184 LVecBase4d scaled = data * 255.0;
4185 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
4186 scaled[3], scaled[2], scaled[1], scaled[0]);
4187 }
4188 break;
4189
4190 case NT_packed_dabc:
4191 {
4192 LVecBase4d scaled = data * 255.0;
4193 *(uint32_t *)pointer = GeomVertexData::pack_abcd(
4194 scaled[3], scaled[0], scaled[1], scaled[2]);
4195 }
4196 break;
4197
4198 case NT_float32:
4199 {
4200 PN_float32 *pi = (PN_float32 *)pointer;
4201 pi[0] = data[0];
4202 pi[1] = data[1];
4203 pi[2] = data[2];
4204 pi[3] = data[3];
4205 }
4206 break;
4207
4208 case NT_float64:
4209 {
4210 PN_float64 *pi = (PN_float64 *)pointer;
4211 pi[0] = data[0];
4212 pi[1] = data[1];
4213 pi[2] = data[2];
4214 pi[3] = data[3];
4215 }
4216 break;
4217
4218 case NT_stdfloat:
4219 case NT_int8:
4220 case NT_int16:
4221 case NT_int32:
4222 nassertv(false);
4223 break;
4224
4225 case NT_packed_ufloat:
4226 nassertv(false);
4227 break;
4228 }
4229 }
4230 }
4231
4232 /**
4233 *
4234 */
4235 const LVecBase3f &GeomVertexColumn::Packer_float32_3::
4236 get_data3f(const unsigned char *pointer) {
4237 const PN_float32 *pi = (const PN_float32 *)pointer;
4238 _v3.set(pi[0], pi[1], pi[2]);
4239 return _v3;
4240 }
4241
4242 /**
4243 *
4244 */
4245 void GeomVertexColumn::Packer_float32_3::
4246 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
4247 PN_float32 *pi = (PN_float32 *)pointer;
4248 pi[0] = data[0];
4249 pi[1] = data[1];
4250 pi[2] = data[2];
4251 }
4252
4253 /**
4254 *
4255 */
4256 const LVecBase2f &GeomVertexColumn::Packer_point_float32_2::
4257 get_data2f(const unsigned char *pointer) {
4258 const PN_float32 *pi = (const PN_float32 *)pointer;
4259 _v2.set(pi[0], pi[1]);
4260 return _v2;
4261 }
4262
4263 /**
4264 *
4265 */
4266 void GeomVertexColumn::Packer_point_float32_2::
4267 set_data2f(unsigned char *pointer, const LVecBase2f &data) {
4268 PN_float32 *pi = (PN_float32 *)pointer;
4269 pi[0] = data[0];
4270 pi[1] = data[1];
4271 }
4272
4273 /**
4274 *
4275 */
4276 const LVecBase3f &GeomVertexColumn::Packer_point_float32_3::
4277 get_data3f(const unsigned char *pointer) {
4278 const PN_float32 *pi = (const PN_float32 *)pointer;
4279 _v3.set(pi[0], pi[1], pi[2]);
4280 return _v3;
4281 }
4282
4283 /**
4284 *
4285 */
4286 void GeomVertexColumn::Packer_point_float32_3::
4287 set_data3f(unsigned char *pointer, const LVecBase3f &data) {
4288 PN_float32 *pi = (PN_float32 *)pointer;
4289 pi[0] = data[0];
4290 pi[1] = data[1];
4291 pi[2] = data[2];
4292 }
4293
4294 /**
4295 *
4296 */
4297 const LVecBase4f &GeomVertexColumn::Packer_point_float32_4::
4298 get_data4f(const unsigned char *pointer) {
4299 const PN_float32 *pi = (const PN_float32 *)pointer;
4300 _v4.set(pi[0], pi[1], pi[2], pi[3]);
4301 return _v4;
4302 }
4303
4304 /**
4305 *
4306 */
4307 void GeomVertexColumn::Packer_point_float32_4::
4308 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
4309 PN_float32 *pi = (PN_float32 *)pointer;
4310 pi[0] = data[0];
4311 pi[1] = data[1];
4312 pi[2] = data[2];
4313 pi[3] = data[3];
4314 }
4315
4316 /**
4317 *
4318 */
4319 const LVecBase3f &GeomVertexColumn::Packer_nativefloat_3::
4320 get_data3f(const unsigned char *pointer) {
4321 return *(const LVecBase3f *)pointer;
4322 }
4323
4324 /**
4325 *
4326 */
4327 const LVecBase2f &GeomVertexColumn::Packer_point_nativefloat_2::
4328 get_data2f(const unsigned char *pointer) {
4329 return *(const LVecBase2f *)pointer;
4330 }
4331
4332 /**
4333 *
4334 */
4335 const LVecBase3f &GeomVertexColumn::Packer_point_nativefloat_3::
4336 get_data3f(const unsigned char *pointer) {
4337 return *(const LVecBase3f *)pointer;
4338 }
4339
4340 /**
4341 *
4342 */
4343 const LVecBase4f &GeomVertexColumn::Packer_point_nativefloat_4::
4344 get_data4f(const unsigned char *pointer) {
4345 return *(const LVecBase4f *)pointer;
4346 }
4347
4348 /**
4349 *
4350 */
4351 const LVecBase3d &GeomVertexColumn::Packer_float64_3::
4352 get_data3d(const unsigned char *pointer) {
4353 const PN_float64 *pi = (const PN_float64 *)pointer;
4354 _v3d.set(pi[0], pi[1], pi[2]);
4355 return _v3d;
4356 }
4357
4358 /**
4359 *
4360 */
4361 void GeomVertexColumn::Packer_float64_3::
4362 set_data3d(unsigned char *pointer, const LVecBase3d &data) {
4363 PN_float64 *pi = (PN_float64 *)pointer;
4364 pi[0] = data[0];
4365 pi[1] = data[1];
4366 pi[2] = data[2];
4367 }
4368
4369 /**
4370 *
4371 */
4372 const LVecBase2d &GeomVertexColumn::Packer_point_float64_2::
4373 get_data2d(const unsigned char *pointer) {
4374 const PN_float64 *pi = (const PN_float64 *)pointer;
4375 _v2d.set(pi[0], pi[1]);
4376 return _v2d;
4377 }
4378
4379 /**
4380 *
4381 */
4382 void GeomVertexColumn::Packer_point_float64_2::
4383 set_data2d(unsigned char *pointer, const LVecBase2d &data) {
4384 PN_float64 *pi = (PN_float64 *)pointer;
4385 pi[0] = data[0];
4386 pi[1] = data[1];
4387 }
4388
4389 /**
4390 *
4391 */
4392 const LVecBase3d &GeomVertexColumn::Packer_point_float64_3::
4393 get_data3d(const unsigned char *pointer) {
4394 const PN_float64 *pi = (const PN_float64 *)pointer;
4395 _v3d.set(pi[0], pi[1], pi[2]);
4396 return _v3d;
4397 }
4398
4399 /**
4400 *
4401 */
4402 void GeomVertexColumn::Packer_point_float64_3::
4403 set_data3d(unsigned char *pointer, const LVecBase3d &data) {
4404 PN_float64 *pi = (PN_float64 *)pointer;
4405 pi[0] = data[0];
4406 pi[1] = data[1];
4407 pi[2] = data[2];
4408 }
4409
4410 /**
4411 *
4412 */
4413 const LVecBase4d &GeomVertexColumn::Packer_point_float64_4::
4414 get_data4d(const unsigned char *pointer) {
4415 const PN_float64 *pi = (const PN_float64 *)pointer;
4416 _v4d.set(pi[0], pi[1], pi[2], pi[3]);
4417 return _v4d;
4418 }
4419
4420 /**
4421 *
4422 */
4423 void GeomVertexColumn::Packer_point_float64_4::
4424 set_data4d(unsigned char *pointer, const LVecBase4d &data) {
4425 PN_float64 *pi = (PN_float64 *)pointer;
4426 pi[0] = data[0];
4427 pi[1] = data[1];
4428 pi[2] = data[2];
4429 pi[3] = data[3];
4430 }
4431
4432 /**
4433 *
4434 */
4435 const LVecBase3d &GeomVertexColumn::Packer_nativedouble_3::
4436 get_data3d(const unsigned char *pointer) {
4437 return *(const LVecBase3d *)pointer;
4438 }
4439
4440 /**
4441 *
4442 */
4443 const LVecBase2d &GeomVertexColumn::Packer_point_nativedouble_2::
4444 get_data2d(const unsigned char *pointer) {
4445 return *(const LVecBase2d *)pointer;
4446 }
4447
4448 /**
4449 *
4450 */
4451 const LVecBase3d &GeomVertexColumn::Packer_point_nativedouble_3::
4452 get_data3d(const unsigned char *pointer) {
4453 return *(const LVecBase3d *)pointer;
4454 }
4455
4456 /**
4457 *
4458 */
4459 const LVecBase4d &GeomVertexColumn::Packer_point_nativedouble_4::
4460 get_data4d(const unsigned char *pointer) {
4461 return *(const LVecBase4d *)pointer;
4462 }
4463
4464 /**
4465 *
4466 */
4467 const LVecBase4f &GeomVertexColumn::Packer_argb_packed::
4468 get_data4f(const unsigned char *pointer) {
4469 uint32_t dword = *(const uint32_t *)pointer;
4470 _v4.set(GeomVertexData::unpack_abcd_b(dword),
4471 GeomVertexData::unpack_abcd_c(dword),
4472 GeomVertexData::unpack_abcd_d(dword),
4473 GeomVertexData::unpack_abcd_a(dword));
4474 _v4 /= 255.0f;
4475 return _v4;
4476 }
4477
4478 /**
4479 *
4480 */
4481 void GeomVertexColumn::Packer_argb_packed::
4482 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
4483 // when packing an argb, we want to make sure we cap the input values at 1
4484 // since going above one will cause the value to be truncated.
4485 *(uint32_t *)pointer = GeomVertexData::pack_abcd
4486 ((unsigned int)(min(max(data[3], 0.0f), 1.0f) * 255.0f),
4487 (unsigned int)(min(max(data[0], 0.0f), 1.0f) * 255.0f),
4488 (unsigned int)(min(max(data[1], 0.0f), 1.0f) * 255.0f),
4489 (unsigned int)(min(max(data[2], 0.0f), 1.0f) * 255.0f));
4490 }
4491
4492 /**
4493 *
4494 */
4495 const LVecBase4f &GeomVertexColumn::Packer_rgba_uint8_4::
4496 get_data4f(const unsigned char *pointer) {
4497 _v4.set((float)pointer[0], (float)pointer[1],
4498 (float)pointer[2], (float)pointer[3]);
4499 _v4 /= 255.0f;
4500 return _v4;
4501 }
4502
4503 /**
4504 *
4505 */
4506 void GeomVertexColumn::Packer_rgba_uint8_4::
4507 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
4508 pointer[0] = (unsigned int)(min(max(data[0], 0.0f), 1.0f) * 255.0f);
4509 pointer[1] = (unsigned int)(min(max(data[1], 0.0f), 1.0f) * 255.0f);
4510 pointer[2] = (unsigned int)(min(max(data[2], 0.0f), 1.0f) * 255.0f);
4511 pointer[3] = (unsigned int)(min(max(data[3], 0.0f), 1.0f) * 255.0f);
4512 }
4513
4514 /**
4515 *
4516 */
4517 const LVecBase4f &GeomVertexColumn::Packer_rgba_float32_4::
4518 get_data4f(const unsigned char *pointer) {
4519 const PN_float32 *pi = (const PN_float32 *)pointer;
4520 _v4.set(pi[0], pi[1], pi[2], pi[3]);
4521 return _v4;
4522 }
4523
4524 /**
4525 *
4526 */
4527 void GeomVertexColumn::Packer_rgba_float32_4::
4528 set_data4f(unsigned char *pointer, const LVecBase4f &data) {
4529 PN_float32 *pi = (PN_float32 *)pointer;
4530 pi[0] = data[0];
4531 pi[1] = data[1];
4532 pi[2] = data[2];
4533 pi[3] = data[3];
4534 }
4535
4536 /**
4537 *
4538 */
4539 const LVecBase4f &GeomVertexColumn::Packer_rgba_nativefloat_4::
4540 get_data4f(const unsigned char *pointer) {
4541 return *(const LVecBase4f *)pointer;
4542 }
4543
4544 /**
4545 *
4546 */
4547 int GeomVertexColumn::Packer_uint16_1::
4548 get_data1i(const unsigned char *pointer) {
4549 return *(const uint16_t *)pointer;
4550 }
4551
4552 /**
4553 *
4554 */
4555 void GeomVertexColumn::Packer_uint16_1::
4556 set_data1i(unsigned char *pointer, int data) {
4557 *(uint16_t *)pointer = data;
4558 nassertv(*(uint16_t *)pointer == data);
4559 }
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
BamReader::read_pointer
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
BamReader::get_file_minor_ver
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition: bamReader.I:83
BamWriter
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
BamWriter::write_pointer
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:317
BamWriter::get_file_minor_ver
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
Definition: bamWriter.I:59
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
DatagramIterator::get_uint8
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
Definition: datagramIterator.I:72
DatagramIterator::get_uint16
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
Definition: datagramIterator.I:145
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
Datagram::add_uint8
void add_uint8(uint8_t value)
Adds an unsigned 8-bit integer to the datagram.
Definition: datagram.I:50
Datagram::add_uint16
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:85
GeomVertexColumn
This defines how a single column is interleaved within a vertex array stored within a Geom.
Definition: geomVertexColumn.h:37
GeomVertexColumn::get_num_values
int get_num_values() const
Returns the number of numeric values of the column: the number of distinct numeric values that go int...
Definition: geomVertexColumn.I:99
GeomVertexColumn::fillin
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...
Definition: geomVertexColumn.cxx:430
GeomVertexColumn::get_start
int get_start() const
Returns the byte within the array record at which this column starts.
Definition: geomVertexColumn.I:133
GeomVertexColumn::set_column_alignment
void set_column_alignment(int column_alignment)
Changes the column alignment of an existing column.
Definition: geomVertexColumn.cxx:94
GeomVertexColumn::get_numeric_type
NumericType get_numeric_type() const
Returns the token representing the numeric type of the data storage.
Definition: geomVertexColumn.I:116
GeomVertexColumn::write_datagram
void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: geomVertexColumn.cxx:386
GeomVertexColumn::set_name
void set_name(InternalName *name)
Replaces the name of an existing column.
Definition: geomVertexColumn.cxx:44
GeomVertexColumn::complete_pointers
int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition: geomVertexColumn.cxx:410
GeomVertexColumn::set_numeric_type
void set_numeric_type(NumericType numeric_type)
Changes the numeric type an existing column.
Definition: geomVertexColumn.cxx:64
GeomVertexColumn::get_name
const InternalName * get_name() const
Returns the name of this particular data field, e.g.
Definition: geomVertexColumn.I:77
GeomVertexColumn::set_contents
void set_contents(Contents contents)
Changes the semantic meaning of an existing column.
Definition: geomVertexColumn.cxx:74
GeomVertexColumn::set_start
void set_start(int start)
Changes the start byte of an existing column.
Definition: geomVertexColumn.cxx:84
GeomVertexColumn::set_num_components
void set_num_components(int num_components)
Changes the number of components of an existing column.
Definition: geomVertexColumn.cxx:54
GeomVertexColumn::get_contents
Contents get_contents() const
Returns the token representing the semantic meaning of the stored value.
Definition: geomVertexColumn.I:124
GeomVertexColumn::get_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...
Definition: geomVertexColumn.I:87
GeomVertexData::pack_ufloat
static uint32_t pack_ufloat(float a, float b, float c)
Packs three float values in an unsigned 32-bit int.
Definition: geomVertexData.I:353
GeomVertexData::unpack_ufloat_c
static float unpack_ufloat_c(uint32_t data)
Unpacks an unsigned float10 value from an uint32.
Definition: geomVertexData.I:461
GeomVertexData::unpack_ufloat_a
static float unpack_ufloat_a(uint32_t data)
Unpacks an unsigned float11 value from an uint32.
Definition: geomVertexData.I:409
GeomVertexData::unpack_ufloat_b
static float unpack_ufloat_b(uint32_t data)
Unpacks an unsigned float11 value from an uint32.
Definition: geomVertexData.I:435
GeomVertexData::unpack_abcd_b
static unsigned int unpack_abcd_b(uint32_t data)
Returns the second packed value from a DirectX-style NT_packed_abcd.
Definition: geomVertexData.I:329
GeomVertexData::unpack_abcd_a
static unsigned int unpack_abcd_a(uint32_t data)
Returns the first packed value from a DirectX-style NT_packed_abcd.
Definition: geomVertexData.I:321
GeomVertexData::pack_abcd
static uint32_t pack_abcd(unsigned int a, unsigned int b, unsigned int c, unsigned int d)
Packs four values in a DirectX-style NT_packed_abcd value.
Definition: geomVertexData.I:309
GeomVertexData::unpack_abcd_c
static unsigned int unpack_abcd_c(uint32_t data)
Returns the third packed value from a DirectX-style NT_packed_abcd.
Definition: geomVertexData.I:337
GeomVertexData::unpack_abcd_d
static unsigned int unpack_abcd_d(uint32_t data)
Returns the fourth packed value from a DirectX-style NT_packed_abcd.
Definition: geomVertexData.I:345
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition: internalName.h:38
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
geomVertexColumn.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
geomVertexData.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.