Take advantage of GL_ARB_texture_non_power_of_two when it's available
authorSam Lantinga <slouken@libsdl.org>
Thu, 14 Aug 2014 21:31:50 -0700
changeset 9063 66a0d743dd76
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
--- a/src/render/opengl/SDL_render_gl.c	Tue Aug 12 23:37:12 2014 +0200
+++ b/src/render/opengl/SDL_render_gl.c	Thu Aug 14 21:31:50 2014 -0700
@@ -121,6 +121,7 @@
     GLDEBUGPROCARB next_error_callback;
     GLvoid *next_error_userparam;
 
+    SDL_bool GL_ARB_texture_non_power_of_two_supported;
     SDL_bool GL_ARB_texture_rectangle_supported;
     struct {
         GL_Shader shader;
@@ -499,9 +500,13 @@
         data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
     }
 
-    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
-        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
+    if (SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) {
+        data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE;
+    } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
+               SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
         data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
+    }
+    if (data->GL_ARB_texture_rectangle_supported) {
         data->glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &value);
         renderer->info.max_texture_width = value;
         renderer->info.max_texture_height = value;
@@ -697,7 +702,7 @@
 
     GL_CheckError("", renderer);
     renderdata->glGenTextures(1, &data->texture);
-    if (GL_CheckError("glGenTexures()", renderer) < 0) {
+    if (GL_CheckError("glGenTextures()", renderer) < 0) {
         if (data->pixels) {
             SDL_free(data->pixels);
         }
@@ -706,8 +711,13 @@
     }
     texture->driverdata = data;
 
-    if ((renderdata->GL_ARB_texture_rectangle_supported)
-        /* && texture->access != SDL_TEXTUREACCESS_TARGET */){
+    if (renderdata->GL_ARB_texture_non_power_of_two_supported) {
+        data->type = GL_TEXTURE_2D;
+        texture_w = texture->w;
+        texture_h = texture->h;
+        data->texw = 1.0f;
+        data->texh = 1.0f;
+    } else if (renderdata->GL_ARB_texture_rectangle_supported) {
         data->type = GL_TEXTURE_RECTANGLE_ARB;
         texture_w = texture->w;
         texture_h = texture->h;
--- a/src/render/opengl/SDL_shaders_gl.c	Tue Aug 12 23:37:12 2014 +0200
+++ b/src/render/opengl/SDL_shaders_gl.c	Thu Aug 14 21:31:50 2014 -0700
@@ -376,8 +376,9 @@
         return NULL;
     }
 
-    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
-        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
+    if (!SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two") &&
+        (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
+         SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle"))) {
         ctx->GL_ARB_texture_rectangle_supported = SDL_TRUE;
     }