fTarget: GLuint;
fAnisotropic: Integer;
fDeleteTextureOnFree: Boolean;
+ fFreeDataOnDestroy: Boolean;
fFreeDataAfterGenTexture: Boolean;
fData: PByte;
fIsResident: Boolean;
procedure SetCustomData(const aValue: Pointer);
procedure SetCustomName(const aValue: String);
procedure SetCustomNameW(const aValue: WideString);
+ procedure SetFreeDataOnDestroy(const aValue: Boolean);
procedure SetDeleteTextureOnFree(const aValue: Boolean);
procedure SetFormat(const aValue: TglBitmapFormat);
procedure SetFreeDataAfterGenTexture(const aValue: Boolean);
property CustomData: Pointer read fCustomData write SetCustomData;
property DeleteTextureOnFree: Boolean read fDeleteTextureOnFree write SetDeleteTextureOnFree;
+ property FreeDataOnDestroy: Boolean read fFreeDataOnDestroy write SetFreeDataOnDestroy;
property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture;
property Dimension: TglBitmapPixelPosition read fDimension;
constructor Create; overload;
constructor Create(const aFileName: String); overload;
constructor Create(const aStream: TStream); overload;
- constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat); overload;
+ constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; aData: PByte = nil); overload;
constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;
constructor Create(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil); overload;
constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SetFreeDataOnDestroy(const aValue: Boolean);
+begin
+ if fFreeDataOnDestroy = aValue then
+ exit;
+ fFreeDataOnDestroy := aValue;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.SetDeleteTextureOnFree(const aValue: Boolean);
begin
if fDeleteTextureOnFree = aValue then
fTarget := 0;
fIsResident := false;
- fFormat := glBitmapGetDefaultFormat;
fMipMap := glBitmapDefaultMipmap;
fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture;
fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree;
var
NewData: PByte;
begin
- NewData := nil;
- SetDataPointer(NewData, tfEmpty); //be careful, Data could be freed by this method
+ if fFreeDataOnDestroy then begin
+ NewData := nil;
+ SetDataPointer(NewData, tfEmpty); //be careful, Data could be freed by this method
+ end;
if (fID > 0) and fDeleteTextureOnFree then
glDeleteTextures(1, @fID);
inherited BeforeDestruction;
FreeMem(tmpData);
raise;
end;
- AddFunc(Self, aFunc, false, Format, aArgs);
+ AddFunc(Self, aFunc, false, aFormat, aArgs);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
glbReadOpenGLExtensions;
{$ENDIF}
inherited Create;
+ fFormat := glBitmapGetDefaultFormat;
+ fFreeDataOnDestroy := true;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat);
+constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; aData: PByte);
var
- Image: PByte;
ImageSize: Integer;
begin
Create;
- ImageSize := TFormatDescriptor.Get(aFormat).GetSize(aSize);
- GetMem(Image, ImageSize);
- try
- FillChar(Image^, ImageSize, #$FF);
- SetDataPointer(Image, aFormat, aSize.X, aSize.Y); //be careful, Data could be freed by this method
- except
- if Assigned(Image) then
- FreeMem(Image);
- raise;
+ if not Assigned(aData) then begin
+ ImageSize := TFormatDescriptor.Get(aFormat).GetSize(aSize);
+ GetMem(aData, ImageSize);
+ try
+ FillChar(aData^, ImageSize, #$FF);
+ SetDataPointer(aData, aFormat, aSize.X, aSize.Y); //be careful, Data could be freed by this method
+ except
+ if Assigned(aData) then
+ FreeMem(aData);
+ raise;
+ end;
+ end else begin
+ SetDataPointer(aData, aFormat, aSize.X, aSize.Y); //be careful, Data could be freed by this method
+ fFreeDataOnDestroy := false;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat;
- const aFunc: TglBitmapFunction; const aArgs: Pointer);
+constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer);
begin
Create;
LoadFromFunc(aSize, aFunc, aFormat, aArgs);