]> git.mxchange.org Git - simgear.git/commitdiff
Canvas Image: fix updating while showing nested canvas.
authorThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:17:30 +0000 (19:17 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Fri, 31 May 2013 17:17:30 +0000 (19:17 +0200)
simgear/canvas/elements/CanvasImage.cxx
simgear/canvas/elements/CanvasImage.hxx

index bc6ff0914727e0e3c531afbd52ea3e02791f5c97..d472a6aef4cf828d9afa62e20404e9c710fb185d 100644 (file)
@@ -149,6 +149,24 @@ namespace canvas
   {
     Element::update(dt);
 
+    osg::Texture2D* texture = dynamic_cast<osg::Texture2D*>
+    (
+      _geom->getOrCreateStateSet()
+           ->getTextureAttribute(0, osg::StateAttribute::TEXTURE)
+    );
+    simgear::canvas::CanvasPtr canvas = _src_canvas.lock();
+
+    if(    (_attributes_dirty & SRC_CANVAS)
+           // check if texture has changed (eg. due to resizing)
+        || (canvas && texture != canvas->getTexture()) )
+    {
+      _geom->getOrCreateStateSet()
+           ->setTextureAttribute(0, canvas ? canvas->getTexture() : 0);
+
+      if( !canvas || canvas->isInit() )
+        _attributes_dirty &= ~SRC_CANVAS;
+    }
+
     if( !_attributes_dirty )
       return;
 
@@ -335,8 +353,7 @@ namespace canvas
       _canvas.lock()->removeChildCanvas(_src_canvas);
 
     _src_canvas = canvas;
-    _geom->getOrCreateStateSet()
-         ->setTextureAttribute(0, canvas ? canvas->getTexture() : 0);
+    _attributes_dirty |= SRC_CANVAS;
     _geom->setCullCallback(canvas ? new CullCallback(canvas) : 0);
 
     if( !_src_canvas.expired() )
index 105c628f35bbc26e6c00184695ed797f47e3aaa2..3b8dca7884aa401e4145f7c67750a31413fa6303 100644 (file)
@@ -88,7 +88,8 @@ namespace canvas
       enum ImageAttributes
       {
         SRC_RECT       = LAST_ATTRIBUTE << 1, // Source image rectangle
-        DEST_SIZE      = SRC_RECT << 1        // Element size
+        DEST_SIZE      = SRC_RECT << 1,       // Element size
+        SRC_CANVAS     = DEST_SIZE << 1
       };
 
       virtual void childChanged(SGPropertyNode * child);