The OpenGL context returned by the UIKit backend is now an actual OpenGL context instead of the OpenGL view we created.
authorSam Lantinga <slouken@libsdl.org>
Wed, 06 Aug 2014 00:28:02 -0700
changeset 9045 c689ac0e8411
parent 9044 5716114f158e
child 9046 c3ec7c3e6c24
child 9512 c9f61d1dac7b
The OpenGL context returned by the UIKit backend is now an actual OpenGL context instead of the OpenGL view we created. This allows you to use the returned context in functions like CVOpenGLESTextureCacheCreate()
src/video/uikit/SDL_uikitopengles.m
--- a/src/video/uikit/SDL_uikitopengles.m	Tue Aug 05 21:03:02 2014 -0700
+++ b/src/video/uikit/SDL_uikitopengles.m	Wed Aug 06 00:28:02 2014 -0700
@@ -51,14 +51,7 @@
 */
 int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 {
-    if (context) {
-        SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
-        [data->view setCurrentContext];
-    }
-    else {
-        [EAGLContext setCurrentContext: nil];
-    }
-
+    [EAGLContext setCurrentContext: context];
     return 0;
 }
 
@@ -146,8 +139,9 @@
         uiwindow.rootViewController = view->viewcontroller;
     }
 
-    if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
-        UIKit_GL_DeleteContext(_this, view);
+    EAGLContext *context = view.context;
+    if (UIKit_GL_MakeCurrent(_this, window, context) < 0) {
+        UIKit_GL_DeleteContext(_this, context);
         return NULL;
     }
 
@@ -157,23 +151,37 @@
         SDL_SetKeyboardFocus(window);
     }
 
-    return view;
+    return context;
 }
 
 void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
 {
-    /* the delegate has retained the view, this will release him */
-    SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
-    if (view->viewcontroller) {
-        UIWindow *uiwindow = (UIWindow *)view.superview;
-        if (uiwindow.rootViewController == view->viewcontroller) {
-            uiwindow.rootViewController = nil;
+    SDL_Window *window;
+
+    /* Find the view associated with this context */
+    for (window = _this->windows; window; window = window->next) {
+        SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+        SDL_uikitopenglview *view = data->view;
+        if (view.context == context) {
+            /* the delegate has retained the view, this will release him */
+            if (view->viewcontroller) {
+                UIWindow *uiwindow = (UIWindow *)view.superview;
+                if (uiwindow.rootViewController == view->viewcontroller) {
+                    uiwindow.rootViewController = nil;
+                }
+                [view->viewcontroller setView:nil];
+                [view->viewcontroller release];
+            }
+            [view removeFromSuperview];
+
+            /* FIXME: This doesn't actually call view dealloc - what is holding a reference to it? */
+            [view release];
+            return;
         }
-        [view->viewcontroller setView:nil];
-        [view->viewcontroller release];
     }
-    [view removeFromSuperview];
-    [view release];
+
+    /* View not found... delete the context anyway? */
+    [(EAGLContext *)context release];
 }
 
 #endif /* SDL_VIDEO_DRIVER_UIKIT */