This class defines the physical layout of the vertex data stored within a Geom. More...

#include "geomVertexFormat.h"

Inheritance diagram for GeomVertexFormat:
TypedWritableReferenceCount GeomEnums TypedWritable ReferenceCount TypedObject MemoryBase MemoryBase

List of all members.

Classes

class  DataTypeRecord
class  MorphRecord
class  Registry

Public Member Functions

 GeomVertexFormat (const GeomVertexArrayFormat *array_format)
 GeomVertexFormat (const GeomVertexFormat &copy)
int add_array (const GeomVertexArrayFormat *array_format)
 Adds the indicated array definition to the list of arrays included within this vertex format definition.
void align_columns_for_animation ()
 Reprocesses the columns in the format to align the C_point and C_vector columns to 16-byte boundaries to allow for the more efficient SSE2 operations (assuming SSE2 is enabled in the build).
void clear_arrays ()
 Removes all of the array definitions from the format and starts over.
int compare_to (const GeomVertexFormat &other) const
virtual int complete_pointers (TypedWritable **plist, BamReader *manager)
 Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
 CPT (GeomVertexFormat) get_post_animated_format() const
 CPT (GeomVertexFormat) get_union_format(const GeomVertexFormat *other) const
virtual TypeHandle force_init_type ()
const GeomVertexAnimationSpecget_animation () const
 Returns the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animation.
const GeomVertexArrayFormatget_array (int array) const
 Returns the description of the nth array used by the format.
bool get_array_info (const InternalName *name, int &array_index, const GeomVertexColumn *&column) const
 Quickly looks up the indicated column within all of the nested arrays and sets array_index and column appropriately.
int get_array_with (int i) const
 Returns the index number of the array with the ith column.
int get_array_with (const InternalName *name) const
 Returns the index number of the array with the indicated column, or -1 if no arrays contained that name.
int get_color_array_index () const
 Returns the array index of the array including the "color" column, or -1 if there is no such array.
const GeomVertexColumnget_color_column () const
 Returns the column definition of the "color" column, or NULL if there is no such column.
const GeomVertexColumnget_column (int i) const
 Returns the ith column of the specification, across all arrays.
const GeomVertexColumnget_column (const InternalName *name) const
 Returns the specification with the indicated name, or NULL if the name is not used.
const InternalNameget_morph_base (int n) const
 Returns the name of the base column that the nth morph modifies.
const InternalNameget_morph_delta (int n) const
 Returns the name of the column that defines the nth morph.
const InternalNameget_morph_slider (int n) const
 Returns the slider name associated with the nth morph column.
int get_normal_array_index () const
 Returns the array index of the array including the "normal" column, or -1 if there is no such array.
const GeomVertexColumnget_normal_column () const
 Returns the column definition of the "normal" column, or NULL if there is no such column.
int get_num_arrays () const
 Returns the number of individual arrays required by the format.
int get_num_columns () const
 Returns the total number of different columns in the specification, across all arrays.
int get_num_morphs () const
 Returns the number of columns within the format that represent morph deltas.
int get_num_points () const
 Returns the number of columns within the format that represent points in space.
int get_num_texcoords () const
 Returns the number of columns within the format that represent texture coordinates.
int get_num_vectors () const
 Returns the number of columns within the format that represent directional vectors.
const InternalNameget_point (int n) const
 Returns the name of the nth point column.
const InternalNameget_texcoord (int n) const
 Returns the name of the nth texcoord column.
virtual TypeHandle get_type () const
const InternalNameget_vector (int n) const
 Returns the name of the nth vector column.
int get_vertex_array_index () const
 Returns the array index of the array including the "vertex" column, or -1 if there is no such array.
const GeomVertexColumnget_vertex_column () const
 Returns the column definition of the "vertex" column, or NULL if there is no such column.
bool has_column (const InternalName *name) const
 Returns true if the format has the named column, false otherwise.
void insert_array (int array, const GeomVertexArrayFormat *array_format)
 Adds the indicated array definition to the list of arrays at the indicated position.
bool is_registered () const
 Returns true if this format has been registered, false if it has not.
 MAKE_SEQ (get_arrays, get_num_arrays, get_array)
 MAKE_SEQ (get_columns, get_num_columns, get_column)
 MAKE_SEQ (get_points, get_num_points, get_point)
 MAKE_SEQ (get_vectors, get_num_vectors, get_vector)
 MAKE_SEQ (get_texcoords, get_num_texcoords, get_texcoord)
 MAKE_SEQ (get_morph_sliders, get_num_morphs, get_morph_slider)
 MAKE_SEQ (get_morph_bases, get_num_morphs, get_morph_base)
 MAKE_SEQ (get_morph_deltas, get_num_morphs, get_morph_delta)
void maybe_align_columns_for_animation ()
 Calls align_columns_for_animation() if this format's AnimationSpec indicates that it contains animated vertices, and if vertex-animation-align-16 is true.
GeomVertexArrayFormatmodify_array (int array)
 Returns a modifiable pointer to the indicated array.
void operator= (const GeomVertexFormat &copy)
void output (ostream &out) const
void pack_columns ()
 Removes wasted space between columns.
void remove_array (int array)
 Removes the nth array from the format.
void remove_column (const InternalName *name, bool keep_empty_array=false)
 Removes the named column from the format, from whichever array it exists in.
void remove_empty_arrays ()
 Removes the arrays that define no columns.
void set_animation (const GeomVertexAnimationSpec &animation)
 Resets the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animation.
void set_array (int array, const GeomVertexArrayFormat *format)
 Replaces the definition of the indicated array.
virtual bool unref () const
 This method overrides ReferenceCount::unref() to unregister the object when its reference count goes to zero.
void write (ostream &out, int indent_level=0) 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.
void write_with_data (ostream &out, int indent_level, const GeomVertexData *data) const

Static Public Member Functions

static CPT (GeomVertexFormat) register_format(const GeomVertexFormat *format)
static CPT (GeomVertexFormat) register_format(const GeomVertexArrayFormat *format)
static TypeHandle get_class_type ()
static const GeomVertexFormatget_v3 ()
 Returns a standard vertex format with just a 3-component vertex position.
static const GeomVertexFormatget_v3c4 ()
 Returns a standard vertex format with a 4-component color and a 3-component vertex position.
static const GeomVertexFormatget_v3c4t2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color, and a 3-component vertex position.
static const GeomVertexFormatget_v3cp ()
 Returns a standard vertex format with a packed color and a 3-component vertex position.
static const GeomVertexFormatget_v3cpt2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair, a packed color, and a 3-component vertex position.
static const GeomVertexFormatget_v3n3 ()
 Returns a standard vertex format with a 3-component normal and a 3-component vertex position.
static const GeomVertexFormatget_v3n3c4 ()
 Returns a standard vertex format with a 4-component color, a 3-component normal, and a 3-component vertex position.
static const GeomVertexFormatget_v3n3c4t2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color, a 3-component normal, and a 3-component vertex position.
static const GeomVertexFormatget_v3n3cp ()
 Returns a standard vertex format with a packed color, a 3-component normal, and a 3-component vertex position.
static const GeomVertexFormatget_v3n3cpt2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair, a packed color, a 3-component normal, and a 3-component vertex position.
static const GeomVertexFormatget_v3n3t2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair, a 3-component normal, and a 3-component vertex position.
static const GeomVertexFormatget_v3t2 ()
 Returns a standard vertex format with a 2-component texture coordinate pair and a 3-component vertex position.
static void init_type ()
static void register_with_read_factory ()
 Tells the BamReader how to create objects of type GeomVertexFormat.

Protected Member Functions

void fillin (DatagramIterator &scan, BamReader *manager)
 This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new GeomVertexFormat.

Static Protected Member Functions

static TypedWritablemake_from_bam (const FactoryParams &params)
 This function is called by the BamReader's factory when a new object of type GeomVertexFormat is encountered in the Bam file.

Friends

class GeomMunger
class GeomVertexFormat::Registry

Detailed Description

This class defines the physical layout of the vertex data stored within a Geom.

The layout consists of a list of named columns, each of which has a numeric type and a size.

The columns are typically interleaved within a single array, but they may also be distributed among multiple different arrays; at the extreme, each column may be alone within its own array (which amounts to a parallel-array definition).

Thus, a GeomVertexFormat is really a list of GeomVertexArrayFormats, each of which contains a list of columns. However, a particular column name should not appear more than once in the format, even between different arrays.

There are a handful of standard pre-defined GeomVertexFormat objects, or you may define your own as needed. You may record any combination of standard and/or user-defined columns in your custom GeomVertexFormat constructions.

Definition at line 61 of file geomVertexFormat.h.


Member Function Documentation

int GeomVertexFormat::add_array ( const GeomVertexArrayFormat array_format)

Adds the indicated array definition to the list of arrays included within this vertex format definition.

The return value is the index number of the new array.

This may not be called once the format has been registered.

Definition at line 335 of file geomVertexFormat.cxx.

Reprocesses the columns in the format to align the C_point and C_vector columns to 16-byte boundaries to allow for the more efficient SSE2 operations (assuming SSE2 is enabled in the build).

Also see maybe_align_columns_for_animation().

Definition at line 603 of file geomVertexFormat.cxx.

Removes all of the array definitions from the format and starts over.

This may not be called once the format has been registered.

Definition at line 372 of file geomVertexFormat.cxx.

int GeomVertexFormat::complete_pointers ( TypedWritable **  p_list,
BamReader manager 
) [virtual]

Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().

Returns the number of pointers processed.

Reimplemented from TypedWritable.

Definition at line 944 of file geomVertexFormat.cxx.

References GeomVertexData::complete_pointers().

void GeomVertexFormat::fillin ( DatagramIterator scan,
BamReader manager 
) [protected, virtual]

This internal function is called by make_from_bam to read in all of the relevant data from the BamFile for the new GeomVertexFormat.

Reimplemented from TypedWritable.

Definition at line 984 of file geomVertexFormat.cxx.

References GeomVertexData::fillin(), DatagramIterator::get_uint16(), and BamReader::read_pointer().

bool GeomVertexFormat::get_array_info ( const InternalName name,
int &  array_index,
const GeomVertexColumn *&  column 
) const

Quickly looks up the indicated column within all of the nested arrays and sets array_index and column appropriately.

Returns true if the data type exists in this format, false if it does not. If it returns false, array_index is set to -1, and column is set to NULL.

This may only be called after the format has been registered.

Definition at line 707 of file geomVertexFormat.cxx.

int GeomVertexFormat::get_array_with ( int  i) const

Returns the index number of the array with the ith column.

The return value can be passed to get_array_format() to get the format of the array. It may also be passed to GeomVertexData::get_array_data() or get_data() or set_data() to manipulate the actual array data.

Definition at line 449 of file geomVertexFormat.cxx.

Referenced by GeomVertexData::copy_from(), GeomVertexData::describe_vertex(), GeomVertexReader::GeomVertexReader(), GeomVertexWriter::GeomVertexWriter(), GeomVertexReader::set_column(), and GeomVertexWriter::set_column().

int GeomVertexFormat::get_array_with ( const InternalName name) const

Returns the index number of the array with the indicated column, or -1 if no arrays contained that name.

The return value can be passed to get_array_format() to get the format of the array. It may also be passed to GeomVertexData::get_array_data() or get_data() or set_data() to manipulate the actual array data.

This may only be called after the format has been registered.

Definition at line 478 of file geomVertexFormat.cxx.

Returns the array index of the array including the "color" column, or -1 if there is no such array.

This may only be called after the format has been registered.

Definition at line 514 of file geomVertexFormat.I.

Returns the column definition of the "color" column, or NULL if there is no such column.

This may only be called after the format has been registered.

Definition at line 529 of file geomVertexFormat.I.

Returns the specification with the indicated name, or NULL if the name is not used.

Use get_array_with() to determine which array this column is associated with.

Definition at line 498 of file geomVertexFormat.cxx.

const InternalName * GeomVertexFormat::get_morph_base ( int  n) const [inline]

Returns the name of the base column that the nth morph modifies.

This column will also be defined within the format, and can be retrieved via get_array_with() and/or get_column().

This may only be called after the format has been registered.

Definition at line 274 of file geomVertexFormat.I.

const InternalName * GeomVertexFormat::get_morph_delta ( int  n) const [inline]

Returns the name of the column that defines the nth morph.

This contains the delta offsets that are to be applied to the column defined by get_morph_base(). This column will be defined within the format, and can be retrieved via get_array_with() and/or get_column().

This may only be called after the format has been registered.

Definition at line 295 of file geomVertexFormat.I.

const InternalName * GeomVertexFormat::get_morph_slider ( int  n) const [inline]

Returns the slider name associated with the nth morph column.

This is the name of the slider that will control the morph, and should be defined within the SliderTable associated with the GeomVertexData.

This may only be called after the format has been registered.

Definition at line 255 of file geomVertexFormat.I.

Returns the array index of the array including the "normal" column, or -1 if there is no such array.

This may only be called after the format has been registered.

Definition at line 484 of file geomVertexFormat.I.

Returns the column definition of the "normal" column, or NULL if there is no such column.

This may only be called after the format has been registered.

Definition at line 499 of file geomVertexFormat.I.

int GeomVertexFormat::get_num_arrays ( ) const [inline]

Returns the number of individual arrays required by the format.

If the array data is completely interleaved, this will be 1; if it is completely parallel, this will be the same as the number of data types.

Definition at line 104 of file geomVertexFormat.I.

Referenced by STTerrain::convert_vertex_format(), GeomVertexData::copy_from(), GeomVertexData::copy_row_from(), GeomVertexData::describe_vertex(), GeomVertexData::GeomVertexData(), and GeomVertexData::unclean_set_format().

Returns the total number of different columns in the specification, across all arrays.

Definition at line 408 of file geomVertexFormat.cxx.

Referenced by GeomVertexData::describe_vertex().

int GeomVertexFormat::get_num_morphs ( ) const [inline]

Returns the number of columns within the format that represent morph deltas.

This may only be called after the format has been registered.

Definition at line 237 of file geomVertexFormat.I.

int GeomVertexFormat::get_num_points ( ) const [inline]

Returns the number of columns within the format that represent points in space.

This may only be called after the format has been registered.

Definition at line 141 of file geomVertexFormat.I.

Referenced by GeomVertexData::transform_vertices().

int GeomVertexFormat::get_num_texcoords ( ) const [inline]

Returns the number of columns within the format that represent texture coordinates.

This may only be called after the format has been registered.

Definition at line 206 of file geomVertexFormat.I.

int GeomVertexFormat::get_num_vectors ( ) const [inline]

Returns the number of columns within the format that represent directional vectors.

This may only be called after the format has been registered.

Definition at line 173 of file geomVertexFormat.I.

Referenced by GeomVertexData::transform_vertices().

const InternalName * GeomVertexFormat::get_point ( int  n) const [inline]

Returns the name of the nth point column.

This represents a point in space, which should be transformed by any spatial transform matrix.

This may only be called after the format has been registered.

Definition at line 157 of file geomVertexFormat.I.

Referenced by GeomVertexData::transform_vertices().

const InternalName * GeomVertexFormat::get_texcoord ( int  n) const [inline]

Returns the name of the nth texcoord column.

This represents a texture coordinate.

This may only be called after the format has been registered.

Definition at line 221 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3c4 ( ) [inline, static]

Returns a standard vertex format with a 4-component color and a 3-component vertex position.

Definition at line 403 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3c4t2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color, and a 3-component vertex position.

Definition at line 427 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3cp ( ) [inline, static]

Returns a standard vertex format with a packed color and a 3-component vertex position.

Definition at line 355 of file geomVertexFormat.I.

Referenced by LineSegs::create(), PortalClipper::draw_lines(), CollisionLine::fill_viz_geom(), CollisionRay::fill_viz_geom(), CollisionParabola::fill_viz_geom(), and CollisionSegment::fill_viz_geom().

const GeomVertexFormat * GeomVertexFormat::get_v3cpt2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair, a packed color, and a 3-component vertex position.

Definition at line 379 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3 ( ) [inline, static]

Returns a standard vertex format with a 3-component normal and a 3-component vertex position.

Definition at line 320 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3c4 ( ) [inline, static]

Returns a standard vertex format with a 4-component color, a 3-component normal, and a 3-component vertex position.

Definition at line 415 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3c4t2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair, a 4-component color, a 3-component normal, and a 3-component vertex position.

Definition at line 440 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3cp ( ) [inline, static]

Returns a standard vertex format with a packed color, a 3-component normal, and a 3-component vertex position.

Definition at line 367 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3cpt2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair, a packed color, a 3-component normal, and a 3-component vertex position.

Definition at line 392 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3n3t2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair, a 3-component normal, and a 3-component vertex position.

Definition at line 344 of file geomVertexFormat.I.

const GeomVertexFormat * GeomVertexFormat::get_v3t2 ( ) [inline, static]

Returns a standard vertex format with a 2-component texture coordinate pair and a 3-component vertex position.

Definition at line 332 of file geomVertexFormat.I.

Referenced by PfmVizzer::generate_vis_points().

const InternalName * GeomVertexFormat::get_vector ( int  n) const [inline]

Returns the name of the nth vector column.

This represents a directional vector, which should be transformed by any spatial transform matrix as a vector.

This may only be called after the format has been registered.

Definition at line 190 of file geomVertexFormat.I.

Referenced by GeomVertexData::transform_vertices().

Returns the array index of the array including the "vertex" column, or -1 if there is no such array.

This may only be called after the format has been registered.

Definition at line 454 of file geomVertexFormat.I.

Returns the column definition of the "vertex" column, or NULL if there is no such column.

This may only be called after the format has been registered.

Definition at line 469 of file geomVertexFormat.I.

bool GeomVertexFormat::has_column ( const InternalName name) const [inline]

Returns true if the format has the named column, false otherwise.

Definition at line 127 of file geomVertexFormat.I.

References get_column().

void GeomVertexFormat::insert_array ( int  array,
const GeomVertexArrayFormat array_format 
)

Adds the indicated array definition to the list of arrays at the indicated position.

This works just like add_array(), except that you can specify which array index the new array should have.

This may not be called once the format has been registered.

Definition at line 355 of file geomVertexFormat.cxx.

bool GeomVertexFormat::is_registered ( ) const [inline]

Returns true if this format has been registered, false if it has not.

It may not be used for a Geom until it has been registered, but once registered, it may no longer be modified.

Definition at line 31 of file geomVertexFormat.I.

Referenced by GeomVertexData::GeomVertexData(), GeomVertexData::set_format(), and GeomVertexData::unclean_set_format().

TypedWritable * GeomVertexFormat::make_from_bam ( const FactoryParams params) [static, protected]

This function is called by the BamReader's factory when a new object of type GeomVertexFormat is encountered in the Bam file.

It should create the GeomVertexFormat and extract its information from the file.

Definition at line 965 of file geomVertexFormat.cxx.

Calls align_columns_for_animation() if this format's AnimationSpec indicates that it contains animated vertices, and if vertex-animation-align-16 is true.

Definition at line 622 of file geomVertexFormat.cxx.

Returns a modifiable pointer to the indicated array.

This means duplicating it if it is shared or registered.

This may not be called once the format has been registered.

Definition at line 280 of file geomVertexFormat.cxx.

Removes wasted space between columns.

Definition at line 581 of file geomVertexFormat.cxx.

void GeomVertexFormat::remove_array ( int  array)

Removes the nth array from the format.

This may not be called once the format has been registered.

Definition at line 316 of file geomVertexFormat.cxx.

void GeomVertexFormat::remove_column ( const InternalName name,
bool  keep_empty_array = false 
)

Removes the named column from the format, from whichever array it exists in.

If there are other columns remaining in the array, the array is left with a gap where the column used to be; if this was the only column in the array, the array is removed (unless keep_empty_array is true).

This may not be called once the format has been registered.

Definition at line 542 of file geomVertexFormat.cxx.

References GeomVertexArrayFormat::get_column(), GeomVertexArrayFormat::get_num_columns(), ReferenceCount::get_ref_count(), GeomVertexArrayFormat::is_registered(), and GeomVertexArrayFormat::remove_column().

Removes the arrays that define no columns.

This may not be called once the format has been registered.

Definition at line 387 of file geomVertexFormat.cxx.

References GeomVertexArrayFormat::get_num_columns().

void GeomVertexFormat::set_animation ( const GeomVertexAnimationSpec animation) [inline]

Resets the GeomVertexAnimationSpec that indicates how this format's vertices are set up for animation.

You should also, of course, change the columns in the tables accordingly.

This may not be called once the format has been registered.

Definition at line 89 of file geomVertexFormat.I.

void GeomVertexFormat::set_array ( int  array,
const GeomVertexArrayFormat format 
)

Replaces the definition of the indicated array.

This may not be called once the format has been registered.

Definition at line 301 of file geomVertexFormat.cxx.

bool GeomVertexFormat::unref ( ) const [virtual]

This method overrides ReferenceCount::unref() to unregister the object when its reference count goes to zero.

Reimplemented from ReferenceCount.

Definition at line 97 of file geomVertexFormat.cxx.

References ReferenceCount::unref().

void GeomVertexFormat::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.

Definition at line 924 of file geomVertexFormat.cxx.

References Datagram::add_uint16(), GeomVertexData::write_datagram(), and BamWriter::write_pointer().


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