[osg-users] Shaders with multiple views using ViewportCallback

Christoph Dohmen christoph.dohmen at cae.de
Mon May 14 00:08:34 PDT 2018


Hi Robert,

I just tried the uniform setting for the camera and it worked quite nice.
But I'm not able to use a callback to do the updating stuff :-(.

I tried to install this callback:


Code:

struct ViewportCallback : public osg::Uniform::Callback
{
    ViewportCallback( osg::Camera* camera )
                    : _camera( camera )
    {
        std::cout << "ViewportCallback::ViewportCallback()" << std::endl;
    }

    virtual void operator()( osg::Uniform* uniform, osg::NodeVisitor* /*nv*/)
    {
        std::cout << "ViewportCallback::operator()" << std::endl;
        osg::Viewport * vp( _camera->getViewport() );
        uniform->set( osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
    }

    osg::Camera* _camera;
};




and set it via


Code:

    osg::Viewport * vp( viewer.getCamera()->getViewport() );
    osg::Uniform * viewportUniform = new osg::Uniform( "viewport", osg::Vec4( vp->x(), vp->y(), vp->width(), vp->height() ) );
    viewportUniform->setUpdateCallback( new ViewportCallback( viewer.getCamera() ) );
    viewer.getCamera()->getOrCreateStateSet()->addUniform( viewportUniform );




But I don't get any output from operator() nor do I get an updated viewport value in my shader.

What's wrong with this?


Thank you!

Cheers,
Christoph

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73632#73632







More information about the osg-users mailing list