SDL_GL_LoadLibrary() has slightly different behavior between 1.2 and 2.0.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 28 Feb 2019 09:43:17 -0500
changeset 879dc1cdfa0fa9
parent 86 4b12bf655509
child 88 60cb434b52b8
SDL_GL_LoadLibrary() has slightly different behavior between 1.2 and 2.0.
src/SDL12_compat.c
src/SDL20_syms.h
     1.1 --- a/src/SDL12_compat.c	Thu Feb 28 09:42:52 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Thu Feb 28 09:43:17 2019 -0500
     1.3 @@ -3055,6 +3055,36 @@
     1.4  }
     1.5  
     1.6  DECLSPEC int SDLCALL
     1.7 +SDL_GL_LoadLibrary(const char *libname)
     1.8 +{
     1.9 +    /* SDL 1.2 would unload the previous library if one was loaded. SDL2
    1.10 +       reports an error if one is already loaded, and sometimes loads it
    1.11 +       internally for some video targets, so unloading it probably isn't safe.
    1.12 +       There really isn't a good reason to be using anything other than the
    1.13 +       system OpenGL in 2019, so we ignore the error in this case to match 1.2
    1.14 +       behavior, even if you were going to load a different library this time.
    1.15 +       Oh well. */
    1.16 +    const int rc = SDL20_GL_LoadLibrary(libname);
    1.17 +    if (rc == -1) {
    1.18 +        const char *err = SDL20_GetError();
    1.19 +        if (SDL20_strcmp(err, "OpenGL library already loaded") == 0) {
    1.20 +            return 0;
    1.21 +        }
    1.22 +
    1.23 +        /* reset the actual error. */
    1.24 +        char *dup = SDL_strdup(err);
    1.25 +        if (!dup) {
    1.26 +            SDL20_SetError("Out of memory");
    1.27 +        } else {
    1.28 +            SDL20_SetError(dup);
    1.29 +            SDL_free(dup);
    1.30 +        }
    1.31 +    }
    1.32 +    return rc;
    1.33 +}
    1.34 +
    1.35 +
    1.36 +DECLSPEC int SDLCALL
    1.37  SDL_GL_SetAttribute(SDL12_GLattr attr, int value)
    1.38  {
    1.39      if (attr >= SDL12_GL_MAX_ATTRIBUTE)
     2.1 --- a/src/SDL20_syms.h	Thu Feb 28 09:42:52 2019 -0500
     2.2 +++ b/src/SDL20_syms.h	Thu Feb 28 09:43:17 2019 -0500
     2.3 @@ -98,7 +98,7 @@
     2.4  SDL20_SYM(void,FreeSurface,(SDL_Surface *a),(a),)
     2.5  SDL20_SYM(SDL_Surface*,LoadBMP_RW,(SDL_RWops *a, int b),(a,b),return)
     2.6  SDL20_SYM(int,SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
     2.7 -SDL20_SYM_PASSTHROUGH(int,GL_LoadLibrary,(const char *a),(a),return)
     2.8 +SDL20_SYM(int,GL_LoadLibrary,(const char *a),(a),return)
     2.9  SDL20_SYM_PASSTHROUGH(void *,GL_GetProcAddress,(const char *a),(a),return)
    2.10  SDL20_SYM(int,GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return)
    2.11  SDL20_SYM(int,GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return)