Browse Source

* removed native OpenGL support

master
Bergmann89 9 years ago
parent
commit
360534200c
1 changed files with 5 additions and 589 deletions
  1. +5
    -589
      glBitmap.pas

+ 5
- 589
glBitmap.pas View File

@@ -26,7 +26,7 @@ unit glBitmap;

// Please uncomment the defines below to configure the glBitmap to your preferences.
// If you have configured the unit you can uncomment the warning above.
{$MESSAGE error 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'}
{.$MESSAGE error 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Preferences ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -44,14 +44,6 @@ unit glBitmap;
{.$DEFINE OPENGL_ES_EXT}


// activate to enable build-in OpenGL support with statically linked methods
// use dglOpenGL.pas if not enabled
{.$DEFINE GLB_NATIVE_OGL_STATIC}

// activate to enable build-in OpenGL support with dynamically linked methods
// use dglOpenGL.pas if not enabled
{.$DEFINE GLB_NATIVE_OGL_DYNAMIC}


// activate to enable the support for SDL_surfaces
{.$DEFINE GLB_SDL}
@@ -126,15 +118,6 @@ unit glBitmap;
{$IF DEFINED(OPENGL_ES_2_0)} {$DEFINE OPENGL_ES_1_1} {$IFEND}
{$IF DEFINED(OPENGL_ES_1_1)} {$DEFINE OPENGL_ES} {$IFEND}

// native OpenGL Support
{$IF DEFINED(GLB_NATIVE_OGL_STATIC) OR DEFINED(GLB_NATIVE_OGL_DYNAMIC)}
{$IFDEF OPENGL_ES}
{$ERROR 'native OpenGL is not supported yet for OpenGL ES, please use dglOpenGLES.pas instead'}
{$ELSE}
{$DEFINE GLB_NATIVE_OGL}
{$ENDIF}
{$IFEND}

// checking define combinations
//SDL Image
{$IFDEF GLB_SDL_IMAGE}
@@ -253,11 +236,6 @@ unit glBitmap;
{$DEFINE GLB_SUPPORT_JPEG_WRITE}
{$ENDIF}

// native OpenGL
{$IF DEFINED(GLB_NATIVE_OGL_STATIC) AND DEFINED(GLB_NATIVE_OGL_DYNAMIC)}
{$MESSAGE warn 'GLB_NATIVE_OGL_STATIC will be ignored because you enabled GLB_NATIVE_OGL_DYNAMIC'}
{$IFEND}

// general options
{$EXTENDEDSYNTAX ON}
{$LONGSTRINGS ON}
@@ -269,13 +247,11 @@ unit glBitmap;
interface

uses
{$IFNDEF GLB_NATIVE_OGL}
{$IFDEF OPENGL_ES} dglOpenGLES,
{$ELSE} dglOpenGL, {$ENDIF}
{$ENDIF}
{$IFDEF OPENGL_ES} dglOpenGLES,
{$ELSE} dglOpenGL, {$ENDIF}

{$IF DEFINED(GLB_WIN) AND
(DEFINED(GLB_NATIVE_OGL) OR
DEFINED(GLB_DELPHI))} windows, {$IFEND}
DEFINED(GLB_DELPHI)} windows, {$IFEND}

{$IFDEF GLB_SDL} SDL, {$ENDIF}
{$IFDEF GLB_LAZARUS} IntfGraphics, GraphType, Graphics, {$ENDIF}
@@ -289,319 +265,6 @@ uses

Classes, SysUtils;

{$IFDEF GLB_NATIVE_OGL}
const
GL_TRUE = 1;
GL_FALSE = 0;

GL_ZERO = 0;
GL_ONE = 1;

GL_VERSION = $1F02;
GL_EXTENSIONS = $1F03;

GL_TEXTURE_1D = $0DE0;
GL_TEXTURE_2D = $0DE1;
GL_TEXTURE_RECTANGLE = $84F5;

GL_NORMAL_MAP = $8511;
GL_TEXTURE_CUBE_MAP = $8513;
GL_REFLECTION_MAP = $8512;
GL_TEXTURE_CUBE_MAP_POSITIVE_X = $8515;
GL_TEXTURE_CUBE_MAP_NEGATIVE_X = $8516;
GL_TEXTURE_CUBE_MAP_POSITIVE_Y = $8517;
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y = $8518;
GL_TEXTURE_CUBE_MAP_POSITIVE_Z = $8519;
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z = $851A;

GL_TEXTURE_WIDTH = $1000;
GL_TEXTURE_HEIGHT = $1001;
GL_TEXTURE_INTERNAL_FORMAT = $1003;
GL_TEXTURE_SWIZZLE_RGBA = $8E46;

GL_S = $2000;
GL_T = $2001;
GL_R = $2002;
GL_Q = $2003;

GL_TEXTURE_GEN_S = $0C60;
GL_TEXTURE_GEN_T = $0C61;
GL_TEXTURE_GEN_R = $0C62;
GL_TEXTURE_GEN_Q = $0C63;

GL_RED = $1903;
GL_GREEN = $1904;
GL_BLUE = $1905;

GL_ALPHA = $1906;
GL_ALPHA4 = $803B;
GL_ALPHA8 = $803C;
GL_ALPHA12 = $803D;
GL_ALPHA16 = $803E;

GL_LUMINANCE = $1909;
GL_LUMINANCE4 = $803F;
GL_LUMINANCE8 = $8040;
GL_LUMINANCE12 = $8041;
GL_LUMINANCE16 = $8042;

GL_LUMINANCE_ALPHA = $190A;
GL_LUMINANCE4_ALPHA4 = $8043;
GL_LUMINANCE6_ALPHA2 = $8044;
GL_LUMINANCE8_ALPHA8 = $8045;
GL_LUMINANCE12_ALPHA4 = $8046;
GL_LUMINANCE12_ALPHA12 = $8047;
GL_LUMINANCE16_ALPHA16 = $8048;

GL_RGB = $1907;
GL_BGR = $80E0;
GL_R3_G3_B2 = $2A10;
GL_RGB4 = $804F;
GL_RGB5 = $8050;
GL_RGB565 = $8D62;
GL_RGB8 = $8051;
GL_RGB10 = $8052;
GL_RGB12 = $8053;
GL_RGB16 = $8054;

GL_RGBA = $1908;
GL_BGRA = $80E1;
GL_RGBA2 = $8055;
GL_RGBA4 = $8056;
GL_RGB5_A1 = $8057;
GL_RGBA8 = $8058;
GL_RGB10_A2 = $8059;
GL_RGBA12 = $805A;
GL_RGBA16 = $805B;

GL_DEPTH_COMPONENT = $1902;
GL_DEPTH_COMPONENT16 = $81A5;
GL_DEPTH_COMPONENT24 = $81A6;
GL_DEPTH_COMPONENT32 = $81A7;

GL_COMPRESSED_RGB = $84ED;
GL_COMPRESSED_RGBA = $84EE;
GL_COMPRESSED_RGB_S3TC_DXT1_EXT = $83F0;
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT = $83F1;
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT = $83F2;
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT = $83F3;

GL_UNSIGNED_BYTE = $1401;
GL_UNSIGNED_BYTE_3_3_2 = $8032;
GL_UNSIGNED_BYTE_2_3_3_REV = $8362;

GL_UNSIGNED_SHORT = $1403;
GL_UNSIGNED_SHORT_5_6_5 = $8363;
GL_UNSIGNED_SHORT_4_4_4_4 = $8033;
GL_UNSIGNED_SHORT_5_5_5_1 = $8034;
GL_UNSIGNED_SHORT_5_6_5_REV = $8364;
GL_UNSIGNED_SHORT_4_4_4_4_REV = $8365;
GL_UNSIGNED_SHORT_1_5_5_5_REV = $8366;

GL_UNSIGNED_INT = $1405;
GL_UNSIGNED_INT_8_8_8_8 = $8035;
GL_UNSIGNED_INT_10_10_10_2 = $8036;
GL_UNSIGNED_INT_8_8_8_8_REV = $8367;
GL_UNSIGNED_INT_2_10_10_10_REV = $8368;

{ Texture Filter }
GL_TEXTURE_MAG_FILTER = $2800;
GL_TEXTURE_MIN_FILTER = $2801;
GL_NEAREST = $2600;
GL_NEAREST_MIPMAP_NEAREST = $2700;
GL_NEAREST_MIPMAP_LINEAR = $2702;
GL_LINEAR = $2601;
GL_LINEAR_MIPMAP_NEAREST = $2701;
GL_LINEAR_MIPMAP_LINEAR = $2703;

{ Texture Wrap }
GL_TEXTURE_WRAP_S = $2802;
GL_TEXTURE_WRAP_T = $2803;
GL_TEXTURE_WRAP_R = $8072;
GL_CLAMP = $2900;
GL_REPEAT = $2901;
GL_CLAMP_TO_EDGE = $812F;
GL_CLAMP_TO_BORDER = $812D;
GL_MIRRORED_REPEAT = $8370;

{ Other }
GL_GENERATE_MIPMAP = $8191;
GL_TEXTURE_BORDER_COLOR = $1004;
GL_MAX_TEXTURE_SIZE = $0D33;
GL_PACK_ALIGNMENT = $0D05;
GL_UNPACK_ALIGNMENT = $0CF5;

GL_TEXTURE_MAX_ANISOTROPY_EXT = $84FE;
GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = $84FF;
GL_MAX_CUBE_MAP_TEXTURE_SIZE = $851C;
GL_TEXTURE_GEN_MODE = $2500;

{$IF DEFINED(GLB_WIN)}
libglu = 'glu32.dll';
libopengl = 'opengl32.dll';
{$ELSEIF DEFINED(GLB_LINUX)}
libglu = 'libGLU.so.1';
libopengl = 'libGL.so.1';
{$IFEND}

type
GLboolean = BYTEBOOL;
GLint = Integer;
GLsizei = Integer;
GLuint = Cardinal;
GLfloat = Single;
GLenum = Cardinal;

PGLvoid = Pointer;
PGLboolean = ^GLboolean;
PGLint = ^GLint;
PGLuint = ^GLuint;
PGLfloat = ^GLfloat;

TglCompressedTexImage1D = procedure(target: GLenum; level: GLint; internalformat: GLenum; width: GLsizei; border: GLint; imageSize: GLsizei; const data: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglCompressedTexImage2D = procedure(target: GLenum; level: GLint; internalformat: GLenum; width: GLsizei; height: GLsizei; border: GLint; imageSize: GLsizei; const data: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetCompressedTexImage = procedure(target: GLenum; level: GLint; img: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

{$IF DEFINED(GLB_WIN)}
TwglGetProcAddress = function (ProcName: PAnsiChar): Pointer; stdcall;
{$ELSEIF DEFINED(GLB_LINUX)}
TglXGetProcAddress = function(ProcName: PAnsiChar): Pointer; cdecl;
TglXGetProcAddressARB = function(const name: PAnsiChar): pointer; cdecl;
{$IFEND}

{$IF DEFINED(GLB_NATIVE_OGL_DYNAMIC)}
TglEnable = procedure(cap: GLenum); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglDisable = procedure(cap: GLenum); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TglGetString = function(name: GLenum): PAnsiChar; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetIntegerv = procedure(pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TglTexParameteri = procedure(target: GLenum; pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglTexParameteriv = procedure(target: GLenum; pname: GLenum; const params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglTexParameterfv = procedure(target: GLenum; pname: GLenum; const params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetTexParameteriv = procedure(target: GLenum; pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetTexParameterfv = procedure(target: GLenum; pname: GLenum; params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetTexLevelParameteriv = procedure(target: GLenum; level: GLint; pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetTexLevelParameterfv = procedure(target: GLenum; level: GLint; pname: GLenum; params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TglTexGeni = procedure(coord: GLenum; pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGenTextures = procedure(n: GLsizei; textures: PGLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglBindTexture = procedure(target: GLenum; texture: GLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglDeleteTextures = procedure(n: GLsizei; const textures: PGLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TglAreTexturesResident = function(n: GLsizei; const textures: PGLuint; residences: PGLboolean): GLboolean; {$IFDEF DGL_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglReadPixels = procedure(x: GLint; y: GLint; width: GLsizei; height: GLsizei; format: GLenum; _type: GLenum; pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglPixelStorei = procedure(pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TglTexImage1D = procedure(target: GLenum; level: GLint; internalformat: GLint; width: GLsizei; border: GLint; format: GLenum; _type: GLenum; const pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglTexImage2D = procedure(target: GLenum; level: GLint; internalformat: GLint; width: GLsizei; height: GLsizei; border: GLint; format: GLenum; _type: GLenum; const pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TglGetTexImage = procedure(target: GLenum; level: GLint; format: GLenum; _type: GLenum; pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

TgluBuild1DMipmaps = function(target: GLEnum; components, width: GLint; format, atype: GLEnum; const data: Pointer): GLint; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}
TgluBuild2DMipmaps = function(target: GLEnum; components, width, height: GLint; format, atype: GLEnum; const Data: Pointer): GLint; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF}

{$ELSEIF DEFINED(GLB_NATIVE_OGL_STATIC)}
procedure glEnable(cap: GLenum); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glDisable(cap: GLenum); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

function glGetString(name: GLenum): PAnsiChar; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetIntegerv(pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glTexParameteriv(target: GLenum; pname: GLenum; const params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glTexParameterfv(target: GLenum; pname: GLenum; const params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetTexParameteriv(target: GLenum; pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetTexParameterfv(target: GLenum; pname: GLenum; params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetTexLevelParameteriv(target: GLenum; level: GLint; pname: GLenum; params: PGLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetTexLevelParameterfv(target: GLenum; level: GLint; pname: GLenum; params: PGLfloat); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

procedure glTexGeni(coord: GLenum; pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGenTextures(n: GLsizei; textures: PGLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glBindTexture(target: GLenum; texture: GLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glDeleteTextures(n: GLsizei; const textures: PGLuint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

function glAreTexturesResident(n: GLsizei; const textures: PGLuint; residences: PGLboolean): GLboolean; {$IFDEF DGL_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glReadPixels(x: GLint; y: GLint; width: GLsizei; height: GLsizei; format: GLenum; _type: GLenum; pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glPixelStorei(pname: GLenum; param: GLint); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

procedure glTexImage1D(target: GLenum; level: GLint; internalformat: GLint; width: GLsizei; border: GLint; format: GLenum; _type: GLenum; const pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glTexImage2D(target: GLenum; level: GLint; internalformat: GLint; width: GLsizei; height: GLsizei; border: GLint; format: GLenum; _type: GLenum; const pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;
procedure glGetTexImage(target: GLenum; level: GLint; format: GLenum; _type: GLenum; pixels: PGLvoid); {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libopengl;

function gluBuild1DMipmaps(target: GLEnum; components, width: GLint; format, atype: GLEnum; const data: Pointer): GLint; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libglu;
function gluBuild2DMipmaps(target: GLEnum; components, width, height: GLint; format, atype: GLEnum; const Data: Pointer): GLint; {$IFDEF GLB_WIN}stdcall; {$ELSE}cdecl; {$ENDIF} external libglu;
{$IFEND}

var
GL_VERSION_1_2,
GL_VERSION_1_3,
GL_VERSION_1_4,
GL_VERSION_2_0,
GL_VERSION_3_3,

GL_SGIS_generate_mipmap,

GL_ARB_texture_border_clamp,
GL_ARB_texture_mirrored_repeat,
GL_ARB_texture_rectangle,
GL_ARB_texture_non_power_of_two,
GL_ARB_texture_swizzle,
GL_ARB_texture_cube_map,

GL_IBM_texture_mirrored_repeat,

GL_NV_texture_rectangle,

GL_EXT_texture_edge_clamp,
GL_EXT_texture_rectangle,
GL_EXT_texture_swizzle,
GL_EXT_texture_cube_map,
GL_EXT_texture_filter_anisotropic: Boolean;

glCompressedTexImage1D: TglCompressedTexImage1D;
glCompressedTexImage2D: TglCompressedTexImage2D;
glGetCompressedTexImage: TglGetCompressedTexImage;

{$IF DEFINED(GLB_WIN)}
wglGetProcAddress: TwglGetProcAddress;
{$ELSEIF DEFINED(GLB_LINUX)}
glXGetProcAddress: TglXGetProcAddress;
glXGetProcAddressARB: TglXGetProcAddress;
{$IFEND}

{$IFDEF GLB_NATIVE_OGL_DYNAMIC}
glEnable: TglEnable;
glDisable: TglDisable;

glGetString: TglGetString;
glGetIntegerv: TglGetIntegerv;

glTexParameteri: TglTexParameteri;
glTexParameteriv: TglTexParameteriv;
glTexParameterfv: TglTexParameterfv;
glGetTexParameteriv: TglGetTexParameteriv;
glGetTexParameterfv: TglGetTexParameterfv;
glGetTexLevelParameteriv: TglGetTexLevelParameteriv;
glGetTexLevelParameterfv: TglGetTexLevelParameterfv;

glTexGeni: TglTexGeni;
glGenTextures: TglGenTextures;
glBindTexture: TglBindTexture;
glDeleteTextures: TglDeleteTextures;

glAreTexturesResident: TglAreTexturesResident;
glReadPixels: TglReadPixels;
glPixelStorei: TglPixelStorei;

glTexImage1D: TglTexImage1D;
glTexImage2D: TglTexImage2D;
glGetTexImage: TglGetTexImage;

gluBuild1DMipmaps: TgluBuild1DMipmaps;
gluBuild2DMipmaps: TgluBuild2DMipmaps;
{$ENDIF}
{$ENDIF}

type
{$IFNDEF fpc}
QWord = System.UInt64;
@@ -2397,234 +2060,6 @@ begin
DEPTH_WEIGHT_B * aPixel.Data.b);
end;

{$IFDEF GLB_NATIVE_OGL}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//OpenGLInitialization///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var
GL_LibHandle: Pointer = nil;

function glbGetProcAddress(aProcName: PAnsiChar; aLibHandle: Pointer = nil; const aRaiseOnErr: Boolean = true): Pointer;
begin
if not Assigned(aLibHandle) then
aLibHandle := GL_LibHandle;

{$IF DEFINED(GLB_WIN)}
result := GetProcAddress({%H-}HMODULE(aLibHandle), aProcName);
if Assigned(result) then
exit;

if Assigned(wglGetProcAddress) then
result := wglGetProcAddress(aProcName);
{$ELSEIF DEFINED(GLB_LINUX)}
if Assigned(glXGetProcAddress) then begin
result := glXGetProcAddress(aProcName);
if Assigned(result) then
exit;
end;

if Assigned(glXGetProcAddressARB) then begin
result := glXGetProcAddressARB(aProcName);
if Assigned(result) then
exit;
end;

result := dlsym(aLibHandle, aProcName);
{$IFEND}
if not Assigned(result) and aRaiseOnErr then
raise EglBitmap.Create('unable to load procedure form library: ' + aProcName);
end;

{$IFDEF GLB_NATIVE_OGL_DYNAMIC}
var
GLU_LibHandle: Pointer = nil;
OpenGLInitialized: Boolean;
InitOpenGLCS: TCriticalSection;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure glbInitOpenGL;

////////////////////////////////////////////////////////////////////////////////
function glbLoadLibrary(const aName: PChar): Pointer;
begin
{$IF DEFINED(GLB_WIN)}
result := {%H-}Pointer(LoadLibrary(aName));
{$ELSEIF DEFINED(GLB_LINUX)}
result := dlopen(Name, RTLD_LAZY);
{$ELSE}
result := nil;
{$IFEND}
end;

////////////////////////////////////////////////////////////////////////////////
function glbFreeLibrary(const aLibHandle: Pointer): Boolean;
begin
result := false;
if not Assigned(aLibHandle) then
exit;

{$IF DEFINED(GLB_WIN)}
Result := FreeLibrary({%H-}HINST(aLibHandle));
{$ELSEIF DEFINED(GLB_LINUX)}
Result := dlclose(aLibHandle) = 0;
{$IFEND}
end;

begin
if Assigned(GL_LibHandle) then
glbFreeLibrary(GL_LibHandle);

if Assigned(GLU_LibHandle) then
glbFreeLibrary(GLU_LibHandle);

GL_LibHandle := glbLoadLibrary(libopengl);
if not Assigned(GL_LibHandle) then
raise EglBitmap.Create('unable to load library: ' + libopengl);

GLU_LibHandle := glbLoadLibrary(libglu);
if not Assigned(GLU_LibHandle) then
raise EglBitmap.Create('unable to load library: ' + libglu);

{$IF DEFINED(GLB_WIN)}
wglGetProcAddress := glbGetProcAddress('wglGetProcAddress');
{$ELSEIF DEFINED(GLB_LINUX)}
glXGetProcAddress := glbGetProcAddress('glXGetProcAddress');
glXGetProcAddressARB := glbGetProcAddress('glXGetProcAddressARB');
{$IFEND}

glEnable := glbGetProcAddress('glEnable');
glDisable := glbGetProcAddress('glDisable');
glGetString := glbGetProcAddress('glGetString');
glGetIntegerv := glbGetProcAddress('glGetIntegerv');
glTexParameteri := glbGetProcAddress('glTexParameteri');
glTexParameteriv := glbGetProcAddress('glTexParameteriv');
glTexParameterfv := glbGetProcAddress('glTexParameterfv');
glGetTexParameteriv := glbGetProcAddress('glGetTexParameteriv');
glGetTexParameterfv := glbGetProcAddress('glGetTexParameterfv');
glGetTexLevelParameteriv := glbGetProcAddress('glGetTexLevelParameteriv');
glGetTexLevelParameterfv := glbGetProcAddress('glGetTexLevelParameterfv');
glTexGeni := glbGetProcAddress('glTexGeni');
glGenTextures := glbGetProcAddress('glGenTextures');
glBindTexture := glbGetProcAddress('glBindTexture');
glDeleteTextures := glbGetProcAddress('glDeleteTextures');
glAreTexturesResident := glbGetProcAddress('glAreTexturesResident');
glReadPixels := glbGetProcAddress('glReadPixels');
glPixelStorei := glbGetProcAddress('glPixelStorei');
glTexImage1D := glbGetProcAddress('glTexImage1D');
glTexImage2D := glbGetProcAddress('glTexImage2D');
glGetTexImage := glbGetProcAddress('glGetTexImage');

gluBuild1DMipmaps := glbGetProcAddress('gluBuild1DMipmaps', GLU_LibHandle);
gluBuild2DMipmaps := glbGetProcAddress('gluBuild2DMipmaps', GLU_LibHandle);
end;
{$ENDIF}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure glbReadOpenGLExtensions;
var
Buffer: AnsiString;
MajorVersion, MinorVersion: Integer;

///////////////////////////////////////////////////////////////////////////////////////////
procedure TrimVersionString(aBuffer: AnsiString; out aMajor, aMinor: Integer);
var
Separator: Integer;
begin
aMinor := 0;
aMajor := 0;

Separator := Pos(AnsiString('.'), aBuffer);
if (Separator > 1) and (Separator < Length(aBuffer)) and
(aBuffer[Separator - 1] in ['0'..'9']) and
(aBuffer[Separator + 1] in ['0'..'9']) then begin

Dec(Separator);
while (Separator > 0) and (aBuffer[Separator] in ['0'..'9']) do
Dec(Separator);

Delete(aBuffer, 1, Separator);
Separator := Pos(AnsiString('.'), aBuffer) + 1;

while (Separator <= Length(aBuffer)) and (AnsiChar(aBuffer[Separator]) in ['0'..'9']) do
Inc(Separator);

Delete(aBuffer, Separator, 255);
Separator := Pos(AnsiString('.'), aBuffer);

aMajor := StrToInt(Copy(String(aBuffer), 1, Separator - 1));
aMinor := StrToInt(Copy(String(aBuffer), Separator + 1, 1));
end;
end;

///////////////////////////////////////////////////////////////////////////////////////////
function CheckExtension(const Extension: AnsiString): Boolean;
var
ExtPos: Integer;
begin
ExtPos := Pos(Extension, Buffer);
result := ExtPos > 0;
if result then
result := ((ExtPos + Length(Extension) - 1) = Length(Buffer)) or not (Buffer[ExtPos + Length(Extension)] in ['_', 'A'..'Z', 'a'..'z']);
end;

///////////////////////////////////////////////////////////////////////////////////////////
function CheckVersion(const aMajor, aMinor: Integer): Boolean;
begin
result := (MajorVersion > aMajor) or ((MajorVersion = aMajor) and (MinorVersion >= aMinor));
end;

begin
{$IFDEF GLB_NATIVE_OGL_DYNAMIC}
InitOpenGLCS.Enter;
try
if not OpenGLInitialized then begin
glbInitOpenGL;
OpenGLInitialized := true;
end;
finally
InitOpenGLCS.Leave;
end;
{$ENDIF}

// Version
Buffer := glGetString(GL_VERSION);
TrimVersionString(Buffer, MajorVersion, MinorVersion);

GL_VERSION_1_2 := CheckVersion(1, 2);
GL_VERSION_1_3 := CheckVersion(1, 3);
GL_VERSION_1_4 := CheckVersion(1, 4);
GL_VERSION_2_0 := CheckVersion(2, 0);
GL_VERSION_3_3 := CheckVersion(3, 3);

// Extensions
Buffer := glGetString(GL_EXTENSIONS);
GL_ARB_texture_border_clamp := CheckExtension('GL_ARB_texture_border_clamp');
GL_ARB_texture_non_power_of_two := CheckExtension('GL_ARB_texture_non_power_of_two');
GL_ARB_texture_swizzle := CheckExtension('GL_ARB_texture_swizzle');
GL_ARB_texture_cube_map := CheckExtension('GL_ARB_texture_cube_map');
GL_ARB_texture_rectangle := CheckExtension('GL_ARB_texture_rectangle');
GL_ARB_texture_mirrored_repeat := CheckExtension('GL_ARB_texture_mirrored_repeat');
GL_EXT_texture_edge_clamp := CheckExtension('GL_EXT_texture_edge_clamp');
GL_EXT_texture_filter_anisotropic := CheckExtension('GL_EXT_texture_filter_anisotropic');
GL_EXT_texture_rectangle := CheckExtension('GL_EXT_texture_rectangle');
GL_EXT_texture_swizzle := CheckExtension('GL_EXT_texture_swizzle');
GL_EXT_texture_cube_map := CheckExtension('GL_EXT_texture_cube_map');
GL_NV_texture_rectangle := CheckExtension('GL_NV_texture_rectangle');
GL_IBM_texture_mirrored_repeat := CheckExtension('GL_IBM_texture_mirrored_repeat');
GL_SGIS_generate_mipmap := CheckExtension('GL_SGIS_generate_mipmap');

if GL_VERSION_1_3 then begin
glCompressedTexImage1D := glbGetProcAddress('glCompressedTexImage1D');
glCompressedTexImage2D := glbGetProcAddress('glCompressedTexImage2D');
glGetCompressedTexImage := glbGetProcAddress('glGetCompressedTexImage');
end else begin
glCompressedTexImage1D := glbGetProcAddress('glCompressedTexImage1DARB', nil, false);
glCompressedTexImage2D := glbGetProcAddress('glCompressedTexImage2DARB', nil, false);
glGetCompressedTexImage := glbGetProcAddress('glGetCompressedTexImageARB', nil, false);
end;
end;
{$ENDIF}

{$IFDEF GLB_SDL_IMAGE}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SDL Image Helper /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -6577,9 +6012,6 @@ constructor TglBitmap.Create;
begin
if (ClassType = TglBitmap) then
raise EglBitmap.Create('Don''t create TglBitmap directly. Use one of the deviated classes (TglBitmap2D) instead.');
{$IFDEF GLB_NATIVE_OGL}
glbReadOpenGLExtensions;
{$ENDIF}
inherited Create;
fFormat := glBitmapGetDefaultFormat;
fFreeDataOnDestroy := true;
@@ -9528,23 +8960,7 @@ initialization

TFormatDescriptor.Init;

{$IFDEF GLB_NATIVE_OGL_DYNAMIC}
OpenGLInitialized := false;
InitOpenGLCS := TCriticalSection.Create;
{$ENDIF}

finalization
TFormatDescriptor.Finalize;

{$IFDEF GLB_NATIVE_OGL}
if Assigned(GL_LibHandle) then
glbFreeLibrary(GL_LibHandle);

{$IFDEF GLB_NATIVE_OGL_DYNAMIC}
if Assigned(GLU_LibHandle) then
glbFreeLibrary(GLU_LibHandle);
FreeAndNil(InitOpenGLCS);
{$ENDIF}
{$ENDIF}

end.

Loading…
Cancel
Save