From 7ad25ee134897226cb4e96aacffff32d89d1e45a Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Fri, 8 Sep 2023 15:05:59 +0300 Subject: [PATCH] gl: detect NPOT support --- src/engine/e_graphics.pas | 40 +++++++++++++++++++++++++++++++++++++++ src/engine/e_textures.pas | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index 96513d9..b47556b 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -172,6 +172,8 @@ type Pixels: Pointer; end; + ArrayOfAnsiString = array of AnsiString; + var e_Textures: array of TTexture = nil; e_TextureFonts: array of TTextureFont = nil; @@ -180,6 +182,43 @@ var //function e_getTextGLId (ID: DWORD): GLuint; begin result := e_Textures[ID].tx.id; end; +function GLExtensionList(): ArrayOfAnsiString; + var s: PChar; i, j, num: GLint; +begin + result := nil; + s := glGetString(GL_EXTENSIONS); + if s <> nil then + begin + num := 0; + i := 0; + j := 0; + while (s[i] <> #0) and (s[i] = ' ') do Inc(i); + while (s[i] <> #0) do + begin + while (s[i] <> #0) and (s[i] <> ' ') do Inc(i); + SetLength(Result, num + 1); + Result[num] := Copy(s, j + 1, i - j); + while (s[i] <> #0) and (s[i] = ' ') do Inc(i); + j := i; + Inc(num); + end; + end; +end; + +function GLExtensionSupported(ext: AnsiString): Boolean; + var e: AnsiString; +begin + result := false; + for e in GLExtensionList() do + begin + if CompareText(e, ext) = 0 then + begin + Result := True; + exit; + end; + end; +end; + //------------------------------------------------------------------ // Èíèöèàëèçèðóåò OpenGL //------------------------------------------------------------------ @@ -190,6 +229,7 @@ begin e_DummyTextures := True; Exit; end; + e_glLegacyNPOT := not (GLExtensionSupported('GL_ARB_texture_non_power_of_two') or GLExtensionSupported('GL_OES_texture_npot')); e_Colors.R := 255; e_Colors.G := 255; e_Colors.B := 255; diff --git a/src/engine/e_textures.pas b/src/engine/e_textures.pas index 7e1bcea..e484acb 100644 --- a/src/engine/e_textures.pas +++ b/src/engine/e_textures.pas @@ -36,7 +36,7 @@ type var e_DummyTextures: Boolean = False; - e_glLegacyNPOT: Boolean = False; + e_glLegacyNPOT: Boolean = True; TEXTUREFILTER: Integer = GL_NEAREST; function CreateTexture (var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer): Boolean; -- 2.29.2