Most of my G3D programs are multithreaded these days. GThread,
GMutex, and ThreadSet are big helpers for this. Also note that G3D
and GApp allow you to make RenderDevice calls from anywhere. I often
have GApp::onSimulation methods that invoke off-screen rendering.
OpenGL is not threadsafe. It is up to you to ensure that you do not
invoke OpenGL calls (which generally means RenderDevice calls or
Texture creation) on multiple threads simultaneously. I think that if
you are rendering to multiple contexts this might be relaxed slightly,
but I don't recommend rendering to multiple contexts.
The fact that OpenGL is not threadsafe isn't very important, though,
since most OpenGL calls don't block. The GPU is a separate processor,
and an OpenGL call tells it to launch a thread. So if you have one
CPU thread that issues OpenGL calls, that thread will almost never
block (unless you're performing some kind of readback). This means
that you can use as many CPU threads as you want, and just ensure that
only one communicates with OpenGL.
You could alternatively protect RenderDevice with a GMutex, but the
overhead of doing that for every call is fairly high and since OpenGL
is a state machine, you'd have to synchronize at a higher level to
avoid confusing your state across threads.
-m
> --
>
> You received this message because you are subscribed to the Google Groups "G3D Users" group.
> To post to this group, send email to
g3d-...@googlegroups.com.
> To unsubscribe from this group, send email to
g3d-users+...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/g3d-users?hl=en.
>
>
>