From: Thomas Geymayer Date: Sun, 23 Sep 2012 15:30:20 +0000 (+0200) Subject: Canvas: Fix detection if something has changed X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=efe978e6795249126a351d9823a434b41eda5994;p=flightgear.git Canvas: Fix detection if something has changed - Reset dirty flag for redrawing canvas properly after rendering has complted. - Update path properly if path elements have been removed. --- diff --git a/src/Canvas/canvas.cxx b/src/Canvas/canvas.cxx index 5c08061a5..ddc9e7225 100644 --- a/src/Canvas/canvas.cxx +++ b/src/Canvas/canvas.cxx @@ -35,6 +35,26 @@ #include #include +/** + * Callback for resetting the render_dirty flag after rendering a frame. + */ +class Canvas::DrawCallback: + public osg::Camera::DrawCallback +{ + public: + DrawCallback(Canvas* canvas): + _canvas(canvas) + {} + + virtual void operator()(osg::RenderInfo& renderInfo) const + { + _canvas->_render_dirty = false; + } + + protected: + Canvas *_canvas; +}; + //---------------------------------------------------------------------------- Canvas::CameraCullCallback::CameraCullCallback(): _render( true ), @@ -142,6 +162,7 @@ void Canvas::update(double delta_time_sec) _texture.allocRT(_camera_callback); _texture.getCamera()->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f , 1.0f)); _texture.getCamera()->addChild(_root_group->getMatrixTransform()); + _texture.getCamera()->setFinalDrawCallback(new DrawCallback(this)); if( _texture.serviceable() ) { @@ -154,12 +175,8 @@ void Canvas::update(double delta_time_sec) } } - _root_group->update(delta_time_sec); - _texture.setRender(_render_dirty); - - // Always render if sampling or color has changed - _render_dirty = _sampling_dirty || _color_dirty; + _root_group->update(delta_time_sec); if( _sampling_dirty ) { @@ -169,6 +186,7 @@ void Canvas::update(double delta_time_sec) _node->getIntValue("color-samples") ); _sampling_dirty = false; + _render_dirty = true; } if( _color_dirty ) { @@ -180,6 +198,7 @@ void Canvas::update(double delta_time_sec) _color_background[3]->getFloatValue() ) ); _color_dirty = false; + _render_dirty = true; } while( !_dirty_placements.empty() ) @@ -311,6 +330,8 @@ void Canvas::childAdded( SGPropertyNode * parent, void Canvas::childRemoved( SGPropertyNode * parent, SGPropertyNode * child ) { + _render_dirty = true; + if( parent != _node ) return; @@ -327,7 +348,6 @@ void Canvas::valueChanged(SGPropertyNode* node) if( boost::starts_with(node->getNameString(), "status") || node->getParent()->getNameString() == "bounding-box" ) return; - _render_dirty = true; bool handled = true; diff --git a/src/Canvas/canvas.hxx b/src/Canvas/canvas.hxx index ce75df921..25cd8e816 100644 --- a/src/Canvas/canvas.hxx +++ b/src/Canvas/canvas.hxx @@ -86,6 +86,11 @@ class Canvas: }; typedef osg::ref_ptr CullCallbackPtr; + /** + * Callback for resetting the render_dirty flag after rendering a frame. + */ + class DrawCallback; + Canvas(SGPropertyNode* node); virtual ~Canvas(); diff --git a/src/Canvas/elements/path.cxx b/src/Canvas/elements/path.cxx index a6cc76682..a9ab7e227 100644 --- a/src/Canvas/elements/path.cxx +++ b/src/Canvas/elements/path.cxx @@ -392,6 +392,12 @@ namespace canvas Element::update(dt); } + //---------------------------------------------------------------------------- + void Path::childRemoved(SGPropertyNode* child) + { + childChanged(child); + } + //---------------------------------------------------------------------------- void Path::childChanged(SGPropertyNode* child) { diff --git a/src/Canvas/elements/path.hxx b/src/Canvas/elements/path.hxx index 6a93f25fe..2d39cfe2d 100644 --- a/src/Canvas/elements/path.hxx +++ b/src/Canvas/elements/path.hxx @@ -43,6 +43,7 @@ namespace canvas osg::ref_ptr _path; + virtual void childRemoved(SGPropertyNode * child); virtual void childChanged(SGPropertyNode * child); };