PDA

View Full Version : After PBO update why I need glTexImage2D?



tdname
01-28-2014, 03:19 AM
I try to understand why I need to "re-create/allocate" image texture after a PBO upload....

Execution:


glGenTextures()
glBindTexture()
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0) //just memory/buffer allocation
glMapBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, w*h*4, GL_MAP_WRITE_BIT)
memcpy(...)
glUnmapBuffer()
...GPU fence waiting upload...
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, 0) //same as n.3!!!!!!


If I comment last line (n.8) I get a texture with "random"/wrong pixels color...
glMapBufferRange and memcpy functions should have uploaded/updated/refreshed texture's bytes, so why the last command (n.8) needed to be executed?

Thanks

chbaker0
01-28-2014, 08:34 AM
Have you tried commenting out the first glTexImage2D and leaving the second?

The reason why the PBO upload doesn't update the texture is because the PBO isn't associated with the texture in any way. A PBO's purpose is to simply store pixel data that will be used at a later time (for a texture or whatever) and let the implementation decide how to manage it.