-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEAGLPContextStack.m
More file actions
59 lines (44 loc) · 926 Bytes
/
EAGLPContextStack.m
File metadata and controls
59 lines (44 loc) · 926 Bytes
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
#import "EAGLPContextStack.h"
@interface EAGLPContextStack ()
@property (nonatomic, strong) NSMutableArray *contextStack;
@end
@implementation EAGLPContextStack
- (instancetype)init
{
self = [super init];
if(self != nil)
{
self.contextStack = [[NSMutableArray alloc] initWithCapacity:4];
}
return self;
}
- (BOOL)pushCurrentContext:(EAGLContext *)newContext
{
EAGLContext *context = EAGLContext.currentContext;
if(context == nil)
{
context = (EAGLContext *)NSNull.null;
}
BOOL success = [EAGLContext setCurrentContext:newContext];
if(!success)
{
return NO;
}
[self.contextStack addObject:context];
return YES;
}
- (void)popCurrentContext
{
EAGLContext *context = self.contextStack.lastObject;
if(context == nil)
{
return;
}
[self.contextStack removeLastObject];
if(context == (EAGLContext *)NSNull.null)
{
context = nil;
}
[EAGLContext setCurrentContext:context];
}
@end