From: Bergmann89 Date: Tue, 22 Oct 2013 18:31:38 +0000 (+0200) Subject: * started refactoring (interface part, mapping functions) X-Git-Tag: v3.0.0~26 X-Git-Url: https://git.delphigl.com/?a=commitdiff_plain;h=b44eb11a7e6cd1cb6eb36f290e184f53a6e6ec86;p=glBitmap.git * started refactoring (interface part, mapping functions) --- diff --git a/glBitmap.pas b/glBitmap.pas index 0641898..1a21c20 100644 --- a/glBitmap.pas +++ b/glBitmap.pas @@ -214,46 +214,45 @@ History ***********************************************************} 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 @@ -263,116 +262,110 @@ unit glBitmap; // ###### 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; @@ -384,18 +377,18 @@ type 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 @@ -541,73 +534,69 @@ var 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); + EglBitmapUnsupportedInternalFormat = class(EglBitmapException); - // Functions TglBitmapPixelDesc = packed record RedRange: Cardinal; - RedShift: Shortint; GreenRange: Cardinal; - GreenShift: Shortint; BlueRange: Cardinal; - BlueShift: Shortint; AlphaRange: Cardinal; + + RedShift: Shortint; + GreenShift: Shortint; + BlueShift: Shortint; AlphaShift: Shortint; end; @@ -616,7 +605,6 @@ type Green: Cardinal; Blue: Cardinal; Alpha: Cardinal; - PixelDesc: TglBitmapPixelDesc; end; @@ -628,7 +616,7 @@ type end; const - cNullSize : TglBitmapPixelPosition = (Fields : []; X: 0; Y: 0); + NULL_SIZE: TglBitmapPixelPosition = (Fields: []; X: 0; Y: 0); type TglBitmap = class; @@ -652,65 +640,94 @@ type 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); + TglBitmapMipMap = ( + mmNone, + mmMipmap, + mmMipmapGlu); + TglBitmapNormalMapFunc = ( + nm4Samples, + nmSobel, + nm3x3, + nm5x5); + TglBitmapFormat = ( + tfRed = GL_RED, + tfGreen = GL_GREEN, + tfBlue = GL_BLUE, + tfAlpha = GL_ALPHA, + tfRGB = GL_RGB, + tfBGR = GL_BGR, + tfRGBA = GL_RGBA, + tfBGRA = GL_BGRA, + tfLuminance = GL_LUMINANCE, + tfLuminanceAlpha = GL_LUMINANCE_ALPHA + ); 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 + ifAlpha4 = GL_ALPHA4, + ifAlpha8 = GL_ALPHA8, + ifAlpha12 = GL_ALPHA12, + ifAlpha16 = GL_ALPHA16, + + ifLuminance4 = GL_LUMINANCE4, + ifLuminance8 = GL_LUMINANCE8, + ifLuminance12 = GL_LUMINANCE12, + ifLuminance16 = GL_LUMINANCE16, + + ifLuminance4Alpha4 = GL_LUMINANCE4_ALPHA4, + ifLuminance6Alpha2 = GL_LUMINANCE6_ALPHA2, + ifLuminance8Alpha8 = GL_LUMINANCE8_ALPHA8, + ifLuminance12Alpha4 = GL_LUMINANCE12_ALPHA4, + ifLuminance12Alpha12 = GL_LUMINANCE12_ALPHA12, + ifLuminance16Alpha16 = GL_LUMINANCE16_ALPHA16, + + ifR3G3B2 = GL_R3_G3_B2, + ifRGB4 = GL_RGB4, + ifRGB5 = GL_RGB5, + ifRGB8 = GL_RGB8, + ifRGB10 = GL_RGB10, + ifRGB12 = GL_RGB12, + ifRGB16 = GL_RGB16, + + ifRGBA2 = GL_RGBA2, + ifRGBA4 = GL_RGBA4, + ifRGB5A1 = GL_RGB5_A1, + ifRGBA8 = GL_RGBA8, + ifRGB10A2 = GL_RGB10_A2, + ifRGBA12 = GL_RGBA12, + ifRGBA16 = GL_RGBA16, + + ifDepth16 = GL_DEPTH_COMPONENT16, + ifDepth24 = GL_DEPTH_COMPONENT24, + ifDepth32 = GL_DEPTH_COMPONENT32 ); // Pixelmapping - TglBitmapMapFunc = procedure (const Pixel: TglBitmapPixelData; var pDest: pByte); - TglBitmapUnMapFunc = procedure (var pData: pByte; var Pixel: TglBitmapPixelData); + TglBitmapMapFunc = procedure(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); + TglBitmapUnMapFunc = procedure(var aData: PByte; var aBitOffset: Byte; var aPixel: TglBitmapPixelData); // 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; + fInternalFormat: TglBitmapInternalFormat; // Mapping fPixelSize: Integer; @@ -719,184 +736,182 @@ type 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); + procedure SetInternalFormat(const aValue: TglBitmapInternalFormat); + + //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 SetDataPointer(NewData: pByte; Format: TglBitmapInternalFormat; 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 ID: Cardinal read fID write SetID; + property Target: Cardinal read fTarget write SetTarget; + property Format: TglBitmapFormat read fFormat write SetFormat; property InternalFormat: TglBitmapInternalFormat read fInternalFormat write SetInternalFormat; - property Dimension: TglBitmapPixelPosition read fDimension; + 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 aInternalFormat: TglBitmapInternalFormat; + const aArgs: PtrInt = 0); + {$IFDEF GLB_DELPHI} + procedure LoadFromResource(Instance: Cardinal; Resource: String; ResType: PChar = nil); + procedure LoadFromResourceID(Instance: Cardinal; ResourceID: Integer; ResType: 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: TglBitmapInternalFormat; 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: TglBitmapInternalFormat): 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 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 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 GetPixel(const Pos: TglBitmapPixelPosition; var Pixel: TglBitmapPixelData); virtual; + procedure SetPixel(const Pos: TglBitmapPixelPosition; const Pixel: TglBitmapPixelData); virtual; - procedure SetBorderColor(Red, Green, Blue, Alpha: Single); - - 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: TglBitmapInternalFormat); overload; + constructor Create(Size: TglBitmapPixelPosition; Format: TglBitmapInternalFormat; Func: TglBitmapFunction; CustomData: Pointer = nil); overload; end; @@ -910,36 +925,29 @@ type 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 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; const aInternalFormat: TglBitmapInternalFormat); 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; @@ -982,78 +990,73 @@ type // 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); +procedure glBitmapSetDefaultDeleteTextureOnFree(const aDeleteTextureOnFree: Boolean); +procedure glBitmapSetDefaultFreeDataAfterGenTexture(const aFreeData: Boolean); +procedure glBitmapSetDefaultFormat(const aFormat: TglBitmapFormat); +procedure glBitmapSetDefaultInternalFormat(const aInternalFormat: TglBitmapInternalFormat); +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 glBitmapGetDefaultFormat: TglBitmapFormat; +function glBitmapGetDefaultInternalFormat: TglBitmapInternalFormat; +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(Format: TglBitmapInternalFormat): Single; function FormatIsCompressed(Format: TglBitmapInternalFormat): boolean; function FormatIsUncompressed(Format: TglBitmapInternalFormat): boolean; function FormatIsEmpty(Format: TglBitmapInternalFormat): boolean; function FormatHasAlpha(Format: TglBitmapInternalFormat): Boolean; - procedure FormatPreparePixel(var Pixel: TglBitmapPixelData; Format: TglBitmapInternalFormat); - function FormatGetWithoutAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat; function FormatGetWithAlpha(Format: TglBitmapInternalFormat): TglBitmapInternalFormat; - function FormatCheckFormat(RedMask, GreenMask, BlueMask, AlphaMask: Cardinal; Format: TglBitmapInternalFormat): boolean; -// Call LoadingMethods -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; - +(* TODO +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; - +*) var - glBitmapDefaultFormat: TglBitmapFormat; - glBitmapDefaultFilterMin: Integer; - glBitmapDefaultFilterMag: Integer; - glBitmapDefaultWrapS: Integer; - glBitmapDefaultWrapT: Integer; - glBitmapDefaultWrapR: Integer; - glBitmapDefaultDeleteTextureOnFree: Boolean; glBitmapDefaultFreeDataAfterGenTextures: Boolean; - -{$ifdef GLB_DELPHI} + glBitmapDefaultFormat: TglBitmapFormat; + glBitmapDefaultInternalFormat: TglBitmapInternalFormat; + glBitmapDefaultFilterMin: Cardinal; + glBitmapDefaultFilterMag: Cardinal; + glBitmapDefaultWrapS: Cardinal; + glBitmapDefaultWrapT: Cardinal; + glBitmapDefaultWrapR: Cardinal; + +{$IFDEF GLB_DELPHI} function CreateGrayPalette: HPALETTE; -{$endif} - +{$ENDIF} implementation uses Math; - -{$ifndef GLB_NO_NATIVE_GL} +(* TODO +{$IFNDEF GLB_NO_NATIVE_GL} procedure ReadOpenGLExtensions; var - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} Context: HGLRC; - {$endif} + {$ENDIF} Buffer: AnsiString; MajorVersion, MinorVersion: Integer; @@ -1104,21 +1107,21 @@ var 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); @@ -1181,13 +1184,14 @@ begin 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; begin Result.Fields := []; @@ -1203,236 +1207,677 @@ 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.'; - 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 ); - - PIXEL_DESC_RGBA8 : TglBitmapPixelDesc = ( - RedRange : $FF; RedShift : 0; - GreenRange : $FF; GreenShift : 8; - BlueRange : $FF; BlueShift : 16; - AlphaRange : $FF; AlphaShift : 24 ); - - PIXEL_DESC_BGR8 : TglBitmapPixelDesc = ( - RedRange : $FF; RedShift : 16; - GreenRange : $FF; GreenShift : 8; - BlueRange : $FF; BlueShift : 0; - AlphaRange : $00; AlphaShift : 0 ); - - PIXEL_DESC_BGRA8 : TglBitmapPixelDesc = ( - RedRange : $FF; RedShift : 16; - GreenRange : $FF; GreenShift : 8; - BlueRange : $FF; BlueShift : 0; - AlphaRange : $FF; AlphaShift : 24 ); - - PIXEL_DESC_RGB10A2 : TglBitmapPixelDesc = ( - RedRange : $3FF; RedShift : 20; - GreenRange : $3FF; GreenShift : 10; - BlueRange : $3FF; BlueShift : 0; - AlphaRange : $003; AlphaShift : 30 ); +{$REGION PixelDescription} +const + //ifAlpha4//////////////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_ALPHA4: TglBitmapPixelDesc = ( + RedRange: $00000000; RedShift: 0; + GreenRange: $00000000; GreenShift: 0; + BlueRange: $00000000; BlueShift: 0; + AlphaRange: $0000000F; AlphaShift: 0); + + //ifAlpha8 + PIXEL_DESC_ALPHA8: TglBitmapPixelDesc = ( + RedRange: $00000000; RedShift: 0; + GreenRange: $00000000; GreenShift: 0; + BlueRange: $00000000; BlueShift: 0; + AlphaRange: $000000FF; AlphaShift: 0); + + //ifAlpha12 + PIXEL_DESC_ALPHA12: TglBitmapPixelDesc = ( + RedRange: $00000000; RedShift: 0; + GreenRange: $00000000; GreenShift: 0; + BlueRange: $00000000; BlueShift: 0; + AlphaRange: $00000FFF; AlphaShift: 0); + + //ifAlpha16 + PIXEL_DESC_ALPHA16: TglBitmapPixelDesc = ( + RedRange: $00000000; RedShift: 0; + GreenRange: $00000000; GreenShift: 0; + BlueRange: $00000000; BlueShift: 0; + AlphaRange: $0000FFFF; AlphaShift: 0); + + //ifLuminance4//////////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_LUMINANCE4: TglBitmapPixelDesc = ( + RedRange: $0000000F; RedShift: 0; + GreenRange: $0000000F; GreenShift: 0; + BlueRange: $0000000F; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); + + //ifLuminance8 + PIXEL_DESC_LUMINANCE8: TglBitmapPixelDesc = ( + RedRange: $000000FF; RedShift: 0; + GreenRange: $000000FF; GreenShift: 0; + BlueRange: $000000FF; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); + + //ifLuminance12 + PIXEL_DESC_LUMINANCE12: TglBitmapPixelDesc = ( + RedRange: $00000FFF; RedShift: 0; + GreenRange: $00000FFF; GreenShift: 0; + BlueRange: $00000FFF; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); + + //ifLuminance16 + PIXEL_DESC_LUMINANCE16: TglBitmapPixelDesc = ( + RedRange: $0000FFFF; RedShift: 0; + GreenRange: $0000FFFF; GreenShift: 0; + BlueRange: $0000FFFF; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); + + //ifLuminance4Alpha4////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_LUMINANCE4_ALPHA4: TglBitmapPixelDesc = ( + RedRange: $0000000F; RedShift: 0; + GreenRange: $0000000F; GreenShift: 0; + BlueRange: $0000000F; BlueShift: 0; + AlphaRange: $0000000F; AlphaShift: 4); + //ifLuminance6Alpha2 + PIXEL_DESC_LUMINANCE6_ALPHA2: TglBitmapPixelDesc = ( + RedRange: $0000003F; RedShift: 0; + GreenRange: $0000003F; GreenShift: 0; + BlueRange: $0000003F; BlueShift: 0; + AlphaRange: $00000003; AlphaShift: 6); + + //ifLuminance8Alpha8 + PIXEL_DESC_LUMINANCE8_ALPHA8: TglBitmapPixelDesc = ( + RedRange: $000000FF; RedShift: 0; + GreenRange: $000000FF; GreenShift: 0; + BlueRange: $000000FF; BlueShift: 0; + AlphaRange: $000000FF; AlphaShift: 8); + + //ifLuminance12Alpha4 + PIXEL_DESC_LUMINANCE12_ALPHA4: TglBitmapPixelDesc = ( + RedRange: $00000FFF; RedShift: 0; + GreenRange: $00000FFF; GreenShift: 0; + BlueRange: $00000FFF; BlueShift: 0; + AlphaRange: $0000000F; AlphaShift: 12); + + //ifLuminance12Alpha12 + PIXEL_DESC_LUMINANCE12_ALPHA12: TglBitmapPixelDesc = ( + RedRange: $00000FFF; RedShift: 0; + GreenRange: $00000FFF; GreenShift: 0; + BlueRange: $00000FFF; BlueShift: 0; + AlphaRange: $00000FFF; AlphaShift: 12); + + //ifLuminance16Alpha16 + PIXEL_DESC_LUMINANCE16_ALPHA16: TglBitmapPixelDesc = ( + RedRange: $0000FFFF; RedShift: 0; + GreenRange: $0000FFFF; GreenShift: 0; + BlueRange: $0000FFFF; BlueShift: 0; + AlphaRange: $0000FFFF; AlphaShift: 16); + + //ifR3G3B2//////////////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_R3_G3_B2: TglBitmapPixelDesc = ( + RedRange: $00000007; RedShift: 0; + GreenRange: $00000007; GreenShift: 3; + BlueRange: $00000003; BlueShift: 6; + AlphaRange: $00000000; AlphaShift: 0); + + //ifRGB4 + PIXEL_DESC_RGB4: TglBitmapPixelDesc = ( + RedRange: $0000000F; RedShift: 0; + GreenRange: $0000000F; GreenShift: 4; + BlueRange: $0000000F; BlueShift: 8; + AlphaRange: $00000000; AlphaShift: 0); + + //ifRGB5 + PIXEL_DESC_RGB5: TglBitmapPixelDesc = ( + RedRange: $0000001F; RedShift: 0; + GreenRange: $0000001F; GreenShift: 5; + BlueRange: $0000001F; BlueShift: 10; + AlphaRange: $00000000; AlphaShift: 0); + + //ifRGB8 + PIXEL_DESC_RGB8: TglBitmapPixelDesc = ( + RedRange: $000000FF; RedShift: 0; + GreenRange: $000000FF; GreenShift: 8; + BlueRange: $000000FF; BlueShift: 16; + AlphaRange: $00000000; AlphaShift: 0); + + //ifRGB10 + PIXEL_DESC_RGB10: TglBitmapPixelDesc = ( + RedRange: $000003FF; RedShift: 0; + GreenRange: $000003FF; GreenShift: 10; + BlueRange: $000003FF; BlueShift: 20; + AlphaRange: $000003FF; AlphaShift: 0); + + //ifRGB12 + PIXEL_DESC_RGB12: TglBitmapPixelDesc = ( + RedRange: $00000000; RedShift: 0; + GreenRange: $00000000; GreenShift: 0; + BlueRange: $00000000; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); + + //ifRGB16 + PIXEL_DESC_RGB16: TglBitmapPixelDesc = ( + RedRange: $0000FFFF; RedShift: 0; + GreenRange: $0000FFFF; GreenShift: 16; + BlueRange: $0000FFFF; BlueShift: 32; + AlphaRange: $0000FFFF; AlphaShift: 0); + + //ifRGBA2///////////////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_RGBA2: TglBitmapPixelDesc = ( + RedRange: $00000003; RedShift: 0; + GreenRange: $00000003; GreenShift: 2; + BlueRange: $00000003; BlueShift: 4; + AlphaRange: $00000003; AlphaShift: 6); + + //ifRGBA4 + PIXEL_DESC_RGBA4: TglBitmapPixelDesc = ( + RedRange: $0000000F; RedShift: 0; + GreenRange: $0000000F; GreenShift: 4; + BlueRange: $0000000F; BlueShift: 8; + AlphaRange: $0000000F; AlphaShift: 12); + + //ifRGB5A1 + PIXEL_DESC_RGB5_A1: TglBitmapPixelDesc = ( + RedRange: $0000001F; RedShift: 0; + GreenRange: $0000001F; GreenShift: 5; + BlueRange: $0000001F; BlueShift: 10; + AlphaRange: $00000001; AlphaShift: 11); + + //ifRGBA8 + PIXEL_DESC_RGBA8: TglBitmapPixelDesc = ( + RedRange: $000000FF; RedShift: 0; + GreenRange: $000000FF; GreenShift: 8; + BlueRange: $000000FF; BlueShift: 16; + AlphaRange: $000000FF; AlphaShift: 24); + + //ifRGB10A2 + PIXEL_DESC_RGB10_A2: TglBitmapPixelDesc = ( + RedRange: $000003FF; RedShift: 0; + GreenRange: $000003FF; GreenShift: 10; + BlueRange: $000003FF; BlueShift: 20; + AlphaRange: $00000003; AlphaShift: 22); + + //ifRGBA12 + PIXEL_DESC_RGBA12: TglBitmapPixelDesc = ( + RedRange: $00000FFF; RedShift: 0; + GreenRange: $00000FFF; GreenShift: 12; + BlueRange: $00000FFF; BlueShift: 24; + AlphaRange: $00000FFF; AlphaShift: 36); + + //ifRGBA16 + PIXEL_DESC_RGBA16: TglBitmapPixelDesc = ( + RedRange: $0000FFFF; RedShift: 0; + GreenRange: $0000FFFF; GreenShift: 16; + BlueRange: $0000FFFF; BlueShift: 32; + AlphaRange: $0000FFFF; AlphaShift: 48); + + //ifDepthComponent16////////////////////////////////////////////////////////////////////////////// + PIXEL_DESC_DEPTH16: TglBitmapPixelDesc = ( + RedRange: $0000FFFF; RedShift: 0; + GreenRange: $0000FFFF; GreenShift: 0; + BlueRange: $0000FFFF; BlueShift: 0; + AlphaRange: $0000FFFF; AlphaShift: 0); -{* -** Mapping -*} + //ifDepthComponent24 + PIXEL_DESC_DEPTH24: TglBitmapPixelDesc = ( + RedRange: $00FFFFFF; RedShift: 0; + GreenRange: $00FFFFFF; GreenShift: 0; + BlueRange: $00FFFFFF; BlueShift: 0; + AlphaRange: $00FFFFFF; AlphaShift: 0); -procedure MapAlpha(const Pixel: TglBitmapPixelData; var pDest: pByte); + //ifDepthComponent32 + PIXEL_DESC_DEPTH32: TglBitmapPixelDesc = ( + RedRange: $FFFFFFFF; RedShift: 0; + GreenRange: $FFFFFFFF; GreenShift: 0; + BlueRange: $FFFFFFFF; BlueShift: 0; + AlphaRange: $00000000; AlphaShift: 0); +{$ENDREGION} + +{$REGION MapFunctions} +//ALPHA///////////////////////////////////////////////////////////////////////////////////////////// +procedure MapAlpha4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := Pixel.Alpha; - Inc(pDest); + //TODO end; +procedure MapAlpha8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + aData^ := aPixel.Alpha; + inc(aData); +end; -procedure MapLuminance(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapAlpha12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := Trunc(Pixel.Red * 0.3 + Pixel.Green * 0.59 + Pixel.Blue * 0.11); - Inc(pDest); + //TODO end; +procedure MapAlpha16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := aPixel.Alpha; + inc(aData, 2); +end; -procedure MapDepth8(const Pixel: TglBitmapPixelData; var pDest: pByte); +//LUMINANCE///////////////////////////////////////////////////////////////////////////////////////// +procedure MapLuminance4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := (Pixel.Red + Pixel.Green + Pixel.Blue) div 3; - Inc(pDest); + //TODO end; +procedure MapLuminance8(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; -procedure MapLuminanceAlpha(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapLuminance12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := Trunc(Pixel.Red * 0.3 + Pixel.Green * 0.59 + Pixel.Blue * 0.11); - Inc(pDest); + //TODO +end; - pDest^ := Pixel.Alpha; - Inc(pDest); +procedure MapLuminance16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := Trunc( + aPixel.Red * LUMINANCE_WEIGHT_R + + aPixel.Green * LUMINANCE_WEIGHT_G + + aPixel.Blue * LUMINANCE_WEIGHT_B); + inc(aData, 2); end; +//LUMINANCE_ALPHA/////////////////////////////////////////////////////////////////////////////////// +procedure MapLuminance4Alpha4(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) and + aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift; + inc(aData); +end; -procedure MapRGBA4(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapLuminance6Alpha2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; + MapLuminance4Alpha4(aPixel, aData, aBitOffset); +end; - Inc(pDest, 2); +procedure MapLuminance8Alpha8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := + ((Trunc(aPixel.Red * LUMINANCE_WEIGHT_R + + aPixel.Green * LUMINANCE_WEIGHT_G + + aPixel.Blue * LUMINANCE_WEIGHT_B) and + aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift; + inc(aData, 2); end; +procedure MapLuminance12Alpha4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + MapLuminance8Alpha8(aPixel, aData, aBitOffset); +end; -procedure MapR5G6B5(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapLuminance12Alpha12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pWord(pDest)^ := - Pixel.Red shl PIXEL_DESC_R5G6B5.RedShift or - Pixel.Green shl PIXEL_DESC_R5G6B5.GreenShift or - Pixel.Blue; + //TODO +end; - Inc(pDest, 2); +procedure MapLuminance16Alpha16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PCardinal(aData)^ := + ((Trunc(aPixel.Red * LUMINANCE_WEIGHT_R + + aPixel.Green * LUMINANCE_WEIGHT_G + + aPixel.Blue * LUMINANCE_WEIGHT_B) and + aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift; + inc(aData, 4); end; +//RGB/////////////////////////////////////////////////////////////////////////////////////////////// +procedure MapR3G3B2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + aData^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift); + inc(aData); +end; -procedure MapRGB5A1(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapRGB4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; + //TODO +end; - Inc(pDest, 2); +procedure MapRGB5(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO end; +procedure MapRGB8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PCardinal(aData)^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift); + inc(aData, 3); +end; -procedure MapRGB8(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapRGB10(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := Pixel.Red; - Inc(pDest); + //TODO +end; - pDest^ := Pixel.Green; - Inc(pDest); +procedure MapRGB12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; - pDest^ := Pixel.Blue; - Inc(pDest); +procedure MapRGB16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := aPixel.Red; + inc(aData, 2); + PWord(aData)^ := aPixel.Green; + inc(aData, 2); + PWord(aData)^ := aPixel.Blue; + inc(aData, 2); end; +//RGBA////////////////////////////////////////////////////////////////////////////////////////////// +procedure MapRGBA2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + aData^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift); + inc(aData); +end; -procedure MapBGR8(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapRGBA4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); begin - pDest^ := Pixel.Blue; - Inc(pDest); + PWord(aData)^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift); + inc(aData, 2); +end; - pDest^ := Pixel.Green; - Inc(pDest); +procedure MapRGB5A1(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift); + inc(aData, 2); +end; - pDest^ := Pixel.Red; - Inc(pDest); +procedure MapRGBA8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PCardinal(aData)^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift); + inc(aData, 4); end; +procedure MapRGB10A2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PCardinal(aData)^ := + ((aPixel.Red and aPixel.PixelDesc.RedRange) shl aPixel.PixelDesc.RedShift) or + ((aPixel.Green and aPixel.PixelDesc.GreenRange) shl aPixel.PixelDesc.GreenShift) or + ((aPixel.Blue and aPixel.PixelDesc.BlueRange) shl aPixel.PixelDesc.BlueShift) or + ((aPixel.Alpha and aPixel.PixelDesc.AlphaRange) shl aPixel.PixelDesc.AlphaShift); + inc(aData, 4); +end; -procedure MapRGBA8(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapRGBA12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; + //TODO +end; - Inc(pDest, 4); +procedure MapRGBA16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := aPixel.Red; + inc(aData, 2); + PWord(aData)^ := aPixel.Green; + inc(aData, 2); + PWord(aData)^ := aPixel.Blue; + inc(aData, 2); + PWord(aData)^ := aPixel.Alpha; + inc(aData, 2); end; +//DEPTH///////////////////////////////////////////////////////////////////////////////////////////// +procedure MapDepth16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PWord(aData)^ := (aPixel.Red + aPixel.Green + aPixel.Blue) div 3; + inc(aData, 2); +end; -procedure MapBGRA8(const Pixel: TglBitmapPixelData; var pDest: pByte); +procedure MapDepth24(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; + //TODO +end; - Inc(pDest, 4); +procedure MapDepth32(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + PCardinal(aData)^ := (aPixel.Red + aPixel.Green + aPixel.Blue) div 3; + inc(aData, 4); end; +function FormatGetMapFunc(const aInternalFormat: TglBitmapInternalFormat): TglBitmapMapFunc; +begin + case aInternalFormat of + ifAlpha4: result := MapAlpha4; + ifAlpha8: result := MapAlpha8; + ifAlpha12: result := MapAlpha12; + ifAlpha16: result := MapAlpha16; -procedure MapRGB10A2(const Pixel: TglBitmapPixelData; var pDest: pByte); + ifLuminance4: result := MapLuminance4; + ifLuminance8: result := MapLuminance8; + ifLuminance12: result := MapLuminance8; + ifLuminance16: result := MapLuminance8; + + ifLuminance4Alpha4: result := MapLuminance4Alpha4; + ifLuminance6Alpha2: result := MapLuminance6Alpha2; + ifLuminance8Alpha8: result := MapLuminance8Alpha8; + ifLuminance12Alpha4: result := MapLuminance12Alpha4; + ifLuminance12Alpha12: result := MapLuminance12Alpha12; + ifLuminance16Alpha16: result := MapLuminance16Alpha16; + + ifR3G3B2: result := MapR3G3B2; + ifRGB4: result := MapRGB4; + ifRGB5: result := MapRGB5; + ifRGB8: result := MapRGB8; + ifRGB10: result := MapRGB10; + ifRGB12: result := MapRGB12; + ifRGB16: result := MapRGB16; + + ifRGBA2: result := MapRGBA2; + ifRGBA4: result := MapRGBA4; + ifRGB5A1: result := MapRGB5A1; + ifRGBA8: result := MapRGBA8; + ifRGB10A2: result := MapRGB10A2; + ifRGBA12: result := MapRGBA12; + ifRGBA16: result := MapRGBA16; + + ifDepth16: result := MapDepth16; + ifDepth24: result := MapDepth24; + ifDepth32: result := MapDepth32; + else + raise EglBitmapUnsupportedInternalFormat.Create('FormatGetMapFunc - ' + UNSUPPORTED_INTERNAL_FORMAT); + end; +end; +{$ENDREGION} + +{$REGION UnmapFunctions} +//ALPHA///////////////////////////////////////////////////////////////////////////////////////////// +procedure UnmapAlpha4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapAlpha8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; - Inc(pDest, 4); end; +procedure UnmapAlpha12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; -function FormatGetMapFunc(Format: TglBitmapInternalFormat): TglBitmapMapFunc; +procedure UnmapAlpha16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); 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; - else - raise EglBitmapUnsupportedInternalFormat.Create('FormatGetMapFunc - ' + UNSUPPORTED_INTERNAL_FORMAT); - end; + end; +//LUMINANCE///////////////////////////////////////////////////////////////////////////////////////// +procedure UnmapLuminance4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapLuminance8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapLuminance12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapLuminance16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +//LUMINANCE_ALPHA/////////////////////////////////////////////////////////////////////////////////// +procedure UnmapLuminance4Alpha4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapLuminance6Alpha2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapLuminance8Alpha8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapLuminance12Alpha4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapLuminance12Alpha12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapLuminance16Alpha16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +//RGB/////////////////////////////////////////////////////////////////////////////////////////////// +procedure UnmapR3G3B2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGB4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapRGB5(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapRGB8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGB10(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapRGB12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapRGB16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +//RGBA////////////////////////////////////////////////////////////////////////////////////////////// +procedure UnmapRGBA2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGBA4(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGB5A1(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGBA8(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGB10A2(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapRGBA12(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapRGBA16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +//DEPTH///////////////////////////////////////////////////////////////////////////////////////////// +procedure UnmapDepth16(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + +procedure UnmapDepth24(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + //TODO +end; + +procedure UnmapDepth32(const aPixel: TglBitmapPixelData; var aData: PByte; var aBitOffset: Byte); +begin + +end; + + + -{* -** Unmapping -*} procedure UnMapAlpha(var pData: pByte; var Pixel: TglBitmapPixelData); begin Pixel.Alpha := pData^; @@ -1600,25 +2045,50 @@ begin end; -function FormatGetUnMapFunc(Format: TglBitmapInternalFormat): TglBitmapUnMapFunc; -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); +function FormatGetUnMapFunc(const aInternalFormat: TglBitmapInternalFormat): TglBitmapUnMapFunc; +begin + case aInternalFormat of + ifAlpha4: result := UnmapAlpha4; + ifAlpha8: result := UnmapAlpha8; + ifAlpha12: result := UnmapAlpha12; + ifAlpha16: result := UnmapAlpha16; + + ifLuminance4: result := UnmapLuminance4; + ifLuminance8: result := UnmapLuminance8; + ifLuminance12: result := UnmapLuminance8; + ifLuminance16: result := UnmapLuminance8; + + ifLuminance4Alpha4: result := UnmapLuminance4Alpha4; + ifLuminance6Alpha2: result := UnmapLuminance6Alpha2; + ifLuminance8Alpha8: result := UnmapLuminance8Alpha8; + ifLuminance12Alpha4: result := UnmapLuminance12Alpha4; + ifLuminance12Alpha12: result := UnmapLuminance12Alpha12; + ifLuminance16Alpha16: result := UnmapLuminance16Alpha16; + + ifR3G3B2: result := UnmapR3G3B2; + ifRGB4: result := UnmapRGB4; + ifRGB5: result := UnmapRGB5; + ifRGB8: result := UnmapRGB8; + ifRGB10: result := UnmapRGB10; + ifRGB12: result := UnmapRGB12; + ifRGB16: result := UnmapRGB16; + + ifRGBA2: result := UnmapRGBA2; + ifRGBA4: result := UnmapRGBA4; + ifRGB5A1: result := UnmapRGB5A1; + ifRGBA8: result := UnmapRGBA8; + ifRGB10A2: result := UnmapRGB10A2; + ifRGBA12: result := UnmapRGBA12; + ifRGBA16: result := UnmapRGBA16; + + ifDepth16: result := UnmapDepth16; + ifDepth24: result := UnmapDepth24; + ifDepth32: result := UnmapDepth32; + else + raise EglBitmapUnsupportedInternalFormat.Create('FormatGetMapFunc - ' + UNSUPPORTED_INTERNAL_FORMAT); end; end; +{$ENDREGION} {* ** Tools @@ -1774,15 +2244,15 @@ function FormatGetSupportedFiles(Format: TglBitmapInternalFormat): TglBitmapFile begin Result := []; - {$ifdef GLB_SUPPORT_PNG_WRITE} + {$IFDEF GLB_SUPPORT_PNG_WRITE} if Format in [ifLuminance, ifAlpha, ifDepth8, ifLuminanceAlpha, ifBGR8, ifBGRA8, ifRGB8, ifRGBA8] then Result := Result + [ftPNG]; - {$endif} + {$ENDIF} - {$ifdef GLB_SUPPORT_JPEG_WRITE} + {$IFDEF GLB_SUPPORT_JPEG_WRITE} if Format in [ifLuminance, ifAlpha, ifDepth8, ifRGB8, ifBGR8] then Result := Result + [ftJPEG]; - {$endif} + {$ENDIF} Result := Result + [ftDDS]; @@ -1871,7 +2341,7 @@ begin end; -{$ifdef GLB_DELPHI} +{$IFDEF GLB_DELPHI} function CreateGrayPalette: HPALETTE; var Idx: Integer; @@ -1903,10 +2373,10 @@ begin FreeMem(Pal); end; -{$endif} +{$ENDIF} -{$ifdef GLB_SDL_IMAGE} +{$IFDEF GLB_SDL_IMAGE} function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl; begin Result := TStream(context^.unknown.data1).Seek(offset, whence); @@ -1944,27 +2414,27 @@ begin Result^.close := glBitmapRWclose; Result^.unknown.data1 := Stream; end; -{$endif} +{$ENDIF} {* ** Helper functions *} -function LoadTexture(Filename: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$endif}): Boolean; +function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean; var glBitmap: TglBitmap2D; begin Result := false; Texture := 0; - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if Instance = 0 then Instance := HInstance; if (LoadFromRes) then glBitmap := TglBitmap2D.CreateFromResourceName(Instance, FileName) else - {$endif} + {$ENDIF} glBitmap := TglBitmap2D.Create(FileName); try @@ -1981,67 +2451,67 @@ begin end; -function LoadCubeMap(PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, NegativeZ: String; var Texture: Cardinal{$ifdef GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$endif}): Boolean; +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} + {$IFDEF GLB_DELPHI} if Instance = 0 then Instance := HInstance; - {$endif} + {$ENDIF} CM := TglBitmapCubeMap.Create; try CM.DeleteTextureOnFree := False; // Maps - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, PositiveX) else - {$endif} + {$ENDIF} CM.LoadFromFile(PositiveX); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_X); - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, NegativeX) else - {$endif} + {$ENDIF} CM.LoadFromFile(NegativeX); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_X); - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, PositiveY) else - {$endif} + {$ENDIF} CM.LoadFromFile(PositiveY); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Y); - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, NegativeY) else - {$endif} + {$ENDIF} CM.LoadFromFile(NegativeY); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y); - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, PositiveZ) else - {$endif} + {$ENDIF} CM.LoadFromFile(PositiveZ); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Z); - {$ifdef GLB_DELPHI} + {$IFDEF GLB_DELPHI} if (LoadFromRes) then CM.LoadFromResource(Instance, NegativeZ) else - {$endif} + {$ENDIF} CM.LoadFromFile(NegativeZ); CM.GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z); @@ -2072,9 +2542,6 @@ begin end; -{* -** Defaults -*} procedure glBitmapSetDefaultFormat(Format: TglBitmapFormat); begin glBitmapDefaultFormat := Format; @@ -2176,9 +2643,9 @@ 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.'); @@ -2201,7 +2668,7 @@ begin end; -{$ifdef GLB_DELPHI} +{$IFDEF GLB_DELPHI} constructor TglBitmap.CreateFromResourceName(Instance: Cardinal; Resource: String; ResType: PChar); begin Create; @@ -2222,7 +2689,7 @@ begin Create; LoadFromResourceID(Instance, ResourceID, ResType); end; -{$endif} +{$ENDIF} constructor TglBitmap.Create(Size: TglBitmapPixelPosition; @@ -2323,12 +2790,12 @@ end; procedure TglBitmap.LoadFromStream(Stream: 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 @@ -2336,7 +2803,7 @@ begin end; -{$ifdef GLB_DELPHI} +{$IFDEF GLB_DELPHI} procedure TglBitmap.LoadFromResource(Instance: Cardinal; Resource: String; ResType: PChar); var RS: TResourceStream; @@ -2374,7 +2841,7 @@ begin RS.Free; end; end; -{$endif} +{$ENDIF} @@ -2416,12 +2883,12 @@ end; procedure TglBitmap.SaveToStream(Stream: TStream; FileType: 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); @@ -2429,7 +2896,7 @@ begin end; -{$ifdef GLB_SDL} +{$IFDEF GLB_SDL} function TglBitmap.AssignToSurface(out Surface: PSDL_Surface): boolean; var Row, RowSize: Integer; @@ -2631,10 +3098,10 @@ begin glBitmap.Free; end; end; -{$endif} +{$ENDIF} -{$ifdef GLB_DELPHI} +{$IFDEF GLB_DELPHI} function TglBitmap.AssignFromBitmap(const Bitmap: TBitmap): boolean; var pSource, pData, pTempData: PByte; @@ -2796,7 +3263,7 @@ begin glBitmap.Free; end; end; -{$endif} +{$ENDIF} function TglBitmap.AddAlphaFromFile(FileName: String; Func: TglBitmapFunction; CustomData: Pointer): boolean; @@ -2825,7 +3292,7 @@ begin end; -{$ifdef GLB_DELPHI} +{$IFDEF GLB_DELPHI} function TglBitmap.AddAlphaFromResource(Instance: Cardinal; Resource: String; ResType: PChar; Func: TglBitmapFunction; CustomData: Pointer): boolean; var @@ -2865,7 +3332,7 @@ begin RS.Free; end; end; -{$endif} +{$ENDIF} procedure glBitmapColorKeyAlphaFunc(var FuncRec: TglBitmapFunctionRec); @@ -2886,7 +3353,8 @@ begin 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; @@ -2996,7 +3464,7 @@ begin 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))); @@ -3153,7 +3621,8 @@ begin end; -procedure TglBitmap.SetDataPointer(NewData: PByte; Format: TglBitmapInternalFormat; Width, Height: Integer); +procedure TglBitmap.SetDataPointer(NewData: pByte; + Format: TglBitmapInternalFormat; Width: Integer; Height: Integer); begin // Data if Data <> NewData then begin @@ -3184,17 +3653,17 @@ 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; @@ -3216,8 +3685,8 @@ begin SDL_FreeRW(RWops); end; end; -{$endif} -{$ifdef GLB_LIB_PNG} +{$ENDIF} +{$IFDEF GLB_LIB_PNG} var StreamPos: Int64; signature: array [0..7] of byte; @@ -3321,8 +3790,8 @@ begin quit_libPNG; end; end; -{$endif} -{$ifdef GLB_PNGIMAGE} +{$ENDIF} +{$IFDEF GLB_PNGIMAGE} var StreamPos: Int64; Png: TPNGObject; @@ -3410,11 +3879,11 @@ begin 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 @@ -3557,12 +4026,12 @@ begin 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; @@ -3584,8 +4053,8 @@ begin SDL_FreeRW(RWops); end; end; -{$endif} -{$ifdef GLB_LIB_JPEG} +{$ENDIF} +{$IFDEF GLB_LIB_JPEG} var StreamPos: Int64; Temp: array[0..1]of Byte; @@ -3693,8 +4162,8 @@ begin quit_libJPEG; end; end; -{$endif} -{$ifdef GLB_DELPHI_JPEG} +{$ENDIF} +{$IFDEF GLB_DELPHI_JPEG} var bmp: TBitmap; jpg: TJPEGImage; @@ -3725,8 +4194,8 @@ begin end; end; end; -{$endif} -{$endif} +{$ENDIF} +{$ENDIF} const @@ -3980,6 +4449,59 @@ type dwReserved2: Cardinal; end; +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; + +procedure TglBitmap.SetCustomNameW(const aValue: WideString); +begin + if fCustomNameW = aValue then Exit; + fCustomNameW := aValue; +end; + +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; + +procedure TglBitmap.SetFreeDataAfterGenTexture(const aValue: Boolean); +begin + if fFreeDataAfterGenTexture = aValue then Exit; + fFreeDataAfterGenTexture := aValue; +end; + +procedure TglBitmap.SetID(const aValue: Cardinal); +begin + if fID = aValue then Exit; + fID := aValue; +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; function TglBitmap.LoadDDS(Stream: TStream): Boolean; var @@ -4381,16 +4903,16 @@ begin 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; @@ -4471,8 +4993,8 @@ begin quit_libPNG; end; end; -{$endif} -{$ifdef GLB_PNGIMAGE} +{$ENDIF} +{$IFDEF GLB_PNGIMAGE} var Png: TPNGObject; @@ -4556,8 +5078,8 @@ begin FreeAndNil(Png); end; end; -{$endif} -{$endif} +{$ENDIF} +{$ENDIF} procedure TglBitmap.SaveDDS(Stream: TStream); @@ -4704,9 +5226,9 @@ begin 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; @@ -4825,8 +5347,8 @@ begin quit_libJPEG; end; end; -{$endif} -{$ifdef GLB_DELPHI_JPEG} +{$ENDIF} +{$IFDEF GLB_DELPHI_JPEG} var Bmp: TBitmap; Jpg: TJPEGImage; @@ -4855,8 +5377,8 @@ begin FreeAndNil(Bmp); end; end; -{$endif} -{$endif} +{$ENDIF} +{$ENDIF} procedure TglBitmap.SaveBMP(Stream: TStream); @@ -5303,13 +5825,13 @@ begin 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 @@ -5324,7 +5846,8 @@ begin end; -procedure TglBitmap.FillWithColorRange(Red, Green, Blue, Alpha: Cardinal); +procedure TglBitmap.FillWithColorRange(Red, Green, Blue: Cardinal; + Alpha: Cardinal); var PixelData: TglBitmapPixelData; begin @@ -5338,7 +5861,7 @@ begin end; -procedure TglBitmap.SetAnisotropic(const Value: Integer); +procedure TglBitmap.SetAnisotropic(const aValue: Integer); var MaxAniso: Integer; begin @@ -5363,7 +5886,7 @@ begin end; -procedure TglBitmap.SetInternalFormat(const Value: TglBitmapInternalFormat); +procedure TglBitmap.SetInternalFormat(const aValue: TglBitmapInternalFormat); begin if InternalFormat <> Value then begin if FormatGetSize(Value) <> FormatGetSize(InternalFormat) then