DEADSOFTWARE

gl: detect NPOT support
[d2df-editor.git] / src / engine / e_graphics.pas
index 47bf1107eff8781417c7e2f583f11e2201d525ce..b47556bdbedce1eaee8dee480f7660c24ec366ac 100644 (file)
@@ -2,8 +2,7 @@
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -37,7 +36,7 @@ type
     X, Y: Double;
   end;
 
-  TRect = record
+  TRectE = record
     Left, Top, Right, Bottom: Integer;
   end;
 
@@ -52,7 +51,7 @@ type
 
   PPoint = ^TPoint;
   PPoint2f = ^TPoint2f;
-  PRect = ^TRect;
+  PRect = ^TRectE;
   PRectWH = ^TRectWH;
 
 
@@ -126,7 +125,7 @@ procedure e_EndRender();
 function _RGB(Red, Green, Blue: Byte): TRGB;
 function _Point(X, Y: Integer): TPoint2i;
 function _Rect(X, Y: Integer; Width, Height: Word): TRectWH;
-function _TRect(L, T, R, B: LongInt): TRect;
+function _TRect(L, T, R, B: LongInt): TRectE;
 
 //function e_getTextGLId (ID: DWORD): GLuint;
 
@@ -173,6 +172,8 @@ type
     Pixels: Pointer;
   end;
 
+  ArrayOfAnsiString = array of AnsiString;
+
 var
   e_Textures: array of TTexture = nil;
   e_TextureFonts: array of TTextureFont = nil;
@@ -181,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
 //------------------------------------------------------------------
@@ -191,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;
@@ -1522,7 +1561,7 @@ begin
  Result.Height := Height;
 end;
 
-function _TRect(L, T, R, B: LongInt): TRect;
+function _TRect(L, T, R, B: LongInt): TRectE;
 begin
  Result.Top := T;
  Result.Left := L;