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

The QGLPixelBuffer class encapsulates an OpenGL pbuffer. More...

#include <qglpixelbuffer.h>

Inheritance diagram for QGLPixelBuffer:
QPaintDevice

Public Functions

GLuint bindTexture (const QImage &image, GLenum target=GL_TEXTURE_2D)
 Generates and binds a 2D GL texture to the current context, based on image. More...
 
GLuint bindTexture (const QPixmap &pixmap, GLenum target=GL_TEXTURE_2D)
 Generates and binds a 2D GL texture based on pixmap. More...
 
GLuint bindTexture (const QString &fileName)
 Reads the DirectDrawSurface (DDS) compressed file fileName and generates a 2D GL texture from it. More...
 
bool bindToDynamicTexture (GLuint texture)
 Generates and binds a 2D GL texture that is the same size as the pbuffer, and returns the texture's ID. More...
 
void deleteTexture (GLuint texture_id)
 Removes the texture identified by texture_id from the texture cache. More...
 
bool doneCurrent ()
 Makes no context the current OpenGL context. More...
 
void drawTexture (const QRectF &target, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. More...
 
void drawTexture (const QPointF &point, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D)
 Draws the given texture, textureId, at the given point in OpenGL model space. More...
 
QGLFormat format () const
 Returns the format of the pbuffer. More...
 
GLuint generateDynamicTexture () const
 
Qt::HANDLE handle () const
 Returns the native pbuffer handle. More...
 
bool isValid () const
 Returns true if this pbuffer is valid; otherwise returns false. More...
 
bool makeCurrent ()
 Makes this pbuffer the current OpenGL rendering context. More...
 
QPaintEnginepaintEngine () const
 Reimplemented Function More...
 
 QGLPixelBuffer (const QSize &size, const QGLFormat &format=QGLFormat::defaultFormat(), QGLWidget *shareWidget=0)
 Constructs an OpenGL pbuffer of the given size. More...
 
 QGLPixelBuffer (int width, int height, const QGLFormat &format=QGLFormat::defaultFormat(), QGLWidget *shareWidget=0)
 Constructs an OpenGL pbuffer with the width and height. More...
 
void releaseFromDynamicTexture ()
 Releases the pbuffer from any previously bound texture. More...
 
QSize size () const
 Returns the size of the pbuffer. More...
 
QImage toImage () const
 Returns the contents of the pbuffer as a QImage. More...
 
void updateDynamicTexture (GLuint texture_id) const
 Copies the pbuffer contents into the texture specified with texture_id. More...
 
virtual ~QGLPixelBuffer ()
 Destroys the pbuffer and frees any allocated resources. More...
 
- Public Functions inherited from QPaintDevice
int colorCount () const
 
int depth () const
 
virtual HDC getDC () const
 
int height () const
 
int heightMM () const
 
int logicalDpiX () const
 
int logicalDpiY () const
 
QT_DEPRECATED int numColors () const
 
bool paintingActive () const
 
int physicalDpiX () const
 
int physicalDpiY () const
 
virtual void releaseDC (HDC hdc) const
 
int width () const
 
int widthMM () const
 
virtual ~QPaintDevice ()
 

Static Public Functions

static bool hasOpenGLPbuffers ()
 Returns true if the OpenGL pbuffer extension is present on this system; otherwise returns false. More...
 
- Static Public Functions inherited from QPaintDevice
static QWSDisplayqwsDisplay ()
 

Protected Functions

int devType () const
 
int metric (PaintDeviceMetric metric) const
 Reimplemented Function More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

QScopedPointer< QGLPixelBufferPrivated_ptr
 

Friends

class QGLContextPrivate
 
class QGLDrawable
 
class QGLPaintDevice
 
class QGLPBufferGLPaintDevice
 
class QGLWindowSurface
 

Additional Inherited Members

- Public Types inherited from QPaintDevice
enum  PaintDeviceMetric {
  PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM,
  PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY,
  PdmPhysicalDpiX, PdmPhysicalDpiY
}
 
- Protected Variables inherited from QPaintDevice
ushort painters
 

Detailed Description

The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

Since
4.1

Rendering into a pbuffer is normally done using full hardware acceleration. This can be significantly faster than rendering into a QPixmap.

There are three approaches to using this class:

  1. We can draw into the pbuffer and convert it to a QImage using toImage(). This is normally much faster than calling QGLWidget::renderPixmap().

  2. We can draw into the pbuffer and copy the contents into an OpenGL texture using updateDynamicTexture(). This allows us to create dynamic textures and works on all systems with pbuffer support.

  3. On systems that support it, we can bind the pbuffer to an OpenGL texture. The texture is then updated automatically when the pbuffer contents change, eliminating the need for additional copy operations. This is supported only on Windows and Mac OS X systems that provide the render_texture extension. Note that under Windows, a multi-sampled pbuffer can't be used in conjunction with the render_texture extension. If a multi-sampled pbuffer is requested under Windows, the render_texture extension is turned off for that pbuffer.

Threading

As of Qt 4.8, it's possible to render into a QGLPixelBuffer using a QPainter in a separate thread. Note that OpenGL 2.0 or OpenGL ES 2.0 is required for this to work. Also, under X11, it's necessary to set the Qt::AA_X11InitThreads application attribute.

Pbuffers are provided by the OpenGL pbuffer extension; call hasOpenGLPbuffer() to find out if the system provides pbuffers.

See also
{opengl/pbuffers}{Pbuffers Example}

Definition at line 56 of file qglpixelbuffer.h.

Constructors and Destructors

◆ QGLPixelBuffer() [1/2]

QGLPixelBuffer::QGLPixelBuffer ( const QSize size,
const QGLFormat format = QGLFormat::defaultFormat(),
QGLWidget shareWidget = 0 
)

Constructs an OpenGL pbuffer of the given size.

If no format is specified, the default format is used. If the shareWidget parameter points to a valid QGLWidget, the pbuffer will share its context with shareWidget.

If you intend to bind this pbuffer as a dynamic texture, the width and height components of size must be powers of two (e.g., 512 x 128).

See also
size(), format()

Definition at line 184 of file qglpixelbuffer.cpp.

185  : d_ptr(new QGLPixelBufferPrivate(this))
186 {
188  d->common_init(size, format, shareWidget);
189 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
QScopedPointer< QGLPixelBufferPrivate > d_ptr

◆ QGLPixelBuffer() [2/2]

QGLPixelBuffer::QGLPixelBuffer ( int  width,
int  height,
const QGLFormat format = QGLFormat::defaultFormat(),
QGLWidget shareWidget = 0 
)

Constructs an OpenGL pbuffer with the width and height.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

If no format is specified, the default format is used. If the shareWidget parameter points to a valid QGLWidget, the pbuffer will share its context with shareWidget.

If you intend to bind this pbuffer as a dynamic texture, the width and height components of size must be powers of two (e.g., 512 x 128).

See also
size(), format()

Definition at line 209 of file qglpixelbuffer.cpp.

210  : d_ptr(new QGLPixelBufferPrivate(this))
211 {
213  d->common_init(QSize(width, height), format, shareWidget);
214 }
double d
Definition: qnumeric_p.h:62
int height() const
Definition: qpaintdevice.h:92
#define Q_D(Class)
Definition: qglobal.h:2482
int width() const
Definition: qpaintdevice.h:91
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
QScopedPointer< QGLPixelBufferPrivate > d_ptr
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ ~QGLPixelBuffer()

QGLPixelBuffer::~QGLPixelBuffer ( )
virtual

Destroys the pbuffer and frees any allocated resources.

Definition at line 224 of file qglpixelbuffer.cpp.

225 {
227 
228  // defined in qpaintengine_opengl.cpp
229  QGLContext *current = const_cast<QGLContext *>(QGLContext::currentContext());
230  if (current != d->qctx)
231  makeCurrent();
232  qgl_cleanup_glyph_cache(d->qctx);
233  d->cleanup();
234  delete d->qctx;
235  if (current && current != d->qctx)
236  current->makeCurrent();
237 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
void qgl_cleanup_glyph_cache(QGLContext *)
virtual void makeCurrent()
Makes this context the current OpenGL rendering context.
Definition: qgl_egl.cpp:213

Functions

◆ bindTexture() [1/3]

GLuint QGLPixelBuffer::bindTexture ( const QImage image,
GLenum  target = GL_TEXTURE_2D 
)

Generates and binds a 2D GL texture to the current context, based on image.

The generated texture id is returned and can be used in later glBindTexture() calls.

The target parameter specifies the texture target.

Equivalent to calling QGLContext::bindTexture().

See also
deleteTexture()

Definition at line 509 of file qglpixelbuffer.cpp.

Referenced by bindTexture(), and QGLPixmapFilterBase::~QGLPixmapFilterBase().

510 {
512 #ifndef QT_OPENGL_ES
513  return d->qctx->bindTexture(image, target, GLint(GL_RGBA8));
514 #else
515  return d->qctx->bindTexture(image, target, GL_RGBA);
516 #endif
517 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
typedef GLint
Definition: glfunctions.h:67
#define GL_RGBA

◆ bindTexture() [2/3]

GLuint QGLPixelBuffer::bindTexture ( const QPixmap pixmap,
GLenum  target = GL_TEXTURE_2D 
)

Generates and binds a 2D GL texture based on pixmap.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Equivalent to calling QGLContext::bindTexture().

See also
deleteTexture()

Definition at line 539 of file qglpixelbuffer.cpp.

540 {
542 #ifndef QT_OPENGL_ES
543  return d->qctx->bindTexture(pixmap, target, GLint(GL_RGBA8));
544 #else
545  return d->qctx->bindTexture(pixmap, target, GL_RGBA);
546 #endif
547 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
typedef GLint
Definition: glfunctions.h:67
#define GL_RGBA

◆ bindTexture() [3/3]

GLuint QGLPixelBuffer::bindTexture ( const QString fileName)

Reads the DirectDrawSurface (DDS) compressed file fileName and generates a 2D GL texture from it.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Equivalent to calling QGLContext::bindTexture().

See also
deleteTexture()

Definition at line 570 of file qglpixelbuffer.cpp.

571 {
573  return d->qctx->bindTexture(fileName);
574 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ bindToDynamicTexture()

bool QGLPixelBuffer::bindToDynamicTexture ( GLuint  texture_id)

Generates and binds a 2D GL texture that is the same size as the pbuffer, and returns the texture's ID.

This can be used in conjunction with bindToDynamicTexture() and updateDynamicTexture().

See also
size()

Binds the texture specified by texture_id to this pbuffer.

Returns true on success; otherwise returns false.

The texture must be of the same size and format as the pbuffer.

To unbind the texture, call releaseFromDynamicTexture(). While the texture is bound, it is updated automatically when the pbuffer contents change, eliminating the need for additional copy operations.

Example:

QGLPixelBuffer pbuffer(...);
...
pbuffer.makeCurrent();
GLuint dynamicTexture = pbuffer.generateDynamicTexture();
pbuffer.bindToDynamicTexture(dynamicTexture);
...
pbuffer.releaseFromDynamicTexture();
Warning
This function uses the {render_texture} extension, which is currently not supported under X11. An alternative that works on all systems (including X11) is to manually copy the pbuffer contents to a texture using updateDynamicTexture().
For the bindToDynamicTexture() call to succeed on the Mac OS X, the pbuffer needs a shared context, i.e. the QGLPixelBuffer must be created with a share widget.
See also
generateDynamicTexture(), releaseFromDynamicTexture()

Definition at line 160 of file qglpixelbuffer_egl.cpp.

Referenced by nearest_gl_texture_size(), and qt_format_to_attrib_list().

161 {
162 #if QGL_RENDER_TEXTURE
164  if (d->invalid || d->textureFormat == EGL_NONE || !d->ctx)
165  return false;
166  glBindTexture(GL_TEXTURE_2D, texture_id);
167  return eglBindTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER);
168 #else
169  Q_UNUSED(texture_id);
170  return false;
171 #endif
172 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_TEXTURE_2D
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
#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

◆ deleteTexture()

void QGLPixelBuffer::deleteTexture ( GLuint  texture_id)

Removes the texture identified by texture_id from the texture cache.

Equivalent to calling QGLContext::deleteTexture().

Definition at line 581 of file qglpixelbuffer.cpp.

582 {
584  d->qctx->deleteTexture(texture_id);
585 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ devType()

int QGLPixelBuffer::devType ( ) const
inlineprotectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 106 of file qglpixelbuffer.h.

◆ doneCurrent()

bool QGLPixelBuffer::doneCurrent ( )

Makes no context the current OpenGL context.

Returns true on success; otherwise returns false.

Definition at line 268 of file qglpixelbuffer.cpp.

269 {
271  if (d->invalid)
272  return false;
273  d->qctx->doneCurrent();
274  return true;
275 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ drawTexture() [1/2]

void QGLPixelBuffer::drawTexture ( const QRectF target,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space.

Since
4.4

The textureTarget should be a 2D texture target.

Equivalent to the corresponding QGLContext::drawTexture().

Definition at line 608 of file qglpixelbuffer.cpp.

Referenced by drawTexture().

609 {
611  d->qctx->drawTexture(target, textureId, textureTarget);
612 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ drawTexture() [2/2]

void QGLPixelBuffer::drawTexture ( const QPointF point,
GLuint  textureId,
GLenum  textureTarget = GL_TEXTURE_2D 
)

Draws the given texture, textureId, at the given point in OpenGL model space.

Since
4.4

The textureTarget parameter should be a 2D texture target.

Equivalent to the corresponding QGLContext::drawTexture().

Definition at line 634 of file qglpixelbuffer.cpp.

635 {
637  d->qctx->drawTexture(point, textureId, textureTarget);
638 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ format()

QGLFormat QGLPixelBuffer::format ( ) const

Returns the format of the pbuffer.

The format may be different from the one that was requested.

Definition at line 653 of file qglpixelbuffer.cpp.

Referenced by QGLWindowSurface::updateGeometry().

654 {
655  Q_D(const QGLPixelBuffer);
656  return d->format;
657 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ generateDynamicTexture()

GLuint QGLPixelBuffer::generateDynamicTexture ( ) const

Definition at line 185 of file qglpixelbuffer_egl.cpp.

Referenced by doneCurrent(), and nearest_gl_texture_size().

186 {
187 #if QGL_RENDER_TEXTURE
188  Q_D(const QGLPixelBuffer);
189  GLuint texture;
190  glGenTextures(1, &texture);
191  glBindTexture(GL_TEXTURE_2D, texture);
192  if (d->textureFormat == EGL_TEXTURE_RGB)
193  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, d->req_size.width(), d->req_size.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
194  else
195  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, d->req_size.width(), d->req_size.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
196  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
197  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
198  return texture;
199 #else
200  return 0;
201 #endif
202 }
double d
Definition: qnumeric_p.h:62
#define GL_RGB
#define GL_TEXTURE_MIN_FILTER
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_TEXTURE_2D
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
#define GL_LINEAR
#define GL_UNSIGNED_BYTE
#define GL_RGBA
#define GL_TEXTURE_MAG_FILTER

◆ handle()

Qt::HANDLE QGLPixelBuffer::handle ( ) const

Returns the native pbuffer handle.

Definition at line 411 of file qglpixelbuffer.cpp.

412 {
413  Q_D(const QGLPixelBuffer);
414  if (d->invalid)
415  return 0;
416  return (Qt::HANDLE) d->pbuf;
417 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
void * HANDLE
Definition: qnamespace.h:1671

◆ hasOpenGLPbuffers()

bool QGLPixelBuffer::hasOpenGLPbuffers ( )
static

Returns true if the OpenGL pbuffer extension is present on this system; otherwise returns false.

Definition at line 204 of file qglpixelbuffer_egl.cpp.

Referenced by nearest_gl_texture_size(), and qt_format_to_attrib_list().

205 {
206  // See if we have at least 1 configuration that matches the default format.
207  EGLDisplay dpy = QEgl::display();
208  if (dpy == EGL_NO_DISPLAY)
209  return false;
210  QEglProperties configProps;
212  configProps.setDeviceType(QInternal::Pbuffer);
213  configProps.setRenderableType(QEgl::OpenGL);
214  do {
215  EGLConfig cfg = 0;
216  EGLint matching = 0;
217  if (eglChooseConfig(dpy, configProps.properties(),
218  &cfg, 1, &matching) && matching > 0)
219  return true;
220  } while (configProps.reduceConfiguration());
221  return false;
222 }
const EGLint * properties() const
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void setRenderableType(QEgl::API api)
bool reduceConfiguration()
static QGLFormat defaultFormat()
Definition: qgl.cpp:1518
void setDeviceType(int devType)
void qt_eglproperties_set_glformat(QEglProperties &eglProperties, const QGLFormat &glFormat)
Definition: qgl_egl.cpp:61

◆ isValid()

bool QGLPixelBuffer::isValid ( ) const

Returns true if this pbuffer is valid; otherwise returns false.

Definition at line 422 of file qglpixelbuffer.cpp.

Referenced by QGLWindowSurface::updateGeometry().

423 {
424  Q_D(const QGLPixelBuffer);
425  return !d->invalid;
426 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ makeCurrent()

bool QGLPixelBuffer::makeCurrent ( )

Makes this pbuffer the current OpenGL rendering context.

Returns true on success; otherwise returns false.

See also
QGLContext::makeCurrent(), doneCurrent()

Definition at line 250 of file qglpixelbuffer.cpp.

Referenced by QGLWindowSurface::flush(), QGLWindowSurface::scroll(), toImage(), QGLWindowSurface::updateGeometry(), and ~QGLPixelBuffer().

251 {
253  if (d->invalid)
254  return false;
255  d->qctx->makeCurrent();
256  return true;
257 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ metric()

int QGLPixelBuffer::metric ( PaintDeviceMetric  metric) const
protectedvirtual

Reimplemented Function

Reimplemented from QPaintDevice.

Definition at line 452 of file qglpixelbuffer.cpp.

453 {
454  Q_D(const QGLPixelBuffer);
455 
456  float dpmx = qt_defaultDpiX()*100./2.54;
457  float dpmy = qt_defaultDpiY()*100./2.54;
458  int w = d->req_size.width();
459  int h = d->req_size.height();
460  switch (metric) {
461  case PdmWidth:
462  return w;
463 
464  case PdmHeight:
465  return h;
466 
467  case PdmWidthMM:
468  return qRound(w * 1000 / dpmx);
469 
470  case PdmHeightMM:
471  return qRound(h * 1000 / dpmy);
472 
473  case PdmNumColors:
474  return 0;
475 
476  case PdmDepth:
477  return 32;//d->depth;
478 
479  case PdmDpiX:
480  return qRound(dpmx * 0.0254);
481 
482  case PdmDpiY:
483  return qRound(dpmy * 0.0254);
484 
485  case PdmPhysicalDpiX:
486  return qRound(dpmx * 0.0254);
487 
488  case PdmPhysicalDpiY:
489  return qRound(dpmy * 0.0254);
490 
491  default:
492  qWarning("QGLPixelBuffer::metric(), Unhandled metric type: %d\n", metric);
493  break;
494  }
495  return 0;
496 }
double d
Definition: qnumeric_p.h:62
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
int metric(PaintDeviceMetric metric) const
Reimplemented Function
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ paintEngine()

QPaintEngine * QGLPixelBuffer::paintEngine ( ) const
virtual

Reimplemented Function

Implements QPaintDevice.

Definition at line 437 of file qglpixelbuffer.cpp.

438 {
439 #if defined(QT_OPENGL_ES_1)
440  return qt_buffer_engine()->engine();
441 #elif defined(QT_OPENGL_ES_2)
442  return qt_buffer_2_engine()->engine();
443 #else
444  if (qt_gl_preferGL2Engine())
445  return qt_buffer_2_engine()->engine();
446  else
447  return qt_buffer_engine()->engine();
448 #endif
449 }
bool qt_gl_preferGL2Engine()
Definition: qgl.cpp:218

◆ releaseFromDynamicTexture()

void QGLPixelBuffer::releaseFromDynamicTexture ( )

Releases the pbuffer from any previously bound texture.

See also
bindToDynamicTexture()

Definition at line 174 of file qglpixelbuffer_egl.cpp.

Referenced by nearest_gl_texture_size(), and qt_format_to_attrib_list().

175 {
176 #if QGL_RENDER_TEXTURE
178  if (d->invalid || d->textureFormat == EGL_NONE || !d->ctx)
179  return;
180  eglReleaseTexImage(d->ctx->display(), d->pbuf, EGL_BACK_BUFFER);
181 #endif
182 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ size()

QSize QGLPixelBuffer::size ( ) const

Returns the size of the pbuffer.

Definition at line 389 of file qglpixelbuffer.cpp.

390 {
391  Q_D(const QGLPixelBuffer);
392  return d->req_size;
393 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.

◆ toImage()

QImage QGLPixelBuffer::toImage ( ) const

Returns the contents of the pbuffer as a QImage.

Definition at line 398 of file qglpixelbuffer.cpp.

Referenced by QGLWindowSurface::buffer().

399 {
400  Q_D(const QGLPixelBuffer);
401  if (d->invalid)
402  return QImage();
403 
404  const_cast<QGLPixelBuffer *>(this)->makeCurrent();
405  return qt_gl_read_framebuffer(d->req_size, d->format.alpha(), true);
406 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
bool makeCurrent()
Makes this pbuffer the current OpenGL rendering context.
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
QImage qt_gl_read_framebuffer(const QSize &, bool, bool)
Definition: qgl.cpp:1860

◆ updateDynamicTexture()

void QGLPixelBuffer::updateDynamicTexture ( GLuint  texture_id) const

Copies the pbuffer contents into the texture specified with texture_id.

The texture must be of the same size and format as the pbuffer.

Example:

QGLPixelBuffer pbuffer(...);
...
pbuffer.makeCurrent();
GLuint dynamicTexture = pbuffer.generateDynamicTexture();
...
pbuffer.updateDynamicTexture(dynamicTexture);

An alternative on Windows and Mac OS X systems that support the render_texture extension is to use bindToDynamicTexture() to get dynamic updates of the texture.

See also
generateDynamicTexture(), bindToDynamicTexture()

Definition at line 366 of file qglpixelbuffer.cpp.

367 {
368  Q_D(const QGLPixelBuffer);
369  if (d->invalid)
370  return;
371  glBindTexture(GL_TEXTURE_2D, texture_id);
372 #ifndef QT_OPENGL_ES
373  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, d->req_size.width(), d->req_size.height(), 0);
374 #else
375  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, d->req_size.width(), d->req_size.height(), 0);
376 #endif
377 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
#define GL_TEXTURE_2D
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
#define GL_RGBA

Friends and Related Functions

◆ QGLContextPrivate

friend class QGLContextPrivate
friend

Definition at line 115 of file qglpixelbuffer.h.

◆ QGLDrawable

friend class QGLDrawable
friend

Definition at line 111 of file qglpixelbuffer.h.

◆ QGLPaintDevice

friend class QGLPaintDevice
friend

Definition at line 113 of file qglpixelbuffer.h.

◆ QGLPBufferGLPaintDevice

Definition at line 114 of file qglpixelbuffer.h.

◆ QGLWindowSurface

friend class QGLWindowSurface
friend

Definition at line 112 of file qglpixelbuffer.h.

Properties

◆ d_ptr

QScopedPointer<QGLPixelBufferPrivate> QGLPixelBuffer::d_ptr
private

Definition at line 110 of file qglpixelbuffer.h.

Referenced by QGLWindowSurface::updateGeometry().


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