StelTextureMgr.cpp   StelTextureMgr.cpp 
skipping to change at line 22 skipping to change at line 22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, U SA.
*/ */
#include "StelTextureMgr.hpp" #include "StelTextureMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelApp.hpp"
#include "StelMainGraphicsView.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "StelPainter.hpp"
#include <QHttp> #include <QHttp>
#include <QFileInfo> #include <QFileInfo>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
#include <QSettings> #include <QSettings>
#include <QGLFormat> #include <QGLFormat>
#include <cstdlib> #include <cstdlib>
StelTextureMgr::StelTextureMgr() StelTextureMgr::StelTextureMgr()
{ {
} }
StelTextureMgr::~StelTextureMgr() StelTextureMgr::~StelTextureMgr()
{ {
} }
void StelTextureMgr::init() void StelTextureMgr::init()
{ {
StelApp::getInstance().makeMainGLContextCurrent(); StelPainter::makeMainGLContextCurrent();
isNoPowerOfTwoAllowed = QGLFormat::openGLVersionFlags().testFlag(QGL Format::OpenGL_Version_2_0) || QGLFormat::openGLVersionFlags().testFlag(QGL Format::OpenGL_ES_Version_2_0); isNoPowerOfTwoAllowed = QGLFormat::openGLVersionFlags().testFlag(QGL Format::OpenGL_Version_2_0) || QGLFormat::openGLVersionFlags().testFlag(QGL Format::OpenGL_ES_Version_2_0);
} }
StelTextureSP StelTextureMgr::createTexture(const QString& afilename, const StelTexture::StelTextureParams& params) StelTextureSP StelTextureMgr::createTexture(const QString& afilename, const StelTexture::StelTextureParams& params)
{ {
if (afilename.isEmpty()) if (afilename.isEmpty())
return StelTextureSP(); return StelTextureSP();
StelTextureSP tex = StelTextureSP(new StelTexture()); StelTextureSP tex = StelTextureSP(new StelTexture());
try try
{ {
tex->fullPath = StelFileMgr::findFile(afilename); tex->fullPath = StelFileMgr::findFile(afilename);
} }
catch (std::runtime_error e) catch (std::runtime_error er)
{ {
try #ifdef USE_OPENGL_ES2
// Allow to replace the texures by compressed .pvr versions
using GPU decompression.
// This saves memory and increases rendering speed.
if (!afilename.endsWith(".pvr"))
{ {
tex->fullPath = StelFileMgr::findFile("textures/" + QString pvrVersion = afilename;
afilename); pvrVersion.replace(".png", ".pvr");
} return createTexture(pvrVersion, params);
catch (std::runtime_error er)
{
qWarning() << "WARNING : Can't find texture file " <
< afilename << ": " << er.what() << endl;
tex->errorOccured = true;
return StelTextureSP();
} }
#endif
qWarning() << "WARNING : Can't find texture file " << afilen
ame << ": " << er.what() << endl;
tex->errorOccured = true;
return StelTextureSP();
} }
tex->qImage = QImage(tex->fullPath); StelPainter::makeMainGLContextCurrent();
if (tex->qImage.isNull()) if (tex->fullPath.endsWith(".pvr"))
return StelTextureSP(); {
tex->loadParams = params; // Load compressed textures using Qt wrapper.
tex->downloaded = true; tex->loadParams = params;
tex->downloaded = true;
if (tex->glLoad()) tex->id = StelPainter::glContext->bindTexture(tex->fullPath)
;
// For some reasons only LINEAR seems to work
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LIN
EAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LIN
EAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, tex->loadP
arams.wrapMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tex->loadP
arams.wrapMode);
return tex; return tex;
}
else else
return StelTextureSP(); {
tex->qImage = QImage(tex->fullPath);
if (tex->qImage.isNull())
return StelTextureSP();
tex->loadParams = params;
tex->downloaded = true;
if (tex->glLoad())
return tex;
else
return StelTextureSP();
}
} }
StelTextureSP StelTextureMgr::createTextureThread(const QString& url, const StelTexture::StelTextureParams& params, const QString& fileExtension, bool lazyLoading) StelTextureSP StelTextureMgr::createTextureThread(const QString& url, const StelTexture::StelTextureParams& params, const QString& fileExtension, bool lazyLoading)
{ {
if (url.isEmpty()) if (url.isEmpty())
return StelTextureSP(); return StelTextureSP();
StelTextureSP tex = StelTextureSP(new StelTexture()); StelTextureSP tex = StelTextureSP(new StelTexture());
tex->loadParams = params; tex->loadParams = params;
if (!url.startsWith("http://")) if (!url.startsWith("http://"))
skipping to change at line 127 skipping to change at line 147
if (fileExtension.isEmpty()) if (fileExtension.isEmpty())
{ {
const int idx = url.lastIndexOf('.'); const int idx = url.lastIndexOf('.');
if (idx!=-1) if (idx!=-1)
tex->fileExtension = url.right(url.size()-id x-1); tex->fileExtension = url.right(url.size()-id x-1);
} }
} }
if (!fileExtension.isEmpty()) if (!fileExtension.isEmpty())
tex->fileExtension = fileExtension; tex->fileExtension = fileExtension;
if (!lazyLoading) if (!lazyLoading)
{
StelPainter::makeMainGLContextCurrent();
tex->bind(); tex->bind();
}
return tex; return tex;
} }
 End of changes. 13 change blocks. 
21 lines changed or deleted 49 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/