QGLFramebufferObject¶
The
QGLFramebufferObject
class encapsulates an OpenGL framebuffer object. More…
Synopsis¶
Functions¶
def
attachment
()def
bind
()def
drawTexture
(point, textureId[, textureTarget=GL_TEXTURE_2D])def
drawTexture
(target, textureId[, textureTarget=GL_TEXTURE_2D])def
format
()def
handle
()def
isBound
()def
isValid
()def
release
()def
size
()def
texture
()def
toImage
()
Static functions¶
def
bindDefault
()def
blitFramebuffer
(target, targetRect, source, sourceRect[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])def
hasOpenGLFramebufferBlit
()def
hasOpenGLFramebufferObjects
()
Detailed Description¶
The
QGLFramebufferObject
class encapsulates an OpenGL framebuffer object, defined by theGL_EXT_framebuffer_object
extension. In addition it provides a rendering surface that can be painted on with aQPainter
, rendered to using native GL calls, or both. This surface can be bound and used as a regular texture in your own GL drawing code. By default, theQGLFramebufferObject
class generates a 2D GL texture (using theGL_TEXTURE_2D
target), which is used as the internal rendering target.It is important to have a current GL context when creating a
QGLFramebufferObject
, otherwise initialization will fail.OpenGL framebuffer objects and pbuffers (see
QGLPixelBuffer
) can both be used to render to offscreen surfaces, but there are a number of advantages with using framebuffer objects instead of pbuffers:
A framebuffer object does not require a separate rendering context, so no context switching will occur when switching rendering targets. There is an overhead involved in switching targets, but in general it is cheaper than a context switch to a pbuffer.
Rendering to dynamic textures (i.e. render-to-texture functionality) works on all platforms. No need to do explicit copy calls from a render buffer into a texture, as was necessary on systems that did not support the
render_texture
extension.It is possible to attach several rendering buffers (or texture objects) to the same framebuffer object, and render to all of them without doing a context switch.
The OpenGL framebuffer extension is a pure GL extension with no system dependant WGL, CGL, or GLX parts. This makes using framebuffer objects more portable.
When using a
QPainter
to paint to aQGLFramebufferObject
you should take care that theQGLFramebufferObject
is created with theCombinedDepthStencil
attachment forQPainter
to be able to render correctly. Note that you need to create aQGLFramebufferObject
with more than one sample per pixel for primitives to be antialiased when drawing using aQPainter
. To create a multisample framebuffer object you should use one of the constructors that take aQGLFramebufferObjectFormat
parameter, and set thesamples()
property to a non-zero value.When painting to a
QGLFramebufferObject
usingQPainter
, the state of the current GL context will be altered by the paint engine to reflect its needs. Applications should not rely upon the GL state being reset to its original conditions, particularly the current shader program, GL viewport, texture units, and drawing modes.For multisample framebuffer objects a color render buffer is created, otherwise a texture with the specified texture target is created. The color render buffer or texture will have the specified internal format, and will be bound to the
GL_COLOR_ATTACHMENT0
attachment in the framebuffer object.If you want to use a framebuffer object with multisampling enabled as a texture, you first need to copy from it to a regular framebuffer object using QGLContext::blitFramebuffer().
Threading¶
As of Qt 4.8, it’s possible to draw into a
QGLFramebufferObject
using aQPainter
in a separate thread. Note that OpenGL 2.0 or OpenGL ES 2.0 is required for this to work.Note
This class has been deprecated in favor of
QOpenGLFramebufferObject
.
- class PySide2.QtOpenGL.QGLFramebufferObject(size[, target=GL_TEXTURE_2D])¶
PySide2.QtOpenGL.QGLFramebufferObject(size, attachment[, target=GL_TEXTURE_2D[, internal_format=0]])
PySide2.QtOpenGL.QGLFramebufferObject(size, format)
PySide2.QtOpenGL.QGLFramebufferObject(width, height[, target=GL_TEXTURE_2D])
PySide2.QtOpenGL.QGLFramebufferObject(width, height, attachment[, target=GL_TEXTURE_2D[, internal_format=0]])
PySide2.QtOpenGL.QGLFramebufferObject(width, height, format)
- param internal_format:
GLenum
- param format:
- param size:
- param target:
GLenum
- param width:
int
- param height:
int
- param attachment:
This is an overloaded function.
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given
size
.The
attachment
parameter describes the depth/stencil buffer configuration,target
the texture target andinternal_format
the internal texture format. The default texture target isGL_TEXTURE_2D
, while the default internal format isGL_RGBA8
for desktop OpenGL andGL_RGBA
for OpenGL/ES.See also
This is an overloaded function.
Constructs an OpenGL framebuffer object and binds a 2D GL texture to the buffer of the given
width
andheight
.This is an overloaded function.
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given
width
andheight
.The
attachment
parameter describes the depth/stencil buffer configuration,target
the texture target andinternal_format
the internal texture format. The default texture target isGL_TEXTURE_2D
, while the default internal format isGL_RGBA8
for desktop OpenGL andGL_RGBA
for OpenGL/ES.See also
- PySide2.QtOpenGL.QGLFramebufferObject.Attachment¶
This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created.
Constant
Description
QGLFramebufferObject.NoAttachment
No attachment is added to the framebuffer object. Note that the OpenGL depth and stencil tests won’t work when rendering to a framebuffer object without any depth or stencil buffers. This is the default value.
QGLFramebufferObject.CombinedDepthStencil
If the
GL_EXT_packed_depth_stencil
extension is present, a combined depth and stencil buffer is attached. If the extension is not present, only a depth buffer is attached.QGLFramebufferObject.Depth
A depth buffer is attached to the framebuffer object.
See also
- PySide2.QtOpenGL.QGLFramebufferObject.attachment()¶
- Return type:
Returns the status of the depth and stencil buffers attached to this framebuffer object.
- PySide2.QtOpenGL.QGLFramebufferObject.bind()¶
- Return type:
bool
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object. Returns
true
upon success, false otherwise.See also
- static PySide2.QtOpenGL.QGLFramebufferObject.bindDefault()¶
- Return type:
bool
Switches rendering back to the default, windowing system provided framebuffer. Returns
true
upon success, false otherwise.
- static PySide2.QtOpenGL.QGLFramebufferObject.blitFramebuffer(target, targetRect, source, sourceRect[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])¶
- Parameters:
targetRect –
PySide2.QtCore.QRect
sourceRect –
PySide2.QtCore.QRect
buffers –
GLbitfield
filter –
GLenum
Blits from the
sourceRect
rectangle in thesource
framebuffer object to thetargetRect
rectangle in thetarget
framebuffer object.If
source
ortarget
isNone
, the default framebuffer will be used instead of a framebuffer object as source or target respectively.The
buffers
parameter should be a mask consisting of any combination ofGL_COLOR_BUFFER_BIT
,GL_DEPTH_BUFFER_BIT
, andGL_STENCIL_BUFFER_BIT
. Any buffer type that is not present both in the source and target buffers is ignored.The
sourceRect
andtargetRect
rectangles may have different sizes; in this casebuffers
should not containGL_DEPTH_BUFFER_BIT
orGL_STENCIL_BUFFER_BIT
. Thefilter
parameter should be set toGL_LINEAR
orGL_NEAREST
, and specifies whether linear or nearest interpolation should be used when scaling is performed.If
source
equalstarget
a copy is performed within the same buffer. Results are undefined if the source and target rectangles overlap and have different sizes. The sizes must also be the same if any of the framebuffer objects are multisample framebuffers.Note that the scissor test will restrict the blit area if enabled.
This function will have no effect unless
hasOpenGLFramebufferBlit()
returns true.See also
- PySide2.QtOpenGL.QGLFramebufferObject.drawTexture(point, textureId[, textureTarget=GL_TEXTURE_2D])¶
- Parameters:
point –
PySide2.QtCore.QPointF
textureId –
GLuint
textureTarget –
GLenum
- PySide2.QtOpenGL.QGLFramebufferObject.drawTexture(target, textureId[, textureTarget=GL_TEXTURE_2D])
- Parameters:
target –
PySide2.QtCore.QRectF
textureId –
GLuint
textureTarget –
GLenum
- PySide2.QtOpenGL.QGLFramebufferObject.format()¶
- Return type:
Returns the format of this framebuffer object.
- PySide2.QtOpenGL.QGLFramebufferObject.handle()¶
- Return type:
GLuint
Returns the GL framebuffer object handle for this framebuffer object (returned by the
glGenFrameBuffersEXT()
function). This handle can be used to attach new images or buffers to the framebuffer. The user is responsible for cleaning up and destroying these objects.
- static PySide2.QtOpenGL.QGLFramebufferObject.hasOpenGLFramebufferBlit()¶
- Return type:
bool
Returns
true
if the OpenGLGL_EXT_framebuffer_blit
extension is present on this system; otherwise returnsfalse
.See also
- static PySide2.QtOpenGL.QGLFramebufferObject.hasOpenGLFramebufferObjects()¶
- Return type:
bool
Returns
true
if the OpenGLGL_EXT_framebuffer_object
extension is present on this system; otherwise returnsfalse
.
- PySide2.QtOpenGL.QGLFramebufferObject.isBound()¶
- Return type:
bool
Returns
true
if the framebuffer object is currently bound to a context, otherwise false is returned.
- PySide2.QtOpenGL.QGLFramebufferObject.isValid()¶
- Return type:
bool
Returns
true
if the framebuffer object is valid.The framebuffer can become invalid if the initialization process fails, the user attaches an invalid buffer to the framebuffer object, or a non-power of two width/height is specified as the texture size if the texture target is
GL_TEXTURE_2D
. The non-power of two limitation does not apply if the OpenGL version is 2.0 or higher, or if the GL_ARB_texture_non_power_of_two extension is present.The framebuffer can also become invalid if the
QGLContext
that the framebuffer was created within is destroyed and there are no other shared contexts that can take over ownership of the framebuffer.
- PySide2.QtOpenGL.QGLFramebufferObject.release()¶
- Return type:
bool
Switches rendering back to the default, windowing system provided framebuffer. Returns
true
upon success, false otherwise.See also
- PySide2.QtOpenGL.QGLFramebufferObject.size()¶
- Return type:
Returns the size of the texture attached to this framebuffer object.
- PySide2.QtOpenGL.QGLFramebufferObject.texture()¶
- Return type:
GLuint
Returns the texture id for the texture attached as the default rendering target in this framebuffer object. This texture id can be bound as a normal texture in your own GL code.
If a multisample framebuffer object is used then the value returned from this function will be invalid.
- PySide2.QtOpenGL.QGLFramebufferObject.toImage()¶
- Return type:
Returns the contents of this framebuffer object as a
QImage
.The returned image has a format of premultiplied ARGB32 or RGB32. The latter is used only when internalTextureFormat() is set to
GL_RGB
.If the rendering in the framebuffer was not done with premultiplied alpha in mind, create a wrapper
QImage
with a non-premultiplied format. This is necessary before performing operations likesave()
because otherwise the image data would get unpremultiplied, even though it was not premultiplied in the first place. To create such a wrapper without performing a copy of the pixel data, do the following:QImage fboImage(fbo.toImage()); QImage image(fboImage.constBits(), fboImage.width(), fboImage.height(), QImage::Format_ARGB32);
On QNX the back buffer is not preserved when a buffer swap occures. So this function might return old content.
© 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.