forked from dahenry/gl-gsync-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsync.c
42 lines (31 loc) · 958 Bytes
/
vsync.c
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <GL/glxew.h>
#include "vsync.h"
void vsyncInitialize(struct VSyncController *controller)
{
controller->isAvailable = false;
controller->dpy = glXGetCurrentDisplay();
controller->drawable = glXGetCurrentDrawable();
controller->isAvailable = GLXEW_EXT_swap_control && controller->drawable;
}
bool vsyncIsAvailable(struct VSyncController *controller)
{
return controller->isAvailable;
}
bool vsyncIsEnabled(struct VSyncController *controller)
{
unsigned int swapInterval;
glXQueryDrawable(controller->dpy, controller->drawable, GLX_SWAP_INTERVAL_EXT, &swapInterval);
switch(swapInterval) {
case 0: return false;
default: return true;
}
}
void vsyncSetEnabled(struct VSyncController *controller, bool enable)
{
unsigned int swapInterval;
switch (enable) {
case false: swapInterval = 0; break;
case true: swapInterval = 1; break;
}
glXSwapIntervalEXT(controller->dpy, controller->drawable, swapInterval);
}