Mercurial > sdl-ios-xcode
comparison src/video/uikit/SDL_uikitopengles.m @ 2765:f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Bring SDL to iPhone and iPod Touch
by Holmes Futrell, mentored by Sam Lantinga
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 04 Oct 2008 06:46:59 +0000 |
parents | |
children | 99210400e8b9 |
comparison
equal
deleted
inserted
replaced
2764:4868c0df2e83 | 2765:f55c87ae336b |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997-2006 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 data->view = view; | |
112 | |
113 /* add the view to our window */ | |
114 [data->uiwindow addSubview: view ]; | |
115 | |
116 /* Don't worry, the window retained the view */ | |
117 [view release]; | |
118 | |
119 if ( UIKit_GL_MakeCurrent(_this, window, view) < 0 ) { | |
120 UIKit_GL_DeleteContext(_this, view); | |
121 return NULL; | |
122 } | |
123 | |
124 return view; | |
125 } | |
126 | |
127 void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) | |
128 { | |
129 /* the delegate has retained the view, this will release him */ | |
130 SDL_uikitopenglview *view = (SDL_uikitopenglview *)context; | |
131 /* this will also delete it */ | |
132 [view removeFromSuperview]; | |
133 | |
134 return; | |
135 } | |
136 | |
137 |