I’m using PBOs to asynchronously move data between my cpu and gpu.
When moving from the GPU i know I can delete the source texture after I have called glMapBuffer on the PBO.
However, what about the other way around? When do I know that the transfer from the PBO to the texture (glTexSubImage2D(…, NULL)) is done and I can safely release or re-use the PBO? Is it as soon as I bind the texture or something else?
I think after calling
glTexImageyou are safe in deleting or reusing the buffer without errors, as the driver handles everything for you, including deferred destruction (that’s the advantage of buffer objects). But this means, that calls toglMapBuffermay block until the precedingglTexImagecopy has completed. If you want to reuse the buffer and just overwrite its whole content, it is common practice to realocate it withglBufferDatabefore callingglMapBuffer. This way the driver knows you don’t care about the previous content anymore and can allocate a new buffer that you can use immediately (the memory containing the previous content is then freed by the driver when it is really not used anymore). Just keep in mind that your buffer object is just a handle to memory, that the driver can manage and copy as it likes.EDIT: This means in the other way (GPU-CPU) you can delete the source texture after
glGetTexImagehas returned, as the driver manages everything behind the scenes. The decision of using buffer objects or not should not have any implications on the order and time in which you call GL functions. Keep in mind that callingglDelete...does not immediately delete an object, it just enqueues this command into the GL command stream and even then, its up to the driver when it really frees any memory.