src/video/SDL_renderer_gles.c
changeset 2753 0969758c8809
parent 2739 68862734a5fd
child 2859 99210400e8b9
     1.1 --- a/src/video/SDL_renderer_gles.c	Mon Sep 15 04:31:30 2008 +0000
     1.2 +++ b/src/video/SDL_renderer_gles.c	Mon Sep 15 04:32:36 2008 +0000
     1.3 @@ -39,38 +39,41 @@
     1.4  static int GLES_DisplayModeChanged(SDL_Renderer * renderer);
     1.5  static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     1.6  static int GLES_QueryTexturePixels(SDL_Renderer * renderer,
     1.7 -                                 SDL_Texture * texture, void **pixels,
     1.8 -                                 int *pitch);
     1.9 +                                   SDL_Texture * texture, void **pixels,
    1.10 +                                   int *pitch);
    1.11  static int GLES_SetTexturePalette(SDL_Renderer * renderer,
    1.12 -                                SDL_Texture * texture,
    1.13 -                                const SDL_Color * colors, int firstcolor,
    1.14 -                                int ncolors);
    1.15 +                                  SDL_Texture * texture,
    1.16 +                                  const SDL_Color * colors, int firstcolor,
    1.17 +                                  int ncolors);
    1.18  static int GLES_GetTexturePalette(SDL_Renderer * renderer,
    1.19 -                                SDL_Texture * texture, SDL_Color * colors,
    1.20 -                                int firstcolor, int ncolors);
    1.21 +                                  SDL_Texture * texture, SDL_Color * colors,
    1.22 +                                  int firstcolor, int ncolors);
    1.23  static int GLES_SetTextureColorMod(SDL_Renderer * renderer,
    1.24 -                                 SDL_Texture * texture);
    1.25 +                                   SDL_Texture * texture);
    1.26  static int GLES_SetTextureAlphaMod(SDL_Renderer * renderer,
    1.27 -                                 SDL_Texture * texture);
    1.28 +                                   SDL_Texture * texture);
    1.29  static int GLES_SetTextureBlendMode(SDL_Renderer * renderer,
    1.30 -                                  SDL_Texture * texture);
    1.31 +                                    SDL_Texture * texture);
    1.32  static int GLES_SetTextureScaleMode(SDL_Renderer * renderer,
    1.33 -                                  SDL_Texture * texture);
    1.34 +                                    SDL_Texture * texture);
    1.35  static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.36 -                            const SDL_Rect * rect, const void *pixels,
    1.37 -                            int pitch);
    1.38 +                              const SDL_Rect * rect, const void *pixels,
    1.39 +                              int pitch);
    1.40  static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.41 -                          const SDL_Rect * rect, int markDirty, void **pixels,
    1.42 -                          int *pitch);
    1.43 -static void GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.44 +                            const SDL_Rect * rect, int markDirty,
    1.45 +                            void **pixels, int *pitch);
    1.46 +static void GLES_UnlockTexture(SDL_Renderer * renderer,
    1.47 +                               SDL_Texture * texture);
    1.48  static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    1.49 -                            int numrects, const SDL_Rect * rects);
    1.50 +                              int numrects, const SDL_Rect * rects);
    1.51  static int GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b,
    1.52 -                         Uint8 a, const SDL_Rect * rect);
    1.53 +                           Uint8 a, const SDL_Rect * rect);
    1.54  static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    1.55 -                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    1.56 +                           const SDL_Rect * srcrect,
    1.57 +                           const SDL_Rect * dstrect);
    1.58  static void GLES_RenderPresent(SDL_Renderer * renderer);
    1.59 -static void GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    1.60 +static void GLES_DestroyTexture(SDL_Renderer * renderer,
    1.61 +                                SDL_Texture * texture);
    1.62  static void GLES_DestroyRenderer(SDL_Renderer * renderer);
    1.63  
    1.64  
    1.65 @@ -87,11 +90,11 @@
    1.66        SDL_TEXTUREBLENDMODE_MOD),
    1.67       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
    1.68        SDL_TEXTURESCALEMODE_SLOW), 2,
    1.69 -		{
    1.70 -		SDL_PIXELFORMAT_RGB24,
    1.71 -		SDL_PIXELFORMAT_ABGR8888,
    1.72 -		},
    1.73 -	 0,
    1.74 +     {
    1.75 +      SDL_PIXELFORMAT_RGB24,
    1.76 +      SDL_PIXELFORMAT_ABGR8888,
    1.77 +      },
    1.78 +     0,
    1.79       0}
    1.80  };
    1.81  
    1.82 @@ -100,18 +103,18 @@
    1.83      SDL_GLContext context;
    1.84      SDL_bool updateSize;
    1.85      int blendMode;
    1.86 -	
    1.87 +
    1.88  #ifndef APIENTRY
    1.89  #define APIENTRY
    1.90  #endif
    1.91 -	
    1.92 -	SDL_bool useDrawTexture;
    1.93 -	SDL_bool GL_OES_draw_texture_supported;
    1.94 -	
    1.95 -	/* OpenGL ES functions */
    1.96 -	#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
    1.97 -	#include "SDL_glesfuncs.h"
    1.98 -	#undef SDL_PROC
    1.99 +
   1.100 +    SDL_bool useDrawTexture;
   1.101 +    SDL_bool GL_OES_draw_texture_supported;
   1.102 +
   1.103 +    /* OpenGL ES functions */
   1.104 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
   1.105 +#include "SDL_glesfuncs.h"
   1.106 +#undef SDL_PROC
   1.107  
   1.108  } GLES_RenderData;
   1.109  
   1.110 @@ -165,12 +168,12 @@
   1.111  static int
   1.112  GLES_LoadFunctions(GLES_RenderData * data)
   1.113  {
   1.114 -	
   1.115 -	#define SDL_PROC(ret,func,params) \
   1.116 +
   1.117 +#define SDL_PROC(ret,func,params) \
   1.118  	data->func = func;
   1.119 -	#include "SDL_glesfuncs.h"
   1.120 -	#undef SDL_PROC
   1.121 -	
   1.122 +#include "SDL_glesfuncs.h"
   1.123 +#undef SDL_PROC
   1.124 +
   1.125      return 0;
   1.126  }
   1.127  
   1.128 @@ -185,7 +188,7 @@
   1.129  SDL_Renderer *
   1.130  GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
   1.131  {
   1.132 -		
   1.133 +
   1.134      SDL_Renderer *renderer;
   1.135      GLES_RenderData *data;
   1.136      GLint value;
   1.137 @@ -232,9 +235,10 @@
   1.138      renderer->info = GL_ES_RenderDriver.info;
   1.139      renderer->window = window->id;
   1.140      renderer->driverdata = data;
   1.141 -	
   1.142 -	
   1.143 -    renderer->info.flags = (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
   1.144 +
   1.145 +
   1.146 +    renderer->info.flags =
   1.147 +        (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
   1.148  
   1.149      if (GLES_LoadFunctions(data) < 0) {
   1.150          GLES_DestroyRenderer(renderer);
   1.151 @@ -265,15 +269,14 @@
   1.152              renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
   1.153          }
   1.154      }
   1.155 -	
   1.156 -	if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
   1.157 -		data->GL_OES_draw_texture_supported = SDL_TRUE;
   1.158 -		data->useDrawTexture = SDL_TRUE;
   1.159 -	}
   1.160 -	else {
   1.161 -		data->GL_OES_draw_texture_supported = SDL_FALSE;
   1.162 -		data->useDrawTexture = SDL_FALSE;
   1.163 -	}	
   1.164 +
   1.165 +    if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
   1.166 +        data->GL_OES_draw_texture_supported = SDL_TRUE;
   1.167 +        data->useDrawTexture = SDL_TRUE;
   1.168 +    } else {
   1.169 +        data->GL_OES_draw_texture_supported = SDL_FALSE;
   1.170 +        data->useDrawTexture = SDL_FALSE;
   1.171 +    }
   1.172  
   1.173      data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
   1.174      renderer->info.max_texture_width = value;
   1.175 @@ -284,18 +287,19 @@
   1.176      data->blendMode = -1;
   1.177      data->glDisable(GL_DEPTH_TEST);
   1.178      data->glDisable(GL_CULL_FACE);
   1.179 -	data->glEnable(GL_TEXTURE_2D);
   1.180 +    data->glEnable(GL_TEXTURE_2D);
   1.181      data->updateSize = SDL_TRUE;
   1.182  
   1.183      return renderer;
   1.184  }
   1.185  
   1.186 -static int GLES_ActivateRenderer(SDL_Renderer * renderer)
   1.187 +static int
   1.188 +GLES_ActivateRenderer(SDL_Renderer * renderer)
   1.189  {
   1.190 -		
   1.191 -    GLES_RenderData *data = (GLES_RenderData *)renderer->driverdata;
   1.192 +
   1.193 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   1.194      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.195 -				
   1.196 +
   1.197      if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
   1.198          return -1;
   1.199      }
   1.200 @@ -305,8 +309,8 @@
   1.201          data->glMatrixMode(GL_MODELVIEW);
   1.202          data->glLoadIdentity();
   1.203          data->glViewport(0, 0, window->w, window->h);
   1.204 -        data->glOrthof(0.0, (GLfloat)window->w, (GLfloat)window->h, 0.0,
   1.205 -                      0.0, 1.0);
   1.206 +        data->glOrthof(0.0, (GLfloat) window->w, (GLfloat) window->h, 0.0,
   1.207 +                       0.0, 1.0);
   1.208          data->updateSize = SDL_FALSE;
   1.209      }
   1.210      return 0;
   1.211 @@ -342,55 +346,55 @@
   1.212      GLenum format, type;
   1.213      int texture_w, texture_h;
   1.214      GLenum result;
   1.215 -	switch (texture->format) {
   1.216 -		case SDL_PIXELFORMAT_INDEX1LSB:
   1.217 -		case SDL_PIXELFORMAT_INDEX1MSB:
   1.218 -		case SDL_PIXELFORMAT_INDEX8:
   1.219 -		case SDL_PIXELFORMAT_RGB332:
   1.220 -		case SDL_PIXELFORMAT_RGB444:
   1.221 -		case SDL_PIXELFORMAT_RGB555:
   1.222 -		case SDL_PIXELFORMAT_ARGB4444:
   1.223 -		case SDL_PIXELFORMAT_ARGB1555:
   1.224 -		case SDL_PIXELFORMAT_BGR24:
   1.225 -		case SDL_PIXELFORMAT_BGR888:
   1.226 -		case SDL_PIXELFORMAT_RGB888:
   1.227 -		case SDL_PIXELFORMAT_RGBA8888:
   1.228 -		case SDL_PIXELFORMAT_ARGB2101010:
   1.229 -		case SDL_PIXELFORMAT_ARGB8888:
   1.230 -		case SDL_PIXELFORMAT_RGB24:
   1.231 -			internalFormat = GL_RGB;
   1.232 -			format = GL_RGB;
   1.233 -			type = GL_UNSIGNED_BYTE;
   1.234 -			break;
   1.235 -		case SDL_PIXELFORMAT_ABGR8888:
   1.236 -			internalFormat = GL_RGBA;
   1.237 -			format = GL_RGBA;
   1.238 -			type = GL_UNSIGNED_BYTE;			
   1.239 -			break;			
   1.240 -		/*
   1.241 -			These formats would be supported if SDL had the necessary pixel formats
   1.242 -		case SDL_PIXELFORMAT_BGR565:
   1.243 -			internalFormat = GL_RGB;
   1.244 -			format = GL_RGB;
   1.245 -			type = GL_UNSIGNED_SHORT_5_6_5;
   1.246 -			break;			
   1.247 -		case SDL_PIXELFORMAT_ABGR5551:
   1.248 -			internalFormat = GL_RGBA;
   1.249 -			format = GL_RGBA;
   1.250 -			type = GL_UNSIGNED_SHORT_5_5_5_1;
   1.251 -			break;
   1.252 -		case SDL_PIXELFORMAT_ABGR4444:
   1.253 -			internalFormat = GL_RGBA;
   1.254 -			format = GL_RGBA;
   1.255 -			type = GL_UNSIGNED_SHORT_4_4_4_4;
   1.256 -			break;
   1.257 -		*/
   1.258 -		default:
   1.259 -			SDL_SetError("Unsupported texture format");
   1.260 -			return -1;
   1.261 +    switch (texture->format) {
   1.262 +    case SDL_PIXELFORMAT_INDEX1LSB:
   1.263 +    case SDL_PIXELFORMAT_INDEX1MSB:
   1.264 +    case SDL_PIXELFORMAT_INDEX8:
   1.265 +    case SDL_PIXELFORMAT_RGB332:
   1.266 +    case SDL_PIXELFORMAT_RGB444:
   1.267 +    case SDL_PIXELFORMAT_RGB555:
   1.268 +    case SDL_PIXELFORMAT_ARGB4444:
   1.269 +    case SDL_PIXELFORMAT_ARGB1555:
   1.270 +    case SDL_PIXELFORMAT_BGR24:
   1.271 +    case SDL_PIXELFORMAT_BGR888:
   1.272 +    case SDL_PIXELFORMAT_RGB888:
   1.273 +    case SDL_PIXELFORMAT_RGBA8888:
   1.274 +    case SDL_PIXELFORMAT_ARGB2101010:
   1.275 +    case SDL_PIXELFORMAT_ARGB8888:
   1.276 +    case SDL_PIXELFORMAT_RGB24:
   1.277 +        internalFormat = GL_RGB;
   1.278 +        format = GL_RGB;
   1.279 +        type = GL_UNSIGNED_BYTE;
   1.280 +        break;
   1.281 +    case SDL_PIXELFORMAT_ABGR8888:
   1.282 +        internalFormat = GL_RGBA;
   1.283 +        format = GL_RGBA;
   1.284 +        type = GL_UNSIGNED_BYTE;
   1.285 +        break;
   1.286 +        /*
   1.287 +           These formats would be supported if SDL had the necessary pixel formats
   1.288 +           case SDL_PIXELFORMAT_BGR565:
   1.289 +           internalFormat = GL_RGB;
   1.290 +           format = GL_RGB;
   1.291 +           type = GL_UNSIGNED_SHORT_5_6_5;
   1.292 +           break;                       
   1.293 +           case SDL_PIXELFORMAT_ABGR5551:
   1.294 +           internalFormat = GL_RGBA;
   1.295 +           format = GL_RGBA;
   1.296 +           type = GL_UNSIGNED_SHORT_5_5_5_1;
   1.297 +           break;
   1.298 +           case SDL_PIXELFORMAT_ABGR4444:
   1.299 +           internalFormat = GL_RGBA;
   1.300 +           format = GL_RGBA;
   1.301 +           type = GL_UNSIGNED_SHORT_4_4_4_4;
   1.302 +           break;
   1.303 +         */
   1.304 +    default:
   1.305 +        SDL_SetError("Unsupported texture format");
   1.306 +        return -1;
   1.307      }
   1.308 -	
   1.309 -	data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
   1.310 +
   1.311 +    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
   1.312      if (!data) {
   1.313          SDL_OutOfMemory();
   1.314          return -1;
   1.315 @@ -410,14 +414,14 @@
   1.316  
   1.317      renderdata->glGetError();
   1.318      renderdata->glGenTextures(1, &data->texture);
   1.319 -    
   1.320 -	data->type = GL_TEXTURE_2D;
   1.321 -	/* no NPOV textures allowed in OpenGL ES (yet) */
   1.322 -	texture_w = power_of_2(texture->w);
   1.323 -	texture_h = power_of_2(texture->h);
   1.324 -	data->texw = (GLfloat) texture->w / texture_w;
   1.325 -	data->texh = (GLfloat) texture->h / texture_h;
   1.326 -	
   1.327 +
   1.328 +    data->type = GL_TEXTURE_2D;
   1.329 +    /* no NPOV textures allowed in OpenGL ES (yet) */
   1.330 +    texture_w = power_of_2(texture->w);
   1.331 +    texture_h = power_of_2(texture->h);
   1.332 +    data->texw = (GLfloat) texture->w / texture_w;
   1.333 +    data->texh = (GLfloat) texture->h / texture_h;
   1.334 +
   1.335      data->format = format;
   1.336      data->formattype = type;
   1.337      renderdata->glBindTexture(data->type, data->texture);
   1.338 @@ -429,9 +433,9 @@
   1.339                                  GL_CLAMP_TO_EDGE);
   1.340      renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
   1.341                                  GL_CLAMP_TO_EDGE);
   1.342 -    
   1.343 -	renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   1.344 -							 texture_h, 0, format, type, NULL);
   1.345 +
   1.346 +    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   1.347 +                             texture_h, 0, format, type, NULL);
   1.348  
   1.349      result = renderdata->glGetError();
   1.350      if (result != GL_NO_ERROR) {
   1.351 @@ -443,7 +447,7 @@
   1.352  
   1.353  static int
   1.354  GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
   1.355 -                      void **pixels, int *pitch)
   1.356 +                        void **pixels, int *pitch)
   1.357  {
   1.358      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.359  
   1.360 @@ -454,17 +458,17 @@
   1.361  
   1.362  static int
   1.363  GLES_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   1.364 -                     const SDL_Color * colors, int firstcolor, int ncolors)
   1.365 +                       const SDL_Color * colors, int firstcolor, int ncolors)
   1.366  {
   1.367 -	SDL_SetError("OpenGL ES does not support paletted textures");
   1.368 +    SDL_SetError("OpenGL ES does not support paletted textures");
   1.369      return -1;
   1.370  }
   1.371  
   1.372  static int
   1.373  GLES_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
   1.374 -                     SDL_Color * colors, int firstcolor, int ncolors)
   1.375 +                       SDL_Color * colors, int firstcolor, int ncolors)
   1.376  {
   1.377 -	SDL_SetError("OpenGL ES does not support paletted textures");
   1.378 +    SDL_SetError("OpenGL ES does not support paletted textures");
   1.379      return -1;
   1.380  }
   1.381  
   1.382 @@ -472,10 +476,10 @@
   1.383  SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
   1.384                     int pitch)
   1.385  {
   1.386 -	
   1.387 -	
   1.388 -	GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.389 -	renderdata->glBindTexture(data->type, data->texture);
   1.390 +
   1.391 +
   1.392 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.393 +    renderdata->glBindTexture(data->type, data->texture);
   1.394      renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   1.395  }
   1.396  
   1.397 @@ -518,7 +522,7 @@
   1.398          return 0;
   1.399      case SDL_TEXTURESCALEMODE_BEST:
   1.400          SDL_Unsupported();
   1.401 -		texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
   1.402 +        texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
   1.403          return -1;
   1.404      default:
   1.405          SDL_Unsupported();
   1.406 @@ -529,15 +533,15 @@
   1.407  
   1.408  static int
   1.409  GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.410 -                 const SDL_Rect * rect, const void *pixels, int pitch)
   1.411 +                   const SDL_Rect * rect, const void *pixels, int pitch)
   1.412  {
   1.413      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
   1.414      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.415      GLenum result;
   1.416  
   1.417      SetupTextureUpdate(renderdata, texture, pitch);
   1.418 -	renderdata->glGetError();
   1.419 -	renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
   1.420 +    renderdata->glGetError();
   1.421 +    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
   1.422                                  rect->h, data->format, data->formattype,
   1.423                                  pixels);
   1.424      result = renderdata->glGetError();
   1.425 @@ -550,8 +554,8 @@
   1.426  
   1.427  static int
   1.428  GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.429 -               const SDL_Rect * rect, int markDirty, void **pixels,
   1.430 -               int *pitch)
   1.431 +                 const SDL_Rect * rect, int markDirty, void **pixels,
   1.432 +                 int *pitch)
   1.433  {
   1.434      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.435  
   1.436 @@ -572,8 +576,8 @@
   1.437  }
   1.438  
   1.439  static void
   1.440 -GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
   1.441 -                const SDL_Rect * rects)
   1.442 +GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.443 +                  int numrects, const SDL_Rect * rects)
   1.444  {
   1.445      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.446      int i;
   1.447 @@ -585,44 +589,45 @@
   1.448  
   1.449  static int
   1.450  GLES_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   1.451 -              const SDL_Rect * rect)
   1.452 +                const SDL_Rect * rect)
   1.453  {
   1.454 - 	
   1.455 -	GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   1.456 +
   1.457 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   1.458      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.459 -	
   1.460 -	/* set proper drawing color */
   1.461 -	GLfloat oldClearColor[4];
   1.462 -	
   1.463 -	data->glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
   1.464 -	
   1.465 -	data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
   1.466 -			  (GLclampf) b * inv255f, (GLclampf) a * inv255f);
   1.467 -	
   1.468 -	data->glScissor(rect->x, window->h - rect->y - rect->h, rect->w, rect->h);
   1.469 -	data->glEnable(GL_SCISSOR_TEST);
   1.470 -	data->glClear(GL_COLOR_BUFFER_BIT);
   1.471 -	data->glDisable(GL_SCISSOR_TEST);
   1.472 -	
   1.473 -	/* reset clear color */
   1.474 -	data->glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2], oldClearColor[2]);
   1.475 -	
   1.476 -	return 0;
   1.477 +
   1.478 +    /* set proper drawing color */
   1.479 +    GLfloat oldClearColor[4];
   1.480 +
   1.481 +    data->glGetFloatv(GL_COLOR_CLEAR_VALUE, oldClearColor);
   1.482 +
   1.483 +    data->glClearColor((GLclampf) r * inv255f, (GLclampf) g * inv255f,
   1.484 +                       (GLclampf) b * inv255f, (GLclampf) a * inv255f);
   1.485 +
   1.486 +    data->glScissor(rect->x, window->h - rect->y - rect->h, rect->w, rect->h);
   1.487 +    data->glEnable(GL_SCISSOR_TEST);
   1.488 +    data->glClear(GL_COLOR_BUFFER_BIT);
   1.489 +    data->glDisable(GL_SCISSOR_TEST);
   1.490 +
   1.491 +    /* reset clear color */
   1.492 +    data->glClearColor(oldClearColor[0], oldClearColor[1], oldClearColor[2],
   1.493 +                       oldClearColor[2]);
   1.494 +
   1.495 +    return 0;
   1.496  }
   1.497  
   1.498  static int
   1.499  GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   1.500 -              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.501 +                const SDL_Rect * srcrect, const SDL_Rect * dstrect)
   1.502  {
   1.503 -		
   1.504 +
   1.505      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
   1.506      GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
   1.507      int minx, miny, maxx, maxy;
   1.508      GLfloat minu, maxu, minv, maxv;
   1.509 -	int i;
   1.510 -	void *temp_buffer; /* used for reformatting dirty rect pixels */
   1.511 -	void *temp_ptr;
   1.512 -	
   1.513 +    int i;
   1.514 +    void *temp_buffer;          /* used for reformatting dirty rect pixels */
   1.515 +    void *temp_ptr;
   1.516 +
   1.517      if (texturedata->dirty.list) {
   1.518          SDL_DirtyRect *dirty;
   1.519          void *pixels;
   1.520 @@ -630,38 +635,40 @@
   1.521          int pitch = texturedata->pitch;
   1.522  
   1.523          SetupTextureUpdate(data, texture, pitch);
   1.524 -		
   1.525 +
   1.526          data->glBindTexture(texturedata->type, texturedata->texture);
   1.527          for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
   1.528              SDL_Rect *rect = &dirty->rect;
   1.529 -            pixels = (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch + rect->x * bpp);
   1.530 -			/*	There is no GL_UNPACK_ROW_LENGTH in OpenGLES 
   1.531 -				we must do this reformatting ourselves(!)
   1.532 -			 
   1.533 -				maybe it'd be a good idea to keep a temp buffer around
   1.534 -				for this purpose rather than allocating it each time
   1.535 -			*/
   1.536 -			temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
   1.537 -			temp_ptr = temp_buffer;
   1.538 -			for (i=0; i<rect->h; i++) {
   1.539 -				SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
   1.540 -				temp_ptr += rect->w * bpp;
   1.541 -				pixels	 += pitch;
   1.542 -			}
   1.543 -			
   1.544 +            pixels =
   1.545 +                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
   1.546 +                          rect->x * bpp);
   1.547 +            /*      There is no GL_UNPACK_ROW_LENGTH in OpenGLES 
   1.548 +               we must do this reformatting ourselves(!)
   1.549 +
   1.550 +               maybe it'd be a good idea to keep a temp buffer around
   1.551 +               for this purpose rather than allocating it each time
   1.552 +             */
   1.553 +            temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
   1.554 +            temp_ptr = temp_buffer;
   1.555 +            for (i = 0; i < rect->h; i++) {
   1.556 +                SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
   1.557 +                temp_ptr += rect->w * bpp;
   1.558 +                pixels += pitch;
   1.559 +            }
   1.560 +
   1.561              data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
   1.562                                    rect->w, rect->h, texturedata->format,
   1.563                                    texturedata->formattype, temp_buffer);
   1.564 -			
   1.565 -			SDL_free(temp_buffer);
   1.566 -			
   1.567 +
   1.568 +            SDL_free(temp_buffer);
   1.569 +
   1.570          }
   1.571          SDL_ClearDirtyRects(&texturedata->dirty);
   1.572      }
   1.573 -	
   1.574 +
   1.575      data->glBindTexture(texturedata->type, texturedata->texture);
   1.576 -	data->glEnable(GL_TEXTURE_2D);
   1.577 -	
   1.578 +    data->glEnable(GL_TEXTURE_2D);
   1.579 +
   1.580      if (texture->modMode) {
   1.581          data->glColor4f((GLfloat) texture->r * inv255f,
   1.582                          (GLfloat) texture->g * inv255f,
   1.583 @@ -697,71 +704,80 @@
   1.584          data->blendMode = texture->blendMode;
   1.585      }
   1.586  
   1.587 -	switch (texture->scaleMode) {
   1.588 -		case SDL_TEXTURESCALEMODE_NONE:
   1.589 -		case SDL_TEXTURESCALEMODE_FAST:
   1.590 -			data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.591 -								  GL_NEAREST);
   1.592 -			data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.593 -								  GL_NEAREST);
   1.594 -			break;
   1.595 -		case SDL_TEXTURESCALEMODE_SLOW:
   1.596 -		case SDL_TEXTURESCALEMODE_BEST:
   1.597 -			data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.598 -								  GL_LINEAR);
   1.599 -			data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.600 -								  GL_LINEAR);
   1.601 -			break;
   1.602 -	}
   1.603 +    switch (texture->scaleMode) {
   1.604 +    case SDL_TEXTURESCALEMODE_NONE:
   1.605 +    case SDL_TEXTURESCALEMODE_FAST:
   1.606 +        data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.607 +                              GL_NEAREST);
   1.608 +        data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.609 +                              GL_NEAREST);
   1.610 +        break;
   1.611 +    case SDL_TEXTURESCALEMODE_SLOW:
   1.612 +    case SDL_TEXTURESCALEMODE_BEST:
   1.613 +        data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
   1.614 +                              GL_LINEAR);
   1.615 +        data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
   1.616 +                              GL_LINEAR);
   1.617 +        break;
   1.618 +    }
   1.619  
   1.620 -	if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
   1.621 -		/* this code is a little funny because the viewport is upside down vs SDL's coordinate system */
   1.622 -		SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.623 -		GLint cropRect[4];
   1.624 -		cropRect[0] = srcrect->x;
   1.625 -		cropRect[1] = srcrect->y + srcrect->h;
   1.626 -		cropRect[2] = srcrect->w;
   1.627 -		cropRect[3] = -srcrect->h;
   1.628 -		data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
   1.629 -		data->glDrawTexiOES(dstrect->x, window->h - dstrect->y - dstrect->h, 0, dstrect->w, dstrect->h);
   1.630 -	}
   1.631 -	else {
   1.632 -		
   1.633 -		minx = dstrect->x;
   1.634 -		miny = dstrect->y;
   1.635 -		maxx = dstrect->x + dstrect->w;
   1.636 -		maxy = dstrect->y + dstrect->h;
   1.637 -		
   1.638 -		minu = (GLfloat) srcrect->x / texture->w;
   1.639 -		minu *= texturedata->texw;
   1.640 -		maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
   1.641 -		maxu *= texturedata->texw;
   1.642 -		minv = (GLfloat) srcrect->y / texture->h;
   1.643 -		minv *= texturedata->texh;
   1.644 -		maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
   1.645 -		maxv *= texturedata->texh;			
   1.646 -		
   1.647 -		GLshort vertices[8];
   1.648 -		GLfloat texCoords[8];
   1.649 -		
   1.650 -		vertices[0] = minx; vertices[1] = miny;
   1.651 -		vertices[2] = maxx; vertices[3] = miny;
   1.652 -		vertices[4]	= minx; vertices[5] = maxy;
   1.653 -		vertices[6] = maxx; vertices[7] = maxy;	
   1.654 -		
   1.655 -		texCoords[0] = minu; texCoords[1] = minv;
   1.656 -		texCoords[2] = maxu; texCoords[3] = minv;
   1.657 -		texCoords[4] = minu; texCoords[5] = maxv;
   1.658 -		texCoords[6] = maxu; texCoords[7] = maxv;	
   1.659 -		
   1.660 -		data->glVertexPointer(2, GL_SHORT, 0, vertices);
   1.661 -		data->glEnableClientState(GL_VERTEX_ARRAY);
   1.662 -		data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
   1.663 -		data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   1.664 -		data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.665 -		
   1.666 -	}
   1.667 -		
   1.668 +    if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
   1.669 +        /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */
   1.670 +        SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.671 +        GLint cropRect[4];
   1.672 +        cropRect[0] = srcrect->x;
   1.673 +        cropRect[1] = srcrect->y + srcrect->h;
   1.674 +        cropRect[2] = srcrect->w;
   1.675 +        cropRect[3] = -srcrect->h;
   1.676 +        data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
   1.677 +                               cropRect);
   1.678 +        data->glDrawTexiOES(dstrect->x, window->h - dstrect->y - dstrect->h,
   1.679 +                            0, dstrect->w, dstrect->h);
   1.680 +    } else {
   1.681 +
   1.682 +        minx = dstrect->x;
   1.683 +        miny = dstrect->y;
   1.684 +        maxx = dstrect->x + dstrect->w;
   1.685 +        maxy = dstrect->y + dstrect->h;
   1.686 +
   1.687 +        minu = (GLfloat) srcrect->x / texture->w;
   1.688 +        minu *= texturedata->texw;
   1.689 +        maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
   1.690 +        maxu *= texturedata->texw;
   1.691 +        minv = (GLfloat) srcrect->y / texture->h;
   1.692 +        minv *= texturedata->texh;
   1.693 +        maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
   1.694 +        maxv *= texturedata->texh;
   1.695 +
   1.696 +        GLshort vertices[8];
   1.697 +        GLfloat texCoords[8];
   1.698 +
   1.699 +        vertices[0] = minx;
   1.700 +        vertices[1] = miny;
   1.701 +        vertices[2] = maxx;
   1.702 +        vertices[3] = miny;
   1.703 +        vertices[4] = minx;
   1.704 +        vertices[5] = maxy;
   1.705 +        vertices[6] = maxx;
   1.706 +        vertices[7] = maxy;
   1.707 +
   1.708 +        texCoords[0] = minu;
   1.709 +        texCoords[1] = minv;
   1.710 +        texCoords[2] = maxu;
   1.711 +        texCoords[3] = minv;
   1.712 +        texCoords[4] = minu;
   1.713 +        texCoords[5] = maxv;
   1.714 +        texCoords[6] = maxu;
   1.715 +        texCoords[7] = maxv;
   1.716 +
   1.717 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
   1.718 +        data->glEnableClientState(GL_VERTEX_ARRAY);
   1.719 +        data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
   1.720 +        data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   1.721 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.722 +
   1.723 +    }
   1.724 +
   1.725      return 0;
   1.726  }
   1.727  
   1.728 @@ -781,7 +797,7 @@
   1.729          return;
   1.730      }
   1.731      if (data->texture) {
   1.732 -		glDeleteTextures(1, &data->texture);
   1.733 +        glDeleteTextures(1, &data->texture);
   1.734      }
   1.735      if (data->pixels) {
   1.736          SDL_free(data->pixels);