2723
|
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 |
/* Look through all SO's for the proc symbol. Here's why:
|
|
37 |
-Looking for the path to the OpenGL Library seems not to work in the iPhone Simulator.
|
|
38 |
-We don't know that the path won't change in the future.
|
|
39 |
*/
|
|
40 |
return SDL_LoadFunction(RTLD_DEFAULT, proc);
|
|
41 |
}
|
|
42 |
|
|
43 |
/*
|
|
44 |
note that SDL_GL_Delete context makes it current without passing the window
|
|
45 |
*/
|
|
46 |
int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) {
|
|
47 |
|
|
48 |
if (context) {
|
|
49 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
|
50 |
[data->view setCurrentContext];
|
|
51 |
}
|
|
52 |
else {
|
|
53 |
[EAGLContext setCurrentContext: nil];
|
|
54 |
}
|
|
55 |
|
|
56 |
return 0;
|
|
57 |
}
|
|
58 |
|
|
59 |
int UIKit_GL_LoadLibrary(_THIS, const char *path) {
|
|
60 |
/*
|
|
61 |
shouldn't be passing a path into this function
|
|
62 |
why? Because we've already loaded the library
|
|
63 |
and because the SDK forbids loading an external SO
|
|
64 |
*/
|
|
65 |
if (path != NULL) {
|
|
66 |
SDL_SetError("iPhone GL Load Library just here for compatibility");
|
|
67 |
return -1;
|
|
68 |
}
|
|
69 |
return 0;
|
|
70 |
}
|
|
71 |
|
|
72 |
void UIKit_GL_SwapWindow(_THIS, SDL_Window * window) {
|
|
73 |
|
|
74 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
|
75 |
|
|
76 |
if (nil == data->view) {
|
|
77 |
return;
|
|
78 |
}
|
|
79 |
[data->view swapBuffers];
|
|
80 |
/* since now we've got something to draw
|
|
81 |
make the window visible */
|
|
82 |
[data->uiwindow makeKeyAndVisible];
|
|
83 |
|
|
84 |
/* we need to let the event cycle run, or the OS won't update the OpenGL view! */
|
|
85 |
SDL_PumpEvents();
|
|
86 |
|
|
87 |
}
|
|
88 |
|
|
89 |
SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window) {
|
|
90 |
|
|
91 |
SDL_uikitopenglview *view;
|
|
92 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
|
|
93 |
|
|
94 |
/* construct our view, passing in SDL's OpenGL configuration data */
|
|
95 |
view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
|
|
96 |
retainBacking: _this->gl_config.retained_backing \
|
|
97 |
rBits: _this->gl_config.red_size \
|
|
98 |
gBits: _this->gl_config.green_size \
|
|
99 |
bBits: _this->gl_config.blue_size \
|
|
100 |
aBits: _this->gl_config.alpha_size \
|
|
101 |
depthBits: _this->gl_config.depth_size ];
|
|
102 |
|
|
103 |
data->view = view;
|
|
104 |
view.tag = 54321;
|
|
105 |
// rotate view
|
|
106 |
[view setTransform:CGAffineTransformMakeRotation(M_PI/2.0f)];
|
|
107 |
/* add the view to our window */
|
|
108 |
[data->uiwindow addSubview: view];
|
|
109 |
|
|
110 |
/* Don't worry, the window retained the view */
|
|
111 |
[view release];
|
|
112 |
|
|
113 |
if ( UIKit_GL_MakeCurrent(_this, window, view) < 0 ) {
|
|
114 |
UIKit_GL_DeleteContext(_this, view);
|
|
115 |
return NULL;
|
|
116 |
}
|
|
117 |
|
|
118 |
return view;
|
|
119 |
}
|
|
120 |
|
|
121 |
void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) {
|
|
122 |
/* the delegate has retained the view, this will release him */
|
|
123 |
SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
|
|
124 |
/* this will also delete it */
|
|
125 |
[view removeFromSuperview];
|
|
126 |
|
|
127 |
return;
|
|
128 |
}
|