| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Go Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 // +build darwin | |
| 6 | |
| 7 #include "_cgo_export.h" | |
| 8 #include <pthread.h> | |
| 9 #include <stdio.h> | |
| 10 #include <sys/utsname.h> | |
| 11 | |
| 12 #import <UIKit/UIKit.h> | |
| 13 #import <GLKit/GLKit.h> | |
| 14 | |
| 15 struct utsname sysInfo; | |
| 16 | |
| 17 @interface AppController : GLKViewController | |
| 18 @end | |
| 19 | |
| 20 @interface AppDelegate : UIResponder<UIApplicationDelegate> | |
| 21 @property (strong, nonatomic) UIWindow *window; | |
| 22 @property (strong, nonatomic) AppController *controller; | |
| 23 @end | |
| 24 | |
| 25 @implementation AppDelegate | |
| 26 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
NSDictionary *)launchOptions { | |
| 27 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bou
nds]]; | |
| 28 self.controller = [[AppController alloc] initWithNibName:nil bundle:nil]
; | |
| 29 self.window.rootViewController = self.controller; | |
| 30 [self.window makeKeyAndVisible]; | |
| 31 return YES; | |
| 32 } | |
| 33 @end | |
| 34 | |
| 35 @interface AppController () | |
| 36 @property (strong, nonatomic) EAGLContext *context; | |
| 37 @end | |
| 38 | |
| 39 @implementation AppController | |
| 40 - (void)viewDidLoad { | |
| 41 [super viewDidLoad]; | |
| 42 self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLE
S2]; | |
| 43 GLKView *view = (GLKView *)self.view; | |
| 44 view.context = self.context; | |
| 45 view.drawableDepthFormat = GLKViewDrawableDepthFormat24; | |
| 46 | |
| 47 // TODO(crawshaw): set correct geometry. | |
| 48 //CGRect bounds = view.bounds; | |
| 49 //view.contentScaleFactor; | |
| 50 setGeom(300, 300); | |
| 51 } | |
| 52 - (void)update { | |
| 53 NSLog(@"AppController update"); | |
| 54 drawgl((GoUintptr)self.context); | |
| 55 } | |
| 56 @end | |
| 57 | |
| 58 void runApp(void) { | |
| 59 @autoreleasepool { | |
| 60 UIApplicationMain(0, nil, nil, NSStringFromClass([AppDelegate cl
ass])); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void setContext(void* context) { | |
| 65 EAGLContext* ctx = (EAGLContext*)context; | |
| 66 if (![EAGLContext setCurrentContext:ctx]) { | |
| 67 // TODO(crawshaw): determine how terrible this is. Exit? | |
| 68 NSLog(@"failed to set current context"); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 uint64_t threadID() { | |
| 73 uint64_t id; | |
| 74 if (pthread_threadid_np(pthread_self(), &id)) { | |
| 75 abort(); | |
| 76 } | |
| 77 return id; | |
| 78 } | |
| OLD | NEW |