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()
This commit is contained in:
Sam Lantinga 2014-08-06 00:28:02 -07:00
parent 2eb7563e35
commit 6299daecba

View file

@ -51,14 +51,7 @@ UIKit_GL_GetProcAddress(_THIS, const char *proc)
*/ */
int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ {
if (context) { [EAGLContext setCurrentContext: context];
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
[data->view setCurrentContext];
}
else {
[EAGLContext setCurrentContext: nil];
}
return 0; return 0;
} }
@ -146,8 +139,9 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
uiwindow.rootViewController = view->viewcontroller; uiwindow.rootViewController = view->viewcontroller;
} }
if (UIKit_GL_MakeCurrent(_this, window, view) < 0) { EAGLContext *context = view.context;
UIKit_GL_DeleteContext(_this, view); if (UIKit_GL_MakeCurrent(_this, window, context) < 0) {
UIKit_GL_DeleteContext(_this, context);
return NULL; return NULL;
} }
@ -157,13 +151,19 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
SDL_SetKeyboardFocus(window); SDL_SetKeyboardFocus(window);
} }
return view; return context;
} }
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
{ {
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 */ /* the delegate has retained the view, this will release him */
SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
if (view->viewcontroller) { if (view->viewcontroller) {
UIWindow *uiwindow = (UIWindow *)view.superview; UIWindow *uiwindow = (UIWindow *)view.superview;
if (uiwindow.rootViewController == view->viewcontroller) { if (uiwindow.rootViewController == view->viewcontroller) {
@ -173,7 +173,15 @@ void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
[view->viewcontroller release]; [view->viewcontroller release];
} }
[view removeFromSuperview]; [view removeFromSuperview];
/* FIXME: This doesn't actually call view dealloc - what is holding a reference to it? */
[view release]; [view release];
return;
}
}
/* View not found... delete the context anyway? */
[(EAGLContext *)context release];
} }
#endif /* SDL_VIDEO_DRIVER_UIKIT */ #endif /* SDL_VIDEO_DRIVER_UIKIT */