***********************************************************}
unit glBitmap;
-{$message warn 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'}
+{.$MESSAGE warn 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'}
// Please uncomment the defines below to configure the glBitmap to your preferences.
// If you have configured the unit you can uncomment the warning above.
-
// ###### Start of preferences ################################################
-{.$define GLB_NO_NATIVE_GL}
+{$DEFINE GLB_NO_NATIVE_GL}
// To enable the dglOpenGL.pas Header
// With native GL then bindings are staticlly declared to support other headers
// or use the glBitmap inside of DLLs (minimize codesize).
-{.$define GLB_SDL}
+{.$DEFINE GLB_SDL}
// To enable the support for SDL_surfaces
-{.$define GLB_DELPHI}
+{.$DEFINE GLB_DELPHI}
// To enable the support for TBitmap from Delphi (not lazarus)
// *** image libs ***
-{.$define GLB_SDL_IMAGE}
+{.$DEFINE GLB_SDL_IMAGE}
// To enable the support of SDL_image to load files. (READ ONLY)
// If you enable SDL_image all other libraries will be ignored!
-{.$define GLB_PNGIMAGE}
+{.$DEFINE GLB_PNGIMAGE}
// to enable png support with the unit pngimage. You can download it from http://pngdelphi.sourceforge.net/
// if you enable pngimage the libPNG will be ignored
-{.$define GLB_LIB_PNG}
+{.$DEFINE GLB_LIB_PNG}
// to use the libPNG http://www.libpng.org/
// You will need an aditional header.
// http://www.opengl24.de/index.php?cat=header&file=libpng
-{.$define GLB_DELPHI_JPEG}
+{.$DEFINE GLB_DELPHI_JPEG}
// if you enable delphi jpegs the libJPEG will be ignored
-{.$define GLB_LIB_JPEG}
+{.$DEFINE GLB_LIB_JPEG}
// to use the libJPEG http://www.ijg.org/
// You will need an aditional header.
// http://www.opengl24.de/index.php?cat=header&file=libjpeg
// ###### PRIVATE. Do not change anything. ####################################
// *** old defines for compatibility ***
-{$ifdef NO_NATIVE_GL}
- {$define GLB_NO_NATIVE_GL}
-{$endif}
-{$ifdef pngimage}
+{$IFDEF NO_NATIVE_GL}
+ {$DEFINE GLB_NO_NATIVE_GL}
+{$ENDIF}
+{$IFDEF pngimage}
{$definde GLB_PNGIMAGE}
-{$endif}
-
+{$ENDIF}
// *** Delphi Versions ***
-{$ifdef fpc}
+{$IFDEF fpc}
{$MODE Delphi}
- {$ifdef CPUI386}
- {$define CPU386}
- {$asmmode INTEL}
- {$endif}
+ {$IFDEF CPUI386}
+ {$DEFINE CPU386}
+ {$ASMMODE INTEL}
+ {$ENDIF}
- {$ifndef WIN32}
+ {$IFNDEF WINDOWS}
{$linklib c}
- {$endif}
-{$endif}
+ {$ENDIF}
+{$ENDIF}
// *** checking define combinations ***
-{$ifdef GLB_SDL_IMAGE}
- {$ifndef GLB_SDL}
- {$message warn 'SDL_image won''t work without SDL. SDL will be activated.'}
- {$define GLB_SDL}
- {$endif}
- {$ifdef GLB_PNGIMAGE}
- {$message warn 'The unit pngimage will be ignored because you are using SDL_image.'}
+{$IFDEF GLB_SDL_IMAGE}
+ {$IFNDEF GLB_SDL}
+ {$MESSAGE warn 'SDL_image won''t work without SDL. SDL will be activated.'}
+ {$DEFINE GLB_SDL}
+ {$ENDIF}
+ {$IFDEF GLB_PNGIMAGE}
+ {$MESSAGE warn 'The unit pngimage will be ignored because you are using SDL_image.'}
{$undef GLB_PNGIMAGE}
- {$endif}
- {$ifdef GLB_DELPHI_JPEG}
- {$message warn 'The unit JPEG will be ignored because you are using SDL_image.'}
+ {$ENDIF}
+ {$IFDEF GLB_DELPHI_JPEG}
+ {$MESSAGE warn 'The unit JPEG will be ignored because you are using SDL_image.'}
{$undef GLB_DELPHI_JPEG}
- {$endif}
- {$ifdef GLB_LIB_PNG}
- {$message warn 'The library libPNG will be ignored because you are using SDL_image.'}
+ {$ENDIF}
+ {$IFDEF GLB_LIB_PNG}
+ {$MESSAGE warn 'The library libPNG will be ignored because you are using SDL_image.'}
{$undef GLB_LIB_PNG}
- {$endif}
- {$ifdef GLB_LIB_JPEG}
- {$message warn 'The library libJPEG will be ignored because you are using SDL_image.'}
+ {$ENDIF}
+ {$IFDEF GLB_LIB_JPEG}
+ {$MESSAGE warn 'The library libJPEG will be ignored because you are using SDL_image.'}
{$undef GLB_LIB_JPEG}
- {$endif}
+ {$ENDIF}
- {$define GLB_SUPPORT_PNG_READ}
- {$define GLB_SUPPORT_JPEG_READ}
-{$endif}
+ {$DEFINE GLB_SUPPORT_PNG_READ}
+ {$DEFINE GLB_SUPPORT_JPEG_READ}
+{$ENDIF}
-{$ifdef GLB_PNGIMAGE}
- {$ifdef GLB_LIB_PNG}
- {$message warn 'The library libPNG will be ignored if you are using pngimage.'}
+{$IFDEF GLB_PNGIMAGE}
+ {$IFDEF GLB_LIB_PNG}
+ {$MESSAGE warn 'The library libPNG will be ignored if you are using pngimage.'}
{$undef GLB_LIB_PNG}
- {$endif}
-
- {$define GLB_SUPPORT_PNG_READ}
- {$define GLB_SUPPORT_PNG_WRITE}
-{$endif}
+ {$ENDIF}
-{$ifdef GLB_LIB_PNG}
- {$define GLB_SUPPORT_PNG_READ}
- {$define GLB_SUPPORT_PNG_WRITE}
-{$endif}
+ {$DEFINE GLB_SUPPORT_PNG_READ}
+ {$DEFINE GLB_SUPPORT_PNG_WRITE}
+{$ENDIF}
+{$IFDEF GLB_LIB_PNG}
+ {$DEFINE GLB_SUPPORT_PNG_READ}
+ {$DEFINE GLB_SUPPORT_PNG_WRITE}
+{$ENDIF}
-{$ifdef GLB_DELPHI_JPEG}
- {$ifdef GLB_LIB_JPEG}
- {$message warn 'The library libJPEG will be ignored if you are using the unit JPEG.'}
+{$IFDEF GLB_DELPHI_JPEG}
+ {$IFDEF GLB_LIB_JPEG}
+ {$MESSAGE warn 'The library libJPEG will be ignored if you are using the unit JPEG.'}
{$undef GLB_LIB_JPEG}
- {$endif}
+ {$ENDIF}
- {$define GLB_SUPPORT_JPEG_READ}
- {$define GLB_SUPPORT_JPEG_WRITE}
-{$endif}
+ {$DEFINE GLB_SUPPORT_JPEG_READ}
+ {$DEFINE GLB_SUPPORT_JPEG_WRITE}
+{$ENDIF}
-{$ifdef GLB_LIB_JPEG}
- {$define GLB_SUPPORT_JPEG_READ}
- {$define GLB_SUPPORT_JPEG_WRITE}
-{$endif}
+{$IFDEF GLB_LIB_JPEG}
+ {$DEFINE GLB_SUPPORT_JPEG_READ}
+ {$DEFINE GLB_SUPPORT_JPEG_WRITE}
+{$ENDIF}
// *** general options ***
{$EXTENDEDSYNTAX ON}
{$LONGSTRINGS ON}
{$ALIGN ON}
-{$ifndef fpc}
+{$IFNDEF FPC}
{$OPTIMIZATION ON}
-{$endif}
-
+{$ENDIF}
interface
-
uses
- {$ifdef GLB_NO_NATIVE_GL} dglOpenGL, {$endif}
+ {$IFDEF GLB_NO_NATIVE_GL} dglOpenGL, {$ENDIF}
- {$ifdef GLB_SDL} SDL, {$endif}
- {$ifdef GLB_DELPHI} Dialogs, Windows, Graphics, {$endif}
+ {$IFDEF GLB_SDL} SDL, {$ENDIF}
+ {$IFDEF GLB_DELPHI} Dialogs, Windows, Graphics, {$ENDIF}
- {$ifdef GLB_SDL_IMAGE} SDL_image, {$endif}
+ {$IFDEF GLB_SDL_IMAGE} SDL_image, {$ENDIF}
- {$ifdef GLB_PNGIMAGE} pngimage, {$endif}
- {$ifdef GLB_LIB_PNG} libPNG, {$endif}
+ {$IFDEF GLB_PNGIMAGE} pngimage, {$ENDIF}
+ {$IFDEF GLB_LIB_PNG} libPNG, {$ENDIF}
- {$ifdef GLB_DELPHI_JPEG} JPEG, {$endif}
- {$ifdef GLB_LIB_JPEG} libJPEG, {$endif}
+ {$IFDEF GLB_DELPHI_JPEG} JPEG, {$ENDIF}
+ {$IFDEF GLB_LIB_JPEG} libJPEG, {$ENDIF}
Classes, SysUtils;
-
-
-{$ifndef GLB_DELPHI}
+{$IFNDEF GLB_DELPHI}
type
HGLRC = Cardinal;
DWORD = Cardinal;
rgbRed: Byte;
rgbReserved: Byte;
end;
-{$endif}
-
+{$ENDIF}
-{$ifndef GLB_NO_NATIVE_GL}
+(* TODO dglOpenGL
+{$IFNDEF GLB_NO_NATIVE_GL}
// Native OpenGL Implementation
type
PByteBool = ^ByteBool;
-{$ifdef GLB_DELPHI}
+{$IFDEF GLB_DELPHI}
var
gLastContext: HGLRC;
-{$endif}
+{$ENDIF}
const
// Generell
GL_IBM_texture_mirrored_repeat,
GL_SGIS_generate_mipmap: Boolean;
- // Funtions
const
-
-{$ifdef LINUX}
+{$IFDEF LINUX}
libglu = 'libGLU.so.1';
libopengl = 'libGL.so.1';
{$else}
libglu = 'glu32.dll';
libopengl = 'opengl32.dll';
-{$endif}
-
+{$ENDIF}
-{$ifdef LINUX}
+{$IFDEF LINUX}
function glXGetProcAddress(ProcName: PAnsiChar): Pointer; cdecl; external libopengl;
{$else}
function wglGetProcAddress(ProcName: PAnsiChar): Pointer; stdcall; external libopengl;
-{$endif}
+{$ENDIF}
- function glGetString(name: Cardinal): PAnsiChar; {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ function glGetString(name: Cardinal): PAnsiChar; {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- procedure glEnable(cap: Cardinal); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glDisable(cap: Cardinal); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glGetIntegerv(pname: Cardinal; params: PInteger); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ procedure glEnable(cap: Cardinal); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glDisable(cap: Cardinal); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glGetIntegerv(pname: Cardinal; params: PInteger); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- procedure glTexImage1D(target: Cardinal; level, internalformat, width, border: Integer; format, atype: Cardinal; const pixels: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glTexImage2D(target: Cardinal; level, internalformat, width, height, border: Integer; format, atype: Cardinal; const pixels: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ procedure glTexImage1D(target: Cardinal; level, internalformat, width, border: Integer; format, atype: Cardinal; const pixels: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glTexImage2D(target: Cardinal; level, internalformat, width, height, border: Integer; format, atype: Cardinal; const pixels: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- procedure glGenTextures(n: Integer; Textures: PCardinal); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glBindTexture(target: Cardinal; Texture: Cardinal); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glDeleteTextures(n: Integer; const textures: PCardinal); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ procedure glGenTextures(n: Integer; Textures: PCardinal); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glBindTexture(target: Cardinal; Texture: Cardinal); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glDeleteTextures(n: Integer; const textures: PCardinal); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- procedure glReadPixels(x, y: Integer; width, height: Integer; format, atype: Cardinal; pixels: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glPixelStorei(pname: Cardinal; param: Integer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glGetTexImage(target: Cardinal; level: Integer; format: Cardinal; _type: Cardinal; pixels: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ procedure glReadPixels(x, y: Integer; width, height: Integer; format, atype: Cardinal; pixels: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glPixelStorei(pname: Cardinal; param: Integer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glGetTexImage(target: Cardinal; level: Integer; format: Cardinal; _type: Cardinal; pixels: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- function glAreTexturesResident(n: Integer; const Textures: PCardinal; residences: PByteBool): ByteBool; {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glTexParameteri(target: Cardinal; pname: Cardinal; param: Integer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glTexParameterfv(target: Cardinal; pname: Cardinal; const params: PSingle); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glGetTexLevelParameteriv(target: Cardinal; level: Integer; pname: Cardinal; params: PInteger); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
- procedure glTexGeni(coord, pname: Cardinal; param: Integer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libopengl;
+ function glAreTexturesResident(n: Integer; const Textures: PCardinal; residences: PByteBool): ByteBool; {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glTexParameteri(target: Cardinal; pname: Cardinal; param: Integer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glTexParameterfv(target: Cardinal; pname: Cardinal; const params: PSingle); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glGetTexLevelParameteriv(target: Cardinal; level: Integer; pname: Cardinal; params: PInteger); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
+ procedure glTexGeni(coord, pname: Cardinal; param: Integer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libopengl;
- function gluBuild1DMipmaps(Target: Cardinal; Components, Width: Integer; Format, atype: Cardinal; Data: Pointer): Integer; {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libglu;
- function gluBuild2DMipmaps(Target: Cardinal; Components, Width, Height: Integer; Format, aType: Cardinal; Data: Pointer): Integer; {$ifdef Win32}stdcall; {$else}cdecl; {$endif} external libglu;
+ function gluBuild1DMipmaps(Target: Cardinal; Components, Width: Integer; Format, atype: Cardinal; Data: Pointer): Integer; {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libglu;
+ function gluBuild2DMipmaps(Target: Cardinal; Components, Width, Height: Integer; Format, aType: Cardinal; Data: Pointer): Integer; {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF} external libglu;
var
- glCompressedTexImage2D : procedure(target: Cardinal; level: Integer; internalformat: Cardinal; width, height: Integer; border: Integer; imageSize: Integer; const data: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif}
- glCompressedTexImage1D : procedure(target: Cardinal; level: Integer; internalformat: Cardinal; width: Integer; border: Integer; imageSize: Integer; const data: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif}
- glGetCompressedTexImage : procedure(target: Cardinal; level: Integer; img: Pointer); {$ifdef Win32}stdcall; {$else}cdecl; {$endif}
-{$endif}
-
+ glCompressedTexImage2D : procedure(target: Cardinal; level: Integer; internalformat: Cardinal; width, height: Integer; border: Integer; imageSize: Integer; const data: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF}
+ glCompressedTexImage1D : procedure(target: Cardinal; level: Integer; internalformat: Cardinal; width: Integer; border: Integer; imageSize: Integer; const data: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF}
+ glGetCompressedTexImage : procedure(target: Cardinal; level: Integer; img: Pointer); {$IFDEF WINDOWS}stdcall; {$else}cdecl; {$ENDIF}
+{$ENDIF}
+*)
type
- // Exception
- EglBitmapException = Exception;
- EglBitmapSizeToLargeException = EglBitmapException;
- EglBitmapNonPowerOfTwoException = EglBitmapException;
- EglBitmapUnsupportedInternalFormat = EglBitmapException;
+////////////////////////////////////////////////////////////////////////////////////////////////////
+ EglBitmapException = class(Exception);
+ EglBitmapSizeToLargeException = class(EglBitmapException);
+ EglBitmapNonPowerOfTwoException = class(EglBitmapException);
+ EglBitmapUnsupportedFormatFormat = class(EglBitmapException);
- // Functions
+////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapPixelDesc = packed record
RedRange: Cardinal;
RedShift: Shortint;
AlphaShift: Shortint;
end;
+////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapPixelData = packed record
Red: Cardinal;
Green: Cardinal;
Blue: Cardinal;
Alpha: Cardinal;
-
PixelDesc: TglBitmapPixelDesc;
end;
+////////////////////////////////////////////////////////////////////////////////////////////////////
+ TglBitmapFormatDesc = packed record
+ Format: Cardinal;
+ InternalFormat: Cardinal;
+ DataType: Cardinal;
+ end;
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapPixelPositionFields = set of (ffX, ffY);
TglBitmapPixelPosition = record
Fields : TglBitmapPixelPositionFields;
Y : Word;
end;
-const
- cNullSize : TglBitmapPixelPosition = (Fields : []; X: 0; Y: 0);
-
-type
+////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmap = class;
-
TglBitmapFunctionRec = record
Sender : TglBitmap;
Size: TglBitmapPixelPosition;
Dest: TglBitmapPixelData;
CustomData: Pointer;
end;
-
TglBitmapFunction = procedure(var FuncRec: TglBitmapFunctionRec);
- TglBitmapGetPixel = procedure (
- const Pos: TglBitmapPixelPosition;
- var Pixel: TglBitmapPixelData) of object;
-
- TglBitmapSetPixel = procedure (
- const Pos: TglBitmapPixelPosition;
- const Pixel: TglBitmapPixelData) of object;
-
- // Settings
+////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapFileType = (
- {$ifdef GLB_SUPPORT_PNG_WRITE} ftPNG, {$endif}
- {$ifdef GLB_SUPPORT_JPEG_WRITE}ftJPEG, {$endif}
+ {$IFDEF GLB_SUPPORT_PNG_WRITE} ftPNG, {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_WRITE}ftJPEG, {$ENDIF}
ftDDS,
ftTGA,
ftBMP);
TglBitmapFileTypes = set of TglBitmapFileType;
- TglBitmapFormat = (tfDefault, tf4BitsPerChanel, tf8BitsPerChanel, tfCompressed);
- TglBitmapMipMap = (mmNone, mmMipmap, mmMipmapGlu);
- TglBitmapNormalMapFunc = (nm4Samples, nmSobel, nm3x3, nm5x5);
- TglBitmapInternalFormat = (
- ifEmpty,
- // 4 Bit
- ifDXT1,
- // 8 Bit
- ifDXT3,
- ifDXT5,
- ifAlpha,
- ifLuminance,
- ifDepth8,
- // 16 Bit
- ifLuminanceAlpha,
- ifRGBA4,
- ifR5G6B5,
- ifRGB5A1,
- // 24 Bit
- ifBGR8,
- ifRGB8,
- // 32 Bit
- ifBGRA8,
- ifRGBA8,
- ifRGB10A2
+ TglBitmapMipMap = (
+ mmNone,
+ mmMipmap,
+ mmMipmapGlu);
+
+ TglBitmapNormalMapFunc = (
+ nm4Samples,
+ nmSobel,
+ nm3x3,
+ nm5x5);
+
+ TglBitmapFormat = (
+ tfEmpty = 0,
+ { TODO
+ tfAlpha4,
+ tfAlpha8,
+ tfAlpha12,
+ tfAlpha16,
+
+ tfLuminance4, }
+ tfLuminance8,
+{ tfLuminance12,
+ tfLuminance16,
+
+ tfuminance4Alpha4,
+ tfLuminance6Alpha2,}
+ tfLuminance8Alpha8,
+{ tfLuminance12Alpha4,
+ tfLuminance12Alpha12,
+ tfLuminance16Alpha16,
+
+ tfR3G3B2,
+ tfRGB4,
+ tfRGB5, }
+ tfRGB8,
+{ tfRGB10,
+ tfRGB12,
+ tfRGB16,
+
+ tfRGBA2,
+ tfRGBA4,
+ tfRGB5A1, }
+ tfRGBA8,
+{ tfRGB10A2,
+ tfRGBA12,
+ tfRGBA16,
+ }
+ tfBGR8,
+ tfBGRA8,
+ {
+ tfDepth16,
+ tfDepth24,
+ tfDepth32 }
);
- // Pixelmapping
- TglBitmapMapFunc = procedure (const Pixel: TglBitmapPixelData; var pDest: pByte);
- TglBitmapUnMapFunc = procedure (var pData: pByte; var Pixel: TglBitmapPixelData);
+////////////////////////////////////////////////////////////////////////////////////////////////////
+ TglBitmapGetPixel = procedure(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData) of object;
+ TglBitmapSetPixel = procedure(const Pos: TglBitmapPixelPosition; const Pixel: TglBitmapPixelData) of object;
+
+ TglBitmapMapFunc = procedure(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
+ TglBitmapUnMapFunc = procedure(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+ TglBitmapFormatDescriptor = class(TObject)
+ public
+ //virtual abstract
+ class function GetFormat: TglBitmapFormat; virtual; abstract;
+ class function GetPixelDesc: TglBitmapPixelDesc; virtual; abstract;
+ class function GetFormatDesc: TglBitmapFormatDesc; virtual; abstract;
+
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); virtual; abstract;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); virtual; abstract;
+
+ //virtual
+ class function WithoutAlpha: TglBitmapFormat; virtual;
+ class function WithAlpha: TglBitmapFormat; virtual;
+
+ class function IsEmpty: Boolean; virtual;
+ class function HasAlpha: Boolean; virtual;
+ class function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean; virtual;
+
+ class procedure PreparePixel(var aPixel: TglBitmapPixelData); virtual;
+
+ (* TODO
+ function FormatIsCompressed(Format: TglBitmapInternalFormat): boolean;
+ function FormatIsUncompressed(Format: TglBitmapInternalFormat): boolean;
+ function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal = 0{$ENDIF}): Boolean;
+ function LoadCubeMap(PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal = 0{$ENDIF}): Boolean;
+ function LoadNormalMap(Size: Integer; var Texture: Cardinal): Boolean;
+ *)
+ end;
+ TglBitmapFormatDescClass = class of TglBitmapFormatDescriptor;
// Base Class
TglBitmap = class
protected
fID: Cardinal;
fTarget: Cardinal;
- fFormat: TglBitmapFormat;
- fMipMap: TglBitmapMipMap;
fAnisotropic: Integer;
- fBorderColor: array [0..3] of single;
-
fDeleteTextureOnFree: Boolean;
fFreeDataAfterGenTexture: Boolean;
+ fData: PByte;
+ fIsResident: Boolean;
+ fBorderColor: array[0..3] of Single;
- // Propertys
- fData: pByte;
- fInternalFormat: TglBitmapInternalFormat;
fDimension: TglBitmapPixelPosition;
-
- fIsResident: Boolean;
+ fMipMap: TglBitmapMipMap;
+ fFormat: TglBitmapFormat;
// Mapping
fPixelSize: Integer;
fMapFunc: TglBitmapMapFunc;
// Filtering
- fFilterMin: Integer;
- fFilterMag: Integer;
+ fFilterMin: Cardinal;
+ fFilterMag: Cardinal;
- // Texturwarp
- fWrapS: Integer;
- fWrapT: Integer;
- fWrapR: Integer;
+ // TexturWarp
+ fWrapS: Cardinal;
+ fWrapT: Cardinal;
+ fWrapR: Cardinal;
fGetPixelFunc: TglBitmapGetPixel;
fSetPixelFunc: TglBitmapSetPixel;
- // custom data
+ // CustomData
fFilename: String;
fCustomName: String;
fCustomNameW: WideString;
- fCustomDataPointer: Pointer;
-
-
- procedure SetDataPointer(NewData: pByte; Format: TglBitmapInternalFormat; Width: Integer = -1; Height: Integer = -1); virtual;
-
- {$ifdef GLB_SUPPORT_PNG_READ}
- function LoadPNG(Stream: TStream): Boolean; virtual;
- {$endif}
- {$ifdef GLB_SUPPORT_JPEG_READ}
- function LoadJPEG(Stream: TStream): Boolean; virtual;
- {$endif}
+ fCustomData: Pointer;
+
+ //Getter
+ function GetHeight: Integer; virtual;
+ function GetWidth: Integer; virtual;
+
+ //Setter
+ procedure SetCustomData(const aValue: Pointer);
+ procedure SetCustomName(const aValue: String);
+ procedure SetCustomNameW(const aValue: WideString);
+ procedure SetDeleteTextureOnFree(const aValue: Boolean);
+ procedure SetFormat(const aValue: TglBitmapFormat);
+ procedure SetFreeDataAfterGenTexture(const aValue: Boolean);
+ procedure SetID(const aValue: Cardinal);
+ procedure SetMipMap(const aValue: TglBitmapMipMap);
+ procedure SetTarget(const aValue: Cardinal);
+ procedure SetAnisotropic(const aValue: Integer);
+
+ //Load
+ {$IFDEF GLB_SUPPORT_PNG_READ}
+ function LoadPNG(Stream: TStream): Boolean; virtual;
+ {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_READ}
+ function LoadJPEG(Stream: TStream): Boolean; virtual;
+ {$ENDIF}
function LoadDDS(Stream: TStream): Boolean; virtual;
function LoadTGA(Stream: TStream): Boolean; virtual;
function LoadBMP(Stream: TStream): Boolean; virtual;
-
- {$ifdef GLB_SUPPORT_PNG_WRITE}
- procedure SavePNG(Stream: TStream); virtual;
- {$endif}
- {$ifdef GLB_SUPPORT_JPEG_WRITE}
- procedure SaveJPEG(Stream: TStream); virtual;
- {$endif}
+ //Save
+ {$IFDEF GLB_SUPPORT_PNG_WRITE}
+ procedure SavePNG(Stream: TStream); virtual;
+ {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_WRITE}
+ procedure SaveJPEG(Stream: TStream); virtual;
+ {$ENDIF}
procedure SaveDDS(Stream: TStream); virtual;
procedure SaveTGA(Stream: TStream); virtual;
procedure SaveBMP(Stream: TStream); virtual;
-
procedure CreateID;
- procedure SetupParameters(var BuildWithGlu: Boolean);
- procedure SelectFormat(DataFormat: TglBitmapInternalFormat; var glFormat, glInternalFormat, glType: Cardinal; CanConvertImage: Boolean = True);
+ procedure SetupParameters(var aBuildWithGlu: Boolean);
+ procedure SelectFormat(const aFormat: TglBitmapFormat; var glFormat, glInternalFormat, glType: Cardinal);
+ procedure SetDataPointer(NewData: pByte; Format: TglBitmapFormat; Width: Integer = -1; Height: Integer = -1); virtual;
procedure GenTexture(TestTextureSize: Boolean = True); virtual; abstract;
- procedure SetAnisotropic(const Value: Integer);
- procedure SetInternalFormat(const Value: TglBitmapInternalFormat);
-
function FlipHorz: Boolean; virtual;
function FlipVert: Boolean; virtual;
- function GetHeight: Integer;
- function GetWidth: Integer;
-
- function GetFileHeight: Integer;
- function GetFileWidth: Integer;
-
- property Width: Integer read GetWidth;
+ property Width: Integer read GetWidth;
property Height: Integer read GetHeight;
-
- property FileWidth: Integer read GetFileWidth;
- property FileHeight: Integer read GetFileHeight;
public
- // propertys
- property ID: Cardinal read fID write fID;
- property Target: Cardinal read fTarget write fTarget;
- property Format: TglBitmapFormat read fFormat write fFormat;
- property InternalFormat: TglBitmapInternalFormat read fInternalFormat write SetInternalFormat;
- property Dimension: TglBitmapPixelPosition read fDimension;
+ 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 Data: pByte read fData;
+ 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 MipMap: TglBitmapMipMap read fMipMap write fMipMap;
- property Anisotropic: Integer read fAnisotropic write SetAnisotropic;
+ property DeleteTextureOnFree: Boolean read fDeleteTextureOnFree write SetDeleteTextureOnFree;
+ property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture;
- property DeleteTextureOnFree: Boolean read fDeleteTextureOnFree write fDeleteTextureOnFree;
- property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write fFreeDataAfterGenTexture;
+ property Dimension: TglBitmapPixelPosition read fDimension;
+ property Data: PByte read fData;
+ property IsResident: Boolean read fIsResident;
- property IsResident: boolean read fIsResident;
-
- // propertys for custom data
- property Filename: String read fFilename;
- property CustomName: String read fCustomName write fCustomName;
- property CustomNameW: WideString read fCustomNameW write fCustomNameW;
- property CustomDataPointer: Pointer read fCustomDataPointer write fCustomDataPointer;
-
- // Construction and Destructions Methods
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
- constructor Create(); overload;
- constructor Create(FileName: String); overload;
- constructor Create(Stream: TStream); overload;
- {$ifdef GLB_DELPHI}
- constructor CreateFromResourceName(Instance: Cardinal; Resource: String; ResType: PChar = nil);
- constructor Create(Instance: Cardinal; Resource: String; ResType: PChar = nil); overload;
- constructor Create(Instance: Cardinal; ResourceID: Integer; ResType: PChar); overload;
- {$endif}
- constructor Create(Size: TglBitmapPixelPosition; Format: TglBitmapInternalFormat); overload;
- constructor Create(Size: TglBitmapPixelPosition; Format: TglBitmapInternalFormat; Func: TglBitmapFunction; CustomData: Pointer = nil); overload;
+ //Loading
+ procedure LoadFromFile(const aFileName: String);
+ procedure LoadFromStream(const aStream: TStream); virtual;
+ procedure LoadFromFunc(const aSize: TglBitmapPixelPosition; const aFunc: TglBitmapFunction;
+ const aFormat: TglBitmapFormat; const aArgs: PtrInt = 0);
+ {$IFDEF GLB_DELPHI}
+ procedure LoadFromResource(const aInstance: Cardinal; aResource: String; const aResType: PChar = nil);
+ procedure LoadFromResourceID(const sInstance: Cardinal; aResourceID: Integer; const aResType: PChar);
+ {$ENDIF}
+
+ procedure SaveToFile(const aFileName: String; const aFileType: TglBitmapFileType);
+ procedure SaveToStream(const aStream: TStream; const aFileType: TglBitmapFileType); virtual;
+
+ //function AddFunc(const aSource: TglBitmap; const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; Format: TglBitmapFormat; CustomData: Pointer = nil): boolean; overload;
+ //function AddFunc(const aFunc: TglBitmapFunction; CreateTemp: Boolean; CustomData: Pointer = nil): boolean; overload;
+(* TODO
+ {$IFDEF GLB_SDL}
+ function AssignToSurface(out aSurface: PSDL_Surface): Boolean;
+ function AssignFromSurface(const aSurface: PSDL_Surface): Boolean;
+ function AssignAlphaToSurface(out aSurface: PSDL_Surface): Boolean;
+ function AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil;
+ const aArgs: PtrInt = 0): Boolean;
+ {$ENDIF}
+
+ {$IFDEF GLB_DELPHI}
+ function AssignToBitmap(const aBitmap: TBitmap): Boolean;
+ function AssignFromBitmap(const aBitmap: TBitmap): Boolean;
+ function AssignAlphaToBitmap(const aBitmap: TBitmap): Boolean;
+ function AddAlphaFromBitmap(const aBitmap: TBitmap; const aFunc: TglBitmapFunction = nil;
+ const aArgs: PtrInt = 0): Boolean;
+ {$ENDIF}
+
+ function AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: PtrInt = 0): Boolean; virtual;
+ function AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ function AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ function AddAlphaFromGlBitmap(const aBitmap: TglBitmap; const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ {$IFDEF GLB_DELPHI}
+ function AddAlphaFromResource(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil;
+ const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ function AddAlphaFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar;
+ const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ {$ENDIF}
+
+ function AddAlphaFromColorKey(const aRed, aGreen, aBlue: Byte; const aDeviation: Byte = 0): Boolean;
+ function AddAlphaFromColorKeyRange(const aRed, aGreen, aBlue: Cardinal; const aDeviation: Cardinal = 0): Boolean;
+ function AddAlphaFromColorKeyFloat(const aRed, aGreen, aBlue: Single; const aDeviation: Single = 0): Boolean;
+
+ function AddAlphaFromValue(const aAlpha: Byte): Boolean;
+ function AddAlphaFromValueRange(const aAlpha: Cardinal): Boolean;
+ function AddAlphaFromValueFloat(const aAlpha: Single): Boolean;
+ function RemoveAlpha: Boolean; virtual;
function Clone: TglBitmap;
-
+ function ConvertTo(const aFormat: TglBitmapFormat; const aInternalFormat: TglBitmapFormat): Boolean; virtual;
+ procedure SetBorderColor(Red, Green, Blue, Alpha: Single);
+ procedure Invert(const aUseRGB: Boolean = true; aUseAlpha: Boolean = false);
procedure FreeData;
- // Loading Methods
- procedure LoadFromFile(FileName: String);
- procedure LoadFromStream(Stream: TStream); virtual;
- {$ifdef GLB_DELPHI}
- procedure LoadFromResource(Instance: Cardinal; Resource: String; ResType: PChar = nil);
- procedure LoadFromResourceID(Instance: Cardinal; ResourceID: Integer; ResType: PChar);
- {$endif}
- procedure LoadFromFunc(Size: TglBitmapPixelPosition; Func: TglBitmapFunction; Format: TglBitmapInternalFormat; CustomData: Pointer = nil);
-
- procedure SaveToFile(FileName: String; FileType: TglBitmapFileType);
- procedure SaveToStream(Stream: TStream; FileType: TglBitmapFileType); virtual;
-
- function AddFunc(Source: TglBitmap; Func: TglBitmapFunction; CreateTemp: Boolean; Format: TglBitmapInternalFormat; CustomData: Pointer = nil): boolean; overload;
- function AddFunc(Func: TglBitmapFunction; CreateTemp: Boolean; CustomData: Pointer = nil): boolean; overload;
-
- {$ifdef GLB_SDL}
- function AssignToSurface(out Surface: PSDL_Surface): boolean;
- function AssignFromSurface(const Surface: PSDL_Surface): boolean;
- function AssignAlphaToSurface(out Surface: PSDL_Surface): boolean;
-
- function AddAlphaFromSurface(Surface: PSDL_Surface; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- {$endif}
- {$ifdef GLB_DELPHI}
- function AssignToBitmap(const Bitmap: TBitmap): boolean;
- function AssignFromBitmap(const Bitmap: TBitmap): boolean;
- function AssignAlphaToBitmap(const Bitmap: TBitmap): boolean;
-
- function AddAlphaFromBitmap(Bitmap: TBitmap; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- {$endif}
-
- function AddAlphaFromFunc(Func: TglBitmapFunction; CustomData: Pointer = nil): boolean; virtual;
- function AddAlphaFromFile(FileName: String; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- function AddAlphaFromStream(Stream: TStream; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- {$ifdef GLB_DELPHI}
- function AddAlphaFromResource(Instance: Cardinal; Resource: String; ResType: PChar = nil; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- function AddAlphaFromResourceID(Instance: Cardinal; ResourceID: Integer; ResType: PChar; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
- {$endif}
- function AddAlphaFromglBitmap(glBitmap: TglBitmap; Func: TglBitmapFunction = nil; CustomData: Pointer = nil): boolean;
-
- function AddAlphaFromColorKey(Red, Green, Blue: Byte; Deviation: Byte = 0): Boolean;
- function AddAlphaFromColorKeyRange(Red, Green, Blue: Cardinal; Deviation: Cardinal = 0): Boolean;
- function AddAlphaFromColorKeyFloat(Red, Green, Blue: Single; Deviation: Single = 0): Boolean;
-
- function AddAlphaFromValue(Alpha: Byte): Boolean;
- function AddAlphaFromValueRange(Alpha: Cardinal): Boolean;
- function AddAlphaFromValueFloat(Alpha: Single): Boolean;
-
- function RemoveAlpha: Boolean; virtual;
-
- function ConvertTo(NewFormat: TglBitmapInternalFormat): boolean; virtual;
-
- // Other
- procedure FillWithColor(Red, Green, Blue: Byte; Alpha : Byte = 255);
- procedure FillWithColorRange(Red, Green, Blue: Cardinal; Alpha : Cardinal = $FFFFFFFF);
- procedure FillWithColorFloat(Red, Green, Blue: Single; Alpha : Single = 1);
-
- procedure Invert(UseRGB: Boolean = true; UseAlpha: Boolean = false);
-
- procedure SetFilter(Min, Mag : Integer);
- procedure SetWrap(S: Integer = GL_CLAMP_TO_EDGE;
- T: Integer = GL_CLAMP_TO_EDGE; R: Integer = GL_CLAMP_TO_EDGE);
-
- procedure SetBorderColor(Red, Green, Blue, Alpha: Single);
+ procedure FillWithColor(const aRed, aGreen, aBlue: aByte; Alpha: Byte = 255);
+ procedure FillWithColorRange(const aRed, aGreen, aBlue: Cardinal; const aAlpha: Cardinal = $FFFFFFFF);
+ procedure FillWithColorFloat(const aRed, aGreen, aBlue: Single; const aAlpha : Single = 1);
+*)
+ procedure SetFilter(const aMin, aMag: Cardinal);
+ procedure SetWrap(
+ const S: Cardinal = GL_CLAMP_TO_EDGE;
+ const T: Cardinal = GL_CLAMP_TO_EDGE;
+ const R: Cardinal = GL_CLAMP_TO_EDGE);
- procedure GetPixel (const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData); virtual;
- procedure SetPixel (const Pos: TglBitmapPixelPosition; const Pixel: TglBitmapPixelData); virtual;
+ procedure GetPixel(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData); virtual;
+ procedure SetPixel(const Pos: TglBitmapPixelPosition; const Pixel: TglBitmapPixelData); virtual;
- // Generation
procedure Unbind(DisableTextureUnit: Boolean = True); virtual;
procedure Bind(EnableTextureUnit: Boolean = True); virtual;
+
+ constructor Create; overload;
+ constructor Create(FileName: String); overload;
+ constructor Create(Stream: TStream); overload;
+ {$IFDEF GLB_DELPHI}
+ constructor CreateFromResourceName(Instance: Cardinal; Resource: String; ResType: PChar = nil);
+ constructor Create(Instance: Cardinal; Resource: String; ResType: PChar = nil); overload;
+ constructor Create(Instance: Cardinal; ResourceID: Integer; ResType: PChar); overload;
+ {$ENDIF}
+ constructor Create(Size: TglBitmapPixelPosition; Format: TglBitmapFormat); overload;
+ constructor Create(Size: TglBitmapPixelPosition; Format: TglBitmapFormat; Func: TglBitmapFunction; CustomData: Pointer = nil); overload;
end;
procedure GetPixel2DDXT3(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData);
procedure GetPixel2DDXT5(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData);
procedure GetPixel2DUnmap(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData);
+ function GetScanline(Index: Integer): Pointer;
procedure SetPixel2DUnmap(const Pos: TglBitmapPixelPosition; const Pixel: TglBitmapPixelData);
- function GetScanline(Index: Integer): Pointer;
-
- procedure SetDataPointer(Data: pByte; Format: TglBitmapInternalFormat; Width: Integer = -1; Height: Integer = -1); override;
+ procedure SetDataPointer(Data: pByte; Format: TglBitmapFormat; Width: Integer = -1; Height: Integer = -1); override;
procedure UploadData (Target, Format, InternalFormat, Typ: Cardinal; BuildWithGlu: Boolean);
public
- // propertys
property Width;
property Height;
-
property Scanline[Index: Integer]: Pointer read GetScanline;
procedure AfterConstruction; override;
- procedure GrabScreen(Top, Left, Right, Bottom: Integer; Format: TglBitmapInternalFormat);
+ procedure GrabScreen(const aTop, aLeft, aRight, aBottom: Integer; const aFormat: TglBitmapFormat);
procedure GetDataFromTexture;
+ procedure ToNormalMap(const aFunc: TglBitmapNormalMapFunc = nm3x3; const aScale: Single = 2; const aUseAlpha: Boolean = False);
+ procedure GenTexture(TestTextureSize: Boolean = True); override;
- // Other
function FlipHorz: Boolean; override;
function FlipVert: Boolean; override;
-
- procedure ToNormalMap(Func: TglBitmapNormalMapFunc = nm3x3; Scale: Single = 2; UseAlpha: Boolean = False);
-
- // Generation
- procedure GenTexture(TestTextureSize: Boolean = True); override;
end;
-
+(* TODO
TglBitmapCubeMap = class(TglBitmap2D)
protected
fGenMode: Integer;
// Generation
procedure GenTexture(TestTextureSize: Boolean = True); override;
end;
+*)
-
-// methods and vars for Defaults
-procedure glBitmapSetDefaultFormat(Format: TglBitmapFormat);
-procedure glBitmapSetDefaultFilter(Min, Mag: Integer);
-procedure glBitmapSetDefaultWrap(S: Integer = GL_CLAMP_TO_EDGE; T: Integer = GL_CLAMP_TO_EDGE; R: Integer = GL_CLAMP_TO_EDGE);
-
-procedure glBitmapSetDefaultDeleteTextureOnFree(DeleteTextureOnFree: Boolean);
-procedure glBitmapSetDefaultFreeDataAfterGenTexture(FreeData: Boolean);
-
-function glBitmapGetDefaultFormat: TglBitmapFormat;
-procedure glBitmapGetDefaultFilter(var Min, Mag: Integer);
-procedure glBitmapGetDefaultTextureWrap(var S, T, R: Integer);
+const
+ NULL_SIZE: TglBitmapPixelPosition = (Fields: []; X: 0; Y: 0);
+
+procedure glBitmapSetDefaultDeleteTextureOnFree(const aDeleteTextureOnFree: Boolean);
+procedure glBitmapSetDefaultFreeDataAfterGenTexture(const aFreeData: Boolean);
+procedure glBitmapSetDefaultMipmap(const aValue: TglBitmapMipMap);
+procedure glBitmapSetDefaultFormat(const aFormat: TglBitmapFormat);
+procedure glBitmapSetDefaultFilter(const aMin, aMag: Integer);
+procedure glBitmapSetDefaultWrap(
+ const S: Cardinal = GL_CLAMP_TO_EDGE;
+ const T: Cardinal = GL_CLAMP_TO_EDGE;
+ const R: Cardinal = GL_CLAMP_TO_EDGE);
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);
-// position / size
function glBitmapPosition(X: Integer = -1; Y: Integer = -1): TglBitmapPixelPosition;
// Formatfunctions
-function FormatGetSize (Format: TglBitmapInternalFormat): Single;
+function FormatGetSize(const aFormat: TglBitmapFormat): Single;
+
+var
+ glBitmapDefaultDeleteTextureOnFree: Boolean;
+ glBitmapDefaultFreeDataAfterGenTextures: Boolean;
+ glBitmapDefaultFormat: TglBitmapFormat;
+ glBitmapDefaultMipmap: TglBitmapMipMap;
+ glBitmapDefaultFilterMin: Cardinal;
+ glBitmapDefaultFilterMag: Cardinal;
+ glBitmapDefaultWrapS: Cardinal;
+ glBitmapDefaultWrapT: Cardinal;
+ glBitmapDefaultWrapR: Cardinal;
+
+{$IFDEF GLB_DELPHI}
+function CreateGrayPalette: HPALETTE;
+{$ENDIF}
+
+implementation
-function FormatIsCompressed(Format: TglBitmapInternalFormat): boolean;
-function FormatIsUncompressed(Format: TglBitmapInternalFormat): boolean;
-function FormatIsEmpty(Format: TglBitmapInternalFormat): boolean;
-function FormatHasAlpha(Format: TglBitmapInternalFormat): Boolean;
+uses
+ Math;
-procedure FormatPreparePixel(var Pixel: TglBitmapPixelData; Format: TglBitmapInternalFormat);
+type
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdEmpty = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
-function FormatGetWithoutAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat;
-function FormatGetWithAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-function FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask: Cardinal; Format: TglBitmapInternalFormat): boolean;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdLuminance8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithAlpha: TglBitmapFormat; override;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-// Call LoadingMethods
-function LoadTexture(Filename: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal = 0{$endif}): Boolean;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdLuminance8Alpha8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithoutAlpha: TglBitmapFormat; override;
-function LoadCubeMap(PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal = 0{$endif}): Boolean;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-function LoadNormalMap(Size: Integer; var Texture: Cardinal): Boolean;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdRGB8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithAlpha: TglBitmapFormat; override;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-var
- glBitmapDefaultFormat: TglBitmapFormat;
- glBitmapDefaultFilterMin: Integer;
- glBitmapDefaultFilterMag: Integer;
- glBitmapDefaultWrapS: Integer;
- glBitmapDefaultWrapT: Integer;
- glBitmapDefaultWrapR: Integer;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdRGBA8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithoutAlpha: TglBitmapFormat; override;
- glBitmapDefaultDeleteTextureOnFree: Boolean;
- glBitmapDefaultFreeDataAfterGenTextures: Boolean;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-{$ifdef GLB_DELPHI}
-function CreateGrayPalette: HPALETTE;
-{$endif}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdBGR8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithAlpha: TglBitmapFormat; override;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
-implementation
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ TfdBGRA8 = class(TglBitmapFormatDescriptor)
+ public
+ class function GetFormat: TglBitmapFormat; override;
+ class function GetPixelDesc: TglBitmapPixelDesc; override;
+ class function GetFormatDesc: TglBitmapFormatDesc; override;
+ class function WithoutAlpha: TglBitmapFormat; override;
-uses
- Math;
+ class procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); override;
+ class procedure Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); override;
+ end;
+const
+ LUMINANCE_WEIGHT_R = 0.30;
+ LUMINANCE_WEIGHT_G = 0.59;
+ LUMINANCE_WEIGHT_B = 0.11;
+ UNSUPPORTED_INTERNAL_FORMAT = 'the given format isn''t supported by this function.';
+
+{$REGION Private Helper}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapPosition(X, Y: Integer): TglBitmapPixelPosition;
+begin
+ Result.Fields := [];
+
+ if X >= 0 then
+ Result.Fields := Result.Fields + [ffX];
+ if Y >= 0 then
+ Result.Fields := Result.Fields + [ffY];
+
+ Result.X := Max(0, X);
+ Result.Y := Max(0, Y);
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function FormatGetImageSize(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat): Integer;
+begin
+ if (aSize.X = 0) and (aSize.Y = 0) then
+ Result := 0
+ else
+ Result := Ceil(Max(aSize.Y, 1) * Max(aSize.X, 1) * FormatGetSize(aFormat));
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function FormatGetSupportedFiles(const aFormat: TglBitmapFormat): TglBitmapFileTypes;
+begin
+ //TODO check Formats!
+ result := [];
+
+ {$IFDEF GLB_SUPPORT_PNG_WRITE}
+ if aFormat in [
+ tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
+ tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
+ tfuminance4Alpha4, tfLuminance6Alpha2, tfLuminance8Alpha8, tfLuminance12Alpha4, tfLuminance12Alpha12, tfLuminance16Alpha16,
+ tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
+ tfRGBA2, tfRGBA4, tfRGB5A1, tfRGBA8, tfRGB10A2, tfRGBA12, tfRGBA16,
+ tfDepth16, tfDepth24, tfDepth32]
+ then
+ result := result + [ftPNG];
+ {$ENDIF}
+
+ {$IFDEF GLB_SUPPORT_JPEG_WRITE}
+ if Format in [
+ tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
+ tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
+ tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
+ tfDepth16, tfDepth24, tfDepth32]
+ then
+ result := result + [ftJPEG];
+ {$ENDIF}
+
+ if aFormat in [
+ tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
+ tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
+ tfuminance4Alpha4, tfLuminance6Alpha2, tfLuminance8Alpha8, tfLuminance12Alpha4, tfLuminance12Alpha12, tfLuminance16Alpha16,
+ tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
+ tfRGBA2, tfRGBA4, tfRGB5A1, tfRGBA8, tfRGB10A2, tfRGBA12, tfRGBA16,
+ tfDepth16, tfDepth24, tfDepth32]
+ then
+ result := result + [ftDDS, ftTGA, ftBMP];
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function IsPowerOfTwo(aNumber: Integer): Boolean;
+begin
+ while (aNumber and 1) = 0 do
+ aNumber := aNumber shr 1;
+ result := aNumber = 1;
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function GetBitSize(aBitSet: Cardinal): Integer;
+begin
+ result := 0;
+ while aBitSet > 0 do begin
+ if (aBitSet and 1) = 1 then
+ inc(result);
+ aBitSet := aBitSet shr 1;
+ end;
+end;
+{$ENDREGION}
-{$ifndef GLB_NO_NATIVE_GL}
+(* GLB_NO_NATIVE_GL
+{$IFNDEF GLB_NO_NATIVE_GL}
procedure ReadOpenGLExtensions;
var
- {$ifdef GLB_DELPHI}
+ {$IFDEF GLB_DELPHI}
Context: HGLRC;
- {$endif}
+ {$ENDIF}
Buffer: AnsiString;
MajorVersion, MinorVersion: Integer;
function glLoad (aFunc: pAnsiChar): pointer;
begin
- {$ifdef LINUX}
+ {$IFDEF LINUX}
Result := glXGetProcAddress(aFunc);
{$else}
Result := wglGetProcAddress(aFunc);
- {$endif}
+ {$ENDIF}
end;
begin
- {$ifdef GLB_DELPHI}
+ {$IFDEF GLB_DELPHI}
Context := wglGetCurrentContext;
if Context <> gLastContext then begin
gLastContext := Context;
- {$endif}
+ {$ENDIF}
// Version
Buffer := glGetString(GL_VERSION);
glCompressedTexImage2D := glLoad('glCompressedTexImage2DARB');
glGetCompressedTexImage := glLoad('glGetCompressedTexImageARB');
end;
- {$ifdef GLB_DELPHI}
+ {$IFDEF GLB_DELPHI}
end;
- {$endif}
+ {$ENDIF}
end;
-{$endif}
+{$ENDIF}
+*)
-
-function glBitmapPosition(X, Y: Integer): TglBitmapPixelPosition;
+(* TODO GLB_DELPHI
+{$IFDEF GLB_DELPHI}
+function CreateGrayPalette: HPALETTE;
+var
+ Idx: Integer;
+ Pal: PLogPalette;
begin
- Result.Fields := [];
-
- if X >= 0 then
- Result.Fields := Result.Fields + [ffX];
- if Y >= 0 then
- Result.Fields := Result.Fields + [ffY];
-
- Result.X := Max(0, X);
- Result.Y := Max(0, Y);
-end;
-
-
-const
- UNSUPPORTED_INTERNAL_FORMAT = 'the given format isn''t supported by this function.';
-
- PIXEL_DESC_ALPHA : TglBitmapPixelDesc = (
- RedRange : $00; RedShift : 0;
- GreenRange : $00; GreenShift : 0;
- BlueRange : $00; BlueShift : 0;
- AlphaRange : $FF; AlphaShift : 0 );
-
- PIXEL_DESC_LUMINANCE : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 0;
- GreenRange : $FF; GreenShift : 0;
- BlueRange : $FF; BlueShift : 0;
- AlphaRange : $00; AlphaShift : 0 );
-
- PIXEL_DESC_DEPTH8 : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 0;
- GreenRange : $FF; GreenShift : 0;
- BlueRange : $FF; BlueShift : 0;
- AlphaRange : $00; AlphaShift : 0 );
-
- PIXEL_DESC_LUMINANCEALPHA : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 0;
- GreenRange : $FF; GreenShift : 0;
- BlueRange : $FF; BlueShift : 0;
- AlphaRange : $FF; AlphaShift : 8 );
-
- PIXEL_DESC_RGBA4 : TglBitmapPixelDesc = (
- RedRange : $0F; RedShift : 8;
- GreenRange : $0F; GreenShift : 4;
- BlueRange : $0F; BlueShift : 0;
- AlphaRange : $0F; AlphaShift : 12 );
-
- PIXEL_DESC_R5G6B5 : TglBitmapPixelDesc = (
- RedRange : $1F; RedShift : 11;
- GreenRange : $3F; GreenShift : 5;
- BlueRange : $1F; BlueShift : 0;
- AlphaRange : $00; AlphaShift : 0 );
-
- PIXEL_DESC_RGB5A1 : TglBitmapPixelDesc = (
- RedRange : $1F; RedShift : 10;
- GreenRange : $1F; GreenShift : 5;
- BlueRange : $1F; BlueShift : 0;
- AlphaRange : $01; AlphaShift : 15 );
-
- PIXEL_DESC_RGB8 : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 0;
- GreenRange : $FF; GreenShift : 8;
- BlueRange : $FF; BlueShift : 16;
- AlphaRange : $00; AlphaShift : 0 );
+ GetMem(Pal, SizeOf(TLogPalette) + (SizeOf(TPaletteEntry) * 256));
- PIXEL_DESC_RGBA8 : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 0;
- GreenRange : $FF; GreenShift : 8;
- BlueRange : $FF; BlueShift : 16;
- AlphaRange : $FF; AlphaShift : 24 );
+ Pal.palVersion := $300;
+ Pal.palNumEntries := 256;
- PIXEL_DESC_BGR8 : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 16;
- GreenRange : $FF; GreenShift : 8;
- BlueRange : $FF; BlueShift : 0;
- AlphaRange : $00; AlphaShift : 0 );
+ {$IFOPT R+}
+ {$DEFINE GLB_TEMPRANGECHECK}
+ {$R-}
+ {$ENDIF}
- PIXEL_DESC_BGRA8 : TglBitmapPixelDesc = (
- RedRange : $FF; RedShift : 16;
- GreenRange : $FF; GreenShift : 8;
- BlueRange : $FF; BlueShift : 0;
- AlphaRange : $FF; AlphaShift : 24 );
+ for Idx := 0 to 256 - 1 do begin
+ Pal.palPalEntry[Idx].peRed := Idx;
+ Pal.palPalEntry[Idx].peGreen := Idx;
+ Pal.palPalEntry[Idx].peBlue := Idx;
+ Pal.palPalEntry[Idx].peFlags := 0;
+ end;
- PIXEL_DESC_RGB10A2 : TglBitmapPixelDesc = (
- RedRange : $3FF; RedShift : 20;
- GreenRange : $3FF; GreenShift : 10;
- BlueRange : $3FF; BlueShift : 0;
- AlphaRange : $003; AlphaShift : 30 );
+ {$IFDEF GLB_TEMPRANGECHECK}
+ {$UNDEF GLB_TEMPRANGECHECK}
+ {$R+}
+ {$ENDIF}
-{*
-** Mapping
-*}
+ Result := CreatePalette(Pal^);
-procedure MapAlpha(const Pixel: TglBitmapPixelData; var pDest: pByte);
-begin
- pDest^ := Pixel.Alpha;
- Inc(pDest);
+ FreeMem(Pal);
end;
+{$ENDIF}
+*)
-
-procedure MapLuminance(const Pixel: TglBitmapPixelData; var pDest: pByte);
+(* TODO GLB_SDL_IMAGE
+{$IFDEF GLB_SDL_IMAGE}
+function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl;
begin
- pDest^ := Trunc(Pixel.Red * 0.3 + Pixel.Green * 0.59 + Pixel.Blue * 0.11);
- Inc(pDest);
+ Result := TStream(context^.unknown.data1).Seek(offset, whence);
end;
-
-procedure MapDepth8(const Pixel: TglBitmapPixelData; var pDest: pByte);
+function glBitmapRWread(context: PSDL_RWops; Ptr: Pointer; size: Integer; maxnum : Integer): Integer; cdecl;
begin
- pDest^ := (Pixel.Red + Pixel.Green + Pixel.Blue) div 3;
- Inc(pDest);
+ Result := TStream(context^.unknown.data1).Read(Ptr^, size * maxnum);
end;
-
-procedure MapLuminanceAlpha(const Pixel: TglBitmapPixelData; var pDest: pByte);
+function glBitmapRWwrite(context: PSDL_RWops; Ptr: Pointer; size: Integer; num: Integer): Integer; cdecl;
begin
- pDest^ := Trunc(Pixel.Red * 0.3 + Pixel.Green * 0.59 + Pixel.Blue * 0.11);
- Inc(pDest);
-
- pDest^ := Pixel.Alpha;
- Inc(pDest);
+ Result := TStream(context^.unknown.data1).Write(Ptr^, size * num);
end;
-
-procedure MapRGBA4(const Pixel: TglBitmapPixelData; var pDest: pByte);
+function glBitmapRWclose(context: PSDL_RWops): Integer; cdecl;
begin
- pWord(pDest)^ :=
- Pixel.Alpha shl PIXEL_DESC_RGBA4.AlphaShift or
- Pixel.Red shl PIXEL_DESC_RGBA4.RedShift or
- Pixel.Green shl PIXEL_DESC_RGBA4.GreenShift or
- Pixel.Blue;
-
- Inc(pDest, 2);
+ Result := 0;
end;
-
-procedure MapR5G6B5(const Pixel: TglBitmapPixelData; var pDest: pByte);
+function glBitmapCreateRWops(Stream: TStream): PSDL_RWops;
begin
- pWord(pDest)^ :=
- Pixel.Red shl PIXEL_DESC_R5G6B5.RedShift or
- Pixel.Green shl PIXEL_DESC_R5G6B5.GreenShift or
- Pixel.Blue;
-
- Inc(pDest, 2);
-end;
-
+ Result := SDL_AllocRW;
-procedure MapRGB5A1(const Pixel: TglBitmapPixelData; var pDest: pByte);
-begin
- pWord(pDest)^ :=
- Pixel.Alpha shl PIXEL_DESC_RGB5A1.AlphaShift or
- Pixel.Red shl PIXEL_DESC_RGB5A1.RedShift or
- Pixel.Green shl PIXEL_DESC_RGB5A1.GreenShift or
- Pixel.Blue;
+ if Result = nil then
+ raise EglBitmapException.Create('glBitmapCreateRWops - SDL_AllocRW failed.');
- Inc(pDest, 2);
+ Result^.seek := glBitmapRWseek;
+ Result^.read := glBitmapRWread;
+ Result^.write := glBitmapRWwrite;
+ Result^.close := glBitmapRWclose;
+ Result^.unknown.data1 := Stream;
end;
+{$ENDIF}
+*)
-
-procedure MapRGB8(const Pixel: TglBitmapPixelData; var pDest: pByte);
+(* TODO LoadFuncs
+function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean;
+var
+ glBitmap: TglBitmap2D;
begin
- pDest^ := Pixel.Red;
- Inc(pDest);
-
- pDest^ := Pixel.Green;
- Inc(pDest);
+ Result := false;
+ Texture := 0;
- pDest^ := Pixel.Blue;
- Inc(pDest);
-end;
+ {$IFDEF GLB_DELPHI}
+ if Instance = 0 then
+ Instance := HInstance;
+ if (LoadFromRes) then
+ glBitmap := TglBitmap2D.CreateFromResourceName(Instance, FileName)
+ else
+ {$ENDIF}
+ glBitmap := TglBitmap2D.Create(FileName);
-procedure MapBGR8(const Pixel: TglBitmapPixelData; var pDest: pByte);
-begin
- pDest^ := Pixel.Blue;
- Inc(pDest);
-
- pDest^ := Pixel.Green;
- Inc(pDest);
-
- pDest^ := Pixel.Red;
- Inc(pDest);
+ try
+ glBitmap.DeleteTextureOnFree := False;
+ glBitmap.FreeDataAfterGenTexture := False;
+ glBitmap.GenTexture(True);
+ if (glBitmap.ID > 0) then begin
+ Texture := glBitmap.ID;
+ Result := True;
+ end;
+ finally
+ glBitmap.Free;
+ end;
end;
-
-procedure MapRGBA8(const Pixel: TglBitmapPixelData; var pDest: pByte);
+function LoadCubeMap(PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean;
+var
+ CM: TglBitmapCubeMap;
begin
- pDWord(pDest)^ :=
- Pixel.Alpha shl PIXEL_DESC_RGBA8.AlphaShift or
- Pixel.Blue shl PIXEL_DESC_RGBA8.BlueShift or
- Pixel.Green shl PIXEL_DESC_RGBA8.GreenShift or
- Pixel.Red;
-
- Inc(pDest, 4);
-end;
+ Texture := 0;
+ {$IFDEF GLB_DELPHI}
+ if Instance = 0 then
+ Instance := HInstance;
+ {$ENDIF}
-procedure MapBGRA8(const Pixel: TglBitmapPixelData; var pDest: pByte);
-begin
- pDWord(pDest)^ :=
- Pixel.Alpha shl PIXEL_DESC_BGRA8.AlphaShift or
- Pixel.Red shl PIXEL_DESC_BGRA8.RedShift or
- Pixel.Green shl PIXEL_DESC_BGRA8.GreenShift or
- Pixel.Blue;
+ CM := TglBitmapCubeMap.Create;
+ try
+ CM.DeleteTextureOnFree := False;
- Inc(pDest, 4);
-end;
+ // Maps
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, PositiveX)
+ else
+ {$ENDIF}
+ CM.LoadFromFile(PositiveX);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, NegativeX)
+ else
+ {$ENDIF}
+ CM.LoadFromFile(NegativeX);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
-procedure MapRGB10A2(const Pixel: TglBitmapPixelData; var pDest: pByte);
-begin
- pDWord(pDest)^ :=
- Pixel.Alpha shl PIXEL_DESC_RGB10A2.AlphaShift or
- Pixel.Red shl PIXEL_DESC_RGB10A2.RedShift or
- Pixel.Green shl PIXEL_DESC_RGB10A2.GreenShift or
- Pixel.Blue;
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, PositiveY)
+ else
+ {$ENDIF}
+ CM.LoadFromFile(PositiveY);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
- Inc(pDest, 4);
-end;
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, NegativeY)
+ else
+ {$ENDIF}
+ CM.LoadFromFile(NegativeY);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, PositiveZ)
+ else
+ {$ENDIF}
+ CM.LoadFromFile(PositiveZ);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
-function FormatGetMapFunc(Format: TglBitmapInternalFormat): TglBitmapMapFunc;
-begin
- case Format of
- ifAlpha: Result := MapAlpha;
- ifLuminance: Result := MapLuminance;
- ifDepth8: Result := MapDepth8;
- ifLuminanceAlpha: Result := MapLuminanceAlpha;
- ifRGBA4: Result := MapRGBA4;
- ifR5G6B5: Result := MapR5G6B5;
- ifRGB5A1: Result := MapRGB5A1;
- ifRGB8: Result := MapRGB8;
- ifBGR8: Result := MapBGR8;
- ifRGBA8: Result := MapRGBA8;
- ifBGRA8: Result := MapBGRA8;
- ifRGB10A2: Result := MapRGB10A2;
+ {$IFDEF GLB_DELPHI}
+ if (LoadFromRes) then
+ CM.LoadFromResource(Instance, NegativeZ)
else
- raise EglBitmapUnsupportedInternalFormat.Create('FormatGetMapFunc - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ {$ENDIF}
+ CM.LoadFromFile(NegativeZ);
+ CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
+
+ Texture := CM.ID;
+ Result := True;
+ finally
+ CM.Free;
end;
end;
-
-{*
-** Unmapping
-*}
-procedure UnMapAlpha(var pData: pByte; var Pixel: TglBitmapPixelData);
+function LoadNormalMap(Size: Integer; var Texture: Cardinal): Boolean;
+var
+ NM: TglBitmapNormalMap;
begin
- Pixel.Alpha := pData^;
- Pixel.Red := Pixel.PixelDesc.RedRange;
- Pixel.Green := Pixel.PixelDesc.GreenRange;
- Pixel.Blue := Pixel.PixelDesc.BlueRange;
+ Texture := 0;
- Inc(pData);
-end;
+ NM := TglBitmapNormalMap.Create;
+ try
+ NM.DeleteTextureOnFree := False;
+ NM.GenerateNormalMap(Size);
+ Texture := NM.ID;
+ Result := True;
+ finally
+ NM.Free;
+ end;
+end;
+*)
-procedure UnMapLuminance(var pData: pByte; var Pixel: TglBitmapPixelData);
+{$REGION default Setter and Gettter}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultDeleteTextureOnFree(const aDeleteTextureOnFree: Boolean);
begin
- Pixel.Alpha := 255;
- Pixel.Red := pData^;
- Pixel.Green := pData^;
- Pixel.Blue := pData^;
-
- Inc(pData);
+ glBitmapDefaultDeleteTextureOnFree := aDeleteTextureOnFree;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultFreeDataAfterGenTexture(const aFreeData: Boolean);
+begin
+ glBitmapDefaultFreeDataAfterGenTextures := aFreeData;
+end;
-procedure UnMapDepth8(var pData: pByte; var Pixel: TglBitmapPixelData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultMipmap(const aValue: TglBitmapMipMap);
begin
- Pixel.Alpha := 255;
- Pixel.Red := pData^;
- Pixel.Green := pData^;
- Pixel.Blue := pData^;
+ glBitmapDefaultMipmap := aValue;
+end;
- Inc(pData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultFormat(const aFormat: TglBitmapFormat);
+begin
+ glBitmapDefaultFormat := aFormat;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultFilter(const aMin, aMag: Integer);
+begin
+ glBitmapDefaultFilterMin := aMin;
+ glBitmapDefaultFilterMag := aMag;
+end;
-procedure UnMapLuminanceAlpha(var pData: pByte; var Pixel: TglBitmapPixelData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapSetDefaultWrap(const S: Cardinal = GL_CLAMP_TO_EDGE; const T: Cardinal = GL_CLAMP_TO_EDGE; const R: Cardinal = GL_CLAMP_TO_EDGE);
begin
- Pixel.Red := pData^;
- Pixel.Green := pData^;
- Pixel.Blue := pData^;
- Inc(pData);
+ glBitmapDefaultWrapS := S;
+ glBitmapDefaultWrapT := T;
+ glBitmapDefaultWrapR := R;
+end;
- Pixel.Alpha := pData^;
- Inc(pData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapGetDefaultDeleteTextureOnFree: Boolean;
+begin
+ result := glBitmapDefaultDeleteTextureOnFree;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapGetDefaultFreeDataAfterGenTexture: Boolean;
+begin
+ result := glBitmapDefaultFreeDataAfterGenTextures;
+end;
-procedure UnMapRGBA4(var pData: pByte; var Pixel: TglBitmapPixelData);
-var
- Temp: Word;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapGetDefaultMipmap: TglBitmapMipMap;
begin
- Temp := pWord(pData)^;
+ result := glBitmapDefaultMipmap;
+end;
- Pixel.Alpha := Temp shr PIXEL_DESC_RGBA4.AlphaShift and PIXEL_DESC_RGBA4.AlphaRange;
- Pixel.Red := Temp shr PIXEL_DESC_RGBA4.RedShift and PIXEL_DESC_RGBA4.RedRange;
- Pixel.Green := Temp shr PIXEL_DESC_RGBA4.GreenShift and PIXEL_DESC_RGBA4.GreenRange;
- Pixel.Blue := Temp and PIXEL_DESC_RGBA4.BlueRange;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapGetDefaultFormat: TglBitmapFormat;
+begin
+ result := glBitmapDefaultFormat;
+end;
- Inc(pData, 2);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapGetDefaultFilter(var aMin, aMag: Cardinal);
+begin
+ aMin := glBitmapDefaultFilterMin;
+ aMag := glBitmapDefaultFilterMag;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure glBitmapGetDefaultTextureWrap(var S, T, R: Cardinal);
+begin
+ S := glBitmapDefaultWrapS;
+ T := glBitmapDefaultWrapT;
+ R := glBitmapDefaultWrapR;
+end;
+{$ENDREGION}
-procedure UnMapR5G6B5(var pData: pByte; var Pixel: TglBitmapPixelData);
-var
- Temp: Word;
+{$REGION TglBitmapFormatDescriptor}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TglBitmapFormatDescriptor///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TglBitmapFormatDescriptor.WithoutAlpha: TglBitmapFormat;
begin
- Temp := pWord(pData)^;
+ if not HasAlpha then
+ result := GetFormat
+ else
+ result := tfEmpty;
+end;
- Pixel.Alpha := Pixel.PixelDesc.AlphaRange;
- Pixel.Red := Temp shr PIXEL_DESC_R5G6B5.RedShift and PIXEL_DESC_R5G6B5.RedRange;
- Pixel.Green := Temp shr PIXEL_DESC_R5G6B5.GreenShift and PIXEL_DESC_R5G6B5.GreenRange;
- Pixel.Blue := Temp and PIXEL_DESC_R5G6B5.BlueRange;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TglBitmapFormatDescriptor.WithAlpha: TglBitmapFormat;
+begin
+ if HasAlpha then
+ result := GetFormat
+ else
+ result := tfEmpty;
+end;
- Inc(pData, 2);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TglBitmapFormatDescriptor.IsEmpty: Boolean;
+begin
+ result := (GetFormat = tfEmpty);
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TglBitmapFormatDescriptor.HasAlpha: Boolean;
+begin
+ result := (GetPixelDesc.AlphaRange > 0);
+end;
-procedure UnMapRGB5A1(var pData: pByte; var Pixel: TglBitmapPixelData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TglBitmapFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean;
var
- Temp: Word;
+ PixelDesc: TglBitmapPixelDesc;
begin
- Temp := pWord(pData)^;
+ result := False;
- Pixel.Alpha := Temp shr PIXEL_DESC_RGB5A1.AlphaShift and PIXEL_DESC_RGB5A1.AlphaRange;
- Pixel.Red := Temp shr PIXEL_DESC_RGB5A1.RedShift and PIXEL_DESC_RGB5A1.RedRange;
- Pixel.Green := Temp shr PIXEL_DESC_RGB5A1.GreenShift and PIXEL_DESC_RGB5A1.GreenRange;
- Pixel.Blue := Temp and PIXEL_DESC_RGB5A1.BlueRange;
+ if (aRedMask = 0) and (aGreenMask = 0) and (aBlueMask = 0) and (aAlphaMask = 0) then
+ raise EglBitmapException.Create('FormatCheckFormat - All Masks are 0');
- Inc(pData, 2);
+ PixelDesc := GetPixelDesc;
+ with PixelDesc do begin
+ if (aRedMask <> 0) and (aRedMask <> (RedRange shl RedShift)) then
+ exit;
+ if (aGreenMask <> 0) and (aGreenMask <> (GreenRange shl GreenShift)) then
+ exit;
+ if (aBlueMask <> 0) and (aBlueMask <> (BlueRange shl BlueShift)) then
+ exit;
+ if (aAlphaMask <> 0) and (aAlphaMask <> (AlphaRange shl AlphaShift)) then
+ exit;
+ end;
+ result := True;
end;
-
-procedure UnMapRGB8(var pData: pByte; var Pixel: TglBitmapPixelData);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class procedure TglBitmapFormatDescriptor.PreparePixel(var aPixel: TglBitmapPixelData);
begin
- Pixel.Alpha := Pixel.PixelDesc.AlphaRange;
-
- Pixel.Red := pData^;
- Inc(pData);
+ FillChar(aPixel, SizeOf(aPixel), 0);
+ with GetPixelDesc do begin
+ aPixel.Red := RedRange;
+ aPixel.Green := GreenRange;
+ aPixel.Blue := BlueRange;
+ aPixel.Alpha := AlphaRange;
+ end;
+end;
+{$ENDREGION}
- Pixel.Green := pData^;
- Inc(pData);
+{$REGION TfdEmpty}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdEmpty////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdEmpty.GetFormat: TglBitmapFormat;
+begin
+ result := tfEmpty;
+end;
- Pixel.Blue := pData^;
- Inc(pData);
+class function TfdEmpty.GetPixelDesc: TglBitmapPixelDesc;
+begin
+ with result do begin
+ RedRange := $00000000; RedShift := 0;
+ GreenRange := $00000000; GreenShift := 0;
+ BlueRange := $00000000; BlueShift := 0;
+ AlphaRange := $00000000; AlphaShift := 0;
+ end;
end;
+class function TfdEmpty.GetFormatDesc: TglBitmapFormatDesc;
+begin
+ with result do begin
+ Format := 0;
+ InternalFormat := 0;
+ DataType := 0;
+ end;
+end;
-procedure UnMapBGR8(var pData: pByte; var Pixel: TglBitmapPixelData);
+class procedure TfdEmpty.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
begin
- Pixel.Alpha := Pixel.PixelDesc.AlphaRange;
+ raise EglBitmapException.Create('format does not support mapping');
+end;
- Pixel.Blue := pData^;
- Inc(pData);
+class procedure TfdEmpty.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
+begin
+ raise EglBitmapException.Create('format does not support unmapping');
+end;
+{$ENDREGION}
- Pixel.Green := pData^;
- Inc(pData);
+{$REGION TfdLuminance8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdLuminance8///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdLuminance8.GetFormat: TglBitmapFormat;
+begin
+ result := tfEmpty;
+end;
- Pixel.Red := pData^;
- Inc(pData);
+class function TfdLuminance8.GetPixelDesc: TglBitmapPixelDesc;
+begin
+ with result do begin
+ RedRange := $000000FF; RedShift := 0;
+ GreenRange := $000000FF; GreenShift := 0;
+ BlueRange := $000000FF; BlueShift := 0;
+ AlphaRange := $00000000; AlphaShift := 0;
+ end;
end;
+class function TfdLuminance8.GetFormatDesc: TglBitmapFormatDesc;
+begin
+ with result do begin
+ Format := GL_LUMINANCE;
+ InternalFormat := GL_LUMINANCE8;
+ DataType := GL_UNSIGNED_BYTE;
+ end;
+end;
-procedure UnMapRGBA8(var pData: pByte; var Pixel: TglBitmapPixelData);
+class function TfdLuminance8.WithAlpha: TglBitmapFormat;
begin
- Pixel.Red := pData^;
- Inc(pData);
+ result := tfLuminance8Alpha8;
+end;
- Pixel.Green := pData^;
- Inc(pData);
+class procedure TfdLuminance8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
+begin
+ aData^ := Trunc(
+ aPixel.Red * LUMINANCE_WEIGHT_R +
+ aPixel.Green * LUMINANCE_WEIGHT_G +
+ aPixel.Blue * LUMINANCE_WEIGHT_B);
+ inc(aData);
+end;
- Pixel.Blue := pData^;
- Inc(pData);
+class procedure TfdLuminance8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
+begin
+ aPixel.Red := aData^;
+ aPixel.Green := aData^;
+ aPixel.Blue := aData^;
+ aPixel.Alpha := 0;
+ inc(aData);
+end;
+{$ENDREGION}
- Pixel.Alpha := pData^;
- Inc(pData);
+{$REGION TfdLuminance8Alpha8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdLuminance8Alpha8/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdLuminance8Alpha8.GetFormat: TglBitmapFormat;
+begin
+ result := tfLuminance8Alpha8;
end;
+class function TfdLuminance8Alpha8.GetPixelDesc: TglBitmapPixelDesc;
+begin
+ with result do begin
+ RedRange := $000000FF; RedShift := 0;
+ GreenRange := $000000FF; GreenShift := 0;
+ BlueRange := $000000FF; BlueShift := 0;
+ AlphaRange := $000000FF; AlphaShift := 8;
+ end;
+end;
-procedure UnMapBGRA8(var pData: pByte; var Pixel: TglBitmapPixelData);
+class function TfdLuminance8Alpha8.GetFormatDesc: TglBitmapFormatDesc;
begin
- Pixel.Blue := pData^;
- Inc(pData);
+ with result do begin
+ Format := GL_LUMINANCE_ALPHA;
+ InternalFormat := GL_LUMINANCE8_ALPHA8;
+ DataType := GL_UNSIGNED_BYTE;
+ end;
+end;
- Pixel.Green := pData^;
- Inc(pData);
+class function TfdLuminance8Alpha8.WithoutAlpha: TglBitmapFormat;
+begin
+ result := tfLuminance8;
+end;
- Pixel.Red := pData^;
- Inc(pData);
+class procedure TfdLuminance8Alpha8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
+begin
+ aData^ := Trunc(
+ aPixel.Red * LUMINANCE_WEIGHT_R +
+ aPixel.Green * LUMINANCE_WEIGHT_G +
+ aPixel.Blue * LUMINANCE_WEIGHT_B);
+ inc(aData);
- Pixel.Alpha := pData^;
- Inc(pData);
+ aData^ := aPixel.Alpha;
+ inc(aData);
end;
-
-procedure UnMapRGB10A2(var pData: pByte; var Pixel: TglBitmapPixelData);
-var
- Temp: DWord;
+class procedure TfdLuminance8Alpha8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
begin
- Temp := pDWord(pData)^;
+ aPixel.Red := aData^;
+ aPixel.Green := aData^;
+ aPixel.Blue := aData^;
+ inc(aData);
- Pixel.Alpha := Temp shr PIXEL_DESC_RGB10A2.AlphaShift and PIXEL_DESC_RGB10A2.AlphaRange;
- Pixel.Red := Temp shr PIXEL_DESC_RGB10A2.RedShift and PIXEL_DESC_RGB10A2.RedRange;
- Pixel.Green := Temp shr PIXEL_DESC_RGB10A2.GreenShift and PIXEL_DESC_RGB10A2.GreenRange;
- Pixel.Blue := Temp and PIXEL_DESC_RGB10A2.BlueRange;
-
- Inc(pData, 4);
+ aPixel.Alpha := aData^;
+ inc(aData);
end;
+{$ENDREGION}
+{$REGION TfdRGB8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdRGB8/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdRGB8.GetFormat: TglBitmapFormat;
+begin
+ result := tfRGB8;
+end;
-function FormatGetUnMapFunc(Format: TglBitmapInternalFormat): TglBitmapUnMapFunc;
+class function TfdRGB8.GetPixelDesc: TglBitmapPixelDesc;
begin
- case Format of
- ifAlpha: Result := UnmapAlpha;
- ifLuminance: Result := UnMapLuminance;
- ifDepth8: Result := UnMapDepth8;
- ifLuminanceAlpha: Result := UnMapLuminanceAlpha;
- ifRGBA4: Result := UnMapRGBA4;
- ifR5G6B5: Result := UnMapR5G6B5;
- ifRGB5A1: Result := UnMapRGB5A1;
- ifRGB8: Result := UnMapRGB8;
- ifBGR8: Result := UnMapBGR8;
- ifRGBA8: Result := UnMapRGBA8;
- ifBGRA8: Result := UnMapBGRA8;
- ifRGB10A2: Result := UnMapRGB10A2;
- else
- raise EglBitmapUnsupportedInternalFormat.Create('FormatGetUnMapFunc - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ with result do begin
+ RedRange := $000000FF; RedShift := 0;
+ GreenRange := $000000FF; GreenShift := 8;
+ BlueRange := $000000FF; BlueShift := 16;
+ AlphaRange := $00000000; AlphaShift := 0;
end;
end;
-{*
-** Tools
-*}
-function FormatGetSize (Format: TglBitmapInternalFormat): Single;
+class function TfdRGB8.GetFormatDesc: TglBitmapFormatDesc;
begin
- case Format of
- ifEmpty:
- Result := 0;
- ifDXT1:
- Result := 0.5;
- ifAlpha, ifLuminance, ifDepth8, ifDXT3, ifDXT5:
- Result := 1;
- ifLuminanceAlpha, ifRGBA4, ifRGB5A1, ifR5G6B5:
- Result := 2;
- ifBGR8, ifRGB8:
- Result := 3;
- ifBGRA8, ifRGBA8, ifRGB10A2:
- Result := 4;
- else
- raise EglBitmapUnsupportedInternalFormat.Create('FormatGetSize - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ with result do begin
+ Format := GL_LUMINANCE;
+ InternalFormat := GL_LUMINANCE8;
+ DataType := GL_UNSIGNED_BYTE;
end;
end;
-
-function FormatIsCompressed(Format: TglBitmapInternalFormat): boolean;
+class function TfdRGB8.WithAlpha: TglBitmapFormat;
begin
- Result := Format in [ifDXT1, ifDXT3, ifDXT5];
+ result := tfRGBA8;
end;
-
-function FormatIsUncompressed(Format: TglBitmapInternalFormat): boolean;
+class procedure TfdRGB8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
begin
- Result := Format in [ifAlpha, ifLuminance, ifDepth8, ifLuminanceAlpha, ifRGBA4, ifRGB5A1, ifR5G6B5, ifBGR8, ifRGB8, ifBGRA8, ifRGBA8, ifRGB10A2];
+ aData^ := aPixel.Red;
+ inc(aData);
+ aData^ := aPixel.Green;
+ inc(aData);
+ aData^ := aPixel.Blue;
+ inc(aData);
end;
-
-function FormatIsEmpty(Format: TglBitmapInternalFormat): boolean;
+class procedure TfdRGB8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
begin
- Result := Format = ifEmpty;
+ aPixel.Red := aData^;
+ inc(aData);
+ aPixel.Green := aData^;
+ inc(aData);
+ aPixel.Blue := aData^;
+ inc(aData);
+ aPixel.Alpha := 0;
end;
+{$ENDREGION}
-
-function FormatHasAlpha(Format: TglBitmapInternalFormat): Boolean;
+{$REGION TfdRGBA8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdRGBA8////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdRGBA8.GetFormat: TglBitmapFormat;
begin
- Result := Format in [ifDXT1, ifDXT3, ifDXT5 ,ifAlpha, ifLuminanceAlpha, ifRGBA4, ifRGB5A1, ifBGRA8, ifRGBA8, ifRGB10A2];
+ result := tfRGBA8;
end;
-
-procedure FormatPreparePixel(var Pixel: TglBitmapPixelData; Format: TglBitmapInternalFormat);
+class function TfdRGBA8.GetPixelDesc: TglBitmapPixelDesc;
begin
- FillChar(Pixel, SizeOf(Pixel), #0);
+ with result do begin
+ RedRange := $000000FF; RedShift := 0;
+ GreenRange := $000000FF; GreenShift := 8;
+ BlueRange := $000000FF; BlueShift := 16;
+ AlphaRange := $000000FF; AlphaShift := 24;
+ end;
+end;
- case Format of
- ifAlpha:
- Pixel.PixelDesc := PIXEL_DESC_ALPHA;
- ifLuminance:
- Pixel.PixelDesc := PIXEL_DESC_LUMINANCE;
- ifDepth8:
- Pixel.PixelDesc := PIXEL_DESC_DEPTH8;
- ifLuminanceAlpha:
- Pixel.PixelDesc := PIXEL_DESC_LUMINANCEALPHA;
- ifRGBA4:
- Pixel.PixelDesc := PIXEL_DESC_RGBA4;
- ifR5G6B5:
- Pixel.PixelDesc := PIXEL_DESC_R5G6B5;
- ifRGB5A1:
- Pixel.PixelDesc := PIXEL_DESC_RGB5A1;
- ifDXT1, ifDXT3, ifDXT5, ifBGRA8:
- Pixel.PixelDesc := PIXEL_DESC_BGRA8;
- ifBGR8:
- Pixel.PixelDesc := PIXEL_DESC_BGR8;
- ifRGB8:
- Pixel.PixelDesc := PIXEL_DESC_RGB8;
- ifRGBA8:
- Pixel.PixelDesc := PIXEL_DESC_RGBA8;
- ifRGB10A2:
- Pixel.PixelDesc := PIXEL_DESC_RGB10A2;
+class function TfdRGBA8.GetFormatDesc: TglBitmapFormatDesc;
+begin
+ with result do begin
+ Format := GL_RGB;
+ InternalFormat := GL_RGB8;
+ DataType := GL_UNSIGNED_BYTE;
end;
+end;
- Pixel.Red := Pixel.PixelDesc.RedRange;
- Pixel.Green := Pixel.PixelDesc.GreenRange;
- Pixel.Blue := Pixel.PixelDesc.BlueRange;
- Pixel.Alpha := Pixel.PixelDesc.AlphaRange;
+class function TfdRGBA8.WithoutAlpha: TglBitmapFormat;
+begin
+ result := tfRGB8;
end;
+class procedure TfdRGBA8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
+begin
+ aData^ := aPixel.Red;
+ inc(aData);
+ aData^ := aPixel.Green;
+ inc(aData);
+ aData^ := aPixel.Blue;
+ inc(aData);
+ aData^ := aPixel.Alpha;
+ inc(aData);
+end;
-function FormatGetWithoutAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat;
+class procedure TfdRGBA8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
begin
- case Format of
- ifAlpha:
- Result := ifLuminance;
- ifLuminanceAlpha:
- Result := ifLuminance;
- ifRGBA4:
- Result := ifR5G6B5;
- ifRGB5A1:
- Result := ifR5G6B5;
- ifBGRA8:
- Result := ifBGR8;
- ifRGBA8:
- Result := ifRGB8;
- ifRGB10A2:
- Result := ifRGB8;
- else
- Result := Format;
- end;
+ aPixel.Red := aData^;
+ inc(aData);
+ aPixel.Green := aData^;
+ inc(aData);
+ aPixel.Blue := aData^;
+ inc(aData);
+ aPixel.Alpha := aData^;
+ inc(aData);
end;
+{$ENDREGION}
+{$REGION TfdBGR8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdBGR8/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdBGR8.GetFormat: TglBitmapFormat;
+begin
+ result := tfBGR8;
+end;
-function FormatGetWithAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat;
+class function TfdBGR8.GetPixelDesc: TglBitmapPixelDesc;
begin
- case Format of
- ifLuminance:
- Result := ifLuminanceAlpha;
- ifR5G6B5:
- Result := ifRGB5A1;
- ifBGR8:
- Result := ifBGRA8;
- ifRGB8:
- Result := ifRGBA8;
- else
- Result := Format;
+ with result do begin
+ RedRange := $000000FF; RedShift := 16;
+ GreenRange := $000000FF; GreenShift := 8;
+ BlueRange := $000000FF; BlueShift := 0;
+ AlphaRange := $00000000; AlphaShift := 0;
end;
end;
-
-function FormatGetUncompressed(Format: TglBitmapInternalFormat): TglBitmapInternalFormat;
+class function TfdBGR8.GetFormatDesc: TglBitmapFormatDesc;
begin
- case Format of
- ifDXT1:
- Result := ifRGB5A1;
- ifDXT3:
- Result := ifRGBA8;
- ifDXT5:
- Result := ifRGBA8;
- else
- Result := Format;
+ with result do begin
+ Format := GL_BGR;
+ InternalFormat := GL_RGB8;
+ DataType := GL_UNSIGNED_BYTE;
end;
end;
-
-function FormatGetImageSize(Size: TglBitmapPixelPosition; Format: TglBitmapInternalFormat): Integer;
+class function TfdBGR8.WithAlpha: TglBitmapFormat;
begin
- if (Size.X = 0) and (Size.Y = 0) then
- Result := 0
- else
- Result := Trunc(Max(Size.Y, 1) * Max(Size.X, 1) * FormatGetSize(Format));
+ result := tfBGRA8;
end;
-
-function FormatGetSupportedFiles(Format: TglBitmapInternalFormat): TglBitmapFileTypes;
+class procedure TfdBGR8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
begin
- Result := [];
-
- {$ifdef GLB_SUPPORT_PNG_WRITE}
- if Format in [ifLuminance, ifAlpha, ifDepth8, ifLuminanceAlpha, ifBGR8, ifBGRA8, ifRGB8, ifRGBA8] then
- Result := Result + [ftPNG];
- {$endif}
-
- {$ifdef GLB_SUPPORT_JPEG_WRITE}
- if Format in [ifLuminance, ifAlpha, ifDepth8, ifRGB8, ifBGR8] then
- Result := Result + [ftJPEG];
- {$endif}
-
- Result := Result + [ftDDS];
-
- if Format in [ifLuminance, ifAlpha, ifDepth8, ifLuminanceAlpha, ifBGR8, ifRGB8, ifBGRA8, ifRGBA8] then
- Result := Result + [ftTGA];
+ aData^ := aPixel.Blue;
+ inc(aData);
+ aData^ := aPixel.Green;
+ inc(aData);
+ aData^ := aPixel.Red;
+ inc(aData);
+end;
- if Format in [ifLuminance, ifAlpha, ifDepth8, ifLuminanceAlpha, ifRGBA4, ifRGB5A1, ifR5G6B5, ifRGB8, ifBGR8, ifRGBA8, ifBGRA8, ifRGB10A2] then
- Result := Result + [ftBMP];
+class procedure TfdBGR8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
+begin
+ aPixel.Blue := aData^;
+ inc(aData);
+ aPixel.Green := aData^;
+ inc(aData);
+ aPixel.Red := aData^;
+ inc(aData);
end;
+{$ENDREGION}
+{$REGION TfdBGRA8}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdBGRA8////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TfdBGRA8.GetFormat: TglBitmapFormat;
+begin
+ result := tfBGRA8;
+end;
-function FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask: Cardinal; Format: TglBitmapInternalFormat): boolean;
-var
- Pix: TglBitmapPixelData;
+class function TfdBGRA8.GetPixelDesc: TglBitmapPixelDesc;
begin
- Result := False;
+ with result do begin
+ RedRange := $000000FF; RedShift := 16;
+ GreenRange := $000000FF; GreenShift := 8;
+ BlueRange := $000000FF; BlueShift := 0;
+ AlphaRange := $000000FF; AlphaShift := 24;
+ end;
+end;
- if (RedMask = 0) and (GreenMask = 0) and (BlueMask = 0) and (AlphaMask = 0) then
- raise EglBitmapException.Create('FormatCheckFormat - All Masks are 0');
+class function TfdBGRA8.GetFormatDesc: TglBitmapFormatDesc;
+begin
+ with result do begin
+ Format := GL_BGRA;
+ InternalFormat := GL_RGBA8;
+ DataType := GL_UNSIGNED_BYTE;
+ end;
+end;
- FormatPreparePixel(Pix, Format);
+class function TfdBGRA8.WithoutAlpha: TglBitmapFormat;
+begin
+ result := tfBGR8;
+end;
- with Pix.PixelDesc do begin
- if RedMask <> 0 then
- if (RedMask <> (RedRange shl RedShift)) then
- Exit;
+class procedure TfdBGRA8.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte);
+begin
+ aData^ := aPixel.Blue;
+ inc(aData);
+ aData^ := aPixel.Green;
+ inc(aData);
+ aData^ := aPixel.Red;
+ inc(aData);
+ aData^ := aPixel.Alpha;
+ inc(aData);
+end;
- if GreenMask <> 0 then
- if (GreenMask <> (GreenRange shl GreenShift)) then
- Exit;
+class procedure TfdBGRA8.Unmap(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData);
+begin
+ aPixel.Blue := aData^;
+ inc(aData);
+ aPixel.Green := aData^;
+ inc(aData);
+ aPixel.Red := aData^;
+ inc(aData);
+ aPixel.Alpha := aData^;
+ inc(aData);
+end;
+{$ENDREGION}
- if BlueMask <> 0 then
- if (BlueMask <> (BlueRange shl BlueShift)) then
- Exit;
+{$REGION TglBitmap }
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TglBitmap///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.GetHeight: Integer;
+begin
+ if (ffY in fDimension.Fields) then
+ result := fDimension.Y
+ else
+ result := -1;
+end;
- if AlphaMask <> 0 then
- if (AlphaMask <> (AlphaRange shl AlphaShift)) then
- Exit;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.GetWidth: Integer;
+begin
+ if (ffX in fDimension.Fields) then
+ result := fDimension.X
+ else
+ result := -1;
+end;
- Result := True;
- end;
+{$REGION Setter}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetCustomData(const aValue: Pointer);
+begin
+ if fCustomData = aValue then
+ exit;
+ fCustomData := aValue;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetCustomName(const aValue: String);
+begin
+ if fCustomName = aValue then
+ exit;
+ fCustomName := aValue;
+end;
-function IsPowerOfTwo(Number: Integer): Boolean;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetCustomNameW(const aValue: WideString);
begin
- while Number and 1 = 0 do
- Number := Number shr 1;
+ if fCustomNameW = aValue then
+ exit;
+ fCustomNameW := aValue;
+end;
- Result := Number = 1;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetDeleteTextureOnFree(const aValue: Boolean);
+begin
+ if fDeleteTextureOnFree = aValue then
+ exit;
+ fDeleteTextureOnFree := aValue;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetFormat(const aValue: TglBitmapFormat);
+begin
+ if fFormat = aValue then
+ exit;
+ fFormat := aValue;
+end;
-function GetBitSize(BitSet: Cardinal): Integer;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetFreeDataAfterGenTexture(const aValue: Boolean);
begin
- Result := 0;
+ if fFreeDataAfterGenTexture = aValue then
+ exit;
+ fFreeDataAfterGenTexture := aValue;
+end;
- while BitSet > 0 do begin
- if (BitSet and $1) = 1 then
- Inc(Result);
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetID(const aValue: Cardinal);
+begin
+ if fID = aValue then
+ exit;
+ fID := aValue;
+end;
- BitSet := BitSet shr 1;
- end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetMipMap(const aValue: TglBitmapMipMap);
+begin
+ if fMipMap = aValue then
+ exit;
+ fMipMap := aValue;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetTarget(const aValue: Cardinal);
+begin
+ if fTarget = aValue then
+ exit;
+ fTarget := aValue;
+end;
-procedure SwapRGB(pData: pByte; Width: Integer; HasAlpha: Boolean);
-type
- PRGBPix = ^TRGBPix;
- TRGBPix = array [0..2] of byte;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetAnisotropic(const aValue: Integer);
var
- Temp: Byte;
+ MaxAnisotropic: Integer;
begin
- while Width > 0 do begin
- Temp := pRGBPIX(pData)^[0];
- pRGBPIX(pData)^[0] := pRGBPIX(pData)^[2];
- pRGBPIX(pData)^[2] := Temp;
-
- if HasAlpha then
- Inc(pData, 4)
- else
- Inc(pData, 3);
-
- Dec(Width);
+ fAnisotropic := Value;
+ if (ID > 0) then begin
+ if GL_EXT_texture_filter_anisotropic then begin
+ if fAnisotropic > 0 then begin
+ Bind(False);
+ glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, @MaxAnisotropic);
+ if aValue > MaxAnisotropic then
+ fAnisotropic := MaxAnisotropic;
+ glTexParameteri(Target, GL_TEXTURE_MAX_ANISOTROPY_EXT, fAnisotropic);
+ end;
+ end else begin
+ fAnisotropic := 0;
+ end;
end;
end;
+{$ENDREGION}
-
-{$ifdef GLB_DELPHI}
-function CreateGrayPalette: HPALETTE;
-var
- Idx: Integer;
- Pal: PLogPalette;
+procedure TglBitmap.AfterConstruction;
begin
- GetMem(Pal, SizeOf(TLogPalette) + (SizeOf(TPaletteEntry) * 256));
-
- Pal.palVersion := $300;
- Pal.palNumEntries := 256;
-
- {$IFOPT R+}
- {$DEFINE GLB_TEMPRANGECHECK}
- {$R-}
- {$ENDIF}
+ inherited AfterConstruction;
- for Idx := 0 to 256 - 1 do begin
- Pal.palPalEntry[Idx].peRed := Idx;
- Pal.palPalEntry[Idx].peGreen := Idx;
- Pal.palPalEntry[Idx].peBlue := Idx;
- Pal.palPalEntry[Idx].peFlags := 0;
- end;
-
- {$IFDEF GLB_TEMPRANGECHECK}
- {$UNDEF GLB_TEMPRANGECHECK}
- {$R+}
- {$ENDIF}
+ fID := 0;
+ fTarget := 0;
+ fIsResident := False;
- Result := CreatePalette(Pal^);
+ fFormat := glBitmapGetDefaultFormat;
+ fMipMap := glBitmapDefaultMipmap;
+ fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture;
+ fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree;
- FreeMem(Pal);
+ glBitmapGetDefaultFilter (fFilterMin, fFilterMag);
+ glBitmapGetDefaultTextureWrap(fWrapS, fWrapT, fWrapR);
end;
-{$endif}
-
-{$ifdef GLB_SDL_IMAGE}
-function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.BeforeDestruction;
begin
- Result := TStream(context^.unknown.data1).Seek(offset, whence);
+ SetDataPointer(nil, ifEmpty);
+ if (ID > 0) and fDeleteTextureOnFree then
+ glDeleteTextures(1, @ID);
+ inherited BeforeDestruction;
end;
-
-function glBitmapRWread(context: PSDL_RWops; Ptr: Pointer; size: Integer; maxnum : Integer): Integer; cdecl;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.CreateID;
begin
- Result := TStream(context^.unknown.data1).Read(Ptr^, size * maxnum);
+ if ID <> 0 then
+ glDeleteTextures(1, @ID);
+ glGenTextures(1, @ID);
+ Bind(false);
end;
-
-function glBitmapRWwrite(context: PSDL_RWops; Ptr: Pointer; size: Integer; num: Integer): Integer; cdecl;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetupParameters(var aBuildWithGlu: Boolean);
begin
- Result := TStream(context^.unknown.data1).Write(Ptr^, size * num);
-end;
-
+ // Set Up Parameters
+ SetWrap(fWrapS, fWrapT, fWrapR);
+ SetFilter(fFilterMin, fFilterMag);
+ SetAnisotropic(fAnisotropic);
+ SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]);
-function glBitmapRWclose(context: PSDL_RWops): Integer; cdecl;
-begin
- Result := 0;
+ // Mip Maps Generation Mode
+ aBuildWithGlu := False;
+ if (MipMap = mmMipmap) then begin
+ if (GL_VERSION_1_4 or GL_SGIS_generate_mipmap) then
+ glTexParameteri(Target, GL_GENERATE_MIPMAP, GL_TRUE)
+ else
+ BuildWithGlu := True;
+ end else if (MipMap = mmMipmapGlu) then
+ BuildWithGlu := True;
end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SelectFormat(const aFormat: TglBitmapFormat; var glFormat, glInternalFormat, glType: Cardinal);
+
+ procedure Check12;
+ begin
+ if not GL_VERSION_1_2 then
+ raise EglBitmapUnsupportedFormatFormat.Create('SelectFormat - You need at least OpenGL 1.2 to support these format.');
+ end;
-function glBitmapCreateRWops(Stream: TStream): PSDL_RWops;
begin
- Result := SDL_AllocRW;
+ PIXEL_DESC_ALPHA12;
+ glType := GL_UNSIGNED_BYTE;
+ glInternalFormat := Cardinal(aFormat);
- if Result = nil then
- raise EglBitmapException.Create('glBitmapCreateRWops - SDL_AllocRW failed.');
+ case aFormat of
+ tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16:
+ glFormat := GL_ALPHA;
- Result^.seek := glBitmapRWseek;
- Result^.read := glBitmapRWread;
- Result^.write := glBitmapRWwrite;
- Result^.close := glBitmapRWclose;
- Result^.unknown.data1 := Stream;
-end;
-{$endif}
+ tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16:
+ glFormat := GL_LUMINANCE;
+ tfuminance4Alpha4, tfLuminance6Alpha2, tfLuminance8Alpha8,
+ tfLuminance12Alpha4, tfLuminance12Alpha12, tfLuminance16Alpha16:
+ glFormat := GL_LUMINANCE_ALPHA;
-{*
-** Helper functions
-*}
-function LoadTexture(Filename: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$endif}): Boolean;
-var
- glBitmap: TglBitmap2D;
-begin
- Result := false;
- Texture := 0;
+ tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16:
+ glFormat := GL_RGB;
- {$ifdef GLB_DELPHI}
- if Instance = 0 then
- Instance := HInstance;
+ tfRGBA2, tfRGBA4, tfRGB5A1, tfRGBA8, tfRGB10A2, tfRGBA12, tfRGBA16:
+ glFormat := GL_RGBA;
- if (LoadFromRes) then
- glBitmap := TglBitmap2D.CreateFromResourceName(Instance, FileName)
+ tfDepth16, tfDepth24, tfDepth32:
+ glFormat := GL_DEPTH_COMPONENT;
else
- {$endif}
- glBitmap := TglBitmap2D.Create(FileName);
-
- try
- glBitmap.DeleteTextureOnFree := False;
- glBitmap.FreeDataAfterGenTexture := False;
- glBitmap.GenTexture(True);
- if (glBitmap.ID > 0) then begin
- Texture := glBitmap.ID;
- Result := True;
- end;
- finally
- glBitmap.Free;
+ glFormat := 0;
end;
-end;
-
-
-function LoadCubeMap(PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$endif}): Boolean;
-var
- CM: TglBitmapCubeMap;
-begin
- Texture := 0;
-
- {$ifdef GLB_DELPHI}
- if Instance = 0 then
- Instance := HInstance;
- {$endif}
-
- CM := TglBitmapCubeMap.Create;
- try
- CM.DeleteTextureOnFree := False;
- // Maps
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, PositiveX)
- else
- {$endif}
- CM.LoadFromFile(PositiveX);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_X);
-
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, NegativeX)
- else
- {$endif}
- CM.LoadFromFile(NegativeX);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_X);
-
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, PositiveY)
- else
- {$endif}
- CM.LoadFromFile(PositiveY);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
+ case aFormat of
+ tfRGBA4:
+ glType := GL_UNSIGNED_SHORT_4_4_4_4;
+ tfRGB5A1:
+ glType := GL_UNSIGNED_SHORT_5_5_5_1;
+ tfRG
+ end;
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, NegativeY)
- else
- {$endif}
- CM.LoadFromFile(NegativeY);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y);
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, PositiveZ)
- else
- {$endif}
- CM.LoadFromFile(PositiveZ);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
-
- {$ifdef GLB_DELPHI}
- if (LoadFromRes) then
- CM.LoadFromResource(Instance, NegativeZ)
+ // selecting Format
+ case DataFormat of
+ ifAlpha:
+ glFormat := GL_ALPHA;
+ ifLuminance:
+ glFormat := GL_LUMINANCE;
+ ifDepth8:
+ glFormat := GL_DEPTH_COMPONENT;
+ ifLuminanceAlpha:
+ glFormat := GL_LUMINANCE_ALPHA;
+ ifBGR8:
+ begin
+ if (GL_VERSION_1_2 or GL_EXT_bgra) then begin
+ glFormat := GL_BGR;
+ end else begin
+ if CanConvertImage then
+ ConvertTo(tfRGB8);
+ glFormat := GL_RGB;
+ end;
+ end;
+ ifBGRA8:
+ begin
+ if (GL_VERSION_1_2 or GL_EXT_bgra) then begin
+ glFormat := GL_BGRA;
+ end else begin
+ if CanConvertImage then
+ ConvertTo(tfRGBA8);
+ glFormat := GL_RGBA;
+ end;
+ end;
+ tfRGB8:
+ glFormat := GL_RGB;
+ tfRGBA8:
+ glFormat := GL_RGBA;
+ tfRGBA4:
+ begin
+ Check12;
+ glFormat := GL_BGRA;
+ glType := GL_UNSIGNED_SHORT_4_4_4_4_REV;
+ end;
+ tfRGB5A1:
+ begin
+ Check12;
+ glFormat := GL_BGRA;
+ glType := GL_UNSIGNED_SHORT_1_5_5_5_REV;
+ end;
+ tfRGB10A2:
+ begin
+ Check12;
+ glFormat := GL_BGRA;
+ glType := GL_UNSIGNED_INT_2_10_10_10_REV;
+ end;
+ ifR5G6B5:
+ begin
+ Check12;
+ glFormat := GL_RGB;
+ glType := GL_UNSIGNED_SHORT_5_6_5;
+ end;
else
- {$endif}
- CM.LoadFromFile(NegativeZ);
- CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z);
-
- Texture := CM.ID;
- Result := True;
- finally
- CM.Free;
+ glFormat := 0;
end;
-end;
-
-
-function LoadNormalMap(Size: Integer; var Texture: Cardinal): Boolean;
-var
- NM: TglBitmapNormalMap;
-begin
- Texture := 0;
-
- NM := TglBitmapNormalMap.Create;
- try
- NM.DeleteTextureOnFree := False;
- NM.GenerateNormalMap(Size);
- Texture := NM.ID;
- Result := True;
- finally
- NM.Free;
+ // Selecting InternalFormat
+ case DataFormat of
+ ifDXT1, ifDXT3, ifDXT5:
+ begin
+ if GL_EXT_texture_compression_s3tc then begin
+ case DataFormat of
+ ifDXT1:
+ glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
+ ifDXT3:
+ glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
+ ifDXT5:
+ glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
+ end;
+ end else begin
+ // Compression isn't supported so convert to RGBA
+ if CanConvertImage then
+ ConvertTo(tfRGBA8);
+ glFormat := GL_RGBA;
+ glInternalFormat := GL_RGBA8;
+ end;
+ end;
+ ifAlpha:
+ begin
+ case Format of
+ tf4BitsPerChanel:
+ glInternalFormat := GL_ALPHA4;
+ tf8BitsPerChanel:
+ glInternalFormat := GL_ALPHA8;
+ tfCompressed:
+ begin
+ if (GL_ARB_texture_compression or GL_VERSION_1_3) then
+ glInternalFormat := GL_COMPRESSED_ALPHA
+ else
+ glInternalFormat := GL_ALPHA;
+ end;
+ else
+ glInternalFormat := GL_ALPHA;
+ end;
+ end;
+ ifLuminance:
+ begin
+ case Format of
+ tf4BitsPerChanel:
+ glInternalFormat := GL_LUMINANCE4;
+ tf8BitsPerChanel:
+ glInternalFormat := GL_LUMINANCE8;
+ tfCompressed:
+ begin
+ if (GL_ARB_texture_compression or GL_VERSION_1_3) then
+ glInternalFormat := GL_COMPRESSED_LUMINANCE
+ else
+ glInternalFormat := GL_LUMINANCE;
+ end;
+ else
+ glInternalFormat := GL_LUMINANCE;
+ end;
+ end;
+ ifDepth8:
+ begin
+ glInternalFormat := GL_DEPTH_COMPONENT;
+ end;
+ ifLuminanceAlpha:
+ begin
+ case Format of
+ tf4BitsPerChanel:
+ glInternalFormat := GL_LUMINANCE4_ALPHA4;
+ tf8BitsPerChanel:
+ glInternalFormat := GL_LUMINANCE8_ALPHA8;
+ tfCompressed:
+ begin
+ if (GL_ARB_texture_compression or GL_VERSION_1_3) then
+ glInternalFormat := GL_COMPRESSED_LUMINANCE_ALPHA
+ else
+ glInternalFormat := GL_LUMINANCE_ALPHA;
+ end;
+ else
+ glInternalFormat := GL_LUMINANCE_ALPHA;
+ end;
+ end;
+ ifBGR8, tfRGB8:
+ begin
+ case Format of
+ tf4BitsPerChanel:
+ glInternalFormat := GL_RGB4;
+ tf8BitsPerChanel:
+ glInternalFormat := GL_RGB8;
+ tfCompressed:
+ begin
+ if (GL_ARB_texture_compression or GL_VERSION_1_3) then begin
+ glInternalFormat := GL_COMPRESSED_RGB
+ end else begin
+ if (GL_EXT_texture_compression_s3tc) then
+ glInternalFormat := GL_COMPRESSED_RGB_S3TC_DXT1_EXT
+ else
+ glInternalFormat := GL_RGB;
+ end;
+ end;
+ else
+ glInternalFormat := GL_RGB;
+ end;
+ end;
+ ifBGRA8, tfRGBA8, tfRGBA4, tfRGB5A1, tfRGB10A2, ifR5G6B5:
+ begin
+ case Format of
+ tf4BitsPerChanel:
+ glInternalFormat := GL_RGBA4;
+ tf8BitsPerChanel:
+ glInternalFormat := GL_RGBA8;
+ tfCompressed:
+ begin
+ if (GL_ARB_texture_compression or GL_VERSION_1_3) then begin
+ glInternalFormat := GL_COMPRESSED_RGBA
+ end else begin
+ if (GL_EXT_texture_compression_s3tc) then
+ glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
+ else
+ glInternalFormat := GL_RGBA;
+ end;
+ end;
+ else
+ glInternalFormat := GL_RGBA;
+ end;
+ end;
end;
end;
-{*
-** Defaults
-*}
-procedure glBitmapSetDefaultFormat(Format: TglBitmapFormat);
-begin
- glBitmapDefaultFormat := Format;
-end;
-procedure glBitmapSetDefaultDeleteTextureOnFree(DeleteTextureOnFree: Boolean);
-begin
- glBitmapDefaultDeleteTextureOnFree := DeleteTextureOnFree;
-end;
-procedure glBitmapSetDefaultFilter(Min, Mag: Integer);
-begin
- glBitmapDefaultFilterMin := Min;
- glBitmapDefaultFilterMag := Mag;
-end;
-
-
-procedure glBitmapSetDefaultWrap(S: Integer; T: Integer; R: Integer);
-begin
- glBitmapDefaultWrapS := S;
- glBitmapDefaultWrapT := T;
- glBitmapDefaultWrapR := R;
-end;
-
-
-procedure glBitmapSetDefaultFreeDataAfterGenTexture(FreeData: Boolean);
-begin
- glBitmapDefaultFreeDataAfterGenTextures := FreeData;
-end;
-
-function glBitmapGetDefaultFormat: TglBitmapFormat;
-begin
- Result := glBitmapDefaultFormat;
-end;
-function glBitmapGetDefaultDeleteTextureOnFree: Boolean;
-begin
- Result := glBitmapDefaultDeleteTextureOnFree;
-end;
-procedure glBitmapGetDefaultFilter(var Min, Mag: Integer);
-begin
- Min := glBitmapDefaultFilterMin;
- Mag := glBitmapDefaultFilterMag;
-end;
-procedure glBitmapGetDefaultTextureWrap(var S, T, R: Integer);
-begin
- S := glBitmapDefaultWrapS;
- T := glBitmapDefaultWrapT;
- R := glBitmapDefaultWrapR;
-end;
-function glBitmapGetDefaultFreeDataAfterGenTexture: Boolean;
-begin
- Result := glBitmapDefaultFreeDataAfterGenTextures;
-end;
-
-
-{ TglBitmap }
-
-procedure TglBitmap.AfterConstruction;
-begin
- inherited;
-
- fID := 0;
- fTarget := 0;
- fMipMap := mmMipmap;
- fIsResident := False;
-
- // get defaults
- fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture;
- fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree;
-
- fFormat := glBitmapGetDefaultFormat;
-
- glBitmapGetDefaultFilter(fFilterMin, fFilterMag);
- glBitmapGetDefaultTextureWrap(fWrapS, fWrapT, fWrapR);
-end;
-
-
-procedure TglBitmap.BeforeDestruction;
-begin
- SetDataPointer(nil, ifEmpty);
-
- if ((ID > 0) and (fDeleteTextureOnFree)) then
- glDeleteTextures(1, @ID);
-
- inherited;
-end;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TglBitmap.Create;
begin
- {$ifndef GLB_NO_NATIVE_GL}
+ {$IFNDEF GLB_NO_NATIVE_GL}
ReadOpenGLExtensions;
- {$endif}
+ {$ENDIF}
if (ClassType = TglBitmap) then
raise EglBitmapException.Create('Don''t create TglBitmap directly. Use one of the deviated classes (TglBitmap2D) instead.');
end;
-{$ifdef GLB_DELPHI}
+{$IFDEF GLB_DELPHI}
constructor TglBitmap.CreateFromResourceName(Instance: Cardinal; Resource: String; ResType: PChar);
begin
Create;
Create;
LoadFromResourceID(Instance, ResourceID, ResType);
end;
-{$endif}
+{$ENDIF}
constructor TglBitmap.Create(Size: TglBitmapPixelPosition;
- Format: TglBitmapInternalFormat);
+ Format: TglBitmapFormat);
var
Image: pByte;
ImageSize: Integer;
constructor TglBitmap.Create(Size: TglBitmapPixelPosition;
- Format: TglBitmapInternalFormat; Func: TglBitmapFunction; CustomData: Pointer);
+ Format: TglBitmapFormat; Func: TglBitmapFunction; CustomData: Pointer);
begin
Create;
LoadFromFunc(Size, Func, Format, CustomData);
end;
-procedure TglBitmap.LoadFromFile(FileName: String);
+procedure TglBitmap.LoadFromFile(const aFileName: String);
var
FS: TFileStream;
begin
end;
-procedure TglBitmap.LoadFromStream(Stream: TStream);
+procedure TglBitmap.LoadFromStream(const aStream: TStream);
begin
- {$ifdef GLB_SUPPORT_PNG_READ}
+ {$IFDEF GLB_SUPPORT_PNG_READ}
if not LoadPNG(Stream) then
- {$endif}
- {$ifdef GLB_SUPPORT_JPEG_READ}
+ {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_READ}
if not LoadJPEG(Stream) then
- {$endif}
+ {$ENDIF}
if not LoadDDS(Stream) then
if not LoadTGA(Stream) then
if not LoadBMP(Stream) then
end;
-{$ifdef GLB_DELPHI}
+{$IFDEF GLB_DELPHI}
procedure TglBitmap.LoadFromResource(Instance: Cardinal; Resource: String; ResType: PChar);
var
RS: TResourceStream;
RS.Free;
end;
end;
-{$endif}
+{$ENDIF}
-procedure TglBitmap.LoadFromFunc(Size: TglBitmapPixelPosition;
- Func: TglBitmapFunction; Format: TglBitmapInternalFormat; CustomData: Pointer);
+procedure TglBitmap.LoadFromFunc(const aSize: TglBitmapPixelPosition;
+ const aFunc: TglBitmapFunction; const aFormat: TglBitmapFormat;
+ const aArgs: PtrInt);
var
Image: pByte;
ImageSize: Integer;
end;
-procedure TglBitmap.SaveToFile(FileName: String; FileType: TglBitmapFileType);
+procedure TglBitmap.SaveToFile(const aFileName: String;
+ const aFileType: TglBitmapFileType);
var
FS: TFileStream;
begin
end;
-procedure TglBitmap.SaveToStream(Stream: TStream; FileType: TglBitmapFileType);
+procedure TglBitmap.SaveToStream(const aStream: TStream;
+ const aFileType: TglBitmapFileType);
begin
case FileType of
- {$ifdef GLB_SUPPORT_PNG_WRITE}
+ {$IFDEF GLB_SUPPORT_PNG_WRITE}
ftPNG: SavePng(Stream);
- {$endif}
- {$ifdef GLB_SUPPORT_JPEG_WRITE}
+ {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_WRITE}
ftJPEG: SaveJPEG(Stream);
- {$endif}
+ {$ENDIF}
ftDDS: SaveDDS(Stream);
ftTGA: SaveTGA(Stream);
ftBMP: SaveBMP(Stream);
end;
-{$ifdef GLB_SDL}
+{$IFDEF GLB_SDL}
function TglBitmap.AssignToSurface(out Surface: PSDL_Surface): boolean;
var
Row, RowSize: Integer;
glBitmap.Free;
end;
end;
-{$endif}
+{$ENDIF}
-{$ifdef GLB_DELPHI}
+{$IFDEF GLB_DELPHI}
function TglBitmap.AssignFromBitmap(const Bitmap: TBitmap): boolean;
var
pSource, pData, pTempData: PByte;
glBitmap.Free;
end;
end;
-{$endif}
+{$ENDIF}
function TglBitmap.AddAlphaFromFile(FileName: String; Func: TglBitmapFunction; CustomData: Pointer): boolean;
end;
-{$ifdef GLB_DELPHI}
+{$IFDEF GLB_DELPHI}
function TglBitmap.AddAlphaFromResource(Instance: Cardinal; Resource: String;
ResType: PChar; Func: TglBitmapFunction; CustomData: Pointer): boolean;
var
RS.Free;
end;
end;
-{$endif}
+{$ENDIF}
procedure glBitmapColorKeyAlphaFunc(var FuncRec: TglBitmapFunctionRec);
end;
-function TglBitmap.AddAlphaFromColorKey(Red, Green, Blue, Deviation: Byte): Boolean;
+function TglBitmap.AddAlphaFromColorKey(Red, Green, Blue: Byte; Deviation: Byte
+ ): Boolean;
begin
Result := AddAlphaFromColorKeyFloat(Red / $FF, Green / $FF, Blue / $FF, Deviation / $FF);
end;
end;
-procedure TglBitmap.Invert(UseRGB, UseAlpha: Boolean);
+procedure TglBitmap.Invert(UseRGB: Boolean; UseAlpha: Boolean);
begin
if ((UseRGB) or (UseAlpha)) then
AddFunc(glBitmapInvertFunc, False, Pointer(Integer(UseAlpha) shl 1 or Integer(UseRGB)));
end;
-procedure TglBitmap.SetFilter(Min, Mag: Integer);
+procedure TglBitmap.SetFilter(const aMin, aMag: Cardinal);
begin
case Min of
GL_NEAREST:
end;
-procedure TglBitmap.SetWrap(S: Integer; T: Integer; R: Integer);
+procedure TglBitmap.SetWrap(const S: Cardinal; const T: Cardinal;
+ const R: Cardinal);
begin
case S of
GL_CLAMP:
end;
-procedure TglBitmap.SetDataPointer(NewData: PByte; Format: TglBitmapInternalFormat; Width, Height: Integer);
+procedure TglBitmap.SetDataPointer(NewData: pByte;
+ Format: TglBitmapFormat; Width: Integer; Height: Integer);
begin
// Data
if Data <> NewData then begin
end;
end;
-{$ifdef GLB_SUPPORT_PNG_READ}
-{$ifdef GLB_LIB_PNG}
+{$IFDEF GLB_SUPPORT_PNG_READ}
+{$IFDEF GLB_LIB_PNG}
procedure glBitmap_libPNG_read_func(png: png_structp; buffer: png_bytep; size: cardinal); cdecl;
begin
TStream(png_get_io_ptr(png)).Read(buffer^, size);
end;
-{$endif}
+{$ENDIF}
function TglBitmap.LoadPNG(Stream: TStream): Boolean;
-{$ifdef GLB_SDL_IMAGE}
+{$IFDEF GLB_SDL_IMAGE}
var
Surface: PSDL_Surface;
RWops: PSDL_RWops;
SDL_FreeRW(RWops);
end;
end;
-{$endif}
-{$ifdef GLB_LIB_PNG}
+{$ENDIF}
+{$IFDEF GLB_LIB_PNG}
var
StreamPos: Int64;
signature: array [0..7] of byte;
quit_libPNG;
end;
end;
-{$endif}
-{$ifdef GLB_PNGIMAGE}
+{$ENDIF}
+{$IFDEF GLB_PNGIMAGE}
var
StreamPos: Int64;
Png: TPNGObject;
end;
end;
end;
-{$endif}
-{$endif}
+{$ENDIF}
+{$ENDIF}
-{$ifdef GLB_LIB_JPEG}
+{$IFDEF GLB_LIB_JPEG}
type
glBitmap_libJPEG_source_mgr_ptr = ^glBitmap_libJPEG_source_mgr;
glBitmap_libJPEG_source_mgr = record
dest^.DestStream.Write(dest^.DestBuffer[Idx], 1);
end;
end;
-{$endif}
+{$ENDIF}
-{$ifdef GLB_SUPPORT_JPEG_READ}
+{$IFDEF GLB_SUPPORT_JPEG_READ}
function TglBitmap.LoadJPEG(Stream: TStream): Boolean;
-{$ifdef GLB_SDL_IMAGE}
+{$IFDEF GLB_SDL_IMAGE}
var
Surface: PSDL_Surface;
RWops: PSDL_RWops;
SDL_FreeRW(RWops);
end;
end;
-{$endif}
-{$ifdef GLB_LIB_JPEG}
+{$ENDIF}
+{$IFDEF GLB_LIB_JPEG}
var
StreamPos: Int64;
Temp: array[0..1]of Byte;
quit_libJPEG;
end;
end;
-{$endif}
-{$ifdef GLB_DELPHI_JPEG}
+{$ENDIF}
+{$IFDEF GLB_DELPHI_JPEG}
var
bmp: TBitmap;
jpg: TJPEGImage;
end;
end;
end;
-{$endif}
-{$endif}
+{$ENDIF}
+{$ENDIF}
const
Info: TBMPInfo;
NewImage, pData: pByte;
- Format: TglBitmapInternalFormat;
+ Format: TglBitmapFormat;
LineSize, Padding, LineIdx: Integer;
RedMask, GreenMask, BlueMask, AlphaMask: Cardinal;
16:
begin
if (RedMask = 0) and (GreenMask = 0) and (BlueMask = 0) then begin
- Format := ifRGB5A1;
+ Format := tfRGB5A1;
end else begin
if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, ifLuminanceAlpha) then
Format := ifLuminanceAlpha;
- if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, ifRGBA4) then
- Format := ifRGBA4;
+ if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, tfRGBA4) then
+ Format := tfRGBA4;
- if FormatCheckFormat(RedMask, GreenMask, BlueMask, 0, ifRGB5A1) then
- Format := ifRGB5A1;
+ if FormatCheckFormat(RedMask, GreenMask, BlueMask, 0, tfRGB5A1) then
+ Format := tfRGB5A1;
if FormatCheckFormat(RedMask, GreenMask, BlueMask, 0, ifR5G6B5) then
Format := ifR5G6B5;
if (RedMask = 0) and (GreenMask = 0) and (BlueMask = 0) then begin
Format := ifBGRA8;
end else begin
- if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, ifRGBA8) then
- Format := ifRGBA8;
+ if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, tfRGBA8) then
+ Format := tfRGBA8;
if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, ifBGRA8) then
Format := ifBGRA8;
- if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, ifRGB10A2) then
- Format := ifRGB10A2;
+ if FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask, tfRGB10A2) then
+ Format := tfRGB10A2;
end;
end;
end;
end
else Stream.Position := StreamPos;
end;
-
+{$ENDREGION}
const
DDS_MAGIC = $20534444;
end;
+
function TglBitmap.LoadDDS(Stream: TStream): Boolean;
var
Header: TDDSHeader;
// MipMapCount, X, Y, XSize, YSize: Cardinal;
RowSize: Cardinal;
NewImage, pData: pByte;
- Format: TglBitmapInternalFormat;
+ Format: TglBitmapFormat;
function RaiseEx : Exception;
end;
- function GetInternalFormat: TglBitmapInternalFormat;
+ function GetInternalFormat: TglBitmapFormat;
begin
with Header.PixelFormat do begin
// Compresses
if dwFlags and DDPF_ALPHAPIXELS > 0 then begin
// Alpha
case GetBitSize(dwRBitMask) of
- 5: Result := ifRGB5A1;
- 4: Result := ifRGBA4;
+ 5: Result := tfRGB5A1;
+ 4: Result := tfRGBA4;
else
Result := ifLuminanceAlpha;
end;
if dwRBitMask > dwBBitMask then
Result := ifBGR8
else
- Result := ifRGB8;
+ Result := tfRGB8;
end;
32:
begin
if GetBitSize(dwRBitMask) = 10 then
- Result := ifRGB10A2
+ Result := tfRGB10A2
else
if dwRBitMask > dwBBitMask then
Result := ifBGRA8
else
- Result := ifRGBA8;
+ Result := tfRGBA8;
end;
else
raise RaiseEx;
NewImage, pData: PByte;
StreamPos: Int64;
PixelSize, LineSize, YStart, YEnd, YInc: Integer;
- Format: TglBitmapInternalFormat;
+ Format: TglBitmapFormat;
const
CACHE_SIZE = $4000;
end;
-{$ifdef GLB_SUPPORT_PNG_WRITE}
-{$ifdef GLB_LIB_PNG}
+{$IFDEF GLB_SUPPORT_PNG_WRITE}
+{$IFDEF GLB_LIB_PNG}
procedure glBitmap_libPNG_write_func(png: png_structp; buffer: png_bytep; size: cardinal); cdecl;
begin
TStream(png_get_io_ptr(png)).Write(buffer^, size);
end;
-{$endif}
+{$ENDIF}
procedure TglBitmap.SavePNG(Stream: TStream);
-{$ifdef GLB_LIB_PNG}
+{$IFDEF GLB_LIB_PNG}
var
png: png_structp;
png_info: png_infop;
quit_libPNG;
end;
end;
-{$endif}
-{$ifdef GLB_PNGIMAGE}
+{$ENDIF}
+{$IFDEF GLB_PNGIMAGE}
var
Png: TPNGObject;
FreeAndNil(Png);
end;
end;
-{$endif}
-{$endif}
+{$ENDIF}
+{$ENDIF}
procedure TglBitmap.SaveDDS(Stream: TStream);
Pix: TglBitmapPixelData;
begin
if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedInternalFormat.Create('SaveDDS - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SaveDDS - ' + UNSUPPORTED_INTERNAL_FORMAT);
if InternalFormat = ifAlpha then
FormatPreparePixel(Pix, ifLuminance)
begin
if not (ftTGA in FormatGetSupportedFiles (InternalFormat)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SaveTGA - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SaveTGA - ' + UNSUPPORTED_INTERNAL_FORMAT);
FillChar(Header, SizeOf(Header), 0);
Header.ImageType := TGA_UNCOMPRESSED_GRAY;
Header.Bpp := 16;
end;
- ifRGB8, ifBGR8:
+ tfRGB8, ifBGR8:
begin
Header.ImageType := TGA_UNCOMPRESSED_RGB;
Header.Bpp := 24;
end;
- ifRGBA8, ifBGRA8:
+ tfRGBA8, ifBGRA8:
begin
Header.ImageType := TGA_UNCOMPRESSED_RGB;
Header.Bpp := 32;
end;
else
- raise EglBitmapUnsupportedInternalFormat.Create('SaveTGA - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SaveTGA - ' + UNSUPPORTED_INTERNAL_FORMAT);
end;
Header.Width := Width;
// convert RGB(A) to BGR(A)
Size := FormatGetImageSize(glBitmapPosition(Width, Height), InternalFormat);
- if InternalFormat in [ifRGB8, ifRGBA8] then begin
+ if InternalFormat in [tfRGB8, tfRGBA8] then begin
GetMem(pTemp, Size);
end else
pTemp := Data;
try
// convert data
- if InternalFormat in [ifRGB8, ifRGBA8] then begin
+ if InternalFormat in [tfRGB8, tfRGBA8] then begin
Move(Data^, pTemp^, Size);
ConvertData(pTemp);
end;
Stream.Write(pTemp^, Size);
finally
// free tempdata
- if InternalFormat in [ifRGB8, ifRGBA8] then
+ if InternalFormat in [tfRGB8, tfRGBA8] then
FreeMem(pTemp);
end;
end;
-{$ifdef GLB_SUPPORT_JPEG_WRITE}
+{$IFDEF GLB_SUPPORT_JPEG_WRITE}
procedure TglBitmap.SaveJPEG(Stream: TStream);
-{$ifdef GLB_LIB_JPEG}
+{$IFDEF GLB_LIB_JPEG}
var
jpeg: jpeg_compress_struct;
jpeg_err: jpeg_error_mgr;
quit_libJPEG;
end;
end;
-{$endif}
-{$ifdef GLB_DELPHI_JPEG}
+{$ENDIF}
+{$IFDEF GLB_DELPHI_JPEG}
var
Bmp: TBitmap;
Jpg: TJPEGImage;
FreeAndNil(Bmp);
end;
end;
-{$endif}
-{$endif}
+{$ENDIF}
+{$ENDIF}
procedure TglBitmap.SaveBMP(Stream: TStream);
begin
if not (ftBMP in FormatGetSupportedFiles(InternalFormat)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SaveBMP - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_INTERNAL_FORMAT);
ImageSize := Trunc(Width * Height * FormatGetSize(InternalFormat));
Info.biClrUsed := 256;
Info.biClrImportant := 256;
end;
- ifLuminanceAlpha, ifRGBA4, ifR5G6B5, ifRGB5A1:
+ ifLuminanceAlpha, tfRGBA4, ifR5G6B5, tfRGB5A1:
begin
Info.biBitCount := 16;
Info.biCompression := BMP_COMP_BITFIELDS;
end;
- ifBGR8, ifRGB8:
+ ifBGR8, tfRGB8:
Info.biBitCount := 24;
- ifBGRA8, ifRGBA8, ifRGB10A2:
+ ifBGRA8, tfRGBA8, tfRGB10A2:
begin
Info.biBitCount := 32;
Info.biCompression := BMP_COMP_BITFIELDS;
end;
else
- raise EglBitmapUnsupportedInternalFormat.Create('SaveBMP - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_INTERNAL_FORMAT);
end;
Info.biXPelsPerMeter := 2835;
Info.biYPelsPerMeter := 2835;
// prepare row buffer. But only for RGB because RGBA supports color masks
// so it's possible to change color within the image.
- if InternalFormat = ifRGB8 then
+ if InternalFormat = tfRGB8 then
GetMem(pTemp, fRowSize)
else
pTemp := nil;
// write image data
for LineIdx := 0 to Height - 1 do begin
// preparing row
- if InternalFormat = ifRGB8 then begin
+ if InternalFormat = tfRGB8 then begin
Move(pData^, pTemp^, fRowSize);
SwapRGB(pTemp, Width, False);
end else
end;
finally
// destroy row buffer
- if InternalFormat = ifRGB8 then
+ if InternalFormat = tfRGB8 then
FreeMem(pTemp);
end;
end;
end;
-procedure TglBitmap.CreateID;
-begin
- // Generate Texture
- if ID <> 0 then
- glDeleteTextures(1, @ID);
-
- glGenTextures(1, @ID);
-
- Bind(False);
-end;
-
-
-procedure TglBitmap.SetupParameters(var BuildWithGlu: Boolean);
-begin
- // Set up parameters
- SetWrap(fWrapS, fWrapT, fWrapR);
- SetFilter(fFilterMin, fFilterMag);
- SetAnisotropic(fAnisotropic);
- SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]);
-
- // Mip Maps generation Mode
- BuildWithGlu := False;
-
- if (MipMap = mmMipmap) then begin
- if (GL_VERSION_1_4 or GL_SGIS_generate_mipmap) then
- glTexParameteri(Target, GL_GENERATE_MIPMAP, GL_TRUE)
- else
- BuildWithGlu := True;
- end else
- if (MipMap = mmMipmapGlu) then
- BuildWithGlu := True;
-end;
-
-
-procedure TglBitmap.SelectFormat(DataFormat: TglBitmapInternalFormat; var glFormat, glInternalFormat, glType: Cardinal; CanConvertImage: Boolean = True);
-
- procedure Check12;
- begin
- if not GL_VERSION_1_2 then
- raise EglBitmapUnsupportedInternalFormat.Create('SelectFormat - You need at least OpenGL 1.2 to support these format.');
- end;
-
-begin
- glType := GL_UNSIGNED_BYTE;
- // selecting Format
- case DataFormat of
- ifAlpha:
- glFormat := GL_ALPHA;
- ifLuminance:
- glFormat := GL_LUMINANCE;
- ifDepth8:
- glFormat := GL_DEPTH_COMPONENT;
- ifLuminanceAlpha:
- glFormat := GL_LUMINANCE_ALPHA;
- ifBGR8:
- begin
- if (GL_VERSION_1_2 or GL_EXT_bgra) then begin
- glFormat := GL_BGR;
- end else begin
- if CanConvertImage then
- ConvertTo(ifRGB8);
- glFormat := GL_RGB;
- end;
- end;
- ifBGRA8:
- begin
- if (GL_VERSION_1_2 or GL_EXT_bgra) then begin
- glFormat := GL_BGRA;
- end else begin
- if CanConvertImage then
- ConvertTo(ifRGBA8);
- glFormat := GL_RGBA;
- end;
- end;
- ifRGB8:
- glFormat := GL_RGB;
- ifRGBA8:
- glFormat := GL_RGBA;
- ifRGBA4:
- begin
- Check12;
- glFormat := GL_BGRA;
- glType := GL_UNSIGNED_SHORT_4_4_4_4_REV;
- end;
- ifRGB5A1:
- begin
- Check12;
- glFormat := GL_BGRA;
- glType := GL_UNSIGNED_SHORT_1_5_5_5_REV;
- end;
- ifRGB10A2:
- begin
- Check12;
- glFormat := GL_BGRA;
- glType := GL_UNSIGNED_INT_2_10_10_10_REV;
- end;
- ifR5G6B5:
- begin
- Check12;
- glFormat := GL_RGB;
- glType := GL_UNSIGNED_SHORT_5_6_5;
- end;
- else
- glFormat := 0;
- end;
- // Selecting InternalFormat
- case DataFormat of
- ifDXT1, ifDXT3, ifDXT5:
- begin
- if GL_EXT_texture_compression_s3tc then begin
- case DataFormat of
- ifDXT1:
- glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
- ifDXT3:
- glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
- ifDXT5:
- glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
- end;
- end else begin
- // Compression isn't supported so convert to RGBA
- if CanConvertImage then
- ConvertTo(ifRGBA8);
- glFormat := GL_RGBA;
- glInternalFormat := GL_RGBA8;
- end;
- end;
- ifAlpha:
- begin
- case Format of
- tf4BitsPerChanel:
- glInternalFormat := GL_ALPHA4;
- tf8BitsPerChanel:
- glInternalFormat := GL_ALPHA8;
- tfCompressed:
- begin
- if (GL_ARB_texture_compression or GL_VERSION_1_3) then
- glInternalFormat := GL_COMPRESSED_ALPHA
- else
- glInternalFormat := GL_ALPHA;
- end;
- else
- glInternalFormat := GL_ALPHA;
- end;
- end;
- ifLuminance:
- begin
- case Format of
- tf4BitsPerChanel:
- glInternalFormat := GL_LUMINANCE4;
- tf8BitsPerChanel:
- glInternalFormat := GL_LUMINANCE8;
- tfCompressed:
- begin
- if (GL_ARB_texture_compression or GL_VERSION_1_3) then
- glInternalFormat := GL_COMPRESSED_LUMINANCE
- else
- glInternalFormat := GL_LUMINANCE;
- end;
- else
- glInternalFormat := GL_LUMINANCE;
- end;
- end;
- ifDepth8:
- begin
- glInternalFormat := GL_DEPTH_COMPONENT;
- end;
- ifLuminanceAlpha:
- begin
- case Format of
- tf4BitsPerChanel:
- glInternalFormat := GL_LUMINANCE4_ALPHA4;
- tf8BitsPerChanel:
- glInternalFormat := GL_LUMINANCE8_ALPHA8;
- tfCompressed:
- begin
- if (GL_ARB_texture_compression or GL_VERSION_1_3) then
- glInternalFormat := GL_COMPRESSED_LUMINANCE_ALPHA
- else
- glInternalFormat := GL_LUMINANCE_ALPHA;
- end;
- else
- glInternalFormat := GL_LUMINANCE_ALPHA;
- end;
- end;
- ifBGR8, ifRGB8:
- begin
- case Format of
- tf4BitsPerChanel:
- glInternalFormat := GL_RGB4;
- tf8BitsPerChanel:
- glInternalFormat := GL_RGB8;
- tfCompressed:
- begin
- if (GL_ARB_texture_compression or GL_VERSION_1_3) then begin
- glInternalFormat := GL_COMPRESSED_RGB
- end else begin
- if (GL_EXT_texture_compression_s3tc) then
- glInternalFormat := GL_COMPRESSED_RGB_S3TC_DXT1_EXT
- else
- glInternalFormat := GL_RGB;
- end;
- end;
- else
- glInternalFormat := GL_RGB;
- end;
- end;
- ifBGRA8, ifRGBA8, ifRGBA4, ifRGB5A1, ifRGB10A2, ifR5G6B5:
- begin
- case Format of
- tf4BitsPerChanel:
- glInternalFormat := GL_RGBA4;
- tf8BitsPerChanel:
- glInternalFormat := GL_RGBA8;
- tfCompressed:
- begin
- if (GL_ARB_texture_compression or GL_VERSION_1_3) then begin
- glInternalFormat := GL_COMPRESSED_RGBA
- end else begin
- if (GL_EXT_texture_compression_s3tc) then
- glInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
- else
- glInternalFormat := GL_RGBA;
- end;
- end;
- else
- glInternalFormat := GL_RGBA;
- end;
- end;
- end;
-end;
function TglBitmap.FlipHorz: Boolean;
end;
-procedure TglBitmap.FillWithColor(Red, Green, Blue, Alpha: Byte);
+procedure TglBitmap.FillWithColor(Red, Green, Blue: Byte; Alpha: Byte);
begin
FillWithColorFloat(Red / $FF, Green / $FF, Blue / $FF, Alpha / $FF);
end;
-procedure TglBitmap.FillWithColorFloat(Red, Green, Blue, Alpha: Single);
+procedure TglBitmap.FillWithColorFloat(Red, Green, Blue: Single; Alpha: Single);
var
PixelData: TglBitmapPixelData;
begin
end;
-procedure TglBitmap.FillWithColorRange(Red, Green, Blue, Alpha: Cardinal);
+procedure TglBitmap.FillWithColorRange(Red, Green, Blue: Cardinal;
+ Alpha: Cardinal);
var
PixelData: TglBitmapPixelData;
begin
end;
-procedure TglBitmap.SetAnisotropic(const Value: Integer);
-var
- MaxAniso: Integer;
-begin
- fAnisotropic := Value;
-
- if (ID > 0) then begin
- if GL_EXT_texture_filter_anisotropic then begin
- if fAnisotropic > 0 then begin
- Bind(False);
-
- glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, @MaxAniso);
-
- if Value > MaxAniso then
- fAnisotropic := MaxAniso;
-
- glTexParameteri(Target, GL_TEXTURE_MAX_ANISOTROPY_EXT, fAnisotropic);
- end;
- end else begin
- fAnisotropic := 0;
- end;
- end;
-end;
-
-procedure TglBitmap.SetInternalFormat(const Value: TglBitmapInternalFormat);
+procedure TglBitmap.SetInternalFormat(const aValue: TglBitmapFormat);
begin
if InternalFormat <> Value then begin
if FormatGetSize(Value) <> FormatGetSize(InternalFormat) then
- raise EglBitmapUnsupportedInternalFormat.Create('SetInternalFormat - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('SetInternalFormat - ' + UNSUPPORTED_INTERNAL_FORMAT);
// Update whatever
SetDataPointer(Data, Value);
function TglBitmap.AddFunc(Source: TglBitmap; Func: TglBitmapFunction;
- CreateTemp: Boolean; Format: TglBitmapInternalFormat; CustomData: Pointer): boolean;
+ CreateTemp: Boolean; Format: TglBitmapFormat; CustomData: Pointer): boolean;
var
pDest, NewImage, pSource: pByte;
TempHeight, TempWidth: Integer;
end;
-function TglBitmap.ConvertTo(NewFormat: TglBitmapInternalFormat): boolean;
+function TglBitmap.ConvertTo(NewFormat: TglBitmapFormat): boolean;
var
Source, Dest: TglBitmapPixelData;
PixelDesc: TglBitmapPixelDesc;
if (Assigned(Data)) then begin
if not (FormatIsUncompressed(InternalFormat) or FormatHasAlpha(InternalFormat)) then
- raise EglBitmapUnsupportedInternalFormat.Create('RemoveAlpha - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('RemoveAlpha - ' + UNSUPPORTED_INTERNAL_FORMAT);
Result := ConvertTo(FormatGetWithoutAlpha(InternalFormat));
end;
function TglBitmap.AddAlphaFromFunc(Func: TglBitmapFunction; CustomData: Pointer): boolean;
begin
if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedInternalFormat.Create('AddAlphaFromFunc - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('AddAlphaFromFunc - ' + UNSUPPORTED_INTERNAL_FORMAT);
Result := AddFunc(Self, Func, False, FormatGetWithAlpha(InternalFormat), CustomData);
end;
-function TglBitmap.GetHeight: Integer;
-begin
- if ffY in fDimension.Fields then
- Result := fDimension.Y
- else
- Result := -1;
-end;
-
-
-function TglBitmap.GetWidth: Integer;
-begin
- if ffX in fDimension.Fields then
- Result := fDimension.X
- else
- Result := -1;
-end;
-
-
function TglBitmap.GetFileHeight: Integer;
begin
Result := Max(1, Height);
{ TglBitmap2D }
-procedure TglBitmap2D.SetDataPointer(Data: pByte; Format: TglBitmapInternalFormat; Width, Height: Integer);
+procedure TglBitmap2D.SetDataPointer(Data: pByte; Format: TglBitmapFormat; Width, Height: Integer);
var
Idx, LineWidth: Integer;
begin
begin
if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedInternalFormat.Create('TglBitmap2D.ToNormalMap - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('TglBitmap2D.ToNormalMap - ' + UNSUPPORTED_INTERNAL_FORMAT);
if Scale > 100 then
Rec.Scale := 100
end;
-procedure TglBitmap2D.GrabScreen(Top, Left, Right, Bottom: Integer; Format: TglBitmapInternalFormat);
+procedure TglBitmap2D.GrabScreen(Top, Left, Right, Bottom: Integer; Format: TglBitmapFormat);
var
Temp: pByte;
Size: Integer;
glFormat, glInternalFormat, glType: Cardinal;
begin
if not FormatIsUncompressed(Format) then
- raise EglBitmapUnsupportedInternalFormat.Create('TglBitmap2D.GrabScreen - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormatFormat.Create('TglBitmap2D.GrabScreen - ' + UNSUPPORTED_INTERNAL_FORMAT);
// Only to select Formats
SelectFormat(Format, glFormat, glInternalFormat, glType, False);
Temp: pByte;
TempWidth, TempHeight, RedSize, GreenSize, BlueSize, AlphaSize, LumSize: Integer;
TempType, TempIntFormat: Cardinal;
- IntFormat: TglBitmapInternalFormat;
+ IntFormat: TglBitmapFormat;
begin
Bind;
TempType := GL_UNSIGNED_SHORT_5_6_5;
end;
GL_RGB, GL_RGB8:
- IntFormat := ifRGB8;
+ IntFormat := tfRGB8;
GL_RGBA, GL_RGBA4, GL_RGBA8:
begin
if (RedSize = 4) and (BlueSize = 4) and (GreenSize = 4) and (AlphaSize = 4) then begin
- IntFormat := ifRGBA4;
+ IntFormat := tfRGBA4;
TempIntFormat := GL_BGRA;
TempType := GL_UNSIGNED_SHORT_4_4_4_4_REV;
end else
if (RedSize = 5) and (BlueSize = 5) and (GreenSize = 5) and (AlphaSize = 1) then begin
- IntFormat := ifRGB5A1;
+ IntFormat := tfRGB5A1;
TempIntFormat := GL_BGRA;
TempType := GL_UNSIGNED_SHORT_1_5_5_5_REV;
end else begin
- IntFormat := ifRGBA8;
+ IntFormat := tfRGBA8;
end;
end;
GL_BGR:
GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, TestTextureSize);
end;
-
-
initialization
- glBitmapSetDefaultFormat(tfDefault);
+ glBitmapSetDefaultFormat(tfEmpty);
+ glBitmapSetDefaultMipmap(mmMipmap);
glBitmapSetDefaultFilter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
- glBitmapSetDefaultWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ glBitmapSetDefaultWrap (GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
- glBitmapSetDefaultFreeDataAfterGenTexture(True);
- glBitmapSetDefaultDeleteTextureOnFree(True);
+ glBitmapSetDefaultFreeDataAfterGenTexture(true);
+ glBitmapSetDefaultDeleteTextureOnFree (true);
finalization