]> git.sesse.net Git - nageru/blobdiff - ref_counted_gl_sync.h
Add a wrapper to make fences refcounted, as we will soon be needing to split them...
[nageru] / ref_counted_gl_sync.h
diff --git a/ref_counted_gl_sync.h b/ref_counted_gl_sync.h
new file mode 100644 (file)
index 0000000..5e23752
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef _REF_COUNTED_GL_SYNC_H
+#define _REF_COUNTED_GL_SYNC_H 1
+
+// A wrapper around GLsync (OpenGL fences) that is automatically refcounted.
+// Useful since we sometimes want to use the same fence two entirely different
+// places. (We could set two fences at the same time, but they are not an
+// unlimited hardware resource, so it would be a bit wasteful.)
+
+#include <GL/gl.h>
+#include <memory>
+
+typedef std::shared_ptr<__GLsync> RefCountedGLsyncBase;
+
+class RefCountedGLsync : public RefCountedGLsyncBase {
+public:
+       RefCountedGLsync() {}
+
+       RefCountedGLsync(GLenum condition, GLbitfield flags) 
+               : RefCountedGLsyncBase(glFenceSync(condition, flags), glDeleteSync) {}
+};
+
+#endif  // !defined(_REF_COUNTED_GL_SYNC_H)