为了进行基准测试,我们来看看这段著名的PBO回读代码。
问题:
- 使用PBO在我的电脑中没有任何效果。即使有最新的驱动程序更新&正确的像素格式BGRA
更新1:我也用3个PBO尝试过同样的例子。但即便如此,也没有什么区别
注:英特尔(R)酷睿(TM)i5-3470S CPU@2.90GHz,2901 Mhz,4核,显卡:Intel(R)HD Graphics 2500
PBO: off
Read Time: 9 ms
Process Time: 2 ms
Transfer Rate: 39.5 Mpixels/s. (45.0 FPS)
PBO: on
Read Time: 7 ms
Process Time: 2 ms
PBO: on Transfer Rate: 38.8 Mpixels/s. (44.2 FPS)
更新2:PBO在外部GPU&也在英特尔i-7系列中
PC配置:Intel(R)Core(TM)i7-3770 CPU@3.40GHz,3400 Mhz,4核,8逻辑处理器,视频卡:Geforce 210。因此,这是集成GPU的问题;外部GPU。我相信这将是一个有用的提示,许多人想知道为什么他们的代码不工作!
PBO: on
PBO: on Read Time: 0.06 ms
Process Time: 2 ms
Transfer Rate: 112.4 Mpixels/s. (127.9 FPS)
PBO: off
Read Time: 4 ms
Process Time: 2 ms
Transfer Rate: 93.3 Mpixels/s. (106.1 FPS)
在链接中:
正在映射PBO。。。
注意,如果GPU仍在使用缓冲对象,glMapBufferARB()将不会返回,直到GPU用相应的缓冲区对象。要避免此暂停(等待),请调用在glMapBufferARB()之前带有NULL指针的glBufferDataARB(。然后,OpenGL将丢弃旧的缓冲区,并分配新的内存缓冲区对象的空间。
您可能需要将上述建议的更改应用于以下代码:
// "index" is used to read pixels from framebuffer to a PBO
// "nextIndex" is used to update pixels in the other PBO
index = (index + 1) % 2;
nextIndex = (index + 1) % 2;
// set the target framebuffer to read
glReadBuffer(GL_FRONT);
// read pixels from framebuffer to PBO
// glReadPixels() should return immediately.
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[index]);
glReadPixels(0, 0, WIDTH, HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE, 0);
// map the PBO to process its data by CPU
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboIds[nextIndex]);
glBufferDataARB(GL_PIXEL_PACK_BUFFER_ARB, 0, NULL, GL_STATIC_DRAW_ARB);
GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,
GL_READ_ONLY_ARB);
if(ptr)
{
processPixels(ptr, ...);
glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
}
// back to conventional pixel operation
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);