After PBO update why I need glTexImage2D?

I try to understand why I need to “re-create/allocate” image texture after a PBO upload…


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

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?


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.