summaryrefslogtreecommitdiff
path: root/platform/iphone
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-03-03 14:41:36 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-03-03 14:41:36 -0300
commit2c2894ceb674927a35d2798b3e63adabdb020077 (patch)
tree9e8950e0acc8fb7531fa60ce8c0321a5b60c335a /platform/iphone
parent4d2198110b4af7f203eeef95697255569e49bce7 (diff)
parenta0ee5cc3531786a652ee43d3a57cb69dff34bd70 (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Conflicts: modules/gdscript/gd_tokenizer.cpp scene/resources/shader_graph.h
Diffstat (limited to 'platform/iphone')
-rw-r--r--platform/iphone/app_delegate.mm19
-rwxr-xr-xplatform/iphone/gl_view.h8
-rwxr-xr-xplatform/iphone/gl_view.mm32
3 files changed, 52 insertions, 7 deletions
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index 6ca54286ba..fe11b672ac 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -84,13 +84,11 @@ static int frame_count = 0;
switch (frame_count) {
case 0: {
-
- int backingWidth;
- int backingHeight;
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
- glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
-
- iphone_main(backingWidth, backingHeight, gargc, gargv);
+ int backingWidth;
+ int backingHeight;
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+
OS::VideoMode vm;
vm.fullscreen = true;
@@ -198,6 +196,13 @@ static int frame_count = 0;
//glView.autoresizesSubviews = YES;
//[glView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
+ int backingWidth;
+ int backingHeight;
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
+ glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);
+
+ iphone_main(backingWidth, backingHeight, gargc, gargv);
+
view_controller = [[ViewController alloc] init];
view_controller.view = glView;
window.rootViewController = view_controller;
diff --git a/platform/iphone/gl_view.h b/platform/iphone/gl_view.h
index 8eb96e7e98..04334991fd 100755
--- a/platform/iphone/gl_view.h
+++ b/platform/iphone/gl_view.h
@@ -34,6 +34,8 @@
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
+#define USE_CADISPLAYLINK 1 //iOS version 3.1+ is required
+
@protocol GLViewDelegate;
@interface GLView : UIView<UIKeyInput>
@@ -51,8 +53,14 @@
// OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist)
GLuint depthRenderbuffer;
+#if USE_CADISPLAYLINK
+ // CADisplayLink available on 3.1+ synchronizes the animation timer & drawing with the refresh rate of the display, only supports animation intervals of 1/60 1/30 & 1/15
+ CADisplayLink *displayLink;
+#else
// An animation timer that, when animation is started, will periodically call -drawView at the given rate.
NSTimer *animationTimer;
+#endif
+
NSTimeInterval animationInterval;
// Delegate to do our drawing, called by -drawView, which can be called manually or via the animation timer.
diff --git a/platform/iphone/gl_view.mm b/platform/iphone/gl_view.mm
index 7d33c11315..3d6c48ffaf 100755
--- a/platform/iphone/gl_view.mm
+++ b/platform/iphone/gl_view.mm
@@ -415,7 +415,19 @@ static void clear_touches() {
return;
active = TRUE;
printf("start animation!\n");
+#if USE_CADISPLAYLINK
+ // Approximate frame rate
+ // assumes device refreshes at 60 fps
+ int frameInterval = (int) floor(animationInterval * 60.0f);
+
+ displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
+ [displayLink setFrameInterval:frameInterval];
+
+ // Setup DisplayLink in main thread
+ [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+#else
animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
+#endif
if (video_playing)
{
@@ -429,8 +441,13 @@ static void clear_touches() {
return;
active = FALSE;
printf("******** stop animation!\n");
+#if USE_CADISPLAYLINK
+ [displayLink invalidate];
+ displayLink = nil;
+#else
[animationTimer invalidate];
animationTimer = nil;
+#endif
clear_touches();
if (video_playing)
@@ -443,7 +460,11 @@ static void clear_touches() {
{
animationInterval = interval;
+#if USE_CADISPLAYLINK
+ if(displayLink)
+#else
if(animationTimer)
+#endif
{
[self stopAnimation];
[self startAnimation];
@@ -453,6 +474,17 @@ static void clear_touches() {
// Updates the OpenGL view when the timer fires
- (void)drawView
{
+#if USE_CADISPLAYLINK
+ // Pause the CADisplayLink to avoid recursion
+ [displayLink setPaused: YES];
+
+ // Process all input events
+ while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
+
+ // We are good to go, resume the CADisplayLink
+ [displayLink setPaused: NO];
+#endif
+
if (!active) {
printf("draw view not active!\n");
return;