shithub: choc

Download patch

ref: 13704286f092e6c889bf7362ea0252f7d1544342
parent: de098378c0718dc6988f89786b86e5b2a8b0acf7
author: Jonathan Dowland <jon+github@alcopop.org>
date: Thu Jul 14 13:16:40 EDT 2016

use SDL_GL_GetProcAddress to avoid GL dependency

Using SDL_GL_GetProcAddress we can get a function pointer to the
GL routine we want at runtime, if it's available, and avoid a
static dependency on GL libraries.

Thanks to fraggle for the suggestion and Mike for fixing Linux
builds (alas PKG_CHECK_MODULES for GL broke OS X builds)

--- a/configure.ac
+++ b/configure.ac
@@ -38,14 +38,6 @@
 PKG_CHECK_MODULES(SDLMIXER, [SDL2_mixer >= 2.0.0])
 PKG_CHECK_MODULES(SDLNET, [SDL2_net >= 2.0.0])
 PKG_CHECK_MODULES(SDLIMAGE, [SDL2_image >= 2.0.0])
-PKG_CHECK_MODULES(GL, [gl >= 10.0.0])
-
-# Additional LDFLAGS for OS X are required for OpenGL
-case "$host" in
-  *-darwin*)
-    LDFLAGS="$LDFLAGS -framework OpenGL"
-    ;;
-esac
 
 # Check for libsamplerate.
 AC_ARG_WITH([libsamplerate],
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1157,11 +1157,18 @@
 
 static void CheckGLVersion(void)
 {
-    const GLubyte* version = glGetString(GL_VERSION);
+    const char * version;
+    typedef const GLubyte* (APIENTRY * glStringFn_t)(GLenum);
+    glStringFn_t glfp = (glStringFn_t)SDL_GL_GetProcAddress("glGetString");
 
-    if (version && strstr((const char *)version, "Mesa"))
+    if (glfp)
     {
-        printf("%s", hw_emu_warning);
+        version = (const char *)glfp(GL_VERSION);
+
+        if (version && strstr(version, "Mesa"))
+        {
+            printf("%s", hw_emu_warning);
+        }
     }
 }