}
//------------------------------------------------------------------------------
-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;
// 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();
* 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_ */
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)
{
//------------------------------------------------------------------------------
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]);
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,