上QQ阅读APP看书,第一时间看更新
Geode and Drawable classes
The osg::Geode
class corresponds to the leaf node of a scene graph. It has no child nodes, but always contains geometry information for rendering. Its name Geode
is short for geometry node.
The geometry data to be drawn are stored in a set of osg::Drawable
objects managed by osg::Geode
. The non-instantiatable osg::Drawable
class is defined as a pure virtual class. It has several subclasses for rendering models, images, and texts to the OpenGL pipeline. These renderable elements are collectively called drawables.
The osg::Geode
class provides a few methods to attach and detach drawables, as well as collect information about them:
- The public method
addDrawable()
takes anosg::Drawable
pointer as its parameter and attaches a drawable to theosg::Geode
instance. All drawables added are internally managed by theosg::ref_ptr<>
smart pointer. - The public methods
removeDrawable()
andremoveDrawables()
will detach one or more drawables from the currentosg::Geode
object, and decrease their referenced counting number as well. TheremoveDrawable()
method uses anosg::Drawable
pointer as the only parameter, andremoveDrawables()
accepts two parameters: the zero-based index of the start element, and number of elements to be removed. - The
getDrawable()
method returns theosg::Drawable
object stored at the specified zero-based index. - The
getNumDrawables()
method returns the total number of attached drawables. Developers are then able to traverse each drawable in a cycle with thegetDrawable()
method, or remove all drawables at once by using the following code:geode->removeDrawables( 0, geode->getNumDrawables() );