From 2d0072b0b3992b82385c72c2dad7e754d35e0bf7 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 22 Aug 2014 18:00:18 +0200 Subject: [PATCH] Do not resolve core functions on GLES in texture helper As the spec for eglGetProcAddress says, some implementations may not return function pointers for core functions. Similarly to how we cannot get OpenGL 1.0/1.1 functions with WGL for example. To make sure QOpenGLTexture does not just crash with such implementations, we simply use the statically exported functions in -opengl es2 builds. Change-Id: I213bfcc21e58888b17e0ebcd0a26f26f77517e40 Reviewed-by: Giuseppe D'Angelo Reviewed-by: Sean Harmer --- src/gui/opengl/qopengltexturehelper.cpp | 64 +++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/gui/opengl/qopengltexturehelper.cpp b/src/gui/opengl/qopengltexturehelper.cpp index 27aece8ecad..9cb5e8798e5 100644 --- a/src/gui/opengl/qopengltexturehelper.cpp +++ b/src/gui/opengl/qopengltexturehelper.cpp @@ -164,6 +164,60 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context) TexSubImage2D = reinterpret_cast(GetProcAddress(handle, QByteArrayLiteral("glTexSubImage2D"))); TexSubImage1D = reinterpret_cast(GetProcAddress(handle, QByteArrayLiteral("glTexSubImage1D"))); +#elif defined(QT_OPENGL_ES_2) + // Here we are targeting OpenGL ES 2.0+ only. This is likely using EGL, where, + // similarly to WGL, non-extension functions (i.e. any function that is part of the + // GLES spec) *may* not be queried via eglGetProcAddress. + + // OpenGL 1.0 + GetIntegerv = ::glGetIntegerv; + GetBooleanv = ::glGetBooleanv; + PixelStorei = ::glPixelStorei; + GetTexLevelParameteriv = 0; + GetTexLevelParameterfv = 0; + GetTexParameteriv = ::glGetTexParameteriv; + GetTexParameterfv = ::glGetTexParameterfv; + GetTexImage = 0; + TexImage2D = ::glTexImage2D; + TexImage1D = 0; + TexParameteriv = ::glTexParameteriv; + TexParameteri = ::glTexParameteri; + TexParameterfv = ::glTexParameterfv; + TexParameterf = ::glTexParameterf; + + // OpenGL 1.1 + GenTextures = ::glGenTextures; + DeleteTextures = ::glDeleteTextures; + BindTexture = ::glBindTexture; + TexSubImage2D = ::glTexSubImage2D; + TexSubImage1D = 0; + + // OpenGL 1.3 + GetCompressedTexImage = 0; + CompressedTexSubImage1D = 0; + CompressedTexSubImage2D = ::glCompressedTexSubImage2D; + CompressedTexImage1D = 0; + CompressedTexImage2D = ::glCompressedTexImage2D; + ActiveTexture = ::glActiveTexture; + + // OpenGL 3.0 + GenerateMipmap = ::glGenerateMipmap; + + // OpenGL 3.2 + TexImage3DMultisample = 0; + TexImage2DMultisample = 0; + + // OpenGL 4.2 + TexStorage3D = 0; + TexStorage2D = 0; + TexStorage1D = 0; + + // OpenGL 4.3 + TexStorage3DMultisample = 0; + TexStorage2DMultisample = 0; + TexBufferRange = 0; + TextureView = 0; + #else // OpenGL 1.0 @@ -196,6 +250,13 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context) CompressedTexImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glCompressedTexImage3DOES"))); CompressedTexSubImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glCompressedTexSubImage3DOES"))); } else { +#ifdef QT_OPENGL_ES_3 + // OpenGL ES 3.0+ has glTexImage3D. + TexImage3D = ::glTexImage3D; + TexSubImage3D = ::glTexSubImage3D; + CompressedTexImage3D = ::glCompressedTexImage3D; + CompressedTexSubImage3D = ::glCompressedTexSubImage3D; +#else // OpenGL 1.2 TexImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glTexImage3D"))); TexSubImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glTexSubImage3D"))); @@ -203,8 +264,10 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context) // OpenGL 1.3 CompressedTexImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glCompressedTexImage3D"))); CompressedTexSubImage3D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glCompressedTexSubImage3D"))); +#endif } +#ifndef QT_OPENGL_ES_2 // OpenGL 1.3 GetCompressedTexImage = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glGetCompressedTexImage"))); CompressedTexSubImage1D = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glCompressedTexSubImage1D"))); @@ -230,6 +293,7 @@ QOpenGLTextureHelper::QOpenGLTextureHelper(QOpenGLContext *context) TexStorage2DMultisample = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glTexStorage2DMultisample"))); TexBufferRange = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glTexBufferRange"))); TextureView = reinterpret_cast(context->getProcAddress(QByteArrayLiteral("glTextureView"))); +#endif } void QOpenGLTextureHelper::dsa_TextureParameteri(GLuint texture, GLenum target, GLenum bindingTarget, GLenum pname, GLint param)