Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QOpenGLFramebufferObject Class Reference

The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object. More...

#include <qopenglframebufferobject.h>

+ Collaboration diagram for QOpenGLFramebufferObject:

Public Types

enum  Attachment { NoAttachment , CombinedDepthStencil , Depth }
 This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created. More...
 
enum  FramebufferRestorePolicy { DontRestoreFramebufferBinding , RestoreFramebufferBindingToDefault , RestoreFrameBufferBinding }
 

Public Member Functions

 QOpenGLFramebufferObject (const QSize &size, GLenum target=GL_TEXTURE_2D)
 Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the size size.
 
 QOpenGLFramebufferObject (int width, int height, GLenum target=GL_TEXTURE_2D)
 Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the given width and height.
 
 QOpenGLFramebufferObject (const QSize &size, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internalFormat=0)
 Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given size.
 
 QOpenGLFramebufferObject (int width, int height, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internalFormat=0)
 Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given width and height.
 
 QOpenGLFramebufferObject (const QSize &size, const QOpenGLFramebufferObjectFormat &format)
 Constructs an OpenGL framebuffer object of the given size based on the supplied format.
 
 QOpenGLFramebufferObject (int width, int height, const QOpenGLFramebufferObjectFormat &format)
 Constructs an OpenGL framebuffer object of the given width and height based on the supplied format.
 
virtual ~QOpenGLFramebufferObject ()
 Destroys the framebuffer object and frees any allocated resources.
 
void addColorAttachment (const QSize &size, GLenum internalFormat=0)
 Creates and attaches an additional texture or renderbuffer of size width and height.
 
void addColorAttachment (int width, int height, GLenum internalFormat=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates and attaches an additional texture or renderbuffer of size width and height.
 
QOpenGLFramebufferObjectFormat format () const
 Returns the format of this framebuffer object.
 
bool isValid () const
 Returns true if the framebuffer object is valid.
 
bool isBound () const
 Returns true if the framebuffer object is currently bound to the current context, otherwise false is returned.
 
bool bind ()
 Switches rendering from the default, windowing system provided framebuffer to this framebuffer object.
 
bool release ()
 Switches rendering back to the default, windowing system provided framebuffer.
 
int width () const
 Returns the width of the framebuffer object attachments.
 
int height () const
 Returns the height of the framebuffer object attachments.
 
GLuint texture () const
 Returns the texture id for the texture attached as the default rendering target in this framebuffer object.
 
QList< GLuinttextures () const
 Returns the texture id for all attached textures.
 
GLuint takeTexture ()
 Returns the texture id for the texture attached to this framebuffer object.
 
GLuint takeTexture (int colorAttachmentIndex)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the texture id for the texture attached to the color attachment of index colorAttachmentIndex of this framebuffer object.
 
QSize size () const
 
QList< QSizesizes () const
 
QImage toImage (bool flipped=true) const
 Returns the contents of this framebuffer object as a QImage.
 
QImage toImage (bool flipped, int colorAttachmentIndex) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the contents of the color attachment of index colorAttachmentIndex of this framebuffer object as a QImage.
 
Attachment attachment () const
 Returns the status of the depth and stencil buffers attached to this framebuffer object.
 
void setAttachment (Attachment attachment)
 Sets the attachments of the framebuffer object to attachment.
 
GLuint handle () const
 Returns the OpenGL framebuffer object handle for this framebuffer object (returned by the {glGenFrameBuffersEXT()} function).
 

Static Public Member Functions

static bool bindDefault ()
 Switches rendering back to the default, windowing system provided framebuffer.
 
static bool hasOpenGLFramebufferObjects ()
 Returns true if the OpenGL {GL_EXT_framebuffer_object} extension is present on this system; otherwise returns false.
 
static bool hasOpenGLFramebufferBlit ()
 Returns true if the OpenGL {GL_EXT_framebuffer_blit} extension is present on this system; otherwise returns false.
 
static void blitFramebuffer (QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers, GLenum filter, int readColorAttachmentIndex, int drawColorAttachmentIndex, FramebufferRestorePolicy restorePolicy)
 
static void blitFramebuffer (QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers, GLenum filter, int readColorAttachmentIndex, int drawColorAttachmentIndex)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Convenience overload to blit between two framebuffer objects and to restore the previous framebuffer binding.
 
static void blitFramebuffer (QOpenGLFramebufferObject *target, const QRect &targetRect, QOpenGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers=GL_COLOR_BUFFER_BIT, GLenum filter=GL_NEAREST)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Convenience overload to blit between two framebuffer objects.
 
static void blitFramebuffer (QOpenGLFramebufferObject *target, QOpenGLFramebufferObject *source, GLbitfield buffers=GL_COLOR_BUFFER_BIT, GLenum filter=GL_NEAREST)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Convenience overload to blit between two framebuffer objects.
 

Friends

class QOpenGLPaintDevice
 
class QOpenGLFBOGLPaintDevice
 

Detailed Description

The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object.

Since
5.0 \inmodule QtOpenGL

The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object, defined by the {GL_EXT_framebuffer_object} extension. It provides a rendering surface that can be painted on with a QPainter with the help of QOpenGLPaintDevice, 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, the QOpenGLFramebufferObject class generates a 2D OpenGL texture (using the {GL_TEXTURE_2D} target), 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 CombinedDepthStencil attachment if you want QPainter to render correctly. Note that you need to create a QOpenGLFramebufferObject with more than one sample per pixel for primitives to be antialiased when drawing using a QPainter. To create a multisample framebuffer object you should use one of the constructors that take a QOpenGLFramebufferObjectFormat parameter, and set the QOpenGLFramebufferObjectFormat::samples() 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_ATTACHMENT0 attachment 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 QOpenGLFramebufferObject using QPainter and QOpenGLPaintDevice in a separate thread.

Definition at line 30 of file qopenglframebufferobject.h.

Member Enumeration Documentation

◆ Attachment

This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created.

\value 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.

\value 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.

\value Depth A depth buffer is attached to the framebuffer object.

See also
attachment()
Enumerator
NoAttachment 
CombinedDepthStencil 
Depth 

Definition at line 34 of file qopenglframebufferobject.h.

◆ FramebufferRestorePolicy

Since
5.7

This enum type is used to configure the behavior related to restoring framebuffer bindings when calling blitFramebuffer().

\value DontRestoreFramebufferBinding Do not restore the previous framebuffer binding. The caller is responsible for tracking and setting the framebuffer binding as needed.

\value RestoreFramebufferBindingToDefault After the blit operation, bind the default framebuffer.

\value RestoreFrameBufferBinding Restore the previously bound framebuffer. This is potentially expensive because of the need to query the currently bound framebuffer.

See also
blitFramebuffer()
Enumerator
DontRestoreFramebufferBinding 
RestoreFramebufferBindingToDefault 
RestoreFrameBufferBinding 

Definition at line 89 of file qopenglframebufferobject.h.

Constructor & Destructor Documentation

◆ QOpenGLFramebufferObject() [1/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( const QSize & size,
GLenum target = GL_TEXTURE_2D )
explicit

Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the size size.

The texture is bound to the GL_COLOR_ATTACHMENT0 target in the framebuffer object.

The target parameter is used to specify the OpenGL texture target. The default target is GL_TEXTURE_2D. Keep in mind that GL_TEXTURE_2D textures must have a power of 2 width and height (e.g. 256x512), unless you are using OpenGL 2.0 or higher.

By default, no depth and stencil buffers are attached. This behavior can be toggled using one of the overloaded constructors.

The default internal texture format is GL_RGBA8 for desktop OpenGL, and GL_RGBA for OpenGL/ES.

It is important that you have a current OpenGL context set when creating the QOpenGLFramebufferObject, otherwise the initialization will fail.

See also
size(), texture(), attachment()

Definition at line 924 of file qopenglframebufferobject.cpp.

References d, effectiveInternalFormat(), and NoAttachment.

+ Here is the call graph for this function:

◆ QOpenGLFramebufferObject() [2/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( int width,
int height,
GLenum target = GL_TEXTURE_2D )

Constructs an OpenGL framebuffer object and binds a 2D OpenGL texture to the buffer of the given width and height.

See also
size(), texture()

Definition at line 938 of file qopenglframebufferobject.cpp.

◆ QOpenGLFramebufferObject() [3/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( const QSize & size,
Attachment attachment,
GLenum target = GL_TEXTURE_2D,
GLenum internalFormat = 0 )

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 and internalFormat the internal texture format. The default texture target is GL_TEXTURE_2D, while the default internal format is GL_RGBA8 for desktop OpenGL and GL_RGBA for OpenGL/ES.

See also
size(), texture(), attachment()

Definition at line 1002 of file qopenglframebufferobject.cpp.

References d, and effectiveInternalFormat().

+ Here is the call graph for this function:

◆ QOpenGLFramebufferObject() [4/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( int width,
int height,
Attachment attachment,
GLenum target = GL_TEXTURE_2D,
GLenum internalFormat = 0 )

Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given width and height.

The attachment parameter describes the depth/stencil buffer configuration, target the texture target and internalFormat the internal texture format. The default texture target is GL_TEXTURE_2D, while the default internal format is GL_RGBA8 for desktop OpenGL and GL_RGBA for OpenGL/ES.

See also
size(), texture(), attachment()

Definition at line 981 of file qopenglframebufferobject.cpp.

References d, and effectiveInternalFormat().

+ Here is the call graph for this function:

◆ QOpenGLFramebufferObject() [5/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( const QSize & size,
const QOpenGLFramebufferObjectFormat & format )

Constructs an OpenGL framebuffer object of the given size based on the supplied format.

Definition at line 949 of file qopenglframebufferobject.cpp.

References d.

◆ QOpenGLFramebufferObject() [6/6]

QOpenGLFramebufferObject::QOpenGLFramebufferObject ( int width,
int height,
const QOpenGLFramebufferObjectFormat & format )

Constructs an OpenGL framebuffer object of the given width and height based on the supplied format.

Definition at line 963 of file qopenglframebufferobject.cpp.

◆ ~QOpenGLFramebufferObject()

QOpenGLFramebufferObject::~QOpenGLFramebufferObject ( )
virtual

Destroys the framebuffer object and frees any allocated resources.

Definition at line 1014 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, QOpenGLContextPrivate::get(), isBound(), and release().

+ Here is the call graph for this function:

Member Function Documentation

◆ addColorAttachment() [1/2]

void QOpenGLFramebufferObject::addColorAttachment ( const QSize & size,
GLenum internalFormat = 0 )

Creates and attaches an additional texture or renderbuffer of size width 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 internalFormat is not 0, 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 QOpenGLFunctions::hasOpenGLFeature() with QOpenGLFunctions::MultipleRenderTargets at runtime to check if MRT is supported.
The internal format of the color attachments may differ but there may be limitations on the supported combinations, depending on the drivers.
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.
Since
5.6

Definition at line 1069 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, effectiveInternalFormat(), GLint(), QOpenGLFunctions::MultipleRenderTargets, and qWarning.

Referenced by addColorAttachment().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addColorAttachment() [2/2]

void QOpenGLFramebufferObject::addColorAttachment ( int width,
int height,
GLenum internalFormat = 0 )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates and attaches an additional texture or renderbuffer of size width and height.

When internalFormat is not 0, it specifies the internal format of the texture or renderbuffer. Otherwise a default of GL_RGBA or GL_RGBA8 is used.

Since
5.6

Definition at line 1099 of file qopenglframebufferobject.cpp.

References addColorAttachment().

+ Here is the call graph for this function:

◆ attachment()

QOpenGLFramebufferObject::Attachment QOpenGLFramebufferObject::attachment ( ) const

Returns the status of the depth and stencil buffers attached to this framebuffer object.

Definition at line 1630 of file qopenglframebufferobject.cpp.

References d, and NoAttachment.

◆ bind()

bool QOpenGLFramebufferObject::bind ( )

Switches rendering from the default, windowing system provided framebuffer to this framebuffer object.

Returns true upon 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
release()

Definition at line 1141 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, QOpenGLContextPrivate::get(), GL_FRAMEBUFFER, i, isValid(), qWarning, and QOpenGLContext::shareGroup().

Referenced by QOpenGLWindowPrivate::beginPaint(), QtWaylandClient::QWaylandEglWindow::bindContentFBO(), QOpenGLWindowPrivate::bindFBO(), QOpenGLWidgetPaintDevice::ensureActiveTarget(), QOpenGLWidgetPrivate::grabFramebuffer(), QWaylandQuickCompositor::grabSurface(), QSGFramebufferObjectNode::render(), and toImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bindDefault()

bool QOpenGLFramebufferObject::bindDefault ( )
static

Switches rendering back to the default, windowing system provided framebuffer.

Returns true upon success, false otherwise.

See also
bind(), release()

Definition at line 1582 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), QOpenGLContext::functions(), QOpenGLContextPrivate::get(), GL_FRAMEBUFFER, QOpenGLFunctions::glBindFramebuffer(), and qWarning.

Referenced by QOpenGLWindowPrivate::bindFBO(), QSGFramebufferObjectNode::render(), and QQuickOpenGLUtils::resetOpenGLState().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ blitFramebuffer() [1/4]

void QOpenGLFramebufferObject::blitFramebuffer ( QOpenGLFramebufferObject * target,
const QRect & targetRect,
QOpenGLFramebufferObject * source,
const QRect & sourceRect,
GLbitfield buffers,
GLenum filter,
int readColorAttachmentIndex,
int drawColorAttachmentIndex )
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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).

Definition at line 1872 of file qopenglframebufferobject.cpp.

References blitFramebuffer(), and RestoreFrameBufferBinding.

+ Here is the call graph for this function:

◆ blitFramebuffer() [2/4]

void QOpenGLFramebufferObject::blitFramebuffer ( QOpenGLFramebufferObject * target,
const QRect & targetRect,
QOpenGLFramebufferObject * source,
const QRect & sourceRect,
GLbitfield buffers,
GLenum filter,
int readColorAttachmentIndex,
int drawColorAttachmentIndex,
QOpenGLFramebufferObject::FramebufferRestorePolicy restorePolicy )
static
Since
5.7

Blits from the sourceRect rectangle in the source framebuffer object to the targetRect rectangle in the target framebuffer object.

If source or target is 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 buffers parameter should be a mask consisting of any combination of GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, and GL_STENCIL_BUFFER_BIT. Any buffer type that is not present both in the source and target buffers is ignored.

The sourceRect and targetRect rectangles may have different sizes; in this case buffers should not contain GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT. The filter parameter should be set to GL_LINEAR or GL_NEAREST, and specifies whether linear or nearest interpolation should be used when scaling is performed.

If source equals target 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
The scissor test will restrict the blit area if enabled.

When multiple render targets are in use, readColorAttachmentIndex and drawColorAttachmentIndex specify the index of the color attachments in the source and destination framebuffers.

The restorePolicy determines 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 to {glGetIntegerv} which on some OpenGL drivers may imply a pipeline stall.

See also
hasOpenGLFramebufferBlit()

Definition at line 1798 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), DontRestoreFramebufferBinding, QOpenGLExtensions::FramebufferBlit, GL_COLOR_ATTACHMENT0, GL_DRAW_FRAMEBUFFER, GL_FRAMEBUFFER, GL_FRAMEBUFFER_BINDING, GL_READ_FRAMEBUFFER, QOpenGLFunctions::glBindFramebuffer(), QOpenGLExtraFunctions::glBlitFramebuffer(), QOpenGLExtraFunctions::glDrawBuffers(), GLenum(), GLint(), QOpenGLExtraFunctions::glReadBuffer(), GLuint, QOpenGLExtensions::hasOpenGLExtension(), QOpenGLFunctions::hasOpenGLFeature(), QRect::height(), QRect::left(), QOpenGLFunctions::MultipleRenderTargets, RestoreFrameBufferBinding, RestoreFramebufferBindingToDefault, QRect::top(), and QRect::width().

Referenced by blitFramebuffer(), blitFramebuffer(), blitFramebuffer(), QSGFramebufferObjectNode::render(), QOpenGLWidgetPrivate::resolveSamplesForBuffer(), and toImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ blitFramebuffer() [3/4]

void QOpenGLFramebufferObject::blitFramebuffer ( QOpenGLFramebufferObject * target,
const QRect & targetRect,
QOpenGLFramebufferObject * source,
const QRect & sourceRect,
GLbitfield buffers = GL_COLOR_BUFFER_BIT,
GLenum filter = GL_NEAREST )
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Convenience overload to blit between two framebuffer objects.

Definition at line 1726 of file qopenglframebufferobject.cpp.

References blitFramebuffer().

+ Here is the call graph for this function:

◆ blitFramebuffer() [4/4]

void QOpenGLFramebufferObject::blitFramebuffer ( QOpenGLFramebufferObject * target,
QOpenGLFramebufferObject * source,
GLbitfield buffers = GL_COLOR_BUFFER_BIT,
GLenum filter = GL_NEAREST )
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Convenience overload to blit between two framebuffer objects.

Definition at line 1697 of file qopenglframebufferobject.cpp.

References blitFramebuffer(), and QSize::isEmpty().

+ Here is the call graph for this function:

◆ format()

QOpenGLFramebufferObjectFormat QOpenGLFramebufferObject::format ( ) const

Returns the format of this framebuffer object.

Definition at line 1347 of file qopenglframebufferobject.cpp.

References d.

Referenced by QOpenGLCompositor::grabToFrameBufferObject(), and toImage().

+ Here is the caller graph for this function:

◆ handle()

GLuint QOpenGLFramebufferObject::handle ( ) const

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.

Definition at line 1619 of file qopenglframebufferobject.cpp.

References d.

Referenced by QtWaylandClient::QWaylandEglWindow::contentFBO(), QOpenGLWindowPrivate::endPaint(), and QOpenGLWidgetPaintDevice::ensureActiveTarget().

+ Here is the caller graph for this function:

◆ hasOpenGLFramebufferBlit()

bool QOpenGLFramebufferObject::hasOpenGLFramebufferBlit ( )
static

Returns true if the OpenGL {GL_EXT_framebuffer_blit} extension is present on this system; otherwise returns false.

See also
blitFramebuffer()

Definition at line 1686 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), QOpenGLExtensions::FramebufferBlit, and QOpenGLExtensions::hasOpenGLExtension().

Referenced by QOpenGLWindowPrivate::initialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasOpenGLFramebufferObjects()

bool QOpenGLFramebufferObject::hasOpenGLFramebufferObjects ( )
static

Returns true if the OpenGL {GL_EXT_framebuffer_object} extension is present on this system; otherwise returns false.

Definition at line 1605 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), and QOpenGLFunctions::Framebuffers.

+ Here is the call graph for this function:

◆ height()

int QOpenGLFramebufferObject::height ( ) const
inline

Returns the height of the framebuffer object attachments.

Definition at line 64 of file qopenglframebufferobject.h.

Referenced by QSGFramebufferObjectNode::render().

+ Here is the caller graph for this function:

◆ isBound()

bool QOpenGLFramebufferObject::isBound ( ) const

Returns true if the framebuffer object is currently bound to the current context, otherwise false is returned.

Definition at line 1667 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, GL_FRAMEBUFFER_BINDING, GLint(), and GLuint.

Referenced by ~QOpenGLFramebufferObject(), and takeTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValid()

bool QOpenGLFramebufferObject::isValid ( ) const

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 QOpenGLContext that the framebuffer was created within is destroyed and there are no other shared contexts that can take over ownership of the framebuffer.

Definition at line 1122 of file qopenglframebufferobject.cpp.

References d.

Referenced by bind(), release(), setAttachment(), and takeTexture().

+ Here is the caller graph for this function:

◆ release()

bool QOpenGLFramebufferObject::release ( )

Switches rendering back to the default, windowing system provided framebuffer.

Returns true upon success, false otherwise.

See also
bind()

Definition at line 1179 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, QOpenGLContext::defaultFramebufferObject(), QOpenGLContextPrivate::get(), GL_FRAMEBUFFER, isValid(), qWarning, and QOpenGLContext::shareGroup().

Referenced by ~QOpenGLFramebufferObject(), QOpenGLWindowPrivate::endPaint(), and takeTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setAttachment()

void QOpenGLFramebufferObject::setAttachment ( QOpenGLFramebufferObject::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.

Definition at line 1646 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, QOpenGLContextPrivate::get(), GL_FRAMEBUFFER, isValid(), qWarning, and QOpenGLContext::shareGroup().

+ Here is the call graph for this function:

◆ size()

QSize QOpenGLFramebufferObject::size ( ) const
Returns
the size of the color and depth/stencil attachments attached to this framebuffer object.

Definition at line 1310 of file qopenglframebufferobject.cpp.

References d.

Referenced by QOpenGLWindowPrivate::beginPaint(), QOpenGLWindowPrivate::endPaint(), QOpenGLCompositor::grabToFrameBufferObject(), and toImage().

+ Here is the caller graph for this function:

◆ sizes()

QList< QSize > QOpenGLFramebufferObject::sizes ( ) const
Returns
the sizes of all color attachments attached to this framebuffer object.
Since
5.6

Definition at line 1322 of file qopenglframebufferobject.cpp.

References d.

◆ takeTexture() [1/2]

GLuint QOpenGLFramebufferObject::takeTexture ( )

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 to bind() 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.

Since
5.3
See also
texture(), bind(), release()

Definition at line 1265 of file qopenglframebufferobject.cpp.

References takeTexture().

Referenced by takeTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ takeTexture() [2/2]

GLuint QOpenGLFramebufferObject::takeTexture ( int colorAttachmentIndex)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the texture id for the texture attached to the color attachment of index colorAttachmentIndex of this framebuffer object.

The ownership of the texture is transferred to the caller.

When colorAttachmentIndex is 0, 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 to bind() 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.

Since
5.6

Definition at line 1289 of file qopenglframebufferobject.cpp.

References QOpenGLContext::currentContext(), d, GLuint, isBound(), isValid(), release(), and QOpenGLContext::shareGroup().

+ Here is the call graph for this function:

◆ texture()

GLuint QOpenGLFramebufferObject::texture ( ) const

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
takeTexture(), textures()

Definition at line 1220 of file qopenglframebufferobject.cpp.

References d.

Referenced by QtWaylandClient::QWaylandEglWindow::contentTexture(), QOpenGLWindowPrivate::endPaint(), and QOpenGLWidgetPrivate::ensureRhiDependentResources().

+ Here is the caller graph for this function:

◆ textures()

QList< GLuint > QOpenGLFramebufferObject::textures ( ) const

Returns the texture id for all attached textures.

If a multisample framebuffer object is used, then an empty vector is returned.

Since
5.6
See also
takeTexture(), texture()

Definition at line 1235 of file qopenglframebufferobject.cpp.

References d.

◆ toImage() [1/2]

QImage QOpenGLFramebufferObject::toImage ( bool flipped,
int colorAttachmentIndex ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the contents of the color attachment of index colorAttachmentIndex of this framebuffer object as a QImage.

This method flips the image from OpenGL coordinates to raster coordinates when flipped is set to true.

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.
Since
5.6

Definition at line 1511 of file qopenglframebufferobject.cpp.

References bind(), blitFramebuffer(), QOpenGLContext::currentContext(), d, fmt, format(), GL_COLOR_ATTACHMENT0, GL_FRAMEBUFFER, GL_FRAMEBUFFER_BINDING, GLint(), GLuint, QOpenGLFunctions::MultipleRenderTargets, qt_gl_read_framebuffer(), qWarning, rect, QOpenGLFramebufferObjectFormat::samples(), QOpenGLFramebufferObjectFormat::setInternalTextureFormat(), size(), and toImage().

+ Here is the call graph for this function:

◆ toImage() [2/2]

QImage QOpenGLFramebufferObject::toImage ( bool flipped = true) const

Returns the contents of this framebuffer object as a QImage.

If flipped is true the image is flipped from OpenGL coordinates to raster coordinates. If used together with QOpenGLPaintDevice, flipped should be the opposite of the value of QOpenGLPaintDevice::paintFlipped().

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 QImage with a non-premultiplied format. This is necessary before performing operations like QImage::save() 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);
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32
Definition qimage.h:47
Definition image.cpp:4

For multisampled framebuffer objects the samples are resolved using the {GL_EXT_framebuffer_blit} extension. 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
QOpenGLPaintDevice::paintFlipped()

Definition at line 1493 of file qopenglframebufferobject.cpp.

References toImage().

Referenced by QOpenGLCompositor::grab(), QWaylandQuickCompositor::grabSurface(), toImage(), and toImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ width()

int QOpenGLFramebufferObject::width ( ) const
inline

Returns the width of the framebuffer object attachments.

Definition at line 63 of file qopenglframebufferobject.h.

Referenced by QSGFramebufferObjectNode::render().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ QOpenGLFBOGLPaintDevice

friend class QOpenGLFBOGLPaintDevice
friend

Definition at line 121 of file qopenglframebufferobject.h.

◆ QOpenGLPaintDevice

friend class QOpenGLPaintDevice
friend

Definition at line 120 of file qopenglframebufferobject.h.


The documentation for this class was generated from the following files: