summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgltexturepool.cpp
diff options
context:
space:
mode:
authorJani Hautakangas <jani.hautakangas@nokia.com>2011-05-10 20:41:09 (GMT)
committerJani Hautakangas <jani.hautakangas@nokia.com>2011-06-09 10:31:54 (GMT)
commit489baff3d49f7acce8d36dd98d27885ca207d6e7 (patch)
treef9b7a0decd67048b52c0513b7665ccd46135a8ce /src/opengl/qgltexturepool.cpp
parent7b0762c17f9899e68c0f67480a81b25c6f0c7dda (diff)
downloadQt-489baff3d49f7acce8d36dd98d27885ca207d6e7.zip
Qt-489baff3d49f7acce8d36dd98d27885ca207d6e7.tar.gz
Qt-489baff3d49f7acce8d36dd98d27885ca207d6e7.tar.bz2
Simplify texture pooling logic in GL graphics system.
Remove ugly TemporarilyCachedBindOption and use QGLTexture objects as texture pool entries instead of QGLPixmapData. Make texture pooling totally Symbian specific, remove VG like texture pooling code and use common texture binding path which is used on other platforms also on Symbian. QGLPixmapData should be only used to bind SgImage based textures (will be implemented by another commit). Task-number: QTBUG-19180 Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/opengl/qgltexturepool.cpp')
-rw-r--r--src/opengl/qgltexturepool.cpp136
1 files changed, 66 insertions, 70 deletions
diff --git a/src/opengl/qgltexturepool.cpp b/src/opengl/qgltexturepool.cpp
index d809328..9ad66f2 100644
--- a/src/opengl/qgltexturepool.cpp
+++ b/src/opengl/qgltexturepool.cpp
@@ -41,6 +41,7 @@
#include "qgltexturepool_p.h"
#include "qpixmapdata_gl_p.h"
+#include "qgl_p.h"
QT_BEGIN_NAMESPACE
@@ -53,8 +54,8 @@ class QGLTexturePoolPrivate
public:
QGLTexturePoolPrivate() : lruFirst(0), lruLast(0) {}
- QGLPixmapData *lruFirst;
- QGLPixmapData *lruLast;
+ QGLTexture *lruFirst;
+ QGLTexture *lruLast;
};
QGLTexturePool::QGLTexturePool()
@@ -73,36 +74,36 @@ QGLTexturePool *QGLTexturePool::instance()
return qt_gl_texture_pool;
}
-GLuint QGLTexturePool::createTextureForPixmap(GLenum target,
+GLuint QGLTexturePool::createTexture(GLenum target,
GLint level,
GLint internalformat,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
- QGLPixmapData *data)
+ QGLTexture *texture)
{
- GLuint texture;
- glGenTextures(1, &texture);
- glBindTexture(target, texture);
+ GLuint tex;
+ glGenTextures(1, &tex);
+ glBindTexture(target, tex);
do {
glTexImage2D(target, level, internalformat, width, height, 0, format, type, 0);
GLenum error = glGetError();
if (error == GL_NO_ERROR) {
- if (data)
- moveToHeadOfLRU(data);
- return texture;
+ if (texture)
+ moveToHeadOfLRU(texture);
+ return tex;
} else if (error != GL_OUT_OF_MEMORY) {
qWarning("QGLTexturePool: cannot create temporary texture because of invalid params");
return 0;
}
- } while (reclaimSpace(internalformat, width, height, format, type, data));
- qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d pixmap",
+ } while (reclaimSpace(internalformat, width, height, format, type, texture));
+ qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture",
width, height);
return 0;
}
-bool QGLTexturePool::createPermanentTexture(GLuint texture,
+bool QGLTexturePool::createPermanentTexture(GLuint tex,
GLenum target,
GLint level,
GLint internalformat,
@@ -112,7 +113,7 @@ bool QGLTexturePool::createPermanentTexture(GLuint texture,
GLenum type,
const GLvoid *data)
{
- glBindTexture(target, texture);
+ glBindTexture(target, tex);
do {
glTexImage2D(target, level, internalformat, width, height, 0, format, type, data);
@@ -124,32 +125,21 @@ bool QGLTexturePool::createPermanentTexture(GLuint texture,
return false;
}
} while (reclaimSpace(internalformat, width, height, format, type, 0));
- qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d pixmap",
+ qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture",
width, height);
return 0;
}
-void QGLTexturePool::releaseTexture(QGLPixmapData *data, GLuint texture)
+void QGLTexturePool::useTexture(QGLTexture *texture)
{
- // Very simple strategy at the moment: just destroy the texture.
- if (data)
- removeFromLRU(data);
-
- QGLWidget *shareWidget = qt_gl_share_widget();
- if (shareWidget) {
- QGLShareContextScope ctx(shareWidget->context());
- glDeleteTextures(1, &texture);
- }
-}
-
-void QGLTexturePool::useTexture(QGLPixmapData *data)
-{
- moveToHeadOfLRU(data);
+ moveToHeadOfLRU(texture);
+ texture->inTexturePool = true;
}
-void QGLTexturePool::detachTexture(QGLPixmapData *data)
+void QGLTexturePool::detachTexture(QGLTexture *texture)
{
- removeFromLRU(data);
+ removeFromLRU(texture);
+ texture->inTexturePool = false;
}
bool QGLTexturePool::reclaimSpace(GLint internalformat,
@@ -157,7 +147,7 @@ bool QGLTexturePool::reclaimSpace(GLint internalformat,
GLsizei height,
GLenum format,
GLenum type,
- QGLPixmapData *data)
+ QGLTexture *texture)
{
Q_UNUSED(internalformat); // For future use in picking the best texture to eject.
Q_UNUSED(width);
@@ -167,19 +157,22 @@ bool QGLTexturePool::reclaimSpace(GLint internalformat,
bool succeeded = false;
bool wasInLRU = false;
- if (data) {
- wasInLRU = data->inLRU;
- moveToHeadOfLRU(data);
+ if (texture) {
+ wasInLRU = texture->inLRU;
+ moveToHeadOfLRU(texture);
}
- QGLPixmapData *lrudata = pixmapLRU();
- if (lrudata && lrudata != data) {
- lrudata->reclaimTexture();
+ QGLTexture *lrutexture = textureLRU();
+ if (lrutexture && lrutexture != texture) {
+ if (lrutexture->boundPixmap)
+ lrutexture->boundPixmap->reclaimTexture();
+ else
+ QGLTextureCache::instance()->remove(lrutexture->boundKey);
succeeded = true;
}
- if (data && !wasInLRU)
- removeFromLRU(data);
+ if (texture && !wasInLRU)
+ removeFromLRU(texture);
return succeeded;
}
@@ -187,55 +180,58 @@ bool QGLTexturePool::reclaimSpace(GLint internalformat,
void QGLTexturePool::hibernate()
{
Q_D(QGLTexturePool);
- QGLPixmapData *pd = d->lruLast;
- while (pd) {
- QGLPixmapData *prevLRU = pd->prevLRU;
- pd->inTexturePool = false;
- pd->inLRU = false;
- pd->nextLRU = 0;
- pd->prevLRU = 0;
- pd->hibernate();
- pd = prevLRU;
+ QGLTexture *texture = d->lruLast;
+ while (texture) {
+ QGLTexture *prevLRU = texture->prevLRU;
+ texture->inTexturePool = false;
+ texture->inLRU = false;
+ texture->nextLRU = 0;
+ texture->prevLRU = 0;
+ if (texture->boundPixmap)
+ texture->boundPixmap->hibernate();
+ else
+ QGLTextureCache::instance()->remove(texture->boundKey);
+ texture = prevLRU;
}
d->lruFirst = 0;
d->lruLast = 0;
}
-void QGLTexturePool::moveToHeadOfLRU(QGLPixmapData *data)
+void QGLTexturePool::moveToHeadOfLRU(QGLTexture *texture)
{
Q_D(QGLTexturePool);
- if (data->inLRU) {
- if (!data->prevLRU)
+ if (texture->inLRU) {
+ if (!texture->prevLRU)
return; // Already at the head of the list.
- removeFromLRU(data);
+ removeFromLRU(texture);
}
- data->inLRU = true;
- data->nextLRU = d->lruFirst;
- data->prevLRU = 0;
+ texture->inLRU = true;
+ texture->nextLRU = d->lruFirst;
+ texture->prevLRU = 0;
if (d->lruFirst)
- d->lruFirst->prevLRU = data;
+ d->lruFirst->prevLRU = texture;
else
- d->lruLast = data;
- d->lruFirst = data;
+ d->lruLast = texture;
+ d->lruFirst = texture;
}
-void QGLTexturePool::removeFromLRU(QGLPixmapData *data)
+void QGLTexturePool::removeFromLRU(QGLTexture *texture)
{
Q_D(QGLTexturePool);
- if (!data->inLRU)
+ if (!texture->inLRU)
return;
- if (data->nextLRU)
- data->nextLRU->prevLRU = data->prevLRU;
+ if (texture->nextLRU)
+ texture->nextLRU->prevLRU = texture->prevLRU;
else
- d->lruLast = data->prevLRU;
- if (data->prevLRU)
- data->prevLRU->nextLRU = data->nextLRU;
+ d->lruLast = texture->prevLRU;
+ if (texture->prevLRU)
+ texture->prevLRU->nextLRU = texture->nextLRU;
else
- d->lruFirst = data->nextLRU;
- data->inLRU = false;
+ d->lruFirst = texture->nextLRU;
+ texture->inLRU = false;
}
-QGLPixmapData *QGLTexturePool::pixmapLRU()
+QGLTexture *QGLTexturePool::textureLRU()
{
Q_D(QGLTexturePool);
return d->lruLast;