[osg-users] Cannot stop rendering slave camera

Robert Osfield robert.osfield at gmail.com
Wed Jun 15 02:33:35 PDT 2016


Hi Etienne,

To toggle on/off a Camera the most efficient way to do it is to toggle
it's NodeMask i.e

  // switch off
  slave_camera->setNodeMask(0x0);

 // switch on
 slave_camera->setNodeMask(0xffffffff);

Robert.

On 15 June 2016 at 10:07, Etienne de Sarrieu
<etienne.desarrieu at altran.com> wrote:
> Hi,
>
> Due to performance consumption, I am trying to disable rendering of a slave camera, but it seems impossible. The camera is _pov_camera, and is defined as below :
>
>
> Code:
> void MySensor::initialize()
> {
>    Sensor::initialize();
>
>    // Master camera depth texture
>    _input_depth = new osg::Texture2D();
>    _input_depth->setTextureSize(_w, _h);
>    _input_depth->setInternalFormat(GL_DEPTH_COMPONENT24);
>    _input_depth->setSourceFormat(GL_DEPTH_COMPONENT);
>    _input_depth->setSourceType(GL_FLOAT);
>    _input_depth->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST);
>    _input_depth->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST);
>    _view->getCamera()->attach(osg::Camera::DEPTH_BUFFER, _input_depth);
>
>    // Point of view depth texture
>    _pov_depth = new osg::Texture2D();
>    _pov_depth->setTextureSize(_w, _h);
>    _pov_depth->setInternalFormat(GL_DEPTH_COMPONENT24);
>    _pov_depth->setSourceFormat(GL_DEPTH_COMPONENT);
>    _pov_depth->setSourceType(GL_FLOAT);
>    _pov_depth->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
>    _pov_depth->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
>
>    // Point of view camera
>    _pov_camera = new osg::Camera();
>    _pov_camera->setViewport(0., 0., _w, _h);
>    _pov_camera->setRenderOrder(osg::Camera::PRE_RENDER);
>    _pov_camera->setClearColor(Color(1., 0., 0., 1.));
>    _pov_camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>    _pov_camera->setCullMask(Sensor::EXT);
>    _pov_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>    _pov_camera->setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>    _pov_camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
>    _pov_camera->attach(osg::Camera::DEPTH_BUFFER, _pov_depth);
>    _pov_camera->setGraphicsContext(_view->getCamera()->getGraphicsContext());
>    //_was_on = false;_autor=false;
>    _view->addSlave(_pov_camera, true);
>
>    _pov_camera->getOrCreateStateSet()->setAttributeAndModes(new osg::CullFace(osg::CullFace::FRONT));
>
> (...)
> }
>
>
>
>
> The _pov_camera is used to compute shadows on a map. But it consumes much resources from CPU whereas I only compute shadows from time to time.
>
> I tried to remove slave camera after using it :
>
> Code:
>
>                    int result = _view->findSlaveIndexForCamera(_pov_camera);
>                    if (result < _view->getNumSlaves())
>                    {
>                            _view->removeSlave(result);
>                    }
>                    static_cast<osgViewer::Renderer*>(_pov_camera->getRenderer())->setDone(true);
>
>
>
>
> After using it but it does not change anything (whereas if I do not add the slave camera at the beginning performances are OK...). Why removing slave camera does not permit to roll back completely on adding it?
> Do you know a way to disable my _pov_camera?
>
> Thank you!
>
> Cheers,
> Etienne
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=67631#67631
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



More information about the osg-users mailing list