From 42c8c7e9dbf4c9e67b88bd16f0fe4e0d3c57857b Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 15 Oct 2013 18:32:02 +0100 Subject: Support APPLE VAO extension on Mac. Since Mac lacks a compatibility profile, we often use the highest supported compatible version, 2.1; this lacks vertex-array-object (VAO) support in the API, but Apple provide a compatible extension. Extend the helper object to detect this case and make VAO support work. Change-Id: I75a74e048a0d188cec76bc5a4a9eafa4c9143740 Reviewed-by: Sean Harmer --- src/gui/opengl/qopenglvertexarrayobject.cpp | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/gui/opengl/qopenglvertexarrayobject.cpp b/src/gui/opengl/qopenglvertexarrayobject.cpp index 16ed79ac10..1f039a8ca9 100644 --- a/src/gui/opengl/qopenglvertexarrayobject.cpp +++ b/src/gui/opengl/qopenglvertexarrayobject.cpp @@ -58,9 +58,15 @@ public: { Q_ASSERT(context); #if !defined(QT_OPENGL_ES_2) - GenVertexArrays = reinterpret_cast(context->getProcAddress("glGenVertexArrays")); - DeleteVertexArrays = reinterpret_cast(context->getProcAddress("glDeleteVertexArrays")); - BindVertexArray = reinterpret_cast(context->getProcAddress("glBindVertexArray")); + if (context->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) { + GenVertexArrays = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glGenVertexArraysAPPLE"))); + DeleteVertexArrays = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glDeleteVertexArraysAPPLE"))); + BindVertexArray = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glBindVertexArrayAPPLE"))); + } else { + GenVertexArrays = reinterpret_cast(context->getProcAddress("glGenVertexArrays")); + DeleteVertexArrays = reinterpret_cast(context->getProcAddress("glDeleteVertexArrays")); + BindVertexArray = reinterpret_cast(context->getProcAddress("glBindVertexArray")); + } #else GenVertexArrays = reinterpret_cast(context->getProcAddress("glGenVertexArraysOES")); DeleteVertexArrays = reinterpret_cast(context->getProcAddress("glDeleteVertexArraysOES")); @@ -84,7 +90,7 @@ public: } private: - // Function signatures are equivalent between desktop core, ARB and ES 2 extensions + // Function signatures are equivalent between desktop core, ARB, APPLE 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); @@ -109,8 +115,8 @@ public: #if defined(QT_OPENGL_ES_2) delete vaoFuncs; #else - if (vaoFuncsType == ARB) - delete vaoFuncs.arb; + if ((vaoFuncsType == ARB) || (vaoFuncsType == APPLE)) + delete vaoFuncs.helper; #endif } @@ -130,13 +136,14 @@ public: union { QOpenGLFunctions_3_0 *core_3_0; QOpenGLFunctions_3_2_Core *core_3_2; - QVertexArrayObjectHelper *arb; + QVertexArrayObjectHelper *helper; } vaoFuncs; enum { NotSupported, Core_3_0, Core_3_2, - ARB + ARB, + APPLE } vaoFuncsType; #endif QOpenGLContext *context; @@ -181,9 +188,13 @@ bool QOpenGLVertexArrayObjectPrivate::create() vaoFuncs.core_3_0->initializeOpenGLFunctions(); vaoFuncs.core_3_0->glGenVertexArrays(1, &vao); } else if (ctx->hasExtension("GL_ARB_vertex_array_object")) { - vaoFuncs.arb = new QVertexArrayObjectHelper(ctx); + vaoFuncs.helper = new QVertexArrayObjectHelper(ctx); vaoFuncsType = ARB; - vaoFuncs.arb->glGenVertexArrays(1, &vao); + vaoFuncs.helper->glGenVertexArrays(1, &vao); + } else if (ctx->hasExtension(QByteArrayLiteral("GL_APPLE_vertex_array_object"))) { + vaoFuncs.helper = new QVertexArrayObjectHelper(ctx); + vaoFuncsType = APPLE; + vaoFuncs.helper->glGenVertexArrays(1, &vao); } #endif return (vao != 0); @@ -205,7 +216,8 @@ void QOpenGLVertexArrayObjectPrivate::destroy() vaoFuncs.core_3_0->glDeleteVertexArrays(1, &vao); break; case ARB: - vaoFuncs.arb->glDeleteVertexArrays(1, &vao); + case APPLE: + vaoFuncs.helper->glDeleteVertexArrays(1, &vao); break; case NotSupported: break; @@ -236,7 +248,8 @@ void QOpenGLVertexArrayObjectPrivate::bind() vaoFuncs.core_3_0->glBindVertexArray(vao); break; case ARB: - vaoFuncs.arb->glBindVertexArray(vao); + case APPLE: + vaoFuncs.helper->glBindVertexArray(vao); break; case NotSupported: break; @@ -258,7 +271,8 @@ void QOpenGLVertexArrayObjectPrivate::release() vaoFuncs.core_3_0->glBindVertexArray(0); break; case ARB: - vaoFuncs.arb->glBindVertexArray(0); + case APPLE: + vaoFuncs.helper->glBindVertexArray(0); break; case NotSupported: break; -- cgit v1.2.3