diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/opengl/qopenglframebufferobject.cpp | 35 | ||||
-rw-r--r-- | src/gui/opengl/qopengltexturecache.cpp | 31 | ||||
-rw-r--r-- | src/gui/opengl/qopenglvertexarrayobject.cpp | 86 | ||||
-rw-r--r-- | src/gui/opengl/qopenglvertexarrayobject.h | 2 | ||||
-rw-r--r-- | src/gui/opengl/qopenglvertexarrayobject_p.h | 119 |
5 files changed, 216 insertions, 57 deletions
diff --git a/src/gui/opengl/qopenglframebufferobject.cpp b/src/gui/opengl/qopenglframebufferobject.cpp index 0c05b61e76..16094804c2 100644 --- a/src/gui/opengl/qopenglframebufferobject.cpp +++ b/src/gui/opengl/qopenglframebufferobject.cpp @@ -104,10 +104,18 @@ QT_BEGIN_NAMESPACE #define GL_RGB8 0x8051 #endif +#ifndef GL_RGB10 +#define GL_RGB10 0x8052 +#endif + #ifndef GL_RGBA8 #define GL_RGBA8 0x8058 #endif +#ifndef GL_RGB10_A2 +#define GL_RGB10_A2 0x8059 +#endif + #ifndef GL_BGRA #define GL_BGRA 0x80E1 #endif @@ -116,6 +124,10 @@ QT_BEGIN_NAMESPACE #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 #endif +#ifndef GL_UNSIGNED_INT_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#endif + /*! \class QOpenGLFramebufferObjectFormat @@ -539,8 +551,12 @@ void QOpenGLFramebufferObjectPrivate::initTexture(GLenum target, GLenum internal funcs.glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); funcs.glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + GLuint pixelType = GL_UNSIGNED_BYTE; + if (internal_format == GL_RGB10_A2 || internal_format == GL_RGB10) + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + funcs.glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + GL_RGBA, pixelType, NULL); if (mipmap) { int width = size.width(); int height = size.height(); @@ -550,7 +566,7 @@ void QOpenGLFramebufferObjectPrivate::initTexture(GLenum target, GLenum internal height = qMax(1, height >> 1); ++level; funcs.glTexImage2D(target, level, internal_format, width, height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); + GL_RGBA, pixelType, NULL); } } funcs.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, @@ -1142,6 +1158,14 @@ static inline QImage qt_gl_read_framebuffer_rgba8(const QSize &size, bool includ return rgbaImage; } +static inline QImage qt_gl_read_framebuffer_rgb10a2(const QSize &size, bool include_alpha, QOpenGLContext *context) +{ + // We assume OpenGL 1.2+ or ES 3.0+ here. + QImage img(size, include_alpha ? QImage::Format_A2BGR30_Premultiplied : QImage::Format_BGR30); + context->functions()->glReadPixels(0, 0, size.width(), size.height(), GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, img.bits()); + return img; +} + static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, bool include_alpha, bool flip) { QOpenGLContext *ctx = QOpenGLContext::currentContext(); @@ -1152,6 +1176,10 @@ static QImage qt_gl_read_framebuffer(const QSize &size, GLenum internal_format, case GL_RGB: case GL_RGB8: return qt_gl_read_framebuffer_rgba8(size, false, ctx).mirrored(false, flip); + case GL_RGB10: + return qt_gl_read_framebuffer_rgb10a2(size, false, ctx).mirrored(false, flip); + case GL_RGB10_A2: + return qt_gl_read_framebuffer_rgb10a2(size, include_alpha, ctx).mirrored(false, flip); case GL_RGBA: case GL_RGBA8: default: @@ -1177,7 +1205,8 @@ Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_format, of QOpenGLPaintDevice::paintFlipped(). Will try to return a premultiplied ARBG32 or RGB32 image. Since 5.2 it will fall back to - a premultiplied RGBA8888 or RGBx8888 image when reading to ARGB32 is not supported. + a premultiplied RGBA8888 or RGBx8888 image when reading to ARGB32 is not supported. Since 5.4 an + A2BGR30 image is returned if the internal format is RGB10_A2. For multisampled framebuffer objects the samples are resolved using the \c{GL_EXT_framebuffer_blit} extension. If the extension is not available, the contents diff --git a/src/gui/opengl/qopengltexturecache.cpp b/src/gui/opengl/qopengltexturecache.cpp index 4a4a36d7e5..055974d5a4 100644 --- a/src/gui/opengl/qopengltexturecache.cpp +++ b/src/gui/opengl/qopengltexturecache.cpp @@ -49,6 +49,10 @@ QT_BEGIN_NAMESPACE +#ifndef GL_RGB10_A2 +#define GL_RGB10_A2 0x8059 +#endif + #ifndef GL_BGR #define GL_BGR 0x80E0 #endif @@ -61,6 +65,10 @@ QT_BEGIN_NAMESPACE #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 #endif +#ifndef GL_UNSIGNED_INT_2_10_10_10_REV +#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 +#endif + class QOpenGLTextureCacheWrapper { public: @@ -228,6 +236,29 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con } targetFormat = image.format(); break; + case QImage::Format_BGR30: + case QImage::Format_A2BGR30_Premultiplied: + if (isOpenGL12orBetter || (context->isOpenGLES() && context->format().majorVersion() >= 3)) { + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + externalFormat = GL_RGBA; + internalFormat = GL_RGB10_A2; + targetFormat = image.format(); + } + break; + case QImage::Format_RGB30: + case QImage::Format_A2RGB30_Premultiplied: + if (isOpenGL12orBetter) { + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + externalFormat = GL_BGRA; + internalFormat = GL_RGB10_A2; + targetFormat = image.format(); + } else if (context->isOpenGLES() && context->format().majorVersion() >= 3) { + pixelType = GL_UNSIGNED_INT_2_10_10_10_REV; + externalFormat = GL_RGBA; + internalFormat = GL_RGB10_A2; + targetFormat = QImage::Format_A2BGR30_Premultiplied; + } + break; case QImage::Format_RGB444: case QImage::Format_RGB555: case QImage::Format_RGB16: diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp index d9b9385751..3b106fecf5 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.cpp +++ b/src/gui/opengl/qopenglvertexarrayobject.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sean Harmer <sean.harmer@kdab.com> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -49,69 +49,49 @@ #include <QtGui/qopenglfunctions_3_0.h> #include <QtGui/qopenglfunctions_3_2_core.h> +#include <private/qopenglvertexarrayobject_p.h> + QT_BEGIN_NAMESPACE class QOpenGLFunctions_3_0; class QOpenGLFunctions_3_2_Core; -class QVertexArrayObjectHelper +void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context) { -public: - QVertexArrayObjectHelper(QOpenGLContext *context) - { - Q_ASSERT(context); - bool tryARB = true; + Q_ASSERT(helper); + Q_ASSERT(context); + + bool tryARB = true; - if (context->isOpenGLES()) { + if (context->isOpenGLES()) { #ifdef QT_OPENGL_ES_3 - GenVertexArrays = ::glGenVertexArrays; - DeleteVertexArrays = ::glDeleteVertexArrays; - BindVertexArray = ::glBindVertexArray; + if (context->format().majorVersion() >= 3) { + helper->GenVertexArrays = ::glGenVertexArrays; + helper->DeleteVertexArrays = ::glDeleteVertexArrays; + helper->BindVertexArray = ::glBindVertexArray; tryARB = false; -#else - if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) { - GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES"))); - DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES"))); - BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES"))); - tryARB = false; - } + } else #endif - } else if (!context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object")) - && context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) { - GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE"))); - DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE"))); - BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE"))); + if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) { + helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES"))); + helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES"))); + helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES"))); tryARB = false; } - - if (tryARB) { - GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays"))); - DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays"))); - BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray"))); - } - } - - inline void glGenVertexArrays(GLsizei n, GLuint *arrays) - { - GenVertexArrays(n, arrays); + } else if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object")) && + !context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { + helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE"))); + helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE"))); + helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE"))); + tryARB = false; } - inline void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) - { - DeleteVertexArrays(n, arrays); + if (tryARB && context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { + helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays"))); + helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays"))); + helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray"))); } - - inline void glBindVertexArray(GLuint array) - { - BindVertexArray(array); - } - -private: - // Function signatures are equivalent between desktop core, ARB, APPLE, ES3 and ES 2 extensions - void (QOPENGLF_APIENTRYP GenVertexArrays)(GLsizei n, GLuint *arrays); - void (QOPENGLF_APIENTRYP DeleteVertexArrays)(GLsizei n, const GLuint *arrays); - void (QOPENGLF_APIENTRYP BindVertexArray)(GLuint array); -}; +} class QOpenGLVertexArrayObjectPrivate : public QObjectPrivate { @@ -142,7 +122,7 @@ public: union { QOpenGLFunctions_3_0 *core_3_0; QOpenGLFunctions_3_2_Core *core_3_2; - QVertexArrayObjectHelper *helper; + QOpenGLVertexArrayObjectHelper *helper; } vaoFuncs; enum { NotSupported, @@ -175,7 +155,7 @@ bool QOpenGLVertexArrayObjectPrivate::create() if (ctx->isOpenGLES()) { if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) { - vaoFuncs.helper = new QVertexArrayObjectHelper(ctx); + vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); vaoFuncsType = OES; vaoFuncs.helper->glGenVertexArrays(1, &vao); } @@ -197,11 +177,11 @@ bool QOpenGLVertexArrayObjectPrivate::create() } else #endif if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) { - vaoFuncs.helper = new QVertexArrayObjectHelper(ctx); + vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); vaoFuncsType = ARB; vaoFuncs.helper->glGenVertexArrays(1, &vao); } else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) { - vaoFuncs.helper = new QVertexArrayObjectHelper(ctx); + vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx); vaoFuncsType = APPLE; vaoFuncs.helper->glGenVertexArrays(1, &vao); } diff --git a/src/gui/opengl/qopenglvertexarrayobject.h b/src/gui/opengl/qopenglvertexarrayobject.h index 8369497660..19da85bffd 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.h +++ b/src/gui/opengl/qopenglvertexarrayobject.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB). +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sean Harmer <sean.harmer@kdab.com> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtGui module of the Qt Toolkit. diff --git a/src/gui/opengl/qopenglvertexarrayobject_p.h b/src/gui/opengl/qopenglvertexarrayobject_p.h new file mode 100644 index 0000000000..161a388b1a --- /dev/null +++ b/src/gui/opengl/qopenglvertexarrayobject_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sean Harmer <sean.harmer@kdab.com> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QOPENGLVERTEXARRAYOBJECT_P_H +#define QOPENGLVERTEXARRAYOBJECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of the Qt OpenGL classes. This header file may change from +// version to version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qglobal.h> + +#ifndef QT_NO_OPENGL + +#include <QtGui/qopengl.h> + +QT_BEGIN_NAMESPACE + +class QOpenGLVertexArrayObjectHelper; +class QOpenGLContext; + +void Q_GUI_EXPORT qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context); + +class QOpenGLVertexArrayObjectHelper +{ + Q_DISABLE_COPY(QOpenGLVertexArrayObjectHelper) + +public: + explicit inline QOpenGLVertexArrayObjectHelper(QOpenGLContext *context) + : GenVertexArrays(Q_NULLPTR) + , DeleteVertexArrays(Q_NULLPTR) + , BindVertexArray(Q_NULLPTR) + { + qtInitializeVertexArrayObjectHelper(this, context); + } + + inline bool isValid() const + { + return GenVertexArrays && DeleteVertexArrays && BindVertexArray; + } + + inline void glGenVertexArrays(GLsizei n, GLuint *arrays) const + { + GenVertexArrays(n, arrays); + } + + inline void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) const + { + DeleteVertexArrays(n, arrays); + } + + inline void glBindVertexArray(GLuint array) const + { + BindVertexArray(array); + } + +private: + friend void Q_GUI_EXPORT qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context); + + // Function signatures are equivalent between desktop core, ARB, APPLE, ES 3 and ES 2 extensions + typedef void (QOPENGLF_APIENTRYP qt_GenVertexArrays_t)(GLsizei n, GLuint *arrays); + typedef void (QOPENGLF_APIENTRYP qt_DeleteVertexArrays_t)(GLsizei n, const GLuint *arrays); + typedef void (QOPENGLF_APIENTRYP qt_BindVertexArray_t)(GLuint array); + + qt_GenVertexArrays_t GenVertexArrays; + qt_DeleteVertexArrays_t DeleteVertexArrays; + qt_BindVertexArray_t BindVertexArray; +}; + +QT_END_NAMESPACE + +#endif // QT_NO_OPENGL + +#endif // QOPENGLVERTEXARRAYOBJECT_P_H |