Delphi android/iphone cache for firemonkey controls (using openGL Texture)

  

I want to improuve the rendering of Firemonkey visual components. for this the idea is to “cache” the paint in some TTexture or in Tbitmap (i don’t know with is the best).

it’s work good, for exemple i can reduce from 3ms to 0.1 ms the draw of a Trectangle with round corners using Ttexture Cache. The main problem now is that to create this Ttexture cache it’s cost me around 30 ms !

this is the code i use, if someone have any idea how i can do to speed it :

function TCacheRectangle.MakeBufBitmap: TTexture;
var TmpBitmap: Tbitmap;
M: TBitmapData;
SaveTempCanvas: TCanvas;
SceneScale: Single;
begin

if Scene <> nil then SceneScale := Scene.GetSceneScale
else SceneScale := 1;

TmpBitmap := Tbitmap.Create(round(Width * SceneScale), round(height * SceneScale));
try
TmpBitmap.BitmapScale := SceneScale;
TmpBitmap.Clear(0);
if TmpBitmap.Canvas.BeginScene then
try
SaveTempCanvas := TempCanvas;
try
TempCanvas := TmpBitmap.Canvas;
inherited paint;
finally
TempCanvas := SaveTempCanvas;
end;
finally
TmpBitmap.Canvas.EndScene;
end;
//—–
fBufBitmap := TTexture.Create;
fBufBitmap.Assign(TmpBitmap);
if (TCanvasStyle.NeedGPUSurface in TmpBitmap.CanvasClass.GetCanvasStyle) then begin
if TmpBitmap.Map(TMapAccess.Read, M) then begin
try
fBufBitmap.UpdateTexture(M.Data, M.Pitch);
finally
TmpBitmap.Unmap(M);
end;
end;
end;
//—–
finally
TmpBitmap.Free;
end;

end;

it is mostly slow on this instruction: TmpBitmap.Canvas.EndScene;

after i don’t know also what it’s the best to use: TTexture or Tbitmap. i think Ttexture are stored in GPU memory and Tbitmap in local memory but i don’t really understand the advantage/disadvantage of each (what if no more gpu memory, how to check it, how to compress a Ttexture using png for exemple, etc)

Comments are closed.