OpenSceneGraph  3.4.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends
osg::Drawable Class Reference

Pure virtual base class for drawable geometry. More...

Inheritance diagram for osg::Drawable:
Inheritance graph
[legend]

List of all members.

Classes

class  AttributeFunctor
struct  ComputeBoundingBoxCallback
 Callback to allow users to override the default computation of bounding volume. More...
class  ConstAttributeFunctor
struct  CullCallback
struct  DrawCallback
 Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object. More...
struct  EventCallback
struct  UpdateCallback

Public Types

enum  AttributeTypes {
  VERTICES = 0, WEIGHTS = 1, NORMALS = 2, COLORS = 3,
  SECONDARY_COLORS = 4, FOG_COORDS = 5, ATTRIBUTE_6 = 6, ATTRIBUTE_7 = 7,
  TEXTURE_COORDS = 8, TEXTURE_COORDS_0 = TEXTURE_COORDS, TEXTURE_COORDS_1 = TEXTURE_COORDS_0+1, TEXTURE_COORDS_2 = TEXTURE_COORDS_0+2,
  TEXTURE_COORDS_3 = TEXTURE_COORDS_0+3, TEXTURE_COORDS_4 = TEXTURE_COORDS_0+4, TEXTURE_COORDS_5 = TEXTURE_COORDS_0+5, TEXTURE_COORDS_6 = TEXTURE_COORDS_0+6,
  TEXTURE_COORDS_7 = TEXTURE_COORDS_0+7
}
typedef unsigned int AttributeType

Public Member Functions

 Drawable ()
 Drawable (const Drawable &drawable, const CopyOp &copyop=CopyOp::SHALLOW_COPY)
 Copy constructor using CopyOp to manage deep vs shallow copy.
 META_Node (osg, Drawable)
virtual DrawableasDrawable ()
 convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.
virtual const DrawableasDrawable () const
 convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.
virtual void computeDataVariance ()
 Compute the DataVariance based on an assessment of callback etc.
MatrixList getWorldMatrices (const osg::Node *haltTraversalAtNode=0) const
 Get the list of matrices that transform this node from local coordinates to world coordinates.
void setInitialBound (const osg::BoundingBox &bbox)
 Set the initial bounding volume to use when computing the overall bounding volume.
const BoundingBoxgetInitialBound () const
 Set the initial bounding volume to use when computing the overall bounding volume.
const BoundingSpheregetBound () const
const BoundingBoxgetBoundingBox () const
 Get BoundingBox of Drawable.
virtual BoundingSphere computeBound () const
 Compute the bounding sphere around Drawables's geometry.
virtual BoundingBox computeBoundingBox () const
 Compute the bounding box around Drawables's geometry.
void setComputeBoundingBoxCallback (ComputeBoundingBoxCallback *callback)
 Set the compute bound callback to override the default computeBound.
ComputeBoundingBoxCallbackgetComputeBoundingBoxCallback ()
 Get the compute bound callback.
const ComputeBoundingBoxCallbackgetComputeBoundingBoxCallback () const
 Get the const compute bound callback.
void setShape (Shape *shape)
 Set the Shape of the Drawable.
ShapegetShape ()
 Get the Shape of the Drawable.
const ShapegetShape () const
 Get the const Shape of the const Drawable.
void setSupportsDisplayList (bool flag)
 Set the drawable so that it can or cannot be used in conjunction with OpenGL display lists.
bool getSupportsDisplayList () const
 Get whether display lists are supported for this drawable instance.
void setUseDisplayList (bool flag)
 When set to true, force the draw method to use OpenGL Display List for rendering.
bool getUseDisplayList () const
 Return whether OpenGL display lists are being used for rendering.
GLuint & getDisplayList (unsigned int contextID) const
 Return OpenGL display list for specified contextID.
virtual void setUseVertexBufferObjects (bool flag)
 When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation method to use OpenGL vertex buffer objects for rendering.
bool getUseVertexBufferObjects () const
 Return whether OpenGL vertex buffer objects should be used when supported by OpenGL driver.
virtual void dirtyDisplayList ()
 Force a recompile on next draw() of any OpenGL display list associated with this geoset.
virtual unsigned int getGLObjectSizeHint () const
 Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.
void draw (RenderInfo &renderInfo) const
 Draw OpenGL primitives.
virtual void compileGLObjects (RenderInfo &renderInfo) const
 Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.
virtual void setThreadSafeRefUnref (bool threadSafe)
 Set whether to use a mutex to ensure ref() and unref() are thread safe.
virtual void resizeGLObjectBuffers (unsigned int maxSize)
 Resize any per context GLObject buffers to specified size.
virtual void releaseGLObjects (State *state=0) const
 If State is non-zero, this function releases OpenGL objects for the specified graphics context.
virtual void setDrawCallback (DrawCallback *dc)
 Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.
DrawCallbackgetDrawCallback ()
 Get the non const DrawCallback.
const DrawCallbackgetDrawCallback () const
 Get the const DrawCallback.
virtual void drawImplementation (RenderInfo &) const
 drawImplementation(RenderInfo&) is a pure virtual method for the actual implementation of OpenGL drawing calls, such as vertex arrays and primitives, that must be implemented in concrete subclasses of the Drawable base class, examples include osg::Geometry and osg::ShapeDrawable.
virtual bool supports (const AttributeFunctor &) const
 Return true if the Drawable subclass supports accept(AttributeFunctor&).
virtual void accept (AttributeFunctor &)
 accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.
virtual bool supports (const ConstAttributeFunctor &) const
 Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).
virtual void accept (ConstAttributeFunctor &) const
 Accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.
virtual bool supports (const PrimitiveFunctor &) const
 Return true if the Drawable subclass supports accept(PrimitiveFunctor&).
virtual void accept (PrimitiveFunctor &) const
 Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.
virtual bool supports (const PrimitiveIndexFunctor &) const
 Return true if the Drawable subclass supports accept(PrimitiveIndexFunctor&).
virtual void accept (PrimitiveIndexFunctor &) const
 Accept a PrimitiveIndexFunctor and call its methods to tell it about the internal primitives that this Drawable has.

Static Public Member Functions

static GLuint generateDisplayList (unsigned int contextID, unsigned int sizeHint=0)
 Return a OpenGL display list handle a newly generated or reused from display list cache.
static void setMinimumNumberOfDisplayListsToRetainInCache (unsigned int minimum)
 Set the minimum number of display lists to retain in the deleted display list cache.
static unsigned int getMinimumNumberOfDisplayListsToRetainInCache ()
 Get the minimum number of display lists to retain in the deleted display list cache.
static void deleteDisplayList (unsigned int contextID, GLuint globj, unsigned int sizeHint=0)
 Use deleteDisplayList instead of glDeleteList to allow OpenGL display list to be cached until they can be deleted by the OpenGL context in which they were created, specified by contextID.
static void flushAllDeletedDisplayLists (unsigned int contextID)
 Flush all the cached display list which need to be deleted in the OpenGL context related to contextID.
static void discardAllDeletedDisplayLists (unsigned int contextID)
 Flush all the cached display list which need to be deleted in the OpenGL context related to contextID.
static void flushDeletedDisplayLists (unsigned int contextID, double &availableTime)
 Flush the cached display list which need to be deleted in the OpenGL context related to contextID.

Static Public Attributes

static unsigned int s_numberDrawablesReusedLastInLastFrame
static unsigned int s_numberNewDrawablesInLastFrame
static unsigned int s_numberDeletedDrawablesInLastFrame

Protected Types

typedef osg::buffered_value
< GLuint > 
GLObjectList

Protected Member Functions

Drawableoperator= (const Drawable &)
virtual ~Drawable ()
void setBound (const BoundingBox &bb) const
 set the bounding box .

Protected Attributes

BoundingBox _initialBound
ref_ptr
< ComputeBoundingBoxCallback
_computeBoundCallback
BoundingBox _boundingBox
bool _boundingBoxComputed
ref_ptr< Shape_shape
bool _supportsDisplayList
bool _useDisplayList
bool _supportsVertexBufferObjects
bool _useVertexBufferObjects
GLObjectList _globjList
ref_ptr< UpdateCallback_drawableUpdateCallback
ref_ptr< EventCallback_drawableEventCallback
ref_ptr< CullCallback_drawableCullCallback
ref_ptr< DrawCallback_drawCallback

Friends

class Node
class Geode
class StateSet

Detailed Description

Pure virtual base class for drawable geometry.

In OSG, everything that can be rendered is implemented as a class derived from Drawable. The Drawable class contains no drawing primitives, since these are provided by subclasses such as osg::Geometry.

Notice that a Drawable is not a Node, and therefore it cannot be directly added to a scene graph. Instead, Drawables are attached to Geodes, which are scene graph nodes.

The OpenGL state that must be used when rendering a Drawable is represented by a StateSet. Since a Drawable has a reference (osg::ref_ptr) to a StateSet, StateSets can be shared between different Drawables. In fact, sharing StateSets is a good way to improve performance, since this allows OSG to reduce the number of expensive changes in the OpenGL state.

Finally, Drawables can also be shared between different Geodes, so that the same geometry (loaded to memory just once) can be used in different parts of the scene graph.


Member Typedef Documentation

typedef unsigned int osg::Drawable::AttributeType
typedef osg::buffered_value<GLuint> osg::Drawable::GLObjectList [protected]

Member Enumeration Documentation

Enumerator:
VERTICES 
WEIGHTS 
NORMALS 
COLORS 
SECONDARY_COLORS 
FOG_COORDS 
ATTRIBUTE_6 
ATTRIBUTE_7 
TEXTURE_COORDS 
TEXTURE_COORDS_0 
TEXTURE_COORDS_1 
TEXTURE_COORDS_2 
TEXTURE_COORDS_3 
TEXTURE_COORDS_4 
TEXTURE_COORDS_5 
TEXTURE_COORDS_6 
TEXTURE_COORDS_7 

Constructor & Destructor Documentation

osg::Drawable::Drawable ( const Drawable drawable,
const CopyOp copyop = CopyOp::SHALLOW_COPY 
)

Copy constructor using CopyOp to manage deep vs shallow copy.

virtual osg::Drawable::~Drawable ( ) [protected, virtual]

Member Function Documentation

virtual void osg::Drawable::accept ( AttributeFunctor ) [inline, virtual]

accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.

return true if functor handled by drawable, return false on failure of drawable to generate functor calls.

Reimplemented in osgTerrain::HeightFieldDrawable, osg::Geometry, and osgTerrain::SharedGeometry.

virtual void osg::Drawable::accept ( ConstAttributeFunctor ) const [inline, virtual]

Accept an AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.

return true if functor handled by drawable, return false on failure of drawable to generate functor calls.

Reimplemented in osgText::Text, osgTerrain::HeightFieldDrawable, osg::Geometry, osg::ShapeDrawable, osgText::Text3D, and osgTerrain::SharedGeometry.

virtual void osg::Drawable::accept ( PrimitiveFunctor ) const [inline, virtual]

Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.

return true if functor handled by drawable, return false on failure of drawable to generate functor calls. Note, PrimtiveFunctor only provides const access of the primitives, as primitives may be procedurally generated so one cannot modify it.

Reimplemented in osgText::Text, osgTerrain::HeightFieldDrawable, osg::Geometry, osg::ShapeDrawable, osgSim::ImpostorSprite, osgParticle::PrecipitationEffect::PrecipitationDrawable, osgText::Text3D, and osgTerrain::SharedGeometry.

virtual void osg::Drawable::accept ( PrimitiveIndexFunctor ) const [inline, virtual]

Accept a PrimitiveIndexFunctor and call its methods to tell it about the internal primitives that this Drawable has.

return true if functor handled by drawable, return false on failure of drawable to generate functor calls. Note, PrimtiveIndexFunctor only provide const access of the primitives, as primitives may be procedurally generated so one cannot modify it.

Reimplemented in osgTerrain::HeightFieldDrawable, osg::Geometry, osgParticle::PrecipitationEffect::PrecipitationDrawable, and osgTerrain::SharedGeometry.

virtual Drawable* osg::Drawable::asDrawable ( ) [inline, virtual]

convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.

Equivalent to dynamic_cast<Group*>(this).

Reimplemented from osg::Node.

Referenced by osg::Geode::getDrawable().

virtual const Drawable* osg::Drawable::asDrawable ( ) const [inline, virtual]

convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.

Equivalent to dynamic_cast<const Group*>(this).

Reimplemented from osg::Node.

virtual void osg::Drawable::compileGLObjects ( RenderInfo renderInfo) const [virtual]

Immediately compile this Drawable into an OpenGL Display List/VertexBufferObjects.

Note:
Operation is ignored if _useDisplayList is false or VertexBufferObjects are not used.

Reimplemented in osgTerrain::HeightFieldDrawable, osg::Geometry, and osgTerrain::SharedGeometry.

virtual BoundingSphere osg::Drawable::computeBound ( ) const [virtual]

Compute the bounding sphere around Drawables's geometry.

Reimplemented from osg::Node.

virtual BoundingBox osg::Drawable::computeBoundingBox ( ) const [virtual]

Compute the DataVariance based on an assessment of callback etc.

Reimplemented from osg::Object.

static void osg::Drawable::deleteDisplayList ( unsigned int  contextID,
GLuint  globj,
unsigned int  sizeHint = 0 
) [static]

Use deleteDisplayList instead of glDeleteList to allow OpenGL display list to be cached until they can be deleted by the OpenGL context in which they were created, specified by contextID.

virtual void osg::Drawable::dirtyDisplayList ( ) [virtual]

Force a recompile on next draw() of any OpenGL display list associated with this geoset.

Reimplemented in osg::Geometry.

static void osg::Drawable::discardAllDeletedDisplayLists ( unsigned int  contextID) [static]

Flush all the cached display list which need to be deleted in the OpenGL context related to contextID.

Note, unlike flush no OpenGL calls are made, instead the handles are all removed. this call is useful for when an OpenGL context has been destroyed.

void osg::Drawable::draw ( RenderInfo renderInfo) const [inline]

Draw OpenGL primitives.

If the Drawable has _useDisplayList set to true, then use an OpenGL display list, automatically compiling one if required. Otherwise, call drawImplementation().

Note:
This method should not be overridden in subclasses, as it manages the optional display list (notice this is not even virtual). Subclasses should override drawImplementation() instead.

References _drawCallback, _globjList, _supportsVertexBufferObjects, _useDisplayList, _useVertexBufferObjects, osg::Drawable::DrawCallback::drawImplementation(), drawImplementation(), generateDisplayList(), osg::RenderInfo::getContextID(), getGLObjectSizeHint(), osg::RenderInfo::getState(), osg::State::isVertexBufferObjectSupported(), and osg::ref_ptr< T >::valid().

virtual void osg::Drawable::drawImplementation ( RenderInfo ) const [inline, virtual]

drawImplementation(RenderInfo&) is a pure virtual method for the actual implementation of OpenGL drawing calls, such as vertex arrays and primitives, that must be implemented in concrete subclasses of the Drawable base class, examples include osg::Geometry and osg::ShapeDrawable.

drawImplementation(RenderInfo&) is called from the draw(RenderInfo&) method, with the draw method handling management of OpenGL display lists, and drawImplementation(RenderInfo&) handling the actual drawing itself.

Parameters:
renderInfoThe osg::RenderInfo object that encapsulates the current rendering information including the osg::State OpenGL state for the current graphics context.

Reimplemented in osgText::Text, osgParticle::ParticleSystem, osgShadow::ShadowVolumeGeometry, osgTerrain::HeightFieldDrawable, osg::Geometry, osg::ShapeDrawable, osgSim::ImpostorSprite, osgParticle::PrecipitationEffect::PrecipitationDrawable, osgAnimation::RigGeometry, osgText::Text3D, osg::QueryGeometry, osgTerrain::SharedGeometry, osgShadow::OccluderGeometry, osg::DrawPixels, osgParticle::ConnectedParticleSystem, and osgText::FadeText.

Referenced by draw().

static void osg::Drawable::flushAllDeletedDisplayLists ( unsigned int  contextID) [static]

Flush all the cached display list which need to be deleted in the OpenGL context related to contextID.

static void osg::Drawable::flushDeletedDisplayLists ( unsigned int  contextID,
double &  availableTime 
) [static]

Flush the cached display list which need to be deleted in the OpenGL context related to contextID.

static GLuint osg::Drawable::generateDisplayList ( unsigned int  contextID,
unsigned int  sizeHint = 0 
) [static]

Return a OpenGL display list handle a newly generated or reused from display list cache.

Referenced by draw().

const BoundingSphere& osg::Drawable::getBound ( ) const [inline]

Reimplemented from osg::Node.

const BoundingBox& osg::Drawable::getBoundingBox ( ) const [inline]

Get BoundingBox of Drawable.

If the BoundingBox is not up to date then its updated via an internal call to computeBond().

References osg::BoundingBoxImpl< VT >::expandBy().

Get the compute bound callback.

Get the const compute bound callback.

GLuint& osg::Drawable::getDisplayList ( unsigned int  contextID) const [inline]

Return OpenGL display list for specified contextID.

Get the non const DrawCallback.

const DrawCallback* osg::Drawable::getDrawCallback ( ) const [inline]

Get the const DrawCallback.

virtual unsigned int osg::Drawable::getGLObjectSizeHint ( ) const [inline, virtual]

Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.

This size is used a hint for reuse of deleted display lists/vertex buffer objects.

Reimplemented in osg::Geometry.

Referenced by draw().

const BoundingBox& osg::Drawable::getInitialBound ( ) const [inline]

Set the initial bounding volume to use when computing the overall bounding volume.

Reimplemented from osg::Node.

Get the minimum number of display lists to retain in the deleted display list cache.

Get the Shape of the Drawable.

const Shape* osg::Drawable::getShape ( ) const [inline]

Get the const Shape of the const Drawable.

bool osg::Drawable::getSupportsDisplayList ( ) const [inline]

Get whether display lists are supported for this drawable instance.

bool osg::Drawable::getUseDisplayList ( ) const [inline]

Return whether OpenGL display lists are being used for rendering.

Return whether OpenGL vertex buffer objects should be used when supported by OpenGL driver.

MatrixList osg::Drawable::getWorldMatrices ( const osg::Node haltTraversalAtNode = 0) const

Get the list of matrices that transform this node from local coordinates to world coordinates.

The optional Node* haltTraversalAtNode allows the user to prevent traversal beyond a specifed node.

Reimplemented from osg::Node.

Drawable& osg::Drawable::operator= ( const Drawable ) [inline, protected]
virtual void osg::Drawable::releaseGLObjects ( State state = 0) const [virtual]

If State is non-zero, this function releases OpenGL objects for the specified graphics context.

Otherwise, releases OpenGL objects for all graphics contexts.

Reimplemented from osg::Node.

Reimplemented in osgText::Text, osgText::TextBase, osgTerrain::HeightFieldDrawable, osg::Geometry, osgText::Text3D, osg::QueryGeometry, and osgTerrain::SharedGeometry.

virtual void osg::Drawable::resizeGLObjectBuffers ( unsigned int  maxSize) [virtual]

Resize any per context GLObject buffers to specified size.

Reimplemented from osg::Node.

Reimplemented in osgText::Text, osgText::TextBase, osgTerrain::HeightFieldDrawable, osg::Geometry, osgText::Text3D, and osgTerrain::SharedGeometry.

void osg::Drawable::setBound ( const BoundingBox bb) const [protected]

set the bounding box .

Set the compute bound callback to override the default computeBound.

virtual void osg::Drawable::setDrawCallback ( DrawCallback dc) [inline, virtual]

Set the DrawCallback which allows users to attach customize the drawing of existing Drawable object.

Set the initial bounding volume to use when computing the overall bounding volume.

static void osg::Drawable::setMinimumNumberOfDisplayListsToRetainInCache ( unsigned int  minimum) [static]

Set the minimum number of display lists to retain in the deleted display list cache.

void osg::Drawable::setShape ( Shape shape) [inline]

Set the Shape of the Drawable.

The shape can be used to speed up collision detection or as a guide for procedural geometry generation.

See also:
osg::Shape.

Set the drawable so that it can or cannot be used in conjunction with OpenGL display lists.

When set to true, calls to Drawable::setUseDisplayList, whereas when set to false, no display lists can be created and calls to setUseDisplayList are ignored, and a warning is produced. The latter is typically used to guard against the switching on of display lists on objects with dynamic internal data such as continuous Level of Detail algorithms.

virtual void osg::Drawable::setThreadSafeRefUnref ( bool  threadSafe) [virtual]

Set whether to use a mutex to ensure ref() and unref() are thread safe.

Reimplemented from osg::Node.

Reimplemented in osgText::Text, osgText::TextBase, and osgText::Text3D.

When set to true, force the draw method to use OpenGL Display List for rendering.

If false, rendering directly. If the display list has not been compiled already, the next call to draw will automatically create the display list.

virtual void osg::Drawable::setUseVertexBufferObjects ( bool  flag) [virtual]

When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation method to use OpenGL vertex buffer objects for rendering.

Reimplemented in osg::Geometry.

virtual bool osg::Drawable::supports ( const AttributeFunctor ) const [inline, virtual]
virtual bool osg::Drawable::supports ( const ConstAttributeFunctor ) const [inline, virtual]

Return true if the Drawable subclass supports accept(ConstAttributeFunctor&).

Reimplemented in osgText::Text, osgTerrain::HeightFieldDrawable, osg::Geometry, osg::ShapeDrawable, osgText::Text3D, and osgTerrain::SharedGeometry.

virtual bool osg::Drawable::supports ( const PrimitiveFunctor ) const [inline, virtual]
virtual bool osg::Drawable::supports ( const PrimitiveIndexFunctor ) const [inline, virtual]

Return true if the Drawable subclass supports accept(PrimitiveIndexFunctor&).

Reimplemented in osgTerrain::HeightFieldDrawable, osg::Geometry, osgParticle::PrecipitationEffect::PrecipitationDrawable, and osgTerrain::SharedGeometry.


Friends And Related Function Documentation

friend class Geode [friend]
friend class Node [friend]
friend class StateSet [friend]

Member Data Documentation

bool osg::Drawable::_boundingBoxComputed [mutable, protected]

Reimplemented from osg::Node.

Referenced by draw().

Referenced by draw().

Reimplemented from osg::Node.

Referenced by draw().

Referenced by draw().

Referenced by draw().


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

osg logo
Generated at Tue Dec 8 2015 00:14:24 for the OpenSceneGraph by doxygen 1.7.6.1.