Add a structure to cache detected GL capabilities
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 12 Jun 2011 13:54:51 +0000 (13:54 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Sun, 12 Jun 2011 13:54:51 +0000 (13:54 +0000)
git-svn-id: https://s.snth.net/svn/neverball/branches/gles@3597 78b8d119-cf0a-0410-b17c-f493084dd1d7

share/geom.c
share/glext.c
share/glext.h
share/image.c

index 289fe92..da2346e 100644 (file)
@@ -239,15 +239,13 @@ void back_draw_easy(void)
 
 /*---------------------------------------------------------------------------*/
 
-static GLint max_tex_units;
-
 static GLuint clip_text;
 
 static GLubyte clip_data[] = { 0xff, 0xff, 0x0, 0x0 };
 
 void clip_init(void)
 {
-    if (max_tex_units < 3)
+    if (gli.max_texture_units < 3)
         return;
 
     glActiveTexture_(GL_TEXTURE2);
@@ -294,7 +292,7 @@ void clip_free(void)
 
 void clip_draw_set(void)
 {
-    if (max_tex_units < 3)
+    if (gli.max_texture_units < 3)
         return;
 
     glActiveTexture_(GL_TEXTURE2);
@@ -307,7 +305,7 @@ void clip_draw_set(void)
 
 void clip_draw_clr(void)
 {
-    if (max_tex_units < 3)
+    if (gli.max_texture_units < 3)
         return;
 
     glActiveTexture_(GL_TEXTURE2);
@@ -338,9 +336,7 @@ void shad_init(void)
     if (!config_get_d(CONFIG_SHADOW))
         return;
 
-    glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_tex_units);
-
-    if (max_tex_units < 2)
+    if (gli.max_texture_units < 2)
     {
         config_set_d(CONFIG_SHADOW, 0);
         return;
@@ -375,7 +371,7 @@ void shad_draw_set(void)
         glEnable(GL_TEXTURE_2D);
         glBindTexture(GL_TEXTURE_2D, shad_text);
 
-        if (max_tex_units < 3)
+        if (gli.max_texture_units < 3)
         {
             glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
         }
index a7e64e4..9f726b8 100644 (file)
@@ -17,6 +17,8 @@
 
 #include "glext.h"
 
+struct gl_info gli;
+
 /*---------------------------------------------------------------------------*/
 
 #if !ENABLE_OPENGLES
@@ -77,17 +79,27 @@ int glext_assert(const char *ext)
 
 int glext_init(void)
 {
-#if !ENABLE_OPENGLES
+    void *ptr = 0;
+
+    memset(&gli, 0, sizeof (struct gl_info));
 
-    void *ptr;
+    /* Common init. */
+
+    gli.max_texture_units = 1;
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gli.max_texture_size);
+
+#if !ENABLE_OPENGLES
+    /* Desktop init. */
 
     if (glext_assert("ARB_multitexture"))
     {
+        glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gli.max_texture_units);
+
         SDL_GL_GFPA(glClientActiveTexture_, "glClientActiveTextureARB");
         SDL_GL_GFPA(glActiveTexture_,       "glActiveTextureARB");
+
+        gli.multitexture = 1;
     }
-    else
-        return 0;
 
     if (glext_assert("ARB_vertex_buffer_object"))
     {
@@ -97,21 +109,30 @@ int glext_init(void)
         SDL_GL_GFPA(glBufferSubData_,       "glBufferSubDataARB");
         SDL_GL_GFPA(glDeleteBuffers_,       "glDeleteBuffersARB");
         SDL_GL_GFPA(glIsBuffer_,            "glIsBufferARB");
+
+        gli.vertex_buffer_object = 1;
     }
-    else
-        return 0;
 
     if (glext_assert("ARB_point_parameters"))
+    {
         SDL_GL_GFPA(glPointParameterfv_,   "glPointParameterfvARB");
-    else
-        return 0;
 
-    return 1;
+        gli.point_parameters = 1;
+    }
 
+    return (gli.multitexture &&
+            gli.vertex_buffer_object &&
+            gli.point_parameters);
 #else
+    /* GLES init. */
 
-    return 1;
+    glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gli.max_texture_units);
 
+    gli.multitexture = 1;
+    gli.vertex_buffer_object = 1;
+    gli.point_parameters = 1;
+
+    return 1;
 #endif
 }
 
index c283b70..63d7419 100644 (file)
@@ -152,4 +152,18 @@ extern PFNGLPOINTPARAMETERFV_PROC glPointParameterfv_;
 void glClipPlane4f_(GLenum, GLfloat, GLfloat, GLfloat, GLfloat);
 
 /*---------------------------------------------------------------------------*/
+
+struct gl_info
+{
+    GLint max_texture_units;
+    GLint max_texture_size;
+
+    unsigned int multitexture:1;
+    unsigned int vertex_buffer_object:1;
+    unsigned int point_parameters:1;
+};
+
+extern struct gl_info gli;
+
+/*---------------------------------------------------------------------------*/
 #endif
index 42a937a..8ee9ccb 100644 (file)
@@ -120,12 +120,10 @@ static GLuint make_texture(const void *p, int w, int h, int b)
     int W = w;
     int H = h;
 
-    GLint max;
+    GLint max = gli.max_texture_size;
 
     void *q = NULL;
 
-    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
-
     while (w / k > (int) max || h / k > (int) max)
         k *= 2;