Qt 4.8
|
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object. More...
#include <qglframebufferobject.h>
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... | |
Public Types inherited from QPaintDevice | |
enum | PaintDeviceMetric { PdmWidth = 1, PdmHeight, PdmWidthMM, PdmHeightMM, PdmNumColors, PdmDepth, PdmDpiX, PdmDpiY, PdmPhysicalDpiX, PdmPhysicalDpiY } |
Public Functions | |
Attachment | attachment () const |
Returns the status of the depth and stencil buffers attached to this framebuffer object. More... | |
bool | bind () |
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object. More... | |
void | drawTexture (const QRectF &target, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D) |
Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space. More... | |
void | drawTexture (const QPointF &point, GLuint textureId, GLenum textureTarget=GL_TEXTURE_2D) |
Draws the given texture, textureId, at the given point in OpenGL model space. More... | |
QGLFramebufferObjectFormat | format () const |
Returns the format of this framebuffer object. More... | |
GLuint | handle () const |
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffersEXT() function). More... | |
bool | isBound () const |
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned. More... | |
bool | isValid () const |
Returns true if the framebuffer object is valid. More... | |
QPaintEngine * | paintEngine () const |
Reimplemented Function More... | |
QGLFramebufferObject (const QSize &size, GLenum target=GL_TEXTURE_2D) | |
Constructs an OpenGL framebuffer object and binds a 2D GL texture to the buffer of the size size. More... | |
QGLFramebufferObject (int width, int height, GLenum target=GL_TEXTURE_2D) | |
Constructs an OpenGL framebuffer object and binds a 2D GL texture to the buffer of the given width and height. More... | |
QGLFramebufferObject (const QSize &size, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internal_format=GL_RGBA8) | |
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given size. More... | |
QGLFramebufferObject (int width, int height, Attachment attachment, GLenum target=GL_TEXTURE_2D, GLenum internal_format=GL_RGBA8) | |
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given width and height. More... | |
QGLFramebufferObject (const QSize &size, const QGLFramebufferObjectFormat &format) | |
Constructs an OpenGL framebuffer object of the given size based on the supplied format. More... | |
QGLFramebufferObject (int width, int height, const QGLFramebufferObjectFormat &format) | |
Constructs an OpenGL framebuffer object of the given width and height based on the supplied format. More... | |
bool | release () |
Switches rendering back to the default, windowing system provided framebuffer. More... | |
QSize | size () const |
Returns the size of the texture attached to this framebuffer object. More... | |
GLuint | texture () const |
Returns the texture id for the texture attached as the default rendering target in this framebuffer object. More... | |
QImage | toImage () const |
Returns the contents of this framebuffer object as a QImage. More... | |
virtual | ~QGLFramebufferObject () |
Destroys the framebuffer object and frees any allocated resources. More... | |
Public Functions inherited from QPaintDevice | |
int | colorCount () const |
int | depth () const |
virtual HDC | getDC () const |
int | height () const |
int | heightMM () const |
int | logicalDpiX () const |
int | logicalDpiY () const |
QT_DEPRECATED int | numColors () const |
bool | paintingActive () const |
int | physicalDpiX () const |
int | physicalDpiY () const |
virtual void | releaseDC (HDC hdc) const |
int | width () const |
int | widthMM () const |
virtual | ~QPaintDevice () |
Static Public Functions | |
static bool | bindDefault () |
Switches rendering back to the default, windowing system provided framebuffer. More... | |
static void | blitFramebuffer (QGLFramebufferObject *target, const QRect &targetRect, QGLFramebufferObject *source, const QRect &sourceRect, GLbitfield buffers=GL_COLOR_BUFFER_BIT, GLenum filter=GL_NEAREST) |
Blits from the sourceRect rectangle in the source framebuffer object to the targetRect rectangle in the target framebuffer object. More... | |
static bool | hasOpenGLFramebufferBlit () |
Returns true if the OpenGL GL_EXT_framebuffer_blit extension is present on this system; otherwise returns false. More... | |
static bool | hasOpenGLFramebufferObjects () |
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise returns false. More... | |
Static Public Functions inherited from QPaintDevice | |
static QWSDisplay * | qwsDisplay () |
Protected Functions | |
int | devType () const |
int | metric (PaintDeviceMetric metric) const |
Reimplemented Function More... | |
Protected Functions inherited from QPaintDevice | |
QPaintDevice () | |
Properties | |
QScopedPointer< QGLFramebufferObjectPrivate > | d_ptr |
Friends | |
class | QGLFBOGLPaintDevice |
class | QGLPaintDevice |
Additional Inherited Members | |
Protected Variables inherited from QPaintDevice | |
ushort | painters |
Related Functions inherited from QPaintDevice | |
const Q_GUI_EXPORT QX11Info * | qt_x11Info (const QPaintDevice *pd) |
Returns the QX11Info structure for the pd paint device. More... | |
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object, defined by the GL_EXT_framebuffer_object
extension. In addition it provides a rendering surface that can be painted on with a QPainter, 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, the QGLFramebufferObject class generates a 2D GL texture (using the GL_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.
When using a QPainter to paint to a QGLFramebufferObject you should take care that the QGLFramebufferObject is created with the CombinedDepthStencil attachment for QPainter to be able to render correctly. Note that you need to create a QGLFramebufferObject 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 QGLFramebufferObject parameter, and set the QGLFramebufferObject::samples() property to a non-zero value.
When painting to a QGLFramebufferObject using QPainter, 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().
As of Qt 4.8, it's possible to draw into a QGLFramebufferObject using a QPainter in a separate thread. Note that OpenGL 2.0 or OpenGL ES 2.0 is required for this to work. Also, under X11, it's necessary to set the Qt::AA_X11InitThreads application attribute.
Definition at line 57 of file qglframebufferobject.h.
This enum type is used to configure the depth and stencil buffers attached to the framebuffer object when it is created.
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.Enumerator | |
---|---|
NoAttachment | |
CombinedDepthStencil | |
Depth |
Definition at line 61 of file qglframebufferobject.h.
QGLFramebufferObject::QGLFramebufferObject | ( | const QSize & | size, |
GLenum | target = GL_TEXTURE_2D |
||
) |
Constructs an OpenGL framebuffer object and binds a 2D GL 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 GL 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 GL context set when creating the QGLFramebufferObject, otherwise the initialization will fail.
Definition at line 794 of file qglframebufferobject.cpp.
Referenced by QGLFramebufferObject().
QGLFramebufferObject::QGLFramebufferObject | ( | int | width, |
int | height, | ||
GLenum | target = GL_TEXTURE_2D |
||
) |
Constructs an OpenGL framebuffer object and binds a 2D GL texture to the buffer of the given width and height.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 821 of file qglframebufferobject.cpp.
QGLFramebufferObject::QGLFramebufferObject | ( | const QSize & | size, |
Attachment | attachment, | ||
GLenum | target = GL_TEXTURE_2D , |
||
GLenum | internal_format = GL_RGBA8 |
||
) |
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given size.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The attachment parameter describes the depth/stencil buffer configuration, target the texture target and internal_format 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.
Definition at line 923 of file qglframebufferobject.cpp.
QGLFramebufferObject::QGLFramebufferObject | ( | int | width, |
int | height, | ||
Attachment | attachment, | ||
GLenum | target = GL_TEXTURE_2D , |
||
GLenum | internal_format = GL_RGBA8 |
||
) |
Constructs an OpenGL framebuffer object and binds a texture to the buffer of the given width and height.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
The attachment parameter describes the depth/stencil buffer configuration, target the texture target and internal_format 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.
Definition at line 888 of file qglframebufferobject.cpp.
QGLFramebufferObject::QGLFramebufferObject | ( | const QSize & | size, |
const QGLFramebufferObjectFormat & | format | ||
) |
Constructs an OpenGL framebuffer object of the given size based on the supplied format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 837 of file qglframebufferobject.cpp.
QGLFramebufferObject::QGLFramebufferObject | ( | int | width, |
int | height, | ||
const QGLFramebufferObjectFormat & | format | ||
) |
Constructs an OpenGL framebuffer object of the given width and height based on the supplied format.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 854 of file qglframebufferobject.cpp.
|
virtual |
Destroys the framebuffer object and frees any allocated resources.
Definition at line 950 of file qglframebufferobject.cpp.
QGLFramebufferObject::Attachment QGLFramebufferObject::attachment | ( | ) | const |
Returns the status of the depth and stencil buffers attached to this framebuffer object.
Definition at line 1364 of file qglframebufferobject.cpp.
Referenced by QGLFramebufferObject().
bool QGLFramebufferObject::bind | ( | ) |
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object.
Returns true upon success, false otherwise.
Definition at line 1011 of file qglframebufferobject.cpp.
Referenced by QGLWindowSurface::beginPaint(), QGLWindowSurface::flush(), and toImage().
|
static |
Switches rendering back to the default, windowing system provided framebuffer.
Returns true upon success, false otherwise.
Definition at line 1202 of file qglframebufferobject.cpp.
|
static |
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.
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 that the scissor test will restrict the blit area if enabled.
This function will have no effect unless hasOpenGLFramebufferBlit() returns true.
Definition at line 1442 of file qglframebufferobject.cpp.
Referenced by toImage().
|
inlineprotectedvirtual |
Reimplemented from QPaintDevice.
Definition at line 130 of file qglframebufferobject.h.
void QGLFramebufferObject::drawTexture | ( | const QRectF & | target, |
GLuint | textureId, | ||
GLenum | textureTarget = GL_TEXTURE_2D |
||
) |
Draws the given texture, textureId, to the given target rectangle, target, in OpenGL model space.
The textureTarget should be a 2D texture target.
The framebuffer object should be bound when calling this function.
Equivalent to the corresponding QGLContext::drawTexture().
Definition at line 1250 of file qglframebufferobject.cpp.
Referenced by drawTexture().
void QGLFramebufferObject::drawTexture | ( | const QPointF & | point, |
GLuint | textureId, | ||
GLenum | textureTarget = GL_TEXTURE_2D |
||
) |
Draws the given texture, textureId, at the given point in OpenGL model space.
The textureTarget should be a 2D texture target.
The framebuffer object should be bound when calling this function.
Equivalent to the corresponding QGLContext::drawTexture().
Definition at line 1276 of file qglframebufferobject.cpp.
QGLFramebufferObjectFormat QGLFramebufferObject::format | ( | ) | const |
Returns the format of this framebuffer object.
Definition at line 1109 of file qglframebufferobject.cpp.
Referenced by QGLFramebufferObjectPool::acquire(), QGLWindowSurface::flush(), QGLFBOGLPaintDevice::setFBO(), toImage(), ShaderEffectSource::updateBackbuffer(), and QGLWindowSurface::updateGeometry().
GLuint QGLFramebufferObject::handle | ( | ) | const |
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.
Definition at line 1348 of file qglframebufferobject.cpp.
Referenced by blitFramebuffer(), QGLPixmapData::copy(), QGLPixmapData::copyBackFromRenderFbo(), and QGLWindowSurface::flush().
|
static |
Returns true if the OpenGL GL_EXT_framebuffer_blit
extension is present on this system; otherwise returns false.
Definition at line 1402 of file qglframebufferobject.cpp.
Referenced by QGLPixmapData::useFramebufferObjects().
|
static |
Returns true if the OpenGL GL_EXT_framebuffer_object
extension is present on this system; otherwise returns false.
Definition at line 1231 of file qglframebufferobject.cpp.
Referenced by QGL2PaintEngineEx::begin(), QGLTextureGlyphCache::createTextureData(), QGL2PaintEngineEx::drawStaticTextItem(), QGL2PaintEngineEx::drawTextItem(), QGLTextureGlyphCache::fillTexture(), QGLGlyphTexture::QGLGlyphTexture(), QGLTextureGlyphCache::resizeTextureData(), and QGLPixmapData::useFramebufferObjects().
bool QGLFramebufferObject::isBound | ( | ) | const |
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned.
Definition at line 1382 of file qglframebufferobject.cpp.
Referenced by QGLPixmapData::copy(), QGLPixmapData::copyBackFromRenderFbo(), QWaylandGLWindowSurface::flush(), QGLWindowSurface::flush(), and toImage().
bool QGLFramebufferObject::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 QGLContext 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 993 of file qglframebufferobject.cpp.
Referenced by QGLFramebufferObjectPool::acquire(), bind(), ShaderEffectSource::bind(), release(), ShaderEffectSource::updateBackbuffer(), QGLWindowSurface::updateGeometry(), ShaderEffect::updateRenderTargets(), ShaderEffectSource::updateSizeAndTexture(), and ~QGLFramebufferObject().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QPaintDevice.
Definition at line 1290 of file qglframebufferobject.cpp.
|
virtual |
Reimplemented Function
Implements QPaintDevice.
Definition at line 1158 of file qglframebufferobject.cpp.
bool QGLFramebufferObject::release | ( | ) |
Switches rendering back to the default, windowing system provided framebuffer.
Returns true upon success, false otherwise.
Definition at line 1046 of file qglframebufferobject.cpp.
Referenced by QGLWindowSurface::beginPaint(), QWaylandGLWindowSurface::flush(), QGLWindowSurface::flush(), and toImage().
QSize QGLFramebufferObject::size | ( | ) | const |
Returns the size of the texture attached to this framebuffer object.
Definition at line 1100 of file qglframebufferobject.cpp.
Referenced by QGLFramebufferObjectPool::acquire(), QWaylandGLWindowSurface::flush(), QGLWindowSurface::flush(), QGLFramebufferObject(), toImage(), ShaderEffectSource::updateBackbuffer(), ShaderEffect::updateRenderTargets(), and ShaderEffectSource::updateSizeAndTexture().
GLuint QGLFramebufferObject::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 GL code.
If a multisample framebuffer object is used then the value returned from this function will be invalid.
Definition at line 1085 of file qglframebufferobject.cpp.
Referenced by ShaderEffectSource::bind(), QWaylandGLWindowSurface::flush(), and QGLWindowSurface::flush().
QImage QGLFramebufferObject::toImage | ( | ) | const |
Returns the contents of this framebuffer object as a QImage.
Definition at line 1123 of file qglframebufferobject.cpp.
Referenced by QGLWindowSurface::buffer(), and toImage().
|
friend |
Definition at line 136 of file qglframebufferobject.h.
|
friend |
Definition at line 135 of file qglframebufferobject.h.
|
private |
Definition at line 134 of file qglframebufferobject.h.
Referenced by QGLFramebufferObject().