Added SDL_GL_ExtensionSupported()
authorSam Lantinga <slouken@libsdl.org>
Sat, 22 Jul 2006 21:58:17 +0000
changeset 1926307355678142
parent 1925 411bfb37082b
child 1927 aeb8263d377a
Added SDL_GL_ExtensionSupported()
Use GL_ARB_texture_rectangle in the OpenGL renderer, if supported.
include/SDL_video.h
src/video/SDL_renderer_gl.c
src/video/SDL_video.c
src/video/win32/SDL_win32opengl.c
     1.1 --- a/include/SDL_video.h	Sat Jul 22 21:17:37 2006 +0000
     1.2 +++ b/include/SDL_video.h	Sat Jul 22 21:58:17 2006 +0000
     1.3 @@ -1459,6 +1459,14 @@
     1.4  extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc);
     1.5  
     1.6  /**
     1.7 + * \fn SDL_bool SDL_GL_ExtensionSupported(const char *extension)
     1.8 + *
     1.9 + * \brief Return true if an OpenGL extension is supported for the current context.
    1.10 + */
    1.11 +extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char
    1.12 +                                                           *extension);
    1.13 +
    1.14 +/**
    1.15   * \fn int SDL_GL_SetAttribute(SDL_GLattr attr, int value)
    1.16   *
    1.17   * \brief Set an OpenGL window attribute before window creation.
     2.1 --- a/src/video/SDL_renderer_gl.c	Sat Jul 22 21:17:37 2006 +0000
     2.2 +++ b/src/video/SDL_renderer_gl.c	Sat Jul 22 21:58:17 2006 +0000
     2.3 @@ -97,6 +97,7 @@
     2.4  typedef struct
     2.5  {
     2.6      SDL_GLContext context;
     2.7 +    SDL_bool GL_ARB_texture_rectangle_supported;
     2.8  } GL_RenderData;
     2.9  
    2.10  typedef struct
    2.11 @@ -226,16 +227,19 @@
    2.12      glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_width);
    2.13      glGetIntegerv(GL_MAX_TEXTURE_SIZE, &renderer->info.max_texture_height);
    2.14  
    2.15 -    /* FIXME: Check for GL_ARB_texture_rectangle and GL_EXT_texture_rectangle */
    2.16 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
    2.17 +        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
    2.18 +        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
    2.19 +    }
    2.20  
    2.21      /* Set up parameters for rendering */
    2.22      glDisable(GL_DEPTH_TEST);
    2.23      glDisable(GL_CULL_FACE);
    2.24 -#ifdef USE_GL_TEXTURE_RECTANGLE
    2.25 -    glEnable(GL_TEXTURE_RECTANGLE_ARB);
    2.26 -#else
    2.27 -    glEnable(GL_TEXTURE_2D);
    2.28 -#endif
    2.29 +    if (data->GL_ARB_texture_rectangle_supported) {
    2.30 +        glEnable(GL_TEXTURE_RECTANGLE_ARB);
    2.31 +    } else {
    2.32 +        glEnable(GL_TEXTURE_2D);
    2.33 +    }
    2.34      glMatrixMode(GL_PROJECTION);
    2.35      glLoadIdentity();
    2.36      glMatrixMode(GL_MODELVIEW);
    2.37 @@ -369,19 +373,19 @@
    2.38  
    2.39      glGetError();
    2.40      glGenTextures(1, &data->texture);
    2.41 -#ifdef USE_GL_TEXTURE_RECTANGLE
    2.42 -    data->type = GL_TEXTURE_RECTANGLE_ARB;
    2.43 -    texture_w = texture->w;
    2.44 -    texture_h = texture->h;
    2.45 -    data->texw = (GLfloat) texture->w;
    2.46 -    data->texh = (GLfloat) texture->h;
    2.47 -#else
    2.48 -    data->type = GL_TEXTURE_2D;
    2.49 -    texture_w = power_of_2(texture->w);
    2.50 -    texture_h = power_of_2(texture->h);
    2.51 -    data->texw = (GLfloat) texture->w / texture_w;
    2.52 -    data->texh = (GLfloat) texture->h / texture_h;
    2.53 -#endif
    2.54 +    if (renderdata->GL_ARB_texture_rectangle_supported) {
    2.55 +        data->type = GL_TEXTURE_RECTANGLE_ARB;
    2.56 +        texture_w = texture->w;
    2.57 +        texture_h = texture->h;
    2.58 +        data->texw = (GLfloat) texture->w;
    2.59 +        data->texh = (GLfloat) texture->h;
    2.60 +    } else {
    2.61 +        data->type = GL_TEXTURE_2D;
    2.62 +        texture_w = power_of_2(texture->w);
    2.63 +        texture_h = power_of_2(texture->h);
    2.64 +        data->texw = (GLfloat) texture->w / texture_w;
    2.65 +        data->texh = (GLfloat) texture->h / texture_h;
    2.66 +    }
    2.67      data->format = format;
    2.68      data->formattype = type;
    2.69      glBindTexture(data->type, data->texture);
     3.1 --- a/src/video/SDL_video.c	Sat Jul 22 21:17:37 2006 +0000
     3.2 +++ b/src/video/SDL_video.c	Sat Jul 22 21:58:17 2006 +0000
     3.3 @@ -32,6 +32,15 @@
     3.4  #include "../events/SDL_sysevents.h"
     3.5  #include "../events/SDL_events_c.h"
     3.6  
     3.7 +#if SDL_VIDEO_OPENGL
     3.8 +#include "SDL_opengl.h"
     3.9 +
    3.10 +/* On Windows, windows.h defines CreateWindow */
    3.11 +#ifdef CreateWindow
    3.12 +#undef CreateWindow
    3.13 +#endif
    3.14 +#endif /* SDL_VIDEO_OPENGL */
    3.15 +
    3.16  /* Available video drivers */
    3.17  static VideoBootStrap *bootstrap[] = {
    3.18  #if SDL_VIDEO_DRIVER_QUARTZ
    3.19 @@ -2064,6 +2073,62 @@
    3.20      return func;
    3.21  }
    3.22  
    3.23 +SDL_bool
    3.24 +SDL_GL_ExtensionSupported(const char *extension)
    3.25 +{
    3.26 +#if SDL_VIDEO_OPENGL
    3.27 +    const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
    3.28 +    const char *extensions;
    3.29 +    const char *start;
    3.30 +    const char *where, *terminator;
    3.31 +
    3.32 +    /* Extension names should not have spaces. */
    3.33 +    where = SDL_strchr(extension, ' ');
    3.34 +    if (where || *extension == '\0') {
    3.35 +        return SDL_FALSE;
    3.36 +    }
    3.37 +
    3.38 +    /* See if there's an environment variable override */
    3.39 +    start = SDL_getenv(extension);
    3.40 +    if (start && *start == '0') {
    3.41 +        return SDL_FALSE;
    3.42 +    }
    3.43 +
    3.44 +    /* Lookup the available extensions */
    3.45 +    glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
    3.46 +    if (glGetStringFunc) {
    3.47 +        extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
    3.48 +    } else {
    3.49 +        extensions = NULL;
    3.50 +    }
    3.51 +    if (!extensions) {
    3.52 +        return SDL_FALSE;
    3.53 +    }
    3.54 +
    3.55 +    /* It takes a bit of care to be fool-proof about parsing the
    3.56 +     * OpenGL extensions string. Don't be fooled by sub-strings,
    3.57 +     * etc. */
    3.58 +
    3.59 +    start = extensions;
    3.60 +
    3.61 +    for (;;) {
    3.62 +        where = SDL_strstr(start, extension);
    3.63 +        if (!where)
    3.64 +            break;
    3.65 +
    3.66 +        terminator = where + SDL_strlen(extension);
    3.67 +        if (where == start || *(where - 1) == ' ')
    3.68 +            if (*terminator == ' ' || *terminator == '\0')
    3.69 +                return SDL_TRUE;
    3.70 +
    3.71 +        start = terminator;
    3.72 +    }
    3.73 +    return SDL_FALSE;
    3.74 +#else
    3.75 +    return SDL_FALSE;
    3.76 +#endif
    3.77 +}
    3.78 +
    3.79  int
    3.80  SDL_GL_SetAttribute(SDL_GLattr attr, int value)
    3.81  {
     4.1 --- a/src/video/win32/SDL_win32opengl.c	Sat Jul 22 21:17:37 2006 +0000
     4.2 +++ b/src/video/win32/SDL_win32opengl.c	Sat Jul 22 21:58:17 2006 +0000
     4.3 @@ -196,7 +196,6 @@
     4.4      int pixel_format;
     4.5      HGLRC hglrc;
     4.6      const char *(WINAPI * wglGetExtensionsStringARB) (HDC) = 0;
     4.7 -    const GLubyte *(WINAPI * glGetStringFunc) (GLenum);
     4.8      const char *extensions;
     4.9  
    4.10      hwnd =
    4.11 @@ -241,14 +240,6 @@
    4.12          }
    4.13      }
    4.14  
    4.15 -    glGetStringFunc = WIN_GL_GetProcAddress(_this, "glGetString");
    4.16 -    if (glGetStringFunc) {
    4.17 -        extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
    4.18 -    } else {
    4.19 -        /* Uh oh, something is seriously wrong here... */
    4.20 -        extensions = NULL;
    4.21 -    }
    4.22 -
    4.23      /* Check for WGL_EXT_swap_control */
    4.24      if (HasExtension("WGL_EXT_swap_control", extensions)) {
    4.25          _this->gl_data->wglSwapIntervalEXT =