From 35405858a345be2682c80356301a1019011e154a Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 3 Feb 2016 09:23:48 +0100 Subject: Cleanups Remove the different flags when trying to resolve opengl functions. Rather we simply try hard to find a matching method by resolving over possible suffixes when we can't find the standard name. Change-Id: Ic73085faec3bd406f5214ed4219eb7b796651d8d Reviewed-by: Laszlo Agocs --- src/gui/opengl/qopenglfunctions.cpp | 66 +++++++++++++++---------------------- 1 file changed, 27 insertions(+), 39 deletions(-) (limited to 'src/gui/opengl') diff --git a/src/gui/opengl/qopenglfunctions.cpp b/src/gui/opengl/qopenglfunctions.cpp index 9cbfadc1ad..5b728c9b8d 100644 --- a/src/gui/opengl/qopenglfunctions.cpp +++ b/src/gui/opengl/qopenglfunctions.cpp @@ -2098,48 +2098,36 @@ void QOpenGLFunctions::initializeOpenGLFunctions() namespace { -enum ResolvePolicy -{ - ResolveOES = 0x1, - ResolveEXT = 0x2, - ResolveANGLE = 0x4, - ResolveNV = 0x8 -}; - -static QFunctionPointer getProcAddress(QOpenGLContext *context, const char *funcName, int policy = ResolveOES|ResolveEXT|ResolveANGLE|ResolveNV) +// this function tries hard to get the opengl function we're looking for by also +// trying to resolve it with some of the common extensions if the generic name +// can't be found. +static QFunctionPointer getProcAddress(QOpenGLContext *context, const char *funcName) { QFunctionPointer function = context->getProcAddress(funcName); - if (!function && policy) { + static const struct { + const char *name; + int len; // includes trailing \0 + } extensions[] = { + { "ARB", 4 }, + { "OES", 4 }, + { "EXT", 4 }, + { "ANGLE", 6 }, + { "NV", 3 }, + }; + + if (!function) { char fn[512]; size_t size = strlen(funcName); Q_ASSERT(size < 500); memcpy(fn, funcName, size); - char *ext = fn + size; - if (!function && (policy & ResolveOES)) { - memcpy(ext, "OES", 4); - function = context->getProcAddress(fn); - } - - if (!function) { - memcpy(ext, "ARB", 4); - function = context->getProcAddress(fn); - } - - if (!function && (policy & ResolveEXT)) { - memcpy(ext, "EXT", 4); - function = context->getProcAddress(fn); - } - - if (!function && (policy & ResolveANGLE)) { - memcpy(ext, "ANGLE", 6); - function = context->getProcAddress(fn); - } - if (!function && (policy & ResolveNV)) { - memcpy(ext, "NV", 3); + for (const auto &e : extensions) { + memcpy(ext, e.name, e.len); function = context->getProcAddress(fn); + if (function) + break; } } @@ -2147,15 +2135,15 @@ static QFunctionPointer getProcAddress(QOpenGLContext *context, const char *func } template -Func resolve(QOpenGLContext *context, const char *name, int policy, Func) +Func resolve(QOpenGLContext *context, const char *name, Func) { - return reinterpret_cast(getProcAddress(context, name, policy)); + return reinterpret_cast(getProcAddress(context, name)); } } -#define RESOLVE(name, policy) \ - resolve(context, "gl"#name, policy, name) +#define RESOLVE(name) \ + resolve(context, "gl"#name, name) #ifndef QT_OPENGL_ES_2 @@ -4523,9 +4511,9 @@ QOpenGLExtensionsPrivate::QOpenGLExtensionsPrivate(QOpenGLContext *ctx) { QOpenGLContext *context = QOpenGLContext::currentContext(); - MapBuffer = RESOLVE(MapBuffer, ResolveOES); - GetBufferSubData = RESOLVE(GetBufferSubData, ResolveEXT); - DiscardFramebuffer = RESOLVE(DiscardFramebuffer, ResolveEXT); + MapBuffer = RESOLVE(MapBuffer); + GetBufferSubData = RESOLVE(GetBufferSubData); + DiscardFramebuffer = RESOLVE(DiscardFramebuffer); } void QOpenGLExtensions::flushShared() -- cgit v1.2.3