Qt 4.8
Public Functions | Properties | List of all members
QGLFramebufferObjectPool Class Reference

The QGLFramebufferObject class provides a pool of framebuffer objects for offscreen rendering purposes. More...

#include <qpixmapdata_gl_p.h>

Public Functions

QGLFramebufferObjectacquire (const QSize &size, const QGLFramebufferObjectFormat &format, bool strictSize=false)
 
void release (QGLFramebufferObject *fbo)
 

Properties

QList< QGLFramebufferObject * > m_fbos
 

Detailed Description

The QGLFramebufferObject class provides a pool of framebuffer objects for offscreen rendering purposes.

Since
4.6

When requesting an FBO of a given size and format, an FBO of the same format and a size at least as big as the requested size will be returned.

Warning
This function is not part of the public interface.

Definition at line 79 of file qpixmapdata_gl_p.h.

Functions

◆ acquire()

QGLFramebufferObject * QGLFramebufferObjectPool::acquire ( const QSize size,
const QGLFramebufferObjectFormat format,
bool  strictSize = false 
)

Definition at line 99 of file qpixmapdata_gl.cpp.

Referenced by QGLWindowSurface::flush(), and QGLPixmapData::paintEngine().

100 {
101  QGLFramebufferObject *chosen = 0;
102  QGLFramebufferObject *candidate = 0;
103  for (int i = 0; !chosen && i < m_fbos.size(); ++i) {
104  QGLFramebufferObject *fbo = m_fbos.at(i);
105 
106  if (strictSize) {
107  if (fbo->size() == requestSize && fbo->format() == requestFormat) {
108  chosen = fbo;
109  break;
110  } else {
111  continue;
112  }
113  }
114 
115  if (fbo->format() == requestFormat) {
116  // choose the fbo with a matching format and the closest size
117  if (!candidate || areaDiff(requestSize, candidate) > areaDiff(requestSize, fbo))
118  candidate = fbo;
119  }
120 
121  if (candidate) {
122  m_fbos.removeOne(candidate);
123 
124  const QSize fboSize = candidate->size();
125  QSize sz = fboSize;
126 
127  if (sz.width() < requestSize.width())
128  sz.setWidth(qMax(requestSize.width(), qRound(sz.width() * 1.5)));
129  if (sz.height() < requestSize.height())
130  sz.setHeight(qMax(requestSize.height(), qRound(sz.height() * 1.5)));
131 
132  // wasting too much space?
133  if (sz.width() * sz.height() > requestSize.width() * requestSize.height() * 4)
134  sz = requestSize;
135 
136  if (sz != fboSize) {
137  delete candidate;
138  candidate = new QGLFramebufferObject(maybeRoundToNextPowerOfTwo(sz), requestFormat);
139  }
140 
141  chosen = candidate;
142  }
143  }
144 
145  if (!chosen) {
146  if (strictSize)
147  chosen = new QGLFramebufferObject(requestSize, requestFormat);
148  else
149  chosen = new QGLFramebufferObject(maybeRoundToNextPowerOfTwo(requestSize), requestFormat);
150  }
151 
152  if (!chosen->isValid()) {
153  delete chosen;
154  chosen = 0;
155  }
156 
157  return chosen;
158 }
QSize size() const
Returns the size of the texture attached to this framebuffer object.
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void setWidth(int w)
Sets the width to the given width.
Definition: qsize.h:132
bool removeOne(const T &t)
Removes the first occurrence of value in the list and returns true on success; otherwise returns fals...
Definition: qlist.h:796
int width() const
Returns the width.
Definition: qsize.h:126
QList< QGLFramebufferObject * > m_fbos
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
int height() const
Returns the height.
Definition: qsize.h:129
static QSize maybeRoundToNextPowerOfTwo(const QSize &sz)
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static int areaDiff(const QSize &size, const QGLFramebufferObject *fbo)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ release()

void QGLFramebufferObjectPool::release ( QGLFramebufferObject fbo)

Definition at line 160 of file qpixmapdata_gl.cpp.

Referenced by QGLPixmapGLPaintDevice::endPaint(), and QGLWindowSurface::flush().

161 {
162  if (fbo)
163  m_fbos << fbo;
164 }
QList< QGLFramebufferObject * > m_fbos

Properties

◆ m_fbos

QList<QGLFramebufferObject *> QGLFramebufferObjectPool::m_fbos
private

Definition at line 86 of file qpixmapdata_gl_p.h.

Referenced by acquire(), and release().


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