summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 2cf3d63a09..dde4eba715 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 8839f60e2d..b1c9503608 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