sgl

diff src/wsys_ios.m @ 37:b3374e30361c

xcode project for uikit version, untested
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 27 Jun 2012 05:15:50 +0300
parents af9d2e895594
children e1a27aa24956
line diff
     1.1 --- a/src/wsys_ios.m	Fri Feb 24 08:49:29 2012 +0200
     1.2 +++ b/src/wsys_ios.m	Wed Jun 27 05:15:50 2012 +0300
     1.3 @@ -1,9 +1,10 @@
     1.4  #include <assert.h>
     1.5  #import <UIKit/UIKit.h>
     1.6 +#import <QuartzCore/QuartzCore.h>
     1.7  #include <OpenGLES/ES2/gl.h>
     1.8  #include <OpenGLES/ES2/glext.h>
     1.9  
    1.10 -@interface GLView : UIView {
    1.11 +@interface SGLView : UIView {
    1.12  @private
    1.13  	BOOL active;
    1.14  	BOOL use_disp_link;
    1.15 @@ -14,22 +15,28 @@
    1.16  	unsigned int fbo, rbuf_color, rbuf_depth;
    1.17  }
    1.18  
    1.19 +@property (readonly, nonatomic, getter=isAnimating) BOOL active;
    1.20 +@property (nonatomic) NSInteger frame_interval;
    1.21 +
    1.22  -(void)start_anim;
    1.23  -(void)stop_anim;
    1.24 --(void)draw: (id)sender;
    1.25 +-(void)drawView: (id)sender;
    1.26  @end
    1.27  
    1.28  @interface SGLDelegate : NSObject <UIApplicationDelegate> {
    1.29  	UIWindow *win;
    1.30 -	GLView *view;
    1.31 +	SGLView *view;
    1.32  }
    1.33 +
    1.34 +@property (nonatomic, retain) IBOutlet UIWindow *win;
    1.35 +@property (nonatomic, retain) IBOutlet SGLView *view;
    1.36  @end
    1.37  
    1.38  
    1.39  
    1.40 -@implementation GLView
    1.41 +@implementation SGLView
    1.42  
    1.43 -@synthesize animating;
    1.44 +@synthesize active;
    1.45  @dynamic frame_interval;
    1.46  
    1.47  +(Class)layerClass
    1.48 @@ -72,7 +79,7 @@
    1.49  		glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth);
    1.50  		assert(glGetError() == GL_NO_ERROR);
    1.51  
    1.52 -		animating = FALSE;
    1.53 +		active = FALSE;
    1.54  		use_disp_link = FALSE;
    1.55  		frame_interval = 1;
    1.56  		disp_link = nil;
    1.57 @@ -82,7 +89,7 @@
    1.58  		// class is used as fallback when it isn't available.
    1.59  		NSString *req_ver = @"3.1";
    1.60  		NSString *cur_ver = [[UIDevice currentDevice] systemVersion];
    1.61 -		if([curr_ver compare: req_ver options: NSNumericSearch] != NSOrderedAscending) {
    1.62 +		if([cur_ver compare: req_ver options: NSNumericSearch] != NSOrderedAscending) {
    1.63  			use_disp_link = TRUE;
    1.64  		}
    1.65  
    1.66 @@ -122,13 +129,13 @@
    1.67  
    1.68  		if(active)
    1.69  		{
    1.70 -			[self stopAnimation];
    1.71 -			[self startAnimation];
    1.72 +			[self stop_anim];
    1.73 +			[self start_anim];
    1.74  		}
    1.75  	}
    1.76  }
    1.77  
    1.78 --(void)startAnimation
    1.79 +-(void)start_anim
    1.80  {
    1.81  	if(!active) {
    1.82  		if(use_disp_link) {
    1.83 @@ -138,8 +145,8 @@
    1.84  
    1.85  			disp_link = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget: self
    1.86  				selector: @selector(drawView:)];
    1.87 -			[displayLink setFrameInterval: frame_interval];
    1.88 -			[displayLink addToRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
    1.89 +			[disp_link setFrameInterval: frame_interval];
    1.90 +			[disp_link addToRunLoop: [NSRunLoop currentRunLoop] forMode: NSDefaultRunLoopMode];
    1.91  		} else {
    1.92  			anim_timer = [NSTimer scheduledTimerWithTimeInterval: (NSTimeInterval)((1.0 / 60.0) * frame_interval)
    1.93  				target: self selector: @selector(drawView:) userInfo: nil
    1.94 @@ -150,7 +157,7 @@
    1.95  	}
    1.96  }
    1.97  
    1.98 -- (void)stopAnimation
    1.99 +- (void)stop_anim
   1.100  {
   1.101  	if(active) {
   1.102  		if(use_disp_link) {
   1.103 @@ -179,23 +186,23 @@
   1.104  
   1.105  -(BOOL)application: (UIApplication*)app didFinishLaunchingWithOptions: (NSDictionary*)opt
   1.106  {
   1.107 -	[view startAnimation];
   1.108 +	[view start_anim];
   1.109  	return YES;
   1.110  }
   1.111  
   1.112  -(void)applicationWillResignActive: (UIApplication*)app
   1.113  {
   1.114 -	[view stopAnimation];
   1.115 +	[view stop_anim];
   1.116  }
   1.117  
   1.118  -(void)applicationDidBecomeActive: (UIApplication*)app
   1.119  {
   1.120 -	[view startAnimation];
   1.121 +	[view start_anim];
   1.122  }
   1.123  
   1.124  -(void)applicationWillTerminate: (UIApplication*)app
   1.125  {
   1.126 -	[view stopAnimation];
   1.127 +	[view stop_anim];
   1.128  }
   1.129  
   1.130  -(void)dealloc