QOpenGLVAO: refactor the helper class and export it
It is useful in other places, for instance in QtQuick, to avoid duplicating the same resolver logic. Change-Id: I9748a420a0abeb07cc84f948965b1e0321a95ca2 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
parent
7616586691
commit
12867bb8e2
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the QtGui module of the Qt Toolkit.
|
** This file is part of the QtGui module of the Qt Toolkit.
|
||||||
@ -49,69 +49,48 @@
|
|||||||
#include <QtGui/qopenglfunctions_3_0.h>
|
#include <QtGui/qopenglfunctions_3_0.h>
|
||||||
#include <QtGui/qopenglfunctions_3_2_core.h>
|
#include <QtGui/qopenglfunctions_3_2_core.h>
|
||||||
|
|
||||||
|
#include <private/qopenglvertexarrayobject_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class QOpenGLFunctions_3_0;
|
class QOpenGLFunctions_3_0;
|
||||||
class QOpenGLFunctions_3_2_Core;
|
class QOpenGLFunctions_3_2_Core;
|
||||||
|
|
||||||
class QVertexArrayObjectHelper
|
void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context)
|
||||||
{
|
{
|
||||||
public:
|
Q_ASSERT(helper);
|
||||||
QVertexArrayObjectHelper(QOpenGLContext *context)
|
|
||||||
{
|
|
||||||
Q_ASSERT(context);
|
Q_ASSERT(context);
|
||||||
|
|
||||||
bool tryARB = true;
|
bool tryARB = true;
|
||||||
|
|
||||||
if (context->isOpenGLES()) {
|
if (context->isOpenGLES()) {
|
||||||
#ifdef QT_OPENGL_ES_3
|
#ifdef QT_OPENGL_ES_3
|
||||||
GenVertexArrays = ::glGenVertexArrays;
|
helper->GenVertexArrays = ::glGenVertexArrays;
|
||||||
DeleteVertexArrays = ::glDeleteVertexArrays;
|
helper->DeleteVertexArrays = ::glDeleteVertexArrays;
|
||||||
BindVertexArray = ::glBindVertexArray;
|
helper->BindVertexArray = ::glBindVertexArray;
|
||||||
tryARB = false;
|
tryARB = false;
|
||||||
#else
|
#else
|
||||||
if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
|
if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
|
||||||
GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES")));
|
helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysOES")));
|
||||||
DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES")));
|
helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysOES")));
|
||||||
BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES")));
|
helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayOES")));
|
||||||
tryARB = false;
|
tryARB = false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (!context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))
|
} else if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object")) &&
|
||||||
&& context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
|
!context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
|
||||||
GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE")));
|
helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE")));
|
||||||
DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE")));
|
helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE")));
|
||||||
BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE")));
|
helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE")));
|
||||||
tryARB = false;
|
tryARB = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tryARB) {
|
if (tryARB && context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
|
||||||
GenVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , GLuint *)>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays")));
|
helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glGenVertexArrays")));
|
||||||
DeleteVertexArrays = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLsizei , const GLuint *)>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays")));
|
helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArrays")));
|
||||||
BindVertexArray = reinterpret_cast<void (QOPENGLF_APIENTRYP)(GLuint )>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray")));
|
helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress(QByteArrayLiteral("glBindVertexArray")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void glGenVertexArrays(GLsizei n, GLuint *arrays)
|
|
||||||
{
|
|
||||||
GenVertexArrays(n, arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void glDeleteVertexArrays(GLsizei n, const GLuint *arrays)
|
|
||||||
{
|
|
||||||
DeleteVertexArrays(n, arrays);
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
class QOpenGLVertexArrayObjectPrivate : public QObjectPrivate
|
||||||
{
|
{
|
||||||
@ -142,7 +121,7 @@ public:
|
|||||||
union {
|
union {
|
||||||
QOpenGLFunctions_3_0 *core_3_0;
|
QOpenGLFunctions_3_0 *core_3_0;
|
||||||
QOpenGLFunctions_3_2_Core *core_3_2;
|
QOpenGLFunctions_3_2_Core *core_3_2;
|
||||||
QVertexArrayObjectHelper *helper;
|
QOpenGLVertexArrayObjectHelper *helper;
|
||||||
} vaoFuncs;
|
} vaoFuncs;
|
||||||
enum {
|
enum {
|
||||||
NotSupported,
|
NotSupported,
|
||||||
@ -175,7 +154,7 @@ bool QOpenGLVertexArrayObjectPrivate::create()
|
|||||||
|
|
||||||
if (ctx->isOpenGLES()) {
|
if (ctx->isOpenGLES()) {
|
||||||
if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
|
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;
|
vaoFuncsType = OES;
|
||||||
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
||||||
}
|
}
|
||||||
@ -197,11 +176,11 @@ bool QOpenGLVertexArrayObjectPrivate::create()
|
|||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
|
if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
|
||||||
vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
|
vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
|
||||||
vaoFuncsType = ARB;
|
vaoFuncsType = ARB;
|
||||||
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
||||||
} else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
|
} else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
|
||||||
vaoFuncs.helper = new QVertexArrayObjectHelper(ctx);
|
vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
|
||||||
vaoFuncsType = APPLE;
|
vaoFuncsType = APPLE;
|
||||||
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
vaoFuncs.helper->glGenVertexArrays(1, &vao);
|
||||||
}
|
}
|
||||||
|
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the QtGui module of the Qt Toolkit.
|
** This file is part of the QtGui module of the Qt Toolkit.
|
||||||
|
119
src/gui/opengl/qopenglvertexarrayobject_p.h
Normal file
119
src/gui/opengl/qopenglvertexarrayobject_p.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user