* added documentation (in-code and pasdoc generated)
[glBitmap.git] / glBitmap.pas
index 4986ed4..5f18496 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 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// enable OpenGL ES support
+// 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 statically linked methods
 // use dglOpenGL.pas if not enabled
 {.$DEFINE GLB_NATIVE_OGL_STATIC}
@@ -791,14 +603,6 @@ var
 {$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
-
 {$IFNDEF fpc}
   QWord   = System.UInt64;
   PQWord  = ^QWord;
@@ -807,93 +611,104 @@ type
   PtrUInt = DWord;
 {$ENDIF}
 
+
+  { 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,
@@ -901,426 +716,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)
   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;
+    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;
+    fIsResident: GLboolean;               //< @true if OpenGL texture object has data, @false otherwise
 {$ENDIF}
-    fBorderColor: array[0..3] of Single;
+    fBorderColor: array[0..3] of Single;  //< color of the texture border
 
-    fDimension: TglBitmapPixelPosition;
-    fMipMap: TglBitmapMipMap;
-    fFormat: TglBitmapFormat;
+    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;
+
+    { 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 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;
+    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);
+
+    { free texture stored data }
+    procedure FreeData;
+
 {$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}
-    procedure FreeData;
 
-    //ColorFill
+  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_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}  function  LoadJPEG(const aStream: TStream): Boolean; virtual; {$ENDIF}
-    {$IFDEF GLB_SUPPORT_JPEG_WRITE} procedure SaveJPEG(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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{$IFNDEF OPENGL_ES}
+{$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;
-{$ENDIF}
+{$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;
+
+    { 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
   {$IFNDEF OPENGL_ES}
-    fGenMode: Integer;
+    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);
+
+    { 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);
@@ -1332,13 +1595,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;
@@ -1348,6 +1619,17 @@ function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean;
 
 function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D;
 
+{$IFDEF GLB_DELPHI}
+function CreateGrayPalette: HPALETTE;
+{$ENDIF}
+
+implementation
+
+uses
+  Math, syncobjs, typinfo
+  {$IF DEFINED(GLB_SUPPORT_JPEG_READ) AND DEFINED(GLB_LAZ_JPEG)}, FPReadJPEG{$IFEND};
+
+
 var
   glBitmapDefaultDeleteTextureOnFree: Boolean;
   glBitmapDefaultFreeDataAfterGenTextures: Boolean;
@@ -1360,16 +1642,6 @@ var
   glBitmapDefaultWrapR: Cardinal;
   glDefaultSwizzle: array[0..3] of GLenum;
 
-{$IFDEF GLB_DELPHI}
-function CreateGrayPalette: HPALETTE;
-{$ENDIF}
-
-implementation
-
-uses
-  Math, syncobjs, typinfo
-  {$IF DEFINED(GLB_SUPPORT_JPEG_READ) AND DEFINED(GLB_LAZ_JPEG)}, FPReadJPEG{$IFEND};
-
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 type
   TFormatDescriptor = class(TglBitmapFormatDescriptor)
@@ -1377,7 +1649,7 @@ type
     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;
@@ -1895,20 +2167,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;
@@ -2477,7 +2753,7 @@ begin
   R := glBitmapDefaultWrapR;
 end;
 
-{$IFNDEF OPENGL_ES}
+{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure glBitmapGetDefaultSwizzle(var r, g, b, a: GLenum);
 begin
@@ -2491,7 +2767,7 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TFormatDescriptor///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetSize(const aSize: TglBitmapPixelPosition): Integer;
+function TFormatDescriptor.GetSize(const aSize: TglBitmapSize): Integer;
 var
   w, h: Integer;
 begin
@@ -4989,7 +5265,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;
@@ -5005,7 +5281,7 @@ begin
       FreeMem(tmpData);
     raise;
   end;
-  AddFunc(Self, aFunc, false, aFormat, aArgs);
+  Convert(Self, aFunc, false, aFormat, aArgs);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5036,7 +5312,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
@@ -5067,13 +5343,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;
@@ -5158,6 +5434,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;
@@ -5755,7 +6098,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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5990,81 +6333,23 @@ 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);
@@ -6081,15 +6366,6 @@ end;
 {$ENDIF}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.FreeData;
-var
-  TempPtr: PByte;
-begin
-  TempPtr := nil;
-  SetDataPointer(TempPtr, tfEmpty); //be careful, Data could be freed by this method
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TglBitmap.FillWithColor(const aRed, aGreen, aBlue: Byte;
   const aAlpha: Byte);
 begin
@@ -6121,7 +6397,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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -6324,7 +6600,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
@@ -6342,12 +6618,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);
@@ -8870,7 +9145,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;
 
@@ -8992,10 +9267,10 @@ 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;
@@ -9198,7 +9473,7 @@ 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;