summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@trolltech.com>2009-09-03 12:51:07 (GMT)
committerGunnar Sletta <gunnar@trolltech.com>2009-09-03 12:56:47 (GMT)
commitaa0a85a5c333e7a35101e469cf3f001c41e0f350 (patch)
treef78a9f86d5fbcd1d9721eff6067a7f358b1f862c /src
parent1bfc0fbf6ea476af24be545c95768e363c61a1c5 (diff)
downloadQt-aa0a85a5c333e7a35101e469cf3f001c41e0f350.zip
Qt-aa0a85a5c333e7a35101e469cf3f001c41e0f350.tar.gz
Qt-aa0a85a5c333e7a35101e469cf3f001c41e0f350.tar.bz2
Fixed bindTexture() on bigendian and older implementations
Reviewed-by: Trond
Diffstat (limited to 'src')
-rw-r--r--src/opengl/qgl.cpp37
-rw-r--r--src/opengl/qglextensions_p.h4
2 files changed, 37 insertions, 4 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 2cf3d63..dde4eba 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -2005,9 +2005,15 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G
QImage::Format target_format = img.format();
bool premul = options & QGLContext::PremultipliedAlphaBindOption;
- GLenum texture_format = QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2
- ? GL_BGRA : GL_RGBA;
- GLuint pixel_type = GL_UNSIGNED_BYTE;
+ GLenum texture_format;
+ GLuint pixel_type;
+ if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2) {
+ texture_format = GL_BGRA;
+ pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+ } else {
+ texture_format = GL_RGBA;
+ pixel_type = GL_UNSIGNED_BYTE;
+ }
switch (target_format) {
case QImage::Format_ARGB32:
@@ -2034,7 +2040,6 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G
if (format == GL_RGBA)
format = GL_RGB;
break;
-
default:
if (img.hasAlphaChannel()) {
img = img.convertToFormat(premul
@@ -2062,6 +2067,30 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G
}
}
+ if (texture_format == GL_RGBA) {
+ // The only case where we end up with a depth different from
+ // 32 in the switch above is for the RGB16 case, where we set
+ // the format to GL_RGB
+ Q_ASSERT(img.depth() == 32);
+ const int width = img.width();
+ const int height = img.height();
+
+ if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV
+ || (pixel_type == GL_UNSIGNED_BYTE && QSysInfo::ByteOrder == QSysInfo::LittleEndian)) {
+ for (int i=0; i < height; ++i) {
+ uint *p = (uint *) img.scanLine(i);
+ for (int x=0; x<width; ++x)
+ p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
+ }
+ } else {
+ for (int i=0; i < height; ++i) {
+ uint *p = (uint *) img.scanLine(i);
+ for (int x=0; x<width; ++x)
+ p[x] = (p[x] << 8) | ((p[x] >> 24) & 0xff);
+ }
+ }
+ }
+
const QImage &constRef = img; // to avoid detach in bits()...
glTexImage2D(target, 0, format, img.width(), img.height(), 0, texture_format,
pixel_type, constRef.bits());
diff --git a/src/opengl/qglextensions_p.h b/src/opengl/qglextensions_p.h
index 8839f60..b1c9503 100644
--- a/src/opengl/qglextensions_p.h
+++ b/src/opengl/qglextensions_p.h
@@ -418,6 +418,10 @@ struct QGLExtensionFuncs
#define GL_UNSIGNED_SHORT_5_6_5 33635
#endif
+#ifndef GL_UNSIGNED_INT_8_8_8_8_REV
+#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
+#endif
+
#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE 0x809D
#endif