]> git.mxchange.org Git - simgear.git/commitdiff
Create new FBO if Canvas render target size chanages
authorThomas Geymayer <tomgey@gmail.com>
Sun, 9 Dec 2012 22:08:04 +0000 (23:08 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 9 Dec 2012 22:08:07 +0000 (23:08 +0100)
As doesnt seem to work to just resize the texture, if changing
the size of the Canvas render target a new FBO is created and
placed on all active placements.

simgear/canvas/Canvas.cxx
simgear/canvas/Canvas.hxx
simgear/canvas/ODGauge.cxx
simgear/canvas/ODGauge.hxx

index c2882ebf05371e19406e6fc50df73a32099b12d6..8d3059cbc9d5b1a9a3979c705ca7588dbb8d9c8e 100644 (file)
@@ -159,15 +159,30 @@ namespace canvas
   //----------------------------------------------------------------------------
   void Canvas::update(double delta_time_sec)
   {
-    if( !_texture.serviceable() )
-    {
-      if( _status != STATUS_OK )
-        return;
+    if(    (!_texture.serviceable() && _status != STATUS_DIRTY)
+        || (_status & CREATE_FAILED) )
+      return;
 
+    if( _status == STATUS_DIRTY )
+    {
       _texture.setSize(_size_x, _size_y);
-      _texture.useImageCoords(true);
-      _texture.useStencil(true);
-      _texture.allocRT(/*_camera_callback*/);
+
+      if( !_texture.serviceable() )
+      {
+        _texture.useImageCoords(true);
+        _texture.useStencil(true);
+        _texture.allocRT(/*_camera_callback*/);
+      }
+      else
+      {
+        // Resizing causes a new texture to be created so we need to reapply all
+        // existing placements
+        for(size_t i = 0; i < _placements.size(); ++i)
+        {
+          if( !_placements[i].empty() )
+            _dirty_placements.push_back( _placements[i].front()->getProps() );
+        }
+      }
 
       osg::Camera* camera = _texture.getCamera();
 
@@ -183,6 +198,8 @@ namespace canvas
       if( _texture.serviceable() )
       {
         setStatusFlags(STATUS_OK);
+        setStatusFlags(STATUS_DIRTY, false);
+        _render_dirty = true;
       }
       else
       {
@@ -273,8 +290,7 @@ namespace canvas
     if( _size_x == sx )
       return;
     _size_x = sx;
-
-    // TODO resize if texture already allocated
+    setStatusFlags(STATUS_DIRTY);
 
     if( _size_x <= 0 )
       setStatusFlags(MISSING_SIZE_X);
@@ -291,8 +307,7 @@ namespace canvas
     if( _size_y == sy )
       return;
     _size_y = sy;
-
-    // TODO resize if texture already allocated
+    setStatusFlags(STATUS_DIRTY);
 
     if( _size_y <= 0 )
       setStatusFlags(MISSING_SIZE_Y);
@@ -545,7 +560,7 @@ namespace canvas
       _status_msg = "Missing size-y";
     else if( _status & CREATE_FAILED )
       _status_msg = "Creating render target failed";
-    else if( _status == STATUS_OK && !_texture.serviceable() )
+    else if( _status == STATUS_DIRTY )
       _status_msg = "Creation pending...";
     else
       _status_msg = "Ok";
index 4a3187fff4d68c4d73820463d6e9ae5c9f2a2b45..f53c7492d4ae8f44ad85819c57f4ac647a86b207 100644 (file)
@@ -46,9 +46,10 @@ namespace canvas
       enum StatusFlags
       {
         STATUS_OK,
-        MISSING_SIZE_X = 0x0001,
-        MISSING_SIZE_Y = 0x0002,
-        CREATE_FAILED  = 0x0004
+        STATUS_DIRTY     = 1,
+        MISSING_SIZE_X = STATUS_DIRTY << 1,
+        MISSING_SIZE_Y = MISSING_SIZE_X << 1,
+        CREATE_FAILED  = MISSING_SIZE_Y << 1
       };
 
       /**
index 8b27c06f8727240d91db990a4173f874e1694697..b59efc6a0f762d82608c687dca564fccfa97ce49 100644 (file)
@@ -70,8 +70,7 @@ namespace canvas
   //----------------------------------------------------------------------------
   ODGauge::~ODGauge()
   {
-    if( camera.valid() && _system_adapter )
-      _system_adapter->removeCamera(camera.get());
+    clear();
   }
 
   //----------------------------------------------------------------------------
@@ -86,8 +85,10 @@ namespace canvas
     _size_x = size_x;
     _size_y = size_y < 0 ? size_x : size_y;
 
-    if( texture.valid() )
-      texture->setTextureSize(_size_x, _size_x);
+    if( serviceable() )
+      reinit();
+    else if( texture )
+      texture->setTextureSize(_size_x, _size_y);
   }
 
   //----------------------------------------------------------------------------
@@ -217,6 +218,25 @@ namespace canvas
     rtAvailable = true;
   }
 
+  //----------------------------------------------------------------------------
+  void ODGauge::reinit()
+  {
+    osg::NodeCallback* cull_callback = camera ? camera->getCullCallback() : 0;
+    clear();
+    allocRT(cull_callback);
+  }
+
+  //----------------------------------------------------------------------------
+  void ODGauge::clear()
+  {
+    if( camera.valid() && _system_adapter )
+      _system_adapter->removeCamera(camera.get());
+    camera.release();
+    texture.release();
+
+    rtAvailable = false;
+  }
+
   //----------------------------------------------------------------------------
   void ODGauge::updateCoordinateFrame()
   {
index 5a07d69e2e53c59c498794e7f88e992e6861f0d8..3005132c10d9b7f66aefb93422d92b10c03e4189 100644 (file)
@@ -123,6 +123,8 @@ namespace canvas
 
       // Real initialization function. Bad name.
       void allocRT(osg::NodeCallback* camera_cull_callback = 0);
+      void reinit();
+      void clear();
 
     protected: