glBitmap by Steffen Xonna aka Lossy eX (2003-2008)
http://www.opengl24.de/index.php?cat=header&file=glbitmap
-modified by Delphi OpenGL Community (http://delphigl.com/)
+modified by Delphi OpenGL Community (http://delphigl.com/) (2013)
------------------------------------------------------------
The contents of this file are used with permission, subject to
obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
------------------------------------------------------------
-Version 2.0.3
+Version 3.0.0 unstable
------------------------------------------------------------
History
+20-11-2013
+- refactoring of the complete library
21-03-2010
- The define GLB_DELPHI dosn't check versions anymore. If you say you are using delphi
then it's your problem if that isn't true. This prevents the unit for incompatibility
Y : Word;
end;
+ TglBitmapFormatDescriptor = class(TObject)
+ protected
+ function GetIsCompressed: Boolean; virtual; abstract;
+ function GetHasAlpha: Boolean; virtual; abstract;
+
+ function GetglDataFormat: GLenum; virtual; abstract;
+ function GetglFormat: GLenum; virtual; abstract;
+ function GetglInternalFormat: GLenum; virtual; abstract;
+ public
+ property IsCompressed: Boolean read GetIsCompressed;
+ property HasAlpha: Boolean read GetHasAlpha;
+
+ property glFormat: GLenum read GetglFormat;
+ property glInternalFormat: GLenum read GetglInternalFormat;
+ property glDataFormat: GLenum read GetglDataFormat;
+ end;
+
////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmap = class;
TglBitmapFunctionRec = record
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmap = class
+ private
+ function GetFormatDesc: TglBitmapFormatDescriptor;
protected
fID: GLuint;
fTarget: GLuint;
property MipMap: TglBitmapMipMap read fMipMap write SetMipMap;
property Anisotropic: Integer read fAnisotropic write SetAnisotropic;
+ property FormatDesc: TglBitmapFormatDescriptor read GetFormatDesc;
+
property Filename: String read fFilename;
property CustomName: String read fCustomName write SetCustomName;
property CustomNameW: WideString read fCustomNameW write SetCustomNameW;
1: (arr: array[0..3] of Byte);
end;
- TFormatDescriptor = class(TObject)
+ TFormatDescriptor = class(TglBitmapFormatDescriptor)
private
function GetRedMask: QWord;
function GetGreenMask: QWord;
fRange: TglBitmapColorRec;
fShift: TShiftRec;
- fglFormat: Cardinal;
- fglInternalFormat: Cardinal;
- fglDataFormat: Cardinal;
+ fglFormat: GLenum;
+ fglInternalFormat: GLenum;
+ fglDataFormat: GLenum;
+
+ function GetIsCompressed: Boolean; override;
+ function GetHasAlpha: Boolean; override;
+
+ function GetglFormat: GLenum; override;
+ function GetglInternalFormat: GLenum; override;
+ function GetglDataFormat: GLenum; override;
function GetComponents: Integer; virtual;
public
property RGBInverted: TglBitmapFormat read fRGBInverted;
property Components: Integer read GetComponents;
property PixelSize: Single read fPixelSize;
- property IsCompressed: Boolean read fIsCompressed;
-
- property glFormat: Cardinal read fglFormat;
- property glInternalFormat: Cardinal read fglInternalFormat;
- property glDataFormat: Cardinal read fglDataFormat;
property Range: TglBitmapColorRec read fRange;
property Shift: TShiftRec read fShift;
procedure FreeMappingData(var aMappingData: Pointer); virtual;
function IsEmpty: Boolean; virtual;
- function HasAlpha: Boolean; virtual;
function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual;
procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TFormatDescriptor.GetIsCompressed: Boolean;
+begin
+ result := fIsCompressed;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TFormatDescriptor.GetHasAlpha: Boolean;
+begin
+ result := (fRange.a > 0);
+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;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.HasAlpha: Boolean;
-begin
- result := (fRange.a > 0);
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean;
begin
result := false;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglBitmap - PROTECTED///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.GetFormatDesc: TglBitmapFormatDescriptor;
+begin
+ result := TFormatDescriptor.Get(Format);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.GetWidth: Integer;
begin
if (ffX in fDimension.Fields) then
var
FS: TFileStream;
begin
- FS := TFileStream.Create(FileName, fmOpenRead);
+ FS := TFileStream.Create(aFileName, fmOpenRead);
try
result := AddAlphaFromStream(FS, aFunc, aArgs);
finally
constructor TglBitmap.Create(const aFileName: String);
begin
Create;
- LoadFromFile(FileName);
+ LoadFromFile(aFileName);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Size, w, h: Integer;
FormatDesc: TFormatDescriptor;
begin
- FormatDesc := TFormatDescriptor.Get(Format);
+ FormatDesc := TFormatDescriptor.Get(aFormat);
if FormatDesc.IsCompressed then
- raise EglBitmapUnsupportedFormat.Create(Format);
+ raise EglBitmapUnsupportedFormat.Create(aFormat);
w := aRight - aLeft;
h := aBottom - aTop;
try
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(aLeft, aTop, w, h, FormatDesc.glFormat, FormatDesc.glDataFormat, Temp);
- SetDataPointer(Temp, Format, w, h); //be careful, Data could be freed by this method
+ SetDataPointer(Temp, aFormat, w, h); //be careful, Data could be freed by this method
FlipVert;
except
if Assigned(Temp) then