Panda3D
geomVertexReader.I
1 // Filename: geomVertexReader.I
2 // Created by: drose (25Mar05)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GeomVertexReader::Default Constructor
18 // Access: Published
19 // Description: Constructs an invalid GeomVertexReader. You must use
20 // the assignment operator to assign a valid
21 // GeomVertexReader to this object before you can use
22 // it.
23 ////////////////////////////////////////////////////////////////////
24 INLINE GeomVertexReader::
25 GeomVertexReader(Thread *current_thread) :
26  _vertex_data(NULL),
27  _current_thread(current_thread)
28 {
29  initialize();
30 }
31 
32 ////////////////////////////////////////////////////////////////////
33 // Function: GeomVertexReader::Constructor
34 // Access: Published
35 // Description: Constructs a new reader to process the vertices of
36 // the indicated data object.
37 ////////////////////////////////////////////////////////////////////
38 INLINE GeomVertexReader::
39 GeomVertexReader(const GeomVertexData *vertex_data,
40  Thread *current_thread) :
41  _vertex_data(vertex_data),
42  _current_thread(current_thread)
43 {
44  initialize();
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function: GeomVertexReader::Constructor
49 // Access: Published
50 // Description: Constructs a new reader to process the vertices of
51 // the indicated data object. This flavor creates the
52 // reader specifically to process the named data type.
53 ////////////////////////////////////////////////////////////////////
54 INLINE GeomVertexReader::
55 GeomVertexReader(const GeomVertexData *vertex_data,
56  CPT_InternalName name,
57  Thread *current_thread) :
58  _vertex_data(vertex_data),
59  _current_thread(current_thread)
60 {
61  initialize();
62  set_column(MOVE(name));
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: GeomVertexReader::Constructor
67 // Access: Published
68 // Description: Constructs a new reader to process the vertices of
69 // the indicated array only.
70 ////////////////////////////////////////////////////////////////////
71 INLINE GeomVertexReader::
73  Thread *current_thread) :
74  _array_data(array_data),
75  _current_thread(current_thread)
76 {
77  initialize();
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: GeomVertexReader::Constructor
82 // Access: Published
83 // Description: Constructs a new reader to process the vertices of
84 // the indicated array only.
85 ////////////////////////////////////////////////////////////////////
86 INLINE GeomVertexReader::
87 GeomVertexReader(const GeomVertexArrayData *array_data, int column,
88  Thread *current_thread) :
89  _array_data(array_data),
90  _current_thread(current_thread)
91 {
92  initialize();
93  set_column(column);
94 }
95 
96 ////////////////////////////////////////////////////////////////////
97 // Function: GeomVertexReader::Constructor
98 // Access: Public
99 // Description: Constructs a new reader to process the vertices of
100 // the indicated data object. This flavor creates the
101 // reader specifically to process the named data type.
102 ////////////////////////////////////////////////////////////////////
103 INLINE GeomVertexReader::
105  const InternalName *name, bool force) :
106  _vertex_data(data_reader->get_object()),
107  _current_thread(data_reader->get_current_thread())
108 {
109  initialize();
110  _force = force;
111  const GeomVertexFormat *format = data_reader->get_format();
112  set_vertex_column(format->get_array_with(name),
113  format->get_column(name),
114  data_reader);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: GeomVertexReader::Copy Constructor
119 // Access: Published
120 // Description:
121 ////////////////////////////////////////////////////////////////////
122 INLINE GeomVertexReader::
123 GeomVertexReader(const GeomVertexReader &copy) :
124  _vertex_data(copy._vertex_data),
125  _array(copy._array),
126  _array_data(copy._array_data),
127  _current_thread(copy._current_thread),
128  _packer(copy._packer),
129  _stride(copy._stride),
130  _handle(copy._handle),
131  _pointer_begin(copy._pointer_begin),
132  _pointer_end(copy._pointer_end),
133  _pointer(copy._pointer),
134  _start_row(copy._start_row),
135  _force(copy._force)
136 {
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: GeomVertexReader::Copy Assignment Operator
141 // Access: Published
142 // Description:
143 ////////////////////////////////////////////////////////////////////
144 INLINE void GeomVertexReader::
145 operator = (const GeomVertexReader &copy) {
146  _vertex_data = copy._vertex_data;
147  _array = copy._array;
148  _array_data = copy._array_data;
149  _current_thread = copy._current_thread;
150  _packer = copy._packer;
151  _stride = copy._stride;
152  _handle = copy._handle;
153  _pointer_begin = copy._pointer_begin;
154  _pointer_end = copy._pointer_end;
155  _pointer = copy._pointer;
156  _start_row = copy._start_row;
157  _force = copy._force;
158 }
159 
160 ////////////////////////////////////////////////////////////////////
161 // Function: GeomVertexReader::Destructor
162 // Access: Published
163 // Description:
164 ////////////////////////////////////////////////////////////////////
165 INLINE GeomVertexReader::
166 ~GeomVertexReader() {
167 }
168 
169 ////////////////////////////////////////////////////////////////////
170 // Function: GeomVertexReader::get_vertex_data
171 // Access: Published
172 // Description: Returns the vertex data object that the
173 // reader is processing. This may return NULL if the
174 // reader was constructed with just an array pointer.
175 ////////////////////////////////////////////////////////////////////
178  return _vertex_data;
179 }
180 
181 ////////////////////////////////////////////////////////////////////
182 // Function: GeomVertexReader::get_array_data
183 // Access: Published
184 // Description: Returns the particular array object that the
185 // reader is currently processing.
186 ////////////////////////////////////////////////////////////////////
188 get_array_data() const {
189  return _array_data;
190 }
191 
192 ////////////////////////////////////////////////////////////////////
193 // Function: GeomVertexReader::get_array_handle
194 // Access: Published
195 // Description: Returns the read handle to the array object that the
196 // read is currently processing. This low-level call
197 // should be used with caution.
198 ////////////////////////////////////////////////////////////////////
201  return _handle;
202 }
203 
204 ////////////////////////////////////////////////////////////////////
205 // Function: GeomVertexReader::get_stride
206 // Access: Published
207 // Description: Returns the per-row stride (bytes between consecutive
208 // rows) of the underlying vertex array. This low-level
209 // information is normally not needed to use the
210 // GeomVertexReader directly.
211 ////////////////////////////////////////////////////////////////////
212 INLINE size_t GeomVertexReader::
213 get_stride() const {
214  return _stride;
215 }
216 
217 ////////////////////////////////////////////////////////////////////
218 // Function: GeomVertexReader::get_current_thread
219 // Access: Published
220 // Description: Returns the Thread pointer of the currently-executing
221 // thread, as passed to the constructor of this object.
222 ////////////////////////////////////////////////////////////////////
225  return _current_thread;
226 }
227 
228 ////////////////////////////////////////////////////////////////////
229 // Function: GeomVertexReader::set_force
230 // Access: Published
231 // Description: Sets the value of the force flag. When this is true
232 // (the default), vertex data will be paged in from disk
233 // if necessary. When this is false, the GeomVertexData
234 // will simply return a failure code when attempting to
235 // read vertex data that is not resident (but will put
236 // it on the queue to become resident later).
237 //
238 // Normally, vertex data is always resident, so this
239 // will not be an issue. It is only possible for vertex
240 // data to be nonresident if you have enabled vertex
241 // paging via the GeomVertexArrayData and VertexDataPage
242 // interfaces.
243 ////////////////////////////////////////////////////////////////////
244 INLINE void GeomVertexReader::
245 set_force(bool force) {
246  _force = force;
247 }
248 
249 ////////////////////////////////////////////////////////////////////
250 // Function: GeomVertexReader::get_force
251 // Access: Published
252 // Description: Returns the value of the force flag. See
253 // set_force().
254 ////////////////////////////////////////////////////////////////////
255 INLINE bool GeomVertexReader::
256 get_force() const {
257  return _force;
258 }
259 
260 ////////////////////////////////////////////////////////////////////
261 // Function: GeomVertexReader::set_column
262 // Access: Published
263 // Description: Sets up the reader to use the nth data type of the
264 // GeomVertexFormat, numbering from 0.
265 //
266 // This also resets the read row number to the start row
267 // (the same value passed to a previous call to
268 // set_row(), or 0 if set_row() was never called.)
269 //
270 // The return value is true if the data type is valid,
271 // false otherwise.
272 ////////////////////////////////////////////////////////////////////
273 INLINE bool GeomVertexReader::
274 set_column(int column) {
275  if (_vertex_data != (const GeomVertexData *)NULL) {
276  GeomVertexDataPipelineReader reader(_vertex_data, _current_thread);
277  reader.check_array_readers();
278  const GeomVertexFormat *format = reader.get_format();
279  return set_vertex_column(format->get_array_with(column),
280  format->get_column(column),
281  &reader);
282  }
283  if (_array_data != (const GeomVertexArrayData *)NULL) {
284  return set_array_column(_array_data->get_array_format()->get_column(column));
285  }
286  return false;
287 }
288 
289 ////////////////////////////////////////////////////////////////////
290 // Function: GeomVertexReader::set_column
291 // Access: Published
292 // Description: Sets up the reader to use the data type with the
293 // indicated name.
294 //
295 // This also resets the read row number to the start row
296 // (the same value passed to a previous call to
297 // set_row(), or 0 if set_row() was never called.)
298 //
299 // The return value is true if the data type is valid,
300 // false otherwise.
301 ////////////////////////////////////////////////////////////////////
302 INLINE bool GeomVertexReader::
304  if (_vertex_data != (const GeomVertexData *)NULL) {
305  GeomVertexDataPipelineReader reader(_vertex_data, _current_thread);
306  reader.check_array_readers();
307  const GeomVertexFormat *format = reader.get_format();
308  return set_vertex_column(format->get_array_with(name),
309  format->get_column(name),
310  &reader);
311  }
312  if (_array_data != (const GeomVertexArrayData *)NULL) {
313  return set_array_column(_array_data->get_array_format()->get_column(name));
314  }
315 
316  return false;
317 }
318 
319 ////////////////////////////////////////////////////////////////////
320 // Function: GeomVertexReader::clear
321 // Access: Published
322 // Description: Resets the GeomVertexReader to the initial state.
323 ////////////////////////////////////////////////////////////////////
324 INLINE void GeomVertexReader::
325 clear() {
326  (*this) = GeomVertexReader(_current_thread);
327 }
328 
329 ////////////////////////////////////////////////////////////////////
330 // Function: GeomVertexReader::has_column
331 // Access: Published
332 // Description: Returns true if a valid data type has been
333 // successfully set, or false if the data type does not
334 // exist (or if get_force() is false and the vertex data
335 // is nonresident).
336 ////////////////////////////////////////////////////////////////////
337 INLINE bool GeomVertexReader::
338 has_column() const {
339  return (_packer != (GeomVertexColumn::Packer *)NULL);
340 }
341 
342 ////////////////////////////////////////////////////////////////////
343 // Function: GeomVertexReader::get_array
344 // Access: Published
345 // Description: Returns the array index containing the data type that
346 // the reader is working on.
347 ////////////////////////////////////////////////////////////////////
348 INLINE int GeomVertexReader::
349 get_array() const {
350  return _array;
351 }
352 
353 ////////////////////////////////////////////////////////////////////
354 // Function: GeomVertexReader::get_column
355 // Access: Published
356 // Description: Returns the description of the data type that the
357 // reader is working on.
358 ////////////////////////////////////////////////////////////////////
360 get_column() const {
361  if (_packer != (GeomVertexColumn::Packer *)NULL) {
362  return _packer->_column;
363  }
364  return NULL;
365 }
366 
367 ////////////////////////////////////////////////////////////////////
368 // Function: GeomVertexReader::set_row_unsafe
369 // Access: Published
370 // Description: Sets the start row to the indicated value, without
371 // internal checks. This is the same as set_row(), but
372 // it does not check for the possibility that the array
373 // has been reallocated internally for some reason; use
374 // only when you are confident that the array is
375 // unchanged and you really need every bit of available
376 // performance.
377 ////////////////////////////////////////////////////////////////////
378 INLINE void GeomVertexReader::
379 set_row_unsafe(int row) {
380  _start_row = row;
381  if (has_column()) {
382  quick_set_pointer(_start_row);
383  }
384 }
385 
386 ////////////////////////////////////////////////////////////////////
387 // Function: GeomVertexReader::set_row
388 // Access: Published
389 // Description: Sets the start row to the indicated value. The
390 // reader will begin reading from the indicated row;
391 // each subsequent get_data*() call will return the data
392 // from the subsequent row. If set_column() is called,
393 // the reader will return to this row.
394 ////////////////////////////////////////////////////////////////////
395 INLINE void GeomVertexReader::
396 set_row(int row) {
397  _start_row = row;
398  if (has_column()) {
399  bool result = set_pointer(_start_row);
400  nassertv(result);
401  }
402 }
403 
404 ////////////////////////////////////////////////////////////////////
405 // Function: GeomVertexReader::get_start_row
406 // Access: Published
407 // Description: Returns the row index at which the reader started.
408 // It will return to this row if you reset the current
409 // column.
410 ////////////////////////////////////////////////////////////////////
411 INLINE int GeomVertexReader::
412 get_start_row() const {
413  return _start_row;
414 }
415 
416 ////////////////////////////////////////////////////////////////////
417 // Function: GeomVertexReader::get_read_row
418 // Access: Published
419 // Description: Returns the row index from which the data will be
420 // retrieved by the next call to get_data*().
421 ////////////////////////////////////////////////////////////////////
422 INLINE int GeomVertexReader::
423 get_read_row() const {
424  return (int)(_pointer - _pointer_begin) / _stride;
425 }
426 
427 ////////////////////////////////////////////////////////////////////
428 // Function: GeomVertexReader::is_at_end
429 // Access: Published
430 // Description: Returns true if the reader is currently at the end of
431 // the list of vertices, false otherwise. If this is
432 // true, another call to get_data*() will result in a
433 // crash.
434 ////////////////////////////////////////////////////////////////////
435 INLINE bool GeomVertexReader::
436 is_at_end() const {
437  return _pointer >= _pointer_end;
438 }
439 
440 ////////////////////////////////////////////////////////////////////
441 // Function: GeomVertexReader::get_data1f
442 // Access: Published
443 // Description: Returns the data associated with the read row,
444 // expressed as a 1-component value, and advances the
445 // read row.
446 ////////////////////////////////////////////////////////////////////
447 INLINE float GeomVertexReader::
449  nassertr(has_column(), 0.0f);
450  return _packer->get_data1f(inc_pointer());
451 }
452 
453 ////////////////////////////////////////////////////////////////////
454 // Function: GeomVertexReader::get_data2f
455 // Access: Published
456 // Description: Returns the data associated with the read row,
457 // expressed as a 2-component value, and advances the
458 // read row.
459 ////////////////////////////////////////////////////////////////////
460 INLINE const LVecBase2f &GeomVertexReader::
462  nassertr(has_column(), LVecBase2f::zero());
463  return _packer->get_data2f(inc_pointer());
464 }
465 
466 ////////////////////////////////////////////////////////////////////
467 // Function: GeomVertexReader::get_data3f
468 // Access: Published
469 // Description: Returns the data associated with the read row,
470 // expressed as a 3-component value, and advances the
471 // read row.
472 ////////////////////////////////////////////////////////////////////
473 INLINE const LVecBase3f &GeomVertexReader::
475  nassertr(has_column(), LVecBase3f::zero());
476  return _packer->get_data3f(inc_pointer());
477 }
478 
479 ////////////////////////////////////////////////////////////////////
480 // Function: GeomVertexReader::get_data4f
481 // Access: Published
482 // Description: Returns the data associated with the read row,
483 // expressed as a 4-component value, and advances the
484 // read row.
485 ////////////////////////////////////////////////////////////////////
486 INLINE const LVecBase4f &GeomVertexReader::
488  nassertr(has_column(), LVecBase4f::zero());
489  return _packer->get_data4f(inc_pointer());
490 }
491 
492 ////////////////////////////////////////////////////////////////////
493 // Function: GeomVertexReader::get_matrix3f
494 // Access: Published
495 // Description: Returns the 3-by-3 matrix associated with the read
496 // row and advances the read row. This is a special
497 // method that only works when the column in question
498 // contains a matrix of an appropriate size.
499 ////////////////////////////////////////////////////////////////////
502  nassertr(has_column() &&
503  _packer->_column->get_contents() == C_matrix &&
504  _packer->_column->get_num_elements() >= 3,
506 
507  size_t col_stride = _packer->_column->get_element_stride();
508  const unsigned char *pointer = inc_pointer();
509 
510  LMatrix3f mat;
511  mat.set_row(0, _packer->get_data3f(pointer));
512  pointer += col_stride;
513  mat.set_row(1, _packer->get_data3f(pointer));
514  pointer += col_stride;
515  mat.set_row(2, _packer->get_data3f(pointer));
516  return mat;
517 }
518 
519 ////////////////////////////////////////////////////////////////////
520 // Function: GeomVertexReader::get_matrix4f
521 // Access: Published
522 // Description: Returns the 4-by-4 matrix associated with the read
523 // row and advances the read row. This is a special
524 // method that only works when the column in question
525 // contains a matrix of an appropriate size.
526 ////////////////////////////////////////////////////////////////////
529  nassertr(has_column() &&
530  _packer->_column->get_contents() == C_matrix &&
531  _packer->_column->get_num_elements() >= 4,
533 
534  size_t col_stride = _packer->_column->get_element_stride();
535  const unsigned char *pointer = inc_pointer();
536 
537  LMatrix4f mat;
538  mat.set_row(0, _packer->get_data4f(pointer));
539  pointer += col_stride;
540  mat.set_row(1, _packer->get_data4f(pointer));
541  pointer += col_stride;
542  mat.set_row(2, _packer->get_data4f(pointer));
543  pointer += col_stride;
544  mat.set_row(3, _packer->get_data4f(pointer));
545  return mat;
546 }
547 
548 ////////////////////////////////////////////////////////////////////
549 // Function: GeomVertexReader::get_data1d
550 // Access: Published
551 // Description: Returns the data associated with the read row,
552 // expressed as a 1-component value, and advances the
553 // read row.
554 ////////////////////////////////////////////////////////////////////
555 INLINE double GeomVertexReader::
557  nassertr(has_column(), 0.0f);
558  return _packer->get_data1d(inc_pointer());
559 }
560 
561 ////////////////////////////////////////////////////////////////////
562 // Function: GeomVertexReader::get_data2d
563 // Access: Published
564 // Description: Returns the data associated with the read row,
565 // expressed as a 2-component value, and advances the
566 // read row.
567 ////////////////////////////////////////////////////////////////////
568 INLINE const LVecBase2d &GeomVertexReader::
570  nassertr(has_column(), LVecBase2d::zero());
571  return _packer->get_data2d(inc_pointer());
572 }
573 
574 ////////////////////////////////////////////////////////////////////
575 // Function: GeomVertexReader::get_data3d
576 // Access: Published
577 // Description: Returns the data associated with the read row,
578 // expressed as a 3-component value, and advances the
579 // read row.
580 ////////////////////////////////////////////////////////////////////
581 INLINE const LVecBase3d &GeomVertexReader::
583  nassertr(has_column(), LVecBase3d::zero());
584  return _packer->get_data3d(inc_pointer());
585 }
586 
587 ////////////////////////////////////////////////////////////////////
588 // Function: GeomVertexReader::get_data4d
589 // Access: Published
590 // Description: Returns the data associated with the read row,
591 // expressed as a 4-component value, and advances the
592 // read row.
593 ////////////////////////////////////////////////////////////////////
594 INLINE const LVecBase4d &GeomVertexReader::
596  nassertr(has_column(), LVecBase4d::zero());
597  return _packer->get_data4d(inc_pointer());
598 }
599 
600 ////////////////////////////////////////////////////////////////////
601 // Function: GeomVertexReader::get_matrix3d
602 // Access: Published
603 // Description: Returns the 3-by-3 matrix associated with the read
604 // row and advances the read row. This is a special
605 // method that only works when the column in question
606 // contains a matrix of an appropriate size.
607 ////////////////////////////////////////////////////////////////////
610  nassertr(has_column() &&
611  _packer->_column->get_contents() == C_matrix &&
612  _packer->_column->get_num_elements() >= 3,
614 
615  size_t col_stride = _packer->_column->get_element_stride();
616  const unsigned char *pointer = inc_pointer();
617 
618  LMatrix3d mat;
619  mat.set_row(0, _packer->get_data3d(pointer));
620  pointer += col_stride;
621  mat.set_row(1, _packer->get_data3d(pointer));
622  pointer += col_stride;
623  mat.set_row(2, _packer->get_data3d(pointer));
624  return mat;
625 }
626 
627 ////////////////////////////////////////////////////////////////////
628 // Function: GeomVertexReader::get_matrix4d
629 // Access: Published
630 // Description: Returns the 4-by-4 matrix associated with the read
631 // row and advances the read row. This is a special
632 // method that only works when the column in question
633 // contains a matrix of an appropriate size.
634 ////////////////////////////////////////////////////////////////////
637  nassertr(has_column() &&
638  _packer->_column->get_contents() == C_matrix &&
639  _packer->_column->get_num_elements() >= 4,
641 
642  size_t col_stride = _packer->_column->get_element_stride();
643  const unsigned char *pointer = inc_pointer();
644 
645  LMatrix4d mat;
646  mat.set_row(0, _packer->get_data4d(pointer));
647  pointer += col_stride;
648  mat.set_row(1, _packer->get_data4d(pointer));
649  pointer += col_stride;
650  mat.set_row(2, _packer->get_data4d(pointer));
651  pointer += col_stride;
652  mat.set_row(3, _packer->get_data4d(pointer));
653  return mat;
654 }
655 
656 ////////////////////////////////////////////////////////////////////
657 // Function: GeomVertexReader::get_data1
658 // Access: Published
659 // Description: Returns the data associated with the read row,
660 // expressed as a 1-component value, and advances the
661 // read row.
662 ////////////////////////////////////////////////////////////////////
663 INLINE PN_stdfloat GeomVertexReader::
665 #ifndef STDFLOAT_DOUBLE
666  return get_data1f();
667 #else
668  return get_data1d();
669 #endif
670 }
671 
672 ////////////////////////////////////////////////////////////////////
673 // Function: GeomVertexReader::get_data2
674 // Access: Published
675 // Description: Returns the data associated with the read row,
676 // expressed as a 2-component value, and advances the
677 // read row.
678 ////////////////////////////////////////////////////////////////////
679 INLINE const LVecBase2 &GeomVertexReader::
681 #ifndef STDFLOAT_DOUBLE
682  return get_data2f();
683 #else
684  return get_data2d();
685 #endif
686 }
687 
688 ////////////////////////////////////////////////////////////////////
689 // Function: GeomVertexReader::get_data3
690 // Access: Published
691 // Description: Returns the data associated with the read row,
692 // expressed as a 3-component value, and advances the
693 // read row.
694 ////////////////////////////////////////////////////////////////////
695 INLINE const LVecBase3 &GeomVertexReader::
697 #ifndef STDFLOAT_DOUBLE
698  return get_data3f();
699 #else
700  return get_data3d();
701 #endif
702 }
703 
704 ////////////////////////////////////////////////////////////////////
705 // Function: GeomVertexReader::get_data4
706 // Access: Published
707 // Description: Returns the data associated with the read row,
708 // expressed as a 4-component value, and advances the
709 // read row.
710 ////////////////////////////////////////////////////////////////////
711 INLINE const LVecBase4 &GeomVertexReader::
713 #ifndef STDFLOAT_DOUBLE
714  return get_data4f();
715 #else
716  return get_data4d();
717 #endif
718 }
719 
720 ////////////////////////////////////////////////////////////////////
721 // Function: GeomVertexReader::get_matrix3
722 // Access: Published
723 // Description: Returns the 3-by-3 matrix associated with the read
724 // row and advances the read row. This is a special
725 // method that only works when the column in question
726 // contains a matrix of an appropriate size.
727 ////////////////////////////////////////////////////////////////////
730 #ifndef STDFLOAT_DOUBLE
731  return get_matrix3f();
732 #else
733  return get_matrix3d();
734 #endif
735 }
736 
737 ////////////////////////////////////////////////////////////////////
738 // Function: GeomVertexReader::get_matrix4
739 // Access: Published
740 // Description: Returns the 4-by-4 matrix associated with the read
741 // row and advances the read row. This is a special
742 // method that only works when the column in question
743 // contains a matrix of an appropriate size.
744 ////////////////////////////////////////////////////////////////////
747 #ifndef STDFLOAT_DOUBLE
748  return get_matrix4f();
749 #else
750  return get_matrix4d();
751 #endif
752 }
753 
754 ////////////////////////////////////////////////////////////////////
755 // Function: GeomVertexReader::get_data1i
756 // Access: Published
757 // Description: Returns the data associated with the read row,
758 // expressed as a 1-component value, and advances the
759 // read row.
760 ////////////////////////////////////////////////////////////////////
761 INLINE int GeomVertexReader::
763  nassertr(has_column(), 0);
764  return _packer->get_data1i(inc_pointer());
765 }
766 
767 ////////////////////////////////////////////////////////////////////
768 // Function: GeomVertexReader::get_data2i
769 // Access: Published
770 // Description: Returns the data associated with the read row,
771 // expressed as a 2-component value, and advances the
772 // read row.
773 ////////////////////////////////////////////////////////////////////
774 INLINE const LVecBase2i &GeomVertexReader::
776  nassertr(has_column(), LVecBase2i::zero());
777  return _packer->get_data2i(inc_pointer());
778 }
779 
780 ////////////////////////////////////////////////////////////////////
781 // Function: GeomVertexReader::get_data3i
782 // Access: Published
783 // Description: Returns the data associated with the read row,
784 // expressed as a 3-component value, and advances the
785 // read row.
786 ////////////////////////////////////////////////////////////////////
787 INLINE const LVecBase3i &GeomVertexReader::
789  nassertr(has_column(), LVecBase3i::zero());
790  return _packer->get_data3i(inc_pointer());
791 }
792 
793 ////////////////////////////////////////////////////////////////////
794 // Function: GeomVertexReader::get_data4i
795 // Access: Published
796 // Description: Returns the data associated with the read row,
797 // expressed as a 4-component value, and advances the
798 // read row.
799 ////////////////////////////////////////////////////////////////////
800 INLINE const LVecBase4i &GeomVertexReader::
802  nassertr(has_column(), LVecBase4i::zero());
803  return _packer->get_data4i(inc_pointer());
804 }
805 
806 ////////////////////////////////////////////////////////////////////
807 // Function: GeomVertexReader::get_packer
808 // Access: Protected
809 // Description: Returns the reader's Packer object.
810 ////////////////////////////////////////////////////////////////////
811 INLINE GeomVertexColumn::Packer *GeomVertexReader::
812 get_packer() const {
813  return _packer;
814 }
815 
816 ////////////////////////////////////////////////////////////////////
817 // Function: GeomVertexReader::set_pointer
818 // Access: Private
819 // Description: Sets up the array pointers freshly from the source
820 // object (in case they have been reallocated recently),
821 // and sets the internal pointer to the indicated row.
822 //
823 // Returns true if successful, or false if the vertex
824 // data is not resident. If it returns false, the
825 // reader's internal column spec is cleared. It is only
826 // possible to return false if get_force() is false.
827 ////////////////////////////////////////////////////////////////////
828 INLINE bool GeomVertexReader::
829 set_pointer(int row) {
830  _pointer_begin = _handle->get_read_pointer(_force);
831  if (_pointer_begin == NULL && _handle->get_data_size_bytes() != 0) {
832  // Vertex data is not resident.
833  set_column(0, NULL);
834  return false;
835  }
836 
837  // Vertex data is resident, or just empty.
838  _pointer_end = _pointer_begin + _handle->get_data_size_bytes();
839  quick_set_pointer(row);
840  return true;
841 }
842 
843 ////////////////////////////////////////////////////////////////////
844 // Function: GeomVertexReader::quick_set_pointer
845 // Access: Private
846 // Description: Sets up the internal pointer to the indicated row,
847 // without first verifying that arrays haven't been
848 // reallocated.
849 ////////////////////////////////////////////////////////////////////
850 INLINE void GeomVertexReader::
851 quick_set_pointer(int row) {
852  nassertv(has_column() && (_pointer_begin != NULL || row == 0));
853 
854 #if defined(_DEBUG)
855  // Make sure we still have the same pointer as stored in the array.
856  nassertv(_pointer_begin == _handle->get_read_pointer(true));
857 #endif
858 
859  _pointer = _pointer_begin + _packer->_column->get_start() + _stride * row;
860 
861 #if defined(_DEBUG)
862  // We have to allow the pointer to exceed the end by up to one row's
863  // width. This wouldn't be legal on a plain GeomVertexReader, but
864  // it *is* legal for a GeomVertexRewriter.
865  nassertv(_pointer_begin == _pointer_end || (_pointer - _packer->_column->get_start()) <= _pointer_end);
866 #endif
867 }
868 
869 ////////////////////////////////////////////////////////////////////
870 // Function: GeomVertexReader::inc_pointer
871 // Access: Private
872 // Description: Increments to the next row, and returns the data
873 // pointer as it was before incrementing.
874 ////////////////////////////////////////////////////////////////////
875 INLINE const unsigned char *GeomVertexReader::
876 inc_pointer() {
877 #if defined(_DEBUG)
878  nassertr(_pointer < _pointer_end, empty_buffer);
879  // Make sure we still have the same pointer as stored in the array.
880  nassertr(_pointer_begin == _handle->get_read_pointer(true), empty_buffer);
881  nassertr(_pointer < _pointer_begin + _handle->get_data_size_bytes(), empty_buffer);
882 #endif
883 
884  const unsigned char *orig_pointer = _pointer;
885  _pointer += _stride;
886  return orig_pointer;
887 }
static const LMatrix4f & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:903
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition: internalName.h:197
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:4716
static const LMatrix3f & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:2863
const GeomVertexArrayData * get_array_data() const
Returns the particular array object that the reader is currently processing.
bool set_column(int column)
Sets up the reader to use the nth data type of the GeomVertexFormat, numbering from 0...
LMatrix3 get_matrix3()
Returns the 3-by-3 matrix associated with the read row and advances the read row. ...
static const LVecBase2i & zero()
Returns a zero-length vector.
Definition: lvecBase2.h:2614
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:1257
double get_data1d()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
const LVecBase2 & get_data2()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
const GeomVertexColumn * get_column() const
Returns the description of the data type that the reader is working on.
static const LVecBase3i & zero()
Returns a zero-length vector.
Definition: lvecBase3.h:3065
const LVecBase3i & get_data3i()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:2360
bool get_force() const
Returns the value of the force flag.
static const LVecBase4d & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:2059
const LVecBase2d & get_data2d()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
const LVecBase4 & get_data4()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:1677
const LVecBase3f & get_data3f()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
static const LVecBase2f & zero()
Returns a zero-length vector.
Definition: lvecBase2.h:359
void set_row(int row, const LVecBase3f &v)
Replaces the indicated row of the matrix from a three-component vector.
Definition: lmatrix.h:2958
static const LVecBase4i & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:3576
static const LVecBase3f & zero()
Returns a zero-length vector.
Definition: lvecBase3.h:382
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
LMatrix4d get_matrix4d()
Returns the 4-by-4 matrix associated with the read row and advances the read row. ...
size_t get_stride() const
Returns the per-row stride (bytes between consecutive rows) of the underlying vertex array...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:3194
const GeomVertexData * get_vertex_data() const
Returns the vertex data object that the reader is processing.
void set_force(bool force)
Sets the value of the force flag.
void set_row(int row, const LVecBase4d &v)
Replaces the indicated row of the matrix.
Definition: lmatrix.h:5452
This defines how a single column is interleaved within a vertex array stored within a Geom...
const LVecBase4f & get_data4f()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
int get_read_row() const
Returns the row index from which the data will be retrieved by the next call to get_data*().
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
LMatrix3d get_matrix3d()
Returns the 3-by-3 matrix associated with the read row and advances the read row. ...
void set_row(int row, const LVecBase3d &v)
Replaces the indicated row of the matrix from a three-component vector.
Definition: lmatrix.h:7223
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
static const LMatrix4d & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:5168
const LVecBase2i & get_data2i()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
bool has_column() const
Returns true if a valid data type has been successfully set, or false if the data type does not exist...
static const LVecBase3d & zero()
Returns a zero-length vector.
Definition: lvecBase3.h:1748
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
Thread * get_current_thread() const
Returns the Thread pointer of the currently-executing thread, as passed to the constructor of this ob...
const GeomVertexArrayDataHandle * get_array_handle() const
Returns the read handle to the array object that the read is currently processing.
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:1471
void set_row(int row)
Sets the start row to the indicated value.
int get_array() const
Returns the array index containing the data type that the reader is working on.
int get_data1i()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
const LVecBase2f & get_data2f()
Returns the data associated with the read row, expressed as a 2-component value, and advances the rea...
static const LVecBase2d & zero()
Returns a zero-length vector.
Definition: lvecBase2.h:1511
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:2788
A thread; that is, a lightweight process.
Definition: thread.h:51
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
float get_data1f()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
bool is_at_end() const
Returns true if the reader is currently at the end of the list of vertices, false otherwise...
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
void set_row(int row, const LVecBase4f &v)
Replaces the indicated row of the matrix.
Definition: lmatrix.h:1187
void set_row_unsafe(int row)
Sets the start row to the indicated value, without internal checks.
static const LMatrix3d & ident_mat()
Returns an identity matrix.
Definition: lmatrix.h:7128
void clear()
Resets the GeomVertexReader to the initial state.
const LVecBase3d & get_data3d()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:110
int get_start_row() const
Returns the row index at which the reader started.
LMatrix4f get_matrix4f()
Returns the 4-by-4 matrix associated with the read row and advances the read row. ...
LMatrix4 get_matrix4()
Returns the 4-by-4 matrix associated with the read row and advances the read row. ...
const LVecBase4d & get_data4d()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
const LVecBase4i & get_data4i()
Returns the data associated with the read row, expressed as a 4-component value, and advances the rea...
This is the data for one array of a GeomVertexData structure.
static const LVecBase4f & zero()
Returns a zero-length vector.
Definition: lvecBase4.h:493
PN_stdfloat get_data1()
Returns the data associated with the read row, expressed as a 1-component value, and advances the rea...
LMatrix3f get_matrix3f()
Returns the 3-by-3 matrix associated with the read row and advances the read row. ...
GeomVertexReader(Thread *current_thread=Thread::get_current_thread())
Constructs an invalid GeomVertexReader.