File: gropenglsync.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (28 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "graphics/opengl/gropenglsync.h"


gr_sync gr_opengl_sync_fence() {
	auto fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

	// This shouldn't ever fail
	Assertion(fence != nullptr, "Fence creation failed!");

	return (gr_sync) fence;
}
bool gr_opengl_sync_wait(gr_sync sync, uint64_t timeoutns) {
	Assertion(sync != nullptr, "Invalid sync object specified!");
	Assertion(glIsSync((GLsync) sync), "Pointer was specified which is not a sync object");

	// We only need GL_SYNC_FLUSH_COMMANDS_BIT if we actually wait for the sync object. Otherwise we only check if the
	// object is signaled which does not require a flush.
	auto res = glClientWaitSync((GLsync) sync, timeoutns != 0 ? GL_SYNC_FLUSH_COMMANDS_BIT : 0, timeoutns);

	// Return true if the sync object has been signaled in any way
	return res == GL_ALREADY_SIGNALED || res == GL_CONDITION_SATISFIED;
}
void gr_opengl_sync_delete(gr_sync sync) {
	Assertion(sync != nullptr, "Invalid sync object specified!");
	Assertion(glIsSync((GLsync) sync), "Pointer was specified which is not a sync object");

	glDeleteSync((GLsync) sync);
}