Mercurial > sdl-ios-xcode
changeset 2357:ad4a291c85ab gsoc2008_iphone
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.
author | Holmes Futrell <hfutrell@umail.ucsb.edu> |
---|---|
date | Thu, 17 Jul 2008 23:07:58 +0000 |
parents | 5c27688b08cf |
children | da266ae53b98 |
files | src/video/SDL_video.c |
diffstat | 1 files changed, 75 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/SDL_video.c Thu Jul 17 22:50:39 2008 +0000 +++ b/src/video/SDL_video.c Thu Jul 17 23:07:58 2008 +0000 @@ -27,11 +27,19 @@ #include "SDL_sysvideo.h" #include "SDL_blit.h" #include "SDL_pixels_c.h" -#include "SDL_renderer_gl.h" + + +#include "glrenderer/SDL_renderer_gl.h" +#include "glesrenderer/SDL_renderer_gles.h" + #include "SDL_renderer_sw.h" #include "../events/SDL_sysevents.h" #include "../events/SDL_events_c.h" +#if SDL_VIDEO_OPENGL_ES +#include "SDL_opengles.h" +#endif /* SDL_VIDEO_OPENGL_ES */ + #if SDL_VIDEO_OPENGL #include "SDL_opengl.h" @@ -103,6 +111,9 @@ #if SDL_VIDEO_DRIVER_OS2FS &OS2FSLib_bootstrap, #endif +#if SDL_VIDEO_DRIVER_UIKIT + &UIKIT_bootstrap, +#endif #if SDL_VIDEO_DRIVER_DUMMY &DUMMY_bootstrap, #endif @@ -243,6 +254,7 @@ _this->gl_config.stereo = 0; _this->gl_config.multisamplebuffers = 0; _this->gl_config.multisamplesamples = 0; + _this->gl_config.retained_backing = 1; /* most systems have retained backing on the color buffers */ _this->gl_config.accelerated = -1; /* not known, don't set */ /* Initialize the video subsystem */ @@ -263,6 +275,10 @@ #if SDL_VIDEO_RENDER_OGL SDL_AddRenderDriver(i, &GL_RenderDriver); #endif + +#if SDL_VIDEO_RENDER_OGL_ES + SDL_AddRenderDriver(i, &GL_ES_RenderDriver); +#endif if (_this->displays[i].num_render_drivers > 0) { SDL_AddRenderDriver(i, &SW_RenderDriver); } @@ -1410,7 +1426,9 @@ if (index < 0) { const char *override = SDL_getenv("SDL_VIDEO_RENDERER"); - int n = SDL_GetNumRenderDrivers(); + + int n = SDL_GetNumRenderDrivers(); + for (index = 0; index < n; ++index) { SDL_RenderDriver *driver = &SDL_CurrentDisplay.render_drivers[index]; @@ -1443,6 +1461,7 @@ /* Create a new renderer instance */ window->renderer = SDL_CurrentDisplay.render_drivers[index] .CreateRenderer(window, flags); + SDL_SelectRenderer(window->id); return 0; @@ -1546,7 +1565,7 @@ } fmt = surface->format; - if (format) { + if (format) { /* if we were passed in a format */ if (!SDL_PixelFormatEnumToMasks (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { SDL_SetError("Unknown pixel format"); @@ -1556,7 +1575,7 @@ if (surface->format->Amask || !(surface->map->info.flags & (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { - bpp = fmt->BitsPerPixel; + bpp = fmt->BitsPerPixel; Rmask = fmt->Rmask; Gmask = fmt->Gmask; Bmask = fmt->Bmask; @@ -1576,8 +1595,7 @@ } } - textureID = - SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, + textureID = SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, surface->h); if (!textureID) { return 0; @@ -1612,9 +1630,8 @@ SDL_DitherColors(dst_fmt->palette->colors, SDL_BITSPERPIXEL(format)); } - } - - dst = SDL_ConvertSurface(surface, dst_fmt, 0); + } + dst = SDL_ConvertSurface(surface, dst_fmt, 0); if (dst) { SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch); SDL_FreeSurface(dst); @@ -1628,7 +1645,7 @@ SDL_DestroyTexture(textureID); return 0; } - } + } if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, @@ -1996,6 +2013,7 @@ int SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect * rect) { + SDL_Renderer *renderer; SDL_Window *window; SDL_Rect real_rect; @@ -2281,8 +2299,9 @@ SDL_bool SDL_GL_ExtensionSupported(const char *extension) { -#if SDL_VIDEO_OPENGL - const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES + + const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); const char *extensions; const char *start; const char *where, *terminator; @@ -2337,7 +2356,7 @@ int SDL_GL_SetAttribute(SDL_GLattr attr, int value) { -#if SDL_VIDEO_OPENGL +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES int retval; if (!_this) { @@ -2395,6 +2414,9 @@ case SDL_GL_ACCELERATED_VISUAL: _this->gl_config.accelerated = value; break; + case SDL_GL_RETAINED_BACKING: + _this->gl_config.retained_backing = value; + break; default: SDL_SetError("Unknown OpenGL attribute"); retval = -1; @@ -2410,7 +2432,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) { -#if SDL_VIDEO_OPENGL +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); GLenum attrib = 0; @@ -2419,6 +2441,9 @@ return -1; } switch (attr) { + case SDL_GL_RETAINED_BACKING: + *value = _this->gl_config.retained_backing; + return 0; case SDL_GL_RED_SIZE: attrib = GL_RED_BITS; break; @@ -2432,14 +2457,22 @@ attrib = GL_ALPHA_BITS; break; case SDL_GL_DOUBLEBUFFER: + #ifndef SDL_VIDEO_OPENGL_ES attrib = GL_DOUBLEBUFFER; break; + #else + /* I believe double buffering is the only option in OpenGL ES + -- in any case, GL_DOUBLEBUFFER doesn't exist */ + *value = 1; + return 0; + #endif case SDL_GL_DEPTH_SIZE: attrib = GL_DEPTH_BITS; break; case SDL_GL_STENCIL_SIZE: attrib = GL_STENCIL_BITS; break; +#ifndef SDL_VIDEO_OPENGL_ES case SDL_GL_ACCUM_RED_SIZE: attrib = GL_ACCUM_RED_BITS; break; @@ -2452,15 +2485,33 @@ case SDL_GL_ACCUM_ALPHA_SIZE: attrib = GL_ACCUM_ALPHA_BITS; break; - case SDL_GL_STEREO: - attrib = GL_STEREO; - break; - case SDL_GL_MULTISAMPLEBUFFERS: - attrib = GL_SAMPLE_BUFFERS_ARB; - break; - case SDL_GL_MULTISAMPLESAMPLES: - attrib = GL_SAMPLES_ARB; - break; + case SDL_GL_STEREO: + attrib = GL_STEREO; + break; +#else + case SDL_GL_ACCUM_RED_SIZE: + case SDL_GL_ACCUM_GREEN_SIZE: + case SDL_GL_ACCUM_BLUE_SIZE: + case SDL_GL_ACCUM_ALPHA_SIZE: + case SDL_GL_STEREO: + /* none of these are supported in OpenGL ES */ + *value = 0; + return 0; +#endif + case SDL_GL_MULTISAMPLEBUFFERS: + #ifndef SDL_VIDEO_OPENGL_ES + attrib = GL_SAMPLE_BUFFERS_ARB; + #else + attrib = GL_SAMPLE_BUFFERS; + #endif + break; + case SDL_GL_MULTISAMPLESAMPLES: + #ifndef SDL_VIDEO_OPENGL_ES + attrib = GL_SAMPLES_ARB; + #else + attrib = GL_SAMPLES; + #endif + break; case SDL_GL_BUFFER_SIZE: { GLint bits = 0; @@ -2507,7 +2558,6 @@ return NULL; } if (!(window->flags & SDL_WINDOW_OPENGL)) { - SDL_SetError("The specified window isn't an OpenGL window"); return NULL; } return _this->GL_CreateContext(_this, window); @@ -2525,12 +2575,6 @@ if (!context) { window = NULL; } - if (window) { - if (window->context == context) { - return 0; - } - window->context = context; - } return _this->GL_MakeCurrent(_this, window, context); } @@ -2572,6 +2616,7 @@ SDL_Window *window = SDL_GetWindowFromID(windowID); if (!window) { + SDL_SetError("The specified window doesn't exist"); return; } if (!(window->flags & SDL_WINDOW_OPENGL)) {