| @@ -924,6 +924,7 @@ type | |||||
| fTarget: GLuint; | fTarget: GLuint; | ||||
| fAnisotropic: Integer; | fAnisotropic: Integer; | ||||
| fDeleteTextureOnFree: Boolean; | fDeleteTextureOnFree: Boolean; | ||||
| fFreeDataOnDestroy: Boolean; | |||||
| fFreeDataAfterGenTexture: Boolean; | fFreeDataAfterGenTexture: Boolean; | ||||
| fData: PByte; | fData: PByte; | ||||
| fIsResident: Boolean; | fIsResident: Boolean; | ||||
| @@ -966,6 +967,7 @@ type | |||||
| procedure SetCustomData(const aValue: Pointer); | procedure SetCustomData(const aValue: Pointer); | ||||
| procedure SetCustomName(const aValue: String); | procedure SetCustomName(const aValue: String); | ||||
| procedure SetCustomNameW(const aValue: WideString); | procedure SetCustomNameW(const aValue: WideString); | ||||
| procedure SetFreeDataOnDestroy(const aValue: Boolean); | |||||
| procedure SetDeleteTextureOnFree(const aValue: Boolean); | procedure SetDeleteTextureOnFree(const aValue: Boolean); | ||||
| procedure SetFormat(const aValue: TglBitmapFormat); | procedure SetFormat(const aValue: TglBitmapFormat); | ||||
| procedure SetFreeDataAfterGenTexture(const aValue: Boolean); | procedure SetFreeDataAfterGenTexture(const aValue: Boolean); | ||||
| @@ -1004,6 +1006,7 @@ type | |||||
| property CustomData: Pointer read fCustomData write SetCustomData; | property CustomData: Pointer read fCustomData write SetCustomData; | ||||
| property DeleteTextureOnFree: Boolean read fDeleteTextureOnFree write SetDeleteTextureOnFree; | property DeleteTextureOnFree: Boolean read fDeleteTextureOnFree write SetDeleteTextureOnFree; | ||||
| property FreeDataOnDestroy: Boolean read fFreeDataOnDestroy write SetFreeDataOnDestroy; | |||||
| property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture; | property FreeDataAfterGenTexture: Boolean read fFreeDataAfterGenTexture write SetFreeDataAfterGenTexture; | ||||
| property Dimension: TglBitmapPixelPosition read fDimension; | property Dimension: TglBitmapPixelPosition read fDimension; | ||||
| @@ -1104,7 +1107,7 @@ type | |||||
| constructor Create; overload; | constructor Create; overload; | ||||
| constructor Create(const aFileName: String); overload; | constructor Create(const aFileName: String); overload; | ||||
| constructor Create(const aStream: TStream); 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 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 aResource: String; const aResType: PChar = nil); overload; | ||||
| constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload; | constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload; | ||||
| @@ -4175,6 +4178,14 @@ begin | |||||
| fCustomNameW := aValue; | fCustomNameW := aValue; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| procedure TglBitmap.SetFreeDataOnDestroy(const aValue: Boolean); | |||||
| begin | |||||
| if fFreeDataOnDestroy = aValue then | |||||
| exit; | |||||
| fFreeDataOnDestroy := aValue; | |||||
| end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TglBitmap.SetDeleteTextureOnFree(const aValue: Boolean); | procedure TglBitmap.SetDeleteTextureOnFree(const aValue: Boolean); | ||||
| begin | begin | ||||
| @@ -4335,7 +4346,6 @@ begin | |||||
| fTarget := 0; | fTarget := 0; | ||||
| fIsResident := false; | fIsResident := false; | ||||
| fFormat := glBitmapGetDefaultFormat; | |||||
| fMipMap := glBitmapDefaultMipmap; | fMipMap := glBitmapDefaultMipmap; | ||||
| fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture; | fFreeDataAfterGenTexture := glBitmapGetDefaultFreeDataAfterGenTexture; | ||||
| fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree; | fDeleteTextureOnFree := glBitmapGetDefaultDeleteTextureOnFree; | ||||
| @@ -4350,8 +4360,10 @@ procedure TglBitmap.BeforeDestruction; | |||||
| var | var | ||||
| NewData: PByte; | NewData: PByte; | ||||
| begin | 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 | if (fID > 0) and fDeleteTextureOnFree then | ||||
| glDeleteTextures(1, @fID); | glDeleteTextures(1, @fID); | ||||
| inherited BeforeDestruction; | inherited BeforeDestruction; | ||||
| @@ -4418,7 +4430,7 @@ begin | |||||
| FreeMem(tmpData); | FreeMem(tmpData); | ||||
| raise; | raise; | ||||
| end; | end; | ||||
| AddFunc(Self, aFunc, false, Format, aArgs); | |||||
| AddFunc(Self, aFunc, false, aFormat, aArgs); | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -5624,6 +5636,8 @@ begin | |||||
| glbReadOpenGLExtensions; | glbReadOpenGLExtensions; | ||||
| {$ENDIF} | {$ENDIF} | ||||
| inherited Create; | inherited Create; | ||||
| fFormat := glBitmapGetDefaultFormat; | |||||
| fFreeDataOnDestroy := true; | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| @@ -5641,27 +5655,30 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat); | |||||
| constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; aData: PByte); | |||||
| var | var | ||||
| Image: PByte; | |||||
| ImageSize: Integer; | ImageSize: Integer; | ||||
| begin | begin | ||||
| Create; | 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; | ||||
| 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 | begin | ||||
| Create; | Create; | ||||
| LoadFromFunc(aSize, aFunc, aFormat, aArgs); | LoadFromFunc(aSize, aFunc, aFormat, aArgs); | ||||