From 1d3713fbf6afe719bf9ca6ba331fe75cb20b5a26 Mon Sep 17 00:00:00 2001
From: DeaDDooMER <deaddoomer@deadsoftware.ru>
Date: Mon, 20 Feb 2023 02:18:38 +0300
Subject: [PATCH] gl: do not used max bound texture size automatically

---
 src/game/renders/opengl/r_render.pas   | 4 ++++
 src/game/renders/opengl/r_textures.pas | 5 +++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/game/renders/opengl/r_render.pas b/src/game/renders/opengl/r_render.pas
index 88c5079..76adb8e 100644
--- a/src/game/renders/opengl/r_render.pas
+++ b/src/game/renders/opengl/r_render.pas
@@ -216,12 +216,16 @@ implementation
 {$ENDIF}
 
   procedure r_Render_LogGLInfo;
+    var size: GLint;
   begin
+    size := 0;
+    glGetIntegerv(GL_MAX_TEXTURE_SIZE, @size);
     e_LogWritefln('GL Vendor: %s', [glGetString(GL_VENDOR)]);
     e_LogWritefln('GL Renderer: %s', [glGetString(GL_RENDERER)]);
     e_LogWritefln('GL Version: %s', [glGetString(GL_VERSION)]);
     e_LogWritefln('GL Shaders: %s', [glGetString(GL_SHADING_LANGUAGE_VERSION)]);
     e_LogWritefln('GL Extensions: %s', [glGetString(GL_EXTENSIONS)]);
+    e_LogWritefln('GL Texture: %s', [size]);
   end;
 
   procedure r_Render_Initialize;
diff --git a/src/game/renders/opengl/r_textures.pas b/src/game/renders/opengl/r_textures.pas
index 97d572c..56d2656 100644
--- a/src/game/renders/opengl/r_textures.pas
+++ b/src/game/renders/opengl/r_textures.pas
@@ -465,7 +465,8 @@ implementation
     begin
       // auto, max possible reccomended by driver
       glGetIntegerv(GL_MAX_TEXTURE_SIZE, @size);
-      if size < 1 then size := 64;
+      size := size div 2; (* hack: on some devices max size may produce invalid texture *)
+      if size < 64 then size := 64; (* at least 64x64 are guarantied by specification *)
     end
     else
     begin
@@ -482,7 +483,7 @@ implementation
   begin
     currentTexture2D := 0;
     maxTileSize := r_Textures_GetMaxHardwareSize();
-    e_LogWritefln('TEXTURE SIZE: %s', [maxTileSize]);
+    e_LogWritefln('Texture Tile Size: %s', [maxTileSize]);
   end;
 
   procedure r_Textures_Finalize;
-- 
2.29.2