Panda3D
 All Classes Functions Variables Enumerations
geomPrimitive.I
1 // Filename: geomPrimitive.I
2 // Created by: drose (06Mar05)
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: GeomPrimitive::get_shade_model
18 // Access: Published
19 // Description: Returns the ShadeModel hint for this primitive.
20 // This is intended as a hint to the renderer to tell it
21 // how the per-vertex colors and normals are applied.
22 ////////////////////////////////////////////////////////////////////
23 INLINE GeomPrimitive::ShadeModel GeomPrimitive::
24 get_shade_model() const {
25  CDReader cdata(_cycler);
26  return cdata->_shade_model;
27 }
28 
29 ////////////////////////////////////////////////////////////////////
30 // Function: GeomPrimitive::set_shade_model
31 // Access: Published
32 // Description: Changes the ShadeModel hint for this primitive.
33 // This is different from the ShadeModelAttrib that
34 // might also be applied from the scene graph. This
35 // does not affect the shade model that is in effect
36 // when rendering, but rather serves as a hint to the
37 // renderer to tell it how the per-vertex colors and
38 // normals on this primitive are applied.
39 //
40 // Don't call this in a downstream thread unless you
41 // don't mind it blowing away other changes you might
42 // have recently made in an upstream thread.
43 ////////////////////////////////////////////////////////////////////
44 INLINE void GeomPrimitive::
45 set_shade_model(GeomPrimitive::ShadeModel shade_model) {
46  CDWriter cdata(_cycler, true);
47  cdata->_shade_model = shade_model;
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: GeomPrimitive::get_usage_hint
52 // Access: Published
53 // Description: Returns the usage hint for this primitive. See
54 // geomEnums.h. This has nothing to do with the usage
55 // hint associated with the primitive's vertices; this
56 // only specifies how often the vertex indices that
57 // define the primitive will be modified.
58 //
59 // It is perfectly legal (and, in fact, common) for a
60 // GeomPrimitive to have UH_static on itself, while
61 // referencing vertex data with UH_dynamic. This means
62 // that the vertices themselves will be animated, but
63 // the primitive will always reference the same set of
64 // vertices from the pool.
65 ////////////////////////////////////////////////////////////////////
66 INLINE GeomPrimitive::UsageHint GeomPrimitive::
67 get_usage_hint() const {
68  CDReader cdata(_cycler);
69  return cdata->_usage_hint;
70 }
71 
72 ////////////////////////////////////////////////////////////////////
73 // Function: GeomPrimitive::get_index_type
74 // Access: Public
75 // Description: Returns the numeric type of the index column.
76 // Normally, this will be either NT_uint16 or NT_uint32.
77 ////////////////////////////////////////////////////////////////////
78 INLINE GeomPrimitive::NumericType GeomPrimitive::
79 get_index_type() const {
80  CDReader cdata(_cycler);
81  return cdata->_index_type;
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function: GeomPrimitive::is_composite
86 // Access: Published
87 // Description: Returns true if the primitive is a composite
88 // primitive such as a tristrip or trifan, or false if
89 // it is a fundamental primitive such as a collection of
90 // triangles.
91 ////////////////////////////////////////////////////////////////////
92 INLINE bool GeomPrimitive::
93 is_composite() const {
94  return (get_num_vertices_per_primitive() == 0);
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: GeomPrimitive::is_indexed
99 // Access: Published
100 // Description: Returns true if the primitive is indexed, false
101 // otherwise. An indexed primitive stores a table of
102 // index numbers into its GeomVertexData, so that it can
103 // reference the vertices in any order. A nonindexed
104 // primitive, on the other hand, stores only the first
105 // vertex number and number of vertices used, so that it
106 // can only reference the vertices consecutively.
107 ////////////////////////////////////////////////////////////////////
108 INLINE bool GeomPrimitive::
109 is_indexed() const {
111  return reader.is_indexed();
112 }
113 
114 ////////////////////////////////////////////////////////////////////
115 // Function: GeomPrimitive::get_first_vertex
116 // Access: Published
117 // Description: Returns the first vertex number referenced by the
118 // primitive. This is particularly important in the
119 // case of a nonindexed primitive, in which case
120 // get_first_vertex() and get_num_vertices() completely
121 // define the extent of the vertex range.
122 ////////////////////////////////////////////////////////////////////
123 INLINE int GeomPrimitive::
126  return reader.get_first_vertex();
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: GeomPrimitive::get_num_vertices
131 // Access: Published
132 // Description: Returns the number of indices used by all the
133 // primitives in this object.
134 ////////////////////////////////////////////////////////////////////
135 INLINE int GeomPrimitive::
138  return reader.get_num_vertices();
139 }
140 
141 ////////////////////////////////////////////////////////////////////
142 // Function: GeomPrimitive::get_vertex
143 // Access: Published
144 // Description: Returns the ith vertex index in the table.
145 ////////////////////////////////////////////////////////////////////
146 INLINE int GeomPrimitive::
147 get_vertex(int i) const {
149  return reader.get_vertex(i);
150 }
151 
152 ////////////////////////////////////////////////////////////////////
153 // Function: GeomPrimitive::get_num_primitives
154 // Access: Published
155 // Description: Returns the number of individual primitives stored
156 // within this object. All primitives are the same
157 // type.
158 ////////////////////////////////////////////////////////////////////
159 INLINE int GeomPrimitive::
162  return reader.get_num_primitives();
163 }
164 
165 ////////////////////////////////////////////////////////////////////
166 // Function: GeomPrimitive::get_num_faces
167 // Access: Published
168 // Description: Returns the number of triangles or other fundamental
169 // type (such as line segments) represented by all the
170 // primitives in this object.
171 ////////////////////////////////////////////////////////////////////
172 INLINE int GeomPrimitive::
173 get_num_faces() const {
174  int num_vertices_per_primitive = get_num_vertices_per_primitive();
175 
176  if (num_vertices_per_primitive == 0) {
177  int num_primitives = get_num_primitives();
178  int num_vertices = get_num_vertices();
179  int min_num_vertices_per_primitive = get_min_num_vertices_per_primitive();
180  int num_unused_vertices_per_primitive = get_num_unused_vertices_per_primitive();
181  return num_vertices - (num_primitives * (min_num_vertices_per_primitive - 1)) - ((num_primitives - 1) * num_unused_vertices_per_primitive);
182  } else {
183  return get_num_primitives();
184  }
185 }
186 
187 ////////////////////////////////////////////////////////////////////
188 // Function: GeomPrimitive::get_primitive_num_faces
189 // Access: Published
190 // Description: Returns the number of triangles or other fundamental
191 // type (such as line segments) represented by the nth
192 // primitive in this object.
193 ////////////////////////////////////////////////////////////////////
194 INLINE int GeomPrimitive::
196  int num_vertices_per_primitive = get_num_vertices_per_primitive();
197 
198  if (num_vertices_per_primitive == 0) {
200  } else {
201  return 1;
202  }
203 }
204 
205 ////////////////////////////////////////////////////////////////////
206 // Function: GeomPrimitive::get_min_vertex
207 // Access: Published
208 // Description: Returns the minimum vertex index number used by all
209 // the primitives in this object.
210 ////////////////////////////////////////////////////////////////////
211 INLINE int GeomPrimitive::
212 get_min_vertex() const {
214  reader.check_minmax();
215  return reader.get_min_vertex();
216 }
217 
218 ////////////////////////////////////////////////////////////////////
219 // Function: GeomPrimitive::get_max_vertex
220 // Access: Published
221 // Description: Returns the maximum vertex index number used by all
222 // the primitives in this object.
223 ////////////////////////////////////////////////////////////////////
224 INLINE int GeomPrimitive::
225 get_max_vertex() const {
227  reader.check_minmax();
228  return reader.get_max_vertex();
229 }
230 
231 ////////////////////////////////////////////////////////////////////
232 // Function: GeomPrimitive::get_data_size_bytes
233 // Access: Published
234 // Description: Returns the number of bytes stored in the vertices
235 // array.
236 ////////////////////////////////////////////////////////////////////
237 INLINE int GeomPrimitive::
239  CDReader cdata(_cycler);
240  nassertr(!cdata->_vertices.is_null(), 0);
241  return cdata->_vertices.get_read_pointer()->get_data_size_bytes();
242 }
243 
244 ////////////////////////////////////////////////////////////////////
245 // Function: GeomPrimitive::get_modified
246 // Access: Published
247 // Description: Returns a sequence number which is guaranteed to
248 // change at least every time the vertex index array is
249 // modified.
250 ////////////////////////////////////////////////////////////////////
252 get_modified() const {
253  CDReader cdata(_cycler);
254  return cdata->_modified;
255 }
256 
257 ////////////////////////////////////////////////////////////////////
258 // Function: GeomPrimitive::check_valid
259 // Access: Published
260 // Description: Verifies that the primitive only references vertices
261 // that actually exist within the indicated
262 // GeomVertexData. Returns true if the primitive
263 // appears to be valid, false otherwise.
264 ////////////////////////////////////////////////////////////////////
265 INLINE bool GeomPrimitive::
266 check_valid(const GeomVertexData *vertex_data) const {
267  Thread *current_thread = Thread::get_current_thread();
268  GeomPrimitivePipelineReader reader(this, current_thread);
269  reader.check_minmax();
270  GeomVertexDataPipelineReader data_reader(vertex_data, current_thread);
271  data_reader.check_array_readers();
272  return reader.check_valid(&data_reader);
273 }
274 
275 ////////////////////////////////////////////////////////////////////
276 // Function: GeomPrimitive::get_vertices
277 // Access: Published
278 // Description: Returns a const pointer to the vertex index array so
279 // application code can read it directly. This might
280 // return NULL if the primitive is nonindexed. Do not
281 // attempt to modify the returned array; use
282 // modify_vertices() or set_vertices() for this.
283 //
284 // This method is intended for low-level usage only.
285 // There are higher-level methods for more common usage.
286 // We recommend you do not use this method directly. If
287 // you do, be sure you know what you are doing!
288 ////////////////////////////////////////////////////////////////////
290 get_vertices() const {
291  CDReader cdata(_cycler);
292  return cdata->_vertices.get_read_pointer();
293 }
294 
295 ////////////////////////////////////////////////////////////////////
296 // Function: GeomPrimitive::get_index_stride
297 // Access: Published
298 // Description: A convenience function to return the gap between
299 // successive index numbers, in bytes, of the index
300 // data.
301 //
302 // This method is intended for low-level usage only.
303 // There are higher-level methods for more common usage.
304 // We recommend you do not use this method directly. If
305 // you do, be sure you know what you are doing!
306 ////////////////////////////////////////////////////////////////////
307 INLINE int GeomPrimitive::
310  return reader.get_index_stride();
311 }
312 
313 ////////////////////////////////////////////////////////////////////
314 // Function: GeomPrimitive::get_strip_cut_index
315 // Access: Published
316 // Description: If relevant, returns the index value that may be
317 // used in some cases to signify the end of a
318 // primitive. This is typically the highest value
319 // that the numeric type can store.
320 ////////////////////////////////////////////////////////////////////
321 INLINE int GeomPrimitive::
323  CDReader cdata(_cycler);
324  return get_strip_cut_index(cdata->_index_type);
325 }
326 
327 ////////////////////////////////////////////////////////////////////
328 // Function: GeomPrimitive::get_ends
329 // Access: Published
330 // Description: Returns a const pointer to the primitive ends
331 // array so application code can read it directly. Do
332 // not attempt to modify the returned array; use
333 // modify_ends() or set_ends() for this.
334 //
335 // Note that simple primitive types, like triangles, do
336 // not have a ends array: since all the primitives
337 // have the same number of vertices, it is not needed.
338 //
339 // This method is intended for low-level usage only.
340 // There are higher-level methods for more common usage.
341 // We recommend you do not use this method directly. If
342 // you do, be sure you know what you are doing!
343 ////////////////////////////////////////////////////////////////////
345 get_ends() const {
346  CDReader cdata(_cycler);
347  return cdata->_ends;
348 }
349 
350 ////////////////////////////////////////////////////////////////////
351 // Function: GeomPrimitive::get_mins
352 // Access: Published
353 // Description: Returns a const pointer to the primitive mins
354 // array so application code can read it directly. Do
355 // not attempt to modify the returned array; use
356 // set_minmax() for this.
357 //
358 // Note that simple primitive types, like triangles, do
359 // not have a mins array.
360 //
361 // This method is intended for low-level usage only.
362 // There are higher-level methods for more common usage.
363 // We recommend you do not use this method directly. If
364 // you do, be sure you know what you are doing!
365 ////////////////////////////////////////////////////////////////////
367 get_mins() const {
369  reader.check_minmax();
370  return reader.get_mins();
371 }
372 
373 ////////////////////////////////////////////////////////////////////
374 // Function: GeomPrimitive::get_maxs
375 // Access: Published
376 // Description: Returns a const pointer to the primitive maxs
377 // array so application code can read it directly. Do
378 // not attempt to modify the returned array; use
379 // set_minmax().
380 //
381 // Note that simple primitive types, like triangles, do
382 // not have a maxs array.
383 //
384 // This method is intended for low-level usage only.
385 // There are higher-level methods for more common usage.
386 // We recommend you do not use this method directly. If
387 // you do, be sure you know what you are doing!
388 ////////////////////////////////////////////////////////////////////
390 get_maxs() const {
392  reader.check_minmax();
393  return reader.get_maxs();
394 }
395 
396 ////////////////////////////////////////////////////////////////////
397 // Function: GeomPrimitive::add_vertices
398 // Access: Public
399 // Description: Adds several vertices in a row.
400 ////////////////////////////////////////////////////////////////////
401 INLINE void GeomPrimitive::
402 add_vertices(int v1, int v2) {
403  add_vertex(v1);
404  add_vertex(v2);
405 }
406 
407 ////////////////////////////////////////////////////////////////////
408 // Function: GeomPrimitive::add_vertices
409 // Access: Public
410 // Description: Adds several vertices in a row.
411 ////////////////////////////////////////////////////////////////////
412 INLINE void GeomPrimitive::
413 add_vertices(int v1, int v2, int v3) {
414  add_vertex(v1);
415  add_vertex(v2);
416  add_vertex(v3);
417 }
418 
419 ////////////////////////////////////////////////////////////////////
420 // Function: GeomPrimitive::add_vertices
421 // Access: Public
422 // Description: Adds several vertices in a row.
423 ////////////////////////////////////////////////////////////////////
424 INLINE void GeomPrimitive::
425 add_vertices(int v1, int v2, int v3, int v4) {
426  add_vertex(v1);
427  add_vertex(v2);
428  add_vertex(v3);
429  add_vertex(v4);
430 }
431 
432 ////////////////////////////////////////////////////////////////////
433 // Function: GeomPrimitive::get_index_format
434 // Access: Public
435 // Description: Returns a registered format appropriate for using to
436 // store the index table.
437 ////////////////////////////////////////////////////////////////////
438 INLINE const GeomVertexArrayFormat *GeomPrimitive::
441 }
442 
443 ////////////////////////////////////////////////////////////////////
444 // Function: GeomPrimitive::make_index_data
445 // Access: Public
446 // Description: Creates and returns a new, empty index table.
447 ////////////////////////////////////////////////////////////////////
449 make_index_data() const {
450  return new GeomVertexArrayData(get_index_format(), get_usage_hint());
451 }
452 
453 ////////////////////////////////////////////////////////////////////
454 // Function: GeomPrimitive::make_index_format
455 // Access: Private, Static
456 // Description: Returns a registered format appropriate for using to
457 // store the index table.
458 ////////////////////////////////////////////////////////////////////
459 INLINE CPT(GeomVertexArrayFormat) GeomPrimitive::
460 make_index_format(NumericType index_type) {
461  PT(GeomVertexArrayFormat) format = new GeomVertexArrayFormat;
462  // It's important that the index format *not* respect the global
463  // setting of vertex-column-alignment. It needs to be tightly
464  // packed, so we specify an explict column_alignment of 1.
465  format->add_column(InternalName::get_index(), 1, index_type, C_index, 0, 1);
466  return GeomVertexArrayFormat::register_format(format);
467 }
468 
469 ////////////////////////////////////////////////////////////////////
470 // Function: GeomPrimitive::CData::Constructor
471 // Access: Public
472 // Description:
473 ////////////////////////////////////////////////////////////////////
474 INLINE GeomPrimitive::CData::
475 CData() :
476  _shade_model(SM_smooth),
477  _first_vertex(0),
478  _num_vertices(0),
479  _index_type(NT_uint16),
480  _usage_hint(UH_unspecified),
481  _got_minmax(true),
482  _min_vertex(0),
483  _max_vertex(0)
484 {
485 }
486 
487 ////////////////////////////////////////////////////////////////////
488 // Function: GeomPrimitive::CData::Copy Constructor
489 // Access: Public
490 // Description:
491 ////////////////////////////////////////////////////////////////////
492 INLINE GeomPrimitive::CData::
493 CData(const GeomPrimitive::CData &copy) :
494  _shade_model(copy._shade_model),
495  _first_vertex(copy._first_vertex),
496  _num_vertices(copy._num_vertices),
497  _index_type(copy._index_type),
498  _usage_hint(copy._usage_hint),
499  _vertices(copy._vertices),
500  _ends(copy._ends),
501  _mins(copy._mins),
502  _maxs(copy._maxs),
503  _modified(copy._modified),
504  _got_minmax(copy._got_minmax),
505  _min_vertex(copy._min_vertex),
506  _max_vertex(copy._max_vertex)
507 {
508 }
509 ////////////////////////////////////////////////////////////////////
510 // Function: GeomPrimitivePipelineReader::Constructor
511 // Access: Public
512 // Description:
513 ////////////////////////////////////////////////////////////////////
514 INLINE GeomPrimitivePipelineReader::
515 GeomPrimitivePipelineReader(const GeomPrimitive *object,
516  Thread *current_thread) :
517  _object(object),
518  _current_thread(current_thread),
519  _cdata(object->_cycler.read_unlocked(current_thread)),
520  _vertices_reader(NULL)
521 {
522  nassertv(_object->test_ref_count_nonzero());
523 #ifdef DO_PIPELINING
524  _cdata->ref();
525 #endif // DO_PIPELINING
526  if (!_cdata->_vertices.is_null()) {
527  _vertices_reader = _cdata->_vertices.get_read_pointer()->get_handle();
528  }
529 }
530 
531 ////////////////////////////////////////////////////////////////////
532 // Function: GeomPrimitivePipelineReader::Copy Constructor
533 // Access: Private
534 // Description: Don't attempt to copy these objects.
535 ////////////////////////////////////////////////////////////////////
536 INLINE GeomPrimitivePipelineReader::
537 GeomPrimitivePipelineReader(const GeomPrimitivePipelineReader &) {
538  nassertv(false);
539 }
540 
541 ////////////////////////////////////////////////////////////////////
542 // Function: GeomPrimitivePipelineReader::Copy Assignment Operator
543 // Access: Private
544 // Description: Don't attempt to copy these objects.
545 ////////////////////////////////////////////////////////////////////
546 INLINE void GeomPrimitivePipelineReader::
547 operator = (const GeomPrimitivePipelineReader &) {
548  nassertv(false);
549 }
550 
551 ////////////////////////////////////////////////////////////////////
552 // Function: GeomPrimitivePipelineReader::Destructor
553 // Access: Public
554 // Description:
555 ////////////////////////////////////////////////////////////////////
556 INLINE GeomPrimitivePipelineReader::
557 ~GeomPrimitivePipelineReader() {
558 #ifdef _DEBUG
559  nassertv(_object->test_ref_count_nonzero());
560 #endif // _DEBUG
561  // _object->_cycler.release_read(_cdata);
562 
563 #ifdef DO_PIPELINING
564  unref_delete((CycleData *)_cdata);
565 #endif // DO_PIPELINING
566 
567 #ifdef _DEBUG
568  _vertices_reader = NULL;
569  _object = NULL;
570  _cdata = NULL;
571 #endif // _DEBUG
572 }
573 
574 ////////////////////////////////////////////////////////////////////
575 // Function: GeomPrimitivePipelineReader::get_object
576 // Access: Public
577 // Description:
578 ////////////////////////////////////////////////////////////////////
579 INLINE const GeomPrimitive *GeomPrimitivePipelineReader::
580 get_object() const {
581  return _object;
582 }
583 
584 ////////////////////////////////////////////////////////////////////
585 // Function: GeomPrimitivePipelineReader::get_current_thread
586 // Access: Public
587 // Description:
588 ////////////////////////////////////////////////////////////////////
589 INLINE Thread *GeomPrimitivePipelineReader::
590 get_current_thread() const {
591  return _current_thread;
592 }
593 
594 ////////////////////////////////////////////////////////////////////
595 // Function: GeomPrimitivePipelineReader::get_shade_model
596 // Access: Public
597 // Description:
598 ////////////////////////////////////////////////////////////////////
599 INLINE GeomPrimitivePipelineReader::ShadeModel GeomPrimitivePipelineReader::
600 get_shade_model() const {
601  return _cdata->_shade_model;
602 }
603 
604 ////////////////////////////////////////////////////////////////////
605 // Function: GeomPrimitivePipelineReader::get_usage_hint
606 // Access: Public
607 // Description:
608 ////////////////////////////////////////////////////////////////////
609 INLINE GeomPrimitivePipelineReader::UsageHint GeomPrimitivePipelineReader::
610 get_usage_hint() const {
611  return _cdata->_usage_hint;
612 }
613 
614 ////////////////////////////////////////////////////////////////////
615 // Function: GeomPrimitivePipelineReader::get_index_type
616 // Access: Public
617 // Description:
618 ////////////////////////////////////////////////////////////////////
619 INLINE GeomPrimitivePipelineReader::NumericType GeomPrimitivePipelineReader::
620 get_index_type() const {
621  return _cdata->_index_type;
622 }
623 
624 ////////////////////////////////////////////////////////////////////
625 // Function: GeomPrimitivePipelineReader::is_indexed
626 // Access: Public
627 // Description:
628 ////////////////////////////////////////////////////////////////////
629 INLINE bool GeomPrimitivePipelineReader::
630 is_indexed() const {
631  return (!_cdata->_vertices.is_null());
632 }
633 
634 ////////////////////////////////////////////////////////////////////
635 // Function: GeomPrimitivePipelineReader::get_num_vertices
636 // Access: Public
637 // Description:
638 ////////////////////////////////////////////////////////////////////
639 INLINE int GeomPrimitivePipelineReader::
640 get_num_vertices() const {
641  if (_cdata->_num_vertices != -1) {
642  return _cdata->_num_vertices;
643  } else {
644  nassertr(!_cdata->_vertices.is_null(), 0);
645  return _vertices_reader->get_num_rows();
646  }
647 }
648 
649 ////////////////////////////////////////////////////////////////////
650 // Function: GeomPrimitivePipelineReader::get_min_vertex
651 // Access: Public
652 // Description:
653 ////////////////////////////////////////////////////////////////////
654 INLINE int GeomPrimitivePipelineReader::
655 get_min_vertex() const {
656  nassertr(_cdata->_got_minmax, 0);
657  return _cdata->_min_vertex;
658 }
659 
660 ////////////////////////////////////////////////////////////////////
661 // Function: GeomPrimitivePipelineReader::get_max_vertex
662 // Access: Public
663 // Description:
664 ////////////////////////////////////////////////////////////////////
665 INLINE int GeomPrimitivePipelineReader::
666 get_max_vertex() const {
667  nassertr(_cdata->_got_minmax, 0);
668  return _cdata->_max_vertex;
669 }
670 
671 ////////////////////////////////////////////////////////////////////
672 // Function: GeomPrimitivePipelineReader::get_data_size_bytes
673 // Access: Published
674 // Description: Returns the number of bytes stored in the vertices
675 // array.
676 ////////////////////////////////////////////////////////////////////
679  return _vertices_reader->get_data_size_bytes();
680 }
681 
682 ////////////////////////////////////////////////////////////////////
683 // Function: GeomPrimitivePipelineReader::get_modified
684 // Access: Public
685 // Description:
686 ////////////////////////////////////////////////////////////////////
687 INLINE UpdateSeq GeomPrimitivePipelineReader::
688 get_modified() const {
689  return _cdata->_modified;
690 }
691 
692 ////////////////////////////////////////////////////////////////////
693 // Function: GeomPrimitivePipelineReader::get_index_stride
694 // Access: Public
695 // Description:
696 ////////////////////////////////////////////////////////////////////
697 INLINE int GeomPrimitivePipelineReader::
698 get_index_stride() const {
699  nassertr(is_indexed(), 0);
700  return _cdata->_vertices.get_read_pointer()->get_array_format()->get_stride();
701 }
702 
703 ////////////////////////////////////////////////////////////////////
704 // Function: GeomPrimitivePipelineReader::get_vertices_reader
705 // Access: Public
706 // Description:
707 ////////////////////////////////////////////////////////////////////
708 INLINE const GeomVertexArrayDataHandle *GeomPrimitivePipelineReader::
709 get_vertices_reader() const {
710  return _vertices_reader;
711 }
712 
713 ////////////////////////////////////////////////////////////////////
714 // Function: GeomPrimitivePipelineReader::get_read_pointer
715 // Access: Public
716 // Description:
717 ////////////////////////////////////////////////////////////////////
718 INLINE const unsigned char *GeomPrimitivePipelineReader::
719 get_read_pointer(bool force) const {
720  return _vertices_reader->get_read_pointer(force);
721 }
722 
723 ////////////////////////////////////////////////////////////////////
724 // Function: GeomPrimitivePipelineReader::get_strip_cut_index
725 // Access: Published
726 // Description:
727 ////////////////////////////////////////////////////////////////////
728 INLINE int GeomPrimitivePipelineReader::
729 get_strip_cut_index() const {
730  return GeomPrimitive::get_strip_cut_index(_cdata->_index_type);
731 }
732 
733 ////////////////////////////////////////////////////////////////////
734 // Function: GeomPrimitivePipelineReader::get_ends
735 // Access: Public
736 // Description:
737 ////////////////////////////////////////////////////////////////////
738 INLINE CPTA_int GeomPrimitivePipelineReader::
739 get_ends() const {
740  return _cdata->_ends;
741 }
742 
743 ////////////////////////////////////////////////////////////////////
744 // Function: GeomPrimitivePipelineReader::get_mins
745 // Access: Public
746 // Description:
747 ////////////////////////////////////////////////////////////////////
749 get_mins() const {
750  nassertr(is_indexed(), NULL);
751  nassertr(_cdata->_got_minmax, NULL);
752  return _cdata->_mins.get_read_pointer();
753 }
754 
755 ////////////////////////////////////////////////////////////////////
756 // Function: GeomPrimitivePipelineReader::get_maxs
757 // Access: Public
758 // Description:
759 ////////////////////////////////////////////////////////////////////
761 get_maxs() const {
762  nassertr(is_indexed(), NULL);
763  nassertr(_cdata->_got_minmax, NULL);
764  return _cdata->_maxs.get_read_pointer();
765 }
766 
767 ////////////////////////////////////////////////////////////////////
768 // Function: GeomPrimitivePipelineReader::prepare_now
769 // Access: Public
770 // Description:
771 ////////////////////////////////////////////////////////////////////
772 INLINE IndexBufferContext *GeomPrimitivePipelineReader::
773 prepare_now(PreparedGraphicsObjects *prepared_objects,
774  GraphicsStateGuardianBase *gsg) const {
775  return ((GeomPrimitive *)_object.p())->prepare_now(prepared_objects, gsg);
776 }
777 
778 INLINE ostream &
779 operator << (ostream &out, const GeomPrimitive &obj) {
780  obj.output(out);
781  return out;
782 }
int get_min_vertex() const
Returns the minimum vertex index number used by all the primitives in this object.
bool is_indexed() const
Returns true if the primitive is indexed, false otherwise.
virtual int get_min_num_vertices_per_primitive() const
Returns the minimum number of vertices that must be added before close_primitive() may legally be cal...
UsageHint get_usage_hint() const
Returns the usage hint for this primitive.
Definition: geomPrimitive.I:67
This is a special class object that holds all the information returned by a particular GSG to indicat...
int get_strip_cut_index() const
If relevant, returns the index value that may be used in some cases to signify the end of a primitive...
A single page of data maintained by a PipelineCycler.
Definition: cycleData.h:50
const GeomVertexArrayFormat * get_index_format() const
Returns a registered format appropriate for using to store the index table.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
Definition: geomPrimitive.h:63
virtual int get_num_vertices_per_primitive() const
If the primitive type is a simple type in which all primitives have the same number of vertices...
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
virtual int get_num_unused_vertices_per_primitive() const
Returns the number of vertices that are added between primitives that aren&#39;t, strictly speaking...
ShadeModel get_shade_model() const
Returns the ShadeModel hint for this primitive.
Definition: geomPrimitive.I:24
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
int get_index_stride() const
A convenience function to return the gap between successive index numbers, in bytes, of the index data.
A table of objects that are saved within the graphics context for reference by handle later...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
Definition: thread.I:145
This template class calls PipelineCycler::read_unlocked(), and then provides a transparent read-only ...
void add_vertex(int vertex)
Adds the indicated vertex to the list of vertex indices used by the graphics primitive type...
void add_vertices(int v1, int v2)
Adds several vertices in a row.
int get_first_vertex() const
Returns the first vertex number referenced by the primitive.
int get_max_vertex() const
Returns the maximum vertex index number used by all the primitives in this object.
int get_primitive_num_vertices(int n) const
Returns the number of vertices used by the nth primitive.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
bool check_valid(const GeomVertexData *vertex_data) const
Verifies that the primitive only references vertices that actually exist within the indicated GeomVer...
void set_shade_model(ShadeModel shade_model)
Changes the ShadeModel hint for this primitive.
Definition: geomPrimitive.I:45
bool is_composite() const
Returns true if the primitive is a composite primitive such as a tristrip or trifan, or false if it is a fundamental primitive such as a collection of triangles.
Definition: geomPrimitive.I:93
This template class calls PipelineCycler::write() in the constructor and PipelineCycler::release_writ...
int get_num_faces() const
Returns the number of triangles or other fundamental type (such as line segments) represented by all ...
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
void check_minmax() const
Ensures that the primitive&#39;s minmax cache has been computed.
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
int get_num_vertices() const
Returns the number of indices used by all the primitives in this object.
A thread; that is, a lightweight process.
Definition: thread.h:51
CPTA_int get_ends() const
Returns a const pointer to the primitive ends array so application code can read it directly...
int get_vertex(int i) const
Returns the ith vertex index in the table.
int get_primitive_num_faces(int n) const
Returns the number of triangles or other fundamental type (such as line segments) represented by the ...
UpdateSeq get_modified() const
Returns a sequence number which is guaranteed to change at least every time the vertex index array is...
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This is a sequence number that increments monotonically.
Definition: updateSeq.h:43
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
int get_vertex(int i) const
Returns the ith vertex index in the table.
int get_num_primitives() const
Returns the number of individual primitives stored within this object.
Similar to PointerToArray, except that its contents may not be modified.
This is the data for one array of a GeomVertexData structure.
NumericType get_index_type() const
Returns the numeric type of the index column.
Definition: geomPrimitive.I:79