Currently I am attempting to use PBOs to get video data to textures.
I file the buffer with glMapBuffer():
for (int iBuffer = 0; iBuffer < N_MAX_BUFFERS; ++iBuffer)
{
// bind pixel-buffer object
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[iBuffer]);
// create buffer's data container
glBufferData(GL_PIXEL_UNPACK_BUFFER, DATA_SIZE, NULL, GL_STREAM_DRAW);
void * pPixelsPBO = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE);//GL_WRITE_ONLY
// copy original image into the buffer
if(pPixelsPBO)
{
//pPixelsPBO = new unsigned char[imageGL.width() * imageGL.height() * 3];
memcpy(pPixelsPBO, imageGL.bits(), DATA_SIZE);//memcpy
}
// unbind pixel-buffer object
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
And I display the buffer into the texture with glTexSubImage2D:
glBindTexture(GL_TEXTURE_2D, texture);
// bind PBO to update pixel values
// GL_PIXEL_PACK_BUFFER to transfer pixel data to a PBO
//GL_PIXEL_UNPACK_BUFFER to transfer pixel data from PBO.
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[nextIndex]);// for nextIndex
MyLgGetError("glBindBuffer");
displayeInfo();
MyLgGetError("displayeInfo");
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageGL.width(), imageGL.height(), GL_BGRA, GL_UNSIGNED_BYTE, 0);
MyLgGetError("glTexSubImage2D");
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0);
this is a correct way to use PBO ?
Going through the list of reasons the error could be generated, this is what I know:
•texture array has been defined
•not executed between glBegin/glEnd
This one I’m not sure about:
•error is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the data would be unpacked from the buffer object such that the memory reads required would exceed the data store size.
This one seems like it could be an issue, but I’d have no idea how else to handle this:
•error is generated if a non-zero buffer object name is bound to the GL_PIXEL_UNPACK_BUFFER target and the buffer object’s data store is currently mapped.