Skip to main content
gamedev.net
🔒 Locked

When does OGL actually draw what you tell it to?

Started by Tree Penguin Apr 28, 2005 at 3:37 PM 3 replies 2.1k views
Original Post
Tree Penguin
Tree Penguin
For instance, i make a call to glDrawElements, when does it actually draw the geometry? When you call the function? If so, does it return after drawing or asap? Or at another time? Thanks.
Fruny
Fruny
The functions generally return immediately. The geometry is drawn when the driver feels like it. Functions like glFinish will block until all the queued commands are actually processed.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Tree Penguin
Tree Penguin
Thanks, so it's probably more efficient to mix calculations and drawing commands instead of first calculating everything and then drawing everything, am i right?
Eric Lengyel
Eric Lengyel
As you make calls to OpenGL, it builds up a command buffer that contains instructions for the hardware. Some calls cause data to be added to the command buffer immediately, and other calls just cause the OpenGL implementation to save the new state information. When you make a draw call like glDrawElements(), all of the deferred state that you've changed is dumped into the command buffer right before the actual drawing command. In any case, once commands have been written to the command buffer or state has been saved, the OpenGL implementation returns to your code right away.

This process continues without the GPU getting any data until one of the following happens:

1) The command buffer becomes full.
2) You call glFlush() or glFinish().
3) You call SwapBuffers().

When one of these happens, the GPU is told to start processing the command buffer (which typically exists in GPU-accessible memory like AGP space). If you called glFinish(), then the OpenGL implementation will actually wait for the GPU to completely process the whole buffer, but otherwise it will return immediately so that you can do other stuff while the GPU is rendering.

In order to achieve the best concurrency between the CPU and GPU without frame lag, you should start making draw calls as early as possible (especially if you want to use occlusion queries). Part way through your drawing, the command buffer will probably fill up and it will be kicked off to the GPU for rendering.

-- Eric Lengyel

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.