使用像素缓冲对象 (PBO) 从帧缓冲对象 (FBO) 读取像素值 [英] Reading the pixels values from the Frame Buffer Object (FBO) using Pixel Buffer Object (PBO)

查看:28
本文介绍了使用像素缓冲对象 (PBO) 从帧缓冲对象 (FBO) 读取像素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用像素缓冲区对象 (PBO) 直接从 FBO 读取像素值(即使用 glReadPixels)吗(即当 FBO 仍然连接时)?

Can I use Pixel Buffer Object (PBO) to directly read the pixels values (i.e. using glReadPixels) from the FBO (i.e. while FBO is still attached)?

如果是,

  1. 将 PBO 与 FBO 结合使用的优点和缺点是什么?
  2. 以下代码有什么问题

{

//DATA_SIZE = WIDTH * HEIGHT * 3 (BECAUSE I AM USING 3 CHANNELS ONLY)
// FBO and PBO status is good
.
.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
//Draw the objects

遵循 glReadPixels 工作正常

glReadPixels(0, 0, screenWidth, screenHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,  (uchar*)cvimg->imageData);

遵循 glReadPixels 不起作用:(

glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, pboId);
//yes glWriteBuffer has also same target and I also checked with every possible values
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); 
glReadPixels(0, 0, screenWidth, screenHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, (uchar*)cvimg->imageData);
.
.
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); //back to window framebuffer

推荐答案

当使用 PBO 作为 glReadPixels 的目标时,您必须指定缓冲区的字节偏移量 (0>,我想)而不是 (uchar*)cvimg->imageData 作为目标地址.它类似于在使用 VBO 时在 glVertexPointer 中使用缓冲区偏移量.

When using a PBO as target for glReadPixels you have to specify a byte offset into the buffer (0, I suppose) instead of (uchar*)cvimg->imageData as target address. It is similar to using a buffer offset in glVertexPointer when using VBOs.

当 PBO 绑定到 GL_PIXEL_PACK_BUFFER 时,glReadPixels 的最后一个参数不被视为指向系统内存的指针,而是作为绑定缓冲区内存中的字节偏移量.因此,要将像素写入缓冲区,只需传递一个 0(将它们写入缓冲存储器的开头).然后,您可以稍后通过 glMapBuffer 访问缓冲存储器(以获取像素).您在评论中提供的示例链接也可以做到这一点,只需广泛阅读即可.我还建议阅读他们在开始时提到的有关顶点缓冲区对象的部分,因为它们为理解缓冲区对象奠定了基础.

When a PBO is bound to the GL_PIXEL_PACK_BUFFER, the last argument to glReadPixels is not treated as a pointer into system memory but as a byte offset into the bound buffer's memory. So to write the pixels into the buffer just pass a 0 (write them to the start of the buffer memory). You can then later acces the buffer memory (to get the pixels) by means of glMapBuffer. The example link you provided in your comment does that, too, just read it extensively. I also suggest reading the part about vertex buffer objects they mention at the start, as these lay the ground to understand buffer objects.

这篇关于使用像素缓冲对象 (PBO) 从帧缓冲对象 (FBO) 读取像素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆