comparison src/video/uikit/SDL_uikitopengles.m @ 2402:1fe89198aba5 gsoc2008_iphone

removed references to singletons, now uses SDL_WindowData information instead.
author Holmes Futrell <hfutrell@umail.ucsb.edu>
date Tue, 22 Jul 2008 23:03:51 +0000
parents eb828d6c3efb
children e9a1eed243c9
comparison
equal deleted inserted replaced
2401:32602672020e 2402:1fe89198aba5
7 * 7 *
8 */ 8 */
9 9
10 #include "SDL_uikitopengles.h" 10 #include "SDL_uikitopengles.h"
11 #include "SDL_uikitopenglview.h" 11 #include "SDL_uikitopenglview.h"
12 #include "SDL_uikitappdelegate.h"
13 #include "SDL_uikitwindow.h"
12 #include "jump.h" 14 #include "jump.h"
13 #include "SDL_sysvideo.h" 15 #include "SDL_sysvideo.h"
14 #include "SDL_loadso.h" 16 #include "SDL_loadso.h"
15 #include <dlfcn.h> 17 #include <dlfcn.h>
16
17 extern SDL_uikitopenglview *uikitEAGLView;
18 extern UIWindow *uikitWindow;
19 18
20 static int UIKit_GL_Initialize(_THIS); 19 static int UIKit_GL_Initialize(_THIS);
21 20
22 void * 21 void *
23 UIKit_GL_GetProcAddress(_THIS, const char *proc) 22 UIKit_GL_GetProcAddress(_THIS, const char *proc)
29 return SDL_LoadFunction(RTLD_DEFAULT, proc); 28 return SDL_LoadFunction(RTLD_DEFAULT, proc);
30 } 29 }
31 30
32 int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) 31 int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
33 { 32 {
34 [uikitEAGLView setCurrentContext]; 33
34 SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
35
36 [data->view setCurrentContext];
35 return 0; 37 return 0;
36 } 38 }
37 39
38 int 40 int
39 UIKit_GL_LoadLibrary(_THIS, const char *path) 41 UIKit_GL_LoadLibrary(_THIS, const char *path)
48 50
49 51
50 void UIKit_GL_SwapWindow(_THIS, SDL_Window * window) 52 void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
51 { 53 {
52 54
53 [uikitEAGLView swapBuffers]; 55 SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
54 56
57 if (nil == data->view) {
58 return;
59 }
60 [data->view swapBuffers];
55 /* since now we've got something to draw 61 /* since now we've got something to draw
56 make the window visible */ 62 make the window visible */
57 [uikitWindow makeKeyAndVisible]; 63 [data->uiwindow makeKeyAndVisible];
58 64
59 /* we need to let the event cycle run, or the OS won't update the OpenGL view! */ 65 /* we need to let the event cycle run, or the OS won't update the OpenGL view! */
60 SDL_PumpEvents(); 66 SDL_PumpEvents();
61 67
62 } 68 }
63 69
64 SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window) 70 SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
65 { 71 {
66 72
67 uikitEAGLView = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \ 73 SDL_uikitopenglview *view;
68 retainBacking: _this->gl_config.retained_backing \
69 rBits: _this->gl_config.red_size \
70 gBits: _this->gl_config.green_size \
71 bBits: _this->gl_config.blue_size \
72 aBits: _this->gl_config.alpha_size \
73 depthBits: _this->gl_config.depth_size];
74 74
75 [uikitWindow addSubview: [uikitEAGLView autorelease]]; 75 SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
76 uikitEAGLView.multipleTouchEnabled = YES; 76
77 view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
78 retainBacking: _this->gl_config.retained_backing \
79 rBits: _this->gl_config.red_size \
80 gBits: _this->gl_config.green_size \
81 bBits: _this->gl_config.blue_size \
82 aBits: _this->gl_config.alpha_size \
83 depthBits: _this->gl_config.depth_size];
84
85 view.multipleTouchEnabled = YES;
86
87 data->view = view;
88
89 [data->uiwindow addSubview: view ];
90
91 /* Don't worry, the window retained the view */
92 [view release];
77 93
78 if ( UIKit_GL_MakeCurrent(_this, window, NULL) < 0 ) { 94 if ( UIKit_GL_MakeCurrent(_this, window, NULL) < 0 ) {
79 //Cocoa_GL_DeleteContext(_this, context); 95 UIKit_GL_DeleteContext(_this, NULL);
80 return NULL; 96 return NULL;
81 } 97 }
82 98
83 return [uikitEAGLView context]; 99 return view;
84 } 100 }
85 101
86 void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context) 102 void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
87 { 103 {
104 /* the delegate has retained the view, this will release him */
105 SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
106 /* this will also delete it */
107 [view removeFromSuperview];
88 108
89 return; 109 return;
90 } 110 }
91 111
92 112