[osg-users] ShapeDrawable refactored, now subclasses from osg::Geometry

Robert Osfield robert.osfield at gmail.com
Wed Aug 17 13:49:54 PDT 2016


Hi All,

As part of the Vertex Array Object support work that I have been doing
on the git vertex_array_object branch I have tackled a long time issue
with ShapeDrawable.

I have refactored ShapeDrawable so that it now subclasses from
osg::Geometry and builds all the vertex, normal, texcoord and color
arrays and primitives that are required to render the attached
osg::Shape.  This means fast paths are all used for the first with
ShapeDrawable.

To do the building of the required vertex array and primitive sets I
have created an osg::BuildShapeGeometryVisitor that can now be found
in the include/osg/Shape header.  The ShapeDrawable uses this visitor
to do it's work.  This visitor is a ShapeVisitor rather than a
NodeVisitor, so it's something you give to a shape to visitor i.e.

osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::BuildShapeGeometryVisitor dsv(geometry, tessellationHints);
 shape->accept(dsv);

This fills in the geometry so it can then be attached to the scene
graph and render, intersected etc.  The visitor can be run on multiple
Shape objects passing once it's initialized with it's geometry pointer
so can place multiple Shape's into a single geometry.

The ShapeDrawable also support CompositeShape so you can do the
multiple shapes in a singel osg::Geometry via this route as well.

The advantage with this new osg::Geometry based ShapeDrawable and
BuildShapeGeometryVisitor is that nothing needs to be computed on the
fly anymore so intersections and rendering are all faster.  It's also
fully compatible with VBO's and VAO's.

So... for the first time the OSG will be able to render shape efficiently.

This is all checked in the vertex_array_object branch, once this
branch is stable and tested out in the community I'll merge with git
master and will then be part of the up coming OSG-3.6 release.

Robert.



More information about the osg-users mailing list