GLS  1.0.0
GL Stuff - A library aimed at reducing the boilerplate OpenGL code you always have to write.
sync Class Reference

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...
 
syncoperator= (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...
 

Detailed Description

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:

auto sync = gls::sync();
auto write_data = std::vector<char>( 256000000, 0 );
buffer.data( write_data.size(), write_data.data() );
... do stuff that depends on buffer's data ...
sync.insert();
... do some other stuff to give the commands time to complete ...
if( sync.expired() ) {
... all operations that depend on buffer have completed ...
}

Constructor & Destructor Documentation

sync ( )

Default constructor.

~sync ( )

Destructor.

sync ( sync &&  other)

Move constructor.

Parameters
otherOther sync that is being moved from

Member Function Documentation

sync& operator= ( sync &&  other)

Move assignment operator.

Parameters
otherOther sync that is being assigned from
Returns
*this
GLsync name ( ) const

Retrieve the OpenGL name of this sync object.

Returns
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.

Parameters
timeoutTime to wait for the sync to expire in nanoseconds
Returns
true if this object expired upon returning, false otherwise
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.

Returns
true if this object is expired, false otherwise
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.