QOpenGLTextureBlitter¶
The
QOpenGLTextureBlitter
class provides a convenient way to draw textured quads via OpenGL. More…
Synopsis¶
Functions¶
def
bind
([target=GL_TEXTURE_2D])def
blit
(texture, targetTransform, sourceOrigin)def
blit
(texture, targetTransform, sourceTransform)def
create
()def
destroy
()def
isCreated
()def
release
()def
setOpacity
(opacity)def
setRedBlueSwizzle
(swizzle)def
supportsExternalOESTarget
()
Static functions¶
def
sourceTransform
(subTexture, textureSize, origin)def
targetTransform
(target, viewport)
Detailed Description¶
Drawing textured quads, in order to get the contents of a texture onto the screen, is a common operation when developing 2D user interfaces.
QOpenGLTextureBlitter
provides a convenience class to avoid repeating vertex data, shader sources, buffer and program management and matrix calculations.For example, a
QOpenGLWidget
subclass can do the following to draw the contents rendered into a framebuffer at the pixel position(x, y)
:void OpenGLWidget::initializeGL() { m_blitter.create(); m_fbo = new QOpenGLFramebufferObject(size); } void OpenGLWidget::paintGL() { m_fbo->bind(); // update offscreen content m_fbo->release(); m_blitter.bind(); const QRect targetRect(QPoint(x, y), m_fbo->size()); const QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(targetRect, QRect(QPoint(0, 0), m_fbo->size())); m_blitter.blit(m_fbo->texture(), target, QOpenGLTextureBlitter::OriginBottomLeft); m_blitter.release(); }The blitter implements GLSL shaders both for GLSL 1.00 (suitable for OpenGL (ES) 2.x and compatibility profiles of newer OpenGL versions) and version 150 (suitable for core profile contexts with OpenGL 3.2 and newer).
- class PySide2.QtGui.QOpenGLTextureBlitter¶
Constructs a new
QOpenGLTextureBlitter
instance.Note
no graphics resources are initialized in the constructor. This makes it safe to place plain
QOpenGLTextureBlitter
members into classes because the actual initialization that depends on the OpenGL context happens only increate()
.
- PySide2.QtGui.QOpenGLTextureBlitter.Origin¶
Constant
Description
QOpenGLTextureBlitter.OriginBottomLeft
Indicates that the data in the texture follows the OpenGL convention of coordinate systems, meaning Y is running from bottom to top.
QOpenGLTextureBlitter.OriginTopLeft
Indicates that the data in the texture has Y running from top to bottom, which is typical with regular, unflipped image data.
See also
- PySide2.QtGui.QOpenGLTextureBlitter.bind([target=GL_TEXTURE_2D])¶
- Parameters:
target –
GLenum
Binds the graphics resources used by the blitter. This must be called before calling
blit()
. Code modifying the OpenGL state should be avoided between the call to andblit()
because otherwise conflicts may arise.target
is the texture target for the source texture and must be eitherGL_TEXTURE_2D
,GL_TEXTURE_RECTANGLE
, orGL_OES_EGL_image_external
.
- PySide2.QtGui.QOpenGLTextureBlitter.blit(texture, targetTransform, sourceOrigin)¶
- Parameters:
texture –
GLuint
targetTransform –
PySide2.QtGui.QMatrix4x4
sourceOrigin –
Origin
- PySide2.QtGui.QOpenGLTextureBlitter.blit(texture, targetTransform, sourceTransform)
- Parameters:
texture –
GLuint
targetTransform –
PySide2.QtGui.QMatrix4x4
sourceTransform –
PySide2.QtGui.QMatrix3x3
- PySide2.QtGui.QOpenGLTextureBlitter.create()¶
- Return type:
bool
Initializes the graphics resources used by the blitter.
Returns
true
if successful,false
if there was a failure. Failures can occur when there is no OpenGL context current on the current thread, or when shader compilation fails for some reason.See also
- PySide2.QtGui.QOpenGLTextureBlitter.destroy()¶
Frees all graphics resources held by the blitter. Assumes that the OpenGL context, or another context sharing resources with it, that was current on the thread when invoking
create()
is current.The function has no effect when the blitter is not in created state.
See also
- PySide2.QtGui.QOpenGLTextureBlitter.isCreated()¶
- Return type:
bool
Returns
true
ifcreate()
was called and succeeded.false
otherwise.
- PySide2.QtGui.QOpenGLTextureBlitter.release()¶
Unbinds the graphics resources used by the blitter.
See also
- PySide2.QtGui.QOpenGLTextureBlitter.setOpacity(opacity)¶
- Parameters:
opacity – float
Changes the opacity to
opacity
. The default opacity is 1.0.Note
the blitter does not alter the blend state. It is up to the caller of
blit()
to ensure the correct blend settings are active.
- PySide2.QtGui.QOpenGLTextureBlitter.setRedBlueSwizzle(swizzle)¶
- Parameters:
swizzle – bool
Sets whether swizzling is enabled for the red and blue color channels to
swizzle
. An BGRA to RGBA conversion (occurring in the shader on the GPU, instead of a slow CPU-side transformation) can be useful when the source texture contains data from aQImage
with a format likeFormat_ARGB32
which maps to BGRA on little endian systems.By default the red-blue swizzle is disabled since this is what a texture attached to an framebuffer object or a texture based on a byte ordered
QImage
format (likeFormat_RGBA8888
) needs.
- static PySide2.QtGui.QOpenGLTextureBlitter.sourceTransform(subTexture, textureSize, origin)¶
- Parameters:
subTexture –
PySide2.QtCore.QRectF
textureSize –
PySide2.QtCore.QSize
origin –
Origin
- Return type:
Calculates a 3x3 matrix suitable as the input to
blit()
. This is used when only a part of the texture is to be used in the blit.subTexture
is the desired source rectangle in pixels,textureSize
is the full width and height of the texture data.origin
specifies the orientation of the image data when it comes to the Y axis.See also
blit()
Origin
- PySide2.QtGui.QOpenGLTextureBlitter.supportsExternalOESTarget()¶
- Return type:
bool
Returns
true
whenbind()
acceptsGL_TEXTURE_EXTERNAL_OES
as its target argument.
- static PySide2.QtGui.QOpenGLTextureBlitter.targetTransform(target, viewport)¶
- Parameters:
target –
PySide2.QtCore.QRectF
viewport –
PySide2.QtCore.QRect
- Return type:
Calculates a target transform suitable for
blit()
.target
is the target rectangle in pixels.viewport
describes the source dimensions and will in most cases be set to (0, 0, image width, image height).For unscaled output the size of
target
andviewport
should match.See also
© 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.