Hi,
I think I have made a little bit of progress on my integration of osgPPU with 
the MPV IG but I am running into a un-handled exception...

I am still quite a newbie (but eager to learn) with RTT and OSG so excuse my 
ignorance...

Some of the problem is, I believe, related to the fact that the MPV uses the 
osgSDL library, not sure!!! (could it be possible that osgSDL cannot handle the 
kind of information and processing that osgPPU generates?)

<Setup - Done only once>

When a viewport is created (which gets rendered by the osgSDL library), I add a 
camera to do the rtt for that view. Which gets the textures that will be used 
in the ppu processor
        rttCamera = setupRttCamera( viewport.get() );   see bellow for the 
setupRttCamera function code

When my plugin is loaded (different one than the other setup) I use the 
rttCamera that has been setup and use it to arrange my post processor
        // make a new PPU processor
        mProcessor = new osgPPU::Processor();
        viewport->getSceneGraph()->addChild( mProcessor.get() );
        // bind it wirth the current viewport RTT camera
        mProcessor->setCamera( viewport->getRttCamera() );
        mProcessor->setName( viewport->getRttCamera()->getName() );
        mProcessor->dirtyUnitSubgraph();

        // if I add anything to the processor it causes the crash, I tried what 
I thought would be the most basic post processing with just a text... but that 
did not work

fpstext = new osgPPU::UnitText();
fpstext->setName("FPSTextPPU");
fpstext->setSize(44);
fpstext->setText("test test test");
fpstext->setPosition(0.01, 0.95);
mProcessor->addChild(fpstext);
// if the text part is commented out (an empty processor added to the graph) 
everything works ok...

<Done every frame of when some changes occured>

When the viewport is updated, I pass the new Matrix along to the rttCamera
        rttCamera->setViewMatrix( viewMatrix );

after that the update has been done the osgSDL::viewer is update by this call 
and that is when the app crashes (only when something is added to the 
processor)...
        viewer->runOnce();

I don't know if this info would be needed to help but here it is:
    viewer is of osgSDL::Viewer
    viewport is of osgSDL::Viewport
    camera is osg::Camera

Also if I do a dump of my scene graph it looks something like this

RttRootNode (not really used other than to keep things organized)
        ViewportNode (used to set the different wiew on the "world")
                RootNode (world containing much other things like entities, 
terrain, sky ... etc)
                RttCamera (used to get the base textures to use in the post 
processing pipeline)
        there could be more viewportNodes (one per defined viewport) with the 
same structure as above pointing to the same RootNode but with a different 
RttCamera



////////////////////////////////////////////////////////////////////////////////
//! Create a Camera to do Render To Texture
//! Taken from osgPPU example
osg::Camera* ViewportWrapper::setupRttCamera(osgSDL::Viewport* vp)
{
    int width = vp->getWidth();
    int height = vp->getHeight();
    // setup viewer's default camera
    osg::Camera* camera = new osg::Camera();

    // create texture to render to
    osg::Texture* texture = createRenderTexture(width, height, false);
    osg::Texture* depthTexture = createRenderTexture(width, height, true);

    // set up the background color and clear mask.
    camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f));
    camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // set viewport
    //camera->setViewport(vp);
    //camera->setView(vp->getSceneView()->getView());
    camera->setViewMatrix(vp->getSceneView()->getViewMatrix());
    // set camera lens to be the same as the viewport[viewID]
    //camera->setViewMatrix(camMtrx);
    camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
    camera->setProjectionMatrixAsPerspective(20.0, width/height, 0.1, 100.0);
    //camera.get()->setProjectionMatrixAsOrtho2D(0, width, height, 0);

    // tell the camera to use OpenGL frame buffer object where supported.
    camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);

    // attach the texture and use it as the color buffer.
    camera->attach(osg::Camera::COLOR_BUFFER, texture);
    camera->attach(osg::Camera::DEPTH_BUFFER, depthTexture);
    
    return camera;
}


 Thank you all for your help and your patience

Patrick Castonguay
H: 613 435 2235
C: 613 325 1341
 
Technology Innovation Management (TIM) Student - Modeling and Simulation stream

Carleton University, Ottawa, ON
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to