summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@digia.com>2014-02-11 15:12:00 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-11 15:12:00 +0100
commitdf62c31807f7b0a8b9bc222b47ccc7016cfaee65 (patch)
treea7df6263cdb4cc96e2d31486437ec19ca0bf01e5 /src/gui/opengl
parent17de86f2824c1807c0fa7fa7ae0ed3b7d2acca00 (diff)
parenta1fe728fa5bd6cb9e50cf317a58efcf4eea4de2c (diff)
Merge "Merge remote-tracking branch 'origin/stable' into dev" into refs/staging/dev
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopenglframebufferobject.cpp2
-rw-r--r--src/gui/opengl/qopengltexturecache.cpp29
2 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp
index a1c4cf2a29..d67524810d 100644
--- a/src/gui/opengl/qopenglframebufferobject.cpp
+++ b/src/gui/opengl/qopenglframebufferobject.cpp
@@ -432,9 +432,11 @@ void QOpenGLFramebufferObjectPrivate::init(QOpenGLFramebufferObject *, const QSi
samples = 0;
}
+#ifndef QT_OPENGL_ES_2
GLint maxSamples;
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
samples = qBound(0, int(samples), int(maxSamples));
+#endif
size = sz;
target = texture_target;
diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp
index 4238f63cd8..750264935b 100644
--- a/src/gui/opengl/qopengltexturecache.cpp
+++ b/src/gui/opengl/qopengltexturecache.cpp
@@ -40,6 +40,7 @@
****************************************************************************/
#include "qopengltexturecache_p.h"
+#include <qopenglfunctions.h>
#include <private/qopenglcontext_p.h>
#include <private/qimagepixmapcleanuphooks_p.h>
#include <qpa/qplatformpixmap.h>
@@ -128,6 +129,20 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &
return id;
}
+// returns the highest number closest to v, which is a power of 2
+// NB! assumes 32 bit ints
+static int qt_next_power_of_two(int v)
+{
+ v--;
+ v |= v >> 1;
+ v |= v >> 2;
+ v |= v >> 4;
+ v |= v >> 8;
+ v |= v >> 16;
+ ++v;
+ return v;
+}
+
GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image)
{
if (image.isNull())
@@ -144,7 +159,19 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i
}
}
- GLuint id = bindTexture(context, key, image);
+ QImage img = image;
+ if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)) {
+ // Scale the pixmap if needed. GL textures needs to have the
+ // dimensions 2^n+2(border) x 2^m+2(border), unless we're using GL
+ // 2.0 or use the GL_TEXTURE_RECTANGLE texture target
+ int tx_w = qt_next_power_of_two(image.width());
+ int tx_h = qt_next_power_of_two(image.height());
+ if (tx_w != image.width() || tx_h != image.height()) {
+ img = img.scaled(tx_w, tx_h);
+ }
+ }
+
+ GLuint id = bindTexture(context, key, img);
if (id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(image);