|
|
@@ -2,7 +2,7 @@ |
|
|
|
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 |
|
|
@@ -11,9 +11,11 @@ not use this file except in compliance with the License. You may |
|
|
|
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 |
|
|
@@ -818,6 +820,23 @@ type |
|
|
|
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 |
|
|
@@ -832,6 +851,8 @@ type |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
TglBitmap = class |
|
|
|
private |
|
|
|
function GetFormatDesc: TglBitmapFormatDescriptor; |
|
|
|
protected |
|
|
|
fID: GLuint; |
|
|
|
fTarget: GLuint; |
|
|
@@ -909,6 +930,8 @@ type |
|
|
|
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; |
|
|
@@ -1155,7 +1178,7 @@ type |
|
|
|
1: (arr: array[0..3] of Byte); |
|
|
|
end; |
|
|
|
|
|
|
|
TFormatDescriptor = class(TObject) |
|
|
|
TFormatDescriptor = class(TglBitmapFormatDescriptor) |
|
|
|
private |
|
|
|
function GetRedMask: QWord; |
|
|
|
function GetGreenMask: QWord; |
|
|
@@ -1173,9 +1196,16 @@ type |
|
|
|
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 |
|
|
@@ -1185,11 +1215,6 @@ type |
|
|
|
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; |
|
|
@@ -1209,7 +1234,6 @@ type |
|
|
|
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; |
|
|
@@ -2243,6 +2267,36 @@ begin |
|
|
|
result := fRange.a shl fShift.a; |
|
|
|
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 |
|
|
@@ -2294,12 +2348,6 @@ begin |
|
|
|
result := (fFormat = tfEmpty); |
|
|
|
end; |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TFormatDescriptor.HasAlpha: Boolean; |
|
|
|
begin |
|
|
|
result := (fRange.a > 0); |
|
|
|
end; |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; |
|
|
|
begin |
|
|
@@ -4005,6 +4053,12 @@ end; |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
//TglBitmap - PROTECTED/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TglBitmap.GetFormatDesc: TglBitmapFormatDescriptor; |
|
|
|
begin |
|
|
|
result := TFormatDescriptor.Get(Format); |
|
|
|
end; |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
|
function TglBitmap.GetWidth: Integer; |
|
|
|
begin |
|
|
@@ -5009,7 +5063,7 @@ function TglBitmap.AddAlphaFromFile(const aFileName: String; const aFunc: TglBit |
|
|
|
var |
|
|
|
FS: TFileStream; |
|
|
|
begin |
|
|
|
FS := TFileStream.Create(FileName, fmOpenRead); |
|
|
|
FS := TFileStream.Create(aFileName, fmOpenRead); |
|
|
|
try |
|
|
|
result := AddAlphaFromStream(FS, aFunc, aArgs); |
|
|
|
finally |
|
|
@@ -5515,7 +5569,7 @@ end; |
|
|
|
constructor TglBitmap.Create(const aFileName: String); |
|
|
|
begin |
|
|
|
Create; |
|
|
|
LoadFromFile(FileName); |
|
|
|
LoadFromFile(aFileName); |
|
|
|
end; |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
|
@@ -7691,9 +7745,9 @@ var |
|
|
|
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; |
|
|
@@ -7702,7 +7756,7 @@ begin |
|
|
|
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 |
|
|
|