From d852e6164a4aaf8e235e97cba8f0e8e9b933987c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 15 Jul 2011 17:29:29 +0200 Subject: Properly resolve and use glMapBuffer / glUnmapBuffer on GLES2. Even though we're able to resolve the function pointers, the spec says we have to check for the GL_OES_mapbuffer extension before we use them. Fixes a crash on a platform that doesn't advertise the extension but still resolves the function pointers. Reviewed-by: Kim --- src/opengl/qglbuffer.cpp | 4 ++++ src/opengl/qglextensions.cpp | 33 ++++++++++++++++++++------------- src/opengl/qglextensions_p.h | 4 ++++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/opengl/qglbuffer.cpp b/src/opengl/qglbuffer.cpp index a1ec3ef..b5c6b83 100644 --- a/src/opengl/qglbuffer.cpp +++ b/src/opengl/qglbuffer.cpp @@ -543,6 +543,10 @@ void *QGLBuffer::map(QGLBuffer::Access access) return 0; if (!glMapBufferARB) return 0; +#ifdef QT_OPENGL_ES_2 + if (access != QGLBuffer::WriteOnly) + return 0; +#endif return glMapBufferARB(d->type, access); } diff --git a/src/opengl/qglextensions.cpp b/src/opengl/qglextensions.cpp index 98d2960..64f7526 100644 --- a/src/opengl/qglextensions.cpp +++ b/src/opengl/qglextensions.cpp @@ -191,23 +191,30 @@ bool qt_resolve_frag_program_extensions(QGLContext *ctx) bool qt_resolve_buffer_extensions(QGLContext *ctx) { + if (!QGLContextPrivate::extensionFuncs(ctx).qt_bufferFuncsResolved) { #if defined(QGL_RESOLVE_BUFFER_FUNCS) - if (glBindBuffer && glDeleteBuffers && glGenBuffers && glBufferData - && glBufferSubData && glGetBufferParameteriv) - return true; + glBindBuffer = (_glBindBuffer) qt_gl_getProcAddressARB(ctx, "glBindBuffer"); + glDeleteBuffers = (_glDeleteBuffers) qt_gl_getProcAddressARB(ctx, "glDeleteBuffers"); + glGenBuffers = (_glGenBuffers) qt_gl_getProcAddressARB(ctx, "glGenBuffers"); + glBufferData = (_glBufferData) qt_gl_getProcAddressARB(ctx, "glBufferData"); + glBufferSubData = (_glBufferSubData) qt_gl_getProcAddressARB(ctx, "glBufferSubData"); + glGetBufferSubData = (_glGetBufferSubData) qt_gl_getProcAddressARB(ctx, "glGetBufferSubData"); + glGetBufferParameteriv = (_glGetBufferParameteriv) qt_gl_getProcAddressARB(ctx, "glGetBufferParameteriv"); #endif -#if defined(QGL_RESOLVE_BUFFER_FUNCS) - glBindBuffer = (_glBindBuffer) qt_gl_getProcAddressARB(ctx, "glBindBuffer"); - glDeleteBuffers = (_glDeleteBuffers) qt_gl_getProcAddressARB(ctx, "glDeleteBuffers"); - glGenBuffers = (_glGenBuffers) qt_gl_getProcAddressARB(ctx, "glGenBuffers"); - glBufferData = (_glBufferData) qt_gl_getProcAddressARB(ctx, "glBufferData"); - glBufferSubData = (_glBufferSubData) qt_gl_getProcAddressARB(ctx, "glBufferSubData"); - glGetBufferSubData = (_glGetBufferSubData) qt_gl_getProcAddressARB(ctx, "glGetBufferSubData"); - glGetBufferParameteriv = (_glGetBufferParameteriv) qt_gl_getProcAddressARB(ctx, "glGetBufferParameteriv"); +#ifdef QT_OPENGL_ES_2 + QGLExtensionMatcher extensions; + if (extensions.match("GL_OES_mapbuffer")) { + glMapBufferARB = (_glMapBufferARB) qt_gl_getProcAddressARB(ctx, "glMapBufferOES"); + glUnmapBufferARB = (_glUnmapBufferARB) qt_gl_getProcAddressARB(ctx, "glUnmapBufferOES"); + } +#else + glMapBufferARB = (_glMapBufferARB) qt_gl_getProcAddressARB(ctx, "glMapBuffer"); + glUnmapBufferARB = (_glUnmapBufferARB) qt_gl_getProcAddressARB(ctx, "glUnmapBuffer"); #endif - glMapBufferARB = (_glMapBufferARB) qt_gl_getProcAddressARB(ctx, "glMapBuffer"); - glUnmapBufferARB = (_glUnmapBufferARB) qt_gl_getProcAddressARB(ctx, "glUnmapBuffer"); + + QGLContextPrivate::extensionFuncs(ctx).qt_bufferFuncsResolved = true; + } #if defined(QGL_RESOLVE_BUFFER_FUNCS) return glBindBuffer diff --git a/src/opengl/qglextensions_p.h b/src/opengl/qglextensions_p.h index 98433c3..f85c89b 100644 --- a/src/opengl/qglextensions_p.h +++ b/src/opengl/qglextensions_p.h @@ -332,6 +332,8 @@ struct QGLExtensionFuncs qt_glMapBufferARB = 0; qt_glUnmapBufferARB = 0; + qt_bufferFuncsResolved = false; + qt_glProgramParameteriEXT = 0; qt_glFramebufferTextureEXT = 0; qt_glFramebufferTextureLayerEXT = 0; @@ -457,6 +459,8 @@ struct QGLExtensionFuncs _glMapBufferARB qt_glMapBufferARB; _glUnmapBufferARB qt_glUnmapBufferARB; + bool qt_bufferFuncsResolved; + // Geometry shaders... _glProgramParameteriEXT qt_glProgramParameteriEXT; _glFramebufferTextureEXT qt_glFramebufferTextureEXT; -- cgit v0.12