-
Notifications
You must be signed in to change notification settings - Fork 69
/
EAGLView.mm
76 lines (58 loc) · 1.81 KB
/
EAGLView.mm
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
/*
Copyright (C) 2015 Apple Inc. All Rights Reserved.
See LICENSE.txt for this sample’s licensing information
Abstract:
The EAGLView class is a UIView subclass that renders OpenGL scene.
*/
#import "EAGLView.h"
#include "GraphicsTypes.h"
@interface EAGLView ()
{
EAGLContext* _context;
}
@end
@implementation EAGLView
// Must return the CAEAGLLayer class so that CA allocates an EAGLLayer backing for this view
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
// The GL view is stored in the storyboard file. When it's unarchived it's sent -initWithCoder:
- (instancetype) initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
// Get the layer
CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
eaglLayer.opaque = TRUE;
eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
_context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3];
if (!_context || ![EAGLContext setCurrentContext:_context])
{
return nil;
}
[self initApp:(int)Diligent::RENDER_DEVICE_TYPE_GLES];
}
return self;
}
- (void) drawView:(id)sender
{
[EAGLContext setCurrentContext:_context];
// There is no autorelease pool when this method is called
// because it will be called from a background thread.
// It's important to create one or app can leak objects.
@autoreleasepool
{
[self render];
}
}
- (void) dealloc
{
[self terminate];
// tear down context
if ([EAGLContext currentContext] == _context)
[EAGLContext setCurrentContext:nil];
[super dealloc];
}
@end