unit GLtools;

interface

uses Windows, SysUtils, GL, GLu, GLext, WGLext;

function glext_ExtensionSupported(const extension: string): boolean;

implementation

var
  wglGetExtensionsStringARB: function(hdc: HDC): Pchar; stdcall = nil;

function glext_ExtensionSupportedEx(const extension: string; extensions: PChar): boolean;
var
  start, where, terminator: PChar;
begin
  start := extensions;
  while true do
  begin
    where := StrPos(start, PChar(extension));
    if where = nil then Break;
    terminator := Pointer(Integer(where) + Length(extension));
    if (where = start) or (PChar(Integer(where) - 1)^ = ' ') then
    begin
      if (terminator^ = ' ') or (terminator^ = #0) then
      begin
	result := true;
	exit;
      end;
    end;
    start := terminator;
  end;
  result := false;
end;

function glext_ExtensionSupported(const extension: string): boolean;
var
  extensions: PChar;
begin
  result := true;
  extensions := PChar(glGetString(GL_EXTENSIONS));
  if glext_ExtensionSupportedEx(extension, extensions) then exit;
  wglGetExtensionsStringARB := wglGetProcAddress('wglGetExtensionsStringARB');
  if Assigned(wglGetExtensionsStringARB) then
  begin
    extensions := PChar(wglGetExtensionsStringARB(wglGetCurrentDC));
    if glext_ExtensionSupportedEx(extension, extensions) then exit;
  end;
  result := false;
end;

end.
