From bf123b52994a20631f8271aa6e64ac136ffcf71e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 14 Oct 2015 02:48:48 +0200 Subject: [PATCH] Simplify glad --- deps/glad.c | 58 +++++++++-------------------------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/deps/glad.c b/deps/glad.c index a3aa4d3b..cec08bb3 100644 --- a/deps/glad.c +++ b/deps/glad.c @@ -5,47 +5,16 @@ struct gladGLversionStruct GLVersion; -#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0) -#define _GLAD_IS_SOME_NEW_VERSION 1 -#endif - -static int max_loaded_major; -static int max_loaded_minor; - -static const char *exts = NULL; -static int num_exts_i = 0; -static const char **exts_i = NULL; - -static void get_exts(void) { -#ifdef _GLAD_IS_SOME_NEW_VERSION - if(max_loaded_major < 3) { -#endif - exts = (const char *)glGetString(GL_EXTENSIONS); -#ifdef _GLAD_IS_SOME_NEW_VERSION - } else { - int index; - - num_exts_i = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts_i); - if (num_exts_i > 0) { - exts_i = (const char **)realloc((void *)exts_i, num_exts_i * sizeof *exts_i); - } - - for(index = 0; index < num_exts_i; index++) { - exts_i[index] = (const char*)glGetStringi(GL_EXTENSIONS, index); - } - } -#endif -} - static int has_ext(const char *ext) { -#ifdef _GLAD_IS_SOME_NEW_VERSION - if(max_loaded_major < 3) { +#if defined(GL_ES_VERSION_3_0) + if(!GLAD_GL_ES_VERSION_3_0) { +#elif defined(GL_VERSION_3_0) + if(!GLAD_GL_VERSION_3_0) { #endif const char *extensions; const char *loc; const char *terminator; - extensions = exts; + extensions = (const char*) glGetString(GL_EXTENSIONS); if(extensions == NULL || ext == NULL) { return 0; } @@ -63,14 +32,13 @@ static int has_ext(const char *ext) { } extensions = terminator; } -#ifdef _GLAD_IS_SOME_NEW_VERSION +#if defined(GL_ES_VERSION_3_0) || defined(GL_VERSION_3_0) } else { - int index; + GLint num_exts, index; - for(index = 0; index < num_exts_i; index++) { - const char *e = exts_i[index]; - - if(strcmp(e, ext) == 0) { + glGetIntegerv(GL_NUM_EXTENSIONS, &num_exts); + for(index = 0; index < num_exts; index++) { + if(strcmp((const char*) glGetStringi(GL_EXTENSIONS, index), ext) == 0) { return 1; } } @@ -1510,7 +1478,6 @@ static void load_GL_ARB_robustness(GLADloadproc load) { glad_glGetnMinmaxARB = (PFNGLGETNMINMAXARBPROC)load("glGetnMinmaxARB"); } static void find_extensionsGL(void) { - get_exts(); GLAD_GL_EXT_separate_specular_color = has_ext("GL_EXT_separate_specular_color"); GLAD_GL_ARB_multisample = has_ext("GL_ARB_multisample"); GLAD_GL_ARB_robustness = has_ext("GL_ARB_robustness"); @@ -1551,7 +1518,6 @@ static void find_coreGL(void) { #endif GLVersion.major = major; GLVersion.minor = minor; - max_loaded_major = major; max_loaded_minor = minor; GLAD_GL_VERSION_1_0 = (major == 1 && minor >= 0) || major > 1; GLAD_GL_VERSION_1_1 = (major == 1 && minor >= 1) || major > 1; GLAD_GL_VERSION_1_2 = (major == 1 && minor >= 2) || major > 1; @@ -1563,10 +1529,6 @@ static void find_coreGL(void) { GLAD_GL_VERSION_3_0 = (major == 3 && minor >= 0) || major > 3; GLAD_GL_VERSION_3_1 = (major == 3 && minor >= 1) || major > 3; GLAD_GL_VERSION_3_2 = (major == 3 && minor >= 2) || major > 3; - if (GLVersion.major > 3 || (GLVersion.major >= 3 && GLVersion.minor >= 2)) { - max_loaded_major = 3; - max_loaded_minor = 2; - } } int gladLoadGLLoader(GLADloadproc load) {