更新时间:2023-11-10 12:26:46
目前,此方法有效
int pixelData = 0;
GL.ReadPixels (fboWidth / 2, fboHeight / 2, 1, 1, OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, ref pixelData);
int red = Color.FromArgb(pixelData).R;
int green = Color.FromArgb(pixelData).G;
int blue = Color.FromArgb(pixelData).B;
但是有 明显的缺点.
由jp链接的 PBO 文章中所述,glReadPixels()
会阻塞管道并等到所有像素数据传输完毕,然后再将控制权返回给应用程序.在我的程序和我的机器上,该停顿是显而易见的.
As described in the PBO article linked by j-p, glReadPixels()
blocks the pipeline and waits until all pixel data is transferred, only then returning control to the application. In my program, and on my machine, that stall is noticeable.
长期解决方案似乎是像素缓冲区对象,它通过在GL和客户端之间提供异步数据传输来减少开销.当我有东西要显示时,我会修改这个答案.
The long term solution seems to be the Pixel Buffer Object which reduces the overhead by providing asynchronous data transfer between GL and the client. I'll amend this answer when I have something to show.