46 #include <private/qgl_p.h> 47 #include <private/qfont_p.h> 48 #if !defined(QT_OPENGL_ES_1) 49 #include <private/qpaintengineex_opengl2_p.h> 52 #ifndef QT_OPENGL_ES_2 53 #include <private/qpaintengine_opengl_p.h> 64 #define QGL_FUNC_CONTEXT const QGLContext *ctx = d_ptr->fbo_guard.context(); 65 #define QGL_FUNCP_CONTEXT const QGLContext *ctx = fbo_guard.context(); 68 #define QT_RESET_GLERROR() \ 70 while (glGetError() != GL_NO_ERROR) {} \ 72 #define QT_CHECK_GLERROR() \ 74 GLenum err = glGetError(); \ 75 if (err != GL_NO_ERROR) { \ 76 qDebug("[%s line %d] GL Error: %d", \ 77 __FILE__, __LINE__, (int)err); \ 81 #define QT_RESET_GLERROR() {} 82 #define QT_CHECK_GLERROR() {} 318 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 352 return !(*
this == other);
359 m_thisFBO = fbo->d_func()->fbo();
366 fboFormat.setStencil(
true);
368 fboFormat.setDepth(
true);
369 fboFormat.setStencil(
false);
371 fboFormat.setDepth(
false);
372 fboFormat.setStencil(
false);
376 reqAlpha = (format !=
GL_RGB 378 && format != GL_RGB5 && format != GL_RGB8
389 return currentContext;
406 qDebug(
"QGLFramebufferObject: Unsupported framebuffer format.");
409 qDebug(
"QGLFramebufferObject: Framebuffer incomplete attachment.");
412 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, missing attachment.");
414 #ifdef GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT 416 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, duplicate attachment.");
420 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, attached images must have same dimensions.");
423 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, attached images must have same format.");
426 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, missing draw buffer.");
429 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, missing read buffer.");
432 qDebug(
"QGLFramebufferObject: Framebuffer incomplete, attachments must have same number of samples per pixel.");
435 qDebug() <<
"QGLFramebufferObject: An undefined error has occurred: "<<
status;
447 fbo_guard.setContext(ctx);
454 target = texture_target;
461 fbo_guard.setId(fbo);
463 glDevice.setFBO(q, attachment);
468 glGenTextures(1, &texture);
469 glBindTexture(target, texture);
470 glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
489 valid = checkFramebufferStatus();
490 glBindTexture(target, 0);
498 samples =
qBound(0,
int(samples),
int(maxSamples));
504 internal_format, size.width(), size.height());
508 size.width(), size.height());
515 valid = checkFramebufferStatus();
539 stencil_buffer = depth_buffer;
545 valid = checkFramebufferStatus();
548 stencil_buffer = depth_buffer = 0;
576 size.width(), size.height());
579 size.width(), size.height());
587 valid = checkFramebufferStatus();
610 size.width(), size.height());
613 size.width(), size.height());
618 valid = checkFramebufferStatus();
626 valid = checkFramebufferStatus();
628 if (depth_buffer && stencil_buffer) {
630 }
else if (depth_buffer) {
641 glDeleteTextures(1, &texture);
644 if (stencil_buffer && depth_buffer != stencil_buffer)
651 format.setTextureTarget(target);
652 format.setSamples(
int(samples));
653 format.setAttachment(fbo_attachment);
654 format.setInternalTextureFormat(internal_format);
801 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 862 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 893 d->init(
this,
QSize(width, height), attachment, target, internal_format);
896 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 899 QMacCompatGLenum target, QMacCompatGLenum internal_format)
928 d->init(
this, size, attachment, target, internal_format);
931 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 934 QMacCompatGLenum target, QMacCompatGLenum internal_format)
938 d->init(
this, size,
attachment, target, internal_format);
960 glDeleteTextures(1, &
d->texture);
965 if (
d->stencil_buffer &&
d->stencil_buffer !=
d->depth_buffer)
967 GLuint fbo =
d->fbo();
996 return d->valid &&
d->fbo_guard.context();
1024 qWarning(
"QGLFramebufferObject::bind() called from incompatible context");
1028 d->valid =
d->checkFramebufferStatus();
1029 if (
d->valid && current)
1060 qWarning(
"QGLFramebufferObject::release() called from incompatible context");
1130 if (
format().samples() != 0) {
1134 blitFramebuffer(&temp, rect, const_cast<QGLFramebufferObject *>(
this), rect);
1149 #if !defined(QT_OPENGL_ES_1) 1153 #ifndef QT_OPENGL_ES_2 1164 #if !defined(QT_OPENGL_ES_1) 1165 #if !defined (QT_OPENGL_ES_2) 1174 #if !defined (QT_OPENGL_ES_2) 1179 #if !defined(QT_OPENGL_ES_2) 1215 qWarning(
"QGLFramebufferObject::bindDefault() called without current context.");
1255 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 1281 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 1296 int w =
d->size.width();
1297 int h =
d->size.height();
1306 return qRound(w * 1000 / dpmx);
1309 return qRound(h * 1000 / dpmy);
1318 return qRound(dpmx * 0.0254);
1321 return qRound(dpmy * 0.0254);
1324 return qRound(dpmx * 0.0254);
1327 return qRound(dpmy * 0.0254);
1330 qWarning(
"QGLFramebufferObject::metric(), Unhandled metric type: %d.\n", metric);
1368 return d->fbo_attachment;
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();
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();
#define GL_RENDERBUFFER_SAMPLES_EXT
static bool hasOpenGLFramebufferObjects()
Returns true if the OpenGL GL_EXT_framebuffer_object extension is present on this system; otherwise r...
QPaintEngine * paintEngine() const
Reimplemented Function
QSize size() const
Returns the size of the texture attached to this framebuffer object.
int metric(PaintDeviceMetric metric) const
Reimplemented Function
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...
GLuint texture() const
Returns the texture id for the texture attached as the default rendering target in this framebuffer o...
QScopedPointer< QGLContextPrivate > d_ptr
#define GL_TEXTURE_MIN_FILTER
#define QT_END_NAMESPACE
This macro expands to.
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
#define GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
static bool bindDefault()
Switches rendering back to the default, windowing system provided framebuffer.
#define GL_DEPTH_COMPONENT
Q_GUI_EXPORT int qt_defaultDpiY()
QImage toImage() const
Returns the contents of this framebuffer object as a QImage.
The QGLFramebufferObject class encapsulates an OpenGL framebuffer object.
bool isValid() const
Returns true if the framebuffer object is valid.
#define GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT_EXT
Q_GUI_EXPORT int qt_defaultDpiX()
The QPointF class defines a point in the plane using floating point precision.
#define glGenRenderbuffers
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
bool qt_resolve_framebufferobject_extensions(QGLContext *ctx)
static LibLoadStatus status
#define GL_TEXTURE_WRAP_S
bool ref()
Atomically increments the value of this QAtomicInt.
int height() const
Returns the height of the rectangle.
#define GL_FRAMEBUFFER_EXT
#define GL_DEPTH24_STENCIL8_EXT
#define glBindFramebuffer
#define glRenderbufferStorageMultisampleEXT
#define QT_RESET_GLERROR()
Attachment
This enum type is used to configure the depth and stencil buffers attached to the framebuffer object ...
#define glDeleteRenderbuffers
#define GL_COLOR_ATTACHMENT0_EXT
static const QGLContext * currentContext()
Returns the current context, i.e.
#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT
#define glBlitFramebufferEXT
Q_CORE_EXPORT void qDebug(const char *,...)
#define GL_STENCIL_ATTACHMENT_EXT
#define QT_BEGIN_NAMESPACE
This macro expands to.
#define QT_CHECK_GLERROR()
bool isActive() const
Returns true if the paint engine is actively drawing; otherwise returns false.
The QRectF class defines a rectangle in the plane using floating point precision. ...
QScopedPointer< QGLFramebufferObjectPrivate > d_ptr
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
The QGLContext class encapsulates an OpenGL rendering context.
#define GL_DEPTH_COMPONENT16
#define glCheckFramebufferStatus
#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT
#define GL_RENDERBUFFER_EXT
virtual QGLContext * context() const
#define glDeleteFramebuffers
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
bool deref()
Atomically decrements the value of this QAtomicInt.
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...
Q_CORE_EXPORT void qWarning(const char *,...)
#define glGenFramebuffers
The QImage class provides a hardware-independent image representation that allows direct access to th...
#define GL_DEPTH_ATTACHMENT_EXT
#define GL_FRAMEBUFFER_UNSUPPORTED_EXT
QPaintDevice * device() const
Returns the paint device set for this context.
The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a g...
#define glGetRenderbufferParameteriv
GLuint handle() const
Returns the GL framebuffer object handle for this framebuffer object (returned by the glGenFrameBuffe...
#define GL_DRAW_FRAMEBUFFER_EXT
#define glBindRenderbuffer
bool qt_gl_preferGL2Engine()
#define GL_READ_FRAMEBUFFER_EXT
bool checkFramebufferStatus() const
QImage qt_gl_read_framebuffer(const QSize &, bool, bool)
#define GL_TEXTURE_WRAP_T
static QGLContextGroup * contextGroup(const QGLContext *ctx)
int top() const
Returns the y-coordinate of the rectangle's top edge.
#define GL_MAX_SAMPLES_EXT
#define GL_STENCIL_INDEX8_EXT
void init(QGLFramebufferObject *q, const QSize &sz, QGLFramebufferObject::Attachment attachment, GLenum internal_format, GLenum texture_target, GLint samples=0, bool mipmap=false)
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.
#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
void setFBO(QGLFramebufferObject *f, QGLFramebufferObject::Attachment attachment)
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...
The QRect class defines a rectangle in the plane using integer precision.
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
bool release()
Switches rendering back to the default, windowing system provided framebuffer.
#define GL_FRAMEBUFFER_COMPLETE_EXT
static Extensions glExtensions()
#define glFramebufferRenderbuffer
#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT
virtual ~QGLFramebufferObject()
Destroys the framebuffer object and frees any allocated resources.
The QSize class defines the size of a two-dimensional object using integer point precision.
bool isBound() const
Returns true if the framebuffer object is currently bound to a context, otherwise false is returned...
#define GL_TEXTURE_MAG_FILTER
#define glFramebufferTexture2D
#define GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
static bool hasOpenGLFramebufferBlit()
Returns true if the OpenGL GL_EXT_framebuffer_blit extension is present on this system; otherwise ret...
#define QGL_FUNCP_CONTEXT
#define glRenderbufferStorage
#define GL_DEPTH_COMPONENT24_OES
Q_DECL_CONSTEXPR int qRound(qreal d)
#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT
Attachment attachment() const
Returns the status of the depth and stencil buffers attached to this framebuffer object.