1 #ifndef _REF_COUNTED_GL_SYNC_H
2 #define _REF_COUNTED_GL_SYNC_H 1
4 // A wrapper around GLsync (OpenGL fences) that is automatically refcounted.
5 // Useful since we sometimes want to use the same fence two entirely different
6 // places. (We could set two fences at the same time, but they are not an
7 // unlimited hardware resource, so it would be a bit wasteful.)
13 typedef std::shared_ptr<__GLsync> RefCountedGLsyncBase;
15 class RefCountedGLsync : public RefCountedGLsyncBase {
19 RefCountedGLsync(GLenum condition, GLbitfield flags)
20 : RefCountedGLsyncBase(locked_glFenceSync(condition, flags), glDeleteSync) {}
23 // These are to work around apitrace bug #446.
24 static GLsync locked_glFenceSync(GLenum condition, GLbitfield flags)
26 std::lock_guard<std::mutex> lock(fence_lock);
27 return glFenceSync(condition, flags);
30 static void locked_glDeleteSync(GLsync sync)
32 std::lock_guard<std::mutex> lock(fence_lock);
36 static std::mutex fence_lock;
39 #endif // !defined(_REF_COUNTED_GL_SYNC_H)