Hi, I am setting up OpenSG to work with VRJuggler on a multiprocessor CAVE system and I'd like to have a bit of a better understanding of how the multi-threading features of OpenSG and VRJuggler interact. There is a fair bit of documentation I can find of the individual multi-threading features of each, but none that I can find on their interaction, sorry if I've missed some or not found and existing thread on this.
Maybe I should explain what I am trying to do. I have a character animation engine based on Cal3D (not VJAvatar). This engine works in 3 stages:
* do internal updates (animation etc)
* write out a new set of vertex position for the character mesh to a buffer
* use some external system (i.e. opensg) to render the buffer.
If I were to use VRJuggler and GL, as I understanding, it I would use 2 buffers and do something like this:
void intraFrame()
{
// do update
// write verteces to the update buffer
}
void preFrrame()
{
// swap update and render buffers
}
void draw()
{
// draw the render buffer
}
This allows the updates to proceed entirely in parallel with the renderer, the only thing that they need to block on is a pointer swap. In OpenSG I would like to be able to copy the update buffer into an OpenSG geometry object. The simplest way would be to something like this (what my code does now):
void preFrame()
{
OSG::GeoPositions3fPtr pos =
OSG::GeoPositions3fPtr::dcast(mGeometries[i][j]->getPositions());
beginEditCP(pos, OSG::GeoPositions3f::GeoPropDataFieldMask);
for (v = 0; v < vertexCount; v++)
pos->setValue(OSG::Pnt3f(updateBuffer[3*v],
updateBuffer[3*v+1],
updateBuffer[3*v+2]), v);
endEditCP(pos, OSG::GeoPositions3f::GeoPropDataFieldMask);
}
But I don't want to do a copy of all the vertex data, particularly in preFrame, which blocks the render thread. I'd like to do something like:
void intraFrame()
{
// internal update
OSG::GeoPositions3fPtr pos =
OSG::GeoPositions3fPtr::dcast(mGeometries[i][j]->getPositions());
WriteVertecesToBuffer(pos->GetData());
}
But I'm not sure how to make this thread safe.
So here are the questions:
1) As I understand it in OpenSG each thread has its own copy of all the objects so that it is safe to do something like:
WriteVertecesToBuffer(pos->GetData());
in parallel to the renderer if I call:
animationThread->getChangeList()->applyAndClear();
at the end of each frame to sync the two copies. Does this still work when I write vertex values directly using getData?
2) If so, how does it interact with the VRJuggler mutli-threading? Does the above method still apply if do the update in a VRJuggler intraFrame call and the rendering in a preFrame call? Do I still call applyAndClear on the change list or is that handlled by the VRJuggler plugin? Or are the two thread systems fundamentally different? If so, any suggestions.
thanks a lot
Marco
- [Opensg-users] OpenSG and VRJuggler multi-threading Marco Gillies
- Re: [Opensg-users] OpenSG and VRJuggler multi-threading Dirk Reiners
- Re: [Opensg-users] OpenSG and VRJuggler multi-threa... Marco Gillies
