X-Git-Url: https://git.delphigl.com/?p=glBitmap.git;a=blobdiff_plain;f=glBitmap.pas;h=4986ed471cd5380819e44a9b8ca3d4e4a8bbdf7d;hp=f5ba747b5b3c9bfe6ed9b4d88dfb85c683edc180;hb=5a2eeb45d528c5a2406b2ae5d73a4c711b2ea7dc;hpb=9645411434f007b2d4e26f33b5dbb2a023ef6557 diff --git a/glBitmap.pas b/glBitmap.pas index f5ba747..4986ed4 100644 --- a/glBitmap.pas +++ b/glBitmap.pas @@ -221,11 +221,17 @@ unit glBitmap; // Please uncomment the defines below to configure the glBitmap to your preferences. // If you have configured the unit you can uncomment the warning above. -{$MESSAGE error 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'} +{.$MESSAGE error 'Hey. I''m the glBitmap.pas and i need to be configured. My master tell me your preferences! ;)'} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Preferences /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// enable OpenGL ES support +{.$DEFINE OPENGL_ES_1_1} +{.$DEFINE OPENGL_ES_2_0} +{.$DEFINE OPENGL_ES_3_0} +{.$DEFINE OPENGL_ES_EXT} + // activate to enable build-in OpenGL support with statically linked methods // use dglOpenGL.pas if not enabled {.$DEFINE GLB_NATIVE_OGL_STATIC} @@ -302,9 +308,19 @@ unit glBitmap; {$DEFINE GLB_LINUX} {$IFEND} +// OpenGL ES +{$IF DEFINED(OPENGL_ES_EXT)} {$DEFINE OPENGL_ES_1_1} {$IFEND} +{$IF DEFINED(OPENGL_ES_3_0)} {$DEFINE OPENGL_ES_2_0} {$IFEND} +{$IF DEFINED(OPENGL_ES_2_0)} {$DEFINE OPENGL_ES_1_1} {$IFEND} +{$IF DEFINED(OPENGL_ES_1_1)} {$DEFINE OPENGL_ES} {$IFEND} + // native OpenGL Support {$IF DEFINED(GLB_NATIVE_OGL_STATIC) OR DEFINED(GLB_NATIVE_OGL_DYNAMIC)} - {$DEFINE GLB_NATIVE_OGL} + {$IFDEF OPENGL_ES} + {$ERROR 'native OpenGL is not supported yet for OpenGL ES, please use dglOpenGLES.pas instead'} + {$ELSE} + {$DEFINE GLB_NATIVE_OGL} + {$ENDIF} {$IFEND} // checking define combinations @@ -441,7 +457,10 @@ unit glBitmap; interface uses - {$IFNDEF GLB_NATIVE_OGL} dglOpenGL, {$ENDIF} + {$IFNDEF GLB_NATIVE_OGL} + {$IFDEF OPENGL_ES} dglOpenGLES, + {$ELSE} dglOpenGL, {$ENDIF} + {$ENDIF} {$IF DEFINED(GLB_WIN) AND (DEFINED(GLB_NATIVE_OGL) OR DEFINED(GLB_DELPHI))} windows, {$IFEND} @@ -780,6 +799,13 @@ type // - data type (e.g. ub, us, ui) // - number of data types +{$IFNDEF fpc} + QWord = System.UInt64; + PQWord = ^QWord; + + PtrInt = Longint; + PtrUInt = DWord; +{$ENDIF} TglBitmapFormat = ( tfEmpty = 0, //must be smallest value! @@ -859,7 +885,8 @@ type {$IFDEF GLB_SUPPORT_JPEG_WRITE}ftJPEG, {$ENDIF} ftDDS, ftTGA, - ftBMP); + ftBMP, + ftRAW); TglBitmapFileTypes = set of TglBitmapFileType; TglBitmapMipMap = ( @@ -885,53 +912,80 @@ type end; //////////////////////////////////////////////////////////////////////////////////////////////////// - TglBitmapColorRec = packed record + TglBitmapRec4ui = packed record case Integer of 0: (r, g, b, a: Cardinal); 1: (arr: array[0..3] of Cardinal); end; - TglBitmapMask = packed record + TglBitmapRec4ub = packed record case Integer of - 0: (r, g, b, a: QWord); - 1: (arr: array[0..3] of QWord); - end; - - TglBitmapPixelData = packed record - Data, Range: TglBitmapColorRec; - Format: TglBitmapFormat; + 0: (r, g, b, a: Byte); + 1: (arr: array[0..3] of Byte); end; - PglBitmapPixelData = ^TglBitmapPixelData; -//////////////////////////////////////////////////////////////////////////////////////////////////// - TglBitmapPixelPositionFields = set of (ffX, ffY); - TglBitmapPixelPosition = record - Fields : TglBitmapPixelPositionFields; - X : Word; - Y : Word; + TglBitmapRec4ul = packed record + case Integer of + 0: (r, g, b, a: QWord); + 1: (arr: array[0..3] of QWord); end; TglBitmapFormatDescriptor = class(TObject) + private + // cached properties + fBytesPerPixel: Single; + fChannelCount: Integer; + fMask: TglBitmapRec4ul; + fRange: TglBitmapRec4ui; + + function GetHasRed: Boolean; + function GetHasGreen: Boolean; + function GetHasBlue: Boolean; + function GetHasAlpha: Boolean; + function GetHasColor: Boolean; + function GetIsGrayscale: Boolean; protected - function GetIsCompressed: Boolean; virtual; abstract; - function GetHasRed: Boolean; virtual; abstract; - function GetHasGreen: Boolean; virtual; abstract; - function GetHasBlue: Boolean; virtual; abstract; - function GetHasAlpha: Boolean; virtual; abstract; - function GetHasColor: Boolean; virtual; abstract; - function GetIsGrayscale: Boolean; virtual; abstract; - - function GetRGBInverted: TglBitmapFormat; virtual; abstract; - function GetWithAlpha: TglBitmapFormat; virtual; abstract; - function GetWithoutAlpha: TglBitmapFormat; virtual; abstract; - function GetOpenGLFormat: TglBitmapFormat; virtual; abstract; - function GetUncompressed: TglBitmapFormat; virtual; abstract; - - function GetglDataFormat: GLenum; virtual; abstract; - function GetglFormat: GLenum; virtual; abstract; - function GetglInternalFormat: GLenum; virtual; abstract; + fFormat: TglBitmapFormat; + fWithAlpha: TglBitmapFormat; + fWithoutAlpha: TglBitmapFormat; + fOpenGLFormat: TglBitmapFormat; + fRGBInverted: TglBitmapFormat; + fUncompressed: TglBitmapFormat; + + fBitsPerPixel: Integer; + fIsCompressed: Boolean; + + fPrecision: TglBitmapRec4ub; + fShift: TglBitmapRec4ub; + + fglFormat: GLenum; + fglInternalFormat: GLenum; + fglDataFormat: GLenum; + + procedure SetValues; virtual; + procedure CalcValues; public - property IsCompressed: Boolean read GetIsCompressed; + property Format: TglBitmapFormat read fFormat; + property ChannelCount: Integer read fChannelCount; + property IsCompressed: Boolean read fIsCompressed; + property BitsPerPixel: Integer read fBitsPerPixel; + property BytesPerPixel: Single read fBytesPerPixel; + + property Precision: TglBitmapRec4ub read fPrecision; + property Shift: TglBitmapRec4ub read fShift; + property Range: TglBitmapRec4ui read fRange; + property Mask: TglBitmapRec4ul read fMask; + + property RGBInverted: TglBitmapFormat read fRGBInverted; + property WithAlpha: TglBitmapFormat read fWithAlpha; + property WithoutAlpha: TglBitmapFormat read fWithAlpha; + property OpenGLFormat: TglBitmapFormat read fOpenGLFormat; + property Uncompressed: TglBitmapFormat read fUncompressed; + + property glFormat: GLenum read fglFormat; + property glInternalFormat: GLenum read fglInternalFormat; + property glDataFormat: GLenum read fglDataFormat; + property HasRed: Boolean read GetHasRed; property HasGreen: Boolean read GetHasGreen; property HasBlue: Boolean read GetHasBlue; @@ -939,20 +993,27 @@ type property HasColor: Boolean read GetHasColor; property IsGrayscale: Boolean read GetIsGrayscale; - property RGBInverted: TglBitmapFormat read GetRGBInverted; - property WithAlpha: TglBitmapFormat read GetWithAlpha; - property WithoutAlpha: TglBitmapFormat read GetWithoutAlpha; - property OpenGLFormat: TglBitmapFormat read GetOpenGLFormat; - property Uncompressed: TglBitmapFormat read GetUncompressed; - - property glFormat: GLenum read GetglFormat; - property glInternalFormat: GLenum read GetglInternalFormat; - property glDataFormat: GLenum read GetglDataFormat; + constructor Create; public class function GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; end; //////////////////////////////////////////////////////////////////////////////////////////////////// + TglBitmapPixelData = packed record + Data: TglBitmapRec4ui; + Range: TglBitmapRec4ui; + Format: TglBitmapFormat; + end; + PglBitmapPixelData = ^TglBitmapPixelData; + + TglBitmapPixelPositionFields = set of (ffX, ffY); + TglBitmapPixelPosition = record + Fields : TglBitmapPixelPositionFields; + X : Word; + Y : Word; + end; + +//////////////////////////////////////////////////////////////////////////////////////////////////// TglBitmap = class; TglBitmapFunctionRec = record Sender: TglBitmap; @@ -976,7 +1037,9 @@ type fFreeDataOnDestroy: Boolean; fFreeDataAfterGenTexture: Boolean; fData: PByte; +{$IFNDEF OPENGL_ES} fIsResident: GLboolean; +{$ENDIF} fBorderColor: array[0..3] of Single; fDimension: TglBitmapPixelPosition; @@ -996,8 +1059,10 @@ type fWrapT: GLenum; fWrapR: GLenum; +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} //Swizzle fSwizzle: array[0..3] of GLenum; +{$IFEND} // CustomData fFilename: String; @@ -1026,7 +1091,7 @@ type procedure SetAnisotropic(const aValue: Integer); procedure CreateID; - procedure SetupParameters(out aBuildWithGlu: Boolean); + procedure SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF}); procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat; const aWidth: Integer = -1; const aHeight: Integer = -1); virtual; //be careful, aData could be freed by this method procedure GenTexture(const aTestTextureSize: Boolean = true); virtual; abstract; @@ -1060,7 +1125,9 @@ type property Dimension: TglBitmapPixelPosition read fDimension; property Data: PByte read fData; +{$IFNDEF OPENGL_ES} property IsResident: GLboolean read fIsResident; +{$ENDIF} procedure AfterConstruction; override; procedure BeforeDestruction; override; @@ -1133,7 +1200,9 @@ type function Clone: TglBitmap; function ConvertTo(const aFormat: TglBitmapFormat): Boolean; virtual; procedure Invert(const aUseRGB: Boolean = true; const aUseAlpha: Boolean = false); +{$IFNDEF OPENGL_ES} procedure SetBorderColor(const aRed, aGreen, aBlue, aAlpha: Single); +{$ENDIF} procedure FreeData; //ColorFill @@ -1147,7 +1216,9 @@ type const S: GLenum = GL_CLAMP_TO_EDGE; const T: GLenum = GL_CLAMP_TO_EDGE; const R: GLenum = GL_CLAMP_TO_EDGE); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} procedure SetSwizzle(const r, g, b, a: GLenum); +{$IFEND} procedure Bind(const aEnableTextureUnit: Boolean = true); virtual; procedure Unbind(const aDisableTextureUnit: Boolean = true); virtual; @@ -1167,17 +1238,21 @@ type {$IFDEF GLB_SUPPORT_JPEG_READ} function LoadJPEG(const aStream: TStream): Boolean; virtual; {$ENDIF} {$IFDEF GLB_SUPPORT_JPEG_WRITE} procedure SaveJPEG(const aStream: TStream); virtual; {$ENDIF} - function LoadBMP(const aStream: TStream): Boolean; virtual; - procedure SaveBMP(const aStream: TStream); virtual; + function LoadRAW(const aStream: TStream): Boolean; + procedure SaveRAW(const aStream: TStream); + + function LoadBMP(const aStream: TStream): Boolean; + procedure SaveBMP(const aStream: TStream); - function LoadTGA(const aStream: TStream): Boolean; virtual; - procedure SaveTGA(const aStream: TStream); virtual; + function LoadTGA(const aStream: TStream): Boolean; + procedure SaveTGA(const aStream: TStream); - function LoadDDS(const aStream: TStream): Boolean; virtual; - procedure SaveDDS(const aStream: TStream); virtual; + function LoadDDS(const aStream: TStream): Boolean; + procedure SaveDDS(const aStream: TStream); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +{$IFNDEF OPENGL_ES} TglBitmap1D = class(TglBitmap) protected procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat; @@ -1189,6 +1264,7 @@ type function FlipHorz: Boolean; override; procedure GenTexture(const aTestTextureSize: Boolean = true); override; end; +{$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TglBitmap2D = class(TglBitmap) @@ -1197,7 +1273,7 @@ type function GetScanline(const aIndex: Integer): Pointer; procedure SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat; const aWidth: Integer = - 1; const aHeight: Integer = - 1); override; - procedure UploadData(const aTarget: GLenum; const aBuildWithGlu: Boolean); + procedure UploadData(const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF}); public property Width; property Height; @@ -1206,7 +1282,9 @@ type procedure AfterConstruction; override; procedure GrabScreen(const aTop, aLeft, aRight, aBottom: Integer; const aFormat: TglBitmapFormat); +{$IFNDEF OPENGL_ES} procedure GetDataFromTexture; +{$ENDIF} procedure GenTexture(const aTestTextureSize: Boolean = true); override; function FlipHorz: Boolean; override; @@ -1217,23 +1295,29 @@ type end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} TglBitmapCubeMap = class(TglBitmap2D) protected + {$IFNDEF OPENGL_ES} fGenMode: Integer; + {$ENDIF} procedure GenTexture(const aTestTextureSize: Boolean = true); reintroduce; public procedure AfterConstruction; override; procedure GenerateCubeMap(const aCubeTarget: Cardinal; const aTestTextureSize: Boolean = true); - procedure Bind(const aEnableTexCoordsGen: Boolean = true; const aEnableTextureUnit: Boolean = true); reintroduce; virtual; - procedure Unbind(const aDisableTexCoordsGen: Boolean = true; const aDisableTextureUnit: Boolean = true); reintroduce; virtual; + procedure Bind({$IFNDEF OPENGL_ES}const aEnableTexCoordsGen: Boolean = true;{$ENDIF} const aEnableTextureUnit: Boolean = true); reintroduce; virtual; + procedure Unbind({$IFNDEF OPENGL_ES}const aDisableTexCoordsGen: Boolean = true;{$ENDIF} const aDisableTextureUnit: Boolean = true); reintroduce; virtual; end; +{$IFEND} +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TglBitmapNormalMap = class(TglBitmapCubeMap) public procedure AfterConstruction; override; procedure GenerateNormalMap(const aSize: Integer = 32; const aTestTextureSize: Boolean = true); end; +{$IFEND} const NULL_SIZE: TglBitmapPixelPosition = (Fields: []; X: 0; Y: 0); @@ -1256,8 +1340,11 @@ procedure glBitmapGetDefaultFilter(var aMin, aMag: Cardinal); procedure glBitmapGetDefaultTextureWrap(var S, T, R: Cardinal); function glBitmapPosition(X: Integer = -1; Y: Integer = -1): TglBitmapPixelPosition; -function glBitmapColorRec(const r, g, b, a: Cardinal): TglBitmapColorRec; -function glBitmapColorRecCmp(const r1, r2: TglBitmapColorRec): Boolean; +function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub; +function glBitmapRec4ui(const r, g, b, a: Cardinal): TglBitmapRec4ui; +function glBitmapRec4ul(const r, g, b, a: QWord): TglBitmapRec4ul; +function glBitmapRec4ubCompare(const r1, r2: TglBitmapRec4ub): Boolean; +function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean; function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D; @@ -1283,78 +1370,10 @@ uses Math, syncobjs, typinfo {$IF DEFINED(GLB_SUPPORT_JPEG_READ) AND DEFINED(GLB_LAZ_JPEG)}, FPReadJPEG{$IFEND}; -type -{$IFNDEF fpc} - QWord = System.UInt64; - PQWord = ^QWord; - - PtrInt = Longint; - PtrUInt = DWord; -{$ENDIF} - //////////////////////////////////////////////////////////////////////////////////////////////////// - TShiftRec = packed record - case Integer of - 0: (r, g, b, a: Byte); - 1: (arr: array[0..3] of Byte); - end; - +type TFormatDescriptor = class(TglBitmapFormatDescriptor) - private - function GetRedMask: QWord; - function GetGreenMask: QWord; - function GetBlueMask: QWord; - function GetAlphaMask: QWord; - protected - fFormat: TglBitmapFormat; - fWithAlpha: TglBitmapFormat; - fWithoutAlpha: TglBitmapFormat; - fOpenGLFormat: TglBitmapFormat; - fRGBInverted: TglBitmapFormat; - fUncompressed: TglBitmapFormat; - - fPixelSize: Single; - fIsCompressed: Boolean; - - fRange: TglBitmapColorRec; - fShift: TShiftRec; - - fglFormat: GLenum; - fglInternalFormat: GLenum; - fglDataFormat: GLenum; - - function GetIsCompressed: Boolean; override; - function GetHasRed: Boolean; override; - function GetHasGreen: Boolean; override; - function GetHasBlue: Boolean; override; - function GetHasAlpha: Boolean; override; - function GetHasColor: Boolean; override; - function GetIsGrayscale: Boolean; override; - - function GetRGBInverted: TglBitmapFormat; override; - function GetWithAlpha: TglBitmapFormat; override; - function GetWithoutAlpha: TglBitmapFormat; override; - function GetOpenGLFormat: TglBitmapFormat; override; - function GetUncompressed: TglBitmapFormat; override; - - function GetglFormat: GLenum; override; - function GetglInternalFormat: GLenum; override; - function GetglDataFormat: GLenum; override; - - function GetComponents: Integer; virtual; public - property Format: TglBitmapFormat read fFormat; - property Components: Integer read GetComponents; - property PixelSize: Single read fPixelSize; - - property Range: TglBitmapColorRec read fRange; - property Shift: TShiftRec read fShift; - - property RedMask: QWord read GetRedMask; - property GreenMask: QWord read GetGreenMask; - property BlueMask: QWord read GetBlueMask; - property AlphaMask: QWord read GetAlphaMask; - procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); virtual; abstract; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract; @@ -1365,8 +1384,7 @@ type procedure FreeMappingData(var aMappingData: Pointer); virtual; function IsEmpty: Boolean; virtual; - function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual; overload; - function MaskMatch(const aMask: TglBitmapMask): Boolean; virtual; overload; + function MaskMatch(const aMask: TglBitmapRec4ul): Boolean; virtual; procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual; @@ -1375,7 +1393,8 @@ type class procedure Init; class function Get(const aFormat: TglBitmapFormat): TFormatDescriptor; class function GetAlpha(const aFormat: TglBitmapFormat): TFormatDescriptor; - class function GetFromMask(const aMask: TglBitmapMask; const aBitCount: Integer = 0): TFormatDescriptor; + class function GetFromMask(const aMask: TglBitmapRec4ul; const aBitCount: Integer = 0): TFormatDescriptor; + class function GetFromPrecShift(const aPrec, aShift: TglBitmapRec4ub; const aBitCount: Integer): TFormatDescriptor; class procedure Clear; class procedure Finalize; end; @@ -1493,270 +1512,258 @@ type ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdAlpha4ub1 = class(TfdAlphaUB1) - constructor Create; override; + procedure SetValues; override; end; TfdAlpha8ub1 = class(TfdAlphaUB1) - constructor Create; override; + procedure SetValues; override; end; TfdAlpha16us1 = class(TfdAlphaUS1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance4ub1 = class(TfdLuminanceUB1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance8ub1 = class(TfdLuminanceUB1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance16us1 = class(TfdLuminanceUS1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance4Alpha4ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance6Alpha2ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance8Alpha8ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance12Alpha4us2 = class(TfdLuminanceAlphaUS2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance16Alpha16us2 = class(TfdLuminanceAlphaUS2) - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdR3G3B2ub1 = class(TfdUniversalUB1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBX4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdXRGB4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdR5G6B5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB5X1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdX1RGB5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB8ub3 = class(TfdRGBub3) - constructor Create; override; + procedure SetValues; override; end; TfdRGBX8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdXRGB8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB10X2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdX2RGB10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB16us3 = class(TfdRGBus3) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdARGB4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB5A1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdA1RGB5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdARGB8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA8ub4 = class(TfdRGBAub4) - constructor Create; override; + procedure SetValues; override; end; TfdRGB10A2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdA2RGB10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA16us4 = class(TfdRGBAus4) - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdBGRX4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdXBGR4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdB5G6R5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR5X1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdX1BGR5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR8ub3 = class(TfdBGRub3) - constructor Create; override; + procedure SetValues; override; end; TfdBGRX8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdXBGR8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR10X2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdX2BGR10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR16us3 = class(TfdBGRus3) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdABGR4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR5A1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdA1BGR5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdABGR8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA8ub4 = class(TfdBGRAub4) - constructor Create; override; + procedure SetValues; override; end; TfdBGR10A2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdA2BGR10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA16us4 = class(TfdBGRAus4) - constructor Create; override; + procedure SetValues; override; end; TfdDepth16us1 = class(TfdDepthUS1) - constructor Create; override; + procedure SetValues; override; end; TfdDepth24ui1 = class(TfdDepthUI1) - constructor Create; override; + procedure SetValues; override; end; TfdDepth32ui1 = class(TfdDepthUI1) - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx1RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx3RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx5RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TbmpBitfieldFormat = class(TFormatDescriptor) - private - procedure SetRedMask (const aValue: QWord); - procedure SetGreenMask(const aValue: QWord); - procedure SetBlueMask (const aValue: QWord); - procedure SetAlphaMask(const aValue: QWord); - - procedure Update(aMask: QWord; out aRange: Cardinal; out aShift: Byte); public - property RedMask: QWord read GetRedMask write SetRedMask; - property GreenMask: QWord read GetGreenMask write SetGreenMask; - property BlueMask: QWord read GetBlueMask write SetBlueMask; - property AlphaMask: QWord read GetAlphaMask write SetAlphaMask; - - property PixelSize: Single read fPixelSize write fPixelSize; - + procedure SetCustomValues(const aBPP: Integer; aMask: TglBitmapRec4ul); overload; + procedure SetCustomValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload; procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; end; @@ -1768,14 +1775,16 @@ type TbmpColorTable = array of TbmpColorTableEnty; TbmpColorTableFormat = class(TFormatDescriptor) private + fBitsPerPixel: Integer; fColorTable: TbmpColorTable; + protected + procedure SetValues; override; public - property PixelSize: Single read fPixelSize write fPixelSize; - property ColorTable: TbmpColorTable read fColorTable write fColorTable; - property Range: TglBitmapColorRec read fRange write fRange; - property Shift: TShiftRec read fShift write fShift; - property Format: TglBitmapFormat read fFormat write fFormat; + property ColorTable: TbmpColorTable read fColorTable write fColorTable; + property BitsPerPixel: Integer read fBitsPerPixel write fBitsPerPixel; + procedure SetCustomValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload; + procedure CalcValues; procedure CreateColorTable; procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; @@ -1900,7 +1909,7 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapColorRec(const r, g, b, a: Cardinal): TglBitmapColorRec; +function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub; begin result.r := r; result.g := g; @@ -1909,7 +1918,37 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapColorRecCmp(const r1, r2: TglBitmapColorRec): Boolean; +function glBitmapRec4ui(const r, g, b, a: Cardinal): TglBitmapRec4ui; +begin + result.r := r; + result.g := g; + result.b := b; + result.a := a; +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function glBitmapRec4ul(const r, g, b, a: QWord): TglBitmapRec4ul; +begin + result.r := r; + result.g := g; + result.b := b; + result.a := a; +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function glBitmapRec4ubCompare(const r1, r2: TglBitmapRec4ub): Boolean; +var + i: Integer; +begin + result := false; + for i := 0 to high(r1.arr) do + if (r1.arr[i] <> r2.arr[i]) then + exit; + result := true; +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean; var i: Integer; begin @@ -1934,14 +1973,14 @@ begin if (desc.IsCompressed) or (desc.glFormat = 0) then exit; - p := GetMem(ceil(25 * desc.PixelSize)); // 5 x 5 pixel + p := GetMemory(ceil(25 * desc.BytesPerPixel)); // 5 x 5 pixel md := desc.CreateMappingData; try tmp := p; desc.PreparePixel(px); for y := 0 to 4 do for x := 0 to 4 do begin - px.Data := glBitmapColorRec(0, 0, 0, 0); + px.Data := glBitmapRec4ui(0, 0, 0, 0); for i := 0 to 3 do begin if ((y < 3) and (y = i)) or ((y = 3) and (i < 3)) or @@ -1960,6 +1999,7 @@ begin finally desc.FreeMappingData(md); end; + result := TglBitmap2D.Create(glBitmapPosition(5, 5), aFormat, p); result.FreeDataOnDestroy := true; result.FreeDataAfterGenTexture := false; @@ -1967,7 +2007,7 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapShiftRec(const r, g, b, a: Byte): TShiftRec; +function glBitmapShiftRec(const r, g, b, a: Byte): TglBitmapRec4ub; begin result.r := r; result.g := g; @@ -2388,6 +2428,7 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} procedure glBitmapSetDefaultSwizzle(const r: GLenum = GL_RED; g: GLenum = GL_GREEN; b: GLenum = GL_BLUE; a: GLenum = GL_ALPHA); begin glDefaultSwizzle[0] := r; @@ -2395,6 +2436,7 @@ begin glDefaultSwizzle[2] := b; glDefaultSwizzle[3] := a; end; +{$IFEND} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function glBitmapGetDefaultDeleteTextureOnFree: Boolean; @@ -2435,6 +2477,7 @@ begin R := glBitmapDefaultWrapR; end; +{$IFNDEF OPENGL_ES} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure glBitmapGetDefaultSwizzle(var r, g, b, a: GLenum); begin @@ -2443,140 +2486,11 @@ begin b := glDefaultSwizzle[2]; a := glDefaultSwizzle[3]; end; +{$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetRedMask: QWord; -begin - result := fRange.r shl fShift.r; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetGreenMask: QWord; -begin - result := fRange.g shl fShift.g; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetBlueMask: QWord; -begin - result := fRange.b shl fShift.b; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetAlphaMask: QWord; -begin - result := fRange.a shl fShift.a; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetIsCompressed: Boolean; -begin - result := fIsCompressed; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasRed: Boolean; -begin - result := (fRange.r > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasGreen: Boolean; -begin - result := (fRange.g > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasBlue: Boolean; -begin - result := (fRange.b > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasAlpha: Boolean; -begin - result := (fRange.a > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasColor: Boolean; -begin - result := HasRed or HasGreen or HasAlpha; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetIsGrayscale: Boolean; -var - r, g, b: QWord; -begin - r := RedMask; - g := GreenMask; - b := BlueMask; - result := (r = g) and (g = b) and (r > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetRGBInverted: TglBitmapFormat; -begin - result := fRGBInverted; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetWithAlpha: TglBitmapFormat; -begin - result := fWithAlpha; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetWithoutAlpha: TglBitmapFormat; -begin - result := fWithoutAlpha; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetOpenGLFormat: TglBitmapFormat; -begin - result := fOpenGLFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetUncompressed: TglBitmapFormat; -begin - result := fUncompressed; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglFormat: GLenum; -begin - result := fglFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglInternalFormat: GLenum; -begin - result := fglInternalFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglDataFormat: GLenum; -begin - result := fglDataFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetComponents: Integer; -var - i: Integer; -begin - result := 0; - for i := 0 to 3 do - if (fRange.arr[i] > 0) then - inc(result); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TFormatDescriptor.GetSize(const aSize: TglBitmapPixelPosition): Integer; var w, h: Integer; @@ -2595,7 +2509,7 @@ begin result := 0; if (aWidth <= 0) or (aHeight <= 0) then exit; - result := Ceil(aWidth * aHeight * fPixelSize); + result := Ceil(aWidth * aHeight * BytesPerPixel); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2617,58 +2531,34 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; +function TFormatDescriptor.MaskMatch(const aMask: TglBitmapRec4ul): Boolean; +var + i: Integer; + m: TglBitmapRec4ul; begin result := false; - if (aRedMask = 0) and (aGreenMask = 0) and (aBlueMask = 0) and (aAlphaMask = 0) then + if (aMask.r = 0) and (aMask.g = 0) and (aMask.b = 0) and (aMask.a = 0) then raise EglBitmap.Create('FormatCheckFormat - All Masks are 0'); - if (aRedMask <> RedMask) then - exit; - if (aGreenMask <> GreenMask) then - exit; - if (aBlueMask <> BlueMask) then - exit; - if (aAlphaMask <> AlphaMask) then - exit; + m := Mask; + for i := 0 to 3 do + if (aMask.arr[i] <> m.arr[i]) then + exit; result := true; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.MaskMatch(const aMask: TglBitmapMask): Boolean; -begin - result := MaskMatch(aMask.r, aMask.g, aMask.b, aMask.a); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TFormatDescriptor.PreparePixel(out aPixel: TglBitmapPixelData); begin FillChar(aPixel{%H-}, SizeOf(aPixel), 0); - aPixel.Data := fRange; - aPixel.Range := fRange; + aPixel.Data := Range; aPixel.Format := fFormat; + aPixel.Range := Range; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// constructor TFormatDescriptor.Create; begin inherited Create; - - fFormat := tfEmpty; - fWithAlpha := tfEmpty; - fWithoutAlpha := tfEmpty; - fOpenGLFormat := tfEmpty; - fRGBInverted := tfEmpty; - fUncompressed := tfEmpty; - - fPixelSize := 0.0; - fIsCompressed := false; - - fglFormat := 0; - fglInternalFormat := 0; - fglDataFormat := 0; - - FillChar(fRange, 0, SizeOf(fRange)); - FillChar(fShift, 0, SizeOf(fShift)); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2716,8 +2606,8 @@ var begin aData^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - aData^ := aData^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + aData^ := aData^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData); end; @@ -2726,7 +2616,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (aData^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (aData^ shr fShift.arr[i]) and Range.arr[i]; inc(aData); end; @@ -2874,8 +2764,8 @@ var begin PWord(aData)^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - PWord(aData)^ := PWord(aData)^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + PWord(aData)^ := PWord(aData)^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData, 2); end; @@ -2884,7 +2774,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (PWord(aData)^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (PWord(aData)^ shr fShift.arr[i]) and Range.arr[i]; inc(aData, 2); end; @@ -3048,8 +2938,8 @@ var begin PCardinal(aData)^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - PCardinal(aData)^ := PCardinal(aData)^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + PCardinal(aData)^ := PCardinal(aData)^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData, 4); end; @@ -3058,7 +2948,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (PCardinal(aData)^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (PCardinal(aData)^ shr fShift.arr[i]) and Range.arr[i]; inc(aData, 2); end; @@ -3083,1148 +2973,1104 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TfdAlpha4ub1.Create; +procedure TfdAlpha4ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfAlpha4ub1; fWithAlpha := tfAlpha4ub1; + fPrecision := glBitmapRec4ub(0, 0, 0, 8); + fShift := glBitmapRec4ub(0, 0, 0, 0); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfAlpha4ub1; - fRange.a := $FF; fglFormat := GL_ALPHA; fglInternalFormat := GL_ALPHA4; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfAlpha8ub1; +{$ENDIF} end; -constructor TfdAlpha8ub1.Create; +procedure TfdAlpha8ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfAlpha8ub1; fWithAlpha := tfAlpha8ub1; + fPrecision := glBitmapRec4ub(0, 0, 0, 8); + fShift := glBitmapRec4ub(0, 0, 0, 0); fOpenGLFormat := tfAlpha8ub1; - fRange.a := $FF; fglFormat := GL_ALPHA; - fglInternalFormat := GL_ALPHA8; + fglInternalFormat := {$IFNDEF OPENGL_ES}GL_ALPHA8{$ELSE}GL_ALPHA{$ENDIF}; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdAlpha16us1.Create; +procedure TfdAlpha16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfAlpha16us1; fWithAlpha := tfAlpha16us1; + fPrecision := glBitmapRec4ub(0, 0, 0, 16); + fShift := glBitmapRec4ub(0, 0, 0, 0); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfAlpha16us1; - fRange.a := $FFFF; fglFormat := GL_ALPHA; fglInternalFormat := GL_ALPHA16; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfAlpha8ub1; +{$ENDIF} end; -constructor TfdLuminance4ub1.Create; +procedure TfdLuminance4ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfLuminance4ub1; fWithAlpha := tfLuminance4Alpha4ub2; fWithoutAlpha := tfLuminance4ub1; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 0, 0, 0); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance4ub1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; fglFormat := GL_LUMINANCE; fglInternalFormat := GL_LUMINANCE4; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfLuminance8ub1; +{$ENDIF} end; -constructor TfdLuminance8ub1.Create; +procedure TfdLuminance8ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfLuminance8ub1; fWithAlpha := tfLuminance8Alpha8ub2; fWithoutAlpha := tfLuminance8ub1; fOpenGLFormat := tfLuminance8ub1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_LUMINANCE; - fglInternalFormat := GL_LUMINANCE8; + fglInternalFormat := {$IFNDEF OPENGL_ES}GL_LUMINANCE8{$ELSE}GL_LUMINANCE{$ENDIF}; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance16us1.Create; +procedure TfdLuminance16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance16us1; fWithAlpha := tfLuminance16Alpha16us2; fWithoutAlpha := tfLuminance16us1; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub( 0, 0, 0, 0); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance16us1; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; fglFormat := GL_LUMINANCE; fglInternalFormat := GL_LUMINANCE16; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfLuminance8ub1; +{$ENDIF} end; -constructor TfdLuminance4Alpha4ub2.Create; +procedure TfdLuminance4Alpha4ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance4Alpha4ub2; fWithAlpha := tfLuminance4Alpha4ub2; fWithoutAlpha := tfLuminance4ub1; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance4Alpha4ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE4_ALPHA4; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfLuminance8Alpha8ub2; +{$ENDIF} end; -constructor TfdLuminance6Alpha2ub2.Create; +procedure TfdLuminance6Alpha2ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance6Alpha2ub2; fWithAlpha := tfLuminance6Alpha2ub2; fWithoutAlpha := tfLuminance8ub1; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance6Alpha2ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE6_ALPHA2; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfLuminance8Alpha8ub2; +{$ENDIF} end; -constructor TfdLuminance8Alpha8ub2.Create; +procedure TfdLuminance8Alpha8ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance8Alpha8ub2; fWithAlpha := tfLuminance8Alpha8ub2; fWithoutAlpha := tfLuminance8ub1; fOpenGLFormat := tfLuminance8Alpha8ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); fglFormat := GL_LUMINANCE_ALPHA; - fglInternalFormat := GL_LUMINANCE8_ALPHA8; + fglInternalFormat := {$IFNDEF OPENGL_ES}GL_LUMINANCE8_ALPHA8{$ELSE}GL_LUMINANCE_ALPHA{$ENDIF}; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance12Alpha4us2.Create; +procedure TfdLuminance12Alpha4us2.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfLuminance12Alpha4us2; fWithAlpha := tfLuminance12Alpha4us2; fWithoutAlpha := tfLuminance16us1; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 16); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance12Alpha4us2; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 16; fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE12_ALPHA4; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfLuminance8Alpha8ub2; +{$ENDIF} end; -constructor TfdLuminance16Alpha16us2.Create; +procedure TfdLuminance16Alpha16us2.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfLuminance16Alpha16us2; fWithAlpha := tfLuminance16Alpha16us2; fWithoutAlpha := tfLuminance16us1; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 16); +{$IFNDEF OPENGL_ES} fOpenGLFormat := tfLuminance16Alpha16us2; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 16; fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE16_ALPHA16; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfLuminance8Alpha8ub2; +{$ENDIF} end; -constructor TfdR3G3B2ub1.Create; +procedure TfdR3G3B2ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfR3G3B2ub1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfR3G3B2ub1; - fOpenGLFormat := tfR3G3B2ub1; fRGBInverted := tfEmpty; - fRange.r := $07; - fRange.g := $07; - fRange.b := $03; - fShift.r := 5; - fShift.g := 2; - fShift.b := 0; + fPrecision := glBitmapRec4ub(3, 3, 2, 0); + fShift := glBitmapRec4ub(5, 2, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfR3G3B2ub1; fglFormat := GL_RGB; fglInternalFormat := GL_R3_G3_B2; fglDataFormat := GL_UNSIGNED_BYTE_3_3_2; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdRGBX4us1.Create; +procedure TfdRGBX4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGBX4us1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfRGBX4us1; - fOpenGLFormat := tfRGBX4us1; fRGBInverted := tfBGRX4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $00; - fShift.r := 12; - fShift.g := 8; - fShift.b := 4; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub(12, 8, 4, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGBX4us1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdXRGB4us1.Create; +procedure TfdXRGB4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfXRGB4us1; fWithAlpha := tfARGB4us1; fWithoutAlpha := tfXRGB4us1; - fOpenGLFormat := tfXRGB4us1; fRGBInverted := tfXBGR4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 8; - fShift.g := 4; - fShift.b := 0; + fPrecision := glBitmapRec4ub(4, 4, 4, 0); + fShift := glBitmapRec4ub(8, 4, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfXRGB4us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdR5G6B5us1.Create; +procedure TfdR5G6B5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfR5G6B5us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfR5G6B5us1; - fOpenGLFormat := tfR5G6B5us1; fRGBInverted := tfB5G6R5us1; - fRange.r := $1F; - fRange.g := $3F; - fRange.b := $1F; - fShift.r := 11; - fShift.g := 5; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 5, 6, 5, 0); + fShift := glBitmapRec4ub(11, 5, 0, 0); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} + fOpenGLFormat := tfR5G6B5us1; fglFormat := GL_RGB; fglInternalFormat := GL_RGB565; fglDataFormat := GL_UNSIGNED_SHORT_5_6_5; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$IFEND} end; -constructor TfdRGB5X1us1.Create; +procedure TfdRGB5X1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGB5X1us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfRGB5X1us1; - fOpenGLFormat := tfRGB5X1us1; fRGBInverted := tfBGR5X1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 11; - fShift.g := 6; - fShift.b := 1; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub(11, 6, 1, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGB5X1us1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdX1RGB5us1.Create; +procedure TfdX1RGB5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfX1RGB5us1; fWithAlpha := tfA1RGB5us1; fWithoutAlpha := tfX1RGB5us1; - fOpenGLFormat := tfX1RGB5us1; fRGBInverted := tfX1BGR5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 10; - fShift.g := 5; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub(10, 5, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfX1RGB5us1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdRGB8ub3.Create; +procedure TfdRGB8ub3.SetValues; begin - inherited Create; - fPixelSize := 3.0; + inherited SetValues; + fBitsPerPixel := 24; fFormat := tfRGB8ub3; fWithAlpha := tfRGBA8ub4; fWithoutAlpha := tfRGB8ub3; - fOpenGLFormat := tfRGB8ub3; fRGBInverted := tfBGR8ub3; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 8, 16, 0); + fOpenGLFormat := tfRGB8ub3; fglFormat := GL_RGB; - fglInternalFormat := GL_RGB8; + fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGB8{$ELSE}GL_RGB{$IFEND}; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdRGBX8ui1.Create; +procedure TfdRGBX8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGBX8ui1; fWithAlpha := tfRGBA8ui1; fWithoutAlpha := tfRGBX8ui1; - fOpenGLFormat := tfRGB8ub3; fRGBInverted := tfBGRX8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 24; - fShift.g := 16; - fShift.b := 8; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(24, 16, 8, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGBX8ui1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$ENDIF} end; -constructor TfdXRGB8ui1.Create; +procedure TfdXRGB8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfXRGB8ui1; fWithAlpha := tfXRGB8ui1; fWithoutAlpha := tfXRGB8ui1; - fOpenGLFormat := tfRGB8ub3; + fOpenGLFormat := tfXRGB8ui1; fRGBInverted := tfXBGR8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(16, 8, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfXRGB8ui1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$ENDIF} end; -constructor TfdRGB10X2ui1.Create; +procedure TfdRGB10X2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGB10X2ui1; fWithAlpha := tfRGB10A2ui1; fWithoutAlpha := tfRGB10X2ui1; - fOpenGLFormat := tfRGB10X2ui1; fRGBInverted := tfBGR10X2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 22; - fShift.g := 12; - fShift.b := 2; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub(22, 12, 2, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGB10X2ui1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; +{$ELSE} + fOpenGLFormat := tfRGB16us3; +{$ENDIF} end; -constructor TfdX2RGB10ui1.Create; +procedure TfdX2RGB10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfX2RGB10ui1; fWithAlpha := tfA2RGB10ui1; fWithoutAlpha := tfX2RGB10ui1; - fOpenGLFormat := tfX2RGB10ui1; fRGBInverted := tfX2BGR10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 20; - fShift.g := 10; - fShift.b := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub(20, 10, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfX2RGB10ui1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; +{$ELSE} + fOpenGLFormat := tfRGB16us3; +{$ENDIF} end; -constructor TfdRGB16us3.Create; +procedure TfdRGB16us3.SetValues; begin - inherited Create; - fPixelSize := 6.0; + inherited SetValues; + fBitsPerPixel := 48; fFormat := tfRGB16us3; fWithAlpha := tfRGBA16us4; fWithoutAlpha := tfRGB16us3; - fOpenGLFormat := tfRGB16us3; fRGBInverted := tfBGR16us3; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fShift.r := 0; - fShift.g := 16; - fShift.b := 32; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub( 0, 16, 32, 0); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} + fOpenGLFormat := tfRGB16us3; fglFormat := GL_RGB; - fglInternalFormat := GL_RGB16; + fglInternalFormat := {$IFNDEF OPENGL_ES}GL_RGB16{$ELSE}GL_RGB16UI{$ENDIF}; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$IFEND} end; -constructor TfdRGBA4us1.Create; +procedure TfdRGBA4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGBA4us1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfRGBX4us1; fOpenGLFormat := tfRGBA4us1; fRGBInverted := tfBGRA4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 12; - fShift.g := 8; - fShift.b := 4; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub(12, 8, 4, 0); fglFormat := GL_RGBA; - fglInternalFormat := GL_RGBA4; + fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGBA8{$ELSE}GL_RGBA{$IFEND}; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; end; -constructor TfdARGB4us1.Create; +procedure TfdARGB4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfARGB4us1; fWithAlpha := tfARGB4us1; fWithoutAlpha := tfXRGB4us1; - fOpenGLFormat := tfARGB4us1; fRGBInverted := tfABGR4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 8; - fShift.g := 4; - fShift.b := 0; - fShift.a := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 8, 4, 0, 12); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfARGB4us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; +{$ELSE} + fOpenGLFormat := tfRGBA4us1; +{$ENDIF} end; -constructor TfdRGB5A1us1.Create; +procedure TfdRGB5A1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGB5A1us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfRGB5X1us1; fOpenGLFormat := tfRGB5A1us1; fRGBInverted := tfBGR5A1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 11; - fShift.g := 6; - fShift.b := 1; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub(11, 6, 1, 0); fglFormat := GL_RGBA; - fglInternalFormat := GL_RGB5_A1; + fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)}GL_RGB5_A1{$ELSE}GL_RGBA{$IFEND}; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; end; -constructor TfdA1RGB5us1.Create; +procedure TfdA1RGB5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfA1RGB5us1; fWithAlpha := tfA1RGB5us1; fWithoutAlpha := tfX1RGB5us1; - fOpenGLFormat := tfA1RGB5us1; fRGBInverted := tfA1BGR5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 10; - fShift.g := 5; - fShift.b := 0; - fShift.a := 15; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub(10, 5, 0, 15); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfA1RGB5us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; +{$ELSE} + fOpenGLFormat := tfRGB5A1us1; +{$ENDIF} end; -constructor TfdRGBA8ui1.Create; +procedure TfdRGBA8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGBA8ui1; fWithAlpha := tfRGBA8ui1; fWithoutAlpha := tfRGBX8ui1; - fOpenGLFormat := tfRGBA8ui1; fRGBInverted := tfBGRA8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 24; - fShift.g := 16; - fShift.b := 8; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(24, 16, 8, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGBA8ui1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4; +{$ENDIF} end; -constructor TfdARGB8ui1.Create; +procedure TfdARGB8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfARGB8ui1; fWithAlpha := tfARGB8ui1; fWithoutAlpha := tfXRGB8ui1; - fOpenGLFormat := tfARGB8ui1; fRGBInverted := tfABGR8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(16, 8, 0, 24); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfARGB8ui1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4; +{$ENDIF} end; -constructor TfdRGBA8ub4.Create; +procedure TfdRGBA8ub4.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGBA8ub4; fWithAlpha := tfRGBA8ub4; fWithoutAlpha := tfRGB8ub3; fOpenGLFormat := tfRGBA8ub4; fRGBInverted := tfBGRA8ub4; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 0, 8, 16, 24); fglFormat := GL_RGBA; - fglInternalFormat := GL_RGBA8; + fglInternalFormat := {$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)}GL_RGBA8{$ELSE}GL_RGBA{$IFEND}; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdRGB10A2ui1.Create; +procedure TfdRGB10A2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGB10A2ui1; fWithAlpha := tfRGB10A2ui1; fWithoutAlpha := tfRGB10X2ui1; - fOpenGLFormat := tfRGB10A2ui1; fRGBInverted := tfBGR10A2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 22; - fShift.g := 12; - fShift.b := 2; - fShift.a := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub(22, 12, 2, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfRGB10A2ui1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; +{$ELSE} + fOpenGLFormat := tfA2RGB10ui1; +{$ENDIF} end; -constructor TfdA2RGB10ui1.Create; +procedure TfdA2RGB10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfA2RGB10ui1; fWithAlpha := tfA2RGB10ui1; fWithoutAlpha := tfX2RGB10ui1; - fOpenGLFormat := tfA2RGB10ui1; fRGBInverted := tfA2BGR10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 20; - fShift.g := 10; - fShift.b := 0; - fShift.a := 30; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub(20, 10, 0, 30); +{$IF NOT DEFINED(OPENGL_ES)} + fOpenGLFormat := tfA2RGB10ui1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; +{$ELSEIF DEFINED(OPENGL_ES_3_0)} + fOpenGLFormat := tfA2RGB10ui1; + fglFormat := GL_RGBA; + fglInternalFormat := GL_RGB10_A2; + fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; +{$ELSE} + fOpenGLFormat := tfRGBA8ui1; +{$IFEND} end; -constructor TfdRGBA16us4.Create; +procedure TfdRGBA16us4.SetValues; begin - inherited Create; - fPixelSize := 8.0; + inherited SetValues; + fBitsPerPixel := 64; fFormat := tfRGBA16us4; fWithAlpha := tfRGBA16us4; fWithoutAlpha := tfRGB16us3; - fOpenGLFormat := tfRGBA16us4; fRGBInverted := tfBGRA16us4; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 16; - fShift.b := 32; - fShift.a := 48; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 16, 32, 48); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} + fOpenGLFormat := tfRGBA16us4; fglFormat := GL_RGBA; - fglInternalFormat := GL_RGBA16; + fglInternalFormat := {$IFNDEF OPENGL_ES}GL_RGBA16{$ELSE}GL_RGBA16UI{$ENDIF}; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4; +{$IFEND} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TfdBGRX4us1.Create; +procedure TfdBGRX4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGRX4us1; fWithAlpha := tfBGRA4us1; fWithoutAlpha := tfBGRX4us1; - fOpenGLFormat := tfBGRX4us1; fRGBInverted := tfRGBX4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 4; - fShift.g := 8; - fShift.b := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub( 4, 8, 12, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRX4us1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdXBGR4us1.Create; +procedure TfdXBGR4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfXBGR4us1; fWithAlpha := tfABGR4us1; fWithoutAlpha := tfXBGR4us1; - fOpenGLFormat := tfXBGR4us1; fRGBInverted := tfXRGB4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 0; - fShift.g := 4; - fShift.b := 8; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub( 0, 4, 8, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfXBGR4us1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdB5G6R5us1.Create; +procedure TfdB5G6R5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfB5G6R5us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfB5G6R5us1; - fOpenGLFormat := tfB5G6R5us1; fRGBInverted := tfR5G6B5us1; - fRange.r := $1F; - fRange.g := $3F; - fRange.b := $1F; - fShift.r := 0; - fShift.g := 5; - fShift.b := 11; + fPrecision := glBitmapRec4ub( 5, 6, 5, 0); + fShift := glBitmapRec4ub( 0, 5, 11, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfB5G6R5us1; fglFormat := GL_RGB; fglInternalFormat := GL_RGB565; fglDataFormat := GL_UNSIGNED_SHORT_5_6_5_REV; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdBGR5X1us1.Create; +procedure TfdBGR5X1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGR5X1us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfBGR5X1us1; - fOpenGLFormat := tfBGR5X1us1; fRGBInverted := tfRGB5X1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 1; - fShift.g := 6; - fShift.b := 11; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub( 1, 6, 11, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR5X1us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdX1BGR5us1.Create; +procedure TfdX1BGR5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfX1BGR5us1; fWithAlpha := tfA1BGR5us1; fWithoutAlpha := tfX1BGR5us1; - fOpenGLFormat := tfX1BGR5us1; fRGBInverted := tfX1RGB5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 0; - fShift.g := 5; - fShift.b := 10; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub( 0, 5, 10, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfX1BGR5us1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; +{$ELSE} + fOpenGLFormat := tfR5G6B5us1; +{$ENDIF} end; -constructor TfdBGR8ub3.Create; +procedure TfdBGR8ub3.SetValues; begin - inherited Create; - fPixelSize := 3.0; + inherited SetValues; + fBitsPerPixel := 24; fFormat := tfBGR8ub3; fWithAlpha := tfBGRA8ub4; fWithoutAlpha := tfBGR8ub3; - fOpenGLFormat := tfBGR8ub3; fRGBInverted := tfRGB8ub3; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(16, 8, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR8ub3; fglFormat := GL_BGR; fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$ENDIF} end; -constructor TfdBGRX8ui1.Create; +procedure TfdBGRX8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGRX8ui1; fWithAlpha := tfBGRA8ui1; fWithoutAlpha := tfBGRX8ui1; - fOpenGLFormat := tfBGRX8ui1; fRGBInverted := tfRGBX8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 8; - fShift.g := 16; - fShift.b := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub( 8, 16, 24, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRX8ui1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$ENDIF} end; -constructor TfdXBGR8ui1.Create; +procedure TfdXBGR8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfXBGR8ui1; fWithAlpha := tfABGR8ui1; fWithoutAlpha := tfXBGR8ui1; - fOpenGLFormat := tfXBGR8ui1; fRGBInverted := tfXRGB8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub( 0, 8, 16, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfXBGR8ui1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; +{$ELSE} + fOpenGLFormat := tfRGB8ub3; +{$ENDIF} end; -constructor TfdBGR10X2ui1.Create; +procedure TfdBGR10X2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGR10X2ui1; fWithAlpha := tfBGR10A2ui1; fWithoutAlpha := tfBGR10X2ui1; - fOpenGLFormat := tfBGR10X2ui1; fRGBInverted := tfRGB10X2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 2; - fShift.g := 12; - fShift.b := 22; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub( 2, 12, 22, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR10X2ui1; fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; +{$ELSE} + fOpenGLFormat := tfRGB16us3; +{$ENDIF} end; -constructor TfdX2BGR10ui1.Create; +procedure TfdX2BGR10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfX2BGR10ui1; fWithAlpha := tfA2BGR10ui1; fWithoutAlpha := tfX2BGR10ui1; - fOpenGLFormat := tfX2BGR10ui1; fRGBInverted := tfX2RGB10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 0; - fShift.g := 10; - fShift.b := 20; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub( 0, 10, 20, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfX2BGR10ui1; fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; +{$ELSE} + fOpenGLFormat := tfRGB16us3; +{$ENDIF} end; -constructor TfdBGR16us3.Create; +procedure TfdBGR16us3.SetValues; begin - inherited Create; - fPixelSize := 6.0; + inherited SetValues; + fBitsPerPixel := 48; fFormat := tfBGR16us3; fWithAlpha := tfBGRA16us4; fWithoutAlpha := tfBGR16us3; - fOpenGLFormat := tfBGR16us3; fRGBInverted := tfRGB16us3; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fShift.r := 32; - fShift.g := 16; - fShift.b := 0; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub(32, 16, 0, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR16us3; fglFormat := GL_BGR; fglInternalFormat := GL_RGB16; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfRGB16us3; +{$ENDIF} end; -constructor TfdBGRA4us1.Create; +procedure TfdBGRA4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGRA4us1; fWithAlpha := tfBGRA4us1; fWithoutAlpha := tfBGRX4us1; - fOpenGLFormat := tfBGRA4us1; fRGBInverted := tfRGBA4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 4; - fShift.g := 8; - fShift.b := 12; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 4, 8, 12, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRA4us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; +{$ELSE} + fOpenGLFormat := tfRGBA4us1; +{$ENDIF} end; -constructor TfdABGR4us1.Create; +procedure TfdABGR4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfABGR4us1; fWithAlpha := tfABGR4us1; fWithoutAlpha := tfXBGR4us1; - fOpenGLFormat := tfABGR4us1; fRGBInverted := tfARGB4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 0; - fShift.g := 4; - fShift.b := 8; - fShift.a := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 0, 4, 8, 12); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfABGR4us1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; +{$ELSE} + fOpenGLFormat := tfRGBA4us1; +{$ENDIF} end; -constructor TfdBGR5A1us1.Create; +procedure TfdBGR5A1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGR5A1us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfBGR5X1us1; - fOpenGLFormat := tfBGR5A1us1; fRGBInverted := tfRGB5A1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 1; - fShift.g := 6; - fShift.b := 11; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub( 1, 6, 11, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR5A1us1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; +{$ELSE} + fOpenGLFormat := tfRGB5A1us1; +{$ENDIF} end; -constructor TfdA1BGR5us1.Create; +procedure TfdA1BGR5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfA1BGR5us1; fWithAlpha := tfA1BGR5us1; fWithoutAlpha := tfX1BGR5us1; - fOpenGLFormat := tfA1BGR5us1; fRGBInverted := tfA1RGB5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 0; - fShift.g := 5; - fShift.b := 10; - fShift.a := 15; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub( 0, 5, 10, 15); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfA1BGR5us1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; +{$ELSE} + fOpenGLFormat := tfRGB5A1us1; +{$ENDIF} end; -constructor TfdBGRA8ui1.Create; +procedure TfdBGRA8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGRA8ui1; fWithAlpha := tfBGRA8ui1; fWithoutAlpha := tfBGRX8ui1; - fOpenGLFormat := tfBGRA8ui1; fRGBInverted := tfRGBA8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 8; - fShift.g := 16; - fShift.b := 24; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 8, 16, 24, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRA8ui1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4; +{$ENDIF} end; -constructor TfdABGR8ui1.Create; +procedure TfdABGR8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfABGR8ui1; fWithAlpha := tfABGR8ui1; fWithoutAlpha := tfXBGR8ui1; - fOpenGLFormat := tfABGR8ui1; fRGBInverted := tfARGB8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 0, 8, 16, 24); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfABGR8ui1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4 +{$ENDIF} end; -constructor TfdBGRA8ub4.Create; +procedure TfdBGRA8ub4.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGRA8ub4; fWithAlpha := tfBGRA8ub4; fWithoutAlpha := tfBGR8ub3; - fOpenGLFormat := tfBGRA8ub4; fRGBInverted := tfRGBA8ub4; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(16, 8, 0, 24); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRA8ub4; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := tfRGBA8ub4; +{$ENDIF} end; -constructor TfdBGR10A2ui1.Create; +procedure TfdBGR10A2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGR10A2ui1; fWithAlpha := tfBGR10A2ui1; fWithoutAlpha := tfBGR10X2ui1; - fOpenGLFormat := tfBGR10A2ui1; fRGBInverted := tfRGB10A2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 2; - fShift.g := 12; - fShift.b := 22; - fShift.a := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub( 2, 12, 22, 0); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGR10A2ui1; fglFormat := GL_BGRA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; +{$ELSE} + fOpenGLFormat := tfA2RGB10ui1; +{$ENDIF} end; -constructor TfdA2BGR10ui1.Create; +procedure TfdA2BGR10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfA2BGR10ui1; fWithAlpha := tfA2BGR10ui1; fWithoutAlpha := tfX2BGR10ui1; - fOpenGLFormat := tfA2BGR10ui1; fRGBInverted := tfA2RGB10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 0; - fShift.g := 10; - fShift.b := 20; - fShift.a := 30; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub( 0, 10, 20, 30); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfA2BGR10ui1; fglFormat := GL_RGBA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; +{$ELSE} + fOpenGLFormat := tfA2RGB10ui1; +{$ENDIF} end; -constructor TfdBGRA16us4.Create; +procedure TfdBGRA16us4.SetValues; begin - inherited Create; - fPixelSize := 8.0; + inherited SetValues; + fBitsPerPixel := 64; fFormat := tfBGRA16us4; fWithAlpha := tfBGRA16us4; fWithoutAlpha := tfBGR16us3; - fOpenGLFormat := tfBGRA16us4; fRGBInverted := tfRGBA16us4; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 32; - fShift.g := 16; - fShift.b := 0; - fShift.a := 48; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub(32, 16, 0, 48); +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfBGRA16us4; fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA16; fglDataFormat := GL_UNSIGNED_SHORT; +{$ELSE} + fOpenGLFormat := tfRGBA16us4; +{$ENDIF} end; -constructor TfdDepth16us1.Create; +procedure TfdDepth16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfDepth16us1; fWithoutAlpha := tfDepth16us1; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 0); +{$IF NOT DEFINED (OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} fOpenGLFormat := tfDepth16us1; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT16; fglDataFormat := GL_UNSIGNED_SHORT; +{$IFEND} end; -constructor TfdDepth24ui1.Create; +procedure TfdDepth24ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfDepth24ui1; fWithoutAlpha := tfDepth24ui1; fOpenGLFormat := tfDepth24ui1; - fRange.r := $FFFFFFFF; - fRange.g := $FFFFFFFF; - fRange.b := $FFFFFFFF; - fRange.a := $FFFFFFFF; + fPrecision := glBitmapRec4ub(32, 32, 32, 32); + fShift := glBitmapRec4ub( 0, 0, 0, 0); +{$IF NOT DEFINED (OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} + fOpenGLFormat := tfDepth24ui1; fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT24; fglDataFormat := GL_UNSIGNED_INT; +{$IFEND} end; -constructor TfdDepth32ui1.Create; +procedure TfdDepth32ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfDepth32ui1; fWithoutAlpha := tfDepth32ui1; + fPrecision := glBitmapRec4ub(32, 32, 32, 32); + fShift := glBitmapRec4ub( 0, 0, 0, 0); +{$IF NOT DEFINED(OPENGL_ES)} fOpenGLFormat := tfDepth32ui1; - fRange.r := $FFFFFFFF; - fRange.g := $FFFFFFFF; - fRange.b := $FFFFFFFF; - fRange.a := $FFFFFFFF; fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT32; fglDataFormat := GL_UNSIGNED_INT; +{$ELSEIF DEFINED(OPENGL_ES_3_0)} + fOpenGLFormat := tfDepth24ui1; +{$ELSEIF DEFINED(OPENGL_ES_2_0)} + fOpenGLFormat := tfDepth16us1; +{$IFEND} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4240,18 +4086,22 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx1RGBA.Create; +procedure TfdS3tcDtx1RGBA.SetValues; begin - inherited Create; + inherited SetValues; fFormat := tfS3tcDtx1RGBA; fWithAlpha := tfS3tcDtx1RGBA; - fOpenGLFormat := tfS3tcDtx1RGBA; fUncompressed := tfRGB5A1us1; - fPixelSize := 0.5; + fBitsPerPixel := 4; fIsCompressed := true; +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfS3tcDtx1RGBA; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := fUncompressed; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4267,18 +4117,22 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx3RGBA.Create; +procedure TfdS3tcDtx3RGBA.SetValues; begin - inherited Create; + inherited SetValues; fFormat := tfS3tcDtx3RGBA; fWithAlpha := tfS3tcDtx3RGBA; - fOpenGLFormat := tfS3tcDtx3RGBA; fUncompressed := tfRGBA8ub4; - fPixelSize := 1.0; + fBitsPerPixel := 8; fIsCompressed := true; +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfS3tcDtx3RGBA; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := fUncompressed; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4294,23 +4148,100 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx5RGBA.Create; +procedure TfdS3tcDtx5RGBA.SetValues; begin - inherited Create; + inherited SetValues; fFormat := tfS3tcDtx3RGBA; fWithAlpha := tfS3tcDtx3RGBA; - fOpenGLFormat := tfS3tcDtx3RGBA; fUncompressed := tfRGBA8ub4; - fPixelSize := 1.0; + fBitsPerPixel := 8; fIsCompressed := true; +{$IFNDEF OPENGL_ES} + fOpenGLFormat := tfS3tcDtx3RGBA; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; fglDataFormat := GL_UNSIGNED_BYTE; +{$ELSE} + fOpenGLFormat := fUncompressed; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmapFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TglBitmapFormatDescriptor.GetHasRed: Boolean; +begin + result := (fPrecision.r > 0); +end; + +function TglBitmapFormatDescriptor.GetHasGreen: Boolean; +begin + result := (fPrecision.g > 0); +end; + +function TglBitmapFormatDescriptor.GetHasBlue: Boolean; +begin + result := (fPrecision.b > 0); +end; + +function TglBitmapFormatDescriptor.GetHasAlpha: Boolean; +begin + result := (fPrecision.a > 0); +end; + +function TglBitmapFormatDescriptor.GetHasColor: Boolean; +begin + result := HasRed or HasGreen or HasBlue; +end; + +function TglBitmapFormatDescriptor.GetIsGrayscale: Boolean; +begin + result := (Mask.r = Mask.g) and (Mask.g = Mask.b) and (Mask.r > 0); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglBitmapFormatDescriptor.SetValues; +begin + fFormat := tfEmpty; + fWithAlpha := tfEmpty; + fWithoutAlpha := tfEmpty; + fOpenGLFormat := tfEmpty; + fRGBInverted := tfEmpty; + fUncompressed := tfEmpty; + + fBitsPerPixel := 0; + fIsCompressed := false; + + fglFormat := 0; + fglInternalFormat := 0; + fglDataFormat := 0; + + FillChar(fPrecision, 0, SizeOf(fPrecision)); + FillChar(fShift, 0, SizeOf(fShift)); +end; + +procedure TglBitmapFormatDescriptor.CalcValues; +var + i: Integer; +begin + fBytesPerPixel := fBitsPerPixel / 8; + fChannelCount := 0; + for i := 0 to 3 do begin + if (fPrecision.arr[i] > 0) then + inc(fChannelCount); + fRange.arr[i] := (1 shl fPrecision.arr[i]) - 1; + fMask.arr[i] := fRange.arr[i] shl fShift.arr[i]; + end; +end; + +constructor TglBitmapFormatDescriptor.Create; +begin + inherited Create; + SetValues; + CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class function TglBitmapFormatDescriptor.GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; var f: TglBitmapFormat; @@ -4354,7 +4285,7 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class function TFormatDescriptor.GetFromMask(const aMask: TglBitmapMask; const aBitCount: Integer): TFormatDescriptor; +class function TFormatDescriptor.GetFromMask(const aMask: TglBitmapRec4ul; const aBitCount: Integer): TFormatDescriptor; var ft: TglBitmapFormat; begin @@ -4364,7 +4295,34 @@ begin if (result.MaskMatch(aMask)) and (result.glFormat <> 0) and (result.glInternalFormat <> 0) and - ((aBitCount = 0) or (aBitCount = 8 * result.PixelSize)) + ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) + then + exit; + end; + + // find matching format without OpenGL Support + for ft := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin + result := Get(ft); + if result.MaskMatch(aMask) and ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) then + exit; + end; + + result := TFormatDescriptor.Get(tfEmpty); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class function TFormatDescriptor.GetFromPrecShift(const aPrec, aShift: TglBitmapRec4ub; const aBitCount: Integer): TFormatDescriptor; +var + ft: TglBitmapFormat; +begin + // find matching format with OpenGL support + for ft := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin + result := Get(ft); + if glBitmapRec4ubCompare(result.Shift, aShift) and + glBitmapRec4ubCompare(result.Precision, aPrec) and + (result.glFormat <> 0) and + (result.glInternalFormat <> 0) and + ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) then exit; end; @@ -4372,11 +4330,13 @@ begin // find matching format without OpenGL Support for ft := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin result := Get(ft); - if result.MaskMatch(aMask) and ((aBitCount = 0) or (aBitCount = 8 * result.PixelSize)) then + if glBitmapRec4ubCompare(result.Shift, aShift) and + glBitmapRec4ubCompare(result.Precision, aPrec) and + ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) then exit; end; - result := FormatDescriptors[tfEmpty]; + result := TFormatDescriptor.Get(tfEmpty); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4403,103 +4363,102 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TBitfieldFormat///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetRedMask(const aValue: QWord); -begin - Update(aValue, fRange.r, fShift.r); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetGreenMask(const aValue: QWord); -begin - Update(aValue, fRange.g, fShift.g); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetBlueMask(const aValue: QWord); -begin - Update(aValue, fRange.b, fShift.b); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: QWord); +procedure TbmpBitfieldFormat.SetCustomValues(const aBPP: Integer; aMask: TglBitmapRec4ul); +var + i: Integer; begin - Update(aValue, fRange.a, fShift.a); + for i := 0 to 3 do begin + fShift.arr[i] := 0; + while (aMask.arr[i] > 0) and (aMask.arr[i] and 1 > 0) do begin + aMask.arr[i] := aMask.arr[i] shr 1; + inc(fShift.arr[i]); + end; + fPrecision.arr[i] := CountSetBits(aMask.arr[i]); + end; + CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.Update(aMask: QWord; out aRange: Cardinal; out - aShift: Byte); +procedure TbmpBitfieldFormat.SetCustomValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); begin - aShift := 0; - aRange := 0; - if (aMask = 0) then - exit; - while (aMask > 0) and ((aMask and 1) = 0) do begin - inc(aShift); - aMask := aMask shr 1; - end; - aRange := 1; - while (aMask > 0) do begin - aRange := aRange shl 1; - aMask := aMask shr 1; - end; - dec(aRange); - - fPixelSize := Round(GetTopMostBit(RedMask or GreenMask or BlueMask or AlphaMask) / 8); + fBitsPerPixel := aBBP; + fPrecision := aPrec; + fShift := aShift; + CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpBitfieldFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); var data: QWord; - s: Integer; begin data := - ((aPixel.Data.r and fRange.r) shl fShift.r) or - ((aPixel.Data.g and fRange.g) shl fShift.g) or - ((aPixel.Data.b and fRange.b) shl fShift.b) or - ((aPixel.Data.a and fRange.a) shl fShift.a); - s := Round(fPixelSize); - case s of - 1: aData^ := data; - 2: PWord(aData)^ := data; - 4: PCardinal(aData)^ := data; - 8: PQWord(aData)^ := data; + ((aPixel.Data.r and Range.r) shl Shift.r) or + ((aPixel.Data.g and Range.g) shl Shift.g) or + ((aPixel.Data.b and Range.b) shl Shift.b) or + ((aPixel.Data.a and Range.a) shl Shift.a); + case BitsPerPixel of + 8: aData^ := data; + 16: PWord(aData)^ := data; + 32: PCardinal(aData)^ := data; + 64: PQWord(aData)^ := data; else - raise EglBitmap.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); + raise EglBitmap.CreateFmt('invalid pixel size: %d', [BitsPerPixel]); end; - inc(aData, s); + inc(aData, Round(BytesPerPixel)); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpBitfieldFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); var data: QWord; - s, i: Integer; -begin - s := Round(fPixelSize); - case s of - 1: data := aData^; - 2: data := PWord(aData)^; - 4: data := PCardinal(aData)^; - 8: data := PQWord(aData)^; + i: Integer; +begin + case BitsPerPixel of + 8: data := aData^; + 16: data := PWord(aData)^; + 32: data := PCardinal(aData)^; + 64: data := PQWord(aData)^; else - raise EglBitmap.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); + raise EglBitmap.CreateFmt('invalid pixel size: %d', [BitsPerPixel]); end; for i := 0 to 3 do - aPixel.Data.arr[i] := (data shr fShift.arr[i]) and fRange.arr[i]; - inc(aData, s); + aPixel.Data.arr[i] := (data shr fShift.arr[i]) and Range.arr[i]; + inc(aData, Round(BytesPerPixel)); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TColorTableFormat/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.SetValues; +begin + inherited SetValues; + fShift := glBitmapRec4ub(8, 8, 8, 0); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.SetCustomValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); +begin + fFormat := aFormat; + fBitsPerPixel := aBPP; + fPrecision := aPrec; + fShift := aShift; + CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.CalcValues; +begin + inherited CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.CreateColorTable; var i: Integer; begin SetLength(fColorTable, 256); - if (fRange.r = fRange.g) and (fRange.g = fRange.b) and (fRange.r = 0) then begin + if not HasColor then begin // alpha for i := 0 to High(fColorTable) do begin fColorTable[i].r := Round(((i shr Shift.a) and Range.a) / Range.a * 255); @@ -4521,9 +4480,9 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); begin - if (fPixelSize <> 1.0) then + if (BitsPerPixel <> 8) then raise EglBitmapUnsupportedFormat.Create('color table are only supported for 8bit formats'); - if (fRange.r = fRange.g) and (fRange.g = fRange.b) and (fRange.r = 0) then + if not HasColor then // alpha aData^ := aPixel.Data.a else @@ -4538,7 +4497,7 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); begin - if (fPixelSize <> 1.0) then + if (BitsPerPixel <> 8) then raise EglBitmapUnsupportedFormat.Create('color table are only supported for 8bit formats'); with fColorTable[aData^] do begin aPixel.Data.r := r; @@ -4797,7 +4756,7 @@ procedure TglBitmap.SetFormat(const aValue: TglBitmapFormat); begin if fFormat = aValue then exit; - if TFormatDescriptor.Get(Format).PixelSize <> TFormatDescriptor.Get(aValue).PixelSize then + if TFormatDescriptor.Get(Format).BitsPerPixel <> TFormatDescriptor.Get(aValue).BitsPerPixel then raise EglBitmapUnsupportedFormat.Create(Format); SetDataPointer(fData, aValue, Width, Height); //be careful, Data could be freed by this method end; @@ -4836,11 +4795,14 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap.SetAnisotropic(const aValue: Integer); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_EXT)} var MaxAnisotropic: Integer; +{$IFEND} begin fAnisotropic := aValue; if (ID > 0) then begin +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_EXT)} if GL_EXT_texture_filter_anisotropic then begin if fAnisotropic > 0 then begin Bind(false); @@ -4852,6 +4814,9 @@ begin end else begin fAnisotropic := 0; end; +{$ELSE} + fAnisotropic := 0; +{$IFEND} end; end; @@ -4865,17 +4830,20 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TglBitmap.SetupParameters(out aBuildWithGlu: Boolean); +procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF}); begin // Set Up Parameters SetWrap(fWrapS, fWrapT, fWrapR); SetFilter(fFilterMin, fFilterMag); SetAnisotropic(fAnisotropic); - SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]); +{$IFNDEF OPENGL_ES} + SetBorderColor(fBorderColor[0], fBorderColor[1], fBorderColor[2], fBorderColor[3]); if (GL_ARB_texture_swizzle or GL_EXT_texture_swizzle or GL_VERSION_3_3) then SetSwizzle(fSwizzle[0], fSwizzle[1], fSwizzle[2], fSwizzle[3]); +{$ENDIF} +{$IFNDEF OPENGL_ES} // Mip Maps Generation Mode aBuildWithGlu := false; if (MipMap = mmMipmap) then begin @@ -4885,6 +4853,10 @@ begin aBuildWithGlu := true; end else if (MipMap = mmMipmapGlu) then aBuildWithGlu := true; +{$ELSE} + if (MipMap = mmMipmap) then + glTexParameteri(Target, GL_GENERATE_MIPMAP, GL_TRUE); +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -4914,7 +4886,7 @@ begin fDimension.Y := aHeight; end; - s := TFormatDescriptor.Get(aFormat).PixelSize; + s := TFormatDescriptor.Get(aFormat).BytesPerPixel; fFormat := aFormat; fPixelSize := Ceil(s); fRowSize := Ceil(s * aWidth); @@ -4942,7 +4914,9 @@ begin fID := 0; fTarget := 0; +{$IFNDEF OPENGL_ES} fIsResident := false; +{$ENDIF} fMipMap := glBitmapDefaultMipmap; fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture; @@ -4950,7 +4924,9 @@ begin glBitmapGetDefaultFilter (fFilterMin, fFilterMag); glBitmapGetDefaultTextureWrap(fWrapS, fWrapT, fWrapR); +{$IFNDEF OPENGL_ES} glBitmapGetDefaultSwizzle (fSwizzle[0], fSwizzle[1], fSwizzle[2], fSwizzle[3]); +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -5008,6 +4984,7 @@ begin if not LoadDDS(aStream) then if not LoadTGA(aStream) then if not LoadBMP(aStream) then + if not LoadRAW(aStream) then raise EglBitmap.Create('LoadFromStream - Couldn''t load Stream. It''s possible to be an unknow Streamtype.'); end; @@ -5085,6 +5062,7 @@ begin ftDDS: SaveDDS(aStream); ftTGA: SaveTGA(aStream); ftBMP: SaveBMP(aStream); + ftRAW: SaveRAW(aStream); end; end; @@ -5120,7 +5098,7 @@ begin raise EglBitmapUnsupportedFormat.Create('compressed formats are not supported: ', DestFD.Format); // inkompatible Formats so CreateTemp - if (SourceFD.PixelSize <> DestFD.PixelSize) then + if (SourceFD.BitsPerPixel <> DestFD.BitsPerPixel) then aCreateTemp := true; // Values @@ -5535,12 +5513,12 @@ begin rid.Width := Width; rid.Height := Height; - rid.Depth := CountSetBits(FormatDesc.RedMask or FormatDesc.GreenMask or FormatDesc.BlueMask or FormatDesc.AlphaMask); + rid.Depth := FormatDesc.BitsPerPixel; rid.BitOrder := riboBitsInOrder; rid.ByteOrder := riboLSBFirst; rid.LineOrder := riloTopToBottom; rid.LineEnd := rileTight; - rid.BitsPerPixel := Round(8 * FormatDesc.PixelSize); + rid.BitsPerPixel := FormatDesc.BitsPerPixel; rid.RedPrec := CountSetBits(FormatDesc.Range.r); rid.GreenPrec := CountSetBits(FormatDesc.Range.g); rid.BluePrec := CountSetBits(FormatDesc.Range.b); @@ -5571,30 +5549,35 @@ var ImageData: PByte; ImageSize: Integer; CanCopy: Boolean; - Mask: TglBitmapMask; + Mask: TglBitmapRec4ul; procedure CopyConvert; var bfFormat: TbmpBitfieldFormat; pSourceLine, pDestLine: PByte; pSourceMD, pDestMD: Pointer; + Shift, Prec: TglBitmapRec4ub; x, y: Integer; pixel: TglBitmapPixelData; begin bfFormat := TbmpBitfieldFormat.Create; with aImage.DataDescription do begin - bfFormat.RedMask := ((1 shl RedPrec) - 1) shl RedShift; - bfFormat.GreenMask := ((1 shl GreenPrec) - 1) shl GreenShift; - bfFormat.BlueMask := ((1 shl BluePrec) - 1) shl BlueShift; - bfFormat.AlphaMask := ((1 shl AlphaPrec) - 1) shl AlphaShift; - bfFormat.PixelSize := BitsPerPixel / 8; + Prec.r := RedPrec; + Prec.g := GreenPrec; + Prec.b := BluePrec; + Prec.a := AlphaPrec; + Shift.r := RedShift; + Shift.g := GreenShift; + Shift.b := BlueShift; + Shift.a := AlphaShift; + bfFormat.SetCustomValues(BitsPerPixel, Prec, Shift); end; pSourceMD := bfFormat.CreateMappingData; pDestMD := FormatDesc.CreateMappingData; try for y := 0 to aImage.Height-1 do begin pSourceLine := aImage.PixelData + y {%H-}* aImage.DataDescription.BytesPerLine; - pDestLine := ImageData + y * Round(FormatDesc.PixelSize * aImage.Width); + pDestLine := ImageData + y * Round(FormatDesc.BytesPerPixel * aImage.Width); for x := 0 to aImage.Width-1 do begin bfFormat.Unmap(pSourceLine, pixel, pSourceMD); FormatDesc.Map(pixel, pDestLine, pDestMD); @@ -5624,7 +5607,7 @@ begin exit; CanCopy := - (Round(FormatDesc.PixelSize * 8) = aImage.DataDescription.Depth) and + (FormatDesc.BitsPerPixel = aImage.DataDescription.Depth) and (aImage.DataDescription.BitsPerPixel = aImage.DataDescription.Depth); ImageSize := FormatDesc.GetSize(aImage.Width, aImage.Height); @@ -6015,11 +5998,7 @@ var function DataIsIdentical: Boolean; begin - result := - (SourceFD.RedMask = DestFD.RedMask) and - (SourceFD.GreenMask = DestFD.GreenMask) and - (SourceFD.BlueMask = DestFD.BlueMask) and - (SourceFD.AlphaMask = DestFD.AlphaMask); + result := SourceFD.MaskMatch(DestFD.Mask); end; function CanCopyDirect: Boolean; @@ -6086,6 +6065,7 @@ begin (Byte(aUseRGB) and 1) )); end; +{$IFNDEF OPENGL_ES} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap.SetBorderColor(const aRed, aGreen, aBlue, aAlpha: Single); begin @@ -6098,6 +6078,7 @@ begin glTexParameterfv(Target, GL_TEXTURE_BORDER_COLOR, @fBorderColor[0]); end; end; +{$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap.FreeData; @@ -6179,7 +6160,7 @@ begin Bind(false); glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, fFilterMag); - if (MipMap = mmNone) or (Target = GL_TEXTURE_RECTANGLE) then begin + if (MipMap = mmNone) {$IFNDEF OPENGL_ES}or (Target = GL_TEXTURE_RECTANGLE){$ENDIF} then begin case fFilterMin of GL_NEAREST, GL_LINEAR: glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, fFilterMin); @@ -6199,32 +6180,44 @@ procedure TglBitmap.SetWrap(const S: GLenum; const T: GLenum; const R: GLenum); procedure CheckAndSetWrap(const aValue: Cardinal; var aTarget: Cardinal); begin case aValue of +{$IFNDEF OPENGL_ES} GL_CLAMP: aTarget := GL_CLAMP; +{$ENDIF} GL_REPEAT: aTarget := GL_REPEAT; GL_CLAMP_TO_EDGE: begin - if GL_VERSION_1_2 or GL_EXT_texture_edge_clamp then - aTarget := GL_CLAMP_TO_EDGE +{$IFNDEF OPENGL_ES} + if not GL_VERSION_1_2 and not GL_EXT_texture_edge_clamp then + aTarget := GL_CLAMP else - aTarget := GL_CLAMP; +{$ENDIF} + aTarget := GL_CLAMP_TO_EDGE; end; +{$IFNDEF OPENGL_ES} GL_CLAMP_TO_BORDER: begin if GL_VERSION_1_3 or GL_ARB_texture_border_clamp then aTarget := GL_CLAMP_TO_BORDER else aTarget := GL_CLAMP; end; +{$ENDIF} +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} GL_MIRRORED_REPEAT: begin + {$IFNDEF OPENGL_ES} if GL_VERSION_1_4 or GL_ARB_texture_mirrored_repeat or GL_IBM_texture_mirrored_repeat then + {$ELSE} + if GL_VERSION_2_0 then + {$ENDIF} aTarget := GL_MIRRORED_REPEAT else raise EglBitmap.Create('SetWrap - Unsupported Texturewrap GL_MIRRORED_REPEAT (S).'); end; +{$IFEND} else raise EglBitmap.Create('SetWrap - Unknow Texturewrap'); end; @@ -6239,10 +6232,14 @@ begin Bind(false); glTexParameteri(Target, GL_TEXTURE_WRAP_S, fWrapS); glTexParameteri(Target, GL_TEXTURE_WRAP_T, fWrapT); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} + {$IFDEF OPENGL_ES} if GL_VERSION_3_0 then{$ENDIF} glTexParameteri(Target, GL_TEXTURE_WRAP_R, fWrapR); +{$IFEND} end; end; +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap.SetSwizzle(const r, g, b, a: GLenum); @@ -6256,8 +6253,13 @@ procedure TglBitmap.SetSwizzle(const r, g, b, a: GLenum); end; begin +{$IFNDEF OPENGL_ES} if not (GL_ARB_texture_swizzle or GL_EXT_texture_swizzle or GL_VERSION_3_3) then raise EglBitmapNotSupported.Create('texture swizzle is not supported'); +{$ELSE} + if not GL_VERSION_3_0 then + raise EglBitmapNotSupported.Create('texture swizzle is not supported'); +{$ENDIF} CheckAndSetValue(r, 0); CheckAndSetValue(g, 1); CheckAndSetValue(b, 2); @@ -6265,9 +6267,17 @@ begin if (ID > 0) then begin Bind(false); +{$IFNDEF OPENGL_ES} glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_RGBA, PGLint(@fSwizzle[0])); +{$ELSE} + glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_R, PGLint(@fSwizzle[0])); + glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_G, PGLint(@fSwizzle[1])); + glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_B, PGLint(@fSwizzle[2])); + glTexParameteriv(Target, GL_TEXTURE_SWIZZLE_A, PGLint(@fSwizzle[3])); +{$ENDIF} end; end; +{$IFEND} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap.Bind(const aEnableTextureUnit: Boolean); @@ -7332,6 +7342,65 @@ end; {$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//RAW///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +type + RawHeader = packed record + Magic: String[5]; + Version: Byte; + Width: Integer; + Height: Integer; + DataSize: Integer; + BitsPerPixel: Integer; + Precision: TglBitmapRec4ub; + Shift: TglBitmapRec4ub; + end; + +function TglBitmap.LoadRAW(const aStream: TStream): Boolean; +var + header: RawHeader; + StartPos: Int64; + fd: TFormatDescriptor; + buf: PByte; +begin + result := false; + StartPos := aStream.Position; + aStream.Read(header{%H-}, SizeOf(header)); + if (header.Magic <> 'glBMP') then begin + aStream.Position := StartPos; + exit; + end; + + fd := TFormatDescriptor.GetFromPrecShift(header.Precision, header.Shift, header.BitsPerPixel); + if (fd.Format = tfEmpty) then + raise EglBitmapUnsupportedFormat.Create('no supported format found'); + + buf := GetMemory(header.DataSize); + aStream.Read(buf^, header.DataSize); + SetDataPointer(buf, fd.Format, header.Width, header.Height); + + result := true; +end; + +procedure TglBitmap.SaveRAW(const aStream: TStream); +var + header: RawHeader; + fd: TFormatDescriptor; +begin + fd := TFormatDescriptor.Get(Format); + header.Magic := 'glBMP'; + header.Version := 1; + header.Width := Width; + header.Height := Height; + header.DataSize := fd.GetSize(fDimension); + header.BitsPerPixel := fd.BitsPerPixel; + header.Precision := fd.Precision; + header.Shift := fd.Shift; + aStream.Write(header, SizeOf(header)); + aStream.Write(Data^, header.DataSize); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //BMP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const @@ -7369,7 +7438,7 @@ type function TglBitmap.LoadBMP(const aStream: TStream): Boolean; ////////////////////////////////////////////////////////////////////////////////////////////////// - function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapMask): TglBitmapFormat; + function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapRec4ul): TglBitmapFormat; begin result := tfEmpty; aStream.Read(aInfo{%H-}, SizeOf(aInfo)); @@ -7421,13 +7490,13 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean; end; result := TbmpColorTableFormat.Create; - result.PixelSize := aInfo.biBitCount / 8; - result.ColorTable := ColorTable; - result.Range := glBitmapColorRec($FF, $FF, $FF, $00); + result.BitsPerPixel := aInfo.biBitCount; + result.ColorTable := ColorTable; + result.CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////// - function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapMask; const aInfo: TBMPInfo): TbmpBitfieldFormat; + function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapRec4ul; const aInfo: TBMPInfo): TbmpBitfieldFormat; var FormatDesc: TFormatDescriptor; begin @@ -7443,11 +7512,7 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean; aFormat := TFormatDescriptor.Get(aFormat).WithAlpha; result := TbmpBitfieldFormat.Create; - result.PixelSize := aInfo.biBitCount / 8; - result.RedMask := aMask.r; - result.GreenMask := aMask.g; - result.BlueMask := aMask.b; - result.AlphaMask := aMask.a; + result.SetCustomValues(aInfo.biBitCount, aMask); end; end; @@ -7461,7 +7526,7 @@ var BmpFormat: TglBitmapFormat; //records - Mask: TglBitmapMask; + Mask: TglBitmapRec4ul; Header: TBMPHeader; Info: TBMPInfo; @@ -7507,7 +7572,7 @@ begin if (BmpFormat <> tfEmpty) then begin FormatDesc := TFormatDescriptor.Get(BmpFormat); rbLineSize := Round(Info.biWidth * Info.biBitCount / 8); //ReadBuffer LineSize - wbLineSize := Trunc(Info.biWidth * FormatDesc.PixelSize); + wbLineSize := Trunc(Info.biWidth * FormatDesc.BytesPerPixel); Padding := (((Info.biWidth * Info.biBitCount + 31) and - 32) shr 3) - rbLineSize; //get Memory @@ -7616,10 +7681,7 @@ begin Header.bfOffBits := Header.bfOffBits + 256 * SizeOf(Cardinal); //256 ColorTable entries Converter := TbmpColorTableFormat.Create; with (Converter as TbmpColorTableFormat) do begin - PixelSize := 1; - Format := fFormat; - Range := FormatDesc.Range; - Shift := FormatDesc.Shift; + SetCustomValues(fFormat, 1, FormatDesc.Precision, FormatDesc.Shift); CreateColorTable; end; end; @@ -7656,10 +7718,10 @@ begin Header.bfSize := Header.bfSize + 4 * SizeOf(Cardinal); Header.bfOffBits := Header.bfOffBits + 4 * SizeOf(Cardinal); - RedMask := FormatDesc.RedMask; - GreenMask := FormatDesc.GreenMask; - BlueMask := FormatDesc.BlueMask; - AlphaMask := FormatDesc.AlphaMask; + RedMask := FormatDesc.Mask.r; + GreenMask := FormatDesc.Mask.g; + BlueMask := FormatDesc.Mask.b; + AlphaMask := FormatDesc.Mask.a; end; // headers @@ -7681,7 +7743,7 @@ begin end; // image data - rbLineSize := Round(Info.biWidth * FormatDesc.PixelSize); + rbLineSize := Round(Info.biWidth * FormatDesc.BytesPerPixel); wbLineSize := Round(Info.biWidth * Info.biBitCount / 8); Padding := GetLineWidth - wbLineSize; PaddingBuff := 0; @@ -8054,7 +8116,7 @@ begin FormatDesc := TFormatDescriptor.Get(Format); FillChar(Header{%H-}, SizeOf(Header), 0); Header.ImageDesc := CountSetBits(FormatDesc.Range.a) and $F; - Header.Bpp := Trunc(8 * FormatDesc.PixelSize); + Header.Bpp := FormatDesc.BitsPerPixel; Header.Width := Width; Header.Height := Height; Header.ImageDesc := Header.ImageDesc or $20; //flip y @@ -8141,8 +8203,8 @@ var var fd: TFormatDescriptor; i: Integer; - Mask: TglBitmapMask; - Range: TglBitmapColorRec; + Mask: TglBitmapRec4ul; + Range: TglBitmapRec4ui; match: Boolean; begin result := tfEmpty; @@ -8200,11 +8262,7 @@ var end; Converter := TbmpBitfieldFormat.Create; - Converter.RedMask := dwRBitMask; - Converter.GreenMask := dwGBitMask; - Converter.BlueMask := dwBBitMask; - Converter.AlphaMask := dwABitMask; - Converter.PixelSize := dwRGBBitCount / 8; + Converter.SetCustomValues(dwRGBBitCount, glBitmapRec4ul(dwRBitMask, dwGBitMask, dwBBitMask, dwABitMask)); end; end; end; @@ -8249,7 +8307,7 @@ begin raise EglBitmap.Create('LoadDDS - unsupported Pixelformat found.'); FormatDesc := TFormatDescriptor.Get(ddsFormat); - LineSize := Trunc(Header.dwWidth * FormatDesc.PixelSize); + LineSize := Trunc(Header.dwWidth * FormatDesc.BytesPerPixel); GetMem(NewImage, Header.dwHeight * LineSize); try TmpData := NewImage; @@ -8343,20 +8401,20 @@ begin end; end else if not FormatDesc.HasColor and FormatDesc.HasAlpha then begin Header.PixelFormat.dwFlags := Header.PixelFormat.dwFlags or DDPF_ALPHA; - Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8); - Header.PixelFormat.dwABitMask := FormatDesc.AlphaMask; - end else if (FormatDesc.RedMask = FormatDesc.GreenMask) and (FormatDesc.GreenMask = FormatDesc.BlueMask) then begin + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; + end else if FormatDesc.IsGrayscale then begin Header.PixelFormat.dwFlags := Header.PixelFormat.dwFlags or DDPF_LUMINANCE; - Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8); - Header.PixelFormat.dwRBitMask := FormatDesc.RedMask; - Header.PixelFormat.dwABitMask := FormatDesc.AlphaMask; + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwRBitMask := FormatDesc.Mask.r; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; end else begin Header.PixelFormat.dwFlags := Header.PixelFormat.dwFlags or DDPF_RGB; - Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8); - Header.PixelFormat.dwRBitMask := FormatDesc.RedMask; - Header.PixelFormat.dwGBitMask := FormatDesc.GreenMask; - Header.PixelFormat.dwBBitMask := FormatDesc.BlueMask; - Header.PixelFormat.dwABitMask := FormatDesc.AlphaMask; + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwRBitMask := FormatDesc.Mask.r; + Header.PixelFormat.dwGBitMask := FormatDesc.Mask.g; + Header.PixelFormat.dwBBitMask := FormatDesc.Mask.b; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; end; if (FormatDesc.HasAlpha) then @@ -8367,6 +8425,7 @@ begin aStream.Write(Data^, FormatDesc.GetSize(Dimension)); end; +{$IFNDEF OPENGL_ES} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmap1D///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -8427,6 +8486,9 @@ var begin // Upload data FormatDesc := TFormatDescriptor.Get(Format); + if (FormatDesc.glInternalFormat = 0) or (FormatDesc.glDataFormat = 0) then + raise EglBitmap.Create('format is not supported by video adapter, please convert before uploading data'); + if FormatDesc.IsCompressed then begin if not Assigned(glCompressedTexImage1D) then raise EglBitmap.Create('compressed formats not supported by video adapter'); @@ -8474,6 +8536,7 @@ begin inherited; Target := GL_TEXTURE_1D; end; +{$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmap2D///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -8498,7 +8561,7 @@ begin // Assigning Data if Assigned(Data) then begin SetLength(fLines, GetHeight); - LineWidth := Trunc(GetWidth * TFormatDescriptor.Get(Format).PixelSize); + LineWidth := Trunc(GetWidth * TFormatDescriptor.Get(Format).BytesPerPixel); for Idx := 0 to GetHeight-1 do begin fLines[Idx] := Data; @@ -8512,20 +8575,25 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TglBitmap2D.UploadData(const aTarget: GLenum; const aBuildWithGlu: Boolean); +procedure TglBitmap2D.UploadData(const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF}); var FormatDesc: TFormatDescriptor; begin + FormatDesc := TFormatDescriptor.Get(Format); + if (FormatDesc.glInternalFormat = 0) or (FormatDesc.glDataFormat = 0) then + raise EglBitmap.Create('format is not supported by video adapter, please convert before uploading data'); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - FormatDesc := TFormatDescriptor.Get(Format); if FormatDesc.IsCompressed then begin if not Assigned(glCompressedTexImage2D) then raise EglBitmap.Create('compressed formats not supported by video adapter'); glCompressedTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0, FormatDesc.GetSize(fDimension), Data) +{$IFNDEF OPENGL_ES} end else if aBuildWithGlu then begin - gluBuild2DMipmaps(aTarget, FormatDesc.Components, Width, Height, + gluBuild2DMipmaps(aTarget, FormatDesc.ChannelCount, Width, Height, FormatDesc.glFormat, FormatDesc.glDataFormat, Data) +{$ENDIF} end else begin glTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0, FormatDesc.glFormat, FormatDesc.glDataFormat, Data); @@ -8570,6 +8638,7 @@ begin end; end; +{$IFNDEF OPENGL_ES} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap2D.GetDataFromTexture; var @@ -8586,7 +8655,6 @@ begin glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_HEIGHT, @TempHeight); glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, @TempIntFormat); - IntFormat := tfEmpty; FormatDesc := (TglBitmapFormatDescriptor.GetByFormat(TempIntFormat) as TFormatDescriptor); IntFormat := FormatDesc.Format; @@ -8607,11 +8675,15 @@ begin raise; end; end; +{$ENDIF} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmap2D.GenTexture(const aTestTextureSize: Boolean); var - BuildWithGlu, PotTex, TexRec: Boolean; + {$IFNDEF OPENGL_ES} + BuildWithGlu, TexRec: Boolean; + {$ENDIF} + PotTex: Boolean; TexSize: Integer; begin if Assigned(Data) then begin @@ -8623,15 +8695,25 @@ begin raise EglBitmapSizeToLarge.Create('TglBitmap2D.GenTexture - The size for the texture is to large. It''s may be not conform with the Hardware.'); PotTex := IsPowerOfTwo(Height) and IsPowerOfTwo(Width); +{$IF NOT DEFINED(OPENGL_ES)} TexRec := (GL_ARB_texture_rectangle or GL_EXT_texture_rectangle or GL_NV_texture_rectangle) and (Target = GL_TEXTURE_RECTANGLE); if not (PotTex or GL_ARB_texture_non_power_of_two or GL_VERSION_2_0 or TexRec) then raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.'); +{$ELSEIF DEFINED(OPENGL_ES_EXT)} + if not PotTex and not GL_OES_texture_npot then + raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.'); +{$ELSE} + if not PotTex then + raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.'); +{$IFEND} end; CreateId; - SetupParameters(BuildWithGlu); - UploadData(Target, BuildWithGlu); + SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF}); + UploadData(Target{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF}); +{$IFNDEF OPENGL_ES} glAreTexturesResident(1, @fID, @fIsResident); +{$ENDIF} end; end; @@ -8919,6 +9001,7 @@ begin end; end; +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmapCubeMap//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -8932,40 +9015,58 @@ procedure TglBitmapCubeMap.AfterConstruction; begin inherited; +{$IFNDEF OPENGL_ES} if not (GL_VERSION_1_3 or GL_ARB_texture_cube_map or GL_EXT_texture_cube_map) then raise EglBitmap.Create('TglBitmapCubeMap.AfterConstruction - CubeMaps are unsupported.'); +{$ELSE} + if not (GL_VERSION_2_0) then + raise EglBitmap.Create('TglBitmapCubeMap.AfterConstruction - CubeMaps are unsupported.'); +{$ENDIF} SetWrap; Target := GL_TEXTURE_CUBE_MAP; +{$IFNDEF OPENGL_ES} fGenMode := GL_REFLECTION_MAP; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TglBitmapCubeMap.GenerateCubeMap(const aCubeTarget: Cardinal; const aTestTextureSize: Boolean); var + {$IFNDEF OPENGL_ES} BuildWithGlu: Boolean; + {$ENDIF} TexSize: Integer; begin if (aTestTextureSize) then begin glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, @TexSize); if (Height > TexSize) or (Width > TexSize) then - raise EglBitmapSizeToLarge.Create('TglBitmapCubeMap.GenTexture - The size for the Cubemap is to large. It''s may be not conform with the Hardware.'); + raise EglBitmapSizeToLarge.Create('TglBitmapCubeMap.GenerateCubeMap - The size for the Cubemap is to large. It''s may be not conform with the Hardware.'); +{$IF NOT DEFINED(OPENGL_ES)} if not ((IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) or GL_VERSION_2_0 or GL_ARB_texture_non_power_of_two) then - raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenTexture - Cubemaps dosn''t support non power of two texture.'); + raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.'); +{$ELSEIF DEFINED(OPENGL_ES_EXT)} + if not (IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) and not GL_OES_texture_npot then + raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.'); +{$ELSE} + if not (IsPowerOfTwo(Height) and IsPowerOfTwo(Width)) then + raise EglBitmapNonPowerOfTwo.Create('TglBitmapCubeMap.GenerateCubeMap - Cubemaps dosn''t support non power of two texture.'); +{$IFEND} end; if (ID = 0) then CreateID; - SetupParameters(BuildWithGlu); - UploadData(aCubeTarget, BuildWithGlu); + SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF}); + UploadData(aCubeTarget{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF}); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TglBitmapCubeMap.Bind(const aEnableTexCoordsGen: Boolean; const aEnableTextureUnit: Boolean); +procedure TglBitmapCubeMap.Bind({$IFNDEF OPENGL_ES}const aEnableTexCoordsGen: Boolean;{$ENDIF} const aEnableTextureUnit: Boolean); begin inherited Bind (aEnableTextureUnit); +{$IFNDEF OPENGL_ES} if aEnableTexCoordsGen then begin glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, fGenMode); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, fGenMode); @@ -8974,19 +9075,24 @@ begin glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); end; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TglBitmapCubeMap.Unbind(const aDisableTexCoordsGen: Boolean; const aDisableTextureUnit: Boolean); +procedure TglBitmapCubeMap.Unbind({$IFNDEF OPENGL_ES}const aDisableTexCoordsGen: Boolean;{$ENDIF} const aDisableTextureUnit: Boolean); begin inherited Unbind(aDisableTextureUnit); +{$IFNDEF OPENGL_ES} if aDisableTexCoordsGen then begin glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glDisable(GL_TEXTURE_GEN_R); end; +{$ENDIF} end; +{$IFEND} +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_2_0)} ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmapNormalMap////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -9000,7 +9106,7 @@ type Func: TglBitmapNormalMapGetVectorFunc; end; - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure glBitmapNormalMapPosX(out aVec: TVec; const aPosition: TglBitmapPixelPosition; const aHalfSize: Integer); begin aVec[0] := aHalfSize; @@ -9083,7 +9189,9 @@ end; procedure TglBitmapNormalMap.AfterConstruction; begin inherited; +{$IFNDEF OPENGL_ES} fGenMode := GL_NORMAL_MAP; +{$ENDIF} end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -9129,14 +9237,16 @@ begin LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec); GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, aTestTextureSize); end; - +{$IFEND} initialization glBitmapSetDefaultFormat (tfEmpty); glBitmapSetDefaultMipmap (mmMipmap); glBitmapSetDefaultFilter (GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); glBitmapSetDefaultWrap (GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); +{$IF NOT DEFINED(OPENGL_ES) OR DEFINED(OPENGL_ES_3_0)} glBitmapSetDefaultSwizzle(GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA); +{$IFEND} glBitmapSetDefaultFreeDataAfterGenTexture(true); glBitmapSetDefaultDeleteTextureOnFree (true); @@ -9160,6 +9270,6 @@ finalization glbFreeLibrary(GLU_LibHandle); FreeAndNil(InitOpenGLCS); {$ENDIF} -{$ENDIF} +{$ENDIF} end.