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), id(0), avgLuminance(-1.f) StelTexture::StelTexture() : networkReply(NULL), loader(NULL), errorOccured (false), alphaChannel(false), id(0), avgLuminance(-1.f)
{ {
width = -1; width = -1;
height = -1; height = -1;
} }
StelTexture::~StelTexture() StelTexture::~StelTexture()
{ {
if (id != 0) if (id != 0)
{ {
if (glIsTexture(id)==GL_FALSE) if (glIsTexture(id)==GL_FALSE)
skipping to change at line 262 skipping to change at line 262
return ret; return ret;
} }
bool StelTexture::glLoad(const GLData& data) bool StelTexture::glLoad(const GLData& data)
{ {
if (data.data.isEmpty()) if (data.data.isEmpty())
{ {
reportError("Unknown error"); reportError("Unknown error");
return false; return false;
} }
width = data.width; width = data.width;
height = data.height; height = data.height;
//check minimum texture size
GLint maxSize;
glGetIntegerv(GL_MAX_TEXTURE_SIZE,&maxSize);
if(maxSize < width || maxSize < height)
{
reportError(QString("Texture size (%1/%2) is larger than GL_
MAX_TEXTURE_SIZE (%3)!").arg(width).arg(height).arg(maxSize));
return false;
}
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &id); glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id); glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, loadParams.fil glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, loadParams.fil
tering); tering);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, loadParams.fil glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, loadParams.fil
tering); tering);
//the conversion from QImage may result in tightly packed scanlines
that are no longer 4-byte aligned!
//--> we have to set the GL_UNPACK_ALIGNMENT accordingly
//remember current alignment
GLint oldalignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT,&oldalignment);
switch(data.format)
{
case GL_RGBA:
//RGBA pixels are always in 4 byte aligned rows
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
alphaChannel = true;
break;
case GL_LUMINANCE_ALPHA:
//these ones are at least always in 2 byte aligned r
ows, but may also be 4 aligned
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
alphaChannel = true;
break;
default:
//for the other cases, they may be on any alignment
(depending on image width)
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
alphaChannel = false;
}
//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());
//restore old value
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)
{ {
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LIN EAR_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);
} }
// Report success of texture loading // Report success of texture loading
emit(loadingProcessFinished(false)); emit(loadingProcessFinished(false));
return true; return true;
} }
// Actually load the texture to openGL memory // Actually load the texture to openGL memory
bool StelTexture::glLoad(const QImage& image) bool StelTexture::glLoad(const QImage& image)
{ {
 End of changes. 6 change blocks. 
6 lines changed or deleted 52 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/