Struct qt_gui::QOpenGLTextureBlitter
source · #[repr(C)]pub struct QOpenGLTextureBlitter { /* private fields */ }
Expand description
The QOpenGLTextureBlitter class provides a convenient way to draw textured quads via OpenGL.
C++ class: QOpenGLTextureBlitter
.
The QOpenGLTextureBlitter class provides a convenient way to draw textured quads via OpenGL.
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).
Implementations§
source§impl QOpenGLTextureBlitter
impl QOpenGLTextureBlitter
sourcepub unsafe fn bind_1a(&self, target: c_uint)
pub unsafe fn bind_1a(&self, target: c_uint)
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 bind() and blit() because otherwise conflicts may arise.
Calls C++ function: void QOpenGLTextureBlitter::bind(unsigned int target = …)
.
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 bind() and blit() because otherwise conflicts may arise.
target is the texture target for the source texture and must be either GL_TEXTURE_2D
or GL_OES_EGL_image_external
.
sourcepub unsafe fn bind_0a(&self)
pub unsafe fn bind_0a(&self)
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 bind() and blit() because otherwise conflicts may arise.
Calls C++ function: void QOpenGLTextureBlitter::bind()
.
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 bind() and blit() because otherwise conflicts may arise.
target is the texture target for the source texture and must be either GL_TEXTURE_2D
or GL_OES_EGL_image_external
.
sourcepub unsafe fn blit(
&self,
texture: u32,
target_transform: impl CastInto<Ref<QMatrix4X4>>,
source_origin: Origin
)
pub unsafe fn blit( &self, texture: u32, target_transform: impl CastInto<Ref<QMatrix4X4>>, source_origin: Origin )
Performs the blit with the source texture texture.
Calls C++ function: void QOpenGLTextureBlitter::blit(GLuint texture, const QMatrix4x4& targetTransform, QOpenGLTextureBlitter::Origin sourceOrigin)
.
Performs the blit with the source texture texture.
targetTransform specifies the transformation applied. This is usually generated by the targetTransform() helper function.
sourceOrigin specifies if the image data needs flipping. When texture corresponds to a texture attached to an FBO pass OriginBottomLeft. On the other hand, when texture is based on unflipped image data, pass OriginTopLeft. This is more efficient than using QImage::mirrored().
See also targetTransform(), Origin, and bind().
sourcepub unsafe fn create(&self) -> bool
pub unsafe fn create(&self) -> bool
Initializes the graphics resources used by the blitter.
Calls C++ function: bool QOpenGLTextureBlitter::create()
.
sourcepub unsafe fn destroy(&self)
pub unsafe fn destroy(&self)
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.
Calls C++ function: void QOpenGLTextureBlitter::destroy()
.
sourcepub unsafe fn is_created(&self) -> bool
pub unsafe fn is_created(&self) -> bool
Returns true
if create() was called and succeeded. false
otherwise.
Calls C++ function: bool QOpenGLTextureBlitter::isCreated() const
.
sourcepub unsafe fn new() -> CppBox<QOpenGLTextureBlitter>
pub unsafe fn new() -> CppBox<QOpenGLTextureBlitter>
Constructs a new QOpenGLTextureBlitter instance.
Calls C++ function: [constructor] void QOpenGLTextureBlitter::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 in create().
sourcepub unsafe fn release(&self)
pub unsafe fn release(&self)
Unbinds the graphics resources used by the blitter.
Calls C++ function: void QOpenGLTextureBlitter::release()
.
Unbinds the graphics resources used by the blitter.
See also bind().
sourcepub unsafe fn set_opacity(&self, opacity: c_float)
pub unsafe fn set_opacity(&self, opacity: c_float)
Changes the opacity to opacity. The default opacity is 1.0.
Calls C++ function: void QOpenGLTextureBlitter::setOpacity(float opacity)
.
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.
sourcepub unsafe fn set_red_blue_swizzle(&self, swizzle: bool)
pub unsafe fn set_red_blue_swizzle(&self, 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 a QImage with a format like QImage::Format_ARGB32 which maps to BGRA on little endian systems.
Calls C++ function: void QOpenGLTextureBlitter::setRedBlueSwizzle(bool swizzle)
.
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 a QImage with a format like QImage::Format_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 (like QImage::Format_RGBA8888) needs.
sourcepub unsafe fn supports_external_o_e_s_target(&self) -> bool
pub unsafe fn supports_external_o_e_s_target(&self) -> bool
Returns true
when bind() accepts GL_TEXTURE_EXTERNAL_OES
as its target argument.
Calls C++ function: bool QOpenGLTextureBlitter::supportsExternalOESTarget() const
.
sourcepub unsafe fn target_transform(
target: impl CastInto<Ref<QRectF>>,
viewport: impl CastInto<Ref<QRect>>
) -> CppBox<QMatrix4X4>
pub unsafe fn target_transform( target: impl CastInto<Ref<QRectF>>, viewport: impl CastInto<Ref<QRect>> ) -> CppBox<QMatrix4X4>
Calculates a target transform suitable for blit().
Calls C++ function: static QMatrix4x4 QOpenGLTextureBlitter::targetTransform(const QRectF& target, const QRect& viewport)
.
Trait Implementations§
source§impl CppDeletable for QOpenGLTextureBlitter
impl CppDeletable for QOpenGLTextureBlitter
source§unsafe fn delete(&self)
unsafe fn delete(&self)
Destructs the instance.
Calls C++ function: [destructor] void QOpenGLTextureBlitter::~QOpenGLTextureBlitter()
.
Destructs the instance.
Note: When the OpenGL context - or a context sharing resources with it - that was current when calling create() is not current, graphics resources will not be released. Therefore, it is recommended to call destroy() manually instead of relying on the destructor to perform OpenGL resource cleanup.