1
0
Fork 0

CanvasWidget: Retrieve texture id every frame.

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.
This commit is contained in:
Thomas Geymayer 2012-12-09 23:15:17 +01:00
parent dc132ab475
commit e62649e075
4 changed files with 5 additions and 41 deletions

View 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();

View 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_ */

View 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]);

View 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,