Implement crude handling of missing OpenGL extensions
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 25 May 2011 20:04:13 +0000 (20:04 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Wed, 25 May 2011 20:04:13 +0000 (20:04 +0000)
That is, give up completely if any of the extensions are missing. This
is braindead (since only one of the extensions is truly mandatory),
but infinitely better than crashing due to attempts to call a NULL
function pointer.

git-svn-id: https://s.snth.net/svn/neverball/branches/gles@3586 78b8d119-cf0a-0410-b17c-f493084dd1d7

share/glext.c
share/glext.h
share/video.c

index 8ca7993..a7e64e4 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <SDL.h>
+#include <stdio.h>
 
 #include "glext.h"
 
@@ -55,28 +56,40 @@ int glext_check(const char *needle)
     return 0;
 }
 
+int glext_assert(const char *ext)
+{
+    if (!glext_check(ext))
+    {
+        fprintf(stderr, "Missing required OpenGL extension (%s)\n", ext);
+        return 0;
+    }
+    return 1;
+}
+
 /*---------------------------------------------------------------------------*/
 
-#define SDL_GL_GFPA(fun, str) do {     \
-    ptr = SDL_GL_GetProcAddress(str);   \
+#define SDL_GL_GFPA(fun, str) do {       \
+    ptr = SDL_GL_GetProcAddress(str);    \
     memcpy(&fun, &ptr, sizeof (void *)); \
 } while(0)
 
 /*---------------------------------------------------------------------------*/
 
-void glext_init(void)
+int glext_init(void)
 {
 #if !ENABLE_OPENGLES
 
     void *ptr;
 
-    if (glext_check("ARB_multitexture"))
+    if (glext_assert("ARB_multitexture"))
     {
         SDL_GL_GFPA(glClientActiveTexture_, "glClientActiveTextureARB");
         SDL_GL_GFPA(glActiveTexture_,       "glActiveTextureARB");
     }
+    else
+        return 0;
 
-    if (glext_check("ARB_vertex_buffer_object"))
+    if (glext_assert("ARB_vertex_buffer_object"))
     {
         SDL_GL_GFPA(glGenBuffers_,          "glGenBuffersARB");
         SDL_GL_GFPA(glBindBuffer_,          "glBindBufferARB");
@@ -85,9 +98,19 @@ void glext_init(void)
         SDL_GL_GFPA(glDeleteBuffers_,       "glDeleteBuffersARB");
         SDL_GL_GFPA(glIsBuffer_,            "glIsBufferARB");
     }
+    else
+        return 0;
 
-    if (glext_check("ARB_point_parameters"))
+    if (glext_assert("ARB_point_parameters"))
         SDL_GL_GFPA(glPointParameterfv_,   "glPointParameterfvARB");
+    else
+        return 0;
+
+    return 1;
+
+#else
+
+    return 1;
 
 #endif
 }
index 338ad98..c283b70 100644 (file)
@@ -81,8 +81,8 @@
 
 /*---------------------------------------------------------------------------*/
 
-int  glext_check(const char *);
-void glext_init(void);
+int glext_check(const char *);
+int glext_init(void);
 
 /*---------------------------------------------------------------------------*/
 
index 0d2fb5a..b305ae1 100644 (file)
@@ -82,12 +82,13 @@ int video_mode(int f, int w, int h)
 
     if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0)))
     {
-        glext_init();
-
         config_set_d(CONFIG_FULLSCREEN, f);
         config_set_d(CONFIG_WIDTH,      w);
         config_set_d(CONFIG_HEIGHT,     h);
 
+        if (!glext_init())
+            return 0;
+
         glViewport(0, 0, w, h);
         glClearColor(0.0f, 0.0f, 0.0f, 0.0f);