summaryrefslogtreecommitdiffstats
path: root/src/opengl/qglframebufferobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qglframebufferobject.cpp')
-rw-r--r--src/opengl/qglframebufferobject.cpp66
1 files changed, 56 insertions, 10 deletions
diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp
index d8addf6..0af8108 100644
--- a/src/opengl/qglframebufferobject.cpp
+++ b/src/opengl/qglframebufferobject.cpp
@@ -44,6 +44,7 @@
#include <qdebug.h>
#include <private/qgl_p.h>
+#include <private/qfont_p.h>
#if !defined(QT_OPENGL_ES_1)
#include <private/qpaintengineex_opengl2_p.h>
#endif
@@ -202,6 +203,38 @@ int QGLFramebufferObjectFormat::samples() const
}
/*!
+ \since 4.8
+
+ Enables mipmapping if \a enabled is true; otherwise disables it.
+
+ Mipmapping is disabled by default.
+
+ If mipmapping is enabled, additional memory will be allocated for
+ the mipmap levels. The mipmap levels can be updated by binding the
+ texture and calling glGenerateMipmap(). Mipmapping cannot be enabled
+ for multisampled framebuffer objects.
+
+ \sa mipmap(), QGLFramebufferObject::texture()
+*/
+void QGLFramebufferObjectFormat::setMipmap(bool enabled)
+{
+ detach();
+ d->mipmap = enabled;
+}
+
+/*!
+ \since 4.8
+
+ Returns true if mipmapping is enabled.
+
+ \sa setMipmap()
+*/
+bool QGLFramebufferObjectFormat::mipmap() const
+{
+ return d->mipmap;
+}
+
+/*!
Sets the attachment configuration of a framebuffer object to \a attachment.
\sa attachment()
@@ -324,6 +357,10 @@ void QGLFBOGLPaintDevice::setFBO(QGLFramebufferObject* f,
fboFormat.setStencil(true);
} else if (attachment == QGLFramebufferObject::Depth) {
fboFormat.setDepth(true);
+ fboFormat.setStencil(false);
+ } else {
+ fboFormat.setDepth(false);
+ fboFormat.setStencil(false);
}
GLenum format = f->format().internalTextureFormat();
@@ -394,7 +431,8 @@ bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const
void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
QGLFramebufferObject::Attachment attachment,
- GLenum texture_target, GLenum internal_format, GLint samples)
+ GLenum texture_target, GLenum internal_format,
+ GLint samples, bool mipmap)
{
QGLContext *ctx = const_cast<QGLContext *>(QGLContext::currentContext());
fbo_guard.setContext(ctx);
@@ -422,6 +460,8 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
glBindTexture(target, texture);
glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+ if (mipmap)
+ glGenerateMipmap(GL_TEXTURE_2D);
#ifndef QT_OPENGL_ES
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -442,6 +482,7 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
color_buffer = 0;
} else {
+ mipmap = false;
GLint maxSamples;
glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);
@@ -602,6 +643,7 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
format.setSamples(int(samples));
format.setAttachment(fbo_attachment);
format.setInternalTextureFormat(internal_format);
+ format.setMipmap(mipmap);
}
/*!
@@ -674,6 +716,13 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
as a texture, you first need to copy from it to a regular framebuffer
object using QGLContext::blitFramebuffer().
+ \section1 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.
+
\sa {Framebuffer Object Example}
*/
@@ -766,7 +815,7 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, const QGLFramebuff
{
Q_D(QGLFramebufferObject);
d->init(this, size, format.attachment(), format.textureTarget(), format.internalTextureFormat(),
- format.samples());
+ format.samples(), format.mipmap());
}
/*! \overload
@@ -780,7 +829,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, const QGLFrame
{
Q_D(QGLFramebufferObject);
d->init(this, QSize(width, height), format.attachment(), format.textureTarget(),
- format.internalTextureFormat(), format.samples());
+ format.internalTextureFormat(), format.samples(), format.mipmap());
}
#ifdef Q_MAC_COMPAT_GL_FUNCTIONS
@@ -1044,11 +1093,11 @@ QImage QGLFramebufferObject::toImage() const
}
#if !defined(QT_OPENGL_ES_1)
-Q_GLOBAL_STATIC(QGL2PaintEngineEx, qt_buffer_2_engine)
+Q_GLOBAL_STATIC(QGLEngineThreadStorage<QGL2PaintEngineEx>, qt_buffer_2_engine)
#endif
#ifndef QT_OPENGL_ES_2
-Q_GLOBAL_STATIC(QOpenGLPaintEngine, qt_buffer_engine)
+Q_GLOBAL_STATIC(QGLEngineThreadStorage<QOpenGLPaintEngine>, qt_buffer_engine)
#endif
/*! \reimp */
@@ -1062,7 +1111,7 @@ QPaintEngine *QGLFramebufferObject::paintEngine() const
#if !defined (QT_OPENGL_ES_2)
if (qt_gl_preferGL2Engine()) {
#endif
- QPaintEngine *engine = qt_buffer_2_engine();
+ QPaintEngine *engine = qt_buffer_2_engine()->engine();
if (engine->isActive() && engine->paintDevice() != this) {
d->engine = new QGL2PaintEngineEx;
return d->engine;
@@ -1074,7 +1123,7 @@ QPaintEngine *QGLFramebufferObject::paintEngine() const
#endif
#if !defined(QT_OPENGL_ES_2)
- QPaintEngine *engine = qt_buffer_engine();
+ QPaintEngine *engine = qt_buffer_engine()->engine();
if (engine->isActive() && engine->paintDevice() != this) {
d->engine = new QOpenGLPaintEngine;
return d->engine;
@@ -1171,9 +1220,6 @@ void QGLFramebufferObject::drawTexture(const QPointF &point, QMacCompatGLuint te
}
#endif
-Q_GUI_EXPORT int qt_defaultDpiX();
-Q_GUI_EXPORT int qt_defaultDpiY();
-
/*! \reimp */
int QGLFramebufferObject::metric(PaintDeviceMetric metric) const
{