]> git.mxchange.org Git - flightgear.git/commitdiff
CanvasWidget: Retrieve texture id every frame.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 9 Dec 2012 22:15:17 +0000 (23:15 +0100)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 9 Dec 2012 22:15:49 +0000 (23:15 +0100)
If the size of a Canvas changes also the texture id
changes. We now retrieve the texture id for the CanvasWidget
every frame to ensure it uses the latest texture instance.

src/Canvas/canvas_mgr.cxx
src/Canvas/canvas_mgr.hxx
src/GUI/CanvasWidget.cxx
src/GUI/CanvasWidget.hxx

index 1bf143e5c52da2f04248d07782cbae661bffb19f..ca4515e9a09d949323e58c53dead2d761e73ed29 100644 (file)
@@ -48,13 +48,9 @@ CanvasMgr::CanvasMgr():
 }
 
 //------------------------------------------------------------------------------
-unsigned int CanvasMgr::getCanvasTexId(size_t index) const
+unsigned int
+CanvasMgr::getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const
 {
-  simgear::canvas::CanvasPtr canvas = getCanvas(index);
-
-  if( !canvas )
-    return 0;
-
   osg::Texture2D* tex = canvas->getTexture();
   if( !tex )
     return 0;
@@ -65,7 +61,7 @@ unsigned int CanvasMgr::getCanvasTexId(size_t index) const
 //  if( contexts.empty() )
 //    return 0;
 
-  osg::Camera* guiCamera =
+  static osg::Camera* guiCamera =
     flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
 
   osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
index 4a3160873bf5f04efcf08c744f6ecc1e30b65b18..fd4768c34d526d25ef2833f0b160358f27c2a4a9 100644 (file)
@@ -35,10 +35,9 @@ class CanvasMgr:
      *             implementation as PUI can't handle osg::Texture objects.
      *             Use getCanvas(index)->getTexture() instead.
      *
-     * @param Index of canvas
      * @return OpenGL texture name
      */
-    unsigned int getCanvasTexId(size_t index) const;
+    unsigned int getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const;
 };
 
 #endif /* CANVAS_MGR_H_ */
index b505aa5eab425a64de0c60d6d7c2f570f4f79bc6..72b7ec1775f1e9c5fbb4a69567bee7c44506e5ce 100644 (file)
@@ -28,8 +28,6 @@ CanvasWidget::CanvasWidget( int x, int y,
                             const std::string& module ):
   puObject(x, y, width, height),
   _canvas_mgr( dynamic_cast<CanvasMgr*>(globals->get_subsystem("Canvas")) ),
-  _tex_id(0),
-  _no_tex_cnt(0),
   _last_x(0),
   _last_y(0)
 {
@@ -207,34 +205,8 @@ void CanvasWidget::setSize(int w, int h)
 //------------------------------------------------------------------------------
 void CanvasWidget::draw(int dx, int dy)
 {
-  if( !_tex_id )
-  {
-    _tex_id = _canvas_mgr->getCanvasTexId( _canvas->getProps()->getIndex() );
-
-    // Normally we should be able to get the texture after one frame. I don't
-    // know if there are circumstances where it can take longer, so we don't
-    // log a warning message until we have tried a few times.
-    if( !_tex_id )
-    {
-      if( ++_no_tex_cnt == 5 )
-        SG_LOG(SG_GENERAL, SG_WARN, "CanvasWidget: failed to get texture!");
-      return;
-    }
-    else
-    {
-      if( _no_tex_cnt >= 5 )
-        SG_LOG
-        (
-          SG_GENERAL,
-          SG_INFO,
-          "CanvasWidget: got texture after " << _no_tex_cnt << " tries."
-        );
-      _no_tex_cnt = 0;
-    }
-  }
-
   glEnable(GL_TEXTURE_2D);
-  glBindTexture(GL_TEXTURE_2D, _tex_id);
+  glBindTexture(GL_TEXTURE_2D, _canvas_mgr->getCanvasTexId(_canvas));
   glBegin( GL_QUADS );
     glColor3f(1,1,1);
     glTexCoord2f(0,0); glVertex2f(dx + abox.min[0], dy + abox.min[1]);
index a14a9de9bb3b5826d710d9ce14e65e92e66723b1..a2e6c84b113debbfe08953866054b1a849f1b01f 100644 (file)
@@ -36,9 +36,6 @@ class CanvasWidget:
     CanvasMgr  *_canvas_mgr; // TODO maybe we should store this in some central
                              // location or make it static...
 
-    GLuint              _tex_id;    //<! OpenGL texture id if canvas
-    size_t              _no_tex_cnt;//<! Count since how many frames we were not
-                                    //   able to get the texture (for debugging)
     simgear::canvas::CanvasPtr _canvas;
     SGPropertyNode     *_mouse_x,
                        *_mouse_y,