Hello Patrick,
Patrick Hartling wrote:
On Jul 30, 2010, at 1:40 PM, Carsten Neumann wrote:
Patrick Hartling wrote:
When using OSG::GrabForeground with OpenSG 2, I find that some parts of the
scene graph are not being grabbed. Is there anything besides the traversal mask
on the viewport that influences grabbing? The viewport has a traversal mask of
0x1, and as far as I can tell, the nodes that are not being captured have a
mask of 0xffffffff. Of the 4151 nodes in the scene graph I just tested, only 4
do not have a mask of 0xfffffff, and those four being included with the image
output just as I expect.
the GrabForeground simple does a glReadPixels to copy the application
frame buffer into it's image. It should not have any influence on what
is being rendered, especially since all Foregrounds have their draw()
method called after the scene rendering is already done.
That's what I thought from looking at the OSG::Viewport and OSG::GrabForeground
code, but I thought maybe I was missing some subtle detail.
I don't think so or at least I'm missing it too then ;)
In case it makes any difference, the nodes that are being missed are loaded
from OSB files. We are using a custom render action, but it is a simple
subclass of OSG::RenderAction that adds two data members needed as a
conveniences for other parts of our software. The only method that we override
is OSG::RenderAction::start(), and that is just so that we can set a value for
one of the two added data members. The override calls up to
OSG::RenderAction::start() just as it ought to.
Do the missed nodes show up when rendering without the GrabForeground?
Yes.
This is the part were it gets seriously strange, to me it simply makes
no sense that doing a glReadPixels causes some objects to disappear.
What happens if you load the OSB files with e.g. testSimpleSceneManager?
I tried loading some at random using testSimpleSceneManager, and it had no
difficulty with any.
ok.
Have you tried to run the VerifyGeoGraphOp on the problematic nodes (not
that it can catch all errors with geometry, but it does find a few
obvious ones)?
OSG::VerifyGeoGraphOp does not report problems for any of the 1600+ models that
I have.
ok, thanks for checking.
From what you describe I don't see how the custom RenderAction could be
a problem or the GrabForeground for that matter. Can you give some more
details on your setup, please. I believe something else must be involved
to prevent the nodes from rendering.
Our custom scene manager has a viewport with an grab foreground associated with it at all
times. The viewport is associated with a passive window that is itself driven by a Qt 4
QGLWidget. The grab foreground is deactivated except when we want to capture what OpenSG
will render. When we do that, we activate the grab foreground, force the window to render
using the same render action object used for "normal" rendering, and then
disable the grab foreground again. This all works like a charm except for these models.
hm, can you run your application through a GL debugger to get OpenGL
call logs for the cases with and without active GrabForeground?
Perhaps diff'ing them reveals something useful to go by.
One other question, are you changing the value of Window::sfDrawMode_,
i.e. are you using the parallel drawer or the default sequential drawer?
I've attached a modified testSimpleSceneManager that adds a
GrabForeground, can you try that with one of the problematic models? I
don't really expect it to replicate the problem, but just maybe we get
lucky ;) If a single model does not work, maybe writing all or part of
your scene as OSB and loading that with the modified
testSimpleSceneManager does the trick?
Cheers,
Carsten
// OpenSG Tutorial Example: Loading
//
// This example shows how to load a scene file using OpenSG.
// The supported formats right now are VRML97, OBJ, OFF and RAW, so just
// calling this program with a scene file as a parameter should load the scene
// file.
//
// Headers
#include "OSGGLUT.h"
#include "OSGConfig.h"
#include "OSGSimpleGeometry.h"
#include "OSGGLUTWindow.h"
#include "OSGSimpleSceneManager.h"
#include "OSGAction.h"
#include "OSGGrabForeground.h"
#include "OSGImage.h"
// New Headers
// the general scene file loading handler
#include "OSGSceneFileHandler.h"
#include "OSGFieldContainerUtils.h"
// The SimpleSceneManager to manage simple applications
OSG::SimpleSceneManager *mgr;
OSG::GrabForegroundUnrecPtr gfg;
OSG::ImageUnrecPtr img;
// forward declaration so we can have the interesting stuff upfront
int setupGLUT( int *argc, char *argv[] );
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
// OSG init
OSG::osgInit(argc,argv);
// GLUT init
int winid = setupGLUT(&argc, argv);
{
// the connection between GLUT and OpenSG
OSG::GLUTWindowUnrecPtr gwin= OSG::GLUTWindow::create();
gwin->setGlutId(winid);
gwin->init();
// load the scene
OSG::NodeUnrecPtr scene;
if(argc < 2)
{
FWARNING(("No file given!\n"));
FWARNING(("Supported file formats:\n"));
OSG::SceneFileHandler::the()->print();
scene = OSG::makeTorus(.5, 2, 16, 16);
}
else
{
/*
All scene file loading is handled via the SceneFileHandler.
*/
scene = OSG::SceneFileHandler::the()->read(argv[1]);
}
//scene->dump();
img = OSG::Image::create();
img->set(OSG::Image::OSG_RGB_PF, 300, 300, 1, 1, 1, 0.0, NULL, OSG::Image::OSG_UINT8_IMAGEDATA, false);
gfg = OSG::GrabForeground::create();
gfg->setImage(img);
gfg->setAutoResize(true);
gfg->setActive(false);
OSG::commitChanges();
// create the SimpleSceneManager helper
mgr = new OSG::SimpleSceneManager;
mgr->setUseTraversalAction(true);
// tell the manager what to manage
mgr->setWindow(gwin );
mgr->setRoot (scene);
mgr->getWindow()->getPort(0)->editMFForegrounds()->push_back(gfg);
// show the whole scene
mgr->showAll();
}
// GLUT main loop
glutMainLoop();
return 0;
}
//
// GLUT callback functions
//
// redraw the window
void display(void)
{
mgr->idle();
mgr->redraw();
OSG::Thread::getCurrentChangeList()->clear();
if(gfg->getActive() == true)
{
std::cout << "writing test_image.png" << std::endl;
gfg->setActive(false);
img->write("test_image.png");
}
}
// react to size changes
void reshape(int w, int h)
{
mgr->resize(w, h);
glutPostRedisplay();
}
// react to mouse button presses
void mouse(int button, int state, int x, int y)
{
if (state)
mgr->mouseButtonRelease(button, x, y);
else
mgr->mouseButtonPress(button, x, y);
glutPostRedisplay();
}
// react to mouse motions with pressed buttons
void motion(int x, int y)
{
mgr->mouseMove(x, y);
glutPostRedisplay();
}
// react to keys
void keyboard(unsigned char k, int , int )
{
switch(k)
{
case 27:
delete mgr;
gfg = NULL;
img = NULL;
OSG::osgExit();
exit(0);
break;
case 'f':
mgr->setNavigationMode(OSG::Navigator::FLY);
break;
case 't':
mgr->setNavigationMode(OSG::Navigator::TRACKBALL);
break;
case 'q':
mgr->setStatistics(true);
break;
case 'w':
mgr->setStatistics(false);
break;
case 'r':
{
bool useTrav = !mgr->getUseTraversalAction();
mgr->setUseTraversalAction(useTrav);
printf("Using %s action.\n", useTrav ? "render traversal" : "render");
}
break;
case 'p':
{
std::cout << "Scanning memory consumption." << std::endl;
OSG::MemoryConsumption mc;
mc.scan();
mc.print(std::cout);
}
break;
case 'g':
{
gfg->setActive(true);
}
break;
}
}
// setup the GLUT library which handles the windows for us
int setupGLUT(int *argc, char *argv[])
{
glutInit(argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
int winid = glutCreateWindow("OpenSG");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
return winid;
}
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users