1
\$\begingroup\$

If I load my vertex data from a file into a buffer in RAM, and then upload this to the GPU (say, to a static VBO so no need to modify the data), do I need to keep that buffer around? If not, how do I know that the upload is complete?

\$\endgroup\$

3 Answers 3

1
\$\begingroup\$

All OpenGL functions, with the exception noted below, will be finished with any pointer you give it upon that function's return. So glBufferData and glBufferSubData will have finished all reads from their pointers by the time they have returned.

This does not necessarily mean that they have read into those buffers. The implementation may have allocated a piece of storage and copied your data into it, after which it will schedule the upload of the data asynchronously.

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).

\$\endgroup\$
1
\$\begingroup\$

glBufferData will block until all data is copied over somewhere safe.

You can instead map the buffer into RAM and populate that. Then when you unmap the data transfer will be complete.

\$\endgroup\$
0
\$\begingroup\$

No, you don't need to preserve the data in RAM.

The function calls for uploading data stall your application until the uploading is complete.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .