StelTexture.cpp   StelTexture.cpp 
skipping to change at line 40 skipping to change at line 40
#include <QDebug> #include <QDebug>
#include <QUrl> #include <QUrl>
#include <QImage> #include <QImage>
#include <QNetworkReply> #include <QNetworkReply>
#include <QtEndian> #include <QtEndian>
#include <QFuture> #include <QFuture>
#include <QtConcurrent> #include <QtConcurrent>
#include <cstdlib> #include <cstdlib>
StelTexture::StelTexture() : networkReply(NULL), loader(NULL), errorOccured (false), alphaChannel(false), id(0), avgLuminance(-1.f) StelTexture::StelTexture(StelTextureMgr *mgr) : textureMgr(mgr), networkRep ly(NULL), loader(NULL), errorOccured(false), alphaChannel(false), id(0), av gLuminance(-1.f), glSize(0)
{ {
width = -1; width = -1;
height = -1; height = -1;
} }
StelTexture::~StelTexture() StelTexture::~StelTexture()
{ {
if (id != 0) if (id != 0 && QOpenGLContext::currentContext())
{ {
if (glIsTexture(id)==GL_FALSE) if (glIsTexture(id)==GL_FALSE)
{ {
qDebug() << "WARNING: in StelTexture::~StelTexture() tried to delete invalid texture with ID=" << id << "Current GL ERROR statu s is" << glGetError() << "(" << getGLErrorText(glGetError()) << ")"; qDebug() << "WARNING: in StelTexture::~StelTexture() tried to delete invalid texture with ID=" << id << "Current GL ERROR statu s is" << glGetError() << "(" << getGLErrorText(glGetError()) << ")";
} }
else else
{ {
glDeleteTextures(1, &id); glDeleteTextures(1, &id);
textureMgr->glMemoryUsage -= glSize;
glSize = 0;
} }
#ifndef NDEBUG
qDebug()<<"Deleted StelTexture"<<id<<", total memory usage "
<<textureMgr->glMemoryUsage / (1024.0 * 1024.0)<<"MB";
#endif
id = 0; id = 0;
} }
if (networkReply != NULL) else if (id)
{
qWarning()<<"Cannot delete texture"<<id<<", no GL context";
}
if (networkReply)
{ {
networkReply->abort(); networkReply->abort();
networkReply->deleteLater(); //networkReply->deleteLater();
delete networkReply;
networkReply = NULL;
} }
if (loader != NULL) { if (loader != NULL) {
delete loader; delete loader;
loader = NULL; loader = NULL;
} }
} }
/************************************************************************* /*************************************************************************
This method should be called if the texture loading failed for any reasons This method should be called if the texture loading failed for any reasons
*************************************************************************/ *************************************************************************/
skipping to change at line 127 skipping to change at line 138
return true; return true;
} }
if (errorOccured) if (errorOccured)
return false; return false;
// If the file is remote, start a network connection. // If the file is remote, start a network connection.
if (loader == NULL && networkReply == NULL && fullPath.startsWith("h ttp://")) { if (loader == NULL && networkReply == NULL && fullPath.startsWith("h ttp://")) {
QNetworkRequest req = QNetworkRequest(QUrl(fullPath)); QNetworkRequest req = QNetworkRequest(QUrl(fullPath));
// Define that preference should be given to cached files (n o etag checks) // Define that preference should be given to cached files (n o etag checks)
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
req.setRawHeader("User-Agent", StelUtils::getApplicationName ().toLatin1()); req.setRawHeader("User-Agent", StelUtils::getUserAgentString ().toLatin1());
networkReply = StelApp::getInstance().getNetworkAccessManage r()->get(req); networkReply = StelApp::getInstance().getNetworkAccessManage r()->get(req);
connect(networkReply, SIGNAL(finished()), this, SLOT(onNetwo rkReply())); connect(networkReply, SIGNAL(finished()), this, SLOT(onNetwo rkReply()));
return false; return false;
} }
// The network connection is still running. // The network connection is still running.
if (networkReply != NULL) if (networkReply != NULL)
return false; return false;
// Not a remote file, start a loader from local file. // Not a remote file, start a loader from local file.
if (loader == NULL) if (loader == NULL)
{ {
skipping to change at line 161 skipping to change at line 172
void StelTexture::onNetworkReply() void StelTexture::onNetworkReply()
{ {
Q_ASSERT(loader == NULL); Q_ASSERT(loader == NULL);
if (networkReply->error() != QNetworkReply::NoError) if (networkReply->error() != QNetworkReply::NoError)
{ {
reportError(networkReply->errorString()); reportError(networkReply->errorString());
} }
else else
{ {
QByteArray data = networkReply->readAll(); QByteArray data = networkReply->readAll();
loader = new QFuture<GLData>(QtConcurrent::run(loadFromData, if(data.isEmpty()) //prevent starting the loader when there
data)); is nothing to load
reportError(QString("Empty result received for URL:
%1").arg(networkReply->url().toString()));
else
loader = new QFuture<GLData>(QtConcurrent::run(loadF
romData, data));
} }
networkReply->deleteLater(); networkReply->deleteLater();
networkReply = NULL; networkReply = NULL;
} }
/************************************************************************* /*************************************************************************
Return the width and heigth of the texture in pixels Return the width and heigth of the texture in pixels
*************************************************************************/ *************************************************************************/
bool StelTexture::getDimensions(int &awidth, int &aheight) bool StelTexture::getDimensions(int &awidth, int &aheight)
{ {
skipping to change at line 224 skipping to change at line 238
int ipl = tmp.bytesPerLine() / 4; int ipl = tmp.bytesPerLine() / 4;
for (int y = 0; y < height / 2; ++y) for (int y = 0; y < height / 2; ++y)
{ {
int *a = (int *) tmp.scanLine(y); int *a = (int *) tmp.scanLine(y);
int *b = (int *) tmp.scanLine(height - y - 1); int *b = (int *) tmp.scanLine(height - y - 1);
for (int x = 0; x < ipl; ++x) for (int x = 0; x < ipl; ++x)
qSwap(a[x], b[x]); qSwap(a[x], b[x]);
} }
// convert data // convert data
// we always use a tightly packed format, with 1-4 bpp
for (int i = 0; i < height; ++i) for (int i = 0; i < height; ++i)
{ {
uint *p = (uint *) tmp.scanLine(i); uint *p = (uint *) tmp.scanLine(i);
for (int x = 0; x < width; ++x) for (int x = 0; x < width; ++x)
{ {
uint c = qToBigEndian(p[x]); uint c = qToBigEndian(p[x]);
const char* ptr = (const char*)&c; const char* ptr = (const char*)&c;
switch (*format) switch (*format)
{ {
case GL_RGBA: case GL_RGBA:
skipping to change at line 310 skipping to change at line 325
default: default:
//for the other cases, they may be on any alignment (depending on image width) //for the other cases, they may be on any alignment (depending on image width)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
alphaChannel = false; alphaChannel = false;
} }
//do pixel transfer //do pixel transfer
glTexImage2D(GL_TEXTURE_2D, 0, data.format, width, height, 0, data.f ormat, glTexImage2D(GL_TEXTURE_2D, 0, data.format, width, height, 0, data.f ormat,
data.type, data.data.constData()); data.type, data.data.constData());
//for now, assume full sized 8 bit GL formats used internally
glSize = data.data.size();
textureMgr->glMemoryUsage += glSize;
#ifndef NDEBUG
qDebug()<<"StelTexture"<<id<<"uploaded, total memory usage "<<textur
eMgr->glMemoryUsage / (1024.0 * 1024.0)<<"MB";
#endif
//restore old value //restore old value
glPixelStorei(GL_UNPACK_ALIGNMENT, oldalignment); glPixelStorei(GL_UNPACK_ALIGNMENT, oldalignment);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, loadParams.wrapMod e); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, loadParams.wrapMod e);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, loadParams.wrapMod e); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, loadParams.wrapMod e);
if (loadParams.generateMipmaps) if (loadParams.generateMipmaps)
{ {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, loadPa rams.filterMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, loadPa rams.filterMipmaps ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR_MIPMAP_NEAREST);
glGenerateMipmap(GL_TEXTURE_2D); glGenerateMipmap(GL_TEXTURE_2D);
} }
 End of changes. 10 change blocks. 
7 lines changed or deleted 34 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/