daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Jan 19th, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. frameRenderingQueue = dispatch_queue_create("com.mycompany.crw", DISPATCH_QUEUE_SERIAL);
  2. frameRenderingSemaphore = dispatch_semaphore_create(1);
  3.    
  4. CADisplayLink *dl = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(renderFrame)];
  5. [dl addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
  6.    
  7. - (void)renderFrame {
  8.     if (dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_NOW) != 0) {
  9.         NSLog(@"return"); // Gets called ALWAYS!
  10.         return;
  11.     }
  12.  
  13.     dispatch_async(drawingQueue, ^{
  14.         @autoreleasepool {
  15.  
  16.             // OpenGL ES drawing code
  17.  
  18.             dispatch_semaphore_signal(frameRenderingSemaphore);
  19.         }
  20.     });
  21. }
  22.    
  23. - (void)renderFrame {
  24.     dispatch_async(drawingQueue, ^{
  25.         if (dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_NOW) != 0) {
  26.             return;
  27.         }
  28.  
  29.         @autoreleasepool {
  30.             // Drawing code...
  31.         }
  32.  
  33.         dispatch_semaphore_signal(frameRenderingSemaphore);
  34.     });
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top