QOpenGLFramebufferObject¶
The
QOpenGLFramebufferObjectclass encapsulates an OpenGL framebuffer object. More…

New in version 5.0.
Synopsis¶
Functions¶
def
addColorAttachment(size[, internalFormat=0])def
addColorAttachment(width, height[, internalFormat=0])def
attachment()def
bind()def
format()def
handle()def
height()def
isBound()def
isValid()def
release()def
setAttachment(attachment)def
size()def
sizes()def
takeTexture()def
takeTexture(colorAttachmentIndex)def
texture()def
textures()def
toImage()def
toImage(flipped)def
toImage(flipped, colorAttachmentIndex)def
width()
Static functions¶
def
bindDefault()def
blitFramebuffer(target, source[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])def
blitFramebuffer(target, targetRect, source, sourceRect, buffers, filter, readColorAttachmentIndex, drawColorAttachmentIndex)def
blitFramebuffer(target, targetRect, source, sourceRect, buffers, filter, readColorAttachmentIndex, drawColorAttachmentIndex, restorePolicy)def
blitFramebuffer(target, targetRect, source, sourceRect[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])def
hasOpenGLFramebufferBlit()def
hasOpenGLFramebufferObjects()
Detailed Description¶
The
QOpenGLFramebufferObjectclass encapsulates an OpenGL framebuffer object, defined by theGL_EXT_framebuffer_objectextension. It provides a rendering surface that can be painted on with aQPainterwith the help ofQOpenGLPaintDevice, or rendered to using native OpenGL calls. This surface can be bound and used as a regular texture in your own OpenGL drawing code. By default, theQOpenGLFramebufferObjectclass generates a 2D OpenGL texture (using theGL_TEXTURE_2Dtarget), which is used as the internal rendering target.It is important to have a current OpenGL context when creating a
QOpenGLFramebufferObject, otherwise initialization will fail.Create the QOpenGLFrameBufferObject instance with the
CombinedDepthStencilattachment if you wantQPainterto render correctly. Note that you need to create aQOpenGLFramebufferObjectwith 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 aQOpenGLFramebufferObjectFormatparameter, and set thesamples()property to a non-zero value.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_ATTACHMENT0attachment in the framebuffer object.Multiple render targets are also supported, in case the OpenGL implementation supports this. Here there will be multiple textures (or, in case of multisampling, renderbuffers) present and each of them will get attached to
GL_COLOR_ATTACHMENT0,1,2, …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 QOpenGLContext::blitFramebuffer().
It is possible to draw into a
QOpenGLFramebufferObjectusingQPainterandQOpenGLPaintDevicein a separate thread.
- class PySide2.QtGui.QOpenGLFramebufferObject(size[, target=GL_TEXTURE_2D])¶
PySide2.QtGui.QOpenGLFramebufferObject(size, attachment[, target=GL_TEXTURE_2D[, internalFormat=0]])
PySide2.QtGui.QOpenGLFramebufferObject(size, format)
PySide2.QtGui.QOpenGLFramebufferObject(width, height[, target=GL_TEXTURE_2D])
PySide2.QtGui.QOpenGLFramebufferObject(width, height, attachment[, target=GL_TEXTURE_2D[, internalFormat=0]])
PySide2.QtGui.QOpenGLFramebufferObject(width, height, format)
- param format:
- param size:
- param target:
GLenum- param width:
int
- param internalFormat:
GLenum- param height:
int
- param attachment:
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given
size.The
attachmentparameter describes the depth/stencil buffer configuration,targetthe texture target andinternalFormatthe internal texture format. The default texture target isGL_TEXTURE_2D, while the default internal format isGL_RGBA8for desktop OpenGL andGL_RGBAfor OpenGL/ES.See also
Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the given
widthandheight.Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given
widthandheight.The
attachmentparameter describes the depth/stencil buffer configuration,targetthe texture target andinternalFormatthe internal texture format. The default texture target isGL_TEXTURE_2D, while the default internal format isGL_RGBA8for desktop OpenGL andGL_RGBAfor OpenGL/ES.See also
- PySide2.QtGui.QOpenGLFramebufferObject.Attachment¶
This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created.
Constant
Description
QOpenGLFramebufferObject.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.
QOpenGLFramebufferObject.CombinedDepthStencil
If the
GL_EXT_packed_depth_stencilextension is present, a combined depth and stencil buffer is attached. If the extension is not present, only a depth buffer is attached.QOpenGLFramebufferObject.Depth
A depth buffer is attached to the framebuffer object.
See also
- PySide2.QtGui.QOpenGLFramebufferObject.FramebufferRestorePolicy¶
This enum type is used to configure the behavior related to restoring framebuffer bindings when calling
blitFramebuffer().Constant
Description
QOpenGLFramebufferObject.DontRestoreFramebufferBinding
Do not restore the previous framebuffer binding. The caller is responsible for tracking and setting the framebuffer binding as needed.
QOpenGLFramebufferObject.RestoreFramebufferBindingToDefault
After the blit operation, bind the default framebuffer.
QOpenGLFramebufferObject.RestoreFrameBufferBinding
Restore the previously bound framebuffer. This is potentially expensive because of the need to query the currently bound framebuffer.
See also
New in version 5.7.
- PySide2.QtGui.QOpenGLFramebufferObject.addColorAttachment(size[, internalFormat=0])¶
- Parameters:
size –
PySide2.QtCore.QSizeinternalFormat –
GLenum
Creates and attaches an additional texture or renderbuffer of
sizewidth and height.There is always an attachment at GL_COLOR_ATTACHMENT0. Call this function to set up additional attachments at GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, …
When
internalFormatis not0, it specifies the internal format of the texture or renderbuffer. Otherwise a default of GL_RGBA or GL_RGBA8 is used.Note
This is only functional when multiple render targets are supported by the OpenGL implementation. When that is not the case, the function will not add any additional color attachments. Call
hasOpenGLFeature()withMultipleRenderTargetsat runtime to check if MRT is supported.Note
The internal format of the color attachments may differ but there may be limitations on the supported combinations, depending on the drivers.
Note
The size of the color attachments may differ but rendering is limited to the area that fits all the attachments, according to the OpenGL specification. Some drivers may not be fully conformant in this respect, however.
- PySide2.QtGui.QOpenGLFramebufferObject.addColorAttachment(width, height[, internalFormat=0])
- Parameters:
width – int
height – int
internalFormat –
GLenum
This is an overloaded function.
Creates and attaches an additional texture or renderbuffer of size
widthandheight.When
internalFormatis not0, it specifies the internal format of the texture or renderbuffer. Otherwise a default of GL_RGBA or GL_RGBA8 is used.
- PySide2.QtGui.QOpenGLFramebufferObject.attachment()¶
- Return type:
Returns the status of the depth and stencil buffers attached to this framebuffer object.
See also
- PySide2.QtGui.QOpenGLFramebufferObject.bind()¶
- Return type:
bool
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object. Returns
trueupon success, false otherwise.Note
If
takeTexture()was called, a new texture is created and associated with the framebuffer object. This is potentially expensive and changes the context state (the currently bound texture).See also
- static PySide2.QtGui.QOpenGLFramebufferObject.bindDefault()¶
- Return type:
bool
Switches rendering back to the default, windowing system provided framebuffer. Returns
trueupon success, false otherwise.
- static PySide2.QtGui.QOpenGLFramebufferObject.blitFramebuffer(target, source[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])¶
- Parameters:
buffers –
GLbitfieldfilter –
GLenum
This is an overloaded function.
Convenience overload to blit between two framebuffer objects.
- static PySide2.QtGui.QOpenGLFramebufferObject.blitFramebuffer(target, targetRect, source, sourceRect[, buffers=GL_COLOR_BUFFER_BIT[, filter=GL_NEAREST]])
- Parameters:
targetRect –
PySide2.QtCore.QRectsourceRect –
PySide2.QtCore.QRectbuffers –
GLbitfieldfilter –
GLenum
This is an overloaded function.
* Convenience overload to blit between two framebuffer objects.
- static PySide2.QtGui.QOpenGLFramebufferObject.blitFramebuffer(target, targetRect, source, sourceRect, buffers, filter, readColorAttachmentIndex, drawColorAttachmentIndex)
- Parameters:
targetRect –
PySide2.QtCore.QRectsourceRect –
PySide2.QtCore.QRectbuffers –
GLbitfieldfilter –
GLenumreadColorAttachmentIndex – int
drawColorAttachmentIndex – int
This is an overloaded function.
Convenience overload to blit between two framebuffer objects and to restore the previous framebuffer binding. Equivalent to calling
blitFramebuffer(target, targetRect, source, sourceRect, buffers, filter, readColorAttachmentIndex, drawColorAttachmentIndex,RestoreFrameBufferBinding).
- static PySide2.QtGui.QOpenGLFramebufferObject.blitFramebuffer(target, targetRect, source, sourceRect, buffers, filter, readColorAttachmentIndex, drawColorAttachmentIndex, restorePolicy)
- Parameters:
targetRect –
PySide2.QtCore.QRectsourceRect –
PySide2.QtCore.QRectbuffers –
GLbitfieldfilter –
GLenumreadColorAttachmentIndex – int
drawColorAttachmentIndex – int
restorePolicy –
FramebufferRestorePolicy
Blits from the
sourceRectrectangle in thesourceframebuffer object to thetargetRectrectangle in thetargetframebuffer object.If
sourceortargetis 0, the default framebuffer will be used instead of a framebuffer object as source or target respectively.This function will have no effect unless
hasOpenGLFramebufferBlit()returns true.The
buffersparameter 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
sourceRectandtargetRectrectangles may have different sizes; in this casebuffersshould not containGL_DEPTH_BUFFER_BITorGL_STENCIL_BUFFER_BIT. Thefilterparameter should be set toGL_LINEARorGL_NEAREST, and specifies whether linear or nearest interpolation should be used when scaling is performed.If
sourceequalstargeta 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
The scissor test will restrict the blit area if enabled.
When multiple render targets are in use,
readColorAttachmentIndexanddrawColorAttachmentIndexspecify the index of the color attachments in the source and destination framebuffers.The
restorePolicydetermines if the framebuffer that was bound prior to calling this function should be restored, or if the default framebuffer should be bound before returning, of if the caller is responsible for tracking and setting the bound framebuffer. Restoring the previous framebuffer can be relatively expensive due to the call toglGetIntegervwhich on some OpenGL drivers may imply a pipeline stall.See also
- PySide2.QtGui.QOpenGLFramebufferObject.format()¶
- Return type:
Returns the format of this framebuffer object.
- PySide2.QtGui.QOpenGLFramebufferObject.handle()¶
- Return type:
GLuint
Returns the OpenGL 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.QtGui.QOpenGLFramebufferObject.hasOpenGLFramebufferBlit()¶
- Return type:
bool
Returns
trueif the OpenGLGL_EXT_framebuffer_blitextension is present on this system; otherwise returnsfalse.See also
- static PySide2.QtGui.QOpenGLFramebufferObject.hasOpenGLFramebufferObjects()¶
- Return type:
bool
Returns
trueif the OpenGLGL_EXT_framebuffer_objectextension is present on this system; otherwise returnsfalse.
- PySide2.QtGui.QOpenGLFramebufferObject.height()¶
- Return type:
int
Returns the height of the framebuffer object attachments.
- PySide2.QtGui.QOpenGLFramebufferObject.isBound()¶
- Return type:
bool
Returns
trueif the framebuffer object is currently bound to the current context, otherwise false is returned.
- PySide2.QtGui.QOpenGLFramebufferObject.isValid()¶
- Return type:
bool
Returns
trueif 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
QOpenGLContextthat the framebuffer was created within is destroyed and there are no other shared contexts that can take over ownership of the framebuffer.
- PySide2.QtGui.QOpenGLFramebufferObject.release()¶
- Return type:
bool
Switches rendering back to the default, windowing system provided framebuffer. Returns
trueupon success, false otherwise.See also
- PySide2.QtGui.QOpenGLFramebufferObject.setAttachment(attachment)¶
- Parameters:
attachment –
Attachment
Sets the attachments of the framebuffer object to
attachment.This can be used to free or reattach the depth and stencil buffer attachments as needed.
Note
This function alters the current framebuffer binding.
See also
- PySide2.QtGui.QOpenGLFramebufferObject.size()¶
- Return type:
Returns the size of the color and depth/stencil attachments attached to this framebuffer object.
- PySide2.QtGui.QOpenGLFramebufferObject.sizes()¶
- Return type:
Returns the sizes of all color attachments attached to this framebuffer object.
- PySide2.QtGui.QOpenGLFramebufferObject.takeTexture()¶
- Return type:
GLuint
Returns the texture id for the texture attached to this framebuffer object. The ownership of the texture is transferred to the caller.
If the framebuffer object is currently bound, an implicit
release()will be done. During the next call tobind()a new texture will be created.If a multisample framebuffer object is used, then there is no texture and the return value from this function will be invalid. Similarly, incomplete framebuffer objects will also return 0.
- PySide2.QtGui.QOpenGLFramebufferObject.takeTexture(colorAttachmentIndex)
- Parameters:
colorAttachmentIndex – int
- Return type:
GLuint
This is an overloaded function.
Returns the texture id for the texture attached to the color attachment of index
colorAttachmentIndexof this framebuffer object. The ownership of the texture is transferred to the caller.When
colorAttachmentIndexis0, the behavior is identical to the parameter-less variant of this function.If the framebuffer object is currently bound, an implicit
release()will be done. During the next call tobind()a new texture will be created.If a multisample framebuffer object is used, then there is no texture and the return value from this function will be invalid. Similarly, incomplete framebuffer objects will also return 0.
- PySide2.QtGui.QOpenGLFramebufferObject.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 OpenGL code.
If a multisample framebuffer object is used then the value returned from this function will be invalid.
When multiple textures are attached, the return value is the ID of the first one.
See also
- PySide2.QtGui.QOpenGLFramebufferObject.textures()¶
- Return type:
Returns the texture id for all attached textures.
If a multisample framebuffer object is used, then an empty vector is returned.
See also
- PySide2.QtGui.QOpenGLFramebufferObject.toImage()¶
- Return type:
This is an overloaded function.
Returns the contents of this framebuffer object as a
QImage. This method flips the image from OpenGL coordinates to raster coordinates.
- PySide2.QtGui.QOpenGLFramebufferObject.toImage(flipped)
- Parameters:
flipped – bool
- Return type:
Returns the contents of this framebuffer object as a
QImage.If
flippedis true the image is flipped from OpenGL coordinates to raster coordinates. If used together withQOpenGLPaintDevice,flippedshould be the opposite of the value ofpaintFlipped().The returned image has a format of premultiplied ARGB32 or RGB32. The latter is used only when internalTextureFormat() is set to
GL_RGB. Since Qt 5.2 the function will fall back to premultiplied RGBA8888 or RGBx8888 when reading to (A)RGB32 is not supported, and this includes OpenGL ES. Since Qt 5.4 an A2BGR30 image is returned if the internal format is RGB10_A2, and since Qt 5.12 a RGBA64 image is return if the internal format is RGBA16.If the rendering in the framebuffer was not done with premultiplied alpha in mind, create a wrapper
QImagewith 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);
For multisampled framebuffer objects the samples are resolved using the
GL_EXT_framebuffer_blitextension. If the extension is not available, the contents of the returned image is undefined.For singlesampled framebuffers the contents is retrieved via
glReadPixels. This is a potentially expensive and inefficient operation. Therefore it is recommended that this function is used as seldom as possible.See also
- PySide2.QtGui.QOpenGLFramebufferObject.toImage(flipped, colorAttachmentIndex)
- Parameters:
flipped – bool
colorAttachmentIndex – int
- Return type:
This is an overloaded function.
Returns the contents of the color attachment of index
colorAttachmentIndexof this framebuffer object as aQImage. This method flips the image from OpenGL coordinates to raster coordinates whenflippedis set totrue.Note
This overload is only fully functional when multiple render targets are supported by the OpenGL implementation. When that is not the case, only one color attachment will be set up.
- PySide2.QtGui.QOpenGLFramebufferObject.width()¶
- Return type:
int
Returns the width of the framebuffer object attachments.
© 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.