GLint syncStatus; glGetSynciv(*sync,GL_SYNC_STATUS,sizeof(GLint),NULL,&syncStatus); bool finished = syncStatus == GL_SIGNALED;
VS
bool finished = glClientWaitSync(*sync,0 /*flags*/,0 /*timeout*/) == ALREADY_SIGNALED;
一些细节问题:
> glGetSynciv是否执行GL服务器的往返?
>在驱动程序支持/错误方面,是否有其他方法?
>任何一种方法死锁或不能立即返回?
一些上下文:
>这是一个视频播放器,它将图像从物理源传输到GPU进行渲染.
>一个线程正在流式传输/连续上传纹理,另一个线程在完成上传后呈现它们.每个渲染帧我们正在检查下一个纹理是否完成上传.如果有的话,我们开始渲染这个新的纹理,否则继续使用旧的纹理.
>决定只是客户端,我根本不想等待,但是快速地继续渲染正确的纹理.
解决方法
void glGetSynciv(GLsync sync,GLenum pname,GLsizei bufSize,GLsizei *lenght,GLint *values);
Retrieves the properties of a sync object. sync specifies a handle to the sync object from wich to read the property specified by pname. bufSize is the size in bytes of the buffer whose address is given in values. lenght is the address of an integer variable that will receive the number of bytes written into values
而对于glClientWaitSync:
GLenum glClientWaitSync(GLsync sync,GLbitfields flags,GLuint64 timeout);
Causes the client to wait for the sync object to become signaled.
glClientWaitSync() will wait at most timeout nanoseconds for the object to become signaled before generating a timeout. The flags parameter may be used to control flushing behavior of the command. Specifying GL_SYNC_FLUSH_COMMANDS_BIT is equivalent to calling glFlush() before executing wait.
因此,基本上glGetSynciv()用于知道fence对象是否已经被发出信号,并且glClientWaitSync()被用于等待fence对象已经发出信号.
如果你只想知道一个栅栏对象是否已经发出信号,我建议使用glGetSynciv().显然,glClientWaitSync()需要更长的时间来执行glGetSynciv(),但我猜.希望我帮了你