Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Properties | Friends | List of all members
QGLFramebufferObject Class Reference

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

#include <qglframebufferobject.h>

Inheritance diagram for QGLFramebufferObject:
QPaintDevice ShaderEffectBuffer

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...
 
QPaintEnginepaintEngine () 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 QWSDisplayqwsDisplay ()
 

Protected Functions

int devType () const
 
int metric (PaintDeviceMetric metric) const
 Reimplemented Function More...
 
- Protected Functions inherited from QPaintDevice
 QPaintDevice ()
 

Properties

QScopedPointer< QGLFramebufferObjectPrivated_ptr
 

Friends

class QGLFBOGLPaintDevice
 
class QGLPaintDevice
 

Additional Inherited Members

- Protected Variables inherited from QPaintDevice
ushort painters
 

Detailed Description

The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.

Since
4.2

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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 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().

Threading

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.

See also
{Framebuffer Object Example}

Definition at line 57 of file qglframebufferobject.h.

Enumerations

◆ Attachment

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

Since
4.3
  • 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.
  • 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.
  • Depth A depth buffer is attached to the framebuffer object.
See also
attachment()
Enumerator
NoAttachment 
CombinedDepthStencil 
Depth 

Definition at line 61 of file qglframebufferobject.h.

Constructors and Destructors

◆ QGLFramebufferObject() [1/6]

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.

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

Definition at line 794 of file qglframebufferobject.cpp.

Referenced by QGLFramebufferObject().

796 {
798  d->init(this, size, NoAttachment, target, DEFAULT_FORMAT);
799 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
#define DEFAULT_FORMAT

◆ QGLFramebufferObject() [2/6]

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.

See also
size(), texture()

Definition at line 821 of file qglframebufferobject.cpp.

823 {
825  d->init(this, QSize(width, height), NoAttachment, target, DEFAULT_FORMAT);
826 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
int height() const
Definition: qpaintdevice.h:92
#define Q_D(Class)
Definition: qglobal.h:2482
int width() const
Definition: qpaintdevice.h:91
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
#define DEFAULT_FORMAT
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ QGLFramebufferObject() [3/6]

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.

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

Definition at line 923 of file qglframebufferobject.cpp.

926 {
928  d->init(this, size, attachment, target, internal_format);
929 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
Attachment attachment() const
Returns the status of the depth and stencil buffers attached to this framebuffer object.

◆ QGLFramebufferObject() [4/6]

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.

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

Definition at line 888 of file qglframebufferobject.cpp.

891 {
893  d->init(this, QSize(width, height), attachment, target, internal_format);
894 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
int height() const
Definition: qpaintdevice.h:92
#define Q_D(Class)
Definition: qglobal.h:2482
int width() const
Definition: qpaintdevice.h:91
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
Attachment attachment() const
Returns the status of the depth and stencil buffers attached to this framebuffer object.

◆ QGLFramebufferObject() [5/6]

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.

839 {
841  d->init(this, size, format.attachment(), format.textureTarget(), format.internalTextureFormat(),
842  format.samples(), format.mipmap());
843 }
double d
Definition: qnumeric_p.h:62
bool mipmap() const
Returns true if mipmapping is enabled.
int samples() const
Returns the number of samples per pixel if a framebuffer object is a multisample framebuffer object...
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
QGLFramebufferObject::Attachment attachment() const
Returns the configuration of the depth and stencil buffers attached to a framebuffer object...
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
GLenum internalTextureFormat() const
Returns the internal format of a framebuffer object&#39;s texture or multisample framebuffer object&#39;s col...
GLenum textureTarget() const
Returns the texture target of the texture attached to a framebuffer object.

◆ QGLFramebufferObject() [6/6]

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.

856 {
858  d->init(this, QSize(width, height), format.attachment(), format.textureTarget(),
859  format.internalTextureFormat(), format.samples(), format.mipmap());
860 }
double d
Definition: qnumeric_p.h:62
bool mipmap() const
Returns true if mipmapping is enabled.
int samples() const
Returns the number of samples per pixel if a framebuffer object is a multisample framebuffer object...
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
int height() const
Definition: qpaintdevice.h:92
#define Q_D(Class)
Definition: qglobal.h:2482
int width() const
Definition: qpaintdevice.h:91
QGLFramebufferObject::Attachment attachment() const
Returns the configuration of the depth and stencil buffers attached to a framebuffer object...
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
GLenum internalTextureFormat() const
Returns the internal format of a framebuffer object&#39;s texture or multisample framebuffer object&#39;s col...
GLenum textureTarget() const
Returns the texture target of the texture attached to a framebuffer object.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ ~QGLFramebufferObject()

QGLFramebufferObject::~QGLFramebufferObject ( )
virtual

Destroys the framebuffer object and frees any allocated resources.

Definition at line 950 of file qglframebufferobject.cpp.

951 {
954 
955  delete d->engine;
956 
957  if (isValid() && ctx) {
958  QGLShareContextScope scope(ctx);
959  if (d->texture)
960  glDeleteTextures(1, &d->texture);
961  if (d->color_buffer)
962  glDeleteRenderbuffers(1, &d->color_buffer);
963  if (d->depth_buffer)
964  glDeleteRenderbuffers(1, &d->depth_buffer);
965  if (d->stencil_buffer && d->stencil_buffer != d->depth_buffer)
966  glDeleteRenderbuffers(1, &d->stencil_buffer);
967  GLuint fbo = d->fbo();
968  glDeleteFramebuffers(1, &fbo);
969  }
970 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
#define Q_D(Class)
Definition: qglobal.h:2482
#define glDeleteRenderbuffers
#define glDeleteFramebuffers
#define ctx
Definition: qgl.cpp:6094
#define QGL_FUNC_CONTEXT

Functions

◆ attachment()

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

1365 {
1366  Q_D(const QGLFramebufferObject);
1367  if (d->valid)
1368  return d->fbo_attachment;
1369  return NoAttachment;
1370 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ bind()

bool QGLFramebufferObject::bind ( )

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

Returns true upon success, false otherwise.

See also
release()

Definition at line 1011 of file qglframebufferobject.cpp.

Referenced by QGLWindowSurface::beginPaint(), QGLWindowSurface::flush(), and toImage().

1012 {
1013  if (!isValid())
1014  return false;
1017  if (!ctx)
1018  return false; // Context no longer exists.
1019  const QGLContext *current = QGLContext::currentContext();
1020 #ifdef QT_DEBUG
1021  if (!current ||
1023  {
1024  qWarning("QGLFramebufferObject::bind() called from incompatible context");
1025  }
1026 #endif
1028  d->valid = d->checkFramebufferStatus();
1029  if (d->valid && current)
1030  current->d_ptr->current_fbo = d->fbo();
1031  return d->valid;
1032 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
#define Q_D(Class)
Definition: qglobal.h:2482
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
GLuint current_fbo
Definition: qgl_p.h:456
static QGLContextGroup * contextGroup(const QGLContext *ctx)
Definition: qgl_p.h:464
#define ctx
Definition: qgl.cpp:6094
#define QGL_FUNC_CONTEXT

◆ bindDefault()

bool QGLFramebufferObject::bindDefault ( )
static

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

Warning
This function is not part of the public interface.

Returns true upon success, false otherwise.

See also
bind(), release()

Definition at line 1202 of file qglframebufferobject.cpp.

1203 {
1205 
1206  if (ctx) {
1208  if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(ctx)))
1209  return false;
1210 
1211  ctx->d_ptr->current_fbo = ctx->d_ptr->default_fbo;
1213 #ifdef QT_DEBUG
1214  } else {
1215  qWarning("QGLFramebufferObject::bindDefault() called without current context.");
1216 #endif
1217  }
1218 
1219  return ctx != 0;
1220 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
bool qt_resolve_framebufferobject_extensions(QGLContext *ctx)
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
GLuint current_fbo
Definition: qgl_p.h:456
#define ctx
Definition: qgl.cpp:6094
GLuint default_fbo
Definition: qgl_p.h:457
static Extensions glExtensions()
Definition: qgl.cpp:5781

◆ blitFramebuffer()

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

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

Since
4.6

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.

See also
hasOpenGLFramebufferBlit()

Definition at line 1442 of file qglframebufferobject.cpp.

Referenced by toImage().

1446 {
1448  return;
1449 
1451  if (!ctx)
1452  return;
1453 
1454  const int height = ctx->device()->height();
1455 
1456  const int sh = source ? source->height() : height;
1457  const int th = target ? target->height() : height;
1458 
1459  const int sx0 = sourceRect.left();
1460  const int sx1 = sourceRect.left() + sourceRect.width();
1461  const int sy0 = sh - (sourceRect.top() + sourceRect.height());
1462  const int sy1 = sh - sourceRect.top();
1463 
1464  const int tx0 = targetRect.left();
1465  const int tx1 = targetRect.left() + targetRect.width();
1466  const int ty0 = th - (targetRect.top() + targetRect.height());
1467  const int ty1 = th - targetRect.top();
1468 
1469  glBindFramebuffer(GL_READ_FRAMEBUFFER_EXT, source ? source->handle() : 0);
1470  glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, target ? target->handle() : 0);
1471 
1472  glBlitFramebufferEXT(sx0, sy0, sx1, sy1,
1473  tx0, ty0, tx1, ty1,
1474  buffers, filter);
1475 
1477 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
int height() const
Definition: qpaintdevice.h:92
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
#define glBlitFramebufferEXT
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
QPaintDevice * device() const
Returns the paint device set for this context.
Definition: qgl.cpp:3507
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
#define GL_READ_FRAMEBUFFER_EXT
GLuint current_fbo
Definition: qgl_p.h:456
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
#define ctx
Definition: qgl.cpp:6094
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
static Extensions glExtensions()
Definition: qgl.cpp:5781

◆ devType()

int QGLFramebufferObject::devType ( ) const
inlineprotectedvirtual
Warning
This function is not part of the public interface.

Reimplemented from QPaintDevice.

Definition at line 130 of file qglframebufferobject.h.

◆ drawTexture() [1/2]

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.

Since
4.4

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

1251 {
1252  const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(target, textureId, textureTarget);
1253 }
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
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...

◆ drawTexture() [2/2]

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.

Since
4.4

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.

1277 {
1278  const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(point, textureId, textureTarget);
1279 }
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
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...

◆ format()

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

1110 {
1111  Q_D(const QGLFramebufferObject);
1112  return d->format;
1113 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ handle()

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

1349 {
1350  Q_D(const QGLFramebufferObject);
1351  return d->fbo();
1352 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ hasOpenGLFramebufferBlit()

bool QGLFramebufferObject::hasOpenGLFramebufferBlit ( )
static

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

Since
4.6
See also
blitFramebuffer()

Definition at line 1402 of file qglframebufferobject.cpp.

Referenced by QGLPixmapData::useFramebufferObjects().

1403 {
1405 }
static Extensions glExtensions()
Definition: qgl.cpp:5781

◆ hasOpenGLFramebufferObjects()

bool QGLFramebufferObject::hasOpenGLFramebufferObjects ( )
static

◆ isBound()

bool QGLFramebufferObject::isBound ( ) const

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

Since
4.5

Definition at line 1382 of file qglframebufferobject.cpp.

Referenced by QGLPixmapData::copy(), QGLPixmapData::copyBackFromRenderFbo(), QWaylandGLWindowSurface::flush(), QGLWindowSurface::flush(), and toImage().

1383 {
1384  Q_D(const QGLFramebufferObject);
1385  const QGLContext *current = QGLContext::currentContext();
1386  return current ? current->d_ptr->current_fbo == d->fbo() : false;
1387 }
double d
Definition: qnumeric_p.h:62
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
GLuint current_fbo
Definition: qgl_p.h:456

◆ isValid()

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

994 {
995  Q_D(const QGLFramebufferObject);
996  return d->valid && d->fbo_guard.context();
997 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ metric()

int QGLFramebufferObject::metric ( PaintDeviceMetric  metric) const
protectedvirtual

Reimplemented Function

Reimplemented from QPaintDevice.

Definition at line 1290 of file qglframebufferobject.cpp.

1291 {
1292  Q_D(const QGLFramebufferObject);
1293 
1294  float dpmx = qt_defaultDpiX()*100./2.54;
1295  float dpmy = qt_defaultDpiY()*100./2.54;
1296  int w = d->size.width();
1297  int h = d->size.height();
1298  switch (metric) {
1299  case PdmWidth:
1300  return w;
1301 
1302  case PdmHeight:
1303  return h;
1304 
1305  case PdmWidthMM:
1306  return qRound(w * 1000 / dpmx);
1307 
1308  case PdmHeightMM:
1309  return qRound(h * 1000 / dpmy);
1310 
1311  case PdmNumColors:
1312  return 0;
1313 
1314  case PdmDepth:
1315  return 32;//d->depth;
1316 
1317  case PdmDpiX:
1318  return qRound(dpmx * 0.0254);
1319 
1320  case PdmDpiY:
1321  return qRound(dpmy * 0.0254);
1322 
1323  case PdmPhysicalDpiX:
1324  return qRound(dpmx * 0.0254);
1325 
1326  case PdmPhysicalDpiY:
1327  return qRound(dpmy * 0.0254);
1328 
1329  default:
1330  qWarning("QGLFramebufferObject::metric(), Unhandled metric type: %d.\n", metric);
1331  break;
1332  }
1333  return 0;
1334 }
double d
Definition: qnumeric_p.h:62
int metric(PaintDeviceMetric metric) const
Reimplemented Function
Q_GUI_EXPORT int qt_defaultDpiY()
Definition: qfont.cpp:201
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
Q_GUI_EXPORT int qt_defaultDpiX()
Definition: qfont.cpp:162
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ paintEngine()

QPaintEngine * QGLFramebufferObject::paintEngine ( ) const
virtual

Reimplemented Function

Implements QPaintDevice.

Definition at line 1158 of file qglframebufferobject.cpp.

1159 {
1160  Q_D(const QGLFramebufferObject);
1161  if (d->engine)
1162  return d->engine;
1163 
1164 #if !defined(QT_OPENGL_ES_1)
1165 #if !defined (QT_OPENGL_ES_2)
1166  if (qt_gl_preferGL2Engine()) {
1167 #endif
1168  QPaintEngine *engine = qt_buffer_2_engine()->engine();
1169  if (engine->isActive() && engine->paintDevice() != this) {
1170  d->engine = new QGL2PaintEngineEx;
1171  return d->engine;
1172  }
1173  return engine;
1174 #if !defined (QT_OPENGL_ES_2)
1175  }
1176 #endif
1177 #endif
1178 
1179 #if !defined(QT_OPENGL_ES_2)
1180  QPaintEngine *engine = qt_buffer_engine()->engine();
1181  if (engine->isActive() && engine->paintDevice() != this) {
1182  d->engine = new QOpenGLPaintEngine;
1183  return d->engine;
1184  }
1185  return engine;
1186 #endif
1187 }
double d
Definition: qnumeric_p.h:62
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
Definition: qpaintengine.h:154
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
Definition: qpaintengine.h:90
bool qt_gl_preferGL2Engine()
Definition: qgl.cpp:218

◆ release()

bool QGLFramebufferObject::release ( )

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

Returns true upon success, false otherwise.

See also
bind()

Definition at line 1046 of file qglframebufferobject.cpp.

Referenced by QGLWindowSurface::beginPaint(), QWaylandGLWindowSurface::flush(), QGLWindowSurface::flush(), and toImage().

1047 {
1048  if (!isValid())
1049  return false;
1051  if (!ctx)
1052  return false; // Context no longer exists.
1053 
1054  const QGLContext *current = QGLContext::currentContext();
1055 
1056 #ifdef QT_DEBUG
1057  if (!current ||
1059  {
1060  qWarning("QGLFramebufferObject::release() called from incompatible context");
1061  }
1062 #endif
1063 
1064  if (current) {
1065  current->d_ptr->current_fbo = current->d_ptr->default_fbo;
1067  }
1068 
1069  return true;
1070 }
QScopedPointer< QGLContextPrivate > d_ptr
Definition: qgl.h:430
bool isValid() const
Returns true if the framebuffer object is valid.
#define GL_FRAMEBUFFER_EXT
#define glBindFramebuffer
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
Q_CORE_EXPORT void qWarning(const char *,...)
GLuint current_fbo
Definition: qgl_p.h:456
static QGLContextGroup * contextGroup(const QGLContext *ctx)
Definition: qgl_p.h:464
#define ctx
Definition: qgl.cpp:6094
GLuint default_fbo
Definition: qgl_p.h:457
#define QGL_FUNC_CONTEXT

◆ size()

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

1101 {
1102  Q_D(const QGLFramebufferObject);
1103  return d->size;
1104 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ texture()

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

1086 {
1087  Q_D(const QGLFramebufferObject);
1088  return d->texture;
1089 }
double d
Definition: qnumeric_p.h:62
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482

◆ toImage()

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

1124 {
1125  Q_D(const QGLFramebufferObject);
1126  if (!d->valid)
1127  return QImage();
1128 
1129  // qt_gl_read_framebuffer doesn't work on a multisample FBO
1130  if (format().samples() != 0) {
1132 
1133  QRect rect(QPoint(0, 0), size());
1134  blitFramebuffer(&temp, rect, const_cast<QGLFramebufferObject *>(this), rect);
1135 
1136  return temp.toImage();
1137  }
1138 
1139  bool wasBound = isBound();
1140  if (!wasBound)
1141  const_cast<QGLFramebufferObject *>(this)->bind();
1142  QImage image = qt_gl_read_framebuffer(d->size, format().internalTextureFormat() != GL_RGB, true);
1143  if (!wasBound)
1144  const_cast<QGLFramebufferObject *>(this)->release();
1145 
1146  return image;
1147 }
double d
Definition: qnumeric_p.h:62
QSize size() const
Returns the size of the texture attached to this framebuffer object.
#define GL_RGB
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
#define Q_D(Class)
Definition: qglobal.h:2482
QGLFramebufferObjectFormat format() const
Returns the format of this framebuffer object.
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 t...
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QImage qt_gl_read_framebuffer(const QSize &, bool, bool)
Definition: qgl.cpp:1860
bool bind()
Switches rendering from the default, windowing system provided framebuffer to this framebuffer object...
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
The QGLFramebufferObjectFormat class specifies the format of an OpenGL framebuffer object...

Friends and Related Functions

◆ QGLFBOGLPaintDevice

friend class QGLFBOGLPaintDevice
friend

Definition at line 136 of file qglframebufferobject.h.

◆ QGLPaintDevice

friend class QGLPaintDevice
friend

Definition at line 135 of file qglframebufferobject.h.

Properties

◆ d_ptr

QScopedPointer<QGLFramebufferObjectPrivate> QGLFramebufferObject::d_ptr
private

Definition at line 134 of file qglframebufferobject.h.

Referenced by QGLFramebufferObject().


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