[osg-users] Using callbacks for all graph modifications?

Robert Osfield robert.osfield at gmail.com
Sat Aug 19 09:00:04 PDT 2017

Hi Antonie,

On 18 August 2017 at 22:25, Antoine Rennuit <antoinerennuit at hotmail.com>

> I understand the design difference you mentioni and it is relevant.
> Now from my readings of the beginners' guide, I understood that callbacks
> were needed to enforce thread safety. Your answer suggests that it is not
> the case. Can you confirm? i.e. do you confirm I can modify the OSG objects
> in a direct way (without callbacks) before calling Viewer::frame() and
> expect a correct rendering behavior?

Using update callbacks assists with making scene graph updates thread safe
but it's not a necessity, not even a guarantee.  It all depends upon the
threading model you are using in viewer and when you are modifying what

 If you are running the viewer SingleThreaded then the old threads that the
OSG will create will be if you are using a paged database, in which case
the OSG will automatically start background threads for reading the data.
These don't impact most work on applications as it all happening in
background with data local to that paging threads and is only merged during
the update traversal, the viewer handles this all safely for you.

If your are using CullDrawThreadPerContext you also don't need to worry
about threading in the update phase (outside viewer.renderingTraversals()
that's part of viewer.frame()) as all threads that are doing the rendering
only run for the duration of the renderingTraversals() so you'll be safe
modifying nodes and geometry/state outside of frame as well.

It's only in DrawThreadPerContext and
CullThreadPerCameraDrawThreadPerContext threading models that you need to
be careful about modifying the geometry/state in the scene graph as these
elements of the scene graph may be read from in the draw thread that can
still be running when renderingTraversals() finishes.  If you want to
modify geometry/state you need to set the DataVariance on the geometry and
state you are modifying to DYANMIC.  This applies to using callbacks or
modifying the scene graph outwith viewer.frame().

You are free to modify nodes in the scene graph in the main loop/update and
event traversals in all threading models.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170819/ee1d6d0f/attachment.htm>

More information about the osg-users mailing list