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:
parent
dc132ab475
commit
e62649e075
4 changed files with 5 additions and 41 deletions
|
@ -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();
|
osg::Texture2D* tex = canvas->getTexture();
|
||||||
if( !tex )
|
if( !tex )
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -65,7 +61,7 @@ unsigned int CanvasMgr::getCanvasTexId(size_t index) const
|
||||||
// if( contexts.empty() )
|
// if( contexts.empty() )
|
||||||
// return 0;
|
// return 0;
|
||||||
|
|
||||||
osg::Camera* guiCamera =
|
static osg::Camera* guiCamera =
|
||||||
flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
|
flightgear::getGUICamera(flightgear::CameraGroup::getDefault());
|
||||||
|
|
||||||
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
|
osg::State* state = guiCamera->getGraphicsContext()->getState(); //contexts[0]->getState();
|
||||||
|
|
|
@ -35,10 +35,9 @@ class CanvasMgr:
|
||||||
* implementation as PUI can't handle osg::Texture objects.
|
* implementation as PUI can't handle osg::Texture objects.
|
||||||
* Use getCanvas(index)->getTexture() instead.
|
* Use getCanvas(index)->getTexture() instead.
|
||||||
*
|
*
|
||||||
* @param Index of canvas
|
|
||||||
* @return OpenGL texture name
|
* @return OpenGL texture name
|
||||||
*/
|
*/
|
||||||
unsigned int getCanvasTexId(size_t index) const;
|
unsigned int getCanvasTexId(const simgear::canvas::CanvasPtr& canvas) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CANVAS_MGR_H_ */
|
#endif /* CANVAS_MGR_H_ */
|
||||||
|
|
|
@ -28,8 +28,6 @@ CanvasWidget::CanvasWidget( int x, int y,
|
||||||
const std::string& module ):
|
const std::string& module ):
|
||||||
puObject(x, y, width, height),
|
puObject(x, y, width, height),
|
||||||
_canvas_mgr( dynamic_cast<CanvasMgr*>(globals->get_subsystem("Canvas")) ),
|
_canvas_mgr( dynamic_cast<CanvasMgr*>(globals->get_subsystem("Canvas")) ),
|
||||||
_tex_id(0),
|
|
||||||
_no_tex_cnt(0),
|
|
||||||
_last_x(0),
|
_last_x(0),
|
||||||
_last_y(0)
|
_last_y(0)
|
||||||
{
|
{
|
||||||
|
@ -207,34 +205,8 @@ void CanvasWidget::setSize(int w, int h)
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void CanvasWidget::draw(int dx, int dy)
|
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);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glBindTexture(GL_TEXTURE_2D, _tex_id);
|
glBindTexture(GL_TEXTURE_2D, _canvas_mgr->getCanvasTexId(_canvas));
|
||||||
glBegin( GL_QUADS );
|
glBegin( GL_QUADS );
|
||||||
glColor3f(1,1,1);
|
glColor3f(1,1,1);
|
||||||
glTexCoord2f(0,0); glVertex2f(dx + abox.min[0], dy + abox.min[1]);
|
glTexCoord2f(0,0); glVertex2f(dx + abox.min[0], dy + abox.min[1]);
|
||||||
|
|
|
@ -36,9 +36,6 @@ class CanvasWidget:
|
||||||
CanvasMgr *_canvas_mgr; // TODO maybe we should store this in some central
|
CanvasMgr *_canvas_mgr; // TODO maybe we should store this in some central
|
||||||
// location or make it static...
|
// 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;
|
simgear::canvas::CanvasPtr _canvas;
|
||||||
SGPropertyNode *_mouse_x,
|
SGPropertyNode *_mouse_x,
|
||||||
*_mouse_y,
|
*_mouse_y,
|
||||||
|
|
Loading…
Add table
Reference in a new issue