SDL: opengl: If GL version >= 2.0, NPOT textures are supported, so favor them.

From 293a0aa80e0c74712e73e17b2139bfe0c2df49c9 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 22 Feb 2022 10:54:21 -0500
Subject: [PATCH] opengl: If GL version >= 2.0, NPOT textures are supported, so
 favor them.

Fixes #5041.
---
 src/render/opengl/SDL_render_gl.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 9464f8ef034..2b20b17744d 100644
--- a/src/render/opengl/SDL_render_gl.c
+++ b/src/render/opengl/SDL_render_gl.c
@@ -1700,6 +1700,8 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
     Uint32 window_flags;
     int profile_mask = 0, major = 0, minor = 0;
     SDL_bool changed_window = SDL_FALSE;
+    SDL_bool isGL2 = SDL_FALSE;
+    const char *verstr = NULL;
 
     SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask);
     SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major);
@@ -1815,15 +1817,30 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
         data->glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
     }
 
+    verstr = (const char *) data->glGetString(GL_VERSION);
+    if (verstr) {
+        char verbuf[16];
+        char *ptr;
+        SDL_strlcpy(verbuf, verstr, sizeof (verbuf));
+        ptr = SDL_strchr(verbuf, '.');
+        if (ptr) {
+            *ptr = '\0';
+            if (SDL_atoi(verbuf) >= 2) {
+                isGL2 = SDL_TRUE;
+            }
+        }
+    }
+
     data->textype = GL_TEXTURE_2D;
-    if (SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) {
+    if (isGL2 || SDL_GL_ExtensionSupported("GL_ARB_texture_non_power_of_two")) {
         data->GL_ARB_texture_non_power_of_two_supported = SDL_TRUE;
+        data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
+        renderer->info.max_texture_width = value;
+        renderer->info.max_texture_height = value;
     } else if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle") ||
                SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
         data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
         data->textype = GL_TEXTURE_RECTANGLE_ARB;
-    }
-    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;