changeset 1926:307355678142

Added SDL_GL_ExtensionSupported() Use GL_ARB_texture_rectangle in the OpenGL renderer, if supported.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 22 Jul 2006 21:58:17 +0000
parents 411bfb37082b
children aeb8263d377a
files include/SDL_video.h src/video/SDL_renderer_gl.c src/video/SDL_video.c src/video/win32/SDL_win32opengl.c
diffstat 4 files changed, 96 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/include/SDL_video.h	Sat Jul 22 21:17:37 2006 +0000
+++ b/include/SDL_video.h	Sat Jul 22 21:58:17 2006 +0000
@@ -1459,6 +1459,14 @@
 extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
 
 /**
+ * \fn SDL_bool SDL_GL_ExtensionSupported(const char *extension)
+ *
+ * \brief Return true if an OpenGL extension is supported for the current context.
+ */
+extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
+                                                           *extension);
+
+/**
  * \fn int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
  *
  * \brief Set an OpenGL window attribute before window creation.
--- a/src/video/SDL_renderer_gl.c	Sat Jul 22 21:17:37 2006 +0000
+++ b/src/video/SDL_renderer_gl.c	Sat Jul 22 21:58:17 2006 +0000
@@ -97,6 +97,7 @@
 typedef struct
 {
     SDL_GLContext context;
+    SDL_bool GL_ARB_texture_rectangle_supported;
 } GL_RenderData;
 
 typedef struct
@@ -226,16 +227,19 @@
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_width);
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_height);
 
-    /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */
+    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
+        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
+        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
+    }
 
     /* Set up parameters for rendering */
     glDisable(GL_DEPTH_TEST);
     glDisable(GL_CULL_FACE);
-#ifdef USE_GL_TEXTURE_RECTANGLE
-    glEnable(GL_TEXTURE_RECTANGLE_ARB);
-#else
-    glEnable(GL_TEXTURE_2D);
-#endif
+    if (data->GL_ARB_texture_rectangle_supported) {
+        glEnable(GL_TEXTURE_RECTANGLE_ARB);
+    } else {
+        glEnable(GL_TEXTURE_2D);
+    }
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
     glMatrixMode(GL_MODELVIEW);
@@ -369,19 +373,19 @@
 
     glGetError();
     glGenTextures(1, &data->texture);
-#ifdef USE_GL_TEXTURE_RECTANGLE
-    data->type = GL_TEXTURE_RECTANGLE_ARB;
-    texture_w = texture->w;
-    texture_h = texture->h;
-    data->texw = (GLfloat) texture->w;
-    data->texh = (GLfloat) texture->h;
-#else
-    data->type = GL_TEXTURE_2D;
-    texture_w = power_of_2(texture->w);
-    texture_h = power_of_2(texture->h);
-    data->texw = (GLfloat) texture->w / texture_w;
-    data->texh = (GLfloat) texture->h / texture_h;
-#endif
+    if (renderdata->GL_ARB_texture_rectangle_supported) {
+        data->type = GL_TEXTURE_RECTANGLE_ARB;
+        texture_w = texture->w;
+        texture_h = texture->h;
+        data->texw = (GLfloat) texture->w;
+        data->texh = (GLfloat) texture->h;
+    } else {
+        data->type = GL_TEXTURE_2D;
+        texture_w = power_of_2(texture->w);
+        texture_h = power_of_2(texture->h);
+        data->texw = (GLfloat) texture->w / texture_w;
+        data->texh = (GLfloat) texture->h / texture_h;
+    }
     data->format = format;
     data->formattype = type;
     glBindTexture(data->type, data->texture);
--- a/src/video/SDL_video.c	Sat Jul 22 21:17:37 2006 +0000
+++ b/src/video/SDL_video.c	Sat Jul 22 21:58:17 2006 +0000
@@ -32,6 +32,15 @@
 #include "../events/SDL_sysevents.h"
 #include "../events/SDL_events_c.h"
 
+#if SDL_VIDEO_OPENGL
+#include "SDL_opengl.h"
+
+/* On Windows, windows.h defines CreateWindow */
+#ifdef CreateWindow
+#undef CreateWindow
+#endif
+#endif /* SDL_VIDEO_OPENGL */
+
 /* Available video drivers */
 static VideoBootStrap *bootstrap[] = {
 #if SDL_VIDEO_DRIVER_QUARTZ
@@ -2064,6 +2073,62 @@
     return func;
 }
 
+SDL_bool
+SDL_GL_ExtensionSupported(const char *extension)
+{
+#if SDL_VIDEO_OPENGL
+    const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
+    const char *extensions;
+    const char *start;
+    const char *where, *terminator;
+
+    /* Extension names should not have spaces. */
+    where = SDL_strchr(extension, ' ');
+    if (where || *extension == '\0') {
+        return SDL_FALSE;
+    }
+
+    /* See if there's an environment variable override */
+    start = SDL_getenv(extension);
+    if (start && *start == '0') {
+        return SDL_FALSE;
+    }
+
+    /* Lookup the available extensions */
+    glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
+    if (glGetStringFunc) {
+        extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
+    } else {
+        extensions = NULL;
+    }
+    if (!extensions) {
+        return SDL_FALSE;
+    }
+
+    /* It takes a bit of care to be fool-proof about parsing the
+     * OpenGL extensions string. Don't be fooled by sub-strings,
+     * etc. */
+
+    start = extensions;
+
+    for (;;) {
+        where = SDL_strstr(start, extension);
+        if (!where)
+            break;
+
+        terminator = where + SDL_strlen(extension);
+        if (where == start || *(where - 1) == ' ')
+            if (*terminator == ' ' || *terminator == '\0')
+                return SDL_TRUE;
+
+        start = terminator;
+    }
+    return SDL_FALSE;
+#else
+    return SDL_FALSE;
+#endif
+}
+
 int
 SDL_GL_SetAttribute(SDL_GLattr attr, int value)
 {
--- a/src/video/win32/SDL_win32opengl.c	Sat Jul 22 21:17:37 2006 +0000
+++ b/src/video/win32/SDL_win32opengl.c	Sat Jul 22 21:58:17 2006 +0000
@@ -196,7 +196,6 @@
     int pixel_format;
     HGLRC hglrc;
     const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
-    const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
     const char *extensions;
 
     hwnd =
@@ -241,14 +240,6 @@
         }
     }
 
-    glGetStringFunc = WIN_GL_GetProcAddress(_this, "glGetString");
-    if (glGetStringFunc) {
-        extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
-    } else {
-        /* Uh oh, something is seriously wrong here... */
-        extensions = NULL;
-    }
-
     /* Check for WGL_EXT_swap_control */
     if (HasExtension("WGL_EXT_swap_control", extensions)) {
         _this->gl_data->wglSwapIntervalEXT =