diff options
| author | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-02-06 14:21:16 +0100 |
|---|---|---|
| committer | Frederik Gladhorn <frederik.gladhorn@digia.com> | 2014-02-07 13:07:25 +0100 |
| commit | a1fe728fa5bd6cb9e50cf317a58efcf4eea4de2c (patch) | |
| tree | 0798ae897d111147238544826c79243b6f9a48a4 /src/gui/opengl/qopengltexturecache.cpp | |
| parent | 57fe9bd2c6a361cf979d17d962abed5db17a1457 (diff) | |
| parent | 65bd80ebfc1be81a196a861ade40ff874a3554f0 (diff) | |
Merge remote-tracking branch 'origin/stable' into dev
Conflicts:
src/gui/kernel/qguiapplication.cpp
src/plugins/platforms/android/androidjnimain.cpp
src/plugins/platforms/android/qandroidplatformintegration.cpp
src/plugins/platforms/android/qandroidplatformintegration.h
src/plugins/platforms/android/qandroidplatformopenglcontext.cpp
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm
src/plugins/platforms/xcb/qxcbconnection_xi2.cpp
src/sql/doc/src/sql-driver.qdoc
src/widgets/widgets/qtoolbararealayout.cpp
Change-Id: Ifd7e58760c3cb6bd8a7d1dd32ef83b7ec190d41e
Diffstat (limited to 'src/gui/opengl/qopengltexturecache.cpp')
| -rw-r--r-- | src/gui/opengl/qopengltexturecache.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp index 4238f63cd87..750264935b2 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); |
