Kawałek kodu poniżej, zrobiłem sobie prosty test szybkości 1000 powtórzeń:
[1] glReadPixels - wykonywało się 585ms
[2] przepisanie bufora do BMP 200ms
[3] Canvas.CopyRect trwa najdłużej 1454ms
**A jak by mozna było wyświetlać szybciej dane odczytane za pomocą glReadPixels ? **
procedure TForm001.btn4Click(Sender: TObject);
var
b: TBitmap;
mem: Pointer;
mem1: PIntegerArray absolute mem;
p1,p2: pointer;
x,y: integer;
i: integer;
t1,t2: dword;
begin
//Application.OnIdle := nil;
//Timer1.Enabled := False;
b := TBitmap.Create;
b.PixelFormat := pf24bit;
b.Width := Panel1.Width;
b.Height := Panel1.Height;
//
GetMem(mem, b.Width * b.Height *3 );
t1 := GetTickCount;
for I := 0 to 1000 - 1 do
begin
// 585ms/1000
glReadPixels(0,0, b.Width, b.Height, GL_BGR , GL_UNSIGNED_BYTE,mem);
// 200ms/1000
for y := 0 to b.Height - 1 do
begin
//p1 := b.ScanLine[b.Height - y -1];
p1 := b.ScanLine[y ];
p2 := pbyte(mem) + b.Width * 3 * y;
Move(p2^, p1^, b.Width*3 );
end;
// 1454ms/1000
Canvas.CopyRect(Rect(0,0,b.Width,b.Height),b.Canvas ,Rect(0,0,b.Width,b.Height));
end;
t2 := GetTickCount;
caption := ' Czas ms: '+IntToStr(t2 - t1)
+' Transfer MB: '+ floattostr(b.Width * b.Height *3*1000 / (1024*1024) )
+' Speed MB/S: '+ FloatToStr(b.Width * b.Height *3*1000 / (1024*1024) / ((t2 - t1) / 1000 ) ) ;
b.SaveToFile('e.bmp'); // aby sobie pooglądać
FreeMem(mem);
b.Free;
end;