-
Notifications
You must be signed in to change notification settings - Fork 0
/
EAGLContext+Support.m
71 lines (63 loc) · 2.52 KB
/
EAGLContext+Support.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
#import "EAGLContext+GraphitiKit.h"
#import <OpenGLES/ES2/glext.h>
#import <OpenGLES/ES3/glext.h>
@implementation EAGLContext (Supports)
+ (NSMutableDictionary *) glSupportedExtensions {
static NSMutableDictionary *_supportedExtensions;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_supportedExtensions = [NSMutableDictionary dictionary];
});
return _supportedExtensions;
}
+ (EAGLRenderingAPI) highestSupportedAPI {
if([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3]) {
return kEAGLRenderingAPIOpenGLES3;
}
if([[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]) {
return kEAGLRenderingAPIOpenGLES2;
}
return kEAGLRenderingAPIOpenGLES1;
}
- (BOOL) hasExtension:(NSString *)extensionName {
NSAssert(self == [EAGLContext currentContext], @"can onlt get correct implemented extensions on current context");
if([EAGLContext currentContext] != self) {
}
NSSet * set = [self getImplementedExtensionSetWithAPI:self.API];
return [set containsObject:extensionName];
}
- (NSString *) supportedExtensionStrings {
NSAssert(self == [EAGLContext currentContext], @"can onlt get correct implemented extensions on current context");
NSSet * set = [self getImplementedExtensionSetWithAPI:self.API];
NSMutableString *string = [NSMutableString string];
[set enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
[string appendFormat:@"%@,",obj];
}];
return [string copy];
}
- (NSSet *) getImplementedExtensionSetWithAPI:(EAGLRenderingAPI)api {
NSSet *set = [EAGLContext glSupportedExtensions][@(api)];
if(!set) {
switch(api) {
case kEAGLRenderingAPIOpenGLES3: {
int max = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max);
NSMutableSet *extensions = [NSMutableSet set];
for (int i = 0; i < max; i++) {
[extensions addObject: @( (char *)glGetStringi(GL_EXTENSIONS, i) )];
}
set = [extensions copy];
break;
}
default: {
NSString *extensionString = [NSString stringWithUTF8String:(char *)glGetString(GL_EXTENSIONS)];
NSArray *extensions = [extensionString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
set = [NSSet setWithArray:extensions];
break;
}
}
[EAGLContext glSupportedExtensions][@(api)] = set;
}
return set;
}
@end