Take advantage of GL_ARB_texture_non_power_of_two when it's available
authorSam Lantinga
Thu, 14 Aug 2014 21:31:50 -0700
changeset 906366a0d743dd76
parent 9057 8a1d9a60f9be
child 9064 428bff5bf38a
Take advantage of GL_ARB_texture_non_power_of_two when it's available
src/render/opengl/SDL_render_gl.c
src/render/opengl/SDL_shaders_gl.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Tue Aug 12 23:37:12 2014 +0200
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Thu Aug 14 21:31:50 2014 -0700
     1.3 @@ -121,6 +121,7 @@
     1.4      GLDEBUGPROCARB next_error_callback;
     1.5      GLvoid *next_error_userparam;
     1.6  
     1.7 +    SDL_bool GL_ARB_texture_non_power_of_two_supported;
     1.8      SDL_bool GL_ARB_texture_rectangle_supported;
     1.9      struct {
    1.10          GL_Shader shader;
    1.11 @@ -499,9 +500,13 @@
    1.12          data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
    1.13      }
    1.14  
    1.15 -    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
    1.16 -        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
    1.17 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) {
    1.18 +        data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE;
    1.19 +    } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
    1.20 +               SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
    1.21          data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
    1.22 +    }
    1.23 +    if (data->GL_ARB_texture_rectangle_supported) {
    1.24          data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value);
    1.25          renderer->info.max_texture_width = value;
    1.26          renderer->info.max_texture_height = value;
    1.27 @@ -697,7 +702,7 @@
    1.28  
    1.29      GL_CheckError("", renderer);
    1.30      renderdata->glGenTextures(1, &data->texture);
    1.31 -    if (GL_CheckError("glGenTexures()", renderer) < 0) {
    1.32 +    if (GL_CheckError("glGenTextures()", renderer) < 0) {
    1.33          if (data->pixels) {
    1.34              SDL_free(data->pixels);
    1.35          }
    1.36 @@ -706,8 +711,13 @@
    1.37      }
    1.38      texture->driverdata = data;
    1.39  
    1.40 -    if ((renderdata->GL_ARB_texture_rectangle_supported)
    1.41 -        /* && texture->access != SDL_TEXTUREACCESS_TARGET */){
    1.42 +    if (renderdata->GL_ARB_texture_non_power_of_two_supported) {
    1.43 +        data->type = GL_TEXTURE_2D;
    1.44 +        texture_w = texture->w;
    1.45 +        texture_h = texture->h;
    1.46 +        data->texw = 1.0f;
    1.47 +        data->texh = 1.0f;
    1.48 +    } else if (renderdata->GL_ARB_texture_rectangle_supported) {
    1.49          data->type = GL_TEXTURE_RECTANGLE_ARB;
    1.50          texture_w = texture->w;
    1.51          texture_h = texture->h;
     2.1 --- a/src/render/opengl/SDL_shaders_gl.c	Tue Aug 12 23:37:12 2014 +0200
     2.2 +++ b/src/render/opengl/SDL_shaders_gl.c	Thu Aug 14 21:31:50 2014 -0700
     2.3 @@ -376,8 +376,9 @@
     2.4          return NULL;
     2.5      }
     2.6  
     2.7 -    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
     2.8 -        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
     2.9 +    if (!SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two") &&
    2.10 +        (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
    2.11 +         SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle"))) {
    2.12          ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE;
    2.13      }
    2.14