QGLPixelBuffer¶
The
QGLPixelBuffer
class encapsulates an OpenGL pbuffer. More…
Synopsis¶
Functions¶
def
bindTexture
(fileName)def
bindTexture
(image[, target=GL_TEXTURE_2D])def
bindTexture
(pixmap[, target=GL_TEXTURE_2D])def
bindToDynamicTexture
(texture)def
context
()def
deleteTexture
(texture_id)def
doneCurrent
()def
drawTexture
(point, textureId[, textureTarget=GL_TEXTURE_2D])def
drawTexture
(target, textureId[, textureTarget=GL_TEXTURE_2D])def
format
()def
generateDynamicTexture
()def
handle
()def
isValid
()def
makeCurrent
()def
releaseFromDynamicTexture
()def
size
()def
toImage
()def
updateDynamicTexture
(texture_id)
Static functions¶
def
hasOpenGLPbuffers
()
Detailed Description¶
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
usingtoImage()
. This is normally much faster than callingrenderPixmap()
.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 macOS systems that provide the
render_texture
extension. Note that under Windows, a multi-sampled pbuffer can’t be used in conjunction with therender_texture
extension. If a multi-sampled pbuffer is requested under Windows, therender_texture
extension is turned off for that pbuffer.Note
This class has been deprecated, use
QOpenGLFramebufferObject
for offscreen rendering.
Threading¶
As of Qt 4.8, it’s possible to render into a
QGLPixelBuffer
using aQPainter
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.
- class PySide2.QtOpenGL.QGLPixelBuffer(size[, format=QGLFormat.defaultFormat()[, shareWidget=None]])¶
PySide2.QtOpenGL.QGLPixelBuffer(width, height[, format=QGLFormat.defaultFormat()[, shareWidget=None]])
- param format:
- param size:
- param shareWidget:
- param width:
int
- param height:
int
Constructs an OpenGL pbuffer of the given
size
. If noformat
is specified, thedefault format
is used. If theshareWidget
parameter points to a validQGLWidget
, the pbuffer will share its context withshareWidget
.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).This is an overloaded function.
Constructs an OpenGL pbuffer with the
width
andheight
. If noformat
is specified, thedefault format
is used. If theshareWidget
parameter points to a validQGLWidget
, the pbuffer will share its context withshareWidget
.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).
- PySide2.QtOpenGL.QGLPixelBuffer.bindTexture(pixmap[, target=GL_TEXTURE_2D])¶
- Parameters:
pixmap –
PySide2.QtGui.QPixmap
target –
GLenum
- Return type:
GLuint
- PySide2.QtOpenGL.QGLPixelBuffer.bindTexture(fileName)
- Parameters:
fileName – str
- Return type:
GLuint
This is an overloaded function.
Reads the DirectDrawSurface (DDS) compressed file
fileName
and generates a 2D GL texture from it.Equivalent to calling
bindTexture()
.See also
- PySide2.QtOpenGL.QGLPixelBuffer.bindTexture(image[, target=GL_TEXTURE_2D])
- Parameters:
image –
PySide2.QtGui.QImage
target –
GLenum
- Return type:
GLuint
- PySide2.QtOpenGL.QGLPixelBuffer.bindToDynamicTexture(texture)¶
- Parameters:
texture –
GLuint
- Return type:
bool
Binds the texture specified by
texture_id
to this pbuffer. Returnstrue
on success; otherwise returnsfalse
.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:
pbuffer QGLPixelBuffer(...) ... pbuffer.makeCurrent() 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 usingupdateDynamicTexture()
.Warning
For the call to succeed on the macOS, the pbuffer needs a shared context, i.e. the
QGLPixelBuffer
must be created with a share widget.
- PySide2.QtOpenGL.QGLPixelBuffer.context()¶
- Return type:
Returns the context of this pixelbuffer.
- PySide2.QtOpenGL.QGLPixelBuffer.deleteTexture(texture_id)¶
- Parameters:
texture_id –
GLuint
Removes the texture identified by
texture_id
from the texture cache.Equivalent to calling
deleteTexture()
.
- PySide2.QtOpenGL.QGLPixelBuffer.doneCurrent()¶
- Return type:
bool
Makes no context the current OpenGL context. Returns
true
on success; otherwise returnsfalse
.
- PySide2.QtOpenGL.QGLPixelBuffer.drawTexture(point, textureId[, textureTarget=GL_TEXTURE_2D])¶
- Parameters:
point –
PySide2.QtCore.QPointF
textureId –
GLuint
textureTarget –
GLenum
- PySide2.QtOpenGL.QGLPixelBuffer.drawTexture(target, textureId[, textureTarget=GL_TEXTURE_2D])
- Parameters:
target –
PySide2.QtCore.QRectF
textureId –
GLuint
textureTarget –
GLenum
- PySide2.QtOpenGL.QGLPixelBuffer.format()¶
- Return type:
Returns the format of the pbuffer. The format may be different from the one that was requested.
- PySide2.QtOpenGL.QGLPixelBuffer.generateDynamicTexture()¶
- Return type:
GLuint
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()
andupdateDynamicTexture()
.See also
- PySide2.QtOpenGL.QGLPixelBuffer.handle()¶
- Return type:
Qt::HANDLE
Returns the native pbuffer handle.
- static PySide2.QtOpenGL.QGLPixelBuffer.hasOpenGLPbuffers()¶
- Return type:
bool
Returns
true
if the OpenGLpbuffer
extension is present on this system; otherwise returnsfalse
.
- PySide2.QtOpenGL.QGLPixelBuffer.isValid()¶
- Return type:
bool
Returns
true
if this pbuffer is valid; otherwise returnsfalse
.
- PySide2.QtOpenGL.QGLPixelBuffer.makeCurrent()¶
- Return type:
bool
Makes this pbuffer the current OpenGL rendering context. Returns true on success; otherwise returns
false
.See also
- PySide2.QtOpenGL.QGLPixelBuffer.releaseFromDynamicTexture()¶
Releases the pbuffer from any previously bound texture.
See also
- PySide2.QtOpenGL.QGLPixelBuffer.size()¶
- Return type:
Returns the size of the pbuffer.
- PySide2.QtOpenGL.QGLPixelBuffer.toImage()¶
- Return type:
Returns the contents of the pbuffer as a
QImage
.
- PySide2.QtOpenGL.QGLPixelBuffer.updateDynamicTexture(texture_id)¶
- Parameters:
texture_id –
GLuint
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:
pbuffer QGLPixelBuffer(...) ... pbuffer.makeCurrent() dynamicTexture = pbuffer.generateDynamicTexture() ... pbuffer.updateDynamicTexture(dynamicTexture)
An alternative on Windows and macOS systems that support the
render_texture
extension is to usebindToDynamicTexture()
to get dynamic updates of the texture.
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.