Panda3D
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
GeomPrimitive Class Referenceabstract

This is an abstract base class for a family of classes that represent the fundamental geometry primitives that may be stored in a Geom. More...

#include "geomPrimitive.h"

Inheritance diagram for GeomPrimitive:
CopyOnWriteObject GeomEnums CachedTypedWritableReferenceCount TypedWritableReferenceCount TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase GeomLines GeomLinesAdjacency GeomLinestrips GeomLinestripsAdjacency GeomPatches GeomPoints GeomTriangles GeomTrianglesAdjacency GeomTrifans GeomTristrips GeomTristripsAdjacency

Public Member Functions

 GeomPrimitive (UsageHint usage_hint)
 
 GeomPrimitive (const GeomPrimitive &copy)
 
void add_consecutive_vertices (int start, int num_vertices)
 Adds a consecutive sequence of vertices, beginning at start, to the primitive. More...
 
void add_next_vertices (int num_vertices)
 Adds the next n vertices in sequence, beginning from the last vertex added to the primitive + 1. More...
 
void add_vertex (int vertex)
 Adds the indicated vertex to the list of vertex indices used by the graphics primitive type. More...
 
void add_vertices (int v1, int v2)
 
void add_vertices (int v1, int v2, int v3)
 Adds several vertices in a row. More...
 
void add_vertices (int v1, int v2, int v3, int v4)
 Adds several vertices in a row. More...
 
void calc_sphere_radius (const LPoint3 &center, PN_stdfloat &sq_radius, bool &found_any, const GeomVertexData *vertex_data, Thread *current_thread) const
 Expands radius so that a sphere with the given center point fits all of the vertices. More...
 
void calc_tight_bounds (LPoint3 &min_point, LPoint3 &max_point, PN_stdfloat &sq_center_dist, bool &found_any, const GeomVertexData *vertex_data, bool got_mat, const LMatrix4 &mat, const InternalName *column_name, Thread *current_thread) const
 Expands min_point and max_point to include all of the vertices in the Geom, if any (or the data of any point type, for instance, texture coordinates– based on the column name). More...
 
bool check_valid (const GeomVertexData *vertex_data) const
 Verifies that the primitive only references vertices that actually exist within the indicated GeomVertexData. More...
 
bool check_valid (const GeomVertexDataPipelineReader *data_reader) const
 
void clear_minmax ()
 Undoes a previous call to set_minmax(), and allows the minimum and maximum values to be recomputed normally. More...
 
void clear_vertices ()
 Removes all of the vertices and primitives from the object, so they can be re-added. More...
 
bool close_primitive ()
 Indicates that the previous n calls to add_vertex(), since the last call to close_primitive(), have fully defined a new primitive. More...
 
 CPT (GeomPrimitive) decompose() const
 
 CPT (GeomPrimitive) rotate() const
 
 CPT (GeomPrimitive) doubleside() const
 
 CPT (GeomPrimitive) reverse() const
 
 CPT (GeomPrimitive) match_shade_model(ShadeModel shade_model) const
 
 CPT (GeomPrimitive) make_points() const
 
 CPT (GeomPrimitive) make_lines() const
 
 CPT (GeomPrimitive) make_patches() const
 
virtual CPT (GeomPrimitive) make_adjacency() const
 
 CPT (GeomVertexArrayData) get_vertices() const
 
 CPT (GeomVertexArrayDataHandle) get_vertices_handle(Thread *current_thread) const
 
 CPT (GeomVertexArrayData) get_mins() const
 
 CPT (GeomVertexArrayData) get_maxs() const
 
virtual bool draw (GraphicsStateGuardianBase *gsg, const GeomPrimitivePipelineReader *reader, bool force) const =0
 
virtual void finalize (BamReader *manager)
 Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed. More...
 
virtual TypeHandle force_init_type ()
 
int get_data_size_bytes () const
 
CPTA_int get_ends () const
 Returns a const pointer to the primitive ends array so application code can read it directly. More...
 
int get_first_vertex () const
 Returns the first vertex number referenced by the primitive. More...
 
virtual int get_geom_rendering () const
 
const GeomVertexArrayFormatget_index_format () const
 Returns a registered format appropriate for using to store the index table. More...
 
int get_index_stride () const
 
NumericType get_index_type () const
 
int get_max_vertex () const
 Returns the maximum vertex index number used by all the primitives in this object. More...
 
virtual int get_min_num_vertices_per_primitive () const
 
int get_min_vertex () const
 Returns the minimum vertex index number used by all the primitives in this object. More...
 
UpdateSeq get_modified () const
 
int get_num_bytes () const
 
int get_num_faces () const
 Returns the number of triangles or other fundamental type (such as line segments) represented by all the primitives in this object. More...
 
int get_num_primitives () const
 Returns the number of individual primitives stored within this object. More...
 
virtual int get_num_unused_vertices_per_primitive () const
 
int get_num_used_vertices () const
 Returns the number of vertices used by all of the primitives. More...
 
int get_num_vertices () const
 
virtual int get_num_vertices_per_primitive () const
 
int get_primitive_end (int n) const
 Returns the element within the _vertices list at which the nth primitive ends. More...
 
int get_primitive_max_vertex (int n) const
 Returns the maximum vertex index number used by the nth primitive in this object. More...
 
int get_primitive_min_vertex (int n) const
 Returns the minimum vertex index number used by the nth primitive in this object. More...
 
int get_primitive_num_faces (int n) const
 Returns the number of triangles or other fundamental type (such as line segments) represented by the nth primitive in this object. More...
 
int get_primitive_num_vertices (int n) const
 Returns the number of vertices used by the nth primitive. More...
 
int get_primitive_start (int n) const
 Returns the element within the _vertices list at which the nth primitive starts. More...
 
virtual PrimitiveType get_primitive_type () const =0
 
ShadeModel get_shade_model () const
 
int get_strip_cut_index () const
 
virtual TypeHandle get_type () const
 
UsageHint get_usage_hint () const
 
int get_vertex (int i) const
 
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. More...
 
bool is_indexed () const
 Returns true if the primitive is indexed, false otherwise. More...
 
bool is_prepared (PreparedGraphicsObjects *prepared_objects) const
 Returns true if the data has already been prepared or enqueued for preparation on the indicated GSG, false otherwise. More...
 
void make_indexed ()
 Converts the primitive from nonindexed form to indexed form. More...
 
void make_nonindexed (GeomVertexData *dest, const GeomVertexData *source)
 Converts the primitive from indexed to nonindexed by duplicating vertices as necessary into the indicated dest GeomVertexData. More...
 
PTA_int modify_ends ()
 Returns a modifiable pointer to the primitive ends array, so application code can directly fiddle with this data. More...
 
void offset_vertices (int offset)
 Adds the indicated offset to all vertices used by the primitive. More...
 
void offset_vertices (int offset, int begin_row, int end_row)
 Adds the indicated offset to the indicated segment of vertices used by the primitive. More...
 
void operator= (const GeomPrimitive &copy)
 The copy assignment operator is not pipeline-safe. More...
 
virtual void output (std::ostream &out) const
 
void pack_vertices (GeomVertexData *dest, const GeomVertexData *source)
 Packs the vertices used by the primitive from the indicated source array onto the end of the indicated destination array. More...
 
void prepare (PreparedGraphicsObjects *prepared_objects)
 Indicates that the data should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame. More...
 
IndexBufferContextprepare_now (PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
 Creates a context for the data on the particular GSG, if it does not already exist. More...
 
virtual PT (GeomPrimitive) make_copy() const =0
 
 PT (GeomVertexArrayData) modify_vertices(int num_vertices
 
 PT (GeomVertexArrayDataHandle) modify_vertices_handle(Thread *current_thread)
 
 PT (GeomVertexArrayData) make_index_data() const
 
bool release (PreparedGraphicsObjects *prepared_objects)
 Frees the data context only on the indicated object, if it exists there. More...
 
int release_all ()
 Frees the context allocated on all objects for which the data has been declared. More...
 
bool request_resident (Thread *current_thread=Thread::get_current_thread()) const
 
void reserve_num_vertices (int num_vertices)
 This ensures that enough memory space for n vertices is allocated, so that you may increase the number of vertices to n without causing a new memory allocation. More...
 
void set_ends (PTA_int ends)
 Completely replaces the primitive ends array with a new table. More...
 
void set_index_type (NumericType index_type)
 Changes the numeric type of the index column. More...
 
void set_minmax (int min_vertex, int max_vertex, GeomVertexArrayData *mins, GeomVertexArrayData *maxs)
 Explicitly specifies the minimum and maximum vertices, as well as the lists of per-component min and max. More...
 
void set_nonindexed_vertices (int first_vertex, int num_vertices)
 Sets the primitive up as a nonindexed primitive, using the indicated vertex range. More...
 
void set_shade_model (ShadeModel shade_model)
 Changes the ShadeModel hint for this primitive. More...
 
void set_usage_hint (UsageHint usage_hint)
 Changes the UsageHint hint for this primitive. More...
 
void set_vertices (const GeomVertexArrayData *vertices, int num_vertices=-1)
 Completely replaces the vertex index list with a new table. More...
 
virtual void write (std::ostream &out, int indent_level) const
 
virtual void write_datagram (BamWriter *manager, Datagram &dg)
 Writes the contents of this object to the datagram for shipping out to a Bam file. More...
 
- Public Member Functions inherited from CopyOnWriteObject
 CopyOnWriteObject (const CopyOnWriteObject &copy)
 
void operator= (const CopyOnWriteObject &copy)
 
- Public Member Functions inherited from CachedTypedWritableReferenceCount
void cache_ref () const
 Explicitly increments the cache reference count and the normal reference count simultaneously. More...
 
void cache_ref_only () const
 Decrements the cache reference count without affecting the normal reference count. More...
 
bool cache_unref () const
 Explicitly decrements the cache reference count and the normal reference count simultaneously. More...
 
int get_cache_ref_count () const
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
- Public Member Functions inherited from TypedWritableReferenceCount
 TypedWritableReferenceCount (const TypedWritableReferenceCount &copy)
 
virtual ReferenceCountas_reference_count ()
 Returns the pointer cast to a ReferenceCount pointer, if it is in fact of that type. More...
 
void operator= (const TypedWritableReferenceCount &copy)
 
- Public Member Functions inherited from TypedWritable
 TypedWritable (const TypedWritable &copy)
 
virtual int complete_pointers (TypedWritable **p_list, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin(). More...
 
vector_uchar encode_to_bam_stream () const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and returns that data as a bytes object. More...
 
bool encode_to_bam_stream (vector_uchar &data, BamWriter *writer=nullptr) const
 Converts the TypedWritable object into a single stream of data using a BamWriter, and stores that data in the indicated string. More...
 
UpdateSeq get_bam_modified () const
 Returns the current bam_modified counter. More...
 
void mark_bam_modified ()
 Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any open bam streams. More...
 
void operator= (const TypedWritable &copy)
 
virtual bool require_fully_complete () const
 Some objects require all of their nested pointers to have been completed before the objects themselves can be completed. More...
 
virtual void update_bam_nested (BamWriter *manager)
 Called by the BamWriter when this object has not itself been modified recently, but it should check its nested objects for updates. More...
 
- Public Member Functions inherited from TypedObject
 TypedObject (const TypedObject &copy)=default
 
TypedObjectas_typed_object ()
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
const TypedObjectas_typed_object () const
 Returns the object, upcast (if necessary) to a TypedObject pointer. More...
 
int get_best_parent_from_Set (const std::set< int > &) const
 
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More...
 
bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly. More...
 
bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type. More...
 
TypedObjectoperator= (const TypedObject &copy)=default
 
- Public Member Functions inherited from ReferenceCount
int get_ref_count () const
 
WeakReferenceListget_weak_list () const
 Returns the WeakReferenceList associated with this ReferenceCount object. More...
 
bool has_weak_list () const
 Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More...
 
void local_object ()
 This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More...
 
void ref () const
 Explicitly increments the reference count. More...
 
bool ref_if_nonzero () const
 Atomically increases the reference count of this object if it is not zero. More...
 
bool test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus. More...
 
bool test_ref_count_nonzero () const
 Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More...
 
virtual bool unref () const
 Explicitly decrements the reference count. More...
 
WeakReferenceListweak_ref ()
 Adds the indicated PointerToVoid as a weak reference to this object. More...
 
void weak_unref ()
 Removes the indicated PointerToVoid as a weak reference to this object. More...
 

Static Public Member Functions

static TypeHandle get_class_type ()
 
static const GeomVertexArrayFormatget_index_format (NumericType index_type)
 Returns a registered GeomVertexArrayFormat of the indicated unsigned integer numeric type for storing index values. More...
 
static void init_type ()
 
- Static Public Member Functions inherited from CopyOnWriteObject
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from CachedTypedWritableReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedWritableReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 
static PT (TypedWritableReferenceCount) decode_from_bam_stream(vector_uchar data
 
- Static Public Member Functions inherited from TypedWritable
static bool decode_raw_from_bam_stream (TypedWritable *&ptr, ReferenceCount *&ref_ptr, vector_uchar data, BamReader *reader=nullptr)
 Reads the bytes created by a previous call to encode_to_bam_stream(), and extracts the single object on those bytes. More...
 
static TypeHandle get_class_type ()
 
static void init_type ()
 
- Static Public Member Functions inherited from TypedObject
static TypeHandle get_class_type ()
 
static void init_type ()
 This function is declared non-inline to work around a compiler bug in g++ 2.96. More...
 
- Static Public Member Functions inherited from ReferenceCount
static TypeHandle get_class_type ()
 
static void init_type ()
 

Public Attributes

 get_data_size_bytes
 Returns the number of bytes stored in the vertices array. More...
 
 get_geom_rendering
 Returns the set of GeomRendering bits that represent the rendering properties required to properly render this primitive. More...
 
 get_index_stride
 A convenience function to return the gap between successive index numbers, in bytes, of the index data. More...
 
 get_index_type
 Returns the numeric type of the index column. More...
 
 get_maxs
 
 get_min_num_vertices_per_primitive
 Returns the minimum number of vertices that must be added before close_primitive() may legally be called. More...
 
 get_mins
 
 get_modified
 Returns a sequence number which is guaranteed to change at least every time the vertex index array is modified. More...
 
 get_num_bytes
 
 get_num_unused_vertices_per_primitive
 Returns the number of vertices that are added between primitives that aren't, strictly speaking, part of the primitives themselves. More...
 
 get_num_vertices
 Returns the number of indices used by all the primitives in this object. More...
 
 get_num_vertices_per_primitive
 If the primitive type is a simple type in which all primitives have the same number of vertices, like triangles, returns the number of vertices per primitive. More...
 
 get_primitive_type
 
 get_shade_model
 Returns the ShadeModel hint for this primitive. More...
 
 get_strip_cut_index
 Returns the index of the indicated type that is reserved for use as a strip cut index, if enabled for the primitive. More...
 
 get_usage_hint
 Returns the usage hint for this primitive. More...
 
 get_vertex
 Returns the ith vertex index in the table. More...
 
- Public Attributes inherited from CachedTypedWritableReferenceCount
 get_cache_ref_count
 Returns the current reference count. More...
 
- Public Attributes inherited from TypedWritableReferenceCount
static BamReaderreader = nullptr)
 
- Public Attributes inherited from TypedObject
 get_type
 
- Public Attributes inherited from ReferenceCount
 get_ref_count
 Returns the current reference count. More...
 

Friends

class Geom
 
class GeomPrimitivePipelineReader
 
class PreparedGraphicsObjects
 

Additional Inherited Members

- Public Types inherited from GeomEnums
enum  AnimationType { AT_none, AT_panda, AT_hardware }
 
enum  Contents {
  C_other, C_point, C_clip_point, C_vector,
  C_texcoord, C_color, C_index, C_morph_delta,
  C_matrix, C_normal
}
 
enum  GeomRendering {
  GR_indexed_point = 0x00001, GR_indexed_other = 0x10000, GR_indexed_bits = 0x10001, GR_point = 0x00002,
  GR_point_uniform_size = 0x00004, GR_per_point_size = 0x00008, GR_point_perspective = 0x00010, GR_point_aspect_ratio = 0x00020,
  GR_point_scale = 0x00040, GR_point_rotate = 0x00080, GR_point_sprite = 0x00100, GR_point_sprite_tex_matrix = 0x00200,
  GR_point_bits = 0x003fe, GR_triangle_strip = 0x00400, GR_triangle_fan = 0x00800, GR_line_strip = 0x01000,
  GR_composite_bits = 0x01c00, GR_strip_cut_index = 0x20000, GR_flat_first_vertex = 0x02000, GR_flat_last_vertex = 0x04000,
  GR_shade_model_bits = 0x06000, GR_render_mode_wireframe = 0x40000, GR_render_mode_point = 0x80000, GR_adjacency = 0x100000
}
 
enum  NumericType {
  NT_uint8, NT_uint16, NT_uint32, NT_packed_dcba,
  NT_packed_dabc, NT_float32, NT_float64, NT_stdfloat,
  NT_int8, NT_int16, NT_int32, NT_packed_ufloat
}
 
enum  PrimitiveType {
  PT_none, PT_polygons, PT_lines, PT_points,
  PT_patches
}
 
enum  ShadeModel { SM_uniform, SM_smooth, SM_flat_first_vertex, SM_flat_last_vertex }
 
enum  UsageHint {
  UH_client, UH_stream, UH_dynamic, UH_static,
  UH_unspecified
}
 
- Static Public Attributes inherited from TypedWritable
static TypedWritable *const Null = nullptr
 

Detailed Description

This is an abstract base class for a family of classes that represent the fundamental geometry primitives that may be stored in a Geom.

They all have in common the fact that they are defined by tables of vertex data stored in a GeomVertexData object. Each GeomPrimitive object contains an ordered list of integers, which index into the vertex array defined by the GeomVertexData and define the particular vertices of the GeomVertexData that are used for this primitive.

The meaning of a given arrangement of vertices is defined by each individual primitive type; for instance, a GeomTriangle renders a triangle from each three consecutive vertices, while a GeomTriangleStrip renders a strip of (n - 2) connected triangles from each sequence of n vertices.

Definition at line 56 of file geomPrimitive.h.

Member Function Documentation

◆ add_consecutive_vertices()

void GeomPrimitive::add_consecutive_vertices ( int  start,
int  num_vertices 
)

Adds a consecutive sequence of vertices, beginning at start, to the primitive.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 241 of file geomPrimitive.cxx.

References get_num_primitives(), get_num_vertices, and get_primitive_end().

Referenced by add_next_vertices().

◆ add_next_vertices()

void GeomPrimitive::add_next_vertices ( int  num_vertices)

Adds the next n vertices in sequence, beginning from the last vertex added to the primitive + 1.

This is most useful when you are building up a primitive and a GeomVertexData at the same time, and you just want the primitive to reference the first n vertices from the data, then the next n, and so on.

Definition at line 308 of file geomPrimitive.cxx.

References add_consecutive_vertices(), get_num_vertices, and get_vertex.

◆ add_vertex()

void GeomPrimitive::add_vertex ( int  vertex)

Adds the indicated vertex to the list of vertex indices used by the graphics primitive type.

To define a primitive, you must call add_vertex() for each vertex of the new primitive, and then call close_primitive() after you have specified the last vertex of each primitive.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 161 of file geomPrimitive.cxx.

References get_num_primitives(), get_num_vertices, and get_primitive_end().

Referenced by add_vertices().

◆ add_vertices() [1/2]

void GeomPrimitive::add_vertices ( int  v1,
int  v2,
int  v3 
)
inline

Adds several vertices in a row.

Definition at line 368 of file geomPrimitive.I.

References add_vertex().

◆ add_vertices() [2/2]

void GeomPrimitive::add_vertices ( int  v1,
int  v2,
int  v3,
int  v4 
)
inline

Adds several vertices in a row.

Definition at line 378 of file geomPrimitive.I.

References add_vertex().

◆ calc_sphere_radius()

void GeomPrimitive::calc_sphere_radius ( const LPoint3 &  center,
PN_stdfloat &  sq_radius,
bool &  found_any,
const GeomVertexData vertex_data,
Thread current_thread 
) const

Expands radius so that a sphere with the given center point fits all of the vertices.

The center point is assumed to already have been transformed by the matrix, if one is given.

Definition at line 1750 of file geomPrimitive.cxx.

References GeomVertexReader::has_column().

◆ calc_tight_bounds()

void GeomPrimitive::calc_tight_bounds ( LPoint3 &  min_point,
LPoint3 &  max_point,
PN_stdfloat &  sq_center_dist,
bool &  found_any,
const GeomVertexData vertex_data,
bool  got_mat,
const LMatrix4 &  mat,
const InternalName column_name,
Thread current_thread 
) const

Expands min_point and max_point to include all of the vertices in the Geom, if any (or the data of any point type, for instance, texture coordinates– based on the column name).

found_any is set true if any points are found. It is the caller's responsibility to initialize min_point, max_point, and found_any before calling this function. It also sets sq_center_dist, which is the square of the maximum distance of the points to the center. This can be useful when deciding whether a sphere volume might be more appropriate.

Definition at line 1589 of file geomPrimitive.cxx.

◆ check_valid()

bool GeomPrimitive::check_valid ( const GeomVertexData vertex_data) const
inline

Verifies that the primitive only references vertices that actually exist within the indicated GeomVertexData.

Returns true if the primitive appears to be valid, false otherwise.

Definition at line 224 of file geomPrimitive.I.

◆ clear_minmax()

void GeomPrimitive::clear_minmax ( )

Undoes a previous call to set_minmax(), and allows the minimum and maximum values to be recomputed normally.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1318 of file geomPrimitive.cxx.

◆ clear_vertices()

void GeomPrimitive::clear_vertices ( )

Removes all of the vertices and primitives from the object, so they can be re-added.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 405 of file geomPrimitive.cxx.

References Geom::get_next_modified().

◆ close_primitive()

bool GeomPrimitive::close_primitive ( )

Indicates that the previous n calls to add_vertex(), since the last call to close_primitive(), have fully defined a new primitive.

Returns true if successful, false otherwise.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 355 of file geomPrimitive.cxx.

References get_num_unused_vertices_per_primitive, get_num_vertices, and get_num_vertices_per_primitive.

◆ finalize()

void GeomPrimitive::finalize ( BamReader manager)
virtual

Called by the BamReader to perform any final actions needed for setting up the object after all objects have been read and all pointers have been completed.

Reimplemented from TypedWritable.

Definition at line 2105 of file geomPrimitive.cxx.

References GeomVertexArrayData::get_usage_hint, and set_usage_hint().

◆ get_ends()

CPTA_int GeomPrimitive::get_ends ( ) const
inline

Returns a const pointer to the primitive ends array so application code can read it directly.

Do not attempt to modify the returned array; use modify_ends() or set_ends() for this.

Note that simple primitive types, like triangles, do not have a ends array: since all the primitives have the same number of vertices, it is not needed.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 314 of file geomPrimitive.I.

◆ get_first_vertex()

int GeomPrimitive::get_first_vertex ( ) const
inline

Returns the first vertex number referenced by the primitive.

This is particularly important in the case of a nonindexed primitive, in which case get_first_vertex() and get_num_vertices() completely define the extent of the vertex range.

Definition at line 98 of file geomPrimitive.I.

◆ get_index_format() [1/2]

const GeomVertexArrayFormat * GeomPrimitive::get_index_format ( NumericType  index_type)
static

Returns a registered GeomVertexArrayFormat of the indicated unsigned integer numeric type for storing index values.

Definition at line 1475 of file geomPrimitive.cxx.

◆ get_index_format() [2/2]

const GeomVertexArrayFormat * GeomPrimitive::get_index_format ( ) const
inline

Returns a registered format appropriate for using to store the index table.

Definition at line 389 of file geomPrimitive.I.

References get_index_type.

◆ get_max_vertex()

int GeomPrimitive::get_max_vertex ( ) const
inline

Returns the maximum vertex index number used by all the primitives in this object.

Definition at line 192 of file geomPrimitive.I.

References GeomPrimitivePipelineReader::check_minmax().

◆ get_min_vertex()

int GeomPrimitive::get_min_vertex ( ) const
inline

Returns the minimum vertex index number used by all the primitives in this object.

Definition at line 181 of file geomPrimitive.I.

References GeomPrimitivePipelineReader::check_minmax().

◆ get_num_faces()

int GeomPrimitive::get_num_faces ( ) const
inline

Returns the number of triangles or other fundamental type (such as line segments) represented by all the primitives in this object.

Definition at line 147 of file geomPrimitive.I.

References get_min_num_vertices_per_primitive, get_num_primitives(), get_num_unused_vertices_per_primitive, get_num_vertices, and get_num_vertices_per_primitive.

◆ get_num_primitives()

int GeomPrimitive::get_num_primitives ( ) const
inline

Returns the number of individual primitives stored within this object.

All primitives are the same type.

Definition at line 126 of file geomPrimitive.I.

References get_num_vertices, and get_num_vertices_per_primitive.

Referenced by add_consecutive_vertices(), add_vertex(), get_num_faces(), and get_num_used_vertices().

◆ get_num_used_vertices()

int GeomPrimitive::get_num_used_vertices ( ) const

Returns the number of vertices used by all of the primitives.

This is the same as summing get_primitive_num_vertices(n) for n in get_num_primitives(). It is like get_num_vertices except that it excludes all of the degenerate vertices and strip-cut indices.

Definition at line 719 of file geomPrimitive.cxx.

References get_num_primitives(), get_num_unused_vertices_per_primitive, and get_num_vertices.

◆ get_primitive_end()

int GeomPrimitive::get_primitive_end ( int  n) const

Returns the element within the _vertices list at which the nth primitive ends.

This is one past the last valid element for the nth primitive.

Definition at line 667 of file geomPrimitive.cxx.

References get_num_vertices_per_primitive.

Referenced by add_consecutive_vertices(), and add_vertex().

◆ get_primitive_max_vertex()

int GeomPrimitive::get_primitive_max_vertex ( int  n) const

Returns the maximum vertex index number used by the nth primitive in this object.

Definition at line 753 of file geomPrimitive.cxx.

References is_indexed().

◆ get_primitive_min_vertex()

int GeomPrimitive::get_primitive_min_vertex ( int  n) const

Returns the minimum vertex index number used by the nth primitive in this object.

Definition at line 735 of file geomPrimitive.cxx.

References is_indexed().

◆ get_primitive_num_faces()

int GeomPrimitive::get_primitive_num_faces ( int  n) const
inline

Returns the number of triangles or other fundamental type (such as line segments) represented by the nth primitive in this object.

Definition at line 166 of file geomPrimitive.I.

References get_min_num_vertices_per_primitive, get_num_vertices_per_primitive, and get_primitive_num_vertices().

◆ get_primitive_num_vertices()

int GeomPrimitive::get_primitive_num_vertices ( int  n) const

Returns the number of vertices used by the nth primitive.

This is the same thing as get_primitive_end(n) - get_primitive_start(n).

Definition at line 690 of file geomPrimitive.cxx.

References get_num_vertices_per_primitive.

Referenced by get_primitive_num_faces().

◆ get_primitive_start()

int GeomPrimitive::get_primitive_start ( int  n) const

Returns the element within the _vertices list at which the nth primitive starts.

If i is one more than the highest valid primitive vertex, the return value will be one more than the last valid vertex. Thus, it is generally true that the vertices used by a particular primitive i are the set get_primitive_start(n) <= vi < get_primitive_start(n + 1) (although this range also includes the unused vertices between primitives).

Definition at line 640 of file geomPrimitive.cxx.

References get_num_unused_vertices_per_primitive, and get_num_vertices_per_primitive.

◆ is_composite()

bool GeomPrimitive::is_composite ( ) const
inline

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 at line 74 of file geomPrimitive.I.

References get_num_vertices_per_primitive.

◆ is_indexed()

bool GeomPrimitive::is_indexed ( ) const
inline

Returns true if the primitive is indexed, false otherwise.

An indexed primitive stores a table of index numbers into its GeomVertexData, so that it can reference the vertices in any order. A nonindexed primitive, on the other hand, stores only the first vertex number and number of vertices used, so that it can only reference the vertices consecutively.

Definition at line 86 of file geomPrimitive.I.

Referenced by get_primitive_max_vertex(), get_primitive_min_vertex(), offset_vertices(), pack_vertices(), and prepare().

◆ is_prepared()

bool GeomPrimitive::is_prepared ( PreparedGraphicsObjects prepared_objects) const

Returns true if the data has already been prepared or enqueued for preparation on the indicated GSG, false otherwise.

Definition at line 1387 of file geomPrimitive.cxx.

References PreparedGraphicsObjects::is_index_buffer_queued().

◆ make_indexed()

void GeomPrimitive::make_indexed ( )

Converts the primitive from nonindexed form to indexed form.

This will simply create an index table that is numbered consecutively from get_first_vertex(); it does not automatically collapse together identical vertices that may have been split apart by a previous call to make_nonindexed().

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 624 of file geomPrimitive.cxx.

◆ make_nonindexed()

void GeomPrimitive::make_nonindexed ( GeomVertexData dest,
const GeomVertexData source 
)

Converts the primitive from indexed to nonindexed by duplicating vertices as necessary into the indicated dest GeomVertexData.

Note: does not support primitives with strip cut indices.

Definition at line 539 of file geomPrimitive.cxx.

Referenced by pack_vertices().

◆ modify_ends()

PTA_int GeomPrimitive::modify_ends ( )

Returns a modifiable pointer to the primitive ends array, so application code can directly fiddle with this data.

Use with caution, since there are no checks that the data will be left in a stable state.

Note that simple primitive types, like triangles, do not have a ends array: since all the primitives have the same number of vertices, it is not needed.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1242 of file geomPrimitive.cxx.

References Geom::get_next_modified().

◆ offset_vertices() [1/2]

void GeomPrimitive::offset_vertices ( int  offset)

Adds the indicated offset to all vertices used by the primitive.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 430 of file geomPrimitive.cxx.

References is_indexed().

◆ offset_vertices() [2/2]

void GeomPrimitive::offset_vertices ( int  offset,
int  begin_row,
int  end_row 
)

Adds the indicated offset to the indicated segment of vertices used by the primitive.

Unlike the other version of offset_vertices, this makes the geometry indexed if it isn't already.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 477 of file geomPrimitive.cxx.

◆ operator=()

void GeomPrimitive::operator= ( const GeomPrimitive copy)

The copy assignment operator is not pipeline-safe.

This will completely obliterate all stages of the pipeline, so don't do it for a GeomPrimitive that is actively being used for rendering.

Definition at line 86 of file geomPrimitive.cxx.

◆ pack_vertices()

void GeomPrimitive::pack_vertices ( GeomVertexData dest,
const GeomVertexData source 
)

Packs the vertices used by the primitive from the indicated source array onto the end of the indicated destination array.

Definition at line 571 of file geomPrimitive.cxx.

References GeomVertexData::get_num_rows(), get_num_vertices, get_strip_cut_index, is_indexed(), and make_nonindexed().

◆ prepare()

void GeomPrimitive::prepare ( PreparedGraphicsObjects prepared_objects)

Indicates that the data should be enqueued to be prepared in the indicated prepared_objects at the beginning of the next frame.

This will ensure the data is already loaded into the GSG if it is expected to be rendered soon.

Use this function instead of prepare_now() to preload datas from a user interface standpoint.

Definition at line 1376 of file geomPrimitive.cxx.

References PreparedGraphicsObjects::enqueue_index_buffer(), and is_indexed().

◆ prepare_now()

IndexBufferContext * GeomPrimitive::prepare_now ( PreparedGraphicsObjects prepared_objects,
GraphicsStateGuardianBase gsg 
)

Creates a context for the data on the particular GSG, if it does not already exist.

Returns the new (or old) IndexBufferContext. This assumes that the GraphicsStateGuardian is the currently active rendering context and that it is ready to accept new datas. If this is not necessarily the case, you should use prepare() instead.

Normally, this is not called directly except by the GraphicsStateGuardian; a data does not need to be explicitly prepared by the user before it may be rendered.

Definition at line 1408 of file geomPrimitive.cxx.

◆ release()

bool GeomPrimitive::release ( PreparedGraphicsObjects prepared_objects)

Frees the data context only on the indicated object, if it exists there.

Returns true if it was released, false if it had not been prepared.

Definition at line 1430 of file geomPrimitive.cxx.

References PreparedGraphicsObjects::dequeue_index_buffer(), and PreparedGraphicsObjects::release_index_buffer().

◆ release_all()

int GeomPrimitive::release_all ( )

Frees the context allocated on all objects for which the data has been declared.

Returns the number of contexts which have been freed.

Definition at line 1448 of file geomPrimitive.cxx.

References PreparedGraphicsObjects::release_index_buffer().

◆ reserve_num_vertices()

void GeomPrimitive::reserve_num_vertices ( int  num_vertices)

This ensures that enough memory space for n vertices is allocated, so that you may increase the number of vertices to n without causing a new memory allocation.

This is a performance optimization only; it is especially useful when you know ahead of time that you will be adding n vertices to the primitive.

Note that the total you specify here should also include implicit vertices which may be added at each close_primitive() call, according to get_num_unused_vertices_per_primitive().

Note also that making this call will implicitly make the primitive indexed if it is not already, which could result in a performance *penalty*. If you would prefer not to lose the nonindexed nature of your existing GeomPrimitives, check is_indexed() before making this call.

Definition at line 333 of file geomPrimitive.cxx.

◆ set_ends()

void GeomPrimitive::set_ends ( PTA_int  ends)

Completely replaces the primitive ends array with a new table.

Chances are good that you should also replace the vertices list with set_vertices() at the same time.

Note that simple primitive types, like triangles, do not have a ends array: since all the primitives have the same number of vertices, it is not needed.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1273 of file geomPrimitive.cxx.

◆ set_index_type()

void GeomPrimitive::set_index_type ( GeomPrimitive::NumericType  index_type)

Changes the numeric type of the index column.

Normally, this should be either NT_uint16 or NT_uint32.

The index type must be large enough to include all of the index values in the primitive. It may be automatically elevated, if necessary, to a larger index type, by a subsequent call to add_index() that names an index value that does not fit in the index type you specify.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 142 of file geomPrimitive.cxx.

◆ set_minmax()

void GeomPrimitive::set_minmax ( int  min_vertex,
int  max_vertex,
GeomVertexArrayData mins,
GeomVertexArrayData maxs 
)

Explicitly specifies the minimum and maximum vertices, as well as the lists of per-component min and max.

Use this method with extreme caution. It's generally better to let the GeomPrimitive compute these explicitly, unless for some reason you can do it faster and you absolutely need the speed improvement.

Note that any modification to the vertex array will normally cause this to be recomputed, unless you set it immediately again.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1297 of file geomPrimitive.cxx.

References Geom::get_next_modified().

◆ set_nonindexed_vertices()

void GeomPrimitive::set_nonindexed_vertices ( int  first_vertex,
int  num_vertices 
)

Sets the primitive up as a nonindexed primitive, using the indicated vertex range.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1211 of file geomPrimitive.cxx.

◆ set_shade_model()

void GeomPrimitive::set_shade_model ( GeomPrimitive::ShadeModel  shade_model)
inline

Changes the ShadeModel hint for this primitive.

This is different from the ShadeModelAttrib that might also be applied from the scene graph. This does not affect the shade model that is in effect when rendering, but rather serves as a hint to the renderer to tell it how the per-vertex colors and normals on this primitive are applied.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 36 of file geomPrimitive.I.

◆ set_usage_hint()

void GeomPrimitive::set_usage_hint ( GeomPrimitive::UsageHint  usage_hint)

Changes the UsageHint hint for this primitive.

See get_usage_hint().

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

Definition at line 119 of file geomPrimitive.cxx.

References Geom::get_next_modified().

Referenced by finalize().

◆ set_vertices()

void GeomPrimitive::set_vertices ( const GeomVertexArrayData vertices,
int  num_vertices = -1 
)

Completely replaces the vertex index list with a new table.

Chances are good that you should also replace the ends list with set_ends() at the same time.

If num_vertices is not -1, it specifies an artificial limit to the number of vertices in the array. Otherwise, all of the vertices in the array will be used.

Don't call this in a downstream thread unless you don't mind it blowing away other changes you might have recently made in an upstream thread.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 1185 of file geomPrimitive.cxx.

References GeomVertexArrayData::get_array_format.

◆ write_datagram()

void GeomPrimitive::write_datagram ( BamWriter manager,
Datagram dg 
)
virtual

Writes the contents of this object to the datagram for shipping out to a Bam file.

Reimplemented from TypedWritable.

Reimplemented in GeomPatches.

Definition at line 2093 of file geomPrimitive.cxx.

References BamWriter::write_cdata(), and TypedWritable::write_datagram().

Referenced by GeomPatches::write_datagram().

Member Data Documentation

◆ get_data_size_bytes

int GeomPrimitive::get_data_size_bytes
inline

Returns the number of bytes stored in the vertices array.

Definition at line 143 of file geomPrimitive.h.

Referenced by PreparedGraphicsObjects::release_index_buffer().

◆ get_geom_rendering

int GeomPrimitive::get_geom_rendering

Returns the set of GeomRendering bits that represent the rendering properties required to properly render this primitive.

Definition at line 73 of file geomPrimitive.h.

◆ get_index_stride

int GeomPrimitive::get_index_stride
inline

A convenience function to return the gap between successive index numbers, in bytes, of the index data.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 175 of file geomPrimitive.h.

◆ get_index_type

GeomPrimitive::NumericType GeomPrimitive::get_index_type
inline

Returns the numeric type of the index column.

Normally, this will be either NT_uint16 or NT_uint32.

Definition at line 85 of file geomPrimitive.h.

Referenced by get_index_format().

◆ get_min_num_vertices_per_primitive

int GeomPrimitive::get_min_num_vertices_per_primitive

Returns the minimum number of vertices that must be added before close_primitive() may legally be called.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 195 of file geomPrimitive.h.

Referenced by get_num_faces(), and get_primitive_num_faces().

◆ get_modified

UpdateSeq GeomPrimitive::get_modified
inline

Returns a sequence number which is guaranteed to change at least every time the vertex index array is modified.

Definition at line 144 of file geomPrimitive.h.

◆ get_num_unused_vertices_per_primitive

int GeomPrimitive::get_num_unused_vertices_per_primitive

Returns the number of vertices that are added between primitives that aren't, strictly speaking, part of the primitives themselves.

This is used, for instance, to define degenerate triangles to connect otherwise disconnected triangle strips.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 196 of file geomPrimitive.h.

Referenced by close_primitive(), get_num_faces(), get_num_used_vertices(), and get_primitive_start().

◆ get_num_vertices

int GeomPrimitive::get_num_vertices
inline

Returns the number of indices used by all the primitives in this object.

Definition at line 99 of file geomPrimitive.h.

Referenced by add_consecutive_vertices(), add_next_vertices(), add_vertex(), close_primitive(), get_num_faces(), get_num_primitives(), get_num_used_vertices(), and pack_vertices().

◆ get_num_vertices_per_primitive

int GeomPrimitive::get_num_vertices_per_primitive

If the primitive type is a simple type in which all primitives have the same number of vertices, like triangles, returns the number of vertices per primitive.

If the primitive type is a more complex type in which different primitives might have different numbers of vertices, for instance a triangle strip, returns 0.

This method is intended for low-level usage only. There are higher-level methods for more common usage. We recommend you do not use this method directly. If you do, be sure you know what you are doing!

Definition at line 194 of file geomPrimitive.h.

Referenced by close_primitive(), get_num_faces(), get_num_primitives(), get_primitive_end(), get_primitive_num_faces(), get_primitive_num_vertices(), get_primitive_start(), and is_composite().

◆ get_shade_model

GeomPrimitive::ShadeModel GeomPrimitive::get_shade_model
inline

Returns the ShadeModel hint for this primitive.

This is intended as a hint to the renderer to tell it how the per-vertex colors and normals are applied.

Definition at line 77 of file geomPrimitive.h.

◆ get_strip_cut_index

int GeomPrimitive::get_strip_cut_index
inline

Returns the index of the indicated type that is reserved for use as a strip cut index, if enabled for the primitive.

If relevant, returns the index value that may be used in some cases to signify the end of a primitive.

When the renderer encounters this index, it will restart the primitive. This is guaranteed not to point to an actual vertex.

This is typically the highest value that the numeric type can store.

Definition at line 176 of file geomPrimitive.h.

Referenced by pack_vertices().

◆ get_usage_hint

GeomPrimitive::UsageHint GeomPrimitive::get_usage_hint
inline

Returns the usage hint for this primitive.

See geomEnums.h. This has nothing to do with the usage hint associated with the primitive's vertices; this only specifies how often the vertex indices that define the primitive will be modified.

It is perfectly legal (and, in fact, common) for a GeomPrimitive to have UH_static on itself, while referencing vertex data with UH_dynamic. This means that the vertices themselves will be animated, but the primitive will always reference the same set of vertices from the pool.

Definition at line 81 of file geomPrimitive.h.

Referenced by PreparedGraphicsObjects::release_index_buffer().

◆ get_vertex

int GeomPrimitive::get_vertex
inline

Returns the ith vertex index in the table.

Definition at line 99 of file geomPrimitive.h.

Referenced by add_next_vertices().


The documentation for this class was generated from the following files: