summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-18 03:30:47 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-06-22 12:48:30 +0200
commit436b331b7127124b9720bf7a3f915439f2a25cf3 (patch)
treeb3cd72c2a3d59dfbefd3aa6f0fe3dfcc9b513862 /src/opengl
parentf1f0aa4a3a7d364b5110122a8f77079a7742c4e9 (diff)
Enable access to the VAO resolvers through QOpenGLContextPrivate
This is a commit in preparation for an upcoming change in QtQuick. We want to store the resolved functions for managing VAOs somewhere; the "least worst" choice is next to the all other function resolvers, which are in QOpenGLContext(Private). To avoid moving the VAO resolvers themselves, leave a hook in QOGLCPrivate, similar to e.g. the texture function resolvers. The hook gets populated when the VAO resolvers for a given context are requested. This removes memory management burden from the users of those functions (again, just like other function resolvers), and makes the initialization of the functions automatic. Change-Id: I0eba30a85bf8ad82946a5d68e91009d8b4bd91cf Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/qopenglvertexarrayobject.cpp68
-rw-r--r--src/opengl/qopenglvertexarrayobject_p.h15
2 files changed, 48 insertions, 35 deletions
diff --git a/src/opengl/qopenglvertexarrayobject.cpp b/src/opengl/qopenglvertexarrayobject.cpp
index 44a0640567..63e37727f9 100644
--- a/src/opengl/qopenglvertexarrayobject.cpp
+++ b/src/opengl/qopenglvertexarrayobject.cpp
@@ -49,6 +49,7 @@
#include <QtOpenGL/qopenglfunctions_3_0.h>
#include <QtOpenGL/qopenglfunctions_3_2_core.h>
+#include <private/qopenglcontext_p.h>
#include <private/qopenglextensions_p.h>
#include <private/qopenglvertexarrayobject_p.h>
@@ -57,9 +58,28 @@ QT_BEGIN_NAMESPACE
class QOpenGLFunctions_3_0;
class QOpenGLFunctions_3_2_Core;
-void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context)
+static void vertexArrayObjectHelperDestroyCallback(QOpenGLVertexArrayObjectHelper *vaoHelper)
+{
+ delete vaoHelper;
+}
+
+QOpenGLVertexArrayObjectHelper *QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(QOpenGLContext *context)
+{
+ Q_ASSERT(context);
+
+ auto contextPrivate = QOpenGLContextPrivate::get(context);
+ auto &vaoHelper = contextPrivate->vaoHelper;
+
+ if (!vaoHelper) {
+ vaoHelper = new QOpenGLVertexArrayObjectHelper(context);
+ contextPrivate->vaoHelperDestroyCallback = &vertexArrayObjectHelperDestroyCallback;
+ }
+
+ return vaoHelper;
+}
+
+void QOpenGLVertexArrayObjectHelper::initializeFromContext(QOpenGLContext *context)
{
- Q_ASSERT(helper);
Q_ASSERT(context);
bool tryARB = true;
@@ -67,32 +87,32 @@ void qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper,
if (context->isOpenGLES()) {
if (context->format().majorVersion() >= 3) {
QOpenGLExtraFunctionsPrivate *extra = static_cast<QOpenGLExtensions *>(context->extraFunctions())->d();
- helper->GenVertexArrays = extra->f.GenVertexArrays;
- helper->DeleteVertexArrays = extra->f.DeleteVertexArrays;
- helper->BindVertexArray = extra->f.BindVertexArray;
- helper->IsVertexArray = extra->f.IsVertexArray;
+ GenVertexArrays = extra->f.GenVertexArrays;
+ DeleteVertexArrays = extra->f.DeleteVertexArrays;
+ BindVertexArray = extra->f.BindVertexArray;
+ IsVertexArray = extra->f.IsVertexArray;
tryARB = false;
} else if (context->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
- helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress("glGenVertexArraysOES"));
- helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArraysOES"));
- helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArrayOES"));
- helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArrayOES"));
+ GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress("glGenVertexArraysOES"));
+ DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArraysOES"));
+ BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArrayOES"));
+ IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArrayOES"));
tryARB = false;
}
} 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("glGenVertexArraysAPPLE"));
- helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArraysAPPLE"));
- helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArrayAPPLE"));
- helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArrayAPPLE"));
+ GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress("glGenVertexArraysAPPLE"));
+ DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArraysAPPLE"));
+ BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArrayAPPLE"));
+ IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArrayAPPLE"));
tryARB = false;
}
if (tryARB && context->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
- helper->GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress("glGenVertexArrays"));
- helper->DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArrays"));
- helper->BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArray"));
- helper->IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArray"));
+ GenVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_GenVertexArrays_t>(context->getProcAddress("glGenVertexArrays"));
+ DeleteVertexArrays = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_DeleteVertexArrays_t>(context->getProcAddress("glDeleteVertexArrays"));
+ BindVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_BindVertexArray_t>(context->getProcAddress("glBindVertexArray"));
+ IsVertexArray = reinterpret_cast<QOpenGLVertexArrayObjectHelper::qt_IsVertexArray_t>(context->getProcAddress("glIsVertexArray"));
}
}
@@ -107,12 +127,6 @@ public:
{
}
- ~QOpenGLVertexArrayObjectPrivate()
- {
- if (vaoFuncsType == ARB || vaoFuncsType == APPLE || vaoFuncsType == OES)
- delete vaoFuncs.helper;
- }
-
bool create();
void destroy();
void bind();
@@ -167,7 +181,7 @@ bool QOpenGLVertexArrayObjectPrivate::create()
if (ctx->isOpenGLES()) {
if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) {
- vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
+ vaoFuncs.helper = QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(ctx);
vaoFuncsType = OES;
vaoFuncs.helper->glGenVertexArrays(1, &vao);
}
@@ -187,11 +201,11 @@ bool QOpenGLVertexArrayObjectPrivate::create()
} else
#endif
if (ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) {
- vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
+ vaoFuncs.helper = QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(ctx);
vaoFuncsType = ARB;
vaoFuncs.helper->glGenVertexArrays(1, &vao);
} else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) {
- vaoFuncs.helper = new QOpenGLVertexArrayObjectHelper(ctx);
+ vaoFuncs.helper = QOpenGLVertexArrayObjectHelper::vertexArrayObjectHelperForContext(ctx);
vaoFuncsType = APPLE;
vaoFuncs.helper->glGenVertexArrays(1, &vao);
}
diff --git a/src/opengl/qopenglvertexarrayobject_p.h b/src/opengl/qopenglvertexarrayobject_p.h
index 0d0fca4d81..bd50d86073 100644
--- a/src/opengl/qopenglvertexarrayobject_p.h
+++ b/src/opengl/qopenglvertexarrayobject_p.h
@@ -57,25 +57,27 @@
QT_BEGIN_NAMESPACE
-class QOpenGLVertexArrayObjectHelper;
class QOpenGLContext;
-void Q_OPENGL_EXPORT qtInitializeVertexArrayObjectHelper(QOpenGLVertexArrayObjectHelper *helper, QOpenGLContext *context);
-
class QOpenGLVertexArrayObjectHelper
{
Q_DISABLE_COPY(QOpenGLVertexArrayObjectHelper)
-public:
+private:
explicit inline QOpenGLVertexArrayObjectHelper(QOpenGLContext *context)
: GenVertexArrays(nullptr)
, DeleteVertexArrays(nullptr)
, BindVertexArray(nullptr)
, IsVertexArray(nullptr)
{
- qtInitializeVertexArrayObjectHelper(this, context);
+ initializeFromContext(context);
}
+ void Q_OPENGL_EXPORT initializeFromContext(QOpenGLContext *context);
+
+public:
+ static Q_OPENGL_EXPORT QOpenGLVertexArrayObjectHelper *vertexArrayObjectHelperForContext(QOpenGLContext *context);
+
inline bool isValid() const
{
return GenVertexArrays && DeleteVertexArrays && BindVertexArray && IsVertexArray;
@@ -101,9 +103,6 @@ public:
return IsVertexArray(array);
}
-private:
- friend void Q_OPENGL_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);