CPU side copies of data

Hi All,

I was wondering when exactly a copy of CPU data is made into the GPU. For example, we say glGenBuffers() followed by glBufferData().
Now, is the CPU vertex data copied to the GPU when the glDraw* call is made? What is the general approach(if any) or does OpenGL suggests something for driver implementors?
Same applies to textures(glTexImage* functions).

Can anyone please clarify this?

It’s up to the implementation when data is copied between CPU and GPU memory (if these are even different, which isn’t necessarily the case).

However, most functions which accept a pointer to input data require that data to be copied somewhere before the function returns.

So data passed to glBufferData, glTexImage*, etc will be copied before the call returns. It may be copied directly to GPU memory, or copied into a buffer in CPU memory and copied to GPU memory later. But whichever approach is used, modifying the passed-in buffer after the call returns will have no effect upon the operation of OpenGL.

The main exception to this principle is for glVertexAttribPointer (and fixed-function equivalents such as glVertexPointer, glNormalPointer, etc). In that case, the data is read during subsequent draw calls, not during the gl*Pointer call, so modifying the contents of the buffer will affect the results of subsequent draw calls.

The main exception to this principle is

Small point: That’s the only exception. Indeed, that’s the point of the “Pointer” nomenclature: to specify that the pointer in question will be retained by OpenGL and used at some later time. In all other cases (unless you’re using an extension of some sort), pointers given by the user will never be retained by OpenGL. By the end of the function call, the implementation will have done whatever it is going to do with the memory you gave it.

Note also that, while the pointer can be discarded after the call, this does not mean that it has been copied from CPU memory to GPU memory. Generally speaking, implementations will copy your memory out to a block of internally allocated CPU memory. Then it will do the GPU DMA from there. After the DMA completes, the internal memory will be deleted.

The whole point of buffer mapping and pixel buffers is to avoid the use of this internal copying.