1
0
Fork 0

Canvas: Only use cull callback if it's still valid

This commit is contained in:
Thomas Geymayer 2012-09-01 16:50:21 +02:00
parent 26664aaff0
commit 7463ebad1d
3 changed files with 9 additions and 6 deletions

View file

@ -73,7 +73,7 @@ Canvas::CullCallback::CullCallback(CameraCullCallback* camera_cull):
void Canvas::CullCallback::operator()( osg::Node* node, void Canvas::CullCallback::operator()( osg::Node* node,
osg::NodeVisitor* nv ) osg::NodeVisitor* nv )
{ {
if( nv->getTraversalMask() & simgear::MODEL_BIT ) if( (nv->getTraversalMask() & simgear::MODEL_BIT) && _camera_cull.valid() )
_camera_cull->enableRendering(); _camera_cull->enableRendering();
traverse(node, nv); traverse(node, nv);

View file

@ -27,6 +27,7 @@
#include <simgear/props/propertyObject.hxx> #include <simgear/props/propertyObject.hxx>
#include <osg/NodeCallback> #include <osg/NodeCallback>
#include <osg/observer_ptr>
#include <memory> #include <memory>
#include <string> #include <string>
@ -66,6 +67,7 @@ class Canvas:
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
}; };
typedef osg::ref_ptr<CameraCullCallback> CameraCullCallbackPtr; typedef osg::ref_ptr<CameraCullCallback> CameraCullCallbackPtr;
typedef osg::observer_ptr<CameraCullCallback> CameraCullCallbackWeakPtr;
/** /**
* This callback is installed on every placement of the canvas in the * This callback is installed on every placement of the canvas in the
@ -78,7 +80,7 @@ class Canvas:
CullCallback(CameraCullCallback* camera_cull); CullCallback(CameraCullCallback* camera_cull);
private: private:
CameraCullCallback *_camera_cull; CameraCullCallbackWeakPtr _camera_cull;
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv); virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
}; };
@ -91,10 +93,10 @@ class Canvas:
int getSizeX() const int getSizeX() const
{ return _size_x; } { return _size_x; }
int getSizeY() const int getSizeY() const
{ return _size_y; } { return _size_y; }
void setSizeX(int sx); void setSizeX(int sx);
void setSizeY(int sy); void setSizeY(int sy);

View file

@ -43,7 +43,7 @@ class CullCallback:
CullCallback(Canvas::CameraCullCallback* camera_cull); CullCallback(Canvas::CameraCullCallback* camera_cull);
private: private:
Canvas::CameraCullCallback *_camera_cull; Canvas::CameraCullCallbackWeakPtr _camera_cull;
virtual bool cull( osg::NodeVisitor* nv, virtual bool cull( osg::NodeVisitor* nv,
osg::Drawable* drawable, osg::Drawable* drawable,
@ -62,7 +62,8 @@ bool CullCallback::cull( osg::NodeVisitor* nv,
osg::Drawable* drawable, osg::Drawable* drawable,
osg::RenderInfo* renderInfo ) const osg::RenderInfo* renderInfo ) const
{ {
_camera_cull->enableRendering(); if( _camera_cull.valid() )
_camera_cull->enableRendering();
// TODO check if window/image should be culled // TODO check if window/image should be culled
return false; return false;