Qt 4.8
Public Functions | Static Public Functions | Protected Functions | Properties | List of all members
QGLTexturePool Class Reference

#include <qgltexturepool_p.h>

Public Functions

bool createPermanentTexture (GLuint texture, GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data)
 
GLuint createTexture (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, QGLTexture *texture)
 
void detachTexture (QGLTexture *texture)
 
void hibernate ()
 
 QGLTexturePool ()
 
bool reclaimSpace (GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, QGLTexture *data)
 
void useTexture (QGLTexture *texture)
 
virtual ~QGLTexturePool ()
 

Static Public Functions

static QGLTexturePoolinstance ()
 

Protected Functions

void moveToHeadOfLRU (QGLTexture *texture)
 
void removeFromLRU (QGLTexture *texture)
 
QGLTexturetextureLRU ()
 

Properties

QScopedPointer< QGLTexturePoolPrivated_ptr
 

Detailed Description

Definition at line 64 of file qgltexturepool_p.h.

Constructors and Destructors

◆ QGLTexturePool()

QGLTexturePool::QGLTexturePool ( )

Definition at line 61 of file qgltexturepool.cpp.

Referenced by instance().

63 {
64 }
QScopedPointer< QGLTexturePoolPrivate > d_ptr

◆ ~QGLTexturePool()

QGLTexturePool::~QGLTexturePool ( )
virtual

Definition at line 66 of file qgltexturepool.cpp.

67 {
68 }

Functions

◆ createPermanentTexture()

bool QGLTexturePool::createPermanentTexture ( GLuint  texture,
GLenum  target,
GLint  level,
GLint  internalformat,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
const GLvoid *  data 
)

Definition at line 106 of file qgltexturepool.cpp.

115 {
116  glBindTexture(target, tex);
117  do {
118  glTexImage2D(target, level, internalformat, width, height, 0, format, type, data);
119 
120  GLenum error = glGetError();
121  if (error == GL_NO_ERROR) {
122  return true;
123  } else if (error != GL_OUT_OF_MEMORY) {
124  qWarning("QGLTexturePool: cannot create permanent texture because of invalid params");
125  return false;
126  }
127  } while (reclaimSpace(internalformat, width, height, format, type, 0));
128  qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture",
129  width, height);
130  return 0;
131 }
#define GL_OUT_OF_MEMORY
int type
Definition: qmetatype.cpp:239
#define error(msg)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
bool reclaimSpace(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, QGLTexture *data)
unsigned int GLenum
Definition: main.cpp:50
#define GL_NO_ERROR

◆ createTexture()

GLuint QGLTexturePool::createTexture ( GLenum  target,
GLint  level,
GLint  internalformat,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
QGLTexture texture 
)

Definition at line 77 of file qgltexturepool.cpp.

85 {
86  GLuint tex;
87  glGenTextures(1, &tex);
88  glBindTexture(target, tex);
89  do {
90  glTexImage2D(target, level, internalformat, width, height, 0, format, type, 0);
91  GLenum error = glGetError();
92  if (error == GL_NO_ERROR) {
93  if (texture)
94  moveToHeadOfLRU(texture);
95  return tex;
96  } else if (error != GL_OUT_OF_MEMORY) {
97  qWarning("QGLTexturePool: cannot create temporary texture because of invalid params");
98  return 0;
99  }
100  } while (reclaimSpace(internalformat, width, height, format, type, texture));
101  qWarning("QGLTexturePool: cannot reclaim sufficient space for a %dx%d texture",
102  width, height);
103  return 0;
104 }
#define GL_OUT_OF_MEMORY
int type
Definition: qmetatype.cpp:239
void moveToHeadOfLRU(QGLTexture *texture)
#define error(msg)
Q_CORE_EXPORT void qWarning(const char *,...)
bool reclaimSpace(GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, QGLTexture *data)
unsigned int GLenum
Definition: main.cpp:50
#define GL_NO_ERROR

◆ detachTexture()

void QGLTexturePool::detachTexture ( QGLTexture texture)

Definition at line 139 of file qgltexturepool.cpp.

140 {
141  removeFromLRU(texture);
142  texture->inTexturePool = false;
143 }
void removeFromLRU(QGLTexture *texture)

◆ hibernate()

void QGLTexturePool::hibernate ( )

Definition at line 180 of file qgltexturepool.cpp.

Referenced by QGLGraphicsSystem::createWindowSurface().

181 {
183  QGLTexture *texture = d->lruLast;
184  while (texture) {
185  QGLTexture *prevLRU = texture->prevLRU;
186  texture->inTexturePool = false;
187  texture->inLRU = false;
188  texture->nextLRU = 0;
189  texture->prevLRU = 0;
190  if (texture->boundPixmap)
191  texture->boundPixmap->hibernate();
192  else
193  QGLTextureCache::instance()->remove(texture->boundKey);
194  texture = prevLRU;
195  }
196  d->lruFirst = 0;
197  d->lruLast = 0;
198 }
double d
Definition: qnumeric_p.h:62
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
#define Q_D(Class)
Definition: qglobal.h:2482
QPixmapData * boundPixmap
Definition: qgl_p.h:614
void remove(qint64 key)
Definition: qgl.cpp:1929

◆ instance()

QGLTexturePool * QGLTexturePool::instance ( )
static

Definition at line 70 of file qgltexturepool.cpp.

Referenced by QGLGraphicsSystem::createWindowSurface().

71 {
72  if (!qt_gl_texture_pool)
74  return qt_gl_texture_pool;
75 }
static QGLTexturePool * qt_gl_texture_pool

◆ moveToHeadOfLRU()

void QGLTexturePool::moveToHeadOfLRU ( QGLTexture texture)
protected

Definition at line 200 of file qgltexturepool.cpp.

Referenced by createTexture(), reclaimSpace(), and useTexture().

201 {
203  if (texture->inLRU) {
204  if (!texture->prevLRU)
205  return; // Already at the head of the list.
206  removeFromLRU(texture);
207  }
208  texture->inLRU = true;
209  texture->nextLRU = d->lruFirst;
210  texture->prevLRU = 0;
211  if (d->lruFirst)
212  d->lruFirst->prevLRU = texture;
213  else
214  d->lruLast = texture;
215  d->lruFirst = texture;
216 }
double d
Definition: qnumeric_p.h:62
void removeFromLRU(QGLTexture *texture)
#define Q_D(Class)
Definition: qglobal.h:2482

◆ reclaimSpace()

bool QGLTexturePool::reclaimSpace ( GLint  internalformat,
GLsizei  width,
GLsizei  height,
GLenum  format,
GLenum  type,
QGLTexture data 
)

Definition at line 145 of file qgltexturepool.cpp.

Referenced by createPermanentTexture(), and createTexture().

151 {
152  Q_UNUSED(internalformat); // For future use in picking the best texture to eject.
153  Q_UNUSED(width);
154  Q_UNUSED(height);
155  Q_UNUSED(format);
156  Q_UNUSED(type);
157 
158  bool succeeded = false;
159  bool wasInLRU = false;
160  if (texture) {
161  wasInLRU = texture->inLRU;
162  moveToHeadOfLRU(texture);
163  }
164 
165  QGLTexture *lrutexture = textureLRU();
166  if (lrutexture && lrutexture != texture) {
167  if (lrutexture->boundPixmap)
168  lrutexture->boundPixmap->reclaimTexture();
169  else
170  QGLTextureCache::instance()->remove(lrutexture->boundKey);
171  succeeded = true;
172  }
173 
174  if (texture && !wasInLRU)
175  removeFromLRU(texture);
176 
177  return succeeded;
178 }
int type
Definition: qmetatype.cpp:239
void moveToHeadOfLRU(QGLTexture *texture)
static QGLTextureCache * instance()
Definition: qgl.cpp:1995
void removeFromLRU(QGLTexture *texture)
QPixmapData * boundPixmap
Definition: qgl_p.h:614
QGLTexture * textureLRU()
void remove(qint64 key)
Definition: qgl.cpp:1929
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ removeFromLRU()

void QGLTexturePool::removeFromLRU ( QGLTexture texture)
protected

Definition at line 218 of file qgltexturepool.cpp.

Referenced by detachTexture(), moveToHeadOfLRU(), and reclaimSpace().

219 {
221  if (!texture->inLRU)
222  return;
223  if (texture->nextLRU)
224  texture->nextLRU->prevLRU = texture->prevLRU;
225  else
226  d->lruLast = texture->prevLRU;
227  if (texture->prevLRU)
228  texture->prevLRU->nextLRU = texture->nextLRU;
229  else
230  d->lruFirst = texture->nextLRU;
231  texture->inLRU = false;
232 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ textureLRU()

QGLTexture * QGLTexturePool::textureLRU ( )
protected

Definition at line 234 of file qgltexturepool.cpp.

Referenced by reclaimSpace().

235 {
237  return d->lruLast;
238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482

◆ useTexture()

void QGLTexturePool::useTexture ( QGLTexture texture)

Definition at line 133 of file qgltexturepool.cpp.

134 {
135  moveToHeadOfLRU(texture);
136  texture->inTexturePool = true;
137 }
void moveToHeadOfLRU(QGLTexture *texture)

Properties

◆ d_ptr

QScopedPointer<QGLTexturePoolPrivate> QGLTexturePool::d_ptr
private

Definition at line 136 of file qgltexturepool_p.h.


The documentation for this class was generated from the following files: