Преглед изворни кода

* moved parts from TFormatDescriptor to public abstract class to get information outside of glBitmap

master
Bergmann89 пре 12 година
родитељ
комит
e406e4032c
1 измењених фајлова са 77 додато и 23 уклоњено
  1. +77
    -23
      glBitmap.pas

+ 77
- 23
glBitmap.pas Прегледај датотеку

@@ -2,7 +2,7 @@
glBitmap by Steffen Xonna aka Lossy eX (2003-2008) glBitmap by Steffen Xonna aka Lossy eX (2003-2008)
http://www.opengl24.de/index.php?cat=header&file=glbitmap 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 The contents of this file are used with permission, subject to
@@ -11,9 +11,11 @@ not use this file except in compliance with the License. You may
obtain a copy of the License at obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html http://www.mozilla.org/MPL/MPL-1.1.html
------------------------------------------------------------ ------------------------------------------------------------
Version 2.0.3
Version 3.0.0 unstable
------------------------------------------------------------ ------------------------------------------------------------
History History
20-11-2013
- refactoring of the complete library
21-03-2010 21-03-2010
- The define GLB_DELPHI dosn't check versions anymore. If you say you are using delphi - 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 then it's your problem if that isn't true. This prevents the unit for incompatibility
@@ -818,6 +820,23 @@ type
Y : Word; Y : Word;
end; 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; TglBitmap = class;
TglBitmapFunctionRec = record TglBitmapFunctionRec = record
@@ -832,6 +851,8 @@ type


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmap = class TglBitmap = class
private
function GetFormatDesc: TglBitmapFormatDescriptor;
protected protected
fID: GLuint; fID: GLuint;
fTarget: GLuint; fTarget: GLuint;
@@ -909,6 +930,8 @@ type
property MipMap: TglBitmapMipMap read fMipMap write SetMipMap; property MipMap: TglBitmapMipMap read fMipMap write SetMipMap;
property Anisotropic: Integer read fAnisotropic write SetAnisotropic; property Anisotropic: Integer read fAnisotropic write SetAnisotropic;


property FormatDesc: TglBitmapFormatDescriptor read GetFormatDesc;

property Filename: String read fFilename; property Filename: String read fFilename;
property CustomName: String read fCustomName write SetCustomName; property CustomName: String read fCustomName write SetCustomName;
property CustomNameW: WideString read fCustomNameW write SetCustomNameW; property CustomNameW: WideString read fCustomNameW write SetCustomNameW;
@@ -1155,7 +1178,7 @@ type
1: (arr: array[0..3] of Byte); 1: (arr: array[0..3] of Byte);
end; end;


TFormatDescriptor = class(TObject)
TFormatDescriptor = class(TglBitmapFormatDescriptor)
private private
function GetRedMask: QWord; function GetRedMask: QWord;
function GetGreenMask: QWord; function GetGreenMask: QWord;
@@ -1173,9 +1196,16 @@ type
fRange: TglBitmapColorRec; fRange: TglBitmapColorRec;
fShift: TShiftRec; 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; function GetComponents: Integer; virtual;
public public
@@ -1185,11 +1215,6 @@ type
property RGBInverted: TglBitmapFormat read fRGBInverted; property RGBInverted: TglBitmapFormat read fRGBInverted;
property Components: Integer read GetComponents; property Components: Integer read GetComponents;
property PixelSize: Single read fPixelSize; 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 Range: TglBitmapColorRec read fRange;
property Shift: TShiftRec read fShift; property Shift: TShiftRec read fShift;
@@ -1209,7 +1234,6 @@ type
procedure FreeMappingData(var aMappingData: Pointer); virtual; procedure FreeMappingData(var aMappingData: Pointer); virtual;


function IsEmpty: Boolean; virtual; function IsEmpty: Boolean; virtual;
function HasAlpha: Boolean; virtual;
function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual; function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual;


procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual; procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual;
@@ -2243,6 +2267,36 @@ begin
result := fRange.a shl fShift.a; result := fRange.a shl fShift.a;
end; 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; function TFormatDescriptor.GetComponents: Integer;
var var
@@ -2294,12 +2348,6 @@ begin
result := (fFormat = tfEmpty); result := (fFormat = tfEmpty);
end; end;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TFormatDescriptor.HasAlpha: Boolean;
begin
result := (fRange.a > 0);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean;
begin begin
@@ -4005,6 +4053,12 @@ end;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglBitmap - PROTECTED/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmap - PROTECTED///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.GetFormatDesc: TglBitmapFormatDescriptor;
begin
result := TFormatDescriptor.Get(Format);
end;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.GetWidth: Integer; function TglBitmap.GetWidth: Integer;
begin begin
@@ -5009,7 +5063,7 @@ function TglBitmap.AddAlphaFromFile(const aFileName: String; const aFunc: TglBit
var var
FS: TFileStream; FS: TFileStream;
begin begin
FS := TFileStream.Create(FileName, fmOpenRead);
FS := TFileStream.Create(aFileName, fmOpenRead);
try try
result := AddAlphaFromStream(FS, aFunc, aArgs); result := AddAlphaFromStream(FS, aFunc, aArgs);
finally finally
@@ -5515,7 +5569,7 @@ end;
constructor TglBitmap.Create(const aFileName: String); constructor TglBitmap.Create(const aFileName: String);
begin begin
Create; Create;
LoadFromFile(FileName);
LoadFromFile(aFileName);
end; end;


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -7691,9 +7745,9 @@ var
Size, w, h: Integer; Size, w, h: Integer;
FormatDesc: TFormatDescriptor; FormatDesc: TFormatDescriptor;
begin begin
FormatDesc := TFormatDescriptor.Get(Format);
FormatDesc := TFormatDescriptor.Get(aFormat);
if FormatDesc.IsCompressed then if FormatDesc.IsCompressed then
raise EglBitmapUnsupportedFormat.Create(Format);
raise EglBitmapUnsupportedFormat.Create(aFormat);


w := aRight - aLeft; w := aRight - aLeft;
h := aBottom - aTop; h := aBottom - aTop;
@@ -7702,7 +7756,7 @@ begin
try try
glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(aLeft, aTop, w, h, FormatDesc.glFormat, FormatDesc.glDataFormat, Temp); 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; FlipVert;
except except
if Assigned(Temp) then if Assigned(Temp) then


Loading…
Откажи
Сачувај