Hi Antonie,

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

> 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
data.

 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.

Robert.
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to