| @@ -924,6 +924,7 @@ type | |||
| fTarget: GLuint; | |||
| fAnisotropic: Integer; | |||
| fDeleteTextureOnFree: Boolean; | |||
| fFreeDataOnDestroy: Boolean; | |||
| fFreeDataAfterGenTexture: Boolean; | |||
| fData: PByte; | |||
| fIsResident: Boolean; | |||
| @@ -966,6 +967,7 @@ type | |||
| 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); | |||
| @@ -1004,6 +1006,7 @@ type | |||
| 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; | |||
| @@ -1104,7 +1107,7 @@ type | |||
| 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; | |||
| @@ -4175,6 +4178,14 @@ begin | |||
| fCustomNameW := aValue; | |||
| end; | |||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TglBitmap.SetFreeDataOnDestroy(const aValue: Boolean); | |||
| begin | |||
| if fFreeDataOnDestroy = aValue then | |||
| exit; | |||
| fFreeDataOnDestroy := aValue; | |||
| end; | |||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| procedure TglBitmap.SetDeleteTextureOnFree(const aValue: Boolean); | |||
| begin | |||
| @@ -4335,7 +4346,6 @@ begin | |||
| fTarget := 0; | |||
| fIsResident := false; | |||
| fFormat := glBitmapGetDefaultFormat; | |||
| fMipMap := glBitmapDefaultMipmap; | |||
| fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture; | |||
| fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree; | |||
| @@ -4350,8 +4360,10 @@ procedure TglBitmap.BeforeDestruction; | |||
| 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; | |||
| @@ -4418,7 +4430,7 @@ begin | |||
| FreeMem(tmpData); | |||
| raise; | |||
| end; | |||
| AddFunc(Self, aFunc, false, Format, aArgs); | |||
| AddFunc(Self, aFunc, false, aFormat, aArgs); | |||
| end; | |||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| @@ -5624,6 +5636,8 @@ begin | |||
| glbReadOpenGLExtensions; | |||
| {$ENDIF} | |||
| inherited Create; | |||
| fFormat := glBitmapGetDefaultFormat; | |||
| fFreeDataOnDestroy := true; | |||
| end; | |||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||
| @@ -5641,27 +5655,30 @@ begin | |||
| 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); | |||