removed references to singletons, now uses SDL_WindowData information instead. gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Tue, 22 Jul 2008 23:03:51 +0000
branchgsoc2008_iphone
changeset 24021fe89198aba5
parent 2401 32602672020e
child 2403 e9a1eed243c9
removed references to singletons, now uses SDL_WindowData information instead.
src/video/uikit/SDL_uikitopengles.m
     1.1 --- a/src/video/uikit/SDL_uikitopengles.m	Tue Jul 22 23:02:53 2008 +0000
     1.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Tue Jul 22 23:03:51 2008 +0000
     1.3 @@ -9,14 +9,13 @@
     1.4  
     1.5  #include "SDL_uikitopengles.h"
     1.6  #include "SDL_uikitopenglview.h"
     1.7 +#include "SDL_uikitappdelegate.h"
     1.8 +#include "SDL_uikitwindow.h"
     1.9  #include "jump.h"
    1.10  #include "SDL_sysvideo.h"
    1.11  #include "SDL_loadso.h"
    1.12  #include <dlfcn.h>
    1.13  
    1.14 -extern SDL_uikitopenglview *uikitEAGLView;
    1.15 -extern UIWindow *uikitWindow;
    1.16 -
    1.17  static int UIKit_GL_Initialize(_THIS);
    1.18  
    1.19  void *
    1.20 @@ -31,7 +30,10 @@
    1.21  
    1.22  int UIKit_GL_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
    1.23  {
    1.24 -	[uikitEAGLView setCurrentContext];
    1.25 +	
    1.26 +	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    1.27 +	
    1.28 +	[data->view setCurrentContext];
    1.29      return 0;
    1.30  }
    1.31  
    1.32 @@ -50,11 +52,15 @@
    1.33  void UIKit_GL_SwapWindow(_THIS, SDL_Window * window)
    1.34  {
    1.35  
    1.36 -	[uikitEAGLView swapBuffers];
    1.37 +	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    1.38  	
    1.39 +	if (nil == data->view) {
    1.40 +		return;
    1.41 +	}
    1.42 +	[data->view swapBuffers];
    1.43  	/* since now we've got something to draw
    1.44  	   make the window visible */
    1.45 -	[uikitWindow makeKeyAndVisible];
    1.46 +	[data->uiwindow makeKeyAndVisible];
    1.47  
    1.48  	/* we need to let the event cycle run, or the OS won't update the OpenGL view! */
    1.49  	SDL_PumpEvents();
    1.50 @@ -64,27 +70,41 @@
    1.51  SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
    1.52  {
    1.53  	
    1.54 -	uikitEAGLView = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
    1.55 -						retainBacking: _this->gl_config.retained_backing \
    1.56 -						rBits: _this->gl_config.red_size \
    1.57 -						gBits: _this->gl_config.green_size \
    1.58 -						bBits: _this->gl_config.blue_size \
    1.59 -						aBits: _this->gl_config.alpha_size \
    1.60 -						depthBits: _this->gl_config.depth_size];
    1.61 +	SDL_uikitopenglview *view;
    1.62  
    1.63 -	[uikitWindow addSubview: [uikitEAGLView autorelease]];
    1.64 -	uikitEAGLView.multipleTouchEnabled = YES;
    1.65 +	SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    1.66 +	
    1.67 +	view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
    1.68 +									retainBacking: _this->gl_config.retained_backing \
    1.69 +									rBits: _this->gl_config.red_size \
    1.70 +									gBits: _this->gl_config.green_size \
    1.71 +									bBits: _this->gl_config.blue_size \
    1.72 +									aBits: _this->gl_config.alpha_size \
    1.73 +									depthBits: _this->gl_config.depth_size];
    1.74 +
    1.75 +	view.multipleTouchEnabled = YES;
    1.76 +
    1.77 +	data->view = view;
    1.78 +
    1.79 +	[data->uiwindow addSubview: view ];
    1.80 +	
    1.81 +	/* Don't worry, the window retained the view */
    1.82 +	[view release];
    1.83  	
    1.84  	if ( UIKit_GL_MakeCurrent(_this, window, NULL) < 0 ) {
    1.85 -        //Cocoa_GL_DeleteContext(_this, context);
    1.86 +        UIKit_GL_DeleteContext(_this, NULL);
    1.87          return NULL;
    1.88      }
    1.89  		
    1.90 -	return [uikitEAGLView context];
    1.91 +	return view;
    1.92  }
    1.93  
    1.94  void UIKit_GL_DeleteContext(_THIS, SDL_GLContext context)
    1.95  {
    1.96 +	/* the delegate has retained the view, this will release him */
    1.97 +	SDL_uikitopenglview *view = (SDL_uikitopenglview *)context;
    1.98 +	/* this will also delete it */
    1.99 +	[view removeFromSuperview];
   1.100  	
   1.101  	return;
   1.102  }