Hello Christoph,
Christoph Schäfer wrote:
I'm using MT pointers where I think this is needed. Non-MT pointers are
initialized within the gui thread (aspect 1) used for rendering, so this
should not be a problem.
ok.
I tried to hunt down the problem, but on every direction I take the
result is it looks like it should work. Hm. I recently wondered if
anybody has ever used aspect 1 for rendering instead of 0? And if, did
it work out?
I just wrote the attached example, that handles the different task very
similar to what you are doing, only it uses glut for simplicity.
I posted some more screens on ImageShack to show you what makes me think
that it probably is a problem rendering on aspect 0. On [1] you can see
the tie model loaded. In the console you can see the transform of the
cart printed by a listener on every change. As you can see, the model
loaded and the viewAll() method placed the cart in a proper place. If I
move the camera around I get two other views of the tie as seen in [3]
and [4]. These make me think something goes wrong on rendering.
On [2] you can see the Beethoven model loaded, the cart has been placed
to a proper place again without closing the application
hm, thanks for posting these. I still suspect that some information is
not synced in the right way between the aspects.
How does your app handle input from the user? I assume it first receives
it in aspect 1 where the Qt GUI is running, but how do you get it to
aspect 0? In the example I just manipulated the scenegraph in aspect 1,
but making changes in more than one aspect and merging them back is a
tricky business unless you are taking care to work on different parts of
the scene.
The alternative would be to set up some communication between the
threads and forward input from aspect 1 to aspect 0 and only make
changes to the scene there, while aspect 0 focuses on rendering. In that
case you'd only pull changes from aspect 0 into aspect 1.
Hope it helps,
Carsten
#ifdef OSG_BUILD_INTEGRATED
// Headers
#include <OSGGLUT.h>
#include <OSGConfig.h>
#include <OSGSimpleGeometry.h>
#include <OSGPassiveWindow.h>
#include <OSGSimpleSceneManager.h>
#include <OSGBaseFunctions.h>
#include <OSGTransform.h>
#include <OSGSimpleSceneManager.h>
#include <OSGSceneFileHandler.h>
#else
// Headers
#include <OpenSG/OSGGLUT.h>
#include <OpenSG/OSGConfig.h>
#include <OpenSG/OSGSimpleGeometry.h>
#include <OpenSG/OSGPassiveWindow.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGTransform.h>
#include <OpenSG/OSGSimpleSceneManager.h>
#include <OpenSG/OSGSceneFileHandler.h>
#endif
OSG_USING_NAMESPACE
struct AppArgs
{
int argc;
char **argv;
};
SimpleSceneManager *mgr;
TransformUnrecPtr trafo;
PassiveWindowMTRecPtr pwin;
Thread *a0Thread;
Thread *a1Thread;
Barrier *syncBarrier;
volatile bool input = false;
volatile bool sceneUpdate = false;
int setupGLUT(int *argc, char *argv[]);
void initAspect0(int argc, char *argv[])
{
osgInit(argc, argv);
pwin = PassiveWindow::create();
NodeUnrecPtr root = makeCoredNode<Transform>(&trafo);
NodeUnrecPtr scene;
if(argc > 1)
{
scene = SceneFileHandler::the()->read(argv[1]);
}
if(scene == NULL)
{
scene = makeTorus(.5, 2, 16, 16);
}
root->addChild(scene);
mgr = new SimpleSceneManager;
mgr->setWindow(pwin );
mgr->setRoot (root );
mgr->showAll();
commitChanges();
}
void runAspect0(void)
{
Time t0 = getSystemTime();
Time t1 = getSystemTime();
while(true)
{
// std::cerr << "runAspect0 START LOOP" << std::endl;
if(input == true)
{
syncBarrier->enter(2);
std::cerr << "runAspect0 pulling input" << std::endl;
a1Thread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
}
if(sceneUpdate == true)
{
syncBarrier->enter(2);
sceneUpdate = false;
syncBarrier->enter(2);
}
Time t2 = getSystemTime();
if(t2 - t1 > 0.5f)
{
std::cerr << "runAspect0 updating trafo: " << (t2 - t1) << " " <<
(t2 - t0) << std::endl;
Matrix m;
m.setRotate(Quaternion(Vec3f(0,1,0), osgDegree2Rad((t2 - t0) * 5)));
trafo->setMatrix(m);
commitChanges();
t1 = t2;
sceneUpdate = true;
}
// std::cerr << "runAspect0 END LOOP" << std::endl;
}
}
void initAspect1(void *args)
{
AppArgs *appArgs = static_cast<AppArgs *>(args);
setupGLUT(&appArgs->argc, appArgs->argv);
// pull in changes from aspect 0
a0Thread->getChangeList()->applyAndClear();
pwin->init();
}
void runAspect1(void *args)
{
glutMainLoop();
}
int main(int argc, char *argv[])
{
AppArgs appArgs;
appArgs.argc = argc;
appArgs.argv = argv;
initAspect0(argc, argv);
syncBarrier = ThreadManager::the()->getBarrier("syncBarrier");
a0Thread = dynamic_cast<Thread *>(ThreadManager::the()->getAppThread()
);
a1Thread = dynamic_cast<Thread
*>(ThreadManager::the()->getThread("a1Thread"));
// init aspect 1
a1Thread->runFunction(initAspect1, 1, &appArgs);
Thread::join(a1Thread);
// run glutMainLoop on aspect 1
a1Thread->runFunction(runAspect1, 1, NULL);
runAspect0();
return 0;
}
void display(void)
{
// if input
if(input == true)
{
commitChanges();
// allow aspect 0 to pull changes from input
syncBarrier->enter(2);
input = false;
syncBarrier->enter(2);
}
if(sceneUpdate == true)
{
commitChanges();
syncBarrier->enter(2);
std::cerr << "runAspect1 pulling sceneUpdate" << std::endl;
a0Thread->getChangeList()->applyAndClear();
syncBarrier->enter(2);
}
commitChanges();
mgr->redraw();
glutSwapBuffers();
}
void reshape(int w, int h)
{
mgr->resize(w, h);
input = true;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
if(state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
input = true;
glutPostRedisplay();
}
void motion(int x, int y)
{
mgr->mouseMove(x, y);
input = true;
glutPostRedisplay();
}
void idle(void)
{
glutPostRedisplay();
}
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG First Application");
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutReshapeFunc(reshape);
return winid;
}------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users