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

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

问题描述

我可以使用像素缓冲对象(PBO)直接从FBO(即仍连接FBO的情况下)读取像素值(即使用glReadPixels)吗?

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天全站免登陆