Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does OpenGL get finished with pointers in functions?

OpenGL has a number of functions that directly take pointers. Some of them read data from those pointers, others write data to those pointers.

However, OpenGL functions often don't execute immediately. Usually, when you draw something, it takes a while for the drawing to finish.

So how do I know when OpenGL is finished with a pointer I give it?

like image 972
Nicol Bolas Avatar asked Mar 29 '13 05:03

Nicol Bolas


1 Answers

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

like image 158
Nicol Bolas Avatar answered Sep 22 '22 10:09

Nicol Bolas