Added support for OpenGL ES and UIKit Video Driver: gsoc2008_iphone
authorHolmes Futrell <hfutrell@umail.ucsb.edu>
Thu, 17 Jul 2008 23:07:58 +0000
branchgsoc2008_iphone
changeset 2357ad4a291c85ab
parent 2356 5c27688b08cf
child 2358 da266ae53b98
Added support for OpenGL ES and UIKit Video Driver:
- included SDL_renderer_gles.h
- added UIKit Video driver bootstrap declaration
- added property "retained_backing" to gl_config structure. Having retained backing means your video buffers can't be overwritten by other applications between drawing frames. By default, this is enabled. I wanted to give the option to disable this on iPhone because it increases performance greatly.
- modified SDL_GetAttribute and SDL_SetAttribute function for OpenGL ES support. OpenGL ES does not have support for accumulation buffers, and is always double buffered, among other things.
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Thu Jul 17 22:50:39 2008 +0000
     1.2 +++ b/src/video/SDL_video.c	Thu Jul 17 23:07:58 2008 +0000
     1.3 @@ -27,11 +27,19 @@
     1.4  #include "SDL_sysvideo.h"
     1.5  #include "SDL_blit.h"
     1.6  #include "SDL_pixels_c.h"
     1.7 -#include "SDL_renderer_gl.h"
     1.8 +
     1.9 +
    1.10 +#include "glrenderer/SDL_renderer_gl.h"
    1.11 +#include "glesrenderer/SDL_renderer_gles.h"
    1.12 +
    1.13  #include "SDL_renderer_sw.h"
    1.14  #include "../events/SDL_sysevents.h"
    1.15  #include "../events/SDL_events_c.h"
    1.16  
    1.17 +#if SDL_VIDEO_OPENGL_ES
    1.18 +#include "SDL_opengles.h"
    1.19 +#endif /* SDL_VIDEO_OPENGL_ES */
    1.20 +
    1.21  #if SDL_VIDEO_OPENGL
    1.22  #include "SDL_opengl.h"
    1.23  
    1.24 @@ -103,6 +111,9 @@
    1.25  #if SDL_VIDEO_DRIVER_OS2FS
    1.26      &OS2FSLib_bootstrap,
    1.27  #endif
    1.28 +#if SDL_VIDEO_DRIVER_UIKIT
    1.29 +	&UIKIT_bootstrap,
    1.30 +#endif
    1.31  #if SDL_VIDEO_DRIVER_DUMMY
    1.32      &DUMMY_bootstrap,
    1.33  #endif
    1.34 @@ -243,6 +254,7 @@
    1.35      _this->gl_config.stereo = 0;
    1.36      _this->gl_config.multisamplebuffers = 0;
    1.37      _this->gl_config.multisamplesamples = 0;
    1.38 +	_this->gl_config.retained_backing = 1; /* most systems have retained backing on the color buffers */
    1.39      _this->gl_config.accelerated = -1;  /* not known, don't set */
    1.40  
    1.41      /* Initialize the video subsystem */
    1.42 @@ -263,6 +275,10 @@
    1.43  #if SDL_VIDEO_RENDER_OGL
    1.44          SDL_AddRenderDriver(i, &GL_RenderDriver);
    1.45  #endif
    1.46 +		
    1.47 +#if SDL_VIDEO_RENDER_OGL_ES
    1.48 +		SDL_AddRenderDriver(i, &GL_ES_RenderDriver);
    1.49 +#endif
    1.50          if (_this->displays[i].num_render_drivers > 0) {
    1.51              SDL_AddRenderDriver(i, &SW_RenderDriver);
    1.52          }
    1.53 @@ -1410,7 +1426,9 @@
    1.54  
    1.55      if (index < 0) {
    1.56          const char *override = SDL_getenv("SDL_VIDEO_RENDERER");
    1.57 -        int n = SDL_GetNumRenderDrivers();
    1.58 +        		
    1.59 +		int n = SDL_GetNumRenderDrivers();
    1.60 +				
    1.61          for (index = 0; index < n; ++index) {
    1.62              SDL_RenderDriver *driver =
    1.63                  &SDL_CurrentDisplay.render_drivers[index];
    1.64 @@ -1443,6 +1461,7 @@
    1.65      /* Create a new renderer instance */
    1.66      window->renderer = SDL_CurrentDisplay.render_drivers[index]
    1.67          .CreateRenderer(window, flags);
    1.68 +	
    1.69      SDL_SelectRenderer(window->id);
    1.70  
    1.71      return 0;
    1.72 @@ -1546,7 +1565,7 @@
    1.73      }
    1.74      fmt = surface->format;
    1.75  
    1.76 -    if (format) {
    1.77 +    if (format) { /* if we were passed in a format */
    1.78          if (!SDL_PixelFormatEnumToMasks
    1.79              (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
    1.80              SDL_SetError("Unknown pixel format");
    1.81 @@ -1556,7 +1575,7 @@
    1.82          if (surface->format->Amask
    1.83              || !(surface->map->info.flags &
    1.84                   (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
    1.85 -            bpp = fmt->BitsPerPixel;
    1.86 +			bpp = fmt->BitsPerPixel;
    1.87              Rmask = fmt->Rmask;
    1.88              Gmask = fmt->Gmask;
    1.89              Bmask = fmt->Bmask;
    1.90 @@ -1576,8 +1595,7 @@
    1.91          }
    1.92      }
    1.93  
    1.94 -    textureID =
    1.95 -        SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
    1.96 +    textureID = SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w,
    1.97                            surface->h);
    1.98      if (!textureID) {
    1.99          return 0;
   1.100 @@ -1612,9 +1630,8 @@
   1.101                      SDL_DitherColors(dst_fmt->palette->colors,
   1.102                                       SDL_BITSPERPIXEL(format));
   1.103                  }
   1.104 -            }
   1.105 -
   1.106 -            dst = SDL_ConvertSurface(surface, dst_fmt, 0);
   1.107 +            }			
   1.108 +			dst = SDL_ConvertSurface(surface, dst_fmt, 0);
   1.109              if (dst) {
   1.110                  SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
   1.111                  SDL_FreeSurface(dst);
   1.112 @@ -1628,7 +1645,7 @@
   1.113              SDL_DestroyTexture(textureID);
   1.114              return 0;
   1.115          }
   1.116 -    }
   1.117 +	}
   1.118  
   1.119      if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
   1.120          SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
   1.121 @@ -1996,6 +2013,7 @@
   1.122  int
   1.123  SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect)
   1.124  {
   1.125 +		
   1.126      SDL_Renderer *renderer;
   1.127      SDL_Window *window;
   1.128      SDL_Rect real_rect;
   1.129 @@ -2281,8 +2299,9 @@
   1.130  SDL_bool
   1.131  SDL_GL_ExtensionSupported(const char *extension)
   1.132  {
   1.133 -#if SDL_VIDEO_OPENGL
   1.134 -    const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
   1.135 +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
   1.136 +	
   1.137 +	const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
   1.138      const char *extensions;
   1.139      const char *start;
   1.140      const char *where, *terminator;
   1.141 @@ -2337,7 +2356,7 @@
   1.142  int
   1.143  SDL_GL_SetAttribute(SDL_GLattr attr, int value)
   1.144  {
   1.145 -#if SDL_VIDEO_OPENGL
   1.146 +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
   1.147      int retval;
   1.148  
   1.149      if (!_this) {
   1.150 @@ -2395,6 +2414,9 @@
   1.151      case SDL_GL_ACCELERATED_VISUAL:
   1.152          _this->gl_config.accelerated = value;
   1.153          break;
   1.154 +	case SDL_GL_RETAINED_BACKING:
   1.155 +		_this->gl_config.retained_backing = value;
   1.156 +		break;
   1.157      default:
   1.158          SDL_SetError("Unknown OpenGL attribute");
   1.159          retval = -1;
   1.160 @@ -2410,7 +2432,7 @@
   1.161  int
   1.162  SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
   1.163  {
   1.164 -#if SDL_VIDEO_OPENGL
   1.165 +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
   1.166      void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
   1.167      GLenum attrib = 0;
   1.168  
   1.169 @@ -2419,6 +2441,9 @@
   1.170          return -1;
   1.171      }
   1.172      switch (attr) {
   1.173 +	case SDL_GL_RETAINED_BACKING:
   1.174 +		*value = _this->gl_config.retained_backing;
   1.175 +		return 0;
   1.176      case SDL_GL_RED_SIZE:
   1.177          attrib = GL_RED_BITS;
   1.178          break;
   1.179 @@ -2432,14 +2457,22 @@
   1.180          attrib = GL_ALPHA_BITS;
   1.181          break;
   1.182      case SDL_GL_DOUBLEBUFFER:
   1.183 +	#ifndef SDL_VIDEO_OPENGL_ES
   1.184          attrib = GL_DOUBLEBUFFER;
   1.185          break;
   1.186 +	#else
   1.187 +		/* I believe double buffering is the only option in OpenGL ES
   1.188 +		   -- in any case, GL_DOUBLEBUFFER doesn't exist */
   1.189 +		*value = 1;
   1.190 +		return 0;
   1.191 +	#endif
   1.192      case SDL_GL_DEPTH_SIZE:
   1.193          attrib = GL_DEPTH_BITS;
   1.194          break;
   1.195      case SDL_GL_STENCIL_SIZE:
   1.196          attrib = GL_STENCIL_BITS;
   1.197          break;
   1.198 +#ifndef SDL_VIDEO_OPENGL_ES
   1.199      case SDL_GL_ACCUM_RED_SIZE:
   1.200          attrib = GL_ACCUM_RED_BITS;
   1.201          break;
   1.202 @@ -2452,15 +2485,33 @@
   1.203      case SDL_GL_ACCUM_ALPHA_SIZE:
   1.204          attrib = GL_ACCUM_ALPHA_BITS;
   1.205          break;
   1.206 -    case SDL_GL_STEREO:
   1.207 -        attrib = GL_STEREO;
   1.208 -        break;
   1.209 -    case SDL_GL_MULTISAMPLEBUFFERS:
   1.210 -        attrib = GL_SAMPLE_BUFFERS_ARB;
   1.211 -        break;
   1.212 -    case SDL_GL_MULTISAMPLESAMPLES:
   1.213 -        attrib = GL_SAMPLES_ARB;
   1.214 -        break;
   1.215 +	case SDL_GL_STEREO:
   1.216 +		attrib = GL_STEREO;
   1.217 +		break;
   1.218 +#else
   1.219 +	    case SDL_GL_ACCUM_RED_SIZE:
   1.220 +		case SDL_GL_ACCUM_GREEN_SIZE:
   1.221 +		case SDL_GL_ACCUM_BLUE_SIZE:
   1.222 +		case SDL_GL_ACCUM_ALPHA_SIZE:
   1.223 +		case SDL_GL_STEREO:
   1.224 +			/* none of these are supported in OpenGL ES */
   1.225 +			*value = 0;
   1.226 +			return 0;
   1.227 +#endif
   1.228 +		case SDL_GL_MULTISAMPLEBUFFERS:
   1.229 +		#ifndef SDL_VIDEO_OPENGL_ES
   1.230 +			attrib = GL_SAMPLE_BUFFERS_ARB;
   1.231 +		#else
   1.232 +			attrib = GL_SAMPLE_BUFFERS;
   1.233 +		#endif
   1.234 +			break;
   1.235 +		case SDL_GL_MULTISAMPLESAMPLES:
   1.236 +		#ifndef SDL_VIDEO_OPENGL_ES
   1.237 +			attrib = GL_SAMPLES_ARB;
   1.238 +		#else
   1.239 +			attrib = GL_SAMPLES;
   1.240 +		#endif
   1.241 +			break;
   1.242      case SDL_GL_BUFFER_SIZE:
   1.243          {
   1.244              GLint bits = 0;
   1.245 @@ -2507,7 +2558,6 @@
   1.246          return NULL;
   1.247      }
   1.248      if (!(window->flags & SDL_WINDOW_OPENGL)) {
   1.249 -        SDL_SetError("The specified window isn't an OpenGL window");
   1.250          return NULL;
   1.251      }
   1.252      return _this->GL_CreateContext(_this, window);
   1.253 @@ -2525,12 +2575,6 @@
   1.254      if (!context) {
   1.255          window = NULL;
   1.256      }
   1.257 -    if (window) {
   1.258 -        if (window->context == context) {
   1.259 -            return 0;
   1.260 -        }
   1.261 -        window->context = context;
   1.262 -    }
   1.263      return _this->GL_MakeCurrent(_this, window, context);
   1.264  }
   1.265  
   1.266 @@ -2572,6 +2616,7 @@
   1.267      SDL_Window *window = SDL_GetWindowFromID(windowID);
   1.268  
   1.269      if (!window) {
   1.270 +		SDL_SetError("The specified window doesn't exist");
   1.271          return;
   1.272      }
   1.273      if (!(window->flags & SDL_WINDOW_OPENGL)) {