Know if draw call has finished

Is it possible to know if a specific draw call has finished? For example:


bind_some_data(foo);
glDraw*(); // -> draw1

bind_some_data(bar);
glDraw*(); // -> draw2

if (draw1_has_finished())
    do_something();

I’m not asking something like glFinish() nor glFlush() because I don’t mind if “draw2” has finished or not.
I’m using OpenGL 4.3 core/4.4 compatibility.

Use fences.

Add this after your draw call:

GLsync fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0)

and then wait for it to finish:

if (glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 0) == GL_ALREADY_SIGNALED) {
// Draw call finished
}else {
// Do some other useful stuff
}

You also can block until its finished. The above will not block. Furthermore you can specify a max waiting time.

Hope this helps.

Thank you. I thought sync objects do a full synchronization but now they’re working.