Qt 4.8
|
The QGLPixelBuffer class encapsulates an OpenGL pbuffer. More...
#include <qglpixelbuffer.h>
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... | |
QPaintEngine * | paintEngine () 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 QWSDisplay * | qwsDisplay () |
Protected Functions | |
int | devType () const |
int | metric (PaintDeviceMetric metric) const |
Reimplemented Function More... | |
Protected Functions inherited from QPaintDevice | |
QPaintDevice () | |
Properties | |
QScopedPointer< QGLPixelBufferPrivate > | d_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 |
Related Functions inherited from QPaintDevice | |
const Q_GUI_EXPORT QX11Info * | qt_x11Info (const QPaintDevice *pd) |
Returns the QX11Info structure for the pd paint device. More... | |
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
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:
We can draw into the pbuffer and convert it to a QImage using toImage(). This is normally much faster than calling QGLWidget::renderPixmap().
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.
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.
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.
Definition at line 56 of file qglpixelbuffer.h.
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).
Definition at line 184 of file qglpixelbuffer.cpp.
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).
Definition at line 209 of file qglpixelbuffer.cpp.
|
virtual |
Destroys the pbuffer and frees any allocated resources.
Definition at line 224 of file qglpixelbuffer.cpp.
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().
Definition at line 509 of file qglpixelbuffer.cpp.
Referenced by bindTexture(), and QGLPixmapFilterBase::~QGLPixmapFilterBase().
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().
Definition at line 539 of file qglpixelbuffer.cpp.
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().
Definition at line 570 of file qglpixelbuffer.cpp.
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().
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:
{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().Definition at line 160 of file qglpixelbuffer_egl.cpp.
Referenced by nearest_gl_texture_size(), and qt_format_to_attrib_list().
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.
|
inlineprotectedvirtual |
Reimplemented from QPaintDevice.
Definition at line 106 of file qglpixelbuffer.h.
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.
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.
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().
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.
The textureTarget parameter should be a 2D texture target.
Equivalent to the corresponding QGLContext::drawTexture().
Definition at line 634 of file qglpixelbuffer.cpp.
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().
GLuint QGLPixelBuffer::generateDynamicTexture | ( | ) | const |
Definition at line 185 of file qglpixelbuffer_egl.cpp.
Referenced by doneCurrent(), and nearest_gl_texture_size().
Qt::HANDLE QGLPixelBuffer::handle | ( | ) | const |
Returns the native pbuffer handle.
Definition at line 411 of file qglpixelbuffer.cpp.
|
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().
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().
bool QGLPixelBuffer::makeCurrent | ( | ) |
Makes this pbuffer the current OpenGL rendering context.
Returns true on success; otherwise returns false.
Definition at line 250 of file qglpixelbuffer.cpp.
Referenced by QGLWindowSurface::flush(), QGLWindowSurface::scroll(), toImage(), QGLWindowSurface::updateGeometry(), and ~QGLPixelBuffer().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QPaintDevice.
Definition at line 452 of file qglpixelbuffer.cpp.
|
virtual |
void QGLPixelBuffer::releaseFromDynamicTexture | ( | ) |
Releases the pbuffer from any previously bound texture.
Definition at line 174 of file qglpixelbuffer_egl.cpp.
Referenced by nearest_gl_texture_size(), and qt_format_to_attrib_list().
QSize QGLPixelBuffer::size | ( | ) | const |
Returns the size of the pbuffer.
Definition at line 389 of file qglpixelbuffer.cpp.
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().
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:
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.
Definition at line 366 of file qglpixelbuffer.cpp.
|
friend |
Definition at line 115 of file qglpixelbuffer.h.
|
friend |
Definition at line 111 of file qglpixelbuffer.h.
|
friend |
Definition at line 113 of file qglpixelbuffer.h.
|
friend |
Definition at line 114 of file qglpixelbuffer.h.
|
friend |
Definition at line 112 of file qglpixelbuffer.h.
|
private |
Definition at line 110 of file qglpixelbuffer.h.
Referenced by QGLWindowSurface::updateGeometry().