giggle
giggle

Reputation: 1951

DrawPixels with PACK Pixel Buffer Object

guys, In the GLUT display() function, I read the pixel into a PACK buffer object.

// 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));

And I read and update the pixel data content, and draw it into frame buffer again.

But the glDrawPixels return GL_invalid_operation. Is there something wrong?

Thanks.

Upvotes: 1

Views: 3406

Answers (1)

datenwolf
datenwolf

Reputation: 162367

If using a PBO glDrawPixels operates on a GL_UNPACK_BUFFER. You have only a GL_PACK_BUFFER bound. You need to unbind the buffer object from the pack binding, then bind it to the unpack binding and call glDrawPixels then.

EDIT code for clarification

// 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);

Upvotes: 1

Related Questions