Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Oct 25, 2015
2 parents 8f84f41 + 8949db7 commit bd736e5
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 87 deletions.
2 changes: 2 additions & 0 deletions platform/iphone/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ - (void)applicationDidFinishLaunching:(UIApplication*)application {
view_controller.view = glView;
window.rootViewController = view_controller;

glView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink",true)) ? YES : NO;
printf("cadisaplylink: %d", glView.useCADisplayLink);
glView.animationInterval = 1.0 / kRenderingFrequency;
[glView startAnimation];

Expand Down
9 changes: 4 additions & 5 deletions platform/iphone/gl_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>

#define USE_CADISPLAYLINK 0 //iOS version 3.1+ is required

@protocol GLViewDelegate;

@interface GLView : UIView<UIKeyInput>
Expand All @@ -53,13 +51,13 @@
// 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
BOOL useCADisplayLink;
// 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.
// Only used if CADisplayLink is not
NSTimer *animationTimer;
#endif

NSTimeInterval animationInterval;

Expand Down Expand Up @@ -104,6 +102,7 @@
- (void)audioRouteChangeListenerCallback:(NSNotification*)notification;

@property NSTimeInterval animationInterval;
@property(nonatomic, assign) BOOL useCADisplayLink;

@end

Expand Down
75 changes: 38 additions & 37 deletions platform/iphone/gl_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ -(void)setDelegate:(id<GLViewDelegate>)d
delegateSetup = ![delegate respondsToSelector:@selector(setupView:)];
}

@synthesize useCADisplayLink;

// If our view is resized, we'll be asked to layout subviews.
// This is the perfect opportunity to also update the framebuffer so that it is
// the same size as our display area.

-(void)layoutSubviews
{
printf("HERE\n");
//printf("HERE\n");
[EAGLContext setCurrentContext:context];
[self destroyFramebuffer];
[self createFramebuffer];
Expand Down Expand Up @@ -418,19 +420,21 @@ - (void)startAnimation
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 (useCADisplayLink) {

// 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];
}

if (video_playing)
{
Expand All @@ -444,13 +448,16 @@ - (void)stopAnimation
return;
active = FALSE;
printf("******** stop animation!\n");
#if USE_CADISPLAYLINK
[displayLink invalidate];
displayLink = nil;
#else
[animationTimer invalidate];
animationTimer = nil;
#endif

if (useCADisplayLink) {
[displayLink invalidate];
displayLink = nil;
}
else {
[animationTimer invalidate];
animationTimer = nil;
}

clear_touches();

if (video_playing)
Expand All @@ -462,13 +469,7 @@ - (void)stopAnimation
- (void)setAnimationInterval:(NSTimeInterval)interval
{
animationInterval = interval;

#if USE_CADISPLAYLINK
if(displayLink)
#else
if(animationTimer)
#endif
{
if ( (useCADisplayLink && displayLink) || ( !useCADisplayLink && animationTimer ) ) {
[self stopAnimation];
[self startAnimation];
}
Expand All @@ -477,16 +478,16 @@ - (void)setAnimationInterval:(NSTimeInterval)interval
// Updates the OpenGL view when the timer fires
- (void)drawView
{
#if USE_CADISPLAYLINK
// Pause the CADisplayLink to avoid recursion
[displayLink setPaused: YES];
if (useCADisplayLink) {
// Pause the CADisplayLink to avoid recursion
[displayLink setPaused: YES];

// Process all input events
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);
// Process all input events
while(CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE) == kCFRunLoopRunHandledSource);

// We are good to go, resume the CADisplayLink
[displayLink setPaused: NO];
#endif
// We are good to go, resume the CADisplayLink
[displayLink setPaused: NO];
}

if (!active) {
printf("draw view not active!\n");
Expand Down Expand Up @@ -632,7 +633,7 @@ - (void)audioRouteChangeListenerCallback:(NSNotification*)notification
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
NSLog(@"AVAudioSessionRouteChangeReasonOldDeviceUnavailable");
NSLog(@"Headphone/Line was pulled. Resuming video play....");
if (_is_video_playing) {
if (_is_video_playing()) {

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[_instance.avPlayer play]; // NOTE: change this line according your current player implementation
Expand Down
1 change: 1 addition & 0 deletions platform/iphone/globals/global_defaults.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ void register_iphone_global_defaults() {
GLOBAL_DEF("rasterizer.iOS/fp16_framebuffer",false);
GLOBAL_DEF("display.iOS/driver","GLES2");
Globals::get_singleton()->set_custom_property_info("display.iOS/driver",PropertyInfo(Variant::STRING,"display.iOS/driver",PROPERTY_HINT_ENUM,"GLES1,GLES2"));
GLOBAL_DEF("display.iOS/use_cadisplaylink",true);
}
10 changes: 8 additions & 2 deletions platform/x11/context_gl_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct ContextGL_X11_Private {
::GLXContext glx_context;
};


void ContextGL_X11::release_current() {

glXMakeCurrent(x11_display, None, NULL);
Expand All @@ -56,10 +55,12 @@ void ContextGL_X11::make_current() {

glXMakeCurrent(x11_display, x11_window, p->glx_context);
}

void ContextGL_X11::swap_buffers() {

glXSwapBuffers(x11_display,x11_window);
}

/*
static GLWrapperFuncPtr wrapper_get_proc_address(const char* p_function) {
Expand Down Expand Up @@ -154,6 +155,9 @@ Error ContextGL_X11::initialize() {
*/
//glXMakeCurrent(x11_display, None, NULL);

XFree( vi );
XFree( fbc );

return OK;
}

Expand All @@ -164,12 +168,12 @@ int ContextGL_X11::get_window_width() {

return xwa.width;
}

int ContextGL_X11::get_window_height() {
XWindowAttributes xwa;
XGetWindowAttributes(x11_display,x11_window,&xwa);

return xwa.height;

}


Expand All @@ -189,6 +193,8 @@ ContextGL_X11::ContextGL_X11(::Display *p_x11_display,::Window &p_x11_window,con


ContextGL_X11::~ContextGL_X11() {
release_current();
glXDestroyContext( x11_display, p->glx_context );

memdelete( p );
}
Expand Down
Loading

0 comments on commit bd736e5

Please sign in to comment.