diff options
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/opengl.pro | 2 | ||||
-rw-r--r-- | src/opengl/qgl.cpp | 82 | ||||
-rw-r--r-- | src/opengl/qgl.h | 10 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 21 | ||||
-rw-r--r-- | src/opengl/qglframebufferobject.cpp | 73 | ||||
-rw-r--r-- | src/opengl/qglframebufferobject.h | 6 | ||||
-rw-r--r-- | src/opengl/qglpixmapfilter.cpp | 2 | ||||
-rw-r--r-- | src/opengl/qglshaderprogram.cpp | 197 | ||||
-rw-r--r-- | src/opengl/qgraphicsshadereffect.cpp | 18 | ||||
-rw-r--r-- | src/opengl/qgraphicsshadereffect_p.h (renamed from src/opengl/qgraphicsshadereffect.h) | 17 | ||||
-rw-r--r-- | src/opengl/qpixmapdata_gl.cpp | 4 | ||||
-rw-r--r-- | src/opengl/qwindowsurface_gl.cpp | 2 |
12 files changed, 242 insertions, 192 deletions
diff --git a/src/opengl/opengl.pro b/src/opengl/opengl.pro index 458aa7e..560d31f 100644 --- a/src/opengl/opengl.pro +++ b/src/opengl/opengl.pro @@ -38,7 +38,7 @@ SOURCES += qgl.cpp \ !contains(QT_CONFIG, opengles1):!contains(QT_CONFIG, opengles1cl) { HEADERS += qglshaderprogram.h \ qglpixmapfilter_p.h \ - qgraphicsshadereffect.h \ + qgraphicsshadereffect_p.h \ qgraphicssystem_gl_p.h \ qwindowsurface_gl_p.h \ qpixmapdata_gl_p.h \ diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index dde4eba..9e0c5f8 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -207,9 +207,10 @@ QGLSignalProxy *QGLSignalProxy::instance() \i \link setSampleBuffers() Multisample buffers.\endlink \endlist - You can also specify preferred bit depths for the depth buffer, - alpha buffer, accumulation buffer and the stencil buffer with the - functions: setDepthBufferSize(), setAlphaBufferSize(), + You can also specify preferred bit depths for the color buffer, + depth buffer, alpha buffer, accumulation buffer and the stencil + buffer with the functions: setRedBufferSize(), setGreenBufferSize(), + setBlueBufferSize(), setDepthBufferSize(), setAlphaBufferSize(), setAccumBufferSize() and setStencilBufferSize(). Note that even if you specify that you prefer a 32 bit depth @@ -293,19 +294,20 @@ static inline GLint qgluProject(GLdouble objx, GLdouble objy, GLdouble objz, } /*! - Constructs a QGLFormat object with the factory default settings: + Constructs a QGLFormat object with the following default settings: \list \i \link setDoubleBuffer() Double buffer:\endlink Enabled. \i \link setDepth() Depth buffer:\endlink Enabled. \i \link setRgba() RGBA:\endlink Enabled (i.e., color index disabled). \i \link setAlpha() Alpha channel:\endlink Disabled. \i \link setAccum() Accumulator buffer:\endlink Disabled. - \i \link setStencil() Stencil buffer:\endlink Disabled. + \i \link setStencil() Stencil buffer:\endlink Enabled. \i \link setStereo() Stereo:\endlink Disabled. \i \link setDirectRendering() Direct rendering:\endlink Enabled. \i \link setOverlay() Overlay:\endlink Disabled. \i \link setPlane() Plane:\endlink 0 (i.e., normal plane). - \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. + \i \link setSampleBuffers() Multisample buffers:\endlink Enabled on + OpenGL/ES 2.0, disabled on other platforms. \endlist */ @@ -316,26 +318,26 @@ QGLFormat::QGLFormat() /*! - Creates a QGLFormat object that is a copy of the current \link - defaultFormat() application default format\endlink. + Creates a QGLFormat object that is a copy of the current + defaultFormat(). - If \a options is not 0, this copy is modified by these format - options. The \a options parameter should be \c FormatOption values - OR'ed together. + If \a options is not 0, the default format is modified by the + specified format options. The \a options parameter should be + QGL::FormatOption values OR'ed together. This constructor makes it easy to specify a certain desired format in classes derived from QGLWidget, for example: \snippet doc/src/snippets/code/src_opengl_qgl.cpp 3 - Note that there are \c FormatOption values to turn format settings - both on and off, e.g. \c DepthBuffer and \c NoDepthBuffer, - \c DirectRendering and \c IndirectRendering, etc. + Note that there are QGL::FormatOption values to turn format settings + both on and off, e.g. QGL::DepthBuffer and QGL::NoDepthBuffer, + QGL::DirectRendering and QGL::IndirectRendering, etc. The \a plane parameter defaults to 0 and is the plane which this format should be associated with. Not all OpenGL implementations supports overlay/underlay rendering planes. - \sa defaultFormat(), setOption() + \sa defaultFormat(), setOption(), setPlane() */ QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) @@ -349,13 +351,26 @@ QGLFormat::QGLFormat(QGL::FormatOptions options, int plane) } /*! + \internal +*/ +void QGLFormat::detach() +{ + if (d->ref != 1) { + QGLFormatPrivate *newd = new QGLFormatPrivate(d); + if (!d->ref.deref()) + delete d; + d = newd; + } +} + +/*! Constructs a copy of \a other. */ QGLFormat::QGLFormat(const QGLFormat &other) { - d = new QGLFormatPrivate; - *d = *other.d; + d = other.d; + d->ref.ref(); } /*! @@ -364,7 +379,12 @@ QGLFormat::QGLFormat(const QGLFormat &other) QGLFormat &QGLFormat::operator=(const QGLFormat &other) { - *d = *other.d; + if (d != other.d) { + other.d->ref.ref(); + if (!d->ref.deref()) + delete d; + d = other.d; + } return *this; } @@ -373,7 +393,8 @@ QGLFormat &QGLFormat::operator=(const QGLFormat &other) */ QGLFormat::~QGLFormat() { - delete d; + if (!d->ref.deref()) + delete d; } /*! @@ -649,6 +670,7 @@ int QGLFormat::samples() const */ void QGLFormat::setSamples(int numSamples) { + detach(); if (numSamples < 0) { qWarning("QGLFormat::setSamples: Cannot have negative number of samples per pixel %d", numSamples); return; @@ -676,6 +698,7 @@ void QGLFormat::setSamples(int numSamples) */ void QGLFormat::setSwapInterval(int interval) { + detach(); d->swapInterval = interval; } @@ -721,7 +744,7 @@ void QGLFormat::setOverlay(bool enable) is 0, which means the normal plane. The default for overlay formats is 1, which is the first overlay plane. - \sa setPlane() + \sa setPlane(), defaultOverlayFormat() */ int QGLFormat::plane() const { @@ -743,6 +766,7 @@ int QGLFormat::plane() const */ void QGLFormat::setPlane(int plane) { + detach(); d->pln = plane; } @@ -754,6 +778,7 @@ void QGLFormat::setPlane(int plane) void QGLFormat::setOption(QGL::FormatOptions opt) { + detach(); if (opt & 0xffff) d->opts |= opt; else @@ -783,6 +808,7 @@ bool QGLFormat::testOption(QGL::FormatOptions opt) const */ void QGLFormat::setDepthBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setDepthBufferSize: Cannot set negative depth buffer size %d", size); return; @@ -809,6 +835,7 @@ int QGLFormat::depthBufferSize() const */ void QGLFormat::setRedBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setRedBufferSize: Cannot set negative red buffer size %d", size); return; @@ -837,6 +864,7 @@ int QGLFormat::redBufferSize() const */ void QGLFormat::setGreenBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setGreenBufferSize: Cannot set negative green buffer size %d", size); return; @@ -865,6 +893,7 @@ int QGLFormat::greenBufferSize() const */ void QGLFormat::setBlueBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setBlueBufferSize: Cannot set negative blue buffer size %d", size); return; @@ -892,6 +921,7 @@ int QGLFormat::blueBufferSize() const */ void QGLFormat::setAlphaBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setAlphaBufferSize: Cannot set negative alpha buffer size %d", size); return; @@ -918,6 +948,7 @@ int QGLFormat::alphaBufferSize() const */ void QGLFormat::setAccumBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setAccumBufferSize: Cannot set negative accumulate buffer size %d", size); return; @@ -942,6 +973,7 @@ int QGLFormat::accumBufferSize() const */ void QGLFormat::setStencilBufferSize(int size) { + detach(); if (size < 0) { qWarning("QGLFormat::setStencilBufferSize: Cannot set negative stencil buffer size %d", size); return; @@ -1195,7 +1227,7 @@ void QGLFormat::setDefaultFormat(const QGLFormat &f) /*! Returns the default QGLFormat for overlay contexts. - The factory default overlay format is: + The default overlay format is: \list \i \link setDoubleBuffer() Double buffer:\endlink Disabled. \i \link setDepth() Depth buffer:\endlink Disabled. @@ -1206,6 +1238,7 @@ void QGLFormat::setDefaultFormat(const QGLFormat &f) \i \link setStereo() Stereo:\endlink Disabled. \i \link setDirectRendering() Direct rendering:\endlink Enabled. \i \link setOverlay() Overlay:\endlink Disabled. + \i \link setSampleBuffers() Multisample buffers:\endlink Disabled. \i \link setPlane() Plane:\endlink 1 (i.e., first overlay plane). \endlist @@ -1256,7 +1289,12 @@ bool operator==(const QGLFormat& a, const QGLFormat& b) { return (int) a.d->opts == (int) b.d->opts && a.d->pln == b.d->pln && a.d->alphaSize == b.d->alphaSize && a.d->accumSize == b.d->accumSize && a.d->stencilSize == b.d->stencilSize - && a.d->depthSize == b.d->depthSize; + && a.d->depthSize == b.d->depthSize + && a.d->redSize == b.d->redSize + && a.d->greenSize == b.d->greenSize + && a.d->blueSize == b.d->blueSize + && a.d->numSamples == b.d->numSamples + && a.d->swapInterval == b.d->swapInterval; } diff --git a/src/opengl/qgl.h b/src/opengl/qgl.h index 1d9f623..daac760 100644 --- a/src/opengl/qgl.h +++ b/src/opengl/qgl.h @@ -255,6 +255,8 @@ public: private: QGLFormatPrivate *d; + void detach(); + friend Q_OPENGL_EXPORT bool operator==(const QGLFormat&, const QGLFormat&); friend Q_OPENGL_EXPORT bool operator!=(const QGLFormat&, const QGLFormat&); }; @@ -277,7 +279,6 @@ public: bool isSharing() const; void reset(); - // ### Qt 5: make format() return a const ref instead QGLFormat format() const; QGLFormat requestedFormat() const; void setFormat(const QGLFormat& format); @@ -403,15 +404,11 @@ private: #endif friend class QGLFramebufferObject; friend class QGLFramebufferObjectPrivate; -#ifdef Q_WS_WIN - friend bool qt_resolve_GLSL_functions(QGLContext *ctx); - friend bool qt_createGLSLProgram(QGLContext *ctx, GLuint &program, const char *shader_src, GLuint &shader); -#endif private: Q_DISABLE_COPY(QGLContext) }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QGLContext::BindOptions); +Q_DECLARE_OPERATORS_FOR_FLAGS(QGLContext::BindOptions) class Q_OPENGL_EXPORT QGLWidget : public QWidget { @@ -447,7 +444,6 @@ public: bool doubleBuffer() const; void swapBuffers(); - // ### Qt 5: make format() return a const ref instead QGLFormat format() const; void setFormat(const QGLFormat& format); diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 72ec35e..d4b7597 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -59,6 +59,7 @@ #include "QtCore/qthread.h" #include "QtCore/qthreadstorage.h" #include "QtCore/qhash.h" +#include "QtCore/qatomic.h" #include "private/qwidget_p.h" #include "qcache.h" @@ -127,7 +128,9 @@ QT_END_INCLUDE_NAMESPACE class QGLFormatPrivate { public: - QGLFormatPrivate() { + QGLFormatPrivate() + : ref(1) + { opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering | QGL::StencilBuffer; #if defined(QT_OPENGL_ES_2) opts |= QGL::SampleBuffers; @@ -137,6 +140,22 @@ public: numSamples = -1; swapInterval = -1; } + QGLFormatPrivate(const QGLFormatPrivate *other) + : ref(1), + opts(other->opts), + pln(other->pln), + depthSize(other->depthSize), + accumSize(other->accumSize), + stencilSize(other->stencilSize), + redSize(other->redSize), + greenSize(other->greenSize), + blueSize(other->blueSize), + alphaSize(other->alphaSize), + numSamples(other->numSamples), + swapInterval(other->swapInterval) + { + } + QAtomicInt ref; QGL::FormatOptions opts; int pln; int depthSize; diff --git a/src/opengl/qglframebufferobject.cpp b/src/opengl/qglframebufferobject.cpp index a03e627..c53ed3a 100644 --- a/src/opengl/qglframebufferobject.cpp +++ b/src/opengl/qglframebufferobject.cpp @@ -63,7 +63,7 @@ QT_BEGIN_NAMESPACE extern QImage qt_gl_read_framebuffer(const QSize&, bool, bool); -#define QGL_FUNC_CONTEXT QGLContext *ctx = d_ptr->ctx; +#define QGL_FUNC_CONTEXT QGLContextGroup *ctx = d_ptr->ctx; #define QT_CHECK_GLERROR() \ { \ @@ -97,7 +97,7 @@ public: \i \link setSamples() Number of samples per pixels.\endlink \i \link setAttachment() Depth and/or stencil attachments.\endlink \i \link setTextureTarget() Texture target.\endlink - \i \link setInternalFormat() Internal format.\endlink + \i \link setInternalTextureFormat() Internal texture format.\endlink \endlist Note that the desired attachments or number of samples per pixels might not @@ -115,7 +115,7 @@ public: By default the format specifies a non-multisample framebuffer object with no attachments, texture target \c GL_TEXTURE_2D, and internal format \c GL_RGBA8. - \sa samples(), attachment(), target(), internalFormat() + \sa samples(), attachment(), target(), internalTextureFormat() */ #ifndef QT_OPENGL_ES @@ -234,23 +234,24 @@ GLenum QGLFramebufferObjectFormat::textureTarget() const } /*! - Sets the internal format of a framebuffer object's texture or multisample - framebuffer object's color buffer to \a internalFormat. + Sets the internal format of a framebuffer object's texture or + multisample framebuffer object's color buffer to + \a internalTextureFormat. - \sa internalFormat() + \sa internalTextureFormat() */ -void QGLFramebufferObjectFormat::setInternalFormat(GLenum internalFormat) +void QGLFramebufferObjectFormat::setInternalTextureFormat(GLenum internalTextureFormat) { - d->internal_format = internalFormat; + d->internal_format = internalTextureFormat; } /*! Returns the internal format of a framebuffer object's texture or multisample framebuffer object's color buffer. - \sa setInternalFormat() + \sa setInternalTextureFormat() */ -GLenum QGLFramebufferObjectFormat::internalFormat() const +GLenum QGLFramebufferObjectFormat::internalTextureFormat() const { return d->internal_format; } @@ -263,16 +264,16 @@ void QGLFramebufferObjectFormat::setTextureTarget(QMacCompatGLenum target) } /*! \internal */ -void QGLFramebufferObjectFormat::setInternalFormat(QMacCompatGLenum internalFormat) +void QGLFramebufferObjectFormat::setInternalTextureFormat(QMacCompatGLenum internalTextureFormat) { - d->internal_format = internalFormat; + d->internal_format = internalTextureFormat; } #endif class QGLFramebufferObjectPrivate { public: - QGLFramebufferObjectPrivate() : depth_stencil_buffer(0), valid(false), bound(false), ctx(0), previous_fbo(0), engine(0) {} + QGLFramebufferObjectPrivate() : depth_stencil_buffer(0), valid(false), ctx(0), previous_fbo(0), engine(0) {} ~QGLFramebufferObjectPrivate() {} void init(const QSize& sz, QGLFramebufferObject::Attachment attachment, @@ -286,9 +287,8 @@ public: QSize size; QGLFramebufferObjectFormat format; uint valid : 1; - uint bound : 1; QGLFramebufferObject::Attachment fbo_attachment; - QGLContext *ctx; // for Windows extension ptrs + QGLContextGroup *ctx; // for Windows extension ptrs GLuint previous_fbo; mutable QPaintEngine *engine; }; @@ -340,9 +340,10 @@ bool QGLFramebufferObjectPrivate::checkFramebufferStatus() const void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::Attachment attachment, GLenum texture_target, GLenum internal_format, GLint samples) { - ctx = const_cast<QGLContext *>(QGLContext::currentContext()); + QGLContext *currentContext = const_cast<QGLContext *>(QGLContext::currentContext()); + ctx = QGLContextPrivate::contextGroup(currentContext); bool ext_detected = (QGLExtensions::glExtensions & QGLExtensions::FramebufferObject); - if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(ctx))) + if (!ext_detected || (ext_detected && !qt_resolve_framebufferobject_extensions(currentContext))) return; size = sz; @@ -466,7 +467,7 @@ void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::At fbo_attachment = QGLFramebufferObject::NoAttachment; } - glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); + glBindFramebuffer(GL_FRAMEBUFFER_EXT, currentContext->d_ptr->current_fbo); if (!valid) { if (color_buffer) glDeleteRenderbuffers(1, &color_buffer); @@ -479,7 +480,7 @@ void QGLFramebufferObjectPrivate::init(const QSize &sz, QGLFramebufferObject::At format.setTextureTarget(target); format.setSamples(int(samples)); format.setAttachment(fbo_attachment); - format.setInternalFormat(internal_format); + format.setInternalTextureFormat(internal_format); } /*! @@ -636,7 +637,7 @@ QGLFramebufferObject::QGLFramebufferObject(const QSize &size, const QGLFramebuff : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(size, format.attachment(), format.textureTarget(), format.internalFormat(), format.samples()); + d->init(size, format.attachment(), format.textureTarget(), format.internalTextureFormat(), format.samples()); } /*! \overload @@ -649,7 +650,7 @@ QGLFramebufferObject::QGLFramebufferObject(int width, int height, const QGLFrame : d_ptr(new QGLFramebufferObjectPrivate) { Q_D(QGLFramebufferObject); - d->init(QSize(width, height), format.attachment(), format.textureTarget(), format.internalFormat(), format.samples()); + d->init(QSize(width, height), format.attachment(), format.textureTarget(), format.internalTextureFormat(), format.samples()); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS @@ -736,16 +737,19 @@ QGLFramebufferObject::~QGLFramebufferObject() delete d->engine; - if (isValid() - && (d->ctx == QGLContext::currentContext() - || qgl_share_reg()->checkSharing(d->ctx, QGLContext::currentContext()))) - { + if (isValid()) { + const QGLContext *oldContext = QGLContext::currentContext(); + bool switchContext = !oldContext || QGLContextPrivate::contextGroup(oldContext) != ctx; + if (switchContext) + const_cast<QGLContext *>(ctx->context())->makeCurrent(); glDeleteTextures(1, &d->texture); if (d->color_buffer) glDeleteRenderbuffers(1, &d->color_buffer); if (d->depth_stencil_buffer) glDeleteRenderbuffers(1, &d->depth_stencil_buffer); glDeleteFramebuffers(1, &d->fbo); + if (oldContext && switchContext) + const_cast<QGLContext *>(oldContext)->makeCurrent(); } } @@ -791,7 +795,7 @@ bool QGLFramebufferObject::bind() Q_D(QGLFramebufferObject); QGL_FUNC_CONTEXT; glBindFramebuffer(GL_FRAMEBUFFER_EXT, d->fbo); - d->bound = d->valid = d->checkFramebufferStatus(); + d->valid = d->checkFramebufferStatus(); const QGLContext *context = QGLContext::currentContext(); if (d->valid && context) { // Save the previous setting to automatically restore in release(). @@ -822,7 +826,6 @@ bool QGLFramebufferObject::release() return false; Q_D(QGLFramebufferObject); QGL_FUNC_CONTEXT; - d->bound = false; const QGLContext *context = QGLContext::currentContext(); if (context) { @@ -898,7 +901,7 @@ QImage QGLFramebufferObject::toImage() const bool wasBound = isBound(); if (!wasBound) const_cast<QGLFramebufferObject *>(this)->bind(); - QImage image = qt_gl_read_framebuffer(d->size, d->ctx->format().alpha(), true); + QImage image = qt_gl_read_framebuffer(d->size, format().textureTarget() != GL_RGB, true); if (!wasBound) const_cast<QGLFramebufferObject *>(this)->release(); @@ -970,16 +973,14 @@ bool QGLFramebufferObject::hasOpenGLFramebufferObjects() */ void QGLFramebufferObject::drawTexture(const QRectF &target, GLuint textureId, GLenum textureTarget) { - Q_D(QGLFramebufferObject); - d->ctx->drawTexture(target, textureId, textureTarget); + const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(target, textureId, textureTarget); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS /*! \internal */ void QGLFramebufferObject::drawTexture(const QRectF &target, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) { - Q_D(QGLFramebufferObject); - d->ctx->drawTexture(target, textureId, textureTarget); + const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(target, textureId, textureTarget); } #endif @@ -995,16 +996,14 @@ void QGLFramebufferObject::drawTexture(const QRectF &target, QMacCompatGLuint te */ void QGLFramebufferObject::drawTexture(const QPointF &point, GLuint textureId, GLenum textureTarget) { - Q_D(QGLFramebufferObject); - d->ctx->drawTexture(point, textureId, textureTarget); + const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(point, textureId, textureTarget); } #ifdef Q_MAC_COMPAT_GL_FUNCTIONS /*! \internal */ void QGLFramebufferObject::drawTexture(const QPointF &point, QMacCompatGLuint textureId, QMacCompatGLenum textureTarget) { - Q_D(QGLFramebufferObject); - d->ctx->drawTexture(point, textureId, textureTarget); + const_cast<QGLContext *>(QGLContext::currentContext())->drawTexture(point, textureId, textureTarget); } #endif @@ -1101,7 +1100,7 @@ QGLFramebufferObject::Attachment QGLFramebufferObject::attachment() const bool QGLFramebufferObject::isBound() const { Q_D(const QGLFramebufferObject); - return d->bound; + return QGLContext::currentContext()->d_ptr->current_fbo == d->fbo; } /*! diff --git a/src/opengl/qglframebufferobject.h b/src/opengl/qglframebufferobject.h index ad14e50..ec1ae7d 100644 --- a/src/opengl/qglframebufferobject.h +++ b/src/opengl/qglframebufferobject.h @@ -151,12 +151,12 @@ public: void setTextureTarget(GLenum target); GLenum textureTarget() const; - void setInternalFormat(GLenum internalFormat); - GLenum internalFormat() const; + void setInternalTextureFormat(GLenum internalTextureFormat); + GLenum internalTextureFormat() const; #ifdef Q_MAC_COMPAT_GL_FUNCTIONS void setTextureTarget(QMacCompatGLenum target); - void setInternalFormat(QMacCompatGLenum internalFormat); + void setInternalTextureFormat(QMacCompatGLenum internalTextureFormat); #endif private: diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index 56e5baa..68db9c0 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -324,7 +324,7 @@ bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const filter->setSource(generateBlurShader(radius(), quality() == Qt::SmoothTransformation)); QGLFramebufferObjectFormat format; - format.setInternalFormat(GLenum(src.hasAlphaChannel() ? GL_RGBA : GL_RGB)); + format.setInternalTextureFormat(GLenum(src.hasAlphaChannel() ? GL_RGBA : GL_RGB)); QGLFramebufferObject *fbo = qgl_fbo_pool()->acquire(src.size(), format); if (!fbo) diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 56b55d0..bcc6c61 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -2288,6 +2288,58 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) setUniformValue(uniformLocation(name), size); } +// We have to repack matrices from qreal to GLfloat. +#define setUniformMatrix(func,location,value,cols,rows) \ + if (location == -1) \ + return; \ + if (sizeof(qreal) == sizeof(GLfloat)) { \ + func(location, 1, GL_FALSE, \ + reinterpret_cast<const GLfloat *>(value.constData())); \ + } else { \ + GLfloat mat[cols * rows]; \ + const qreal *data = value.constData(); \ + for (int i = 0; i < cols * rows; ++i) \ + mat[i] = data[i]; \ + func(location, 1, GL_FALSE, mat); \ + } +#if !defined(QT_OPENGL_ES_2) +#define setUniformGenericMatrix(func,colfunc,location,value,cols,rows) \ + if (location == -1) \ + return; \ + if (sizeof(qreal) == sizeof(GLfloat)) { \ + const GLfloat *data = reinterpret_cast<const GLfloat *> \ + (value.constData()); \ + if (func) \ + func(location, 1, GL_FALSE, data); \ + else \ + colfunc(location, cols, data); \ + } else { \ + GLfloat mat[cols * rows]; \ + const qreal *data = value.constData(); \ + for (int i = 0; i < cols * rows; ++i) \ + mat[i] = data[i]; \ + if (func) \ + func(location, 1, GL_FALSE, mat); \ + else \ + colfunc(location, cols, mat); \ + } +#else +#define setUniformGenericMatrix(func,colfunc,location,value,cols,rows) \ + if (location == -1) \ + return; \ + if (sizeof(qreal) == sizeof(GLfloat)) { \ + const GLfloat *data = reinterpret_cast<const GLfloat *> \ + (value.constData()); \ + colfunc(location, cols, data); \ + } else { \ + GLfloat mat[cols * rows]; \ + const qreal *data = value.constData(); \ + for (int i = 0; i < cols * rows; ++i) \ + mat[i] = data[i]; \ + colfunc(location, cols, mat); \ + } +#endif + /*! Sets the uniform variable at \a location in the current context to a 2x2 matrix \a value. @@ -2296,8 +2348,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value) { - if (location != -1) - glUniformMatrix2fv(location, 1, GL_FALSE, value.data()); + setUniformMatrix(glUniformMatrix2fv, location, value, 2, 2); } /*! @@ -2321,20 +2372,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix2x3fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix2x3fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform3fv(location, 2, value.data()); - } - } -#else - if (location != -1) - glUniform3fv(location, 2, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix2x3fv, glUniform3fv, location, value, 2, 3); } /*! @@ -2358,20 +2397,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix2x4fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix2x4fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform4fv(location, 2, value.data()); - } - } -#else - if (location != -1) - glUniform4fv(location, 2, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix2x4fv, glUniform4fv, location, value, 2, 4); } /*! @@ -2395,20 +2422,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix3x2fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix3x2fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform2fv(location, 3, value.data()); - } - } -#else - if (location != -1) - glUniform2fv(location, 3, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix3x2fv, glUniform2fv, location, value, 3, 2); } /*! @@ -2432,8 +2447,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value) { - if (location != -1) - glUniformMatrix3fv(location, 1, GL_FALSE, value.data()); + setUniformMatrix(glUniformMatrix3fv, location, value, 3, 3); } /*! @@ -2457,20 +2471,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix3x4fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix3x4fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform4fv(location, 3, value.data()); - } - } -#else - if (location != -1) - glUniform4fv(location, 3, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix3x4fv, glUniform4fv, location, value, 3, 4); } /*! @@ -2494,20 +2496,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix4x2fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix4x2fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform2fv(location, 4, value.data()); - } - } -#else - if (location != -1) - glUniform2fv(location, 4, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix4x2fv, glUniform2fv, location, value, 4, 2); } /*! @@ -2531,20 +2521,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value) { -#if !defined(QT_OPENGL_ES_2) - if (location != -1) { - if (glUniformMatrix4x3fv) { - // OpenGL 2.1+: pass the matrix directly. - glUniformMatrix4x3fv(location, 1, GL_FALSE, value.data()); - } else { - // OpenGL 2.0: pass the matrix columns as a vector. - glUniform3fv(location, 4, value.data()); - } - } -#else - if (location != -1) - glUniform3fv(location, 4, value.data()); -#endif + setUniformGenericMatrix + (glUniformMatrix4x3fv, glUniform3fv, location, value, 4, 3); } /*! @@ -2568,8 +2546,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value */ void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value) { - if (location != -1) - glUniformMatrix4fv(location, 1, GL_FALSE, value.data()); + setUniformMatrix(glUniformMatrix4fv, location, value, 4, 4); } /*! @@ -2815,18 +2792,20 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v setUniformValueArray(uniformLocation(name), values, count); } -// We may have to repack matrix arrays if the matrix types -// contain additional flag bits. Especially QMatrix4x4. +// We have to repack matrix arrays from qreal to GLfloat. #define setUniformMatrixArray(func,location,values,count,type,cols,rows) \ if (location == -1 || count <= 0) \ return; \ - if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \ - func(location, count, GL_FALSE, values->constData()); \ + if (sizeof(type) == sizeof(GLfloat) * cols * rows) { \ + func(location, count, GL_FALSE, \ + reinterpret_cast<const GLfloat *>(values[0].constData())); \ } else { \ QVarLengthArray<GLfloat> temp(cols * rows * count); \ for (int index = 0; index < count; ++index) { \ - qMemCopy(temp.data() + cols * rows * index, \ - values[index].constData(), cols * rows * sizeof(GLfloat)); \ + for (int index2 = 0; index2 < (cols * rows); ++index2) { \ + temp.data()[cols * rows * index + index2] = \ + values[index].constData()[index2]; \ + } \ } \ func(location, count, GL_FALSE, temp.constData()); \ } @@ -2834,16 +2813,20 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v #define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \ if (location == -1 || count <= 0) \ return; \ - if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \ + if (sizeof(type) == sizeof(GLfloat) * cols * rows) { \ + const GLfloat *data = reinterpret_cast<const GLfloat *> \ + (values[0].constData()); \ if (func) \ - func(location, count, GL_FALSE, values->constData()); \ + func(location, count, GL_FALSE, data); \ else \ - colfunc(location, cols * count, values->constData()); \ + colfunc(location, count * cols, data); \ } else { \ QVarLengthArray<GLfloat> temp(cols * rows * count); \ for (int index = 0; index < count; ++index) { \ - qMemCopy(temp.data() + cols * rows * index, \ - values[index].constData(), cols * rows * sizeof(GLfloat)); \ + for (int index2 = 0; index2 < (cols * rows); ++index2) { \ + temp.data()[cols * rows * index + index2] = \ + values[index].constData()[index2]; \ + } \ } \ if (func) \ func(location, count, GL_FALSE, temp.constData()); \ @@ -2854,13 +2837,17 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v #define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \ if (location == -1 || count <= 0) \ return; \ - if (count == 1 || sizeof(type) == cols * rows * sizeof(GLfloat)) { \ - colfunc(location, cols * count, values->constData()); \ + if (sizeof(type) == sizeof(GLfloat) * cols * rows) { \ + const GLfloat *data = reinterpret_cast<const GLfloat *> \ + (values[0].constData()); \ + colfunc(location, count * cols, data); \ } else { \ QVarLengthArray<GLfloat> temp(cols * rows * count); \ for (int index = 0; index < count; ++index) { \ - qMemCopy(temp.data() + cols * rows * index, \ - values[index].constData(), cols * rows * sizeof(GLfloat)); \ + for (int index2 = 0; index2 < (cols * rows); ++index2) { \ + temp.data()[cols * rows * index + index2] = \ + values[index].constData()[index2]; \ + } \ } \ colfunc(location, count * cols, temp.constData()); \ } diff --git a/src/opengl/qgraphicsshadereffect.cpp b/src/opengl/qgraphicsshadereffect.cpp index f1558d1..f733109 100644 --- a/src/opengl/qgraphicsshadereffect.cpp +++ b/src/opengl/qgraphicsshadereffect.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qgraphicsshadereffect.h" +#include "qgraphicsshadereffect_p.h" #if !defined(QT_OPENGL_ES_1) && !defined(QT_OPENGL_ES_1_CL) #include "qglshaderprogram.h" #include "gl2paintengineex/qglcustomshaderstage_p.h" @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE -/*! +/*# \class QGraphicsShaderEffect \brief The QGraphicsShaderEffect class is the base class for creating custom GLSL shader effects in a QGraphicsScene. @@ -175,7 +175,7 @@ public: #endif }; -/*! +/*# Constructs a shader effect and attaches it to \a parent. */ QGraphicsShaderEffect::QGraphicsShaderEffect(QObject *parent) @@ -183,7 +183,7 @@ QGraphicsShaderEffect::QGraphicsShaderEffect(QObject *parent) { } -/*! +/*# Destroys this shader effect. */ QGraphicsShaderEffect::~QGraphicsShaderEffect() @@ -194,7 +194,7 @@ QGraphicsShaderEffect::~QGraphicsShaderEffect() #endif } -/*! +/*# Returns the source code for the pixel shader fragment for this shader effect. The default is a shader that copies its incoming pixmap directly to the output with no effect @@ -208,7 +208,7 @@ QByteArray QGraphicsShaderEffect::pixelShaderFragment() const return d->pixelShaderFragment; } -/*! +/*# Sets the source code for the pixel shader fragment for this shader effect to \a code. @@ -238,7 +238,7 @@ void QGraphicsShaderEffect::setPixelShaderFragment(const QByteArray& code) } } -/*! +/*# \reimp */ void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *source) @@ -277,7 +277,7 @@ void QGraphicsShaderEffect::draw(QPainter *painter, QGraphicsEffectSource *sourc #endif } -/*! +/*# Sets the custom uniform variables on this shader effect to be dirty. The setUniforms() function will be called the next time the shader program corresponding to this effect is used. @@ -296,7 +296,7 @@ void QGraphicsShaderEffect::setUniformsDirty() #endif } -/*! +/*# Sets custom uniform variables on the current GL context when \a program is about to be used by the paint engine. diff --git a/src/opengl/qgraphicsshadereffect.h b/src/opengl/qgraphicsshadereffect_p.h index a186074..a313846 100644 --- a/src/opengl/qgraphicsshadereffect.h +++ b/src/opengl/qgraphicsshadereffect_p.h @@ -39,8 +39,19 @@ ** ****************************************************************************/ -#ifndef QGRAPHICSSHADEREFFECT_H -#define QGRAPHICSSHADEREFFECT_H +#ifndef QGRAPHICSSHADEREFFECT_P_H +#define QGRAPHICSSHADEREFFECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// #include <QtGui/qgraphicseffect.h> @@ -80,4 +91,4 @@ QT_END_NAMESPACE QT_END_HEADER -#endif // QGRAPHICSSHADEREFFECT_H +#endif // QGRAPHICSSHADEREFFECT_P_H diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index b6f5012..d63d2ad 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -84,7 +84,7 @@ QGLFramebufferObject *QGLFramebufferObjectPool::acquire(const QSize &requestSize if (format.samples() == requestFormat.samples() && format.attachment() == requestFormat.attachment() && format.textureTarget() == requestFormat.textureTarget() - && format.internalFormat() == requestFormat.internalFormat()) + && format.internalTextureFormat() == requestFormat.internalTextureFormat()) { // choose the fbo with a matching format and the closest size if (!candidate || areaDiff(requestSize, candidate) > areaDiff(requestSize, fbo)) @@ -467,7 +467,7 @@ QPaintEngine* QGLPixmapData::paintEngine() const QGLFramebufferObjectFormat format; format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); format.setSamples(4); - format.setInternalFormat(GLenum(m_hasAlpha ? GL_RGBA : GL_RGB)); + format.setInternalTextureFormat(GLenum(m_hasAlpha ? GL_RGBA : GL_RGB)); m_renderFbo = qgl_fbo_pool()->acquire(size(), format); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index f974938..a85b9ae 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -569,7 +569,7 @@ void QGLWindowSurface::updateGeometry() QGLFramebufferObjectFormat format; format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); - format.setInternalFormat(GLenum(GL_RGBA)); + format.setInternalTextureFormat(GLenum(GL_RGBA)); format.setTextureTarget(target); if (QGLExtensions::glExtensions & QGLExtensions::FramebufferBlit) |