Take advantage of GL_ARB_texture_non_power_of_two when it's available
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index e3a6b55..c43739e 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -121,6 +121,7 @@ typedef struct
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 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
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_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
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 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
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;
diff --git a/src/render/opengl/SDL_shaders_gl.c b/src/render/opengl/SDL_shaders_gl.c
index 616f64a..d8f60d4 100644
--- a/src/render/opengl/SDL_shaders_gl.c
+++ b/src/render/opengl/SDL_shaders_gl.c
@@ -376,8 +376,9 @@ GL_CreateShaderContext()
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;
}