From 1e8de50674f5b33a50c45224b7e07b3f974f6ab0 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 4 Mar 2014 15:06:36 +0100 Subject: Avoid using direct OpenGL calls in gui and widgets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5d88a2e204ca23e178a4e3044b9cb13392c3e763 Reviewed-by: Jørgen Lind --- src/gui/opengl/qopenglgradientcache.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/gui/opengl/qopenglgradientcache.cpp') diff --git a/src/gui/opengl/qopenglgradientcache.cpp b/src/gui/opengl/qopenglgradientcache.cpp index 9c312808a25..91b4d084749 100644 --- a/src/gui/opengl/qopenglgradientcache.cpp +++ b/src/gui/opengl/qopenglgradientcache.cpp @@ -43,6 +43,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -91,9 +92,10 @@ void QOpenGL2GradientCache::cleanCache() { QMutexLocker lock(&m_mutex); QOpenGLGradientColorTableHash::const_iterator it = cache.constBegin(); + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); for (; it != cache.constEnd(); ++it) { const CacheInfo &cache_info = it.value(); - glDeleteTextures(1, &cache_info.texId); + funcs->glDeleteTextures(1, &cache_info.texId); } cache.clear(); } @@ -129,6 +131,7 @@ GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity) { + QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); if (cache.size() == maxCacheSize()) { int elem_to_remove = qrand() % maxCacheSize(); quint64 key = cache.keys()[elem_to_remove]; @@ -136,7 +139,7 @@ GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient // need to call glDeleteTextures on each removed cache entry: QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(key); do { - glDeleteTextures(1, &it.value().texId); + funcs->glDeleteTextures(1, &it.value().texId); } while (++it != cache.constEnd() && it.key() == key); cache.remove(key); // may remove more than 1, but OK } @@ -144,10 +147,10 @@ GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode()); uint buffer[1024]; generateGradientColorTable(gradient, buffer, paletteSize(), opacity); - glGenTextures(1, &cache_entry.texId); - glBindTexture(GL_TEXTURE_2D, cache_entry.texId); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, paletteSize(), 1, - 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + funcs->glGenTextures(1, &cache_entry.texId); + funcs->glBindTexture(GL_TEXTURE_2D, cache_entry.texId); + funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, paletteSize(), 1, + 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); return cache.insert(hash_val, cache_entry).value().texId; } -- cgit v1.2.3