From e2c0ffbd3c4bc1516930552924062d56447df065 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Mon, 14 Aug 2017 18:05:27 +0300 Subject: [PATCH] autodetect NPOT texture support --- src/game/g_game.pas | 3 +++ src/game/g_window.pas | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 963f8ae..68b2ee4 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -6485,6 +6485,9 @@ var begin Parse_Params(pars); + s := Find_Param_Value(pars, '--opengl-dump-exts'); + if s <> '' then gwin_dump_extensions := true; // sorry + // Debug mode: s := Find_Param_Value(pars, '--debug'); if (s <> '') then diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 651675a..6ffa8ff 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -36,6 +36,9 @@ function GetDisplayModes(dBPP: DWORD; var SelRes: DWORD): SArray; function g_Window_SetDisplay(PreserveGL: Boolean = False): Boolean; function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean; +var + gwin_dump_extensions: Boolean = false; + implementation uses @@ -640,6 +643,47 @@ begin SDL_GL_SetSwapInterval(v); end; +function glHasExtension (name: AnsiString): Boolean; +var + exts: PChar; + i: Integer; + found: Boolean; + extName: ShortString; +begin + result := false; + if length(name) = 0 then exit; + exts := glGetString(GL_EXTENSIONS); + if exts = nil then exit; + while (exts[0] <> #0) and (exts[0] = ' ') do Inc(exts); + while exts[0] <> #0 do + begin + if gwin_dump_extensions then + begin + i := 0; + while (exts[i] <> #0) and (exts[i] <> ' ') do Inc(i); + if i > 255 then + begin + e_WriteLog('FUUUUUUUUUUUUU', MSG_WARNING); + end + else + begin + Move(exts^, extName[1], i); + extName[0] := Char(i); + e_WriteLog(Format('EXT: %s', [extName]), MSG_NOTIFY); + end; + end; + found := true; + for i := 0 to length(name)-1 do + begin + if exts[i] = #0 then begin found := false; break; end; + if exts[i] <> name[i+1] then begin found := false; break; end; + end; + if found and ((exts[length(name)] = #0) or (exts[length(name)] = ' ')) then begin result := true; exit; end; + while (exts[0] <> #0) and (exts[0] <> ' ') do Inc(exts); + while (exts[0] <> #0) and (exts[0] = ' ') do Inc(exts); + end; +end; + function SDLMain(): Integer; begin {$IFDEF HEADLESS} @@ -658,6 +702,17 @@ begin {EnumDisplayModes();} + if not glHasExtension('GL_ARB_texture_non_power_of_two') then + begin + e_WriteLog('Driver DID''T advertised NPOT textures support', MSG_WARNING); + glLegacyNPOT := true; + end + else + begin + e_WriteLog('Driver advertised NPOT textures support', MSG_NOTIFY); + glLegacyNPOT := false; + end; + Init(); Time_Old := GetTimer(); -- 2.29.2