From bf30681bf31ab2db538fccc667c60be4937d44d6 Mon Sep 17 00:00:00 2001 From: Paolo Cignoni cignoni Date: Wed, 14 May 2008 16:56:47 +0000 Subject: [PATCH] Added updateTexture slot. To allow to external plugins to re-load the current texture --- src/meshlab/glarea.cpp | 20 ++++++++++++++------ src/meshlab/glarea.h | 7 +++++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/meshlab/glarea.cpp b/src/meshlab/glarea.cpp index b0f44c536..ad355be09 100644 --- a/src/meshlab/glarea.cpp +++ b/src/meshlab/glarea.cpp @@ -23,7 +23,7 @@ /**************************************************************************** History -$Log$ +$Log: glarea.cpp,v $ Revision 1.143 2008/04/22 16:15:45 bernabei By default, tablet events are treated as mouse events @@ -111,6 +111,7 @@ GLArea::GLArea(QWidget *parent) cfps=0; lastTime=0; hasToPick=false; + hasToUpdateTexture=false; helpVisible=false; takeSnapTile=false; activeDefaultTrackball=true; @@ -713,11 +714,19 @@ void GLArea::setColorMode(vcg::GLW::ColorMode mode) rm.colorMode = mode; updateGL(); } +void GLArea::updateTexture() +{ + hasToUpdateTexture = true; +} // Texture loading done during the first paint. void GLArea::initTexture() { - if(!mm()->cm.textures.empty() && mm()->glw.TMId.empty()){ + if(hasToUpdateTexture) + { + hasToUpdateTexture = false; + } + if(!mm()->cm.textures.empty() && mm()->glw.TMId.empty()){ glEnable(GL_TEXTURE_2D); for(unsigned int i =0; i< mm()->cm.textures.size();++i){ QImage img, imgScaled, imgGL; @@ -725,11 +734,11 @@ void GLArea::initTexture() // image has to be scaled to a 2^n size. We choose the first 2^N <= picture size. int bestW=pow(2.0,floor(::log(double(img.width() ))/::log(2.0))); int bestH=pow(2.0,floor(::log(double(img.height()))/::log(2.0))); + + qDebug("texture[ %i ] = %s ( %i x %i )", mm()->cm.textures[i].c_str(),i , imgGL.width(), imgGL.height()); imgScaled=img.scaled(bestW,bestH,Qt::IgnoreAspectRatio,Qt::SmoothTransformation); imgGL=convertToGLFormat(imgScaled); - qDebug("loaded texture %s. with id %i w %i h %i",mm()->cm.textures[i].c_str(),i, imgGL.width(), imgGL.height()); mm()->glw.TMId.push_back(0); - glGenTextures( 1, (GLuint*)&(mm()->glw.TMId.back()) ); glBindTexture( GL_TEXTURE_2D, mm()->glw.TMId.back() ); glTexImage2D( GL_TEXTURE_2D, 0, 3, imgGL.width(), imgGL.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, imgGL.bits() ); @@ -738,8 +747,7 @@ void GLArea::initTexture() glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - - qDebug("loaded texture %s. in %i",mm()->cm.textures[i].c_str(),mm()->glw.TMId[i]); + qDebug(" will be loaded as GL texture id %i ( %i x %i )",mm()->glw.TMId.back() ,imgGL.width(), imgGL.height()); } } glDisable(GL_TEXTURE_2D); diff --git a/src/meshlab/glarea.h b/src/meshlab/glarea.h index 31638b65b..fdbedecde 100644 --- a/src/meshlab/glarea.h +++ b/src/meshlab/glarea.h @@ -23,7 +23,7 @@ /**************************************************************************** History -$Log$ +$Log: glarea.h,v $ Revision 1.85 2008/04/22 14:54:38 bernabei Added support for tablet events @@ -336,6 +336,8 @@ public: // EndEdit is called only when you press again the same button or when you change editor. public slots: + void updateTexture(); // slot for forcing the texture reload. + void endEdit(){ if(iEdit && currentEditor) { @@ -403,7 +405,8 @@ QMap curMap; bool helpVisible; // Help on screen bool trackBallVisible; // Draws the trackball ? bool activeDefaultTrackball; // keep track on active trackball - bool hasToPick; // has to pick during the next redraw. + bool hasToUpdateTexture; // has to reload textures at the next redraw + bool hasToPick; // has to pick during the next redraw. vcg::Point2i pointToPick; //shader support