]> git.mxchange.org Git - flightgear.git/commitdiff
Canvas: Fix detection if something has changed
authorThomas Geymayer <tomgey@gmail.com>
Sun, 23 Sep 2012 15:30:20 +0000 (17:30 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 23 Sep 2012 15:31:12 +0000 (17:31 +0200)
 - Reset dirty flag for redrawing canvas properly after
   rendering has complted.
 - Update path properly if path elements have been removed.

src/Canvas/canvas.cxx
src/Canvas/canvas.hxx
src/Canvas/elements/path.cxx
src/Canvas/elements/path.hxx

index 5c08061a5cc5bb17d3a03412d48110e2e7eca1a5..ddc9e7225357422adaaa6d3e69e9d695d888a140 100644 (file)
 #include <boost/algorithm/string/predicate.hpp>
 #include <iostream>
 
+/**
+ * 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;
index ce75df921a76793ba28aafca96fda7c993fe0459..25cd8e81676cf205d235b0011cb7ee528a1f3e69 100644 (file)
@@ -86,6 +86,11 @@ class Canvas:
     };
     typedef osg::ref_ptr<CullCallback> CullCallbackPtr;
 
+    /**
+     * Callback for resetting the render_dirty flag after rendering a frame.
+     */
+    class DrawCallback;
+
     Canvas(SGPropertyNode* node);
     virtual ~Canvas();
 
index a6cc76682d2368a34eb34ee57ecf6855a31cc03e..a9ab7e22703199ccaf0dd06199cd4ad4b4067290 100644 (file)
@@ -392,6 +392,12 @@ namespace canvas
     Element::update(dt);
   }
 
+  //----------------------------------------------------------------------------
+  void Path::childRemoved(SGPropertyNode* child)
+  {
+    childChanged(child);
+  }
+
   //----------------------------------------------------------------------------
   void Path::childChanged(SGPropertyNode* child)
   {
index 6a93f25fe2c60b1ada24d81d0dc1f3a3ddd8b8ba..2d39cfe2dd0349d1f3005495840da659e1f1fd90 100644 (file)
@@ -43,6 +43,7 @@ namespace canvas
 
       osg::ref_ptr<PathDrawable> _path;
 
+      virtual void childRemoved(SGPropertyNode * child);
       virtual void childChanged(SGPropertyNode * child);
   };