|
1 /* |
|
2 SDL - Simple DirectMedia Layer |
|
3 Copyright (C) 1997-2009 Sam Lantinga |
|
4 |
|
5 This library is free software; you can redistribute it and/or |
|
6 modify it under the terms of the GNU Lesser General Public |
|
7 License as published by the Free Software Foundation; either |
|
8 version 2.1 of the License, or (at your option) any later version. |
|
9 |
|
10 This library is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 Lesser General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU Lesser General Public |
|
16 License along with this library; if not, write to the Free Software |
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
18 |
|
19 Sam Lantinga |
|
20 slouken@libsdl.org |
|
21 */ |
|
22 |
|
23 #include "SDL_uikitopengles.h" |
|
24 #include "SDL_uikitopenglview.h" |
|
25 #include "SDL_uikitappdelegate.h" |
|
26 #include "SDL_uikitwindow.h" |
|
27 #include "jumphack.h" |
|
28 #include "SDL_sysvideo.h" |
|
29 #include "SDL_loadso.h" |
|
30 #include <dlfcn.h> |
|
31 |
|
32 static int UIKit_GL_Initialize(_THIS); |
|
33 |
|
34 void * |
|
35 UIKit_GL_GetProcAddress(_THIS, const char *proc) |
|
36 { |
|
37 /* Look through all SO's for the proc symbol. Here's why: |
|
38 -Looking for the path to the OpenGL Library seems not to work in the iPhone Simulator. |
|
39 -We don't know that the path won't change in the future. |
|
40 */ |
|
41 return SDL_LoadFunction(RTLD_DEFAULT, proc); |
|
42 } |
|
43 |
|
44 /* |
|
45 note that SDL_GL_Delete context makes it current without passing the window |
|
46 */ |
|
47 int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) |
|
48 { |
|
49 |
|
50 if (context) { |
|
51 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
52 [data->view setCurrentContext]; |
|
53 } |
|
54 else { |
|
55 [EAGLContext setCurrentContext: nil]; |
|
56 } |
|
57 |
|
58 return 0; |
|
59 } |
|
60 |
|
61 int |
|
62 UIKit_GL_LoadLibrary(_THIS, const char *path) |
|
63 { |
|
64 /* |
|
65 shouldn't be passing a path into this function |
|
66 why? Because we've already loaded the library |
|
67 and because the SDK forbids loading an external SO |
|
68 */ |
|
69 if (path != NULL) { |
|
70 SDL_SetError("iPhone GL Load Library just here for compatibility"); |
|
71 return -1; |
|
72 } |
|
73 return 0; |
|
74 } |
|
75 |
|
76 |
|
77 void UIKit_GL_SwapWindow(_THIS, SDL_Window * window) |
|
78 { |
|
79 |
|
80 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
81 |
|
82 if (nil == data->view) { |
|
83 return; |
|
84 } |
|
85 [data->view swapBuffers]; |
|
86 /* since now we've got something to draw |
|
87 make the window visible */ |
|
88 [data->uiwindow makeKeyAndVisible]; |
|
89 |
|
90 /* we need to let the event cycle run, or the OS won't update the OpenGL view! */ |
|
91 SDL_PumpEvents(); |
|
92 |
|
93 } |
|
94 |
|
95 SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window) |
|
96 { |
|
97 |
|
98 SDL_uikitopenglview *view; |
|
99 |
|
100 SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
101 |
|
102 /* construct our view, passing in SDL's OpenGL configuration data */ |
|
103 view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \ |
|
104 retainBacking: _this->gl_config.retained_backing \ |
|
105 rBits: _this->gl_config.red_size \ |
|
106 gBits: _this->gl_config.green_size \ |
|
107 bBits: _this->gl_config.blue_size \ |
|
108 aBits: _this->gl_config.alpha_size \ |
|
109 depthBits: _this->gl_config.depth_size]; |
|
110 |
|
111 // add a tag to be able to remove from superview once finished |
|
112 view.tag = 54867; |
|
113 data->view = view; |
|
114 |
|
115 /* add the view to our window */ |
|
116 [data->uiwindow addSubview: view ]; |
|
117 |
|
118 /* Don't worry, the window retained the view */ |
|
119 [view release]; |
|
120 |
|
121 if ( UIKit_GL_MakeCurrent(_this, window, view) < 0 ) { |
|
122 UIKit_GL_DeleteContext(_this, view); |
|
123 return NULL; |
|
124 } |
|
125 |
|
126 return view; |
|
127 } |
|
128 |
|
129 void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) |
|
130 { |
|
131 /* the delegate has retained the view, this will release him */ |
|
132 SDL_uikitopenglview *view = (SDL_uikitopenglview *)context; |
|
133 /* this will also delete it */ |
|
134 [view removeFromSuperview]; |
|
135 |
|
136 return; |
|
137 } |
|
138 |
|
139 |