summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-13 14:28:58 +0200
committerMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-13 14:28:58 +0200
commit02ff2973ceeef00ced4468b6e15cfadd9f021b0d (patch)
treee5b51329fceb3d0134e533e41c0f3800549f1786 /src/gui/opengl
parentc5b743472fc36986cf34636dbcb73a0d0fa6b9e6 (diff)
parent16c32710bc8a5ecefc833352159361be564f3fe4 (diff)
Merge remote-tracking branch 'gerrit/dev' into dev-highdpi
Conflicts: src/plugins/platforms/xcb/qxcbbackingstore.cpp Change-Id: Ib7f277957636186d0abd58d8c710392ef7b02e13
Diffstat (limited to 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopengldebug.cpp20
-rw-r--r--src/gui/opengl/qopenglframebufferobject.cpp6
-rw-r--r--src/gui/opengl/qopenglgradientcache.cpp43
-rw-r--r--src/gui/opengl/qopenglgradientcache_p.h3
-rw-r--r--src/gui/opengl/qopengltexture.cpp2
-rw-r--r--src/gui/opengl/qopenglversionfunctions.cpp26
-rw-r--r--src/gui/opengl/qopenglversionfunctions.h13
-rw-r--r--src/gui/opengl/qopenglvertexarrayobject.cpp13
8 files changed, 94 insertions, 32 deletions
diff --git a/src/gui/opengl/qopengldebug.cpp b/src/gui/opengl/qopengldebug.cpp
index 114f118989..e747372df9 100644
--- a/src/gui/opengl/qopengldebug.cpp
+++ b/src/gui/opengl/qopengldebug.cpp
@@ -1039,10 +1039,11 @@ bool QOpenGLDebugMessage::operator==(const QOpenGLDebugMessage &debugMessage) co
*/
QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Source source)
{
+ QDebugStateSaver saver(debug);
debug.nospace() << "QOpenGLDebugMessage::Source("
<< qt_messageSourceToString(source)
- << ")";
- return debug.space();
+ << ')';
+ return debug;
}
/*!
@@ -1053,10 +1054,11 @@ QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Source source)
*/
QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Type type)
{
+ QDebugStateSaver saver(debug);
debug.nospace() << "QOpenGLDebugMessage::Type("
<< qt_messageTypeToString(type)
- << ")";
- return debug.space();
+ << ')';
+ return debug;
}
/*!
@@ -1067,10 +1069,11 @@ QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Type type)
*/
QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Severity severity)
{
+ QDebugStateSaver saver(debug);
debug.nospace() << "QOpenGLDebugMessage::Severity("
<< qt_messageSeverityToString(severity)
- << ")";
- return debug.space();
+ << ')';
+ return debug;
}
/*!
@@ -1081,13 +1084,14 @@ QDebug operator<<(QDebug debug, QOpenGLDebugMessage::Severity severity)
*/
QDebug operator<<(QDebug debug, const QOpenGLDebugMessage &message)
{
+ QDebugStateSaver saver(debug);
debug.nospace() << "QOpenGLDebugMessage("
<< qt_messageSourceToString(message.source()) << ", "
<< message.id() << ", "
<< message.message() << ", "
<< qt_messageSeverityToString(message.severity()) << ", "
- << qt_messageTypeToString(message.type()) << ")";
- return debug.space();
+ << qt_messageTypeToString(message.type()) << ')';
+ return debug;
}
#endif // QT_NO_DEBUG_STREAM
diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp
index c4deeea4c9..8d298496df 100644
--- a/src/gui/opengl/qopenglframebufferobject.cpp
+++ b/src/gui/opengl/qopenglframebufferobject.cpp
@@ -1484,8 +1484,10 @@ void QOpenGLFramebufferObject::blitFramebuffer(QOpenGLFramebufferObject *target,
const int ty0 = targetRect.top();
const int ty1 = targetRect.top() + targetRect.height();
- extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, source ? source->handle() : 0);
- extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target ? target->handle() : 0);
+ const GLuint defaultFboId = ctx->defaultFramebufferObject();
+
+ extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, source ? source->handle() : defaultFboId);
+ extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, target ? target->handle() : defaultFboId);
extensions.glBlitFramebuffer(sx0, sy0, sx1, sy1,
tx0, ty0, tx1, ty1,
diff --git a/src/gui/opengl/qopenglgradientcache.cpp b/src/gui/opengl/qopenglgradientcache.cpp
index ab493fa85c..6622d4805f 100644
--- a/src/gui/opengl/qopenglgradientcache.cpp
+++ b/src/gui/opengl/qopenglgradientcache.cpp
@@ -34,8 +34,18 @@
#include "qopenglgradientcache_p.h"
#include <private/qdrawhelper_p.h>
#include <private/qopenglcontext_p.h>
+#include <private/qrgba64_p.h>
#include <QtCore/qmutex.h>
-#include <QtGui/qopenglfunctions.h>
+#include "qopenglfunctions.h"
+#include "qopenglextensions_p.h"
+
+#ifndef GL_RGBA8
+#define GL_RGBA8 0x8058
+#endif
+
+#ifndef GL_RGBA16
+#define GL_RGBA16 0x805B
+#endif
QT_BEGIN_NAMESPACE
@@ -137,33 +147,40 @@ GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient
}
CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode());
- uint buffer[1024];
+ QRgba64 buffer[1024];
generateGradientColorTable(gradient, buffer, paletteSize(), opacity);
funcs->glGenTextures(1, &cache_entry.texId);
funcs->glBindTexture(GL_TEXTURE_2D, cache_entry.texId);
- funcs->glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, paletteSize(), 1,
- 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
+ GLenum internalFormat = GL_RGBA16;
+ if (QOpenGLContext::currentContext()->isOpenGLES()) {
+ if (static_cast<QOpenGLExtensions*>(funcs)->hasOpenGLExtension(QOpenGLExtensions::Sized8Formats))
+ internalFormat = GL_RGBA8;
+ else
+ internalFormat = GL_RGBA; // Let OpenGLES use whatever it prefers.
+ }
+ funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, paletteSize(), 1,
+ 0, GL_RGBA, GL_UNSIGNED_SHORT, buffer);
return cache.insert(hash_val, cache_entry).value().texId;
}
//TODO: Let GL generate the texture using an FBO
-void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
+void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, QRgba64 *colorTable, int size, qreal opacity) const
{
int pos = 0;
QGradientStops s = gradient.stops();
- QVector<uint> colors(s.size());
+ QVector<QRgba64> colors(s.size());
for (int i = 0; i < s.size(); ++i)
- colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian)
+ colors[i] = s[i].second.rgba64();
bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);
uint alpha = qRound(opacity * 256);
- uint current_color = ARGB_COMBINE_ALPHA(colors[0], alpha);
+ QRgba64 current_color = combineAlpha256(colors[0], alpha);
qreal incr = 1.0 / qreal(size);
qreal fpos = 1.5 * incr;
- colorTable[pos++] = ARGB2RGBA(qPremultiply(current_color));
+ colorTable[pos++] = qPremultiply(current_color);
while (fpos <= s.first().first) {
colorTable[pos] = colorTable[pos - 1];
@@ -176,7 +193,7 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
for (int i = 0; i < s.size() - 1; ++i) {
qreal delta = 1/(s[i+1].first - s[i].first);
- uint next_color = ARGB_COMBINE_ALPHA(colors[i+1], alpha);
+ QRgba64 next_color = combineAlpha256(colors[i+1], alpha);
if (colorInterpolation)
next_color = qPremultiply(next_color);
@@ -184,9 +201,9 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
int dist = int(256 * ((fpos - s[i].first) * delta));
int idist = 256 - dist;
if (colorInterpolation)
- colorTable[pos] = ARGB2RGBA(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
+ colorTable[pos] = interpolate256(current_color, idist, next_color, dist);
else
- colorTable[pos] = ARGB2RGBA(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)));
+ colorTable[pos] = qPremultiply(interpolate256(current_color, idist, next_color, dist));
++pos;
fpos += incr;
}
@@ -195,7 +212,7 @@ void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient
Q_ASSERT(s.size() > 0);
- uint last_color = ARGB2RGBA(qPremultiply(ARGB_COMBINE_ALPHA(colors[s.size() - 1], alpha)));
+ QRgba64 last_color = qPremultiply(combineAlpha256(colors[s.size() - 1], alpha));
for (;pos < size; ++pos)
colorTable[pos] = last_color;
diff --git a/src/gui/opengl/qopenglgradientcache_p.h b/src/gui/opengl/qopenglgradientcache_p.h
index bcdf3f4fcf..d368f4bcfc 100644
--- a/src/gui/opengl/qopenglgradientcache_p.h
+++ b/src/gui/opengl/qopenglgradientcache_p.h
@@ -50,6 +50,7 @@
#include <private/qopenglcontext_p.h>
#include <QtCore/qmutex.h>
#include <QGradient>
+#include <qrgba64.h>
QT_BEGIN_NAMESPACE
@@ -83,7 +84,7 @@ public:
private:
inline int maxCacheSize() const { return 60; }
inline void generateGradientColorTable(const QGradient& gradient,
- uint *colorTable,
+ QRgba64 *colorTable,
int size, qreal opacity) const;
GLuint addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity);
void cleanCache();
diff --git a/src/gui/opengl/qopengltexture.cpp b/src/gui/opengl/qopengltexture.cpp
index fa4b6cdab0..9bc9926b70 100644
--- a/src/gui/opengl/qopengltexture.cpp
+++ b/src/gui/opengl/qopengltexture.cpp
@@ -3650,7 +3650,7 @@ QOpenGLTexture::DepthStencilMode QOpenGLTexture::depthStencilMode() const
}
/*!
- \enum ComparisonFunction
+ \enum QOpenGLTexture::ComparisonFunction
\since 5.5
This enum specifies which comparison operator is used when texture comparison
is enabled on this texture.
diff --git a/src/gui/opengl/qopenglversionfunctions.cpp b/src/gui/opengl/qopenglversionfunctions.cpp
index f3f709c3f0..346a526054 100644
--- a/src/gui/opengl/qopenglversionfunctions.cpp
+++ b/src/gui/opengl/qopenglversionfunctions.cpp
@@ -67,6 +67,17 @@ void QAbstractOpenGLFunctionsPrivate::removeFunctionsBackend(QOpenGLContext *con
context->removeFunctionsBackend(v);
}
+void QAbstractOpenGLFunctionsPrivate::insertExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f)
+{
+ Q_ASSERT(context);
+ context->insertExternalFunctions(f);
+}
+
+void QAbstractOpenGLFunctionsPrivate::removeExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f)
+{
+ Q_ASSERT(context);
+ context->removeExternalFunctions(f);
+}
/*!
\class QAbstractOpenGLFunctions
@@ -182,6 +193,9 @@ QAbstractOpenGLFunctions::QAbstractOpenGLFunctions()
QAbstractOpenGLFunctions::~QAbstractOpenGLFunctions()
{
+ Q_D(QAbstractOpenGLFunctions);
+ if (d->owningContext)
+ d->removeExternalFunctions(d->owningContext, this);
delete d_ptr;
}
@@ -191,6 +205,18 @@ bool QAbstractOpenGLFunctions::initializeOpenGLFunctions()
{
Q_D(QAbstractOpenGLFunctions);
d->initialized = true;
+
+ // For a subclass whose instance is not created via
+ // QOpenGLContext::versionFunctions() owningContext is not set. Set it now
+ // and register such instances to the context as external ones. These are
+ // not owned by the context but still need certain cleanup when the context
+ // is destroyed.
+ if (!d->owningContext) {
+ d->owningContext = QOpenGLContext::currentContext();
+ if (d->owningContext)
+ d->insertExternalFunctions(d->owningContext, this);
+ }
+
return true;
}
diff --git a/src/gui/opengl/qopenglversionfunctions.h b/src/gui/opengl/qopenglversionfunctions.h
index 2ae0f429e5..fcf665f97e 100644
--- a/src/gui/opengl/qopenglversionfunctions.h
+++ b/src/gui/opengl/qopenglversionfunctions.h
@@ -114,6 +114,8 @@ public:
QAtomicInt refs;
};
+class QAbstractOpenGLFunctions;
+
class QAbstractOpenGLFunctionsPrivate
{
public:
@@ -128,12 +130,16 @@ public:
const QOpenGLVersionStatus &v,
QOpenGLVersionFunctionsBackend *backend);
static void removeFunctionsBackend(QOpenGLContext *context, const QOpenGLVersionStatus &v);
+ static void insertExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f);
+ static void removeExternalFunctions(QOpenGLContext *context, QAbstractOpenGLFunctions *f);
+
+ static QAbstractOpenGLFunctionsPrivate *get(QAbstractOpenGLFunctions *q);
QOpenGLContext *owningContext;
bool initialized;
};
-class QAbstractOpenGLFunctions
+class Q_GUI_EXPORT QAbstractOpenGLFunctions
{
public:
virtual ~QAbstractOpenGLFunctions();
@@ -154,6 +160,11 @@ protected:
friend class QOpenGLContext;
};
+inline QAbstractOpenGLFunctionsPrivate *QAbstractOpenGLFunctionsPrivate::get(QAbstractOpenGLFunctions *q)
+{
+ return q->d_func();
+}
+
#if !defined(QT_OPENGL_ES_2)
class QOpenGLFunctions_1_0_CoreBackend : public QOpenGLVersionFunctionsBackend
diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp
index 6b0f2fede7..2a1b7f4bf4 100644
--- a/src/gui/opengl/qopenglvertexarrayobject.cpp
+++ b/src/gui/opengl/qopenglvertexarrayobject.cpp
@@ -189,11 +189,16 @@ bool QOpenGLVertexArrayObjectPrivate::create()
void QOpenGLVertexArrayObjectPrivate::destroy()
{
+ Q_Q(QOpenGLVertexArrayObject);
+
+ if (context) {
+ QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
+ context = 0;
+ }
+
if (!vao)
return;
- Q_Q(QOpenGLVertexArrayObject);
-
switch (vaoFuncsType) {
#ifndef QT_OPENGL_ES_2
case Core_3_2:
@@ -212,10 +217,6 @@ void QOpenGLVertexArrayObjectPrivate::destroy()
break;
}
- Q_ASSERT(context);
- QObject::disconnect(context, SIGNAL(aboutToBeDestroyed()), q, SLOT(_q_contextAboutToBeDestroyed()));
- context = 0;
-
vao = 0;
}