具有PACK像素缓冲区对象的DrawPixels

时间:2011-09-05 07:32:43

标签: opengl

人, 在GLUT display()函数中,我将像素读入PACK缓冲区对象。

// Read the frame buffer into the binded read stream.
glBindBuffer(GL_PIXEL_PACK_BUFFER, bufferObject[RetrievingPixelBuffer]);
glReadPixels(0,0,width, height, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));

GLfloat* pixels = (GLfloat*) glMapBuffer( GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
for( int i = 0; i <width*height; i++)
{
    *pixels = 1.0;
    pixels+=4;
}
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);

glDrawPixels(width, height, GL_RGBA,
             GL_FLOAT, BUFFER_OFFSET(0));

我读取并更新像素数据内容,并再次将其绘制到帧缓冲区中。

但glDrawPixels返回GL_invalid_operation。有什么不对吗?

感谢。

1 个答案:

答案 0 :(得分:1)

如果使用PBO glDrawPixelsGL_UNPACK_BUFFER进行操作。您只有GL_PACK_BUFFER个界限。您需要从包绑定中取消绑定缓冲区对象,然后将其绑定到解包绑定,然后调用glDrawPixels

用于澄清的EDIT代码

// Read the frame buffer into the binded read stream.
glBindBuffer(GL_PIXEL_PACK_BUFFER, bufferObject[RetrievingPixelBuffer]);
glReadPixels(0,0,width, height, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));

GLfloat* pixels = (GLfloat*) glMapBuffer( GL_PIXEL_PACK_BUFFER, GL_READ_WRITE);
for( int i = 0; i <width*height; i++)
{
    *pixels = 1.0;
    pixels+=4;
}
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); /* unbind the PBO */

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bufferObject[RetrievingPixelBuffer]);
          /*          ^^^^^^--- You need to bind your PBO for UNPACKING! */
glDrawPixels(width, height, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);