* removed native OpenGL support
[glBitmap.git] / glBitmap.pas
index 759a404..c18c83b 100644 (file)
-{***********************************************************
-glBitmap by Steffen Xonna aka Lossy eX (2003-2008)
-http://www.opengl24.de/index.php?cat=header&file=glbitmap
-
-modified by Delphi OpenGL Community (http://delphigl.com/) (2013)
-
-------------------------------------------------------------
-The contents of this file are used with permission, subject to
-the Mozilla Public License Version 1.1 (the "License"); you may
-not use this file except in compliance with the License. You may
-obtain a copy of the License at
-http://www.mozilla.org/MPL/MPL-1.1.html
-------------------------------------------------------------
-Version 3.0.1
-------------------------------------------------------------
-History
-20-11-2013
-- refactoring of the complete library
-21-03-2010
-- The define GLB_DELPHI dosn't check versions anymore. If you say you are using delphi
-  then it's your problem if that isn't true. This prevents the unit for incompatibility
-  with newer versions of Delphi.
-- Problems with D2009+ resolved (Thanks noeska and all i forgot)
-- GetPixel isn't set if you are loading textures inside the constructor (Thanks Wilson)
-10-08-2008
-- AddAlphaFromglBitmap used the custom pointer instead the imagedatapointer (Thanks Wilson)
-- Additional Datapointer for functioninterface now has the name CustomData
-24-07-2008
-- AssigneAlphaToBitmap overwrites his own palette (Thanks Wilson)
-- If you load an texture from an file the property Filename will be set to the name of the file
-- Three new properties to attach custom data to the Texture objects
-  - CustomName  (free for use string)
-  - CustomNameW (free for use widestring)
-  - CustomDataPointer (free for use pointer to attach other objects or complex structures)
-27-05-2008
-- RLE TGAs loaded much faster
-26-05-2008
-- fixed some problem with reading RLE TGAs.
-21-05-2008
-- function clone now only copys data if it's assigned and now it also copies the ID
-- it seems that lazarus dont like comments in comments.
-01-05-2008
-- It's possible to set the id of the texture
-- define GLB_NO_NATIVE_GL deactivated by default
-27-04-2008
-- Now supports the following libraries
-  - SDL and SDL_image
-  - libPNG
-  - libJPEG
-- Linux compatibillity via free pascal compatibility (delphi sources optional)
-- BMPs now loaded manuel
-- Large restructuring
-- Property DataPtr now has the name Data
-- Functions are more flexible between RGB(A) and BGR(A). RGB can be saved as Bitmap and will be saved as BGR
-- Unused Depth removed
-- Function FreeData to freeing image data added
-24-10-2007
-- ImageID flag of TGAs was ignored. (Thanks Zwoetzen)
-15-11-2006
-- Function SetBorderColor implemented (only used by opengl if wrap is set to GL_CLAMP_TO_BORDER)
-- Function AddAlphaFromValue implemented to use an fixed Value as Alphachannel
-- Function ReadOpenGLExtension is now only intern
-29-06-2006
-- pngimage now disabled by default like all other versions.
-26-06-2006
-- Setting up an anisotropic filter of 0 isnt allowed by nvidia (Thanks Ogridi)
-22-06-2006
-- Fixed some Problem with Delphi 5
-- Now uses the newest version of pngimage. Makes saving pngs much easier.
-22-03-2006
-- Property IsCompressed and Size removed. Not really supported by Spec (Thanks Ogridi)
-09-03-2006
-- Internal Format ifDepth8 added
-- function GrabScreen now supports all uncompressed formats
-31-01-2006
-- AddAlphaFromglBitmap implemented
-29-12-2005
-- LoadFromResource and LoadFromResourceId now needs an Instance and an ResourceType (for ID)
-28-12-2005
-- Width, Height and Depth internal changed to TglBitmapPixelPosition.
-  property Width, Height, Depth are still existing and new property Dimension are avail
-11-12-2005
-- Added native OpenGL Support. Breaking the dglOpenGL "barrier".
-19-10-2005
-- Added function GrabScreen to class TglBitmap2D
-18-10-2005
-- Added support to Save images
-- Added function Clone to Clone Instance
-11-10-2005
-- Functions now works with Cardinals for each channel. Up to 32 Bits per channel.
-  Usefull for Future
-- Several speed optimizations
-09-10-2005
-- Internal structure change. Loading of TGA, PNG and DDS improved.
-  Data, format and size will now set directly with SetDataPtr.
-- AddFunc now works with all Types of Images and Formats
-- Some Funtions moved to Baseclass TglBitmap
-06-10-2005
-- Added Support to decompress DXT3 and DXT5 compressed Images.
-- Added Mapping to convert data from one format into an other.
-05-10-2005
-- Added method ConvertTo in Class TglBitmap2D. Method allows to convert every
-  supported Input format (supported by GetPixel) into any uncompresed Format
-- Added Support to decompress DXT1 compressed Images.
-- SwapColors replaced by ConvertTo
-04-10-2005
-- Added Support for compressed DDSs
-- Added new internal formats (DXT1, DXT3, DXT5)
-29-09-2005
-- Parameter Components renamed to InternalFormat
-23-09-2005
-- Some AllocMem replaced with GetMem (little speed change)
-- better exception handling. Better protection from memory leaks.
-22-09-2005
-- Added support for Direct Draw Surfaces (.DDS) (uncompressed images only)
-- Added new internal formats (RGB8, RGBA8, RGBA4, RGB5A1, RGB10A2, R5G6B5)
-07-09-2005
-- Added support for Grayscale textures
-- Added internal formats (Alpha, Luminance, LuminanceAlpha, BGR8, BGRA8)
-10-07-2005
-- Added support for GL_VERSION_2_0
-- Added support for GL_EXT_texture_filter_anisotropic
-04-07-2005
-- Function FillWithColor fills the Image with one Color
-- Function LoadNormalMap added
-30-06-2005
-- ToNormalMap allows to Create an NormalMap from the Alphachannel
-- ToNormalMap now supports Sobel (nmSobel) function.
-29-06-2005
-- support for RLE Compressed RGB TGAs added
-28-06-2005
-- Class TglBitmapNormalMap added to support Normalmap generation
-- Added function ToNormalMap in class TglBitmap2D to genereate normal maps from textures.
-  3 Filters are supported. (4 Samples, 3x3 and 5x5)
-16-06-2005
-- Method LoadCubeMapClass removed
-- LoadCubeMap returnvalue is now the Texture paramter. Such as LoadTextures
-- virtual abstract method GenTexture in class TglBitmap now is protected
-12-06-2005
-- now support DescriptionFlag in LoadTga. Allows vertical flipped images to be loaded as normal
-10-06-2005
-- little enhancement for IsPowerOfTwo
-- TglBitmap1D.GenTexture now tests NPOT Textures
-06-06-2005
-- some little name changes. All properties or function with Texture in name are
-  now without texture in name. We have allways texture so we dosn't name it.
-03-06-2005
-- GenTexture now tests if texture is NPOT and NPOT-Texture are supported or
-  TextureTarget is GL_TEXTURE_RECTANGLE. Else it raised an exception.
-02-06-2005
-- added support for GL_ARB_texture_rectangle, GL_EXT_texture_rectangle and GL_NV_texture_rectangle
-25-04-2005
-- Function Unbind added
-- call of SetFilter or SetTextureWrap if TextureID exists results in setting properties to opengl texture.
-21-04-2005
-- class TglBitmapCubeMap added (allows to Create Cubemaps)
-29-03-2005
-- Added Support for PNG Images. (http://pngdelphi.sourceforge.net/)
-  To Enable png's use the define pngimage
-22-03-2005
-- New Functioninterface added
-- Function GetPixel added
-27-11-2004
-- Property BuildMipMaps renamed to MipMap
-21-11-2004
-- property Name removed.
-- BuildMipMaps is now a set of 3 values. None, GluBuildMipmaps and SGIS_generate_mipmap
-22-05-2004
-- property name added. Only used in glForms!
-26-11-2003
-- property FreeDataAfterGenTexture is now available as default (default = true)
-- BuildMipmaps now implemented in TglBitmap1D (i've forgotten it)
-- function MoveMemory replaced with function Move (little speed change)
-- several calculations stored in variables (little speed change)
-29-09-2003
-- property BuildMipsMaps added (default = true)
-  if BuildMipMaps isn't set GenTextures uses glTexImage[12]D else it use gluBuild[12]dMipmaps
-- property FreeDataAfterGenTexture added (default = true)
-  if FreeDataAfterGenTexture is set the texturedata were deleted after the texture was generated.
-- parameter DisableOtherTextureUnits of Bind removed
-- parameter FreeDataAfterGeneration of GenTextures removed
-12-09-2003
-- TglBitmap dosn't delete data if class was destroyed (fixed)
-09-09-2003
-- Bind now enables TextureUnits (by params)
-- GenTextures can leave data (by param)
-- LoadTextures now optimal
-03-09-2003
-- Performance optimization in AddFunc
-- procedure Bind moved to subclasses
-- Added new Class TglBitmap1D to support real OpenGL 1D Textures
-19-08-2003
-- Texturefilter and texturewrap now also as defaults
-  Minfilter = GL_LINEAR_MIPMAP_LINEAR
-  Magfilter = GL_LINEAR
-  Wrap(str) = GL_CLAMP_TO_EDGE
-- Added new format tfCompressed to create a compressed texture.
-- propertys IsCompressed, TextureSize and IsResident added
-  IsCompressed and TextureSize only contains data from level 0
-18-08-2003
-- Added function AddFunc to add PerPixelEffects to Image
-- LoadFromFunc now based on AddFunc
-- Invert now based on AddFunc
-- SwapColors now based on AddFunc
-16-08-2003
-- Added function FlipHorz
-15-08-2003
-- Added function LaodFromFunc to create images with function
-- Added function FlipVert
-- Added internal format RGB(A) if GL_EXT_bgra or OpenGL 1.2 isn't supported
-29-07-2003
-- Added Alphafunctions to calculate alpha per function
-- Added Alpha from ColorKey using alphafunctions
-28-07-2003
-- First full functionally Version of glBitmap
-- Support for 24Bit and 32Bit TGA Pictures added
-25-07-2003
-- begin of programming
-***********************************************************}
+{ glBitmap by Steffen Xonna aka Lossy eX (2003-2008)
+  http://www.opengl24.de/index.php?cat=header&file=glbitmap
+
+  modified by Delphi OpenGL Community (http://delphigl.com/) (2013)
+
+  The contents of this file are used with permission, subject to
+  the Mozilla Public License Version 1.1 (the "License"); you may
+  not use this file except in compliance with the License. You may
+  obtain a copy of the License at
+  http://www.mozilla.org/MPL/MPL-1.1.html
+
+  The glBitmap is a Delphi/FPC unit that contains several wrapper classes
+  to manage OpenGL texture objects. Below you can find a list of the main
+  functionality of this classes:
+  - load texture data from file (e.g. BMP, TGA, DDS, PNG, JPEG, ...)
+  - load texture data from several other image objects (e.g. TBitmap, TLazIntfImage, SDL Surface)
+  - save texture data to file (e.g. BMP, TGA, DDS, PNG, JPEG, ...)
+  - save texture data to several other image objects (e.g. TBitmap, TLazIntfImage, SDL Surface)
+  - support for many texture formats (e.g. RGB8, BGR8, RGBA8, BGRA8, ...)
+  - manage texture properties (e.g. Filter, Clamp, Mipmap, ...)
+  - upload texture data to video card
+  - download texture data from video card
+  - manipulate texture data (e.g. add alpha, remove alpha, convert to other format, switch RGB, ...) }
+
 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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// activate to enable build-in OpenGL support with statically linked methods
-// use dglOpenGL.pas if not enabled
-{.$DEFINE GLB_NATIVE_OGL_STATIC}
+// enable support for OpenGL ES 1.1
+{.$DEFINE OPENGL_ES_1_1}
+
+// enable support for OpenGL ES 2.0
+{.$DEFINE OPENGL_ES_2_0}
+
+// enable support for OpenGL ES 3.0
+{.$DEFINE OPENGL_ES_3_0}
+
+// enable support for all OpenGL ES extensions
+{.$DEFINE OPENGL_ES_EXT}
 
-// 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
@@ -302,10 +112,11 @@ unit glBitmap;
   {$DEFINE GLB_LINUX}
 {$IFEND}
 
-// native OpenGL Support
-{$IF DEFINED(GLB_NATIVE_OGL_STATIC) OR DEFINED(GLB_NATIVE_OGL_DYNAMIC)}
-  {$DEFINE GLB_NATIVE_OGL}
-{$IFEND}
+// OpenGL ES
+{$IF DEFINED(OPENGL_ES_EXT)} {$DEFINE OPENGL_ES_1_1} {$IFEND}
+{$IF DEFINED(OPENGL_ES_3_0)} {$DEFINE OPENGL_ES_2_0} {$IFEND}
+{$IF DEFINED(OPENGL_ES_2_0)} {$DEFINE OPENGL_ES_1_1} {$IFEND}
+{$IF DEFINED(OPENGL_ES_1_1)} {$DEFINE OPENGL_ES}     {$IFEND}
 
 // checking define combinations
 //SDL Image
@@ -425,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}
@@ -441,10 +247,11 @@ unit glBitmap;
 interface
 
 uses
-  {$IFNDEF GLB_NATIVE_OGL}      dglOpenGL,                          {$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}
@@ -458,416 +265,113 @@ 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;
+{$IFNDEF fpc}
+  QWord   = System.UInt64;
+  PQWord  = ^QWord;
 
-  gluBuild1DMipmaps: TgluBuild1DMipmaps;
-  gluBuild2DMipmaps: TgluBuild2DMipmaps;
-{$ENDIF}
+  PtrInt  = Longint;
+  PtrUInt = DWord;
 {$ENDIF}
 
-type
-////////////////////////////////////////////////////////////////////////////////////////////////////
-// the name of formats is composed of the following constituents:
-// - multiple chanals:
-//    - channel                          (e.g. R, G, B, A or Alpha, Luminance or X (reserved)
-//    - width of the chanel in bit       (4, 8, 16, ...)
-// - data type                           (e.g. ub, us, ui)
-// - number of data types
-
 
+  { type that describes the format of the data stored in a texture.
+    the name of formats is composed of the following constituents:
+    - multiple channels:
+       - channel                          (e.g. R, G, B, A or Alpha, Luminance or X (reserved))
+       - width of the chanel in bit       (4, 8, 16, ...)
+    - data type                           (e.g. ub, us, ui)
+    - number of elements of data types }
   TglBitmapFormat = (
-    tfEmpty = 0,                //must be smallest value!
-
-    tfAlpha4ub1,                // 1 x unsigned byte
-    tfAlpha8ub1,                // 1 x unsigned byte
-    tfAlpha16us1,               // 1 x unsigned short
-
-    tfLuminance4ub1,            // 1 x unsigned byte
-    tfLuminance8ub1,            // 1 x unsigned byte
-    tfLuminance16us1,           // 1 x unsigned short
-
-    tfLuminance4Alpha4ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
-    tfLuminance6Alpha2ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
-    tfLuminance8Alpha8ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
-    tfLuminance12Alpha4us2,     // 1 x unsigned short (lum), 1 x unsigned short (alpha)
-    tfLuminance16Alpha16us2,    // 1 x unsigned short (lum), 1 x unsigned short (alpha)
-
-    tfR3G3B2ub1,                // 1 x unsigned byte (3bit red, 3bit green, 2bit blue)
-    tfRGBX4us1,                 // 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit reserverd)
-    tfXRGB4us1,                 // 1 x unsigned short (4bit reserved, 4bit red, 4bit green, 4bit blue)
-    tfR5G6B5us1,                // 1 x unsigned short (5bit red, 6bit green, 5bit blue)
-    tfRGB5X1us1,                // 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit reserved)
-    tfX1RGB5us1,                // 1 x unsigned short (1bit reserved, 5bit red, 5bit green, 5bit blue)
-    tfRGB8ub3,                  // 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue)
-    tfRGBX8ui1,                 // 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8bit reserved)
-    tfXRGB8ui1,                 // 1 x unsigned int (8bit reserved, 8bit red, 8bit green, 8bit blue)
-    tfRGB10X2ui1,               // 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit reserved)
-    tfX2RGB10ui1,               // 1 x unsigned int (2bit reserved, 10bit red, 10bit green, 10bit blue)
-    tfRGB16us3,                 // 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue)
-
-    tfRGBA4us1,                 // 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit alpha)
-    tfARGB4us1,                 // 1 x unsigned short (4bit alpha, 4bit red, 4bit green, 4bit blue)
-    tfRGB5A1us1,                // 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit alpha)
-    tfA1RGB5us1,                // 1 x unsigned short (1bit alpha, 5bit red, 5bit green, 5bit blue)
-    tfRGBA8ui1,                 // 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8 bit alpha)
-    tfARGB8ui1,                 // 1 x unsigned int (8 bit alpha, 8bit red, 8bit green, 8bit blue)
-    tfRGBA8ub4,                 // 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue), 1 x unsigned byte (alpha)
-    tfRGB10A2ui1,               // 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit alpha)
-    tfA2RGB10ui1,               // 1 x unsigned int (2bit alpha, 10bit red, 10bit green, 10bit blue)
-    tfRGBA16us4,                // 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue), 1 x unsigned short (alpha)
-
-    tfBGRX4us1,                 // 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit reserved)
-    tfXBGR4us1,                 // 1 x unsigned short (4bit reserved, 4bit blue, 4bit green, 4bit red)
-    tfB5G6R5us1,                // 1 x unsigned short (5bit blue, 6bit green, 5bit red)
-    tfBGR5X1us1,                // 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit reserved)
-    tfX1BGR5us1,                // 1 x unsigned short (1bit reserved, 5bit blue, 5bit green, 5bit red)
-    tfBGR8ub3,                  // 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red)
-    tfBGRX8ui1,                 // 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit reserved)
-    tfXBGR8ui1,                 // 1 x unsigned int (8bit reserved, 8bit blue, 8bit green, 8bit red)
-    tfBGR10X2ui1,               // 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit reserved)
-    tfX2BGR10ui1,               // 1 x unsigned int (2bit reserved, 10bit blue, 10bit green, 10bit red)
-    tfBGR16us3,                 // 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red)
-
-    tfBGRA4us1,                 // 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit alpha)
-    tfABGR4us1,                 // 1 x unsigned short (4bit alpha, 4bit blue, 4bit green, 4bit red)
-    tfBGR5A1us1,                // 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit alpha)
-    tfA1BGR5us1,                // 1 x unsigned short (1bit alpha, 5bit blue, 5bit green, 5bit red)
-    tfBGRA8ui1,                 // 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit alpha)
-    tfABGR8ui1,                 // 1 x unsigned int (8bit alpha, 8bit blue, 8bit green, 8bit red)
-    tfBGRA8ub4,                 // 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red), 1 x unsigned byte (alpha)
-    tfBGR10A2ui1,               // 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit alpha)
-    tfA2BGR10ui1,               // 1 x unsigned int (2bit alpha, 10bit blue, 10bit green, 10bit red)
-    tfBGRA16us4,                // 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red), 1 x unsigned short (alpha)
-
-    tfDepth16us1,               // 1 x unsigned short (depth)
-    tfDepth24ui1,               // 1 x unsigned int (depth)
-    tfDepth32ui1,               // 1 x unsigned int (depth)
+    tfEmpty = 0,
+
+    tfAlpha4ub1,                //< 1 x unsigned byte
+    tfAlpha8ub1,                //< 1 x unsigned byte
+    tfAlpha16us1,               //< 1 x unsigned short
+
+    tfLuminance4ub1,            //< 1 x unsigned byte
+    tfLuminance8ub1,            //< 1 x unsigned byte
+    tfLuminance16us1,           //< 1 x unsigned short
+
+    tfLuminance4Alpha4ub2,      //< 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance6Alpha2ub2,      //< 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance8Alpha8ub2,      //< 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance12Alpha4us2,     //< 1 x unsigned short (lum), 1 x unsigned short (alpha)
+    tfLuminance16Alpha16us2,    //< 1 x unsigned short (lum), 1 x unsigned short (alpha)
+
+    tfR3G3B2ub1,                //< 1 x unsigned byte (3bit red, 3bit green, 2bit blue)
+    tfRGBX4us1,                 //< 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit reserverd)
+    tfXRGB4us1,                 //< 1 x unsigned short (4bit reserved, 4bit red, 4bit green, 4bit blue)
+    tfR5G6B5us1,                //< 1 x unsigned short (5bit red, 6bit green, 5bit blue)
+    tfRGB5X1us1,                //< 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit reserved)
+    tfX1RGB5us1,                //< 1 x unsigned short (1bit reserved, 5bit red, 5bit green, 5bit blue)
+    tfRGB8ub3,                  //< 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue)
+    tfRGBX8ui1,                 //< 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8bit reserved)
+    tfXRGB8ui1,                 //< 1 x unsigned int (8bit reserved, 8bit red, 8bit green, 8bit blue)
+    tfRGB10X2ui1,               //< 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit reserved)
+    tfX2RGB10ui1,               //< 1 x unsigned int (2bit reserved, 10bit red, 10bit green, 10bit blue)
+    tfRGB16us3,                 //< 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue)
+
+    tfRGBA4us1,                 //< 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit alpha)
+    tfARGB4us1,                 //< 1 x unsigned short (4bit alpha, 4bit red, 4bit green, 4bit blue)
+    tfRGB5A1us1,                //< 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit alpha)
+    tfA1RGB5us1,                //< 1 x unsigned short (1bit alpha, 5bit red, 5bit green, 5bit blue)
+    tfRGBA8ui1,                 //< 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8 bit alpha)
+    tfARGB8ui1,                 //< 1 x unsigned int (8 bit alpha, 8bit red, 8bit green, 8bit blue)
+    tfRGBA8ub4,                 //< 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue), 1 x unsigned byte (alpha)
+    tfRGB10A2ui1,               //< 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit alpha)
+    tfA2RGB10ui1,               //< 1 x unsigned int (2bit alpha, 10bit red, 10bit green, 10bit blue)
+    tfRGBA16us4,                //< 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue), 1 x unsigned short (alpha)
+
+    tfBGRX4us1,                 //< 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit reserved)
+    tfXBGR4us1,                 //< 1 x unsigned short (4bit reserved, 4bit blue, 4bit green, 4bit red)
+    tfB5G6R5us1,                //< 1 x unsigned short (5bit blue, 6bit green, 5bit red)
+    tfBGR5X1us1,                //< 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit reserved)
+    tfX1BGR5us1,                //< 1 x unsigned short (1bit reserved, 5bit blue, 5bit green, 5bit red)
+    tfBGR8ub3,                  //< 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red)
+    tfBGRX8ui1,                 //< 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit reserved)
+    tfXBGR8ui1,                 //< 1 x unsigned int (8bit reserved, 8bit blue, 8bit green, 8bit red)
+    tfBGR10X2ui1,               //< 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit reserved)
+    tfX2BGR10ui1,               //< 1 x unsigned int (2bit reserved, 10bit blue, 10bit green, 10bit red)
+    tfBGR16us3,                 //< 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red)
+
+    tfBGRA4us1,                 //< 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit alpha)
+    tfABGR4us1,                 //< 1 x unsigned short (4bit alpha, 4bit blue, 4bit green, 4bit red)
+    tfBGR5A1us1,                //< 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit alpha)
+    tfA1BGR5us1,                //< 1 x unsigned short (1bit alpha, 5bit blue, 5bit green, 5bit red)
+    tfBGRA8ui1,                 //< 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit alpha)
+    tfABGR8ui1,                 //< 1 x unsigned int (8bit alpha, 8bit blue, 8bit green, 8bit red)
+    tfBGRA8ub4,                 //< 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red), 1 x unsigned byte (alpha)
+    tfBGR10A2ui1,               //< 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit alpha)
+    tfA2BGR10ui1,               //< 1 x unsigned int (2bit alpha, 10bit blue, 10bit green, 10bit red)
+    tfBGRA16us4,                //< 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red), 1 x unsigned short (alpha)
+
+    tfDepth16us1,               //< 1 x unsigned short (depth)
+    tfDepth24ui1,               //< 1 x unsigned int (depth)
+    tfDepth32ui1,               //< 1 x unsigned int (depth)
 
     tfS3tcDtx1RGBA,
     tfS3tcDtx3RGBA,
     tfS3tcDtx5RGBA
   );
 
+  { type to define suitable file formats }
   TglBitmapFileType = (
-     {$IFDEF GLB_SUPPORT_PNG_WRITE} ftPNG,  {$ENDIF}
-     {$IFDEF GLB_SUPPORT_JPEG_WRITE}ftJPEG, {$ENDIF}
-     ftDDS,
-     ftTGA,
-     ftBMP,
-     ftRAW);
+     {$IFDEF GLB_SUPPORT_PNG_WRITE} ftPNG,  {$ENDIF}    //< Portable Network Graphic file (PNG)
+     {$IFDEF GLB_SUPPORT_JPEG_WRITE}ftJPEG, {$ENDIF}    //< JPEG file
+     ftDDS,                                             //< Direct Draw Surface file (DDS)
+     ftTGA,                                             //< Targa Image File (TGA)
+     ftBMP,                                             //< Windows Bitmap File (BMP)
+     ftRAW);                                            //< glBitmap RAW file format
    TglBitmapFileTypes = set of TglBitmapFileType;
 
-   TglBitmapMipMap = (
-     mmNone,
-     mmMipmap,
-     mmMipmapGlu);
+  { possible mipmap types }
+  TglBitmapMipMap = (
+     mmNone,                //< no mipmaps
+     mmMipmap,              //< normal mipmaps
+     mmMipmapGlu);          //< mipmaps generated with glu functions
 
+  { possible normal map functions }
    TglBitmapNormalMapFunc = (
      nm4Samples,
      nmSobel,
@@ -875,406 +379,874 @@ type
      nm5x5);
 
  ////////////////////////////////////////////////////////////////////////////////////////////////////
-   EglBitmap                  = class(Exception);
-   EglBitmapNotSupported      = class(Exception);
-   EglBitmapSizeToLarge       = class(EglBitmap);
-   EglBitmapNonPowerOfTwo     = class(EglBitmap);
-   EglBitmapUnsupportedFormat = class(EglBitmap)
+   EglBitmap                  = class(Exception);   //< glBitmap exception
+   EglBitmapNotSupported      = class(Exception);   //< exception for not supported functions
+   EglBitmapSizeToLarge       = class(EglBitmap);   //< exception for to large textures
+   EglBitmapNonPowerOfTwo     = class(EglBitmap);   //< exception for non power of two textures
+   EglBitmapUnsupportedFormat = class(EglBitmap)    //< exception for unsupporetd formats
    public
      constructor Create(const aFormat: TglBitmapFormat); overload;
      constructor Create(const aMsg: String; const aFormat: TglBitmapFormat); overload;
    end;
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
+  { record that stores 4 unsigned integer values }
   TglBitmapRec4ui = packed record
   case Integer of
     0: (r, g, b, a: Cardinal);
     1: (arr: array[0..3] of Cardinal);
   end;
 
+  { record that stores 4 unsigned byte values }
   TglBitmapRec4ub = packed record
   case Integer of
     0: (r, g, b, a: Byte);
     1: (arr: array[0..3] of Byte);
   end;
 
+  { record that stores 4 unsigned long integer values }
   TglBitmapRec4ul = packed record
   case Integer of
     0: (r, g, b, a: QWord);
     1: (arr: array[0..3] of QWord);
   end;
 
+  { describes the properties of a given texture data format }
   TglBitmapFormatDescriptor = class(TObject)
-  strict private
+  private
     // cached properties
-    fBytesPerPixel: Single;
-    fChannelCount: Integer;
-    fMask: TglBitmapRec4ul;
-    fRange: TglBitmapRec4ui;
+    fBytesPerPixel: Single;   //< number of bytes for each pixel
+    fChannelCount: Integer;   //< number of color channels
+    fMask: TglBitmapRec4ul;   //< bitmask for each color channel
+    fRange: TglBitmapRec4ui;  //< maximal value of each color channel
 
+    { @return @true if the format has a red color channel, @false otherwise }
     function GetHasRed: Boolean;
+
+    { @return @true if the format has a green color channel, @false otherwise }
     function GetHasGreen: Boolean;
+
+    { @return @true if the format has a blue color channel, @false otherwise }
     function GetHasBlue: Boolean;
+
+    { @return @true if the format has a alpha color channel, @false otherwise }
     function GetHasAlpha: Boolean;
+
+    { @return @true if the format has any color color channel, @false otherwise }
     function GetHasColor: Boolean;
+
+    { @return @true if the format is a grayscale format, @false otherwise }
     function GetIsGrayscale: Boolean;
   protected
-    fFormat:        TglBitmapFormat;
-    fWithAlpha:     TglBitmapFormat;
-    fWithoutAlpha:  TglBitmapFormat;
-    fOpenGLFormat:  TglBitmapFormat;
-    fRGBInverted:   TglBitmapFormat;
-    fUncompressed:  TglBitmapFormat;
+    fFormat:        TglBitmapFormat;  //< format this descriptor belongs to
+    fWithAlpha:     TglBitmapFormat;  //< suitable format with alpha channel
+    fWithoutAlpha:  TglBitmapFormat;  //< suitable format without alpha channel
+    fOpenGLFormat:  TglBitmapFormat;  //< suitable format that is supported by OpenGL
+    fRGBInverted:   TglBitmapFormat;  //< suitable format with inverted RGB channels
+    fUncompressed:  TglBitmapFormat;  //< suitable format with uncompressed data
 
-    fBitsPerPixel: Integer;
-    fIsCompressed: Boolean;
+    fBitsPerPixel: Integer;           //< number of bits per pixel
+    fIsCompressed: Boolean;           //< @true if the format is compressed, @false otherwise
 
-    fPrecision: TglBitmapRec4ub;
-    fShift:     TglBitmapRec4ub;
+    fPrecision: TglBitmapRec4ub;      //< number of bits for each color channel
+    fShift:     TglBitmapRec4ub;      //< bit offset for each color channel
 
-    fglFormat:         GLenum;
-    fglInternalFormat: GLenum;
-    fglDataFormat:     GLenum;
+    fglFormat:         GLenum;        //< OpenGL format enum (e.g. GL_RGB)
+    fglInternalFormat: GLenum;        //< OpenGL internal format enum (e.g. GL_RGB8)
+    fglDataFormat:     GLenum;        //< OpenGL data format enum (e.g. GL_UNSIGNED_BYTE)
 
+    { set values for this format descriptor }
     procedure SetValues; virtual;
+
+    { calculate cached values }
     procedure CalcValues;
   public
-    property Format:        TglBitmapFormat read fFormat;
-    property ChannelCount:  Integer         read fChannelCount;
-    property IsCompressed:  Boolean         read fIsCompressed;
-    property BitsPerPixel:  Integer         read fBitsPerPixel;
-    property BytesPerPixel: Single          read fBytesPerPixel;
-
-    property Precision: TglBitmapRec4ub read fPrecision;
-    property Shift:     TglBitmapRec4ub read fShift;
-    property Range:     TglBitmapRec4ui read fRange;
-    property Mask:      TglBitmapRec4ul read fMask;
-
-    property RGBInverted:  TglBitmapFormat read fRGBInverted;
-    property WithAlpha:    TglBitmapFormat read fWithAlpha;
-    property WithoutAlpha: TglBitmapFormat read fWithAlpha;
-    property OpenGLFormat: TglBitmapFormat read fOpenGLFormat;
-    property Uncompressed: TglBitmapFormat read fUncompressed;
-
-    property glFormat:         GLenum  read fglFormat;
-    property glInternalFormat: GLenum  read fglInternalFormat;
-    property glDataFormat:     GLenum  read fglDataFormat;
-
-    property HasRed:       Boolean read GetHasRed;
-    property HasGreen:     Boolean read GetHasGreen;
-    property HasBlue:      Boolean read GetHasBlue;
-    property HasAlpha:     Boolean read GetHasAlpha;
-    property HasColor:     Boolean read GetHasColor;
-    property IsGrayscale:  Boolean read GetIsGrayscale;
-
+    property Format:        TglBitmapFormat read fFormat;         //< format this descriptor belongs to
+    property ChannelCount:  Integer         read fChannelCount;   //< number of color channels
+    property IsCompressed:  Boolean         read fIsCompressed;   //< @true if the format is compressed, @false otherwise
+    property BitsPerPixel:  Integer         read fBitsPerPixel;   //< number of bytes per pixel
+    property BytesPerPixel: Single          read fBytesPerPixel;  //< number of bits per pixel
+
+    property Precision: TglBitmapRec4ub read fPrecision;  //< number of bits for each color channel
+    property Shift:     TglBitmapRec4ub read fShift;      //< bit offset for each color channel
+    property Range:     TglBitmapRec4ui read fRange;      //< maximal value of each color channel
+    property Mask:      TglBitmapRec4ul read fMask;       //< bitmask for each color channel
+
+    property RGBInverted:  TglBitmapFormat read fRGBInverted;  //< suitable format with inverted RGB channels
+    property WithAlpha:    TglBitmapFormat read fWithAlpha;    //< suitable format with alpha channel
+    property WithoutAlpha: TglBitmapFormat read fWithAlpha;    //< suitable format without alpha channel
+    property OpenGLFormat: TglBitmapFormat read fOpenGLFormat; //< suitable format that is supported by OpenGL
+    property Uncompressed: TglBitmapFormat read fUncompressed; //< suitable format with uncompressed data
+
+    property glFormat:         GLenum  read fglFormat;         //< OpenGL format enum (e.g. GL_RGB)
+    property glInternalFormat: GLenum  read fglInternalFormat; //< OpenGL internal format enum (e.g. GL_RGB8)
+    property glDataFormat:     GLenum  read fglDataFormat;     //< OpenGL data format enum (e.g. GL_UNSIGNED_BYTE)
+
+    property HasRed:       Boolean read GetHasRed;        //< @true if the format has a red color channel, @false otherwise
+    property HasGreen:     Boolean read GetHasGreen;      //< @true if the format has a green color channel, @false otherwise
+    property HasBlue:      Boolean read GetHasBlue;       //< @true if the format has a blue color channel, @false otherwise
+    property HasAlpha:     Boolean read GetHasAlpha;      //< @true if the format has a alpha color channel, @false otherwise
+    property HasColor:     Boolean read GetHasColor;      //< @true if the format has any color color channel, @false otherwise
+    property IsGrayscale:  Boolean read GetIsGrayscale;   //< @true if the format is a grayscale format, @false otherwise
+
+    { constructor }
     constructor Create;
   public
+    { get the format descriptor by a given OpenGL internal format
+        @param aInternalFormat  OpenGL internal format to get format descriptor for
+        @returns                suitable format descriptor or tfEmpty-Descriptor }
     class function GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor;
   end;
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
+  { structure to store pixel data in }
   TglBitmapPixelData = packed record
-    Data:   TglBitmapRec4ui;
-    Range:  TglBitmapRec4ui;
-    Format: TglBitmapFormat;
+    Data:   TglBitmapRec4ui;  //< color data for each color channel
+    Range:  TglBitmapRec4ui;  //< maximal color value for each channel
+    Format: TglBitmapFormat;  //< format of the pixel
   end;
   PglBitmapPixelData = ^TglBitmapPixelData;
 
-  TglBitmapPixelPositionFields = set of (ffX, ffY);
-  TglBitmapPixelPosition = record
-    Fields : TglBitmapPixelPositionFields;
-    X : Word;
-    Y : Word;
+  TglBitmapSizeFields = set of (ffX, ffY);
+  TglBitmapSize = packed record
+    Fields: TglBitmapSizeFields;
+    X: Word;
+    Y: Word;
   end;
+  TglBitmapPixelPosition = TglBitmapSize;
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
   TglBitmap = class;
+
+  { structure to store data for converting in }
   TglBitmapFunctionRec = record
-    Sender:   TglBitmap;
-    Size:     TglBitmapPixelPosition;
-    Position: TglBitmapPixelPosition;
-    Source:   TglBitmapPixelData;
-    Dest:     TglBitmapPixelData;
-    Args:     Pointer;
+    Sender:   TglBitmap;              //< texture object that stores the data to convert
+    Size:     TglBitmapSize;          //< size of the texture
+    Position: TglBitmapPixelPosition; //< position of the currently pixel
+    Source:   TglBitmapPixelData;     //< pixel data of the current pixel
+    Dest:     TglBitmapPixelData;     //< new data of the pixel (must be filled in)
+    Args:     Pointer;                //< user defined args that was passed to the convert function
   end;
+
+  { callback to use for converting texture data }
   TglBitmapFunction = procedure(var FuncRec: TglBitmapFunctionRec);
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+  { base class for all glBitmap classes. used to manage OpenGL texture objects
+    and to load, save and manipulate texture data }
   TglBitmap = class
   private
+    { @returns format descriptor that describes the format of the stored data }
     function GetFormatDesc: TglBitmapFormatDescriptor;
   protected
-    fID: GLuint;
-    fTarget: GLuint;
-    fAnisotropic: Integer;
-    fDeleteTextureOnFree: Boolean;
-    fFreeDataOnDestroy: Boolean;
-    fFreeDataAfterGenTexture: Boolean;
-    fData: PByte;
-    fIsResident: GLboolean;
-    fBorderColor: array[0..3] of Single;
-
-    fDimension: TglBitmapPixelPosition;
-    fMipMap: TglBitmapMipMap;
-    fFormat: TglBitmapFormat;
+    fID: GLuint;                          //< name of the OpenGL texture object
+    fTarget: GLuint;                      //< texture target (e.g. GL_TEXTURE_2D)
+    fAnisotropic: Integer;                //< anisotropic level
+    fDeleteTextureOnFree: Boolean;        //< delete OpenGL texture object when this object is destroyed
+    fFreeDataOnDestroy: Boolean;          //< free stored data when this object is destroyed
+    fFreeDataAfterGenTexture: Boolean;    //< free stored data after data was uploaded to video card
+    fData: PByte;                         //< data of this texture
+{$IFNDEF OPENGL_ES}
+    fIsResident: GLboolean;               //< @true if OpenGL texture object has data, @false otherwise
+{$ENDIF}
+    fBorderColor: array[0..3] of Single;  //< color of the texture border
+
+    fDimension: TglBitmapSize;            //< size of this texture
+    fMipMap: TglBitmapMipMap;             //< mipmap type
+    fFormat: TglBitmapFormat;             //< format the texture data is stored in
 
     // Mapping
-    fPixelSize: Integer;
-    fRowSize: Integer;
+    fPixelSize: Integer;                  //< size of one pixel (in byte)
+    fRowSize: Integer;                    //< size of one pixel row (in byte)
 
     // Filtering
-    fFilterMin: GLenum;
-    fFilterMag: GLenum;
+    fFilterMin: GLenum;                   //< min filter to apply to the texture
+    fFilterMag: GLenum;                   //< mag filter to apply to the texture
 
     // TexturWarp
-    fWrapS: GLenum;
-    fWrapT: GLenum;
-    fWrapR: GLenum;
+    fWrapS: GLenum;                       //< texture wrapping for x axis
+    fWrapT: GLenum;                       //< texture wrapping for y axis
+    fWrapR: GLenum;                       //< texture wrapping for z axis
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
     //Swizzle
-    fSwizzle: array[0..3] of GLenum;
+    fSwizzle: array[0..3] of GLenum;      //< color channel swizzle
+{$IFEND}
 
     // CustomData
-    fFilename: String;
-    fCustomName: String;
-    fCustomNameW: WideString;
-    fCustomData: Pointer;
+    fFilename: String;                    //< filename the texture was load from
+    fCustomName: String;                  //< user defined name
+    fCustomNameW: WideString;             //< user defined name
+    fCustomData: Pointer;                 //< user defined data
 
-    //Getter
+  protected
+    { @returns the actual width of the texture }
     function GetWidth:  Integer; virtual;
+
+    { @returns the actual height of the texture }
     function GetHeight: Integer; virtual;
 
+    { @returns the width of the texture or 1 if the width is zero }
     function GetFileWidth:  Integer; virtual;
+
+    { @returns the height of the texture or 1 if the height is zero }
     function GetFileHeight: Integer; virtual;
 
-    //Setter
+  protected
+    { set a new value for fCustomData }
     procedure SetCustomData(const aValue: Pointer);
+
+    { set a new value for fCustomName }
     procedure SetCustomName(const aValue: String);
+
+    { set a new value for fCustomNameW }
     procedure SetCustomNameW(const aValue: WideString);
+
+    { set new value for fFreeDataOnDestroy }
     procedure SetFreeDataOnDestroy(const aValue: Boolean);
+
+    { set new value for fDeleteTextureOnFree }
     procedure SetDeleteTextureOnFree(const aValue: Boolean);
+
+    { set new value for the data format. only possible if new format has the same pixel size.
+      if you want to convert the texture data, see ConvertTo function }
     procedure SetFormat(const aValue: TglBitmapFormat);
+
+    { set new value for fFreeDataAfterGenTexture }
     procedure SetFreeDataAfterGenTexture(const aValue: Boolean);
+
+    { set name of OpenGL texture object }
     procedure SetID(const aValue: Cardinal);
+
+    { set new value for fMipMap }
     procedure SetMipMap(const aValue: TglBitmapMipMap);
+
+    { set new value for target }
     procedure SetTarget(const aValue: Cardinal);
+
+    { set new value for fAnisotrophic }
     procedure SetAnisotropic(const aValue: Integer);
 
+  protected
+    { create OpenGL texture object (delete exisiting object if exists) }
     procedure CreateID;
-    procedure SetupParameters(out aBuildWithGlu: Boolean);
+
+    { setup texture parameters }
+    procedure SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF});
+
+    { set data pointer of texture data
+        @param aData    pointer to new texture data (be carefull, aData could be freed by this function)
+        @param aFormat  format of the data stored at aData
+        @param aWidth   width of the texture data
+        @param aHeight  height of the texture data }
     procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat;
-      const aWidth: Integer = -1; const aHeight: Integer = -1); virtual;  //be careful, aData could be freed by this method
+      const aWidth: Integer = -1; const aHeight: Integer = -1); virtual;
+
+    { generate texture (upload texture data to video card)
+        @param aTestTextureSize   test texture size before uploading and raise exception if something is wrong }
     procedure GenTexture(const aTestTextureSize: Boolean = true); virtual; abstract;
 
+    { flip texture horizontal
+        @returns @true in success, @false otherwise }
     function FlipHorz: Boolean; virtual;
+
+    { flip texture vertical
+        @returns @true in success, @false otherwise }
     function FlipVert: Boolean; virtual;
 
-    property Width:  Integer read GetWidth;
-    property Height: Integer read GetHeight;
+  protected
+    property Width:  Integer read GetWidth;             //< the actual width of the texture
+    property Height: Integer read GetHeight;            //< the actual height of the texture
 
-    property FileWidth:  Integer read GetFileWidth;
-    property FileHeight: Integer read GetFileHeight;
+    property FileWidth:  Integer read GetFileWidth;     //< the width of the texture or 1 if the width is zero
+    property FileHeight: Integer read GetFileHeight;    //< the height of the texture or 1 if the height is zero
   public
-    //Properties
-    property ID:           Cardinal        read fID          write SetID;
-    property Target:       Cardinal        read fTarget      write SetTarget;
-    property Format:       TglBitmapFormat read fFormat      write SetFormat;
-    property MipMap:       TglBitmapMipMap read fMipMap      write SetMipMap;
-    property Anisotropic:  Integer         read fAnisotropic write SetAnisotropic;
-
-    property FormatDesc:   TglBitmapFormatDescriptor read GetFormatDesc;
-
-    property Filename:    String     read fFilename;
-    property CustomName:  String     read fCustomName  write SetCustomName;
-    property CustomNameW: WideString read fCustomNameW write SetCustomNameW;
-    property CustomData:  Pointer    read fCustomData  write SetCustomData;
-
-    property DeleteTextureOnFree:     Boolean read fDeleteTextureOnFree     write SetDeleteTextureOnFree;
-    property FreeDataOnDestroy:       Boolean read fFreeDataOnDestroy       write SetFreeDataOnDestroy;
-    property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture;
-
-    property Dimension:  TglBitmapPixelPosition  read fDimension;
-    property Data:       PByte                   read fData;
-    property IsResident: GLboolean               read fIsResident;
+    property ID:           Cardinal        read fID          write SetID;           //< name of the OpenGL texture object
+    property Target:       Cardinal        read fTarget      write SetTarget;       //< texture target (e.g. GL_TEXTURE_2D)
+    property Format:       TglBitmapFormat read fFormat      write SetFormat;       //< format the texture data is stored in
+    property MipMap:       TglBitmapMipMap read fMipMap      write SetMipMap;       //< mipmap type
+    property Anisotropic:  Integer         read fAnisotropic write SetAnisotropic;  //< anisotropic level
+
+    property FormatDesc:   TglBitmapFormatDescriptor read GetFormatDesc;      //< format descriptor that describes the format of the stored data
+
+    property Filename:    String     read fFilename;                          //< filename the texture was load from
+    property CustomName:  String     read fCustomName  write SetCustomName;   //< user defined name (use at will)
+    property CustomNameW: WideString read fCustomNameW write SetCustomNameW;  //< user defined name (as WideString; use at will)
+    property CustomData:  Pointer    read fCustomData  write SetCustomData;   //< user defined data (use at will)
+
+    property DeleteTextureOnFree:     Boolean read fDeleteTextureOnFree     write SetDeleteTextureOnFree;     //< delete texture object when this object is destroyed
+    property FreeDataOnDestroy:       Boolean read fFreeDataOnDestroy       write SetFreeDataOnDestroy;       //< free stored data when this object is destroyed
+    property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture; //< free stored data after it is uplaoded to video card
+
+    property Dimension:  TglBitmapSize read fDimension;     //< size of the texture
+    property Data:       PByte         read fData;          //< texture data (or @nil if unset)
+{$IFNDEF OPENGL_ES}
+    property IsResident: GLboolean read fIsResident;        //< @true if OpenGL texture object has data, @false otherwise
+{$ENDIF}
 
+    { this method is called after the constructor and sets the default values of this object }
     procedure AfterConstruction; override;
+
+    { this method is called before the destructor and does some cleanup }
     procedure BeforeDestruction; override;
 
+    { splits a resource identifier into the resource and it's type
+        @param aResource  resource identifier to split and store name in
+        @param aResType   type of the resource }
     procedure PrepareResType(var aResource: String; var aResType: PChar);
 
-    //Load
+  public
+    { load a texture from a file
+        @param aFilename file to load texuture from }
     procedure LoadFromFile(const aFilename: String);
+
+    { load a texture from a stream
+        @param aStream  stream to load texture from }
     procedure LoadFromStream(const aStream: TStream); virtual;
-    procedure LoadFromFunc(const aSize: TglBitmapPixelPosition; const aFunc: TglBitmapFunction;
+
+    { use a function to generate texture data
+        @param aSize    size of the texture
+        @param aFunc    callback to use for generation
+        @param aFormat  format of the texture data
+        @param aArgs    user defined paramaters (use at will) }
+    procedure LoadFromFunc(const aSize: TglBitmapSize; const aFunc: TglBitmapFunction;
       const aFormat: TglBitmapFormat; const aArgs: Pointer = nil);
+
+    { load a texture from a resource
+        @param aInstance  resource handle
+        @param aResource  resource indentifier
+        @param aResType   resource type (if known) }
     procedure LoadFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil);
+
+    { load a texture from a resource id
+        @param aInstance  resource handle
+        @param aResource  resource ID
+        @param aResType   resource type }
     procedure LoadFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar);
 
-    //Save
-    procedure SaveToFile(const aFileName: String; const aFileType: TglBitmapFileType);
+  public
+    { save texture data to a file
+        @param aFilename  filename to store texture in
+        @param aFileType  file type to store data into }
+    procedure SaveToFile(const aFilename: String; const aFileType: TglBitmapFileType);
+
+    { save texture data to a stream
+        @param aFilename  filename to store texture in
+        @param aFileType  file type to store data into }
     procedure SaveToStream(const aStream: TStream; const aFileType: TglBitmapFileType); virtual;
 
-    //Convert
-    function AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer = nil): Boolean; overload;
-    function AddFunc(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
+  public
+    { convert texture data using a user defined callback
+        @param aFunc        callback to use for converting
+        @param aCreateTemp  create a temporary buffer to use for converting
+        @param aArgs        user defined paramters (use at will)
+        @returns            @true if converting was successful, @false otherwise }
+    function Convert(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer = nil): Boolean; overload;
+
+    { convert texture data using a user defined callback
+        @param aSource      glBitmap to read data from
+        @param aFunc        callback to use for converting
+        @param aCreateTemp  create a temporary buffer to use for converting
+        @param aFormat      format of the new data
+        @param aArgs        user defined paramters (use at will)
+        @returns            @true if converting was successful, @false otherwise }
+    function Convert(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
       const aFormat: TglBitmapFormat; const aArgs: Pointer = nil): Boolean; overload;
+
+    { convert texture data using a specific format
+        @param aFormat  new format of texture data
+        @returns        @true if converting was successful, @false otherwise }
+    function ConvertTo(const aFormat: TglBitmapFormat): Boolean; virtual;
+
+{$IFDEF GLB_SDL}
   public
-    //Alpha & Co
-    {$IFDEF GLB_SDL}
+    { assign texture data to SDL surface
+        @param aSurface SDL surface to write data to
+        @returns        @true on success, @false otherwise }
     function AssignToSurface(out aSurface: PSDL_Surface): Boolean;
+
+    { assign texture data from SDL surface
+        @param aSurface SDL surface to read data from
+        @returns        @true on success, @false otherwise }
     function AssignFromSurface(const aSurface: PSDL_Surface): Boolean;
+
+    { assign alpha channel data to SDL surface
+        @param aSurface SDL surface to write alpha channel data to
+        @returns        @true on success, @false otherwise }
     function AssignAlphaToSurface(out aSurface: PSDL_Surface): Boolean;
-    function AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil;
-      const aArgs: Pointer = nil): Boolean;
-    {$ENDIF}
 
-    {$IFDEF GLB_DELPHI}
+    { assign alpha channel data from SDL surface
+        @param aSurface SDL surface to read data from
+        @param aFunc    callback to use for converting
+        @param aArgs    user defined parameters (use at will)
+        @returns        @true on success, @false otherwise }
+    function AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+{$ENDIF}
+
+{$IFDEF GLB_DELPHI}
+  public
+    { assign texture data to TBitmap object
+        @param aBitmap  TBitmap to write data to
+        @returns        @true on success, @false otherwise }
     function AssignToBitmap(const aBitmap: TBitmap): Boolean;
+
+    { assign texture data from TBitmap object
+        @param aBitmap  TBitmap to read data from
+        @returns        @true on success, @false otherwise }
     function AssignFromBitmap(const aBitmap: TBitmap): Boolean;
+
+    { assign alpha channel data to TBitmap object
+        @param aBitmap  TBitmap to write data to
+        @returns        @true on success, @false otherwise }
     function AssignAlphaToBitmap(const aBitmap: TBitmap): Boolean;
-    function AddAlphaFromBitmap(const aBitmap: TBitmap; const aFunc: TglBitmapFunction = nil;
-      const aArgs: Pointer = nil): Boolean;
-    {$ENDIF}
 
-    {$IFDEF GLB_LAZARUS}
+    { assign alpha channel data from TBitmap object
+        @param aBitmap  TBitmap to read data from
+        @param aFunc    callback to use for converting
+        @param aArgs    user defined parameters (use at will)
+        @returns        @true on success, @false otherwise }
+    function AddAlphaFromBitmap(const aBitmap: TBitmap; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+{$ENDIF}
+
+{$IFDEF GLB_LAZARUS}
+  public
+    { assign texture data to TLazIntfImage object
+        @param aImage   TLazIntfImage to write data to
+        @returns        @true on success, @false otherwise }
     function AssignToLazIntfImage(const aImage: TLazIntfImage): Boolean;
+
+    { assign texture data from TLazIntfImage object
+        @param aImage   TLazIntfImage to read data from
+        @returns        @true on success, @false otherwise }
     function AssignFromLazIntfImage(const aImage: TLazIntfImage): Boolean;
+
+    { assign alpha channel data to TLazIntfImage object
+        @param aImage   TLazIntfImage to write data to
+        @returns        @true on success, @false otherwise }
     function AssignAlphaToLazIntfImage(const aImage: TLazIntfImage): Boolean;
-    function AddAlphaFromLazIntfImage(const aImage: TLazIntfImage; const aFunc: TglBitmapFunction = nil;
-      const aArgs: Pointer = nil): Boolean;
-    {$ENDIF}
 
-    function AddAlphaFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil;
-      const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
-    function AddAlphaFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar;
-      const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+    { assign alpha channel data from TLazIntfImage object
+        @param aImage   TLazIntfImage to read data from
+        @param aFunc    callback to use for converting
+        @param aArgs    user defined parameters (use at will)
+        @returns        @true on success, @false otherwise }
+    function AddAlphaFromLazIntfImage(const aImage: TLazIntfImage; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+{$ENDIF}
 
+  public
+    { load alpha channel data from resource
+        @param aInstance  resource handle
+        @param aResource  resource ID
+        @param aResType   resource type
+        @param aFunc      callback to use for converting
+        @param aArgs      user defined parameters (use at will)
+        @returns          @true on success, @false otherwise }
+    function AddAlphaFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+
+    { load alpha channel data from resource ID
+        @param aInstance    resource handle
+        @param aResourceID  resource ID
+        @param aResType     resource type
+        @param aFunc        callback to use for converting
+        @param aArgs        user defined parameters (use at will)
+        @returns            @true on success, @false otherwise }
+    function AddAlphaFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+
+    { add alpha channel data from function
+        @param aFunc  callback to get data from
+        @param aArgs  user defined parameters (use at will)
+        @returns      @true on success, @false otherwise }
     function AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: Pointer = nil): Boolean; virtual;
+
+    { add alpha channel data from file (macro for: new glBitmap, LoadFromFile, AddAlphaFromGlBitmap)
+        @param aFilename  file to load alpha channel data from
+        @param aFunc      callback to use for converting
+        @param aArgs      user defined parameters (use at will)
+        @returns          @true on success, @false otherwise }
     function AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+
+    { add alpha channel data from stream (macro for: new glBitmap, LoadFromStream, AddAlphaFromGlBitmap)
+        @param aStream  stream to load alpha channel data from
+        @param aFunc    callback to use for converting
+        @param aArgs    user defined parameters (use at will)
+        @returns        @true on success, @false otherwise }
     function AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
+
+    { add alpha channel data from existing glBitmap object
+        @param aBitmap  TglBitmap to copy alpha channel data from
+        @param aFunc    callback to use for converting
+        @param aArgs    user defined parameters (use at will)
+        @returns        @true on success, @false otherwise }
     function AddAlphaFromGlBitmap(const aBitmap: TglBitmap; aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
 
+    { add alpha to pixel if the pixels color is greter than the given color value
+        @param aRed         red threshold (0-255)
+        @param aGreen       green threshold (0-255)
+        @param aBlue        blue threshold (0-255)
+        @param aDeviatation accepted deviatation (0-255)
+        @returns            @true on success, @false otherwise }
     function AddAlphaFromColorKey(const aRed, aGreen, aBlue: Byte; const aDeviation: Byte = 0): Boolean;
+
+    { add alpha to pixel if the pixels color is greter than the given color value
+        @param aRed         red threshold (0-Range.r)
+        @param aGreen       green threshold (0-Range.g)
+        @param aBlue        blue threshold (0-Range.b)
+        @param aDeviatation accepted deviatation (0-max(Range.rgb))
+        @returns            @true on success, @false otherwise }
     function AddAlphaFromColorKeyRange(const aRed, aGreen, aBlue: Cardinal; const aDeviation: Cardinal = 0): Boolean;
+
+    { add alpha to pixel if the pixels color is greter than the given color value
+        @param aRed         red threshold (0.0-1.0)
+        @param aGreen       green threshold (0.0-1.0)
+        @param aBlue        blue threshold (0.0-1.0)
+        @param aDeviatation accepted deviatation (0.0-1.0)
+        @returns            @true on success, @false otherwise }
     function AddAlphaFromColorKeyFloat(const aRed, aGreen, aBlue: Single; const aDeviation: Single = 0): Boolean;
 
+    { add a constand alpha value to all pixels
+        @param aAlpha alpha value to add (0-255)
+        @returns      @true on success, @false otherwise }
     function AddAlphaFromValue(const aAlpha: Byte): Boolean;
+
+    { add a constand alpha value to all pixels
+        @param aAlpha alpha value to add (0-max(Range.rgb))
+        @returns      @true on success, @false otherwise }
     function AddAlphaFromValueRange(const aAlpha: Cardinal): Boolean;
+
+    { add a constand alpha value to all pixels
+        @param aAlpha alpha value to add (0.0-1.0)
+        @returns      @true on success, @false otherwise }
     function AddAlphaFromValueFloat(const aAlpha: Single): Boolean;
 
+    { remove alpha channel
+        @returns  @true on success, @false otherwise }
     function RemoveAlpha: Boolean; virtual;
+
   public
-    //Common
+    { create a clone of the current object
+        @returns clone of this object}
     function Clone: TglBitmap;
-    function ConvertTo(const aFormat: TglBitmapFormat): Boolean; virtual;
+
+    { invert color data (xor)
+        @param aUseRGB   xor each color channel
+        @param aUseAlpha xor alpha channel }
     procedure Invert(const aUseRGB: Boolean = true; const aUseAlpha: Boolean = false);
-    procedure SetBorderColor(const aRed, aGreen, aBlue, aAlpha: Single);
+
+    { free texture stored data }
     procedure FreeData;
 
-    //ColorFill
+{$IFNDEF OPENGL_ES}
+    { set the new value for texture border color
+        @param aRed   red color for border (0.0-1.0)
+        @param aGreen green color for border (0.0-1.0)
+        @param aBlue  blue color for border (0.0-1.0)
+        @param aAlpha alpha color for border (0.0-1.0) }
+    procedure SetBorderColor(const aRed, aGreen, aBlue, aAlpha: Single);
+{$ENDIF}
+
+  public
+    { fill complete texture with one color
+        @param aRed   red color for border (0-255)
+        @param aGreen green color for border (0-255)
+        @param aBlue  blue color for border (0-255)
+        @param aAlpha alpha color for border (0-255) }
     procedure FillWithColor(const aRed, aGreen, aBlue: Byte; const aAlpha: Byte = 255);
+
+    { fill complete texture with one color
+        @param aRed   red color for border (0-Range.r)
+        @param aGreen green color for border (0-Range.g)
+        @param aBlue  blue color for border (0-Range.b)
+        @param aAlpha alpha color for border (0-Range.a) }
     procedure FillWithColorRange(const aRed, aGreen, aBlue: Cardinal; const aAlpha: Cardinal = $FFFFFFFF);
-    procedure FillWithColorFloat(const aRed, aGreen, aBlue: Single; const aAlpha : Single = 1);
 
-    //TexParameters
+    { fill complete texture with one color
+        @param aRed   red color for border (0.0-1.0)
+        @param aGreen green color for border (0.0-1.0)
+        @param aBlue  blue color for border (0.0-1.0)
+        @param aAlpha alpha color for border (0.0-1.0) }
+    procedure FillWithColorFloat(const aRed, aGreen, aBlue: Single; const aAlpha: Single = 1.0);
+
+  public
+    { set new texture filer
+        @param aMin   min filter
+        @param aMag   mag filter }
     procedure SetFilter(const aMin, aMag: GLenum);
+
+    { set new texture wrapping
+        @param S  texture wrapping for x axis
+        @param T  texture wrapping for y axis
+        @param R  texture wrapping for z axis }
     procedure SetWrap(
       const S: GLenum = GL_CLAMP_TO_EDGE;
       const T: GLenum = GL_CLAMP_TO_EDGE;
       const R: GLenum = GL_CLAMP_TO_EDGE);
+
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+    { set new swizzle
+        @param r  swizzle for red channel
+        @param g  swizzle for green channel
+        @param b  swizzle for blue channel
+        @param a  swizzle for alpha channel }
     procedure SetSwizzle(const r, g, b, a: GLenum);
+{$IFEND}
 
+  public
+    { bind texture
+        @param aEnableTextureUnit   enable texture unit for this texture (e.g. glEnable(GL_TEXTURE_2D)) }
     procedure Bind(const aEnableTextureUnit: Boolean = true); virtual;
+
+    { bind texture
+        @param aDisableTextureUnit  disable texture unit for this texture (e.g. glEnable(GL_TEXTURE_2D)) }
     procedure Unbind(const aDisableTextureUnit: Boolean = true); virtual;
 
-    //Constructors
+  public
+    { constructor - created an empty texture }
     constructor Create; overload;
+
+    { constructor - creates a texture and load it from a file
+        @param aFilename file to load texture from }
     constructor Create(const aFileName: String); overload;
+
+    { constructor - creates a texture and load it from a stream
+        @param aStream stream to load texture from }
     constructor Create(const aStream: TStream); overload;
-    constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; aData: PByte = nil); overload;
-    constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;
+
+    { constructor - creates a texture with the given size, format and data
+        @param aSize    size of the texture
+        @param aFormat  format of the given data
+        @param aData    texture data - be carefull: the data will now be managed by the glBitmap object,
+                        you can control this by setting DeleteTextureOnFree, FreeDataOnDestroy and FreeDataAfterGenTexture }
+    constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; aData: PByte = nil); overload;
+
+    { constructor - creates a texture with the given size and format and uses the given callback to create the data
+        @param aSize    size of the texture
+        @param aFormat  format of the given data
+        @param aFunc    callback to use for generating the data
+        @param aArgs    user defined parameters (use at will) }
+    constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;
+
+    { constructor - creates a texture and loads it from a resource
+        @param aInstance  resource handle
+        @param aResource  resource indentifier
+        @param aResType   resource type (if known) }
     constructor Create(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil); overload;
+
+    { constructor - creates a texture and loads it from a resource
+        @param aInstance    resource handle
+        @param aResourceID  resource ID
+        @param aResType     resource type (if known) }
     constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload;
+
   private
-    {$IFDEF GLB_SUPPORT_PNG_READ}  function  LoadPNG(const aStream: TStream): Boolean; virtual; {$ENDIF}
-    {$ifdef GLB_SUPPORT_PNG_WRITE} procedure SavePNG(const aStream: TStream); virtual; {$ENDIF}
+{$IFDEF GLB_SUPPORT_PNG_READ}
+    { try to load a PNG from a stream
+        @param aStream  stream to load PNG from
+        @returns        @true on success, @false otherwise }
+    function  LoadPNG(const aStream: TStream): Boolean; virtual;
+{$ENDIF}
 
-    {$IFDEF GLB_SUPPORT_JPEG_READ}  function  LoadJPEG(const aStream: TStream): Boolean; virtual; {$ENDIF}
-    {$IFDEF GLB_SUPPORT_JPEG_WRITE} procedure SaveJPEG(const aStream: TStream); virtual; {$ENDIF}
+{$ifdef GLB_SUPPORT_PNG_WRITE}
+    { save texture data as PNG to stream
+        @param aStream stream to save data to}
+    procedure SavePNG(const aStream: TStream); virtual;
+{$ENDIF}
+
+{$IFDEF GLB_SUPPORT_JPEG_READ}
+    { try to load a JPEG from a stream
+        @param aStream  stream to load JPEG from
+        @returns        @true on success, @false otherwise }
+    function  LoadJPEG(const aStream: TStream): Boolean; virtual;
+{$ENDIF}
+
+{$IFDEF GLB_SUPPORT_JPEG_WRITE}
+    { save texture data as JPEG to stream
+        @param aStream stream to save data to}
+    procedure SaveJPEG(const aStream: TStream); virtual;
+{$ENDIF}
 
+    { try to load a RAW image from a stream
+        @param aStream  stream to load RAW image from
+        @returns        @true on success, @false otherwise }
     function LoadRAW(const aStream: TStream): Boolean;
+
+    { save texture data as RAW image to stream
+        @param aStream stream to save data to}
     procedure SaveRAW(const aStream: TStream);
 
+    { try to load a BMP from a stream
+        @param aStream  stream to load BMP from
+        @returns        @true on success, @false otherwise }
     function LoadBMP(const aStream: TStream): Boolean;
+
+    { save texture data as BMP to stream
+        @param aStream stream to save data to}
     procedure SaveBMP(const aStream: TStream);
 
+    { try to load a TGA from a stream
+        @param aStream  stream to load TGA from
+        @returns        @true on success, @false otherwise }
     function LoadTGA(const aStream: TStream): Boolean;
+
+    { save texture data as TGA to stream
+        @param aStream stream to save data to}
     procedure SaveTGA(const aStream: TStream);
 
+    { try to load a DDS from a stream
+        @param aStream  stream to load DDS from
+        @returns        @true on success, @false otherwise }
     function LoadDDS(const aStream: TStream): Boolean;
+
+    { save texture data as DDS to stream
+        @param aStream stream to save data to}
     procedure SaveDDS(const aStream: TStream);
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+{$IF NOT DEFINED(OPENGL_ES)}
+  { wrapper class for 1-dimensional textures (OpenGL target = GL_TEXTURE_1D }
   TglBitmap1D = class(TglBitmap)
   protected
-    procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat;
-      const aWidth: Integer = - 1; const aHeight: Integer = - 1); override;
+    { set data pointer of texture data
+        @param aData    pointer to new texture data (be carefull, aData could be freed by this function)
+        @param aFormat  format of the data stored at aData
+        @param aWidth   width of the texture data
+        @param aHeight  height of the texture data }
+    procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat; const aWidth: Integer = - 1; const aHeight: Integer = - 1); override;
+
+    { upload the texture data to video card
+        @param aBuildWithGlu  use glu functions to build mipmaps }
     procedure UploadData(const aBuildWithGlu: Boolean);
   public
-    property Width;
+    property Width; //< actual with of the texture
+
+    { this method is called after constructor and initializes the object }
     procedure AfterConstruction; override;
+
+    { flip texture horizontally
+        @returns @true on success, @fals otherwise }
     function FlipHorz: Boolean; override;
+
+    { generate texture (create texture object if not exist, set texture parameters and upload data
+        @param aTestTextureSize   check the size of the texture and throw exception if something is wrong }
     procedure GenTexture(const aTestTextureSize: Boolean = true); override;
   end;
+{$IFEND}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+  { wrapper class for 2-dimensional textures (OpenGL target = GL_TEXTURE_2D) }
   TglBitmap2D = class(TglBitmap)
   protected
-    fLines: array of PByte;
+    fLines: array of PByte; //< array to store scanline entry points in
+
+    { get a specific scanline
+        @param aIndex   index of the scanline to return
+        @returns        scanline at position aIndex or @nil }
     function GetScanline(const aIndex: Integer): Pointer;
+
+    { set data pointer of texture data
+        @param aData    pointer to new texture data (be carefull, aData could be freed by this function)
+        @param aFormat  format of the data stored at aData
+        @param aWidth   width of the texture data
+        @param aHeight  height of the texture data }
     procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat;
       const aWidth: Integer = - 1; const aHeight: Integer = - 1); override;
-    procedure UploadData(const aTarget: GLenum; const aBuildWithGlu: Boolean);
+
+    { upload the texture data to video card
+        @param aTarget        target o upload data to (e.g. GL_TEXTURE_2D)
+        @param aBuildWithGlu  use glu functions to build mipmaps }
+    procedure UploadData(const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF});
   public
-    property Width;
-    property Height;
-    property Scanline[const aIndex: Integer]: Pointer read GetScanline;
+    property Width;                                                       //< actual width of the texture
+    property Height;                                                      //< actual height of the texture
+    property Scanline[const aIndex: Integer]: Pointer read GetScanline;   //< scanline to access texture data directly
 
+    { this method is called after constructor and initializes the object }
     procedure AfterConstruction; override;
 
+    { copy a part of the frame buffer top the texture
+        @param aTop     topmost pixel to copy
+        @param aLeft    leftmost pixel to copy
+        @param aRight   rightmost pixel to copy
+        @param aBottom  bottommost pixel to copy
+        @param aFormat  format to store data in }
     procedure GrabScreen(const aTop, aLeft, aRight, aBottom: Integer; const aFormat: TglBitmapFormat);
+
+{$IFNDEF OPENGL_ES}
+    { downlaod texture data from OpenGL texture object }
     procedure GetDataFromTexture;
+{$ENDIF}
+
+    { generate texture (create texture object if not exist, set texture parameters and upload data)
+        @param aTestTextureSize   check the size of the texture and throw exception if something is wrong }
     procedure GenTexture(const aTestTextureSize: Boolean = true); override;
 
+    { flip texture horizontally
+        @returns @true on success, @false otherwise }
     function FlipHorz: Boolean; override;
+
+    { flip texture vertically
+        @returns @true on success, @false otherwise }
     function FlipVert: Boolean; override;
 
-    procedure ToNormalMap(const aFunc: TglBitmapNormalMapFunc = nm3x3;
+    { create normal map from texture data
+        @param aFunc      normal map function to generate normalmap with
+        @param aScale     scale of the normale stored in the normal map
+        @param aUseAlpha  generate normalmap from alpha channel data (if present) }
+    procedure GenerateNormalMap(const aFunc: TglBitmapNormalMapFunc = nm3x3;
       const aScale: Single = 2; const aUseAlpha: Boolean = false);
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
+  { wrapper class for cube maps (OpenGL target = GL_TEXTURE_CUBE_MAP) }
   TglBitmapCubeMap = class(TglBitmap2D)
   protected
-    fGenMode: Integer;
+  {$IFNDEF OPENGL_ES}
+    fGenMode: Integer;  //< generation mode for the cube map (e.g. GL_REFLECTION_MAP)
+  {$ENDIF}
+
+    { generate texture (create texture object if not exist, set texture parameters and upload data
+      do not call directly for cubemaps, use GenerateCubeMap instead
+        @param aTestTextureSize   check the size of the texture and throw exception if something is wrong }
     procedure GenTexture(const aTestTextureSize: Boolean = true); reintroduce;
   public
+    { this method is called after constructor and initializes the object }
     procedure AfterConstruction; override;
+
+    { generate texture (create texture object if not exist, set texture parameters and upload data
+        @param aCubeTarget        cube map target to upload data to (e.g. GL_TEXTURE_CUBE_MAP_POSITIVE_X)
+        @param aTestTextureSize   check the size of the texture and throw exception if something is wrong }
     procedure GenerateCubeMap(const aCubeTarget: Cardinal; const aTestTextureSize: Boolean = true);
-    procedure Bind(const aEnableTexCoordsGen: Boolean = true; const aEnableTextureUnit: Boolean = true); reintroduce; virtual;
-    procedure Unbind(const aDisableTexCoordsGen: Boolean = true; const aDisableTextureUnit: Boolean = true); reintroduce; virtual;
+
+    { bind texture
+        @param aEnableTexCoordsGen  enable cube map generator
+        @param aEnableTextureUnit   enable texture unit }
+    procedure Bind({$IFNDEF OPENGL_ES}const aEnableTexCoordsGen: Boolean = true;{$ENDIF} const aEnableTextureUnit: Boolean = true); reintroduce; virtual;
+
+    { unbind texture
+        @param aDisableTexCoordsGen   disable cube map generator
+        @param aDisableTextureUnit    disable texture unit }
+    procedure Unbind({$IFNDEF OPENGL_ES}const aDisableTexCoordsGen: Boolean = true;{$ENDIF} const aDisableTextureUnit: Boolean = true); reintroduce; virtual;
   end;
+{$IFEND}
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+  { wrapper class for cube normal maps }
   TglBitmapNormalMap = class(TglBitmapCubeMap)
   public
+    { this method is called after constructor and initializes the object }
     procedure AfterConstruction; override;
+
+    { create cube normal map from texture data and upload it to video card
+        @param aSize              size of each cube map texture
+        @param aTestTextureSize   check texture size when uploading and throw exception if something is wrong  }
     procedure GenerateNormalMap(const aSize: Integer = 32; const aTestTextureSize: Boolean = true);
   end;
+{$IFEND}
 
 const
-  NULL_SIZE: TglBitmapPixelPosition = (Fields: []; X: 0; Y: 0);
+  NULL_SIZE: TglBitmapSize = (Fields: []; X: 0; Y: 0);
 
 procedure glBitmapSetDefaultDeleteTextureOnFree(const aDeleteTextureOnFree: Boolean);
 procedure glBitmapSetDefaultFreeDataAfterGenTexture(const aFreeData: Boolean);
@@ -1286,13 +1258,21 @@ procedure glBitmapSetDefaultWrap(
   const T: Cardinal = GL_CLAMP_TO_EDGE;
   const R: Cardinal = GL_CLAMP_TO_EDGE);
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+procedure glBitmapSetDefaultSwizzle(const r: GLenum = GL_RED; g: GLenum = GL_GREEN; b: GLenum = GL_BLUE; a: GLenum = GL_ALPHA);
+{$IFEND}
+
 function glBitmapGetDefaultDeleteTextureOnFree: Boolean;
 function glBitmapGetDefaultFreeDataAfterGenTexture: Boolean;
 function glBitmapGetDefaultMipmap: TglBitmapMipMap;
 function glBitmapGetDefaultFormat: TglBitmapFormat;
 procedure glBitmapGetDefaultFilter(var aMin, aMag: Cardinal);
 procedure glBitmapGetDefaultTextureWrap(var S, T, R: Cardinal);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+procedure glBitmapGetDefaultSwizzle(var r, g, b, a: GLenum);
+{$IFEND}
 
+function glBitmapSize(X: Integer = -1; Y: Integer = -1): TglBitmapSize;
 function glBitmapPosition(X: Integer = -1; Y: Integer = -1): TglBitmapPixelPosition;
 function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub;
 function glBitmapRec4ui(const r, g, b, a: Cardinal): TglBitmapRec4ui;
@@ -1302,18 +1282,6 @@ function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean;
 
 function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D;
 
-var
-  glBitmapDefaultDeleteTextureOnFree: Boolean;
-  glBitmapDefaultFreeDataAfterGenTextures: Boolean;
-  glBitmapDefaultFormat: TglBitmapFormat;
-  glBitmapDefaultMipmap: TglBitmapMipMap;
-  glBitmapDefaultFilterMin: Cardinal;
-  glBitmapDefaultFilterMag: Cardinal;
-  glBitmapDefaultWrapS: Cardinal;
-  glBitmapDefaultWrapT: Cardinal;
-  glBitmapDefaultWrapR: Cardinal;
-  glDefaultSwizzle: array[0..3] of GLenum;
-
 {$IFDEF GLB_DELPHI}
 function CreateGrayPalette: HPALETTE;
 {$ENDIF}
@@ -1324,22 +1292,27 @@ uses
   Math, syncobjs, typinfo
   {$IF DEFINED(GLB_SUPPORT_JPEG_READ) AND DEFINED(GLB_LAZ_JPEG)}, FPReadJPEG{$IFEND};
 
-type
-{$IFNDEF fpc}
-  QWord   = System.UInt64;
-  PQWord  = ^QWord;
 
-  PtrInt  = Longint;
-  PtrUInt = DWord;
-{$ENDIF}
+var
+  glBitmapDefaultDeleteTextureOnFree: Boolean;
+  glBitmapDefaultFreeDataAfterGenTextures: Boolean;
+  glBitmapDefaultFormat: TglBitmapFormat;
+  glBitmapDefaultMipmap: TglBitmapMipMap;
+  glBitmapDefaultFilterMin: Cardinal;
+  glBitmapDefaultFilterMag: Cardinal;
+  glBitmapDefaultWrapS: Cardinal;
+  glBitmapDefaultWrapT: Cardinal;
+  glBitmapDefaultWrapR: Cardinal;
+  glDefaultSwizzle: array[0..3] of GLenum;
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
+type
   TFormatDescriptor = class(TglBitmapFormatDescriptor)
   public
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); virtual; abstract;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract;
 
-    function GetSize(const aSize: TglBitmapPixelPosition): Integer; overload; virtual;
+    function GetSize(const aSize: TglBitmapSize): Integer; overload; virtual;
     function GetSize(const aWidth, aHeight: Integer): Integer; overload; virtual;
 
     function CreateMappingData: Pointer; virtual;
@@ -1724,8 +1697,8 @@ type
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   TbmpBitfieldFormat = class(TFormatDescriptor)
   public
-    procedure SetValues(const aBPP: Integer; aMask: TglBitmapRec4ul); overload;
-    procedure SetValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload;
+    procedure SetCustomValues(const aBPP: Integer; aMask: TglBitmapRec4ul); overload;
+    procedure SetCustomValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload;
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
@@ -1740,12 +1713,12 @@ type
     fBitsPerPixel: Integer;
     fColorTable: TbmpColorTable;
   protected
-    procedure SetValues; override; overload;
+    procedure SetValues; override;
   public
     property ColorTable:   TbmpColorTable  read fColorTable   write fColorTable;
     property BitsPerPixel: Integer         read fBitsPerPixel write fBitsPerPixel;
 
-    procedure SetValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload;
+    procedure SetCustomValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload;
     procedure CalcValues;
     procedure CreateColorTable;
 
@@ -1857,20 +1830,24 @@ begin
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function glBitmapPosition(X: Integer; Y: Integer): TglBitmapPixelPosition;
+function glBitmapSize(X: Integer; Y: Integer): TglBitmapSize;
 begin
   result.Fields := [];
-
-  if X >= 0 then
+  if (X >= 0) then
     result.Fields := result.Fields + [ffX];
-  if Y >= 0 then
+  if (Y >= 0) then
     result.Fields := result.Fields + [ffY];
-
   result.X := Max(0, X);
   result.Y := Max(0, Y);
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapPosition(X: Integer; Y: Integer): TglBitmapPixelPosition;
+begin
+  result := glBitmapSize(X, Y);
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub;
 begin
   result.r := r;
@@ -1935,7 +1912,7 @@ begin
   if (desc.IsCompressed) or (desc.glFormat = 0) then
     exit;
 
-  p := GetMem(ceil(25 * desc.BytesPerPixel)); // 5 x 5 pixel
+  p := GetMemory(ceil(25 * desc.BytesPerPixel)); // 5 x 5 pixel
   md := desc.CreateMappingData;
   try
     tmp := p;
@@ -2083,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 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -2390,6 +2139,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
 procedure glBitmapSetDefaultSwizzle(const r: GLenum = GL_RED; g: GLenum = GL_GREEN; b: GLenum = GL_BLUE; a: GLenum = GL_ALPHA);
 begin
   glDefaultSwizzle[0] := r;
@@ -2397,6 +2147,7 @@ begin
   glDefaultSwizzle[2] := b;
   glDefaultSwizzle[3] := a;
 end;
+{$IFEND}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function glBitmapGetDefaultDeleteTextureOnFree: Boolean;
@@ -2437,6 +2188,7 @@ begin
   R := glBitmapDefaultWrapR;
 end;
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure glBitmapGetDefaultSwizzle(var r, g, b, a: GLenum);
 begin
@@ -2445,11 +2197,12 @@ begin
   b := glDefaultSwizzle[2];
   a := glDefaultSwizzle[3];
 end;
+{$ENDIF}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TFormatDescriptor///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetSize(const aSize: TglBitmapPixelPosition): Integer;
+function TFormatDescriptor.GetSize(const aSize: TglBitmapSize): Integer;
 var
   w, h: Integer;
 begin
@@ -2937,12 +2690,16 @@ begin
   fBitsPerPixel     := 8;
   fFormat           := tfAlpha4ub1;
   fWithAlpha        := tfAlpha4ub1;
-  fOpenGLFormat     := tfAlpha4ub1;
   fPrecision        := glBitmapRec4ub(0, 0, 0, 8);
   fShift            := glBitmapRec4ub(0, 0, 0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfAlpha4ub1;
   fglFormat         := GL_ALPHA;
   fglInternalFormat := GL_ALPHA4;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfAlpha8ub1;
+{$ENDIF}
 end;
 
 procedure TfdAlpha8ub1.SetValues;
@@ -2951,11 +2708,11 @@ begin
   fBitsPerPixel     := 8;
   fFormat           := tfAlpha8ub1;
   fWithAlpha        := tfAlpha8ub1;
-  fOpenGLFormat     := tfAlpha8ub1;
   fPrecision        := glBitmapRec4ub(0, 0, 0, 8);
   fShift            := glBitmapRec4ub(0, 0, 0, 0);
+  fOpenGLFormat     := tfAlpha8ub1;
   fglFormat         := GL_ALPHA;
-  fglInternalFormat := GL_ALPHA8;
+  fglInternalFormat := {$IFNDEF OPENGL_ES}GL_ALPHA8{$ELSE}GL_ALPHA{$ENDIF};
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
@@ -2965,12 +2722,16 @@ begin
   fBitsPerPixel     := 16;
   fFormat           := tfAlpha16us1;
   fWithAlpha        := tfAlpha16us1;
-  fOpenGLFormat     := tfAlpha16us1;
   fPrecision        := glBitmapRec4ub(0, 0, 0, 16);
   fShift            := glBitmapRec4ub(0, 0, 0,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfAlpha16us1;
   fglFormat         := GL_ALPHA;
   fglInternalFormat := GL_ALPHA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfAlpha8ub1;
+{$ENDIF}
 end;
 
 procedure TfdLuminance4ub1.SetValues;
@@ -2980,12 +2741,16 @@ begin
   fFormat           := tfLuminance4ub1;
   fWithAlpha        := tfLuminance4Alpha4ub2;
   fWithoutAlpha     := tfLuminance4ub1;
-  fOpenGLFormat     := tfLuminance4ub1;
   fPrecision        := glBitmapRec4ub(8, 8, 8, 0);
   fShift            := glBitmapRec4ub(0, 0, 0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance4ub1;
   fglFormat         := GL_LUMINANCE;
   fglInternalFormat := GL_LUMINANCE4;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8ub1;
+{$ENDIF}
 end;
 
 procedure TfdLuminance8ub1.SetValues;
@@ -2999,7 +2764,7 @@ begin
   fPrecision        := glBitmapRec4ub(8, 8, 8, 0);
   fShift            := glBitmapRec4ub(0, 0, 0, 0);
   fglFormat         := GL_LUMINANCE;
-  fglInternalFormat := GL_LUMINANCE8;
+  fglInternalFormat := {$IFNDEF OPENGL_ES}GL_LUMINANCE8{$ELSE}GL_LUMINANCE{$ENDIF};
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
@@ -3010,12 +2775,16 @@ begin
   fFormat           := tfLuminance16us1;
   fWithAlpha        := tfLuminance16Alpha16us2;
   fWithoutAlpha     := tfLuminance16us1;
-  fOpenGLFormat     := tfLuminance16us1;
   fPrecision        := glBitmapRec4ub(16, 16, 16,  0);
   fShift            := glBitmapRec4ub( 0,  0,  0,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance16us1;
   fglFormat         := GL_LUMINANCE;
   fglInternalFormat := GL_LUMINANCE16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8ub1;
+{$ENDIF}
 end;
 
 procedure TfdLuminance4Alpha4ub2.SetValues;
@@ -3025,12 +2794,16 @@ begin
   fFormat           := tfLuminance4Alpha4ub2;
   fWithAlpha        := tfLuminance4Alpha4ub2;
   fWithoutAlpha     := tfLuminance4ub1;
-  fOpenGLFormat     := tfLuminance4Alpha4ub2;
   fPrecision        := glBitmapRec4ub(8, 8, 8, 8);
   fShift            := glBitmapRec4ub(0, 0, 0, 8);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance4Alpha4ub2;
   fglFormat         := GL_LUMINANCE_ALPHA;
   fglInternalFormat := GL_LUMINANCE4_ALPHA4;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8Alpha8ub2;
+{$ENDIF}
 end;
 
 procedure TfdLuminance6Alpha2ub2.SetValues;
@@ -3040,12 +2813,16 @@ begin
   fFormat           := tfLuminance6Alpha2ub2;
   fWithAlpha        := tfLuminance6Alpha2ub2;
   fWithoutAlpha     := tfLuminance8ub1;
-  fOpenGLFormat     := tfLuminance6Alpha2ub2;
   fPrecision        := glBitmapRec4ub(8, 8, 8, 8);
   fShift            := glBitmapRec4ub(0, 0, 0, 8);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance6Alpha2ub2;
   fglFormat         := GL_LUMINANCE_ALPHA;
   fglInternalFormat := GL_LUMINANCE6_ALPHA2;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8Alpha8ub2;
+{$ENDIF}
 end;
 
 procedure TfdLuminance8Alpha8ub2.SetValues;
@@ -3059,7 +2836,7 @@ begin
   fPrecision        := glBitmapRec4ub(8, 8, 8, 8);
   fShift            := glBitmapRec4ub(0, 0, 0, 8);
   fglFormat         := GL_LUMINANCE_ALPHA;
-  fglInternalFormat := GL_LUMINANCE8_ALPHA8;
+  fglInternalFormat := {$IFNDEF OPENGL_ES}GL_LUMINANCE8_ALPHA8{$ELSE}GL_LUMINANCE_ALPHA{$ENDIF};
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
@@ -3070,12 +2847,16 @@ begin
   fFormat           := tfLuminance12Alpha4us2;
   fWithAlpha        := tfLuminance12Alpha4us2;
   fWithoutAlpha     := tfLuminance16us1;
-  fOpenGLFormat     := tfLuminance12Alpha4us2;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 16);
   fShift            := glBitmapRec4ub( 0,  0,  0, 16);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance12Alpha4us2;
   fglFormat         := GL_LUMINANCE_ALPHA;
   fglInternalFormat := GL_LUMINANCE12_ALPHA4;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8Alpha8ub2;
+{$ENDIF}
 end;
 
 procedure TfdLuminance16Alpha16us2.SetValues;
@@ -3085,12 +2866,16 @@ begin
   fFormat           := tfLuminance16Alpha16us2;
   fWithAlpha        := tfLuminance16Alpha16us2;
   fWithoutAlpha     := tfLuminance16us1;
-  fOpenGLFormat     := tfLuminance16Alpha16us2;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 16);
   fShift            := glBitmapRec4ub( 0,  0,  0, 16);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfLuminance16Alpha16us2;
   fglFormat         := GL_LUMINANCE_ALPHA;
   fglInternalFormat := GL_LUMINANCE16_ALPHA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfLuminance8Alpha8ub2;
+{$ENDIF}
 end;
 
 procedure TfdR3G3B2ub1.SetValues;
@@ -3100,13 +2885,17 @@ begin
   fFormat           := tfR3G3B2ub1;
   fWithAlpha        := tfRGBA4us1;
   fWithoutAlpha     := tfR3G3B2ub1;
-  fOpenGLFormat     := tfR3G3B2ub1;
   fRGBInverted      := tfEmpty;
   fPrecision        := glBitmapRec4ub(3, 3, 2, 0);
   fShift            := glBitmapRec4ub(5, 2, 0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfR3G3B2ub1;
   fglFormat         := GL_RGB;
   fglInternalFormat := GL_R3_G3_B2;
   fglDataFormat     := GL_UNSIGNED_BYTE_3_3_2;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdRGBX4us1.SetValues;
@@ -3116,13 +2905,17 @@ begin
   fFormat           := tfRGBX4us1;
   fWithAlpha        := tfRGBA4us1;
   fWithoutAlpha     := tfRGBX4us1;
-  fOpenGLFormat     := tfRGBX4us1;
   fRGBInverted      := tfBGRX4us1;
   fPrecision        := glBitmapRec4ub( 4, 4, 4, 0);
   fShift            := glBitmapRec4ub(12, 8, 4, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGBX4us1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdXRGB4us1.SetValues;
@@ -3132,13 +2925,17 @@ begin
   fFormat           := tfXRGB4us1;
   fWithAlpha        := tfARGB4us1;
   fWithoutAlpha     := tfXRGB4us1;
-  fOpenGLFormat     := tfXRGB4us1;
   fRGBInverted      := tfXBGR4us1;
   fPrecision        := glBitmapRec4ub(4, 4, 4, 0);
   fShift            := glBitmapRec4ub(8, 4, 0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfXRGB4us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdR5G6B5us1.SetValues;
@@ -3148,13 +2945,17 @@ begin
   fFormat           := tfR5G6B5us1;
   fWithAlpha        := tfRGB5A1us1;
   fWithoutAlpha     := tfR5G6B5us1;
-  fOpenGLFormat     := tfR5G6B5us1;
   fRGBInverted      := tfB5G6R5us1;
   fPrecision        := glBitmapRec4ub( 5, 6, 5, 0);
   fShift            := glBitmapRec4ub(11, 5, 0, 0);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
+  fOpenGLFormat     := tfR5G6B5us1;
   fglFormat         := GL_RGB;
   fglInternalFormat := GL_RGB565;
   fglDataFormat     := GL_UNSIGNED_SHORT_5_6_5;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$IFEND}
 end;
 
 procedure TfdRGB5X1us1.SetValues;
@@ -3164,13 +2965,17 @@ begin
   fFormat           := tfRGB5X1us1;
   fWithAlpha        := tfRGB5A1us1;
   fWithoutAlpha     := tfRGB5X1us1;
-  fOpenGLFormat     := tfRGB5X1us1;
   fRGBInverted      := tfBGR5X1us1;
   fPrecision        := glBitmapRec4ub( 5, 5, 5, 0);
   fShift            := glBitmapRec4ub(11, 6, 1, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGB5X1us1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB5;
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdX1RGB5us1.SetValues;
@@ -3180,13 +2985,17 @@ begin
   fFormat           := tfX1RGB5us1;
   fWithAlpha        := tfA1RGB5us1;
   fWithoutAlpha     := tfX1RGB5us1;
-  fOpenGLFormat     := tfX1RGB5us1;
   fRGBInverted      := tfX1BGR5us1;
   fPrecision        := glBitmapRec4ub( 5, 5, 5, 0);
   fShift            := glBitmapRec4ub(10, 5, 0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfX1RGB5us1;
   fglFormat         := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB5;
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdRGB8ub3.SetValues;
@@ -3196,12 +3005,12 @@ begin
   fFormat           := tfRGB8ub3;
   fWithAlpha        := tfRGBA8ub4;
   fWithoutAlpha     := tfRGB8ub3;
-  fOpenGLFormat     := tfRGB8ub3;
   fRGBInverted      := tfBGR8ub3;
   fPrecision        := glBitmapRec4ub(8, 8,  8, 0);
   fShift            := glBitmapRec4ub(0, 8, 16, 0);
+  fOpenGLFormat     := tfRGB8ub3;
   fglFormat         := GL_RGB;
-  fglInternalFormat := GL_RGB8;
+  fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGB8{$ELSE}GL_RGB{$IFEND};
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
@@ -3212,13 +3021,17 @@ begin
   fFormat           := tfRGBX8ui1;
   fWithAlpha        := tfRGBA8ui1;
   fWithoutAlpha     := tfRGBX8ui1;
-  fOpenGLFormat     := tfRGB8ub3;
   fRGBInverted      := tfBGRX8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8, 0);
   fShift            := glBitmapRec4ub(24, 16,  8, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGBX8ui1;
   fglFormat         := GL_RGBA;  //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$ENDIF}
 end;
 
 procedure TfdXRGB8ui1.SetValues;
@@ -3228,13 +3041,18 @@ begin
   fFormat           := tfXRGB8ui1;
   fWithAlpha        := tfXRGB8ui1;
   fWithoutAlpha     := tfXRGB8ui1;
-  fOpenGLFormat     := tfRGB8ub3;
+  fOpenGLFormat     := tfXRGB8ui1;
   fRGBInverted      := tfXBGR8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8, 0);
   fShift            := glBitmapRec4ub(16,  8,  0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfXRGB8ui1;
   fglFormat         := GL_BGRA;  //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$ENDIF}
 end;
 
 procedure TfdRGB10X2ui1.SetValues;
@@ -3244,13 +3062,17 @@ begin
   fFormat           := tfRGB10X2ui1;
   fWithAlpha        := tfRGB10A2ui1;
   fWithoutAlpha     := tfRGB10X2ui1;
-  fOpenGLFormat     := tfRGB10X2ui1;
   fRGBInverted      := tfBGR10X2ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10, 0);
   fShift            := glBitmapRec4ub(22, 12,  2, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGB10X2ui1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB10;
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
+{$ELSE}
+  fOpenGLFormat     := tfRGB16us3;
+{$ENDIF}
 end;
 
 procedure TfdX2RGB10ui1.SetValues;
@@ -3260,13 +3082,17 @@ begin
   fFormat           := tfX2RGB10ui1;
   fWithAlpha        := tfA2RGB10ui1;
   fWithoutAlpha     := tfX2RGB10ui1;
-  fOpenGLFormat     := tfX2RGB10ui1;
   fRGBInverted      := tfX2BGR10ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10, 0);
   fShift            := glBitmapRec4ub(20, 10,  0, 0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfX2RGB10ui1;
   fglFormat         := GL_BGRA;  //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB10;
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB16us3;
+{$ENDIF}
 end;
 
 procedure TfdRGB16us3.SetValues;
@@ -3276,13 +3102,17 @@ begin
   fFormat           := tfRGB16us3;
   fWithAlpha        := tfRGBA16us4;
   fWithoutAlpha     := tfRGB16us3;
-  fOpenGLFormat     := tfRGB16us3;
   fRGBInverted      := tfBGR16us3;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 0);
   fShift            := glBitmapRec4ub( 0, 16, 32, 0);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+  fOpenGLFormat     := tfRGB16us3;
   fglFormat         := GL_RGB;
-  fglInternalFormat := GL_RGB16;
+  fglInternalFormat := {$IFNDEF OPENGL_ES}GL_RGB16{$ELSE}GL_RGB16UI{$ENDIF};
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$IFEND}
 end;
 
 procedure TfdRGBA4us1.SetValues;
@@ -3297,7 +3127,7 @@ begin
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  4);
   fShift            := glBitmapRec4ub(12,  8,  4,  0);
   fglFormat         := GL_RGBA;
-  fglInternalFormat := GL_RGBA4;
+  fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGBA8{$ELSE}GL_RGBA{$IFEND};
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
 end;
 
@@ -3308,13 +3138,17 @@ begin
   fFormat           := tfARGB4us1;
   fWithAlpha        := tfARGB4us1;
   fWithoutAlpha     := tfXRGB4us1;
-  fOpenGLFormat     := tfARGB4us1;
   fRGBInverted      := tfABGR4us1;
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  4);
   fShift            := glBitmapRec4ub( 8,  4,  0, 12);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfARGB4us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA4us1;
+{$ENDIF}
 end;
 
 procedure TfdRGB5A1us1.SetValues;
@@ -3329,7 +3163,7 @@ begin
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  1);
   fShift            := glBitmapRec4ub(11,  6,  1,  0);
   fglFormat         := GL_RGBA;
-  fglInternalFormat := GL_RGB5_A1;
+  fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}GL_RGB5_A1{$ELSE}GL_RGBA{$IFEND};
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
 end;
 
@@ -3340,13 +3174,17 @@ begin
   fFormat           := tfA1RGB5us1;
   fWithAlpha        := tfA1RGB5us1;
   fWithoutAlpha     := tfX1RGB5us1;
-  fOpenGLFormat     := tfA1RGB5us1;
   fRGBInverted      := tfA1BGR5us1;
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  1);
   fShift            := glBitmapRec4ub(10,  5,  0, 15);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfA1RGB5us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB5_A1;
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB5A1us1;
+{$ENDIF}
 end;
 
 procedure TfdRGBA8ui1.SetValues;
@@ -3356,13 +3194,17 @@ begin
   fFormat           := tfRGBA8ui1;
   fWithAlpha        := tfRGBA8ui1;
   fWithoutAlpha     := tfRGBX8ui1;
-  fOpenGLFormat     := tfRGBA8ui1;
   fRGBInverted      := tfBGRA8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub(24, 16,  8,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGBA8ui1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGBA8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4;
+{$ENDIF}
 end;
 
 procedure TfdARGB8ui1.SetValues;
@@ -3372,13 +3214,17 @@ begin
   fFormat           := tfARGB8ui1;
   fWithAlpha        := tfARGB8ui1;
   fWithoutAlpha     := tfXRGB8ui1;
-  fOpenGLFormat     := tfARGB8ui1;
   fRGBInverted      := tfABGR8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub(16,  8,  0, 24);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfARGB8ui1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4;
+{$ENDIF}
 end;
 
 procedure TfdRGBA8ub4.SetValues;
@@ -3393,7 +3239,7 @@ begin
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub( 0,  8, 16, 24);
   fglFormat         := GL_RGBA;
-  fglInternalFormat := GL_RGBA8;
+  fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGBA8{$ELSE}GL_RGBA{$IFEND};
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
@@ -3404,13 +3250,17 @@ begin
   fFormat           := tfRGB10A2ui1;
   fWithAlpha        := tfRGB10A2ui1;
   fWithoutAlpha     := tfRGB10X2ui1;
-  fOpenGLFormat     := tfRGB10A2ui1;
   fRGBInverted      := tfBGR10A2ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  2);
   fShift            := glBitmapRec4ub(22, 12,  2,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfRGB10A2ui1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGB10_A2;
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
+{$ELSE}
+  fOpenGLFormat     := tfA2RGB10ui1;
+{$ENDIF}
 end;
 
 procedure TfdA2RGB10ui1.SetValues;
@@ -3420,13 +3270,22 @@ begin
   fFormat           := tfA2RGB10ui1;
   fWithAlpha        := tfA2RGB10ui1;
   fWithoutAlpha     := tfX2RGB10ui1;
-  fOpenGLFormat     := tfA2RGB10ui1;
   fRGBInverted      := tfA2BGR10ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  2);
   fShift            := glBitmapRec4ub(20, 10,  0, 30);
+{$IF NOT DEFINED(OPENGL_ES)}
+  fOpenGLFormat     := tfA2RGB10ui1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB10_A2;
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
+{$ELSEIF DEFINED(OPENGL_ES_3_0)}
+  fOpenGLFormat     := tfA2RGB10ui1;
+  fglFormat         := GL_RGBA;
+  fglInternalFormat := GL_RGB10_A2;
+  fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ui1;
+{$IFEND}
 end;
 
 procedure TfdRGBA16us4.SetValues;
@@ -3436,13 +3295,17 @@ begin
   fFormat           := tfRGBA16us4;
   fWithAlpha        := tfRGBA16us4;
   fWithoutAlpha     := tfRGB16us3;
-  fOpenGLFormat     := tfRGBA16us4;
   fRGBInverted      := tfBGRA16us4;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 16);
   fShift            := glBitmapRec4ub( 0, 16, 32, 48);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+  fOpenGLFormat     := tfRGBA16us4;
   fglFormat         := GL_RGBA;
-  fglInternalFormat := GL_RGBA16;
+  fglInternalFormat := {$IFNDEF OPENGL_ES}GL_RGBA16{$ELSE}GL_RGBA16UI{$ENDIF};
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4;
+{$IFEND}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3455,13 +3318,17 @@ begin
   fFormat           := tfBGRX4us1;
   fWithAlpha        := tfBGRA4us1;
   fWithoutAlpha     := tfBGRX4us1;
-  fOpenGLFormat     := tfBGRX4us1;
   fRGBInverted      := tfRGBX4us1;
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  0);
   fShift            := glBitmapRec4ub( 4,  8, 12,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRX4us1;
   fglFormat         := GL_BGRA;  //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdXBGR4us1.SetValues;
@@ -3471,13 +3338,17 @@ begin
   fFormat           := tfXBGR4us1;
   fWithAlpha        := tfABGR4us1;
   fWithoutAlpha     := tfXBGR4us1;
-  fOpenGLFormat     := tfXBGR4us1;
   fRGBInverted      := tfXRGB4us1;
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  0);
   fShift            := glBitmapRec4ub( 0,  4,  8,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfXBGR4us1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdB5G6R5us1.SetValues;
@@ -3487,13 +3358,17 @@ begin
   fFormat           := tfB5G6R5us1;
   fWithAlpha        := tfBGR5A1us1;
   fWithoutAlpha     := tfB5G6R5us1;
-  fOpenGLFormat     := tfB5G6R5us1;
   fRGBInverted      := tfR5G6B5us1;
   fPrecision        := glBitmapRec4ub( 5,  6,  5,  0);
   fShift            := glBitmapRec4ub( 0,  5, 11,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfB5G6R5us1;
   fglFormat         := GL_RGB;
   fglInternalFormat := GL_RGB565;
   fglDataFormat     := GL_UNSIGNED_SHORT_5_6_5_REV;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdBGR5X1us1.SetValues;
@@ -3503,13 +3378,17 @@ begin
   fFormat           := tfBGR5X1us1;
   fWithAlpha        := tfBGR5A1us1;
   fWithoutAlpha     := tfBGR5X1us1;
-  fOpenGLFormat     := tfBGR5X1us1;
   fRGBInverted      := tfRGB5X1us1;
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  0);
   fShift            := glBitmapRec4ub( 1,  6, 11,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR5X1us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB5;
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdX1BGR5us1.SetValues;
@@ -3519,13 +3398,17 @@ begin
   fFormat           := tfX1BGR5us1;
   fWithAlpha        := tfA1BGR5us1;
   fWithoutAlpha     := tfX1BGR5us1;
-  fOpenGLFormat     := tfX1BGR5us1;
   fRGBInverted      := tfX1RGB5us1;
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  0);
   fShift            := glBitmapRec4ub( 0,  5, 10,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfX1BGR5us1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB5;
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
+{$ELSE}
+  fOpenGLFormat     := tfR5G6B5us1;
+{$ENDIF}
 end;
 
 procedure TfdBGR8ub3.SetValues;
@@ -3535,13 +3418,17 @@ begin
   fFormat           := tfBGR8ub3;
   fWithAlpha        := tfBGRA8ub4;
   fWithoutAlpha     := tfBGR8ub3;
-  fOpenGLFormat     := tfBGR8ub3;
   fRGBInverted      := tfRGB8ub3;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  0);
   fShift            := glBitmapRec4ub(16,  8,  0,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR8ub3;
   fglFormat         := GL_BGR;
   fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$ENDIF}
 end;
 
 procedure TfdBGRX8ui1.SetValues;
@@ -3551,13 +3438,17 @@ begin
   fFormat           := tfBGRX8ui1;
   fWithAlpha        := tfBGRA8ui1;
   fWithoutAlpha     := tfBGRX8ui1;
-  fOpenGLFormat     := tfBGRX8ui1;
   fRGBInverted      := tfRGBX8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  0);
   fShift            := glBitmapRec4ub( 8, 16, 24,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRX8ui1;
   fglFormat         := GL_BGRA;  //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$ENDIF}
 end;
 
 procedure TfdXBGR8ui1.SetValues;
@@ -3567,13 +3458,17 @@ begin
   fFormat           := tfXBGR8ui1;
   fWithAlpha        := tfABGR8ui1;
   fWithoutAlpha     := tfXBGR8ui1;
-  fOpenGLFormat     := tfXBGR8ui1;
   fRGBInverted      := tfXRGB8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  0);
   fShift            := glBitmapRec4ub( 0,  8, 16,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfXBGR8ui1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB8ub3;
+{$ENDIF}
 end;
 
 procedure TfdBGR10X2ui1.SetValues;
@@ -3583,13 +3478,17 @@ begin
   fFormat           := tfBGR10X2ui1;
   fWithAlpha        := tfBGR10A2ui1;
   fWithoutAlpha     := tfBGR10X2ui1;
-  fOpenGLFormat     := tfBGR10X2ui1;
   fRGBInverted      := tfRGB10X2ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  0);
   fShift            := glBitmapRec4ub( 2, 12, 22,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR10X2ui1;
   fglFormat         := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB10;
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
+{$ELSE}
+  fOpenGLFormat     := tfRGB16us3;
+{$ENDIF}
 end;
 
 procedure TfdX2BGR10ui1.SetValues;
@@ -3599,13 +3498,17 @@ begin
   fFormat           := tfX2BGR10ui1;
   fWithAlpha        := tfA2BGR10ui1;
   fWithoutAlpha     := tfX2BGR10ui1;
-  fOpenGLFormat     := tfX2BGR10ui1;
   fRGBInverted      := tfX2RGB10ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  0);
   fShift            := glBitmapRec4ub( 0, 10, 20,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfX2BGR10ui1;
   fglFormat         := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA
   fglInternalFormat := GL_RGB10;
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB16us3;
+{$ENDIF}
 end;
 
 procedure TfdBGR16us3.SetValues;
@@ -3615,13 +3518,17 @@ begin
   fFormat           := tfBGR16us3;
   fWithAlpha        := tfBGRA16us4;
   fWithoutAlpha     := tfBGR16us3;
-  fOpenGLFormat     := tfBGR16us3;
   fRGBInverted      := tfRGB16us3;
   fPrecision        := glBitmapRec4ub(16, 16, 16,  0);
   fShift            := glBitmapRec4ub(32, 16,  0,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR16us3;
   fglFormat         := GL_BGR;
   fglInternalFormat := GL_RGB16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfRGB16us3;
+{$ENDIF}
 end;
 
 procedure TfdBGRA4us1.SetValues;
@@ -3631,13 +3538,17 @@ begin
   fFormat           := tfBGRA4us1;
   fWithAlpha        := tfBGRA4us1;
   fWithoutAlpha     := tfBGRX4us1;
-  fOpenGLFormat     := tfBGRA4us1;
   fRGBInverted      := tfRGBA4us1;
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  4);
   fShift            := glBitmapRec4ub( 4,  8, 12,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRA4us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA4us1;
+{$ENDIF}
 end;
 
 procedure TfdABGR4us1.SetValues;
@@ -3647,13 +3558,17 @@ begin
   fFormat           := tfABGR4us1;
   fWithAlpha        := tfABGR4us1;
   fWithoutAlpha     := tfXBGR4us1;
-  fOpenGLFormat     := tfABGR4us1;
   fRGBInverted      := tfARGB4us1;
   fPrecision        := glBitmapRec4ub( 4,  4,  4,  4);
   fShift            := glBitmapRec4ub( 0,  4,  8, 12);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfABGR4us1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGBA4;
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA4us1;
+{$ENDIF}
 end;
 
 procedure TfdBGR5A1us1.SetValues;
@@ -3663,13 +3578,17 @@ begin
   fFormat           := tfBGR5A1us1;
   fWithAlpha        := tfBGR5A1us1;
   fWithoutAlpha     := tfBGR5X1us1;
-  fOpenGLFormat     := tfBGR5A1us1;
   fRGBInverted      := tfRGB5A1us1;
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  1);
   fShift            := glBitmapRec4ub( 1,  6, 11,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR5A1us1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB5_A1;
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
+{$ELSE}
+  fOpenGLFormat     := tfRGB5A1us1;
+{$ENDIF}
 end;
 
 procedure TfdA1BGR5us1.SetValues;
@@ -3679,13 +3598,17 @@ begin
   fFormat           := tfA1BGR5us1;
   fWithAlpha        := tfA1BGR5us1;
   fWithoutAlpha     := tfX1BGR5us1;
-  fOpenGLFormat     := tfA1BGR5us1;
   fRGBInverted      := tfA1RGB5us1;
   fPrecision        := glBitmapRec4ub( 5,  5,  5,  1);
   fShift            := glBitmapRec4ub( 0,  5, 10, 15);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfA1BGR5us1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGB5_A1;
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGB5A1us1;
+{$ENDIF}
 end;
 
 procedure TfdBGRA8ui1.SetValues;
@@ -3695,13 +3618,17 @@ begin
   fFormat           := tfBGRA8ui1;
   fWithAlpha        := tfBGRA8ui1;
   fWithoutAlpha     := tfBGRX8ui1;
-  fOpenGLFormat     := tfBGRA8ui1;
   fRGBInverted      := tfRGBA8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub( 8, 16, 24,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRA8ui1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4;
+{$ENDIF}
 end;
 
 procedure TfdABGR8ui1.SetValues;
@@ -3711,13 +3638,17 @@ begin
   fFormat           := tfABGR8ui1;
   fWithAlpha        := tfABGR8ui1;
   fWithoutAlpha     := tfXBGR8ui1;
-  fOpenGLFormat     := tfABGR8ui1;
   fRGBInverted      := tfARGB8ui1;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub( 0,  8, 16, 24);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfABGR8ui1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGBA8;
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4
+{$ENDIF}
 end;
 
 procedure TfdBGRA8ub4.SetValues;
@@ -3727,13 +3658,17 @@ begin
   fFormat           := tfBGRA8ub4;
   fWithAlpha        := tfBGRA8ub4;
   fWithoutAlpha     := tfBGR8ub3;
-  fOpenGLFormat     := tfBGRA8ub4;
   fRGBInverted      := tfRGBA8ub4;
   fPrecision        := glBitmapRec4ub( 8,  8,  8,  8);
   fShift            := glBitmapRec4ub(16,  8,  0, 24);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRA8ub4;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA8;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA8ub4;
+{$ENDIF}
 end;
 
 procedure TfdBGR10A2ui1.SetValues;
@@ -3743,13 +3678,17 @@ begin
   fFormat           := tfBGR10A2ui1;
   fWithAlpha        := tfBGR10A2ui1;
   fWithoutAlpha     := tfBGR10X2ui1;
-  fOpenGLFormat     := tfBGR10A2ui1;
   fRGBInverted      := tfRGB10A2ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  2);
   fShift            := glBitmapRec4ub( 2, 12, 22,  0);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGR10A2ui1;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGB10_A2;
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
+{$ELSE}
+  fOpenGLFormat     := tfA2RGB10ui1;
+{$ENDIF}
 end;
 
 procedure TfdA2BGR10ui1.SetValues;
@@ -3759,13 +3698,17 @@ begin
   fFormat           := tfA2BGR10ui1;
   fWithAlpha        := tfA2BGR10ui1;
   fWithoutAlpha     := tfX2BGR10ui1;
-  fOpenGLFormat     := tfA2BGR10ui1;
   fRGBInverted      := tfA2RGB10ui1;
   fPrecision        := glBitmapRec4ub(10, 10, 10,  2);
   fShift            := glBitmapRec4ub( 0, 10, 20, 30);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfA2BGR10ui1;
   fglFormat         := GL_RGBA;
   fglInternalFormat := GL_RGB10_A2;
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
+{$ELSE}
+  fOpenGLFormat     := tfA2RGB10ui1;
+{$ENDIF}
 end;
 
 procedure TfdBGRA16us4.SetValues;
@@ -3775,13 +3718,17 @@ begin
   fFormat           := tfBGRA16us4;
   fWithAlpha        := tfBGRA16us4;
   fWithoutAlpha     := tfBGR16us3;
-  fOpenGLFormat     := tfBGRA16us4;
   fRGBInverted      := tfRGBA16us4;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 16);
   fShift            := glBitmapRec4ub(32, 16,  0, 48);
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfBGRA16us4;
   fglFormat         := GL_BGRA;
   fglInternalFormat := GL_RGBA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$ELSE}
+  fOpenGLFormat     := tfRGBA16us4;
+{$ENDIF}
 end;
 
 procedure TfdDepth16us1.SetValues;
@@ -3790,12 +3737,14 @@ begin
   fBitsPerPixel     := 16;
   fFormat           := tfDepth16us1;
   fWithoutAlpha     := tfDepth16us1;
-  fOpenGLFormat     := tfDepth16us1;
   fPrecision        := glBitmapRec4ub(16, 16, 16, 16);
   fShift            := glBitmapRec4ub( 0,  0,  0,  0);
+{$IF NOT DEFINED (OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
+  fOpenGLFormat     := tfDepth16us1;
   fglFormat         := GL_DEPTH_COMPONENT;
   fglInternalFormat := GL_DEPTH_COMPONENT16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
+{$IFEND}
 end;
 
 procedure TfdDepth24ui1.SetValues;
@@ -3807,9 +3756,12 @@ begin
   fOpenGLFormat     := tfDepth24ui1;
   fPrecision        := glBitmapRec4ub(32, 32, 32, 32);
   fShift            := glBitmapRec4ub( 0,  0,  0,  0);
+{$IF NOT DEFINED (OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+  fOpenGLFormat     := tfDepth24ui1;
   fglFormat         := GL_DEPTH_COMPONENT;
   fglInternalFormat := GL_DEPTH_COMPONENT24;
   fglDataFormat     := GL_UNSIGNED_INT;
+{$IFEND}
 end;
 
 procedure TfdDepth32ui1.SetValues;
@@ -3818,12 +3770,18 @@ begin
   fBitsPerPixel     := 32;
   fFormat           := tfDepth32ui1;
   fWithoutAlpha     := tfDepth32ui1;
-  fOpenGLFormat     := tfDepth32ui1;
   fPrecision        := glBitmapRec4ub(32, 32, 32, 32);
   fShift            := glBitmapRec4ub( 0,  0,  0,  0);
+{$IF NOT DEFINED(OPENGL_ES)}
+  fOpenGLFormat     := tfDepth32ui1;
   fglFormat         := GL_DEPTH_COMPONENT;
   fglInternalFormat := GL_DEPTH_COMPONENT32;
   fglDataFormat     := GL_UNSIGNED_INT;
+{$ELSEIF DEFINED(OPENGL_ES_3_0)}
+  fOpenGLFormat     := tfDepth24ui1;
+{$ELSEIF DEFINED(OPENGL_ES_2_0)}
+  fOpenGLFormat     := tfDepth16us1;
+{$IFEND}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3844,13 +3802,17 @@ begin
   inherited SetValues;
   fFormat           := tfS3tcDtx1RGBA;
   fWithAlpha        := tfS3tcDtx1RGBA;
-  fOpenGLFormat     := tfS3tcDtx1RGBA;
   fUncompressed     := tfRGB5A1us1;
   fBitsPerPixel     := 4;
   fIsCompressed     := true;
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfS3tcDtx1RGBA;
   fglFormat         := GL_COMPRESSED_RGBA;
   fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := fUncompressed;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3871,13 +3833,17 @@ begin
   inherited SetValues;
   fFormat           := tfS3tcDtx3RGBA;
   fWithAlpha        := tfS3tcDtx3RGBA;
-  fOpenGLFormat     := tfS3tcDtx3RGBA;
   fUncompressed     := tfRGBA8ub4;
   fBitsPerPixel     := 8;
   fIsCompressed     := true;
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfS3tcDtx3RGBA;
   fglFormat         := GL_COMPRESSED_RGBA;
   fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := fUncompressed;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3898,13 +3864,17 @@ begin
   inherited SetValues;
   fFormat           := tfS3tcDtx3RGBA;
   fWithAlpha        := tfS3tcDtx3RGBA;
-  fOpenGLFormat     := tfS3tcDtx3RGBA;
   fUncompressed     := tfRGBA8ub4;
   fBitsPerPixel     := 8;
   fIsCompressed     := true;
+{$IFNDEF OPENGL_ES}
+  fOpenGLFormat     := tfS3tcDtx3RGBA;
   fglFormat         := GL_COMPRESSED_RGBA;
   fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
   fglDataFormat     := GL_UNSIGNED_BYTE;
+{$ELSE}
+  fOpenGLFormat     := fUncompressed;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4104,7 +4074,7 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TBitfieldFormat/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetValues(const aBPP: Integer; aMask: TglBitmapRec4ul);
+procedure TbmpBitfieldFormat.SetCustomValues(const aBPP: Integer; aMask: TglBitmapRec4ul);
 var
   i: Integer;
 begin
@@ -4120,7 +4090,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub);
+procedure TbmpBitfieldFormat.SetCustomValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub);
 begin
   fBitsPerPixel := aBBP;
   fPrecision    := aPrec;
@@ -4178,7 +4148,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpColorTableFormat.SetValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub);
+procedure TbmpColorTableFormat.SetCustomValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub);
 begin
   fFormat       := aFormat;
   fBitsPerPixel := aBPP;
@@ -4536,11 +4506,14 @@ end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.SetAnisotropic(const aValue: Integer);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_EXT)}
 var
   MaxAnisotropic: Integer;
+{$IFEND}
 begin
   fAnisotropic := aValue;
   if (ID > 0) then begin
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_EXT)}
     if GL_EXT_texture_filter_anisotropic then begin
       if fAnisotropic > 0 then begin
         Bind(false);
@@ -4552,6 +4525,9 @@ begin
     end else begin
       fAnisotropic := 0;
     end;
+{$ELSE}
+    fAnisotropic := 0;
+{$IFEND}
   end;
 end;
 
@@ -4565,17 +4541,20 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SetupParameters(out aBuildWithGlu: Boolean);
+procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF});
 begin
   // Set Up Parameters
   SetWrap(fWrapS, fWrapT, fWrapR);
   SetFilter(fFilterMin, fFilterMag);
   SetAnisotropic(fAnisotropic);
-  SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]);
 
+{$IFNDEF OPENGL_ES}
+  SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]);
   if (GL_ARB_texture_swizzle or GL_EXT_texture_swizzle or GL_VERSION_3_3) then
     SetSwizzle(fSwizzle[0], fSwizzle[1], fSwizzle[2], fSwizzle[3]);
+{$ENDIF}
 
+{$IFNDEF OPENGL_ES}
   // Mip Maps Generation Mode
   aBuildWithGlu := false;
   if (MipMap = mmMipmap) then begin
@@ -4585,6 +4564,10 @@ begin
       aBuildWithGlu := true;
   end else if (MipMap = mmMipmapGlu) then
     aBuildWithGlu := true;
+{$ELSE}
+  if (MipMap = mmMipmap) then
+    glTexParameteri(Target, GL_GENERATE_MIPMAP, GL_TRUE);
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4642,7 +4625,9 @@ begin
 
   fID         := 0;
   fTarget     := 0;
+{$IFNDEF OPENGL_ES}
   fIsResident := false;
+{$ENDIF}
 
   fMipMap                  := glBitmapDefaultMipmap;
   fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture;
@@ -4650,7 +4635,9 @@ begin
 
   glBitmapGetDefaultFilter     (fFilterMin, fFilterMag);
   glBitmapGetDefaultTextureWrap(fWrapS, fWrapT, fWrapR);
+{$IFNDEF OPENGL_ES}
   glBitmapGetDefaultSwizzle    (fSwizzle[0], fSwizzle[1], fSwizzle[2], fSwizzle[3]);
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4713,7 +4700,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.LoadFromFunc(const aSize: TglBitmapPixelPosition; const aFunc: TglBitmapFunction;
+procedure TglBitmap.LoadFromFunc(const aSize: TglBitmapSize; const aFunc: TglBitmapFunction;
   const aFormat: TglBitmapFormat; const aArgs: Pointer);
 var
   tmpData: PByte;
@@ -4729,7 +4716,7 @@ begin
       FreeMem(tmpData);
     raise;
   end;
-  AddFunc(Self, aFunc, false, aFormat, aArgs);
+  Convert(Self, aFunc, false, aFormat, aArgs);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -4760,7 +4747,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SaveToFile(const aFileName: String; const aFileType: TglBitmapFileType);
+procedure TglBitmap.SaveToFile(const aFilename: String; const aFileType: TglBitmapFileType);
 var
   fs: TFileStream;
 begin
@@ -4791,13 +4778,13 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer): Boolean;
+function TglBitmap.Convert(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer): Boolean;
 begin
-  result := AddFunc(Self, aFunc, aCreateTemp, Format, aArgs);
+  result := Convert(Self, aFunc, aCreateTemp, Format, aArgs);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddFunc(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
+function TglBitmap.Convert(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
   const aFormat: TglBitmapFormat; const aArgs: Pointer): Boolean;
 var
   DestData, TmpData, SourceData: pByte;
@@ -4882,6 +4869,73 @@ begin
   end;
 end;
 
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.ConvertTo(const aFormat: TglBitmapFormat): Boolean;
+var
+  SourceFD, DestFD: TFormatDescriptor;
+  SourcePD, DestPD: TglBitmapPixelData;
+  ShiftData: TShiftData;
+
+  function DataIsIdentical: Boolean;
+  begin
+    result := SourceFD.MaskMatch(DestFD.Mask);
+  end;
+
+  function CanCopyDirect: Boolean;
+  begin
+    result :=
+      ((SourcePD.Range.r = DestPD.Range.r) or (SourcePD.Range.r = 0) or (DestPD.Range.r = 0)) and
+      ((SourcePD.Range.g = DestPD.Range.g) or (SourcePD.Range.g = 0) or (DestPD.Range.g = 0)) and
+      ((SourcePD.Range.b = DestPD.Range.b) or (SourcePD.Range.b = 0) or (DestPD.Range.b = 0)) and
+      ((SourcePD.Range.a = DestPD.Range.a) or (SourcePD.Range.a = 0) or (DestPD.Range.a = 0));
+  end;
+
+  function CanShift: Boolean;
+  begin
+    result :=
+      ((SourcePD.Range.r >= DestPD.Range.r) or (SourcePD.Range.r = 0) or (DestPD.Range.r = 0)) and
+      ((SourcePD.Range.g >= DestPD.Range.g) or (SourcePD.Range.g = 0) or (DestPD.Range.g = 0)) and
+      ((SourcePD.Range.b >= DestPD.Range.b) or (SourcePD.Range.b = 0) or (DestPD.Range.b = 0)) and
+      ((SourcePD.Range.a >= DestPD.Range.a) or (SourcePD.Range.a = 0) or (DestPD.Range.a = 0));
+  end;
+
+  function GetShift(aSource, aDest: Cardinal) : ShortInt;
+  begin
+    result := 0;
+    while (aSource > aDest) and (aSource > 0) do begin
+      inc(result);
+      aSource := aSource shr 1;
+    end;
+  end;
+
+begin
+  if (aFormat <> fFormat) and (aFormat <> tfEmpty) then begin
+    SourceFD := TFormatDescriptor.Get(Format);
+    DestFD   := TFormatDescriptor.Get(aFormat);
+
+    if DataIsIdentical then begin
+      result := true;
+      Format := aFormat;
+      exit;
+    end;
+
+    SourceFD.PreparePixel(SourcePD);
+    DestFD.PreparePixel  (DestPD);
+
+    if CanCopyDirect then
+      result := Convert(Self, glBitmapConvertCopyFunc, false, aFormat)
+    else if CanShift then begin
+      ShiftData.r := GetShift(SourcePD.Range.r, DestPD.Range.r);
+      ShiftData.g := GetShift(SourcePD.Range.g, DestPD.Range.g);
+      ShiftData.b := GetShift(SourcePD.Range.b, DestPD.Range.b);
+      ShiftData.a := GetShift(SourcePD.Range.a, DestPD.Range.a);
+      result := Convert(Self, glBitmapConvertShiftRGBAFunc, false, aFormat, @ShiftData);
+    end else
+      result := Convert(Self, glBitmapConvertCalculateRGBAFunc, false, aFormat);
+  end else
+    result := true;
+end;
+
 {$IFDEF GLB_SDL}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function TglBitmap.AssignToSurface(out aSurface: PSDL_Surface): Boolean;
@@ -5294,7 +5348,7 @@ var
       Shift.g := GreenShift;
       Shift.b := BlueShift;
       Shift.a := AlphaShift;
-      bfFormat.SetValues(BitsPerPixel, Prec, Shift);
+      bfFormat.SetCustomValues(BitsPerPixel, Prec, Shift);
     end;
     pSourceMD := bfFormat.CreateMappingData;
     pDestMD   := FormatDesc.CreateMappingData;
@@ -5479,7 +5533,7 @@ function TglBitmap.AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs:
 begin
   if TFormatDescriptor.Get(Format).IsCompressed then
     raise EglBitmapUnsupportedFormat.Create(Format);
-  result := AddFunc(Self, aFunc, false, TFormatDescriptor.Get(Format).WithAlpha, aArgs);
+  result := Convert(Self, aFunc, false, TFormatDescriptor.Get(Format).WithAlpha, aArgs);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5714,82 +5768,25 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.ConvertTo(const aFormat: TglBitmapFormat): Boolean;
-var
-  SourceFD, DestFD: TFormatDescriptor;
-  SourcePD, DestPD: TglBitmapPixelData;
-  ShiftData: TShiftData;
-
-  function DataIsIdentical: Boolean;
-  begin
-    result := SourceFD.MaskMatch(DestFD.Mask);
-  end;
-
-  function CanCopyDirect: Boolean;
-  begin
-    result :=
-      ((SourcePD.Range.r = DestPD.Range.r) or (SourcePD.Range.r = 0) or (DestPD.Range.r = 0)) and
-      ((SourcePD.Range.g = DestPD.Range.g) or (SourcePD.Range.g = 0) or (DestPD.Range.g = 0)) and
-      ((SourcePD.Range.b = DestPD.Range.b) or (SourcePD.Range.b = 0) or (DestPD.Range.b = 0)) and
-      ((SourcePD.Range.a = DestPD.Range.a) or (SourcePD.Range.a = 0) or (DestPD.Range.a = 0));
-  end;
-
-  function CanShift: Boolean;
-  begin
-    result :=
-      ((SourcePD.Range.r >= DestPD.Range.r) or (SourcePD.Range.r = 0) or (DestPD.Range.r = 0)) and
-      ((SourcePD.Range.g >= DestPD.Range.g) or (SourcePD.Range.g = 0) or (DestPD.Range.g = 0)) and
-      ((SourcePD.Range.b >= DestPD.Range.b) or (SourcePD.Range.b = 0) or (DestPD.Range.b = 0)) and
-      ((SourcePD.Range.a >= DestPD.Range.a) or (SourcePD.Range.a = 0) or (DestPD.Range.a = 0));
-  end;
-
-  function GetShift(aSource, aDest: Cardinal) : ShortInt;
-  begin
-    result := 0;
-    while (aSource > aDest) and (aSource > 0) do begin
-      inc(result);
-      aSource := aSource shr 1;
-    end;
-  end;
-
-begin
-  if (aFormat <> fFormat) and (aFormat <> tfEmpty) then begin
-    SourceFD := TFormatDescriptor.Get(Format);
-    DestFD   := TFormatDescriptor.Get(aFormat);
-
-    if DataIsIdentical then begin
-      result := true;
-      Format := aFormat;
-      exit;
-    end;
-
-    SourceFD.PreparePixel(SourcePD);
-    DestFD.PreparePixel  (DestPD);
-
-    if CanCopyDirect then
-      result := AddFunc(Self, glBitmapConvertCopyFunc, false, aFormat)
-    else if CanShift then begin
-      ShiftData.r := GetShift(SourcePD.Range.r, DestPD.Range.r);
-      ShiftData.g := GetShift(SourcePD.Range.g, DestPD.Range.g);
-      ShiftData.b := GetShift(SourcePD.Range.b, DestPD.Range.b);
-      ShiftData.a := GetShift(SourcePD.Range.a, DestPD.Range.a);
-      result := AddFunc(Self, glBitmapConvertShiftRGBAFunc, false, aFormat, @ShiftData);
-    end else
-      result := AddFunc(Self, glBitmapConvertCalculateRGBAFunc, false, aFormat);
-  end else
-    result := true;
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.Invert(const aUseRGB: Boolean; const aUseAlpha: Boolean);
 begin
   if aUseRGB or aUseAlpha then
-    AddFunc(glBitmapInvertFunc, false, {%H-}Pointer(
+    Convert(glBitmapInvertFunc, false, {%H-}Pointer(
       ((Byte(aUseAlpha) and 1) shl 1) or
        (Byte(aUseRGB)   and 1)      ));
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.FreeData;
+var
+  TempPtr: PByte;
+begin
+  TempPtr := nil;
+  SetDataPointer(TempPtr, tfEmpty); //be careful, Data could be freed by this method
+end;
+
+{$IFNDEF OPENGL_ES}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.SetBorderColor(const aRed, aGreen, aBlue, aAlpha: Single);
 begin
   fBorderColor[0] := aRed;
@@ -5801,15 +5798,7 @@ begin
     glTexParameterfv(Target, GL_TEXTURE_BORDER_COLOR, @fBorderColor[0]);
   end;
 end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.FreeData;
-var
-  TempPtr: PByte;
-begin
-  TempPtr := nil;
-  SetDataPointer(TempPtr, tfEmpty); //be careful, Data could be freed by this method
-end;
+{$ENDIF}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.FillWithColor(const aRed, aGreen, aBlue: Byte;
@@ -5843,7 +5832,7 @@ begin
     Data.b := Max(0, Min(Range.b, Trunc(Range.b * aBlue)));
     Data.a := Max(0, Min(Range.a, Trunc(Range.a * aAlpha)));
   end;
-  AddFunc(glBitmapFillWithColorFunc, false, @PixelData);
+  Convert(glBitmapFillWithColorFunc, false, @PixelData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5882,7 +5871,7 @@ begin
     Bind(false);
     glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, fFilterMag);
 
-    if (MipMap = mmNone) or (Target = GL_TEXTURE_RECTANGLE) then begin
+    if (MipMap = mmNone) {$IFNDEF OPENGL_ES}or (Target = GL_TEXTURE_RECTANGLE){$ENDIF} then begin
       case fFilterMin of
         GL_NEAREST, GL_LINEAR:
           glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, fFilterMin);
@@ -5902,32 +5891,44 @@ procedure TglBitmap.SetWrap(const S: GLenum; const T: GLenum; const R: GLenum);
   procedure CheckAndSetWrap(const aValue: Cardinal; var aTarget: Cardinal);
   begin
     case aValue of
+{$IFNDEF OPENGL_ES}
       GL_CLAMP:
         aTarget := GL_CLAMP;
+{$ENDIF}
 
       GL_REPEAT:
         aTarget := GL_REPEAT;
 
       GL_CLAMP_TO_EDGE: begin
-        if GL_VERSION_1_2 or GL_EXT_texture_edge_clamp then
-          aTarget := GL_CLAMP_TO_EDGE
+{$IFNDEF OPENGL_ES}
+        if not GL_VERSION_1_2 and not GL_EXT_texture_edge_clamp then
+          aTarget := GL_CLAMP
         else
-          aTarget := GL_CLAMP;
+{$ENDIF}
+          aTarget := GL_CLAMP_TO_EDGE;
       end;
 
+{$IFNDEF OPENGL_ES}
       GL_CLAMP_TO_BORDER: begin
         if GL_VERSION_1_3 or GL_ARB_texture_border_clamp then
           aTarget := GL_CLAMP_TO_BORDER
         else
           aTarget := GL_CLAMP;
       end;
+{$ENDIF}
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
       GL_MIRRORED_REPEAT: begin
+  {$IFNDEF OPENGL_ES}
         if GL_VERSION_1_4 or GL_ARB_texture_mirrored_repeat or GL_IBM_texture_mirrored_repeat then
+  {$ELSE}
+        if GL_VERSION_2_0 then
+  {$ENDIF}
           aTarget := GL_MIRRORED_REPEAT
         else
           raise EglBitmap.Create('SetWrap - Unsupported Texturewrap GL_MIRRORED_REPEAT (S).');
       end;
+{$IFEND}
     else
       raise EglBitmap.Create('SetWrap - Unknow Texturewrap');
     end;
@@ -5942,10 +5943,14 @@ begin
     Bind(false);
     glTexParameteri(Target, GL_TEXTURE_WRAP_S, fWrapS);
     glTexParameteri(Target, GL_TEXTURE_WRAP_T, fWrapT);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
+    {$IFDEF OPENGL_ES} if GL_VERSION_3_0 then{$ENDIF}
     glTexParameteri(Target, GL_TEXTURE_WRAP_R, fWrapR);
+{$IFEND}
   end;
 end;
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.SetSwizzle(const r, g, b, a: GLenum);
 
@@ -5959,8 +5964,13 @@ procedure TglBitmap.SetSwizzle(const r, g, b, a: GLenum);
   end;
 
 begin
+{$IFNDEF OPENGL_ES}
   if not (GL_ARB_texture_swizzle or GL_EXT_texture_swizzle or GL_VERSION_3_3) then
     raise EglBitmapNotSupported.Create('texture swizzle is not supported');
+{$ELSE}
+  if not GL_VERSION_3_0 then
+    raise EglBitmapNotSupported.Create('texture swizzle is not supported');
+{$ENDIF}
   CheckAndSetValue(r, 0);
   CheckAndSetValue(g, 1);
   CheckAndSetValue(b, 2);
@@ -5968,9 +5978,17 @@ begin
 
   if (ID > 0) then begin
     Bind(false);
+{$IFNDEF OPENGL_ES}
     glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_RGBA, PGLint(@fSwizzle[0]));
+{$ELSE}
+    glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_R, PGLint(@fSwizzle[0]));
+    glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_G, PGLint(@fSwizzle[1]));
+    glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_B, PGLint(@fSwizzle[2]));
+    glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_A, PGLint(@fSwizzle[3]));
+{$ENDIF}
   end;
 end;
+{$IFEND}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.Bind(const aEnableTextureUnit: Boolean);
@@ -5994,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;
@@ -6017,7 +6032,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; aData: PByte);
+constructor TglBitmap.Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; aData: PByte);
 var
   ImageSize: Integer;
 begin
@@ -6035,12 +6050,11 @@ begin
     end;
   end else begin
     SetDataPointer(aData, aFormat, aSize.X, aSize.Y); //be careful, Data could be freed by this method
-    fFreeDataOnDestroy := false;
   end;
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer);
+constructor TglBitmap.Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer);
 begin
   Create;
   LoadFromFunc(aSize, aFunc, aFormat, aArgs);
@@ -7068,7 +7082,7 @@ begin
   if (fd.Format = tfEmpty) then
     raise EglBitmapUnsupportedFormat.Create('no supported format found');
 
-  buf := GetMem(header.DataSize);
+  buf := GetMemory(header.DataSize);
   aStream.Read(buf^, header.DataSize);
   SetDataPointer(buf, fd.Format, header.Width, header.Height);
 
@@ -7205,7 +7219,7 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
         aFormat := TFormatDescriptor.Get(aFormat).WithAlpha;
 
       result := TbmpBitfieldFormat.Create;
-      result.SetValues(aInfo.biBitCount, aMask);
+      result.SetCustomValues(aInfo.biBitCount, aMask);
     end;
   end;
 
@@ -7374,7 +7388,7 @@ begin
         Header.bfOffBits := Header.bfOffBits + 256 * SizeOf(Cardinal); //256 ColorTable entries
         Converter := TbmpColorTableFormat.Create;
         with (Converter as TbmpColorTableFormat) do begin
-          SetValues(fFormat, 1, FormatDesc.Precision, FormatDesc.Shift);
+          SetCustomValues(fFormat, 1, FormatDesc.Precision, FormatDesc.Shift);
           CreateColorTable;
         end;
       end;
@@ -7955,7 +7969,7 @@ var
         end;
 
         Converter := TbmpBitfieldFormat.Create;
-        Converter.SetValues(dwRGBBitCount, glBitmapRec4ul(dwRBitMask, dwGBitMask, dwBBitMask, dwABitMask));
+        Converter.SetCustomValues(dwRGBBitCount, glBitmapRec4ul(dwRBitMask, dwGBitMask, dwBBitMask, dwABitMask));
       end;
     end;
   end;
@@ -8118,6 +8132,7 @@ begin
   aStream.Write(Data^, FormatDesc.GetSize(Dimension));
 end;
 
+{$IFNDEF OPENGL_ES}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TglBitmap1D/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -8178,6 +8193,9 @@ var
 begin
   // Upload data
   FormatDesc := TFormatDescriptor.Get(Format);
+  if (FormatDesc.glInternalFormat = 0) or (FormatDesc.glDataFormat = 0) then
+    raise EglBitmap.Create('format is not supported by video adapter, please convert before uploading data');
+
   if FormatDesc.IsCompressed then begin
     if not Assigned(glCompressedTexImage1D) then
       raise EglBitmap.Create('compressed formats not supported by video adapter');
@@ -8225,6 +8243,7 @@ begin
   inherited;
   Target := GL_TEXTURE_1D;
 end;
+{$ENDIF}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TglBitmap2D/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -8263,20 +8282,25 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap2D.UploadData(const aTarget: GLenum; const aBuildWithGlu: Boolean);
+procedure TglBitmap2D.UploadData(const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF});
 var
   FormatDesc: TFormatDescriptor;
 begin
+  FormatDesc := TFormatDescriptor.Get(Format);
+  if (FormatDesc.glInternalFormat = 0) or (FormatDesc.glDataFormat = 0) then
+    raise EglBitmap.Create('format is not supported by video adapter, please convert before uploading data');
+
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
-  FormatDesc := TFormatDescriptor.Get(Format);
   if FormatDesc.IsCompressed then begin
     if not Assigned(glCompressedTexImage2D) then
       raise EglBitmap.Create('compressed formats not supported by video adapter');
     glCompressedTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0, FormatDesc.GetSize(fDimension), Data)
+{$IFNDEF OPENGL_ES}
   end else if aBuildWithGlu then begin
     gluBuild2DMipmaps(aTarget, FormatDesc.ChannelCount, Width, Height,
       FormatDesc.glFormat, FormatDesc.glDataFormat, Data)
+{$ENDIF}
   end else begin
     glTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0,
       FormatDesc.glFormat, FormatDesc.glDataFormat, Data);
@@ -8321,6 +8345,7 @@ begin
   end;
 end;
 
+{$IFNDEF OPENGL_ES}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap2D.GetDataFromTexture;
 var
@@ -8337,7 +8362,6 @@ begin
   glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_HEIGHT,          @TempHeight);
   glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, @TempIntFormat);
 
-  IntFormat  := tfEmpty;
   FormatDesc := (TglBitmapFormatDescriptor.GetByFormat(TempIntFormat) as TFormatDescriptor);
   IntFormat  := FormatDesc.Format;
 
@@ -8358,11 +8382,15 @@ begin
     raise;
   end;
 end;
+{$ENDIF}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap2D.GenTexture(const aTestTextureSize: Boolean);
 var
-  BuildWithGlu, PotTex, TexRec: Boolean;
+  {$IFNDEF OPENGL_ES}
+  BuildWithGlu, TexRec: Boolean;
+  {$ENDIF}
+  PotTex: Boolean;
   TexSize: Integer;
 begin
   if Assigned(Data) then begin
@@ -8374,15 +8402,25 @@ begin
         raise EglBitmapSizeToLarge.Create('TglBitmap2D.GenTexture - The size for the texture is to large. It''s may be not conform with the Hardware.');
 
       PotTex := IsPowerOfTwo(Height) and IsPowerOfTwo(Width);
+{$IF NOT DEFINED(OPENGL_ES)}
       TexRec := (GL_ARB_texture_rectangle or GL_EXT_texture_rectangle or GL_NV_texture_rectangle) and (Target = GL_TEXTURE_RECTANGLE);
       if not (PotTex or GL_ARB_texture_non_power_of_two or GL_VERSION_2_0 or TexRec) then
         raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
+{$ELSEIF DEFINED(OPENGL_ES_EXT)}
+      if not PotTex and not GL_OES_texture_npot then
+        raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
+{$ELSE}
+      if not PotTex then
+        raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
+{$IFEND}
     end;
 
     CreateId;
-    SetupParameters(BuildWithGlu);
-    UploadData(Target, BuildWithGlu);
+    SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF});
+    UploadData(Target{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF});
+{$IFNDEF OPENGL_ES}
     glAreTexturesResident(1, @fID, @fIsResident);
+{$ENDIF}
   end;
 end;
 
@@ -8539,7 +8577,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap2D.ToNormalMap(const aFunc: TglBitmapNormalMapFunc; const aScale: Single; const aUseAlpha: Boolean);
+procedure TglBitmap2D.GenerateNormalMap(const aFunc: TglBitmapNormalMapFunc; const aScale: Single; const aUseAlpha: Boolean);
 var
   Rec: TglBitmapToNormalMapRec;
 
@@ -8661,15 +8699,16 @@ begin
 
     // Daten Sammeln
     if aUseAlpha and TFormatDescriptor.Get(Format).HasAlpha then
-      AddFunc(glBitmapToNormalMapPrepareAlphaFunc, false, @Rec)
+      Convert(glBitmapToNormalMapPrepareAlphaFunc, false, @Rec)
     else
-      AddFunc(glBitmapToNormalMapPrepareFunc, false, @Rec);
-    AddFunc(glBitmapToNormalMapFunc, false, @Rec);
+      Convert(glBitmapToNormalMapPrepareFunc, false, @Rec);
+    Convert(glBitmapToNormalMapFunc, false, @Rec);
   finally
     SetLength(Rec.Heights, 0);
   end;
 end;
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TglBitmapCubeMap////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -8683,40 +8722,58 @@ procedure TglBitmapCubeMap.AfterConstruction;
 begin
   inherited;
 
+{$IFNDEF OPENGL_ES}
   if not (GL_VERSION_1_3 or GL_ARB_texture_cube_map or GL_EXT_texture_cube_map) then
     raise EglBitmap.Create('TglBitmapCubeMap.AfterConstruction - CubeMaps are unsupported.');
+{$ELSE}
+  if not (GL_VERSION_2_0) then
+    raise EglBitmap.Create('TglBitmapCubeMap.AfterConstruction - CubeMaps are unsupported.');
+{$ENDIF}
 
   SetWrap;
   Target   := GL_TEXTURE_CUBE_MAP;
+{$IFNDEF OPENGL_ES}
   fGenMode := GL_REFLECTION_MAP;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmapCubeMap.GenerateCubeMap(const aCubeTarget: Cardinal; const aTestTextureSize: Boolean);
 var
+  {$IFNDEF OPENGL_ES}
   BuildWithGlu: Boolean;
+  {$ENDIF}
   TexSize: Integer;
 begin
   if (aTestTextureSize) then begin
     glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, @TexSize);
 
     if (Height > TexSize) or (Width > TexSize) then
-      raise EglBitmapSizeToLarge.Create('TglBitmapCubeMap.GenTexture - The size for the Cubemap is to large. It''s may be not conform with the Hardware.');
+      raise EglBitmapSizeToLarge.Create('TglBitmapCubeMap.GenerateCubeMap - The size for the Cubemap is to large. It''s may be not conform with the Hardware.');
 
+{$IF NOT DEFINED(OPENGL_ES)}
     if not ((IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) or GL_VERSION_2_0 or GL_ARB_texture_non_power_of_two) then
-      raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenTexture - Cubemaps dosn''t support non power of two texture.');
+      raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.');
+{$ELSEIF DEFINED(OPENGL_ES_EXT)}
+    if not (IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) and not GL_OES_texture_npot then
+      raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.');
+{$ELSE}
+    if not (IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) then
+      raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.');
+{$IFEND}
   end;
 
   if (ID = 0) then
     CreateID;
-  SetupParameters(BuildWithGlu);
-  UploadData(aCubeTarget, BuildWithGlu);
+  SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF});
+  UploadData(aCubeTarget{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF});
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmapCubeMap.Bind(const aEnableTexCoordsGen: Boolean; const aEnableTextureUnit: Boolean);
+procedure TglBitmapCubeMap.Bind({$IFNDEF OPENGL_ES}const aEnableTexCoordsGen: Boolean;{$ENDIF} const aEnableTextureUnit: Boolean);
 begin
   inherited Bind (aEnableTextureUnit);
+{$IFNDEF OPENGL_ES}
   if aEnableTexCoordsGen then begin
     glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, fGenMode);
     glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, fGenMode);
@@ -8725,19 +8782,24 @@ begin
     glEnable(GL_TEXTURE_GEN_T);
     glEnable(GL_TEXTURE_GEN_R);
   end;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmapCubeMap.Unbind(const aDisableTexCoordsGen: Boolean; const aDisableTextureUnit: Boolean);
+procedure TglBitmapCubeMap.Unbind({$IFNDEF OPENGL_ES}const aDisableTexCoordsGen: Boolean;{$ENDIF} const aDisableTextureUnit: Boolean);
 begin
   inherited Unbind(aDisableTextureUnit);
+{$IFNDEF OPENGL_ES}
   if aDisableTexCoordsGen then begin
     glDisable(GL_TEXTURE_GEN_S);
     glDisable(GL_TEXTURE_GEN_T);
     glDisable(GL_TEXTURE_GEN_R);
   end;
+{$ENDIF}
 end;
+{$IFEND}
 
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TglBitmapNormalMap//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -8751,7 +8813,7 @@ type
     Func: TglBitmapNormalMapGetVectorFunc;
   end;
 
-  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure glBitmapNormalMapPosX(out aVec: TVec; const aPosition: TglBitmapPixelPosition; const aHalfSize: Integer);
 begin
   aVec[0] := aHalfSize;
@@ -8834,14 +8896,16 @@ end;
 procedure TglBitmapNormalMap.AfterConstruction;
 begin
   inherited;
+{$IFNDEF OPENGL_ES}
   fGenMode := GL_NORMAL_MAP;
+{$ENDIF}
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmapNormalMap.GenerateNormalMap(const aSize: Integer; const aTestTextureSize: Boolean);
 var
   Rec: TglBitmapNormalMapRec;
-  SizeRec: TglBitmapPixelPosition;
+  SizeRec: TglBitmapSize;
 begin
   Rec.HalfSize := aSize div 2;
   FreeDataAfterGenTexture := false;
@@ -8880,37 +8944,23 @@ begin
   LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, aTestTextureSize);
 end;
-
+{$IFEND}
 
 initialization
   glBitmapSetDefaultFormat (tfEmpty);
   glBitmapSetDefaultMipmap (mmMipmap);
   glBitmapSetDefaultFilter (GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
   glBitmapSetDefaultWrap   (GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
   glBitmapSetDefaultSwizzle(GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA);
+{$IFEND}
 
   glBitmapSetDefaultFreeDataAfterGenTexture(true);
   glBitmapSetDefaultDeleteTextureOnFree    (true);
 
   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.