QOpenGLFramebufferObject Class
The QOpenGLFramebufferObject class encapsulates an OpenGL framebuffer object. More...
| Header: | #include <QOpenGLFramebufferObject> |
| qmake: | QT += gui |
| Since: | Qt 5.0 |
This class was introduced in Qt 5.0.
Public Types
| enum | Attachment { NoAttachment, CombinedDepthStencil, Depth } |
| enum | FramebufferRestorePolicy { DontRestoreFramebufferBinding, RestoreFramebufferBindingToDefault, RestoreFrameBufferBinding } |
Detailed Description
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.
Member Type Documentation
enum QOpenGLFramebufferObject::Attachment
This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created.
| Constant | Value | Description |
|---|---|---|
QOpenGLFramebufferObject::NoAttachment | 0 | 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 | 1 | 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. |
QOpenGLFramebufferObject::Depth | 2 | A depth buffer is attached to the framebuffer object. |
See also attachment().
enum QOpenGLFramebufferObject::FramebufferRestorePolicy
This enum type is used to configure the behavior related to restoring framebuffer bindings when calling blitFramebuffer().
| Constant | Value | Description |
|---|---|---|
QOpenGLFramebufferObject::DontRestoreFramebufferBinding | 0 | Do not restore the previous framebuffer binding. The caller is responsible for tracking and setting the framebuffer binding as needed. |
QOpenGLFramebufferObject::RestoreFramebufferBindingToDefault | 1 | After the blit operation, bind the default framebuffer. |
QOpenGLFramebufferObject::RestoreFrameBufferBinding | 2 | Restore the previously bound framebuffer. This is potentially expensive because of the need to query the currently bound framebuffer. |
This enum was introduced or modified in Qt 5.7.
See also blitFramebuffer().