The QGLPixelBuffer class encapsulates an OpenGL pbuffer. 更多...
头: | #include <QGLPixelBuffer> |
qmake: | QT += opengl |
Since: | Qt 4.1 |
继承: | QPaintDevice |
该类已过时。 提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。
QGLPixelBuffer (const QSize & size , const QGLFormat & format = QGLFormat::defaultFormat(), QGLWidget * shareWidget = nullptr) | |
QGLPixelBuffer (int width , int height , const QGLFormat & format = QGLFormat::defaultFormat(), QGLWidget * shareWidget = nullptr) | |
virtual | ~QGLPixelBuffer () |
GLuint | bindTexture (const QImage & image , GLenum target = GL_TEXTURE_2D) |
GLuint | bindTexture (const QPixmap & pixmap , GLenum target = GL_TEXTURE_2D) |
GLuint | bindTexture (const QString & fileName ) |
bool | bindToDynamicTexture (GLuint texture_id ) |
QGLContext * | context () const |
void | deleteTexture (GLuint texture_id ) |
bool | doneCurrent () |
void | drawTexture (const QRectF & target , GLuint textureId , GLenum textureTarget = GL_TEXTURE_2D) |
void | drawTexture (const QPointF & point , GLuint textureId , GLenum textureTarget = GL_TEXTURE_2D) |
QGLFormat | format () const |
GLuint | generateDynamicTexture () const |
Qt::HANDLE | handle () const |
bool | isValid () const |
bool | makeCurrent () |
void | releaseFromDynamicTexture () |
QSize | size () const |
QImage | toImage () const |
void | updateDynamicTexture (GLuint texture_id ) const |
virtual QPaintEngine * | paintEngine () const override |
bool | hasOpenGLPbuffers () |
virtual int | metric (QPaintDevice::PaintDeviceMetric metric ) const override |
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:
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.
注意: This class has been deprecated, use QOpenGLFramebufferObject for offscreen rendering.
As of Qt 4.8, it's possible to render into a QGLPixelBuffer 使用 QPainter in a separate thread. Note that OpenGL 2.0 or OpenGL ES 2.0 is required for this to work.
Pbuffers are provided by the OpenGL
pbuffer
extension; call hasOpenGLPbuffer() to find out if the system provides pbuffers.
Constructs an OpenGL pbuffer of the given size . If no format is specified, the 默认格式 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).
这是重载函数。
Constructs an OpenGL pbuffer with the width and height . If no format is specified, the 默认格式 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).
[虚拟]
QGLPixelBuffer::
~QGLPixelBuffer
()
Destroys the pbuffer and frees any allocated resources.
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.
相当于调用 QGLContext::bindTexture ().
另请参阅 deleteTexture ().
这是重载函数。
Generates and binds a 2D GL texture based on pixmap .
相当于调用 QGLContext::bindTexture ().
另请参阅 deleteTexture ().
这是重载函数。
Reads the DirectDrawSurface (DDS) compressed file fileName and generates a 2D GL texture from it.
相当于调用 QGLContext::bindTexture ().
另请参阅 deleteTexture ().
Binds the texture specified by
texture_id
to this pbuffer. Returns
true
当成功时;否则返回
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.
范例:
QGLPixelBuffer pbuffer(...); ... pbuffer.makeCurrent(); GLuint dynamicTexture = pbuffer.generateDynamicTexture(); pbuffer.bindToDynamicTexture(dynamicTexture); ... pbuffer.releaseFromDynamicTexture();
警告:
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 macOS , the pbuffer needs a shared context, i.e. the QGLPixelBuffer must be created with a share widget.
另请参阅 generateDynamicTexture () 和 releaseFromDynamicTexture ().
Returns the context of this pixelbuffer.
Removes the texture identified by texture_id from the texture cache.
相当于调用 QGLContext::deleteTexture ().
Makes no context the current OpenGL context. Returns
true
当成功时;否则返回
false
.
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 ().
该函数在 Qt 4.4 引入。
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 ().
该函数在 Qt 4.4 引入。
Returns the format of the pbuffer. The format may be different from the one that was requested.
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 () 和 updateDynamicTexture ().
另请参阅 size ().
Returns the native pbuffer handle.
[static]
bool
QGLPixelBuffer::
hasOpenGLPbuffers
()
返回
true
if the OpenGL
pbuffer
extension is present on this system; otherwise returns
false
.
返回
true
if this pbuffer is valid; otherwise returns
false
.
Makes this pbuffer the current OpenGL rendering context. Returns true on success; otherwise returns
false
.
另请参阅 QGLContext::makeCurrent () 和 doneCurrent ().
[override virtual protected]
int
QGLPixelBuffer::
metric
(
QPaintDevice::PaintDeviceMetric
metric
) const
重实现自 QPaintDevice::metric ().
[override virtual]
QPaintEngine
*QGLPixelBuffer::
paintEngine
() const
重实现自 QPaintDevice::paintEngine ().
Releases the pbuffer from any previously bound texture.
另请参阅 bindToDynamicTexture ().
Returns the size of the pbuffer.
Returns the contents of the pbuffer as a QImage .
Copies the pbuffer contents into the texture specified with texture_id .
The texture must be of the same size and format as the pbuffer.
范例:
QGLPixelBuffer pbuffer(...); ... pbuffer.makeCurrent(); GLuint dynamicTexture = pbuffer.generateDynamicTexture(); ... pbuffer.updateDynamicTexture(dynamicTexture);
An alternative on Windows and
macOS
systems that support the
render_texture
extension is to use
bindToDynamicTexture
() to get dynamic updates of the texture.
另请参阅 generateDynamicTexture () 和 bindToDynamicTexture ().