Question

Currently I am attempting to use PBOs to get video data to textures. I'm not sure if what I'm trying to do is even possible, or a good way to do it if it IS possible... I have 3 textures with the GL_RED format (one for each channel, not using Alpha currently). All three of these will be filled out in a single call to an external library.

Here's binding the buffer, etc:

void LockTexture(const TextureID& id, void ** ppbData)
{
    Texture& tex = textures.getArray()[id];
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, tex.glBufID);
    glBufferData(GL_PIXEL_UNPACK_BUFFER, tex.width * tex.height, NULL, GL_STREAM_DRAW);
    *ppbData = glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
}

This is done for the 3 textures, the buffers are then filled by the external library. Then I attempt to push them to the texture, like so:

void UnlockTexture(const TextureID& id)
{
    Texture& tex = textures.getArray()[id];
    glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
    glBindTexture(tex.glTarget, tex.glTexID);

    glCheckForErrors(); // <--- NO ERROR

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, tex.width, tex.height, GL_RED, GL_UNSIGNED_BYTE, 0);

    glCheckForErrors(); // <--- ERROR

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    glBindTexture(tex.glTarget, 0);
}

Going through the list of reasons the error could be generated, this is what I know:

  • texture array has been defined
  • type is correct
  • data param (offset) is good at 0
  • 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.

Am I correct in saying that this glUnmapBuffer is unmapping the last-mapped buffer, so the correct buffer is still mapped?

GL version is 3.2

I would greatly appreciate any help on this one, thanks!

Was it helpful?

Solution

glUnmapBuffer(target) will unmap the buffer which is currently bound to target. From the code you posted, it is unclear if there will still be the same binding as at the time you did the map call. Your wordings suggests that you do the mapping for all 3 right after each other, and when you try to unmap it, you only unmap the last one mapped because you forget to rebind the other ones, which would lead to this error for the first two of your textures.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top