Skip to content

Commit

Permalink
add ALTransformBitmaptoTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeus64 committed Dec 23, 2018
1 parent dcf1c6c commit 4dbbaea
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
3 changes: 0 additions & 3 deletions source/ALFMXTypes3D.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ TALTextureAccessPrivate = class(TInterfacedPersistent)
FBits: Pointer;
FContextLostId: Integer;
FContextResetId: Integer;
{$IF CompilerVersion <= 31} // berlin
FContextID: integer; // << this was added by me in Berlin in a customized version of FMX.Types3D.TTexture - normally no matter to access previous field - https://quality.embarcadero.com/browse/RSP-19160
{$ENDIF}
protected
public
end;
Expand Down
73 changes: 73 additions & 0 deletions source/ALGraphics.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ function ALJBitmaptoTexture(const aBitmap: Jbitmap; const aVolatileTexture: bool
{$IF defined(ANDROID) or defined(IOS)}
function ALBitmapSurfacetoTexture(const aBitmapSurface: TbitmapSurface; const aVolatileTexture: boolean = true): TTexture;
{$ENDIF}
{$IFDEF _USE_TEXTURE}
function ALTransformBitmaptoTexture(var aBitmap: Tbitmap; const aVolatileTexture: boolean = true): TTexture;
{$ENDIF}

type

Expand Down Expand Up @@ -262,6 +265,9 @@ implementation
ALFmxTypes3D,
alFmxCommon,
{$ENDIF}
{$IFDEF _USE_TEXTURE}
FMX.Canvas.GPU,
{$ENDIF}
ALCommon;

{********************}
Expand Down Expand Up @@ -361,6 +367,73 @@ function ALBitmapSurfacetoTexture(const aBitmapSurface: TbitmapSurface; const aV
end;
{$ENDIF}

{*******************}
{$IFDEF _USE_TEXTURE}
function ALTransformBitmaptoTexture(var aBitmap: Tbitmap; const aVolatileTexture: boolean = true): TTexture;
var aBitmapSurface: TbitmapSurface;
aPaintingTexture: TTexture;
begin

//If TCustomCanvasGpu then simply move the textureID to the result
if aBitmap.CanvasClass.InheritsFrom(TCustomCanvasGpu) then begin

//TBitmap.image = TBitmapImage
//TBitmap.image.handle = TBitmapCtx (but casted as THandle)
aPaintingTexture := TBitmapCtx(aBitmap.Handle).PaintingTexture;
Result := TalTexture.Create(aVolatileTexture);
try

//assign aPaintingTexture to Result
{$IF CompilerVersion > 32} // tokyo
{$MESSAGE WARN 'Check if ALFMXTypes3D.TALTextureAccessPrivate still has the exact same fields and adjust the IFDEF'}
{$ENDIF}
TALTextureAccessPrivate(Result).FWidth := aPaintingTexture.width;
TALTextureAccessPrivate(Result).FHeight := aPaintingTexture.height;
TALTextureAccessPrivate(Result).FPixelFormat := aPaintingTexture.PixelFormat;
TALTextureAccessPrivate(Result).FHandle := aPaintingTexture.Handle;
TALTextureAccessPrivate(Result).FStyle := aPaintingTexture.Style;
TALTextureAccessPrivate(Result).FMagFilter := aPaintingTexture.MagFilter;
TALTextureAccessPrivate(Result).FMinFilter := aPaintingTexture.MinFilter;
TALTextureAccessPrivate(Result).FTextureScale := aPaintingTexture.TextureScale;
//FRequireInitializeAfterLost: Boolean;
//FBits: Pointer;
//FContextLostId: Integer;
//FContextResetId: Integer;

//set the handle of aTmpTexture to 0 to avoid the
//textureID to be deleted from OpenGL when we will free aBitmap
ITextureAccess(aPaintingTexture).Handle := 0;

{$IFDEF DEBUG}
if result.PixelFormat <> TPixelFormat.None then AtomicIncrement(TotalMemoryUsedByTextures, result.Width * result.Height * result.BytesPerPixel);
{$ENDIF}

except
ALFreeAndNil(Result);
raise;
end;

end

//else use a aBitmapSurface to transfert the bitmap to the texture
else begin

aBitmapSurface := TbitmapSurface.create;
try
aBitmapSurface.Assign(aBitmap);
result := ALBitmapSurfacetoTexture(aBitmapSurface);
finally
alfreeAndNil(aBitmapSurface);
end;

end;

//free the aBitmap as we extract the texture from it
alFreeAndNil(aBitmap);

end;
{$ENDIF}

{***********************************************************************************************************************************************************************}
function ALFitIntoAndCropAsRoundRectImageV1(const aStream: TCustomMemoryStream; const W, H: single; const XRadius, YRadius: single; const aCropCenter: TPointF): Tbitmap;
var aBitmap: TBitmap;
Expand Down

0 comments on commit 4dbbaea

Please sign in to comment.