diff --git a/src/Canvas/canvas_mgr.cxx b/src/Canvas/canvas_mgr.cxx index 1bf143e5c..ca4515e9a 100644 --- a/src/Canvas/canvas_mgr.cxx +++ b/src/Canvas/canvas_mgr.cxx @@ -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(); diff --git a/src/Canvas/canvas_mgr.hxx b/src/Canvas/canvas_mgr.hxx index 4a3160873..fd4768c34 100644 --- a/src/Canvas/canvas_mgr.hxx +++ b/src/Canvas/canvas_mgr.hxx @@ -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_ */ diff --git a/src/GUI/CanvasWidget.cxx b/src/GUI/CanvasWidget.cxx index b505aa5ea..72b7ec177 100644 --- a/src/GUI/CanvasWidget.cxx +++ b/src/GUI/CanvasWidget.cxx @@ -28,8 +28,6 @@ CanvasWidget::CanvasWidget( int x, int y, const std::string& module ): puObject(x, y, width, height), _canvas_mgr( dynamic_cast(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]); diff --git a/src/GUI/CanvasWidget.hxx b/src/GUI/CanvasWidget.hxx index a14a9de9b..a2e6c84b1 100644 --- a/src/GUI/CanvasWidget.hxx +++ b/src/GUI/CanvasWidget.hxx @@ -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; //