-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGLPSync.m
78 lines (67 loc) · 1.37 KB
/
GLPSync.m
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#import "GLPSync.h"
@implementation GLPSync
+ (instancetype)sync
{
return [[self alloc] init];
}
+ (GLenum)syncWithClientWait:(NSTimeInterval)timeout
{
return [[self sync] clientWait:timeout];
}
+ (void)syncWithWait:(NSTimeInterval)timeout
{
[[self sync] wait:timeout];
}
- (instancetype)init
{
self = [super init];
if(self != nil)
{
#ifdef GL3_PROTOTYPES
sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
#else
sync = glFenceSyncAPPLE(GL_SYNC_GPU_COMMANDS_COMPLETE_APPLE, 0);
#endif
}
return self;
}
- (void)dealloc
{
if(sync != NULL)
{
#ifdef GL3_PROTOTYPES
glDeleteSync(sync);
#else
glDeleteSyncAPPLE(sync);
#endif
}
}
@synthesize GLSync = sync;
- (BOOL)signaled
{
GLint value = 0;
#ifdef GL3_PROTOTYPES
glGetSynciv(sync, GL_SYNC_STATUS, sizeof(value), NULL, &value);
return value == GL_SIGNALED;
#else
glGetSyncivAPPLE(sync, GL_SYNC_STATUS_APPLE, sizeof(value), NULL, &value);
return value == GL_SIGNALED_APPLE;
#endif
}
- (GLenum)clientWait:(NSTimeInterval)timeout
{
#ifdef GL3_PROTOTYPES
return glClientWaitSync(sync, GL_SYNC_FLUSH_COMMANDS_BIT, timeout * NSEC_PER_SEC);
#else
return glClientWaitSyncAPPLE(sync, GL_SYNC_FLUSH_COMMANDS_BIT_APPLE, timeout * NSEC_PER_SEC);
#endif
}
- (void)wait:(NSTimeInterval)timeout
{
#ifdef GL3_PROTOTYPES
glWaitSync(sync, 0, timeout * NSEC_PER_SEC);
#else
glWaitSyncAPPLE(sync, 0, timeout * NSEC_PER_SEC);
#endif
}
@end