Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

sglDrawable Class Reference

#include <sglDrawable.hpp>

Inheritance diagram for sglDrawable::

sglObject sglGeoSet sglInterleavedGeometry sglTextSet sglTexturedTextSet sglBezierCurveSet sglBezierSurfaceSet sglGeoStripSet sglIndexedGeoSet sglLineSet sglMonoIndexedGeoSet sglPointSet sglQuadSet sglTriangleSet List of all members.

Public Types

typedef void (sglDrawable::* DrawFunc )(const vector< sglTexCoords > &tex_coords) const
enum  AAEnum {
  ePOINT_AA,
  eLINE_AA,
  ePOLYGON_AA,
  eNO_AA
}

Public Methods

 sglDrawable ()
virtual ~sglDrawable ()
void enableDisplayList (bool on)
bool getDisplayListFlag () const
unsigned int getNumParents () const
sglGeodegetParent (unsigned int i)
unsigned int getNumStates ()
StateElement* getState (unsigned int index=0)
StateElement* getStateByMask (unsigned int mask=0) const
StateElement* findState (unsigned int mask) const
void setState (unsigned int mask, const vector< sglStatelet *> &statelets)
void setState (unsigned int mask, const vector< sglStatelet *> &statelets, sglVec2f *tex_coords)
void setState (unsigned int mask, const vector< sglStatelet *> &statelets, const sglTexCoords &tex_coords)
void setState (unsigned int mask, const vector< sglStatelet *> &statelets, const vector< sglTexCoords > &tex_coords)
void setTexCoordList (sglVec2f *tex_coords)
void setTexCoordList (const sglTexCoords &tex_coords)
void setTexCoordList (const vector< sglTexCoords > &tex_coords_list)
bool removeState (unsigned int mask)
void setBound (const sglBoxBound *bbox, sglBound::ModeEnum mode)
virtual const sglBoxBound& getBound ()
sglBound::ModeEnum getBoundMode ()
const sglBoxBound& getPrevBound () const
virtual void addStats (sglStats &stats) const=0
void preDraw ()
sglBound::IntersectResultEnum intersectBBox (sglIntersectf &segset)
sglBound::IntersectResultEnum intersectBBox (sglIntersectd &segset)
virtual sglBound::IntersectResultEnum intersectPrim (sglIntersectf &)
virtual sglBound::IntersectResultEnum intersectPrim (sglIntersectd &)
virtual bool isValid () const
virtual AAEnum getAAType () const
virtual void printInfo (ostream &ostrm, const char *indent_string) const
void drawImmediate (const vector< sglTexCoords > &tex_coords) const

Protected Types

enum  DirtyEnum {
  eBOUND = 0x01,
  eDLIST = 0x02
}

Protected Methods

virtual bool computeBounds ()=0
virtual void computeNoBounds ()
virtual void computeBoundsRecursiveDown ()
void dirty (unsigned char mask, bool all)
void addParent (sglGeode *parent)
void removeParent (sglGeode *parent)
bool cull (const sglFrustum< float > &frustum, unsigned int cull_flags) const
bool cull (const sglFrustum< double > &frustum, unsigned int cull_flags) const

Protected Attributes

sglBoxBound m_bbox
vector<StateElement *> m_state_list
bool m_use_dlist
DrawFunc m_draw_func
sglBound::ModeEnum m_bound_mode
unsigned char m_dirty
vector<sglGeode*> m_parent_list

Friends

class  sglGeode

Detailed Description

sglDrawable is the abstract base class for all objects that can be added to the sglGeode class and collected by the cull traversal for rendering (currently sglGeoSet, sglInterleavedGeometry and an internal sglText::sglTextSet class). It defines the interface (virtual functions) expected by the sglCull class. Its subclasses contain the information need to define various types of 3D objects. This class also contains "states", collections of statelets, that further define the appearance of the 3D objects. You will need to understand this class if you want to extend SGL's geometry nodes or create new types of renderables (that is, drawables).

{\bf Parent Lists}

Just as sglNodes can be added as children to multiple sglGroups, sglDrawable objects can be added to multiple sglGeodes. The sglGeodes are, in effect, the parents of these objects. These objects, therefore, maintain a list of pointers to their parent sglGeodes. The user can query the number of parents a geode has, as well as get pointers to these sglGeodes.

{\bf Axis-Aligned Bounding Boxes}

The group nodes (in the previous chapter) and sglGeode all have bounding spheres that encompass the extent in 3D space that all of its descendents lie within. A bounding sphere is used because its shape is invariant in the presence of affine transformations (is this really true). At this point in the scene graph (below sglGeode) there are no more transformations, and the extent of the geometry is easily represented by an axis-aligned bounding box. By default, this bounding box is automatically computed (by the subclasses). As in the sglNode classes, the user can override this behaviour by calling setBound with the sglBound::eSTATIC mode. The bound is either user-specified (if an sglBoxBound is provided) or computed from the current vertex data.

{\bf Disabling Display Lists}

As in sglText, the user can enable or disable the use of display lists to contain the geometry data. The same general rule of thumb applies: if the geometry data does not change often, then the display list generation should be enabled (the default). Otherwise, it is probably more efficient to disable the use of display lists as they won't mark the tree as dirty when the geometry changes (a dirtied tree is cleaned in preDraw() by traversing all the nodes with dirty bits set).

{\bf State}

Along with geometry data which is managed by the subclasses, OpenGL state information must also be associated with this to affect the appearance of the geometry. In SGL, state consists of a set (STL vector) of sglStatelets (one of each) and, optionally a set of texture coordinates (see State and Texture Coordinates below). SGL is capable of associating multiple different states with a given geometry using the setState(...) member function. The first parameter of this function is a unique bit flag (index) that identifies the state.

By default every sglDrawable has a default (empty) state associate with index 0. The user may override this, or add additional states with different indices. Usually a given state is associated with a single bit of the index (e.g., 0x01, 0x02, 0x04, etc.); however, there is nothing to stop the user from setting the state with an index with multiple bits set (e.g., 0x03, 0x11, etc.). If setState is called with the same index then the vector of statelets and texcoords replace the existing ones.

The purpose of the index is to aid in selection of a single state during the cull traversal. The sglScene::cull(...) function takes a state mask which is an unsigned int. When an sglDrawable passes the cull test (is selected for drawing), it is place on a render list along with a particular state. If no states have been defined, the default state (0) is placed in the render list along with the sglDrawable. Otherwise the list of state's indices are examined in the order they were added to the sglDrawable until the sglCull's state mask ANDed with the this evaluates to non-zero. The state corresponding to this index will be the one put in the render list. If none match, then the default state (index 0) will be used.

Note: when multitexture support is implemented then the behaviour described above may be modified. That is, more than one state may be selected and rendered. Multipass techniques might be accomplished this way as well.

{\bf State and Texture Coordinates}

Texture coordinates used to be one of the attribute arrays handled by sglGeoSet. Because each state (group of statelets) set in the call to setState can have a unique sglTexture, a unique texture coordinate array can be assigned with each state in the same call. If the state contains no sglTexture or an sglTexGen statelet is also present, then this parameter can be given as NULL (see the example below). Note that the other subclass of sglDrawable, sglInterleavedGeometry, has texture coordinates built in to the interleaved arrays, and any texture coordinate array passed into the setState() function is ignored.

{\bf Example:} \begin{verbatim} sglGeode *geode = new sglGeode; sglLineSet *geom = new sglLineSet; // a subclass of sglGeoSet geom->enableDisplayList(true); // the default anyway

geode->addGeometry(geom); unsigned int num = geom->getNumParents(); // returns 1 sglGeode *geode1 = geom->getParent(0); // returns geode

sglBoxBound bbox; bbox.setMin(-10.0f, -10.0f, -10.0f); bbox.setMax( 10.0f, 10.0f, 10.0f); geom->setBound(&bbox, sglBound::eSTATIC); // make bounds static

geom->setBound(NULL, sglBound::eDYNAMIC); // enable automatic computation

set a state - see statelets.html for more details transparency is enabled, and front face polygon style is GL_LINE. vector<sglStatelet*> statelets; statelets.push_back(new sglTransparency(true)); statelets.push_back(new sglPolyFrontStyle(sglPolyStyle::eLINE));

geom->setState(0x01, statelets); // no texcoords \end{verbatim}

Definition at line 169 of file sglDrawable.hpp.


Member Enumeration Documentation

enum sglDrawable::AAEnum
 

Anti-Aliasing types.

Definition at line 327 of file sglDrawable.hpp.


Constructor & Destructor Documentation

sglDrawable::sglDrawable ( )
 

default constructor.

sglDrawable::~sglDrawable ( ) [virtual]
 

virtual destructor.


Member Function Documentation

void sglDrawable::enableDisplayList ( bool on )
 

control whether to create a display list for this (default: true).

unsigned int sglDrawable::getNumStates ( ) [inline]
 

set/get the states.

Definition at line 245 of file sglDrawable.hpp.

void sglDrawable::setTexCoordList ( sglVec2f * tex_coords )
 

Assumes state mask 0.

void sglDrawable::setTexCoordList ( const sglTexCoords & tex_coords )
 

Assumes state mask 0.

void sglDrawable::setTexCoordList ( const vector< sglTexCoords > & tex_coords_list )
 

Assumes state mask 0.

bool sglDrawable::removeState ( unsigned int mask )
 

returns true if corresponding state was found AND deleted. Note you cannot remove the StateElement with zero mask, but calling removeState(0) is equivalent calling setState(0, NULL, NULL). Beware this doesn't delete tex_coords, but will delete statelets if their reference count goes to zero

void sglDrawable::setBound ( const sglBoxBound * bbox,
sglBound::ModeEnum mode )
 

If bbox = NULL, the bounds of this node are computed, else they are set from bbox. If mode is sglBound::eSTATIC, bounds are not set to reflect further changes (if bbox is NULL the bounding box is computed immediately), else if mode is sglBound::eDYNAMIC, bounds are recomputed as necessary.

const sglBoxBound & sglDrawable::getBound ( ) [virtual]
 

Returns the bounding volume (recalculating if necessary).

const sglBoxBound & sglDrawable::getPrevBound ( ) const [inline]
 

Returns the bounding volume as it was last computed.

Definition at line 301 of file sglDrawable.hpp.

void sglDrawable::addStats ( sglStats & stats ) const [pure virtual]
 

Add this drawable's stats to the given sglStats.

Parameters:
stats   The sglStats object to which to add the statistics.

Reimplemented in sglBezierSurfaceSet, sglGeoSet, sglGeoStripSet, sglIndexedGeoStripSet, sglInterleavedGeometry, sglMonoIndexedGeoStripSet, sglTextSet, and sglTexturedTextSet.

void sglDrawable::preDraw ( )
 

pre-draw traversal to clean the tree.

sglBound::IntersectResultEnum sglDrawable::intersectBBox ( sglIntersectf & segset )
 

intersect against the geoset (bbox only or primitives).

sglBound::IntersectResultEnum sglDrawable::intersectPrim ( sglIntersectf & segset ) [inline, virtual]
 

default behaviour for unimplemented versions.

Reimplemented in sglIndexedPolygonSet, sglIndexedQuadSet, sglIndexedQuadStripSet, sglIndexedTriangleFanSet, sglIndexedTriangleSet, sglIndexedTriangleStripSet, sglMonoIndexedPolygonSet, sglMonoIndexedQuadSet, sglMonoIndexedQuadStripSet, sglMonoIndexedTriangleFanSet, sglMonoIndexedTriangleSet, sglMonoIndexedTriangleStripSet, sglPolygonSet, sglQuadSet, sglQuadStripSet, sglTexturedTextSet, sglTriangleFanSet, sglTriangleSet, and sglTriangleStripSet.

Definition at line 317 of file sglDrawable.hpp.

virtual void sglDrawable::printInfo ( ostream & ostrm,
const char * indent_string ) const [virtual]
 

Output the state of this node to the specified ostream.

Parameters:
ostrm   the ostream to which the output is sent
indent_string   the string (usually spaces) that is output at the beginning of every line of output

Reimplemented from sglObject.

Reimplemented in sglGeoSet, sglInterleavedGeometry, sglTextSet, sglTexturedTextSet, and sglCylinder.

bool sglDrawable::computeBounds ( ) [protected, pure virtual]
 

Compute the bounding box for this geometry and fill in the member variable, m_bbox, in this class.

Returns:
true if successful (all information is available for computing a bounding box), otherwise false.

Reimplemented in sglBezierCurveSet, sglBezierSurfaceSet, sglGeoSet, sglGeoStripSet, sglIndexedGeoSet, sglIndexedGeoStripSet, sglInterleavedGeometry, sglMonoIndexedGeoSet, sglMonoIndexedGeoStripSet, sglTextSet, and sglTexturedTextSet.


The documentation for this class was generated from the following file:
Generated at Mon Jul 1 18:00:07 2002 for SGL by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001