为什么当我们执行ttexture.assign(aTBitmap)时,如果设置了TCanvasStyle.NeedGPUSurface,则不会在纹理中复制位图数据。如果我们对TBitmapSurface做同样的事情,那么数据会被复制......为什么会出现这种奇怪的行为?
procedure TTexture.Assign(Source: TPersistent);
var
M: TBitmapData;
begin
if Source is TBitmap then
begin
if FHandle <> 0 then
TContextManager.DefaultContextClass.FinalizeTexture(Self);
FPixelFormat := TBitmap(Source).PixelFormat;
FStyle := [TTextureStyle.Dynamic];
FTextureScale := TBitmap(Source).BitmapScale;
SetSize(TBitmap(Source).Width, TBitmap(Source).Height);
if not (TCanvasStyle.NeedGPUSurface in TBitmap(Source).CanvasClass.GetCanvasStyle) then
begin
if TBitmap(Source).Map(TMapAccess.Read, M) then
try
UpdateTexture(M.Data, M.Pitch);
finally
TBitmap(Source).Unmap(M);
end;
end;
end else if Source is TBitmapSurface then
begin
if FHandle <> 0 then
TContextManager.DefaultContextClass.FinalizeTexture(Self);
FStyle := [TTextureStyle.Dynamic];
SetSize(TBitmapSurface(Source).Width, TBitmapSurface(Source).Height);
UpdateTexture(TBitmapSurface(Source).Bits, TBitmapSurface(Source).Pitch);
end else
inherited ;
end;