zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_uikitopengles.m
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22 
23 #if SDL_VIDEO_DRIVER_UIKIT
24 
25 #include "SDL_uikitopengles.h"
26 #include "SDL_uikitopenglview.h"
27 #include "SDL_uikitappdelegate.h"
28 #include "SDL_uikitmodes.h"
29 #include "SDL_uikitwindow.h"
30 #include "../SDL_sysvideo.h"
31 #include "../../events/SDL_keyboard_c.h"
32 #include "../../events/SDL_mouse_c.h"
33 #include "../../power/uikit/SDL_syspower.h"
34 #include "SDL_loadso.h"
35 #include <dlfcn.h>
36 
37 static int UIKit_GL_Initialize(_THIS);
38 
39 void *
40 UIKit_GL_GetProcAddress(_THIS, const char *proc)
41 {
42  /* Look through all SO's for the proc symbol. Here's why:
43  -Looking for the path to the OpenGL Library seems not to work in the iPhone Simulator.
44  -We don't know that the path won't change in the future.
45  */
46  return dlsym(RTLD_DEFAULT, proc);
47 }
48 
49 /*
50  note that SDL_GL_Delete context makes it current without passing the window
51 */
53 {
54  if (context) {
56  [data->view setCurrentContext];
57  }
58  else {
59  [EAGLContext setCurrentContext: nil];
60  }
61 
62  return 0;
63 }
64 
65 int
66 UIKit_GL_LoadLibrary(_THIS, const char *path)
67 {
68  /*
69  shouldn't be passing a path into this function
70  why? Because we've already loaded the library
71  and because the SDK forbids loading an external SO
72  */
73  if (path != NULL) {
74  return SDL_SetError("iPhone GL Load Library just here for compatibility");
75  }
76  return 0;
77 }
78 
79 void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
80 {
81 #if SDL_POWER_UIKIT
82  /* Check once a frame to see if we should turn off the battery monitor. */
83  SDL_UIKit_UpdateBatteryMonitoring();
84 #endif
85 
87 
88  if (nil == data->view) {
89  return;
90  }
91  [data->view swapBuffers];
92 
93  /* You need to pump events in order for the OS to make changes visible.
94  We don't pump events here because we don't want iOS application events
95  (low memory, terminate, etc.) to happen inside low level rendering.
96  */
97 }
98 
100 {
101  SDL_uikitopenglview *view;
102  SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
104  SDL_DisplayData *displaydata = display->driverdata;
105  SDL_DisplayModeData *displaymodedata = display->current_mode.driverdata;
106  UIWindow *uiwindow = data->uiwindow;
107  EAGLSharegroup *share_group = nil;
108 
111  share_group = [view.context sharegroup];
112  }
113 
114  /* construct our view, passing in SDL's OpenGL configuration data */
115  CGRect frame;
117  frame = [displaydata->uiscreen bounds];
118  } else {
119  frame = [displaydata->uiscreen applicationFrame];
120  }
121  view = [[SDL_uikitopenglview alloc] initWithFrame: frame
122  scale: displaymodedata->scale
123  retainBacking: _this->gl_config.retained_backing
124  rBits: _this->gl_config.red_size
125  gBits: _this->gl_config.green_size
126  bBits: _this->gl_config.blue_size
127  aBits: _this->gl_config.alpha_size
128  depthBits: _this->gl_config.depth_size
129  stencilBits: _this->gl_config.stencil_size
130  majorVersion: _this->gl_config.major_version
131  shareGroup: share_group];
132  if (!view) {
133  return NULL;
134  }
135 
136  data->view = view;
137  view->viewcontroller = data->viewcontroller;
138  if (view->viewcontroller != nil) {
139  [view->viewcontroller setView:view];
140  [view->viewcontroller retain];
141  }
142  [uiwindow addSubview: view];
143 
144  /* The view controller needs to be the root in order to control rotation on iOS 6.0 */
145  if (uiwindow.rootViewController == nil) {
146  uiwindow.rootViewController = view->viewcontroller;
147  }
148 
149  if (UIKit_GL_MakeCurrent(_this, window, view) < 0) {
151  return NULL;
152  }
153 
154  /* Make this window the current mouse focus for touch input */
155  if (displaydata->uiscreen == [UIScreen mainScreen]) {
156  SDL_SetMouseFocus(window);
157  SDL_SetKeyboardFocus(window);
158  }
159 
160  return view;
161 }
162 
164 {
165  /* the delegate has retained the view, this will release him */
166  SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
167  if (view->viewcontroller) {
168  UIWindow *uiwindow = (UIWindow *)view.superview;
169  if (uiwindow.rootViewController == view->viewcontroller) {
170  uiwindow.rootViewController = nil;
171  }
172  [view->viewcontroller setView:nil];
173  [view->viewcontroller release];
174  }
175  [view removeFromSuperview];
176  [view release];
177 }
178 
179 #endif /* SDL_VIDEO_DRIVER_UIKIT */
180 
181 /* vi: set ts=4 sw=4 expandtab: */
SDL_uikitviewcontroller * viewcontroller
Definition: SDL_uikitview.h:51
void SDL_SetKeyboardFocus(SDL_Window *window)
Definition: SDL_keyboard.c:611
#define NULL
Definition: ftobjs.h:61
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
SDL_uikitviewcontroller * viewcontroller
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:161
void SDL_SetMouseFocus(SDL_Window *window)
Definition: SDL_mouse.c:93
char * display
Definition: visualinfo.c:85
if(!yyg->yy_init)
int UIKit_GL_LoadLibrary(_THIS, const char *path)
GLsizei const GLchar *const * path
Definition: glew.h:5828
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
UIScreen * uiscreen
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
#define _THIS
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
UIWindow * uiwindow
void UIKit_GL_SwapWindow(_THIS, SDL_Window *window)
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window *window)
int share_with_current_context
Definition: SDL_sysvideo.h:295
void * UIKit_GL_GetProcAddress(_THIS, const char *proc)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
Definition: SDL_video.c:996
void * driverdata
Definition: SDL_sysvideo.h:99
TParseContext * context
Uint32 flags
Definition: SDL_sysvideo.h:81
struct SDL_VideoDevice::@87 gl_config
int UIKit_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
Get the currently active OpenGL context.
Definition: SDL_video.c:2822
SDL_uikitopenglview * view