Hi Paul,

On Nov 27, 2007 6:20 PM, Paul Martz <[EMAIL PROTECTED]> wrote:
> Why is Camera::DrawCallback::operator() declared as const? Is this simply a
> result of the draw operation itself being entirely const?

This is right, its const because in principle the cull and draw
traversals are both const operations on the scene graph, to enable
safe multi-threaded usage.  Its simply using C++ compilers to enforce
this.

> I have my own structs derived from Camera::DrawCallback, and in operator()
> I'd like to modify some member variables. The fact that operator() is const
> is forcing me to make those mutable or cast away constness.

Just make the variables mutable, or cast away constness.  Don't forget
that you are loosing the easy multi-threaded ability of the callback -
so you'll either need to not use it multi-threaded or using a mutex
locally to serialize access.

> I'm using these as PreDraw and PostDrawCallbacks, and from what I can see of
> the code, those are always executed sequentially by the same thread, so I
> don't see that there's risk of thread collisions if I modify data in my
> callbacks. Correct me if I'm wrong on this.

Cameras can be used at the top level in the Viewer and have one thread
per camera, but also can be used inside the scene graph and in this
instance can be rendered by multiple threads at one time.   Its a case
of if know what you are doing then you can go ahead a cast away
constness, but the constness is there is make you think twice about
doing it.

Robert.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to