GLS
1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
|
Class encapsulating an OpenGL sync object. More...
#include <sync.hpp>
Public Member Functions | |
sync () | |
Default constructor. More... | |
~sync () | |
Destructor. More... | |
sync (sync &&other) | |
Move constructor. More... | |
sync & | operator= (sync &&other) |
Move assignment operator. More... | |
GLsync | name () const |
Retrieve the OpenGL name of this sync object. More... | |
void | insert () |
Insert into the command queue. More... | |
bool | wait (GLuint64 timeout) |
Wait for the sync to expire. More... | |
bool | expired () |
Check if the current sync object has expired. More... | |
void | server_wait () |
Make server execution wait for this sync to expire. More... | |
Class encapsulating an OpenGL sync object.
A gls::sync is an object that encapsulates an OpenGL sync object.
Unlike other objects in GLS, the underlying sync is not generated at object construction. It is however, deleted at destruction. A new sync is generated each time the insert() method is called.
gls::sync objects are move-only.
Sync objects are relatively simple to use. One simply creates them, inserts them into the command queue and either waits or periodically checks to see if they have expired. The fact that they have expired provides valuable information required for proper synchronization of other OpenGL code.
Example usage:
sync | ( | ) |
Default constructor.
~sync | ( | ) |
Destructor.
Move assignment operator.
other | Other sync that is being assigned from |
GLsync name | ( | ) | const |
Retrieve the OpenGL name of this sync object.
void insert | ( | ) |
Insert into the command queue.
This creates a new fence sync object and inserts it into the OpenGL command queue. Any previous sync object managed by this gls::sync object is deleted prior to the creation of the new one.
bool wait | ( | GLuint64 | timeout | ) |
Wait for the sync to expire.
If the passed timeout value is not 0, this method will only return once the timeout has passed, the sync expires or an error occurs. In the case the sync expires, either within the timeout, or prior to this method being called, true will be returned. In all other cases false will be returned.
Be aware that although timeout is specified in nanoseconds, the precision is not guaranteed to be that high. This method will return once at least that much time has passed.
timeout | Time to wait for the sync to expire in nanoseconds |
bool expired | ( | ) |
Check if the current sync object has expired.
This object becomes expired when the GL server completes execution of all commands prior to the location where this object was inserted into the command queue. Upon expiration, the underlying sync object is not yet deleted. It is only deleted when this object is destroyed, or a new sync object is to be inserted into the OpenGL command queue.
void server_wait | ( | ) |
Make server execution wait for this sync to expire.
After calling this method, the server will not receive any new commands from the client until the sync has expired.
Because it is required, the client command queue is automatically flushed prior to waiting.