When does OpenGL get finished with pointers in functions?
Solution 1:
All OpenGL functions, with the exception noted below, will be finished with any pointer you give it upon that function's return. So glReadPixels
will have finished all pixel reading and format conversion upon its return. This is why asynchronous pixel transfer is so important for reading operations. It allows OpenGL to not do that, to not synchronize with the GPU.
The only exception to this rule is every function that ends in the word "Pointer". Things like glVertexAttribPointer
, glTexCoordPointer
, and the like. When you use client-side memory with these functions (no longer legal in core profile OpenGL 3.2+), these functions store a pointer to that memory. Therefore, you must ensure that this pointer is valid for as long as you intend to render with those vertex attributes.
After each rendering call using client-memory, OpenGL requires that the implementation have finished reading from client memory by the time the rendering function returns. So you can call glDrawArrays
, then delete the pointers in question. And as long as you don't make another draw call until you've changed those pointers, you're fine. This means OpenGL has to have copied out all relevant vertex data by the time the rendering call returns (one of the reasons why using buffer objects is faster).