Graphics Reference
In-Depth Information
the server has completed execution of previously submitted commands.
Consider another example where multiple OpenGL ES contexts (each current
to a different thread) are sharing objects. To synchronize correctly between
these contexts, it is important that commands from context A be issued to
the server before commands from context B, which depends on OpenGL
ES state modified by context A. The
glFlush
command is used to flush any
pending commands in the current OpenGL ES context and issue them to the
server. Note that
glFlush
only issues the commands to the server; it does
not wait for them to complete. If the client requires that the commands be
completed, the
glFinish
command should be used. We do not recommend
using
glFinish
unless absolutely necessary. Because
glFinish
does not
return until all queued commands in the context have been completely
processed by the server, calling
glFinish
can adversely impact performance
by forcing the client and the server to synchronize their operations.
OpenGL ES 3.0 introduces a new feature, called a fence, that provides a
way for the application to inform the GPU to wait until a set of OpenGL
ES operations have finished executing before queuing up more for
execution. You can insert a fence command into the GL command stream
and associate it with a sync object to be waited on.
If we compare using sync objects to the
glFinish
command, sync objects
are more efficient, as you can wait on partial completions of the GL
command stream. By comparison, calling the
glFinish
command may
reduce the performance of your applications, as this command will empty
the graphics pipeline.
To insert a fence command to the GL command stream and create a sync
object, you can call the following function:
GLsync
glFenceSync
(GLenum
condition
, GLbitfield
flags
)
condition
specifies the condition that must be met to signal the sync
object; must be
GL_SYNC_GPU_COMMANDS_COMPLETE
specifies a bit-wise combination of flags to control the
behavior of the sync object; must be zero presently
flags