14#ifndef GEOMPRIMITIVE_H
15#define GEOMPRIMITIVE_H
56class EXPCL_PANDA_GOBJ GeomPrimitive :
public CopyOnWriteObject,
public GeomEnums {
59 virtual PT(CopyOnWriteObject) make_cow_copy();
62 explicit GeomPrimitive(UsageHint usage_hint);
63 GeomPrimitive(
const GeomPrimitive ©);
64 void operator = (
const GeomPrimitive ©);
65 virtual ~GeomPrimitive();
66 ALLOC_DELETED_CHAIN(GeomPrimitive);
68 virtual PT(GeomPrimitive) make_copy()
const=0;
70 virtual PrimitiveType get_primitive_type()
const=0;
72 MAKE_PROPERTY(primitive_type, get_primitive_type);
101 INLINE
void add_vertices(
int v1,
int v2);
102 INLINE
void add_vertices(
int v1,
int v2,
int v3);
103 INLINE
void add_vertices(
int v1,
int v2,
int v3,
int v4);
130 CPT(GeomPrimitive)
rotate()
const;
132 CPT(GeomPrimitive)
reverse()
const;
151 virtual void output(std::ostream &out)
const;
152 virtual void write(std::ostream &out,
int indent_level)
const;
184 MAKE_PROPERTY(mins, get_mins);
185 MAKE_PROPERTY(maxs, get_maxs);
187 void set_minmax(
int min_vertex,
int max_vertex,
199 void prepare(PreparedGraphicsObjects *prepared_objects);
200 bool is_prepared(PreparedGraphicsObjects *prepared_objects)
const;
204 bool release(PreparedGraphicsObjects *prepared_objects);
214 void clear_prepared(PreparedGraphicsObjects *prepared_objects);
215 static int get_highest_index_value(NumericType index_type);
220 const GeomPrimitivePipelineReader *reader,
224 PN_stdfloat &sq_center_dist,
bool &found_any,
226 bool got_mat,
const LMatrix4 &mat,
228 Thread *current_thread)
const;
231 PN_stdfloat &sq_radius,
bool &found_any,
233 Thread *current_thread)
const;
236 virtual CPT(GeomPrimitive) decompose_impl()
const;
238 virtual CPT(GeomPrimitive) doubleside_impl()
const;
239 virtual CPT(GeomPrimitive) reverse_impl()
const;
240 virtual bool requires_unused_vertices()
const;
247 void recompute_minmax(CData *cdata);
248 void do_make_indexed(CData *cdata);
249 void consider_elevate_index_type(CData *cdata,
int vertex);
250 void do_set_index_type(CData *cdata, NumericType index_type);
258 typedef pmap<PreparedGraphicsObjects *, IndexBufferContext *> Contexts;
262 class EXPCL_PANDA_GOBJ CData :
public CycleData {
265 INLINE CData(
const CData ©);
266 ALLOC_DELETED_CHAIN(CData);
273 return GeomPrimitive::get_class_type();
276 ShadeModel _shade_model;
279 NumericType _index_type;
280 UsageHint _usage_hint;
288 unsigned int _min_vertex;
289 unsigned int _max_vertex;
295 static void init_type() {
300 static TypeHandle _type_handle;
302 friend class GeomPrimitive;
305 PipelineCycler<CData> _cycler;
306 typedef CycleDataReader<CData> CDReader;
307 typedef CycleDataWriter<CData> CDWriter;
308 typedef CycleDataStageReader<CData> CDStageReader;
309 typedef CycleDataStageWriter<CData> CDStageWriter;
312 static PStatCollector _decompose_pcollector;
313 static PStatCollector _doubleside_pcollector;
314 static PStatCollector _reverse_pcollector;
315 static PStatCollector _rotate_pcollector;
320 virtual void finalize(BamReader *manager);
323 void fillin(DatagramIterator &scan, BamReader *manager);
326 static TypeHandle get_class_type() {
329 static void init_type() {
330 CopyOnWriteObject::init_type();
332 CopyOnWriteObject::get_class_type());
335 virtual TypeHandle get_type()
const {
336 return get_class_type();
338 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
341 static TypeHandle _type_handle;
344 friend class PreparedGraphicsObjects;
345 friend class GeomPrimitivePipelineReader;
352class EXPCL_PANDA_GOBJ GeomPrimitivePipelineReader :
public GeomEnums {
355 GeomPrimitivePipelineReader(
const GeomPrimitivePipelineReader ©) =
delete;
356 INLINE ~GeomPrimitivePipelineReader();
358 ALLOC_DELETED_CHAIN(GeomPrimitivePipelineReader);
360 GeomPrimitivePipelineReader &operator = (
const GeomPrimitivePipelineReader ©) =
delete;
363 INLINE
Thread *get_current_thread()
const;
367 INLINE ShadeModel get_shade_model()
const;
368 INLINE UsageHint get_usage_hint()
const;
369 INLINE NumericType get_index_type()
const;
370 INLINE
bool is_indexed()
const;
371 int get_first_vertex()
const;
372 INLINE
int get_num_vertices()
const;
374 int get_num_primitives()
const;
376 INLINE
int get_min_vertex()
const;
377 INLINE
int get_max_vertex()
const;
381 INLINE
int get_index_stride()
const;
382 INLINE
const unsigned char *get_read_pointer(
bool force)
const;
383 INLINE
int get_strip_cut_index()
const;
384 INLINE CPTA_int get_ends()
const;
395 const GeomPrimitive::CData *_cdata;
398 const GeomVertexArrayData::CData *_vertices_cdata;
404 static void init_type() {
412INLINE std::ostream &operator << (std::ostream &out,
const GeomPrimitive &obj);
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A dynamic array with an unlimited number of bits.
A single page of data maintained by a PipelineCycler.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Encapsulates the data from a GeomPrimitive, pre-fetched for one stage of the pipeline.
int get_data_size_bytes() const
Returns the number of bytes stored in the vertices array.
void get_referenced_vertices(BitArray &bits) const
Turns on all the bits corresponding to the vertices that are referenced by this GeomPrimitive.
void check_minmax() const
Ensures that the primitive's minmax cache has been computed.
int get_vertex(int i) const
Returns the ith vertex index in the table.
This is an abstract base class for a family of classes that represent the fundamental geometry primit...
get_data_size_bytes
Returns the number of bytes stored in the vertices array.
get_min_num_vertices_per_primitive
Returns the minimum number of vertices that must be added before close_primitive() may legally be cal...
ConstPointerTo< GeomPrimitive > rotate() const
Returns a new primitive with the shade_model reversed (if it is flat shaded), if possible.
void clear_vertices()
Removes all of the vertices and primitives from the object, so they can be re-added.
virtual ConstPointerTo< GeomPrimitive > make_adjacency() const
Adds adjacency information to this primitive.
int get_primitive_num_faces(int n) const
Returns the number of triangles or other fundamental type (such as line segments) represented by the ...
int get_max_vertex() const
Returns the maximum vertex index number used by all the primitives in this object.
int get_num_primitives() const
Returns the number of individual primitives stored within this object.
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 an...
ConstPointerTo< GeomPrimitive > make_points() const
Returns a new GeomPoints primitive that represents each of the vertices in the original primitive,...
get_geom_rendering
Returns the set of GeomRendering bits that represent the rendering properties required to properly re...
CPTA_int get_ends() const
Returns a const pointer to the primitive ends array so application code can read it directly.
get_modified
Returns a sequence number which is guaranteed to change at least every time the vertex index array is...
get_vertex
Returns the ith vertex index in the table.
void reserve_num_vertices(int num_vertices)
This ensures that enough memory space for n vertices is allocated, so that you may increase the numbe...
int get_num_faces() const
Returns the number of triangles or other fundamental type (such as line segments) represented by all ...
int get_num_used_vertices() const
Returns the number of vertices used by all of the primitives.
ConstPointerTo< GeomPrimitive > make_lines() const
Returns a new GeomLines primitive that represents each of the edges in the original primitive rendere...
get_usage_hint
Returns the usage hint for this primitive.
ConstPointerTo< GeomPrimitive > reverse() const
Reverses the winding order in the primitive so that each triangle is facing in the opposite direction...
bool is_prepared(PreparedGraphicsObjects *prepared_objects) const
Returns true if the data has already been prepared or enqueued for preparation on the indicated GSG,...
void make_indexed()
Converts the primitive from nonindexed form to indexed form.
void add_consecutive_vertices(int start, int num_vertices)
Adds a consecutive sequence of vertices, beginning at start, to the primitive.
ConstPointerTo< GeomPrimitive > doubleside() const
Duplicates triangles in the primitive so that each triangle is back-to-back with another triangle fac...
get_num_vertices
Returns the number of indices used by all the primitives in this object.
bool check_valid(const GeomVertexData *vertex_data) const
Verifies that the primitive only references vertices that actually exist within the indicated GeomVer...
bool is_composite() const
Returns true if the primitive is a composite primitive such as a tristrip or trifan,...
get_strip_cut_index
Returns the index of the indicated type that is reserved for use as a strip cut index,...
ConstPointerTo< GeomPrimitive > match_shade_model(ShadeModel shade_model) const
Returns a new primitive that is compatible with the indicated shade model, if possible,...
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 indicate...
bool close_primitive()
Indicates that the previous n calls to add_vertex(), since the last call to close_primitive(),...
int get_first_vertex() const
Returns the first vertex number referenced by the primitive.
void set_shade_model(ShadeModel shade_model)
Changes the ShadeModel hint for this primitive.
int get_primitive_max_vertex(int n) const
Returns the maximum vertex index number used by the nth primitive in this object.
get_index_type
Returns the numeric type of the index column.
void set_nonindexed_vertices(int first_vertex, int num_vertices)
Sets the primitive up as a nonindexed primitive, using the indicated vertex range.
get_num_bytes
Returns the number of bytes consumed by the primitive and its index table(s).
bool request_resident(Thread *current_thread=Thread::get_current_thread()) const
Returns true if the primitive data is currently resident in memory.
get_num_unused_vertices_per_primitive
Returns the number of vertices that are added between primitives that aren't, strictly speaking,...
get_index_stride
A convenience function to return the gap between successive index numbers, in bytes,...
ConstPointerTo< GeomPrimitive > decompose() const
Decomposes a complex primitive type into a simpler primitive type, for instance triangle strips to tr...
void set_index_type(NumericType index_type)
Changes the numeric type of the index column.
void set_vertices(const GeomVertexArrayData *vertices, int num_vertices=-1)
Completely replaces the vertex index list with a new table.
void set_ends(PTA_int ends)
Completely replaces the primitive ends array with a new table.
void offset_vertices(int offset)
Adds the indicated offset to all vertices used by the primitive.
bool release(PreparedGraphicsObjects *prepared_objects)
Frees the data context only on the indicated object, if it exists there.
get_num_vertices_per_primitive
If the primitive type is a simple type in which all primitives have the same number of vertices,...
static const GeomVertexArrayFormat * get_index_format(NumericType index_type)
Returns a registered GeomVertexArrayFormat of the indicated unsigned integer numeric type for storing...
PTA_int modify_ends()
Returns a modifiable pointer to the primitive ends array, so application code can directly fiddle wit...
int get_primitive_min_vertex(int n) const
Returns the minimum vertex index number used by the nth primitive in this object.
void add_next_vertices(int num_vertices)
Adds the next n vertices in sequence, beginning from the last vertex added to the primitive + 1.
void make_nonindexed(GeomVertexData *dest, const GeomVertexData *source)
Converts the primitive from indexed to nonindexed by duplicating vertices as necessary into the indic...
void set_usage_hint(UsageHint usage_hint)
Changes the UsageHint hint for this primitive.
int get_primitive_start(int n) const
Returns the element within the _vertices list at which the nth primitive starts.
int get_min_vertex() const
Returns the minimum vertex index number used by all the primitives in this object.
get_shade_model
Returns the ShadeModel hint for this primitive.
void clear_minmax()
Undoes a previous call to set_minmax(), and allows the minimum and maximum values to be recomputed no...
void calc_sphere_radius(const LPoint3 ¢er, 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.
int release_all()
Frees the context allocated on all objects for which the data has been declared.
int get_primitive_num_vertices(int n) const
Returns the number of vertices used by the nth primitive.
int get_primitive_end(int n) const
Returns the element within the _vertices list at which the nth primitive ends.
void add_vertex(int vertex)
Adds the indicated vertex to the list of vertex indices used by the graphics primitive type.
void prepare(PreparedGraphicsObjects *prepared_objects)
Indicates that the data should be enqueued to be prepared in the indicated prepared_objects at the be...
bool is_indexed() const
Returns true if the primitive is indexed, false otherwise.
IndexBufferContext * prepare_now(PreparedGraphicsObjects *prepared_objects, GraphicsStateGuardianBase *gsg)
Creates a context for the data on the particular GSG, if it does not already exist.
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 ...
ConstPointerTo< GeomPrimitive > make_patches() const
Decomposes a complex primitive type into a simpler primitive type, for instance triangle strips to tr...
PointerTo< GeomVertexArrayData > modify_vertices(int num_vertices=-1)
Returns a modifiable pointer to the vertex index list, so application code can directly fiddle with t...
This data object is returned by GeomVertexArrayData::get_handle() or modify_handle().
This is the data for one array of a GeomVertexData structure.
Encapsulates the data from a GeomVertexData, pre-fetched for one stage of the pipeline.
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
This is a base class for the GraphicsStateGuardian class, which is itself a base class for the variou...
This is a special class object that holds all the information returned by a particular GSG to indicat...
Encodes a string name in a hash table, mapping it to a pointer.
A table of objects that are saved within the graphics context for reference by handle later.
A thread; that is, a lightweight process.
get_current_thread
Returns a pointer to the currently-executing Thread object.
TypeHandle is the identifier used to differentiate C++ class types.
Base class for objects that can be written to and read from Bam files.
virtual void finalize(BamReader *manager)
Called by the BamReader to perform any final actions needed for setting up the object after all objec...
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
This is a sequence number that increments monotonically.
This is our own Panda specialization on the default STL list.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.