Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Feb 2011 00:00:13 -0800
changeset 5201523409574510
parent 5200 01bced9a4cc1
child 5202 1f2b17f42fd0
Added an OpenGL ES 2.0 renderer, contributed by itsnotabigtruck

This compiles, but it untested.
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
include/SDL_config_iphoneos.h
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/render/opengles2/SDL_shaders_gles2.c
src/render/opengles2/SDL_shaders_gles2.h
     1.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Sat Feb 05 20:02:37 2011 -0800
     1.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Sun Feb 06 00:00:13 2011 -0800
     1.3 @@ -62,6 +62,9 @@
     1.4  		0098A5631195B4D900343137 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5621195B4D900343137 /* OpenGLES.framework */; };
     1.5  		0098A5651195B4D900343137 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5641195B4D900343137 /* UIKit.framework */; };
     1.6  		0098A5851195B5E200343137 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5841195B5E200343137 /* QuartzCore.framework */; };
     1.7 +		0402A85812FE70C600CECEE3 /* SDL_render_gles2.c in Sources */ = {isa = PBXBuildFile; fileRef = 0402A85512FE70C600CECEE3 /* SDL_render_gles2.c */; };
     1.8 +		0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */ = {isa = PBXBuildFile; fileRef = 0402A85612FE70C600CECEE3 /* SDL_shaders_gles2.c */; };
     1.9 +		0402A85A12FE70C600CECEE3 /* SDL_shaders_gles2.h in Headers */ = {isa = PBXBuildFile; fileRef = 0402A85712FE70C600CECEE3 /* SDL_shaders_gles2.h */; };
    1.10  		041B2CD912FA0E9E0087D585 /* SDL_render.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2CD812FA0E9E0087D585 /* SDL_render.h */; settings = {ATTRIBUTES = (Public, ); }; };
    1.11  		041B2CF112FA0F680087D585 /* SDL_render.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CEA12FA0F680087D585 /* SDL_render.c */; };
    1.12  		041B2CF212FA0F680087D585 /* SDL_sysrender.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2CEB12FA0F680087D585 /* SDL_sysrender.h */; };
    1.13 @@ -324,6 +327,9 @@
    1.14  		0098A5621195B4D900343137 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
    1.15  		0098A5641195B4D900343137 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
    1.16  		0098A5841195B5E200343137 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
    1.17 +		0402A85512FE70C600CECEE3 /* SDL_render_gles2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_render_gles2.c; sourceTree = "<group>"; };
    1.18 +		0402A85612FE70C600CECEE3 /* SDL_shaders_gles2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_shaders_gles2.c; sourceTree = "<group>"; };
    1.19 +		0402A85712FE70C600CECEE3 /* SDL_shaders_gles2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_shaders_gles2.h; sourceTree = "<group>"; };
    1.20  		041B2CD812FA0E9E0087D585 /* SDL_render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_render.h; path = ../../include/SDL_render.h; sourceTree = SOURCE_ROOT; };
    1.21  		041B2CEA12FA0F680087D585 /* SDL_render.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_render.c; sourceTree = "<group>"; };
    1.22  		041B2CEB12FA0F680087D585 /* SDL_sysrender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sysrender.h; sourceTree = "<group>"; };
    1.23 @@ -669,10 +675,21 @@
    1.24  			path = cocoa;
    1.25  			sourceTree = "<group>";
    1.26  		};
    1.27 +		0402A85412FE70C600CECEE3 /* opengles2 */ = {
    1.28 +			isa = PBXGroup;
    1.29 +			children = (
    1.30 +				0402A85512FE70C600CECEE3 /* SDL_render_gles2.c */,
    1.31 +				0402A85612FE70C600CECEE3 /* SDL_shaders_gles2.c */,
    1.32 +				0402A85712FE70C600CECEE3 /* SDL_shaders_gles2.h */,
    1.33 +			);
    1.34 +			path = opengles2;
    1.35 +			sourceTree = "<group>";
    1.36 +		};
    1.37  		041B2CE312FA0F680087D585 /* render */ = {
    1.38  			isa = PBXGroup;
    1.39  			children = (
    1.40  				041B2CE812FA0F680087D585 /* opengles */,
    1.41 +				0402A85412FE70C600CECEE3 /* opengles2 */,
    1.42  				041B2CEC12FA0F680087D585 /* software */,
    1.43  				04409BA212FA989600FB9AA8 /* mmx.h */,
    1.44  				041B2CEA12FA0F680087D585 /* SDL_render.c */,
    1.45 @@ -1249,6 +1266,7 @@
    1.46  				04F7808412FB753F00FC43C0 /* SDL_nullframebuffer_c.h in Headers */,
    1.47  				0442EC4B12FE1BFF004C9285 /* SDL_hints.h in Headers */,
    1.48  				0442EC5012FE1C1E004C9285 /* SDL_render_sw_c.h in Headers */,
    1.49 +				0402A85A12FE70C600CECEE3 /* SDL_shaders_gles2.h in Headers */,
    1.50  			);
    1.51  			runOnlyForDeploymentPostprocessing = 0;
    1.52  		};
    1.53 @@ -1497,6 +1515,8 @@
    1.54  				0442EC5112FE1C1E004C9285 /* SDL_render_sw.c in Sources */,
    1.55  				0442EC5312FE1C28004C9285 /* SDL_render_gles.c in Sources */,
    1.56  				0442EC5512FE1C3F004C9285 /* SDL_hints.c in Sources */,
    1.57 +				0402A85812FE70C600CECEE3 /* SDL_render_gles2.c in Sources */,
    1.58 +				0402A85912FE70C600CECEE3 /* SDL_shaders_gles2.c in Sources */,
    1.59  			);
    1.60  			runOnlyForDeploymentPostprocessing = 0;
    1.61  		};
     2.1 --- a/include/SDL_config_iphoneos.h	Sat Feb 05 20:02:37 2011 -0800
     2.2 +++ b/include/SDL_config_iphoneos.h	Sun Feb 06 00:00:13 2011 -0800
     2.3 @@ -145,6 +145,7 @@
     2.4  /* enable OpenGL ES */
     2.5  #define SDL_VIDEO_OPENGL_ES	1
     2.6  #define SDL_VIDEO_RENDER_OGL_ES	1
     2.7 +#define SDL_VIDEO_RENDER_OGL_ES2	1
     2.8  
     2.9  /* Enable system power support */
    2.10  #define SDL_POWER_UIKIT 1
     3.1 --- a/src/render/SDL_render.c	Sat Feb 05 20:02:37 2011 -0800
     3.2 +++ b/src/render/SDL_render.c	Sun Feb 06 00:00:13 2011 -0800
     3.3 @@ -51,7 +51,10 @@
     3.4      &GL_RenderDriver,
     3.5  #endif
     3.6  #if SDL_VIDEO_RENDER_OGL_ES
     3.7 -    &GL_ES_RenderDriver,
     3.8 +    &GLES_RenderDriver,
     3.9 +#endif
    3.10 +#if SDL_VIDEO_RENDER_OGL_ES2
    3.11 +    &GLES2_RenderDriver,
    3.12  #endif
    3.13  #if SDL_VIDEO_RENDER_DIRECTFB
    3.14      &DirectFB_RenderDriver,
     4.1 --- a/src/render/SDL_sysrender.h	Sat Feb 05 20:02:37 2011 -0800
     4.2 +++ b/src/render/SDL_sysrender.h	Sun Feb 06 00:00:13 2011 -0800
     4.3 @@ -125,7 +125,10 @@
     4.4  extern SDL_RenderDriver GL_RenderDriver;
     4.5  #endif
     4.6  #if SDL_VIDEO_RENDER_OGL_ES
     4.7 -extern SDL_RenderDriver GL_ES_RenderDriver;
     4.8 +extern SDL_RenderDriver GLES_RenderDriver;
     4.9 +#endif
    4.10 +#if SDL_VIDEO_RENDER_OGL_ES2
    4.11 +extern SDL_RenderDriver GLES2_RenderDriver;
    4.12  #endif
    4.13  #if SDL_VIDEO_RENDER_DIRECTFB
    4.14  extern SDL_RenderDriver DirectFB_RenderDriver;
     5.1 --- a/src/render/opengles/SDL_render_gles.c	Sat Feb 05 20:02:37 2011 -0800
     5.2 +++ b/src/render/opengles/SDL_render_gles.c	Sun Feb 06 00:00:13 2011 -0800
     5.3 @@ -71,7 +71,7 @@
     5.4  static void GLES_DestroyRenderer(SDL_Renderer * renderer);
     5.5  
     5.6  
     5.7 -SDL_RenderDriver GL_ES_RenderDriver = {
     5.8 +SDL_RenderDriver GLES_RenderDriver = {
     5.9      GLES_CreateRenderer,
    5.10      {
    5.11       "opengl_es",
    5.12 @@ -201,7 +201,7 @@
    5.13      renderer->RenderPresent = GLES_RenderPresent;
    5.14      renderer->DestroyTexture = GLES_DestroyTexture;
    5.15      renderer->DestroyRenderer = GLES_DestroyRenderer;
    5.16 -    renderer->info = GL_ES_RenderDriver.info;
    5.17 +    renderer->info = GLES_RenderDriver.info;
    5.18      renderer->driverdata = data;
    5.19  
    5.20      renderer->info.flags = SDL_RENDERER_ACCELERATED;
    5.21 @@ -265,7 +265,6 @@
    5.22  static int
    5.23  GLES_ActivateRenderer(SDL_Renderer * renderer)
    5.24  {
    5.25 -
    5.26      GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
    5.27      SDL_Window *window = renderer->window;
    5.28  
    5.29 @@ -390,13 +389,6 @@
    5.30      return 0;
    5.31  }
    5.32  
    5.33 -static void
    5.34 -SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
    5.35 -                   int pitch)
    5.36 -{
    5.37 -    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5.38 -}
    5.39 -
    5.40  static int
    5.41  GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    5.42                     const SDL_Rect * rect, const void *pixels, int pitch)
    5.43 @@ -412,7 +404,7 @@
    5.44      GLES_ActivateRenderer(renderer);
    5.45  
    5.46      renderdata->glGetError();
    5.47 -    SetupTextureUpdate(renderdata, texture, pitch);
    5.48 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5.49      renderdata->glEnable(data->type);
    5.50      renderdata->glBindTexture(data->type, data->texture);
    5.51  
    5.52 @@ -467,7 +459,7 @@
    5.53  
    5.54      GLES_ActivateRenderer(renderer);
    5.55  
    5.56 -    SetupTextureUpdate(renderdata, texture, data->pitch);
    5.57 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    5.58      renderdata->glEnable(data->type);
    5.59      renderdata->glBindTexture(data->type, data->texture);
    5.60      renderdata->glTexSubImage2D(data->type, 0, 0, 0, texture->w,
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/render/opengles2/SDL_render_gles2.c	Sun Feb 06 00:00:13 2011 -0800
     6.3 @@ -0,0 +1,1240 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 2010 itsnotabigtruck.
     6.7 +
     6.8 +    Permission is hereby granted, free of charge, to any person obtaining a
     6.9 +    copy of this software and associated documentation files (the "Software"),
    6.10 +    to deal in the Software without restriction, including without limitation
    6.11 +    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    6.12 +    and/or sell copies of the Software, and to permit persons to whom the
    6.13 +    Software is furnished to do so, subject to the following conditions:
    6.14 +
    6.15 +    The above copyright notice and this permission notice shall be included in
    6.16 +    all copies or substantial portions of the Software.
    6.17 +
    6.18 +    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    6.19 +    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    6.20 +    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    6.21 +    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    6.22 +    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    6.23 +    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    6.24 +    DEALINGS IN THE SOFTWARE.
    6.25 +*/
    6.26 +
    6.27 +#include "SDL_config.h"
    6.28 +
    6.29 +#if SDL_VIDEO_RENDER_OGL_ES2
    6.30 +
    6.31 +#ifdef __IPHONEOS__
    6.32 +#include <OpenGLES/ES2/gl.h>
    6.33 +#include <OpenGLES/ES2/glext.h>
    6.34 +#else
    6.35 +#include <GLES2/gl2.h>
    6.36 +#include <GLES2/gl2ext.h>
    6.37 +#endif
    6.38 +#include "../SDL_sysrender.h"
    6.39 +#include "SDL_shaders_gles2.h"
    6.40 +
    6.41 +/*************************************************************************************************
    6.42 + * Bootstrap data                                                                                *
    6.43 + *************************************************************************************************/
    6.44 +
    6.45 +static SDL_Renderer *GLES2_CreateRenderer(SDL_Window *window, Uint32 flags);
    6.46 +
    6.47 +SDL_RenderDriver GLES2_RenderDriver = {
    6.48 +    GLES2_CreateRenderer,
    6.49 +    {
    6.50 +        "opengles2",
    6.51 +        (SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC),
    6.52 +#if GLES2_ASSUME_BGRA
    6.53 +        11,
    6.54 +        {
    6.55 +            SDL_PIXELFORMAT_ABGR8888,
    6.56 +            SDL_PIXELFORMAT_ABGR4444,
    6.57 +            SDL_PIXELFORMAT_ABGR1555,
    6.58 +            SDL_PIXELFORMAT_BGR565,
    6.59 +            SDL_PIXELFORMAT_BGR24,
    6.60 +            SDL_PIXELFORMAT_ARGB8888,
    6.61 +            SDL_PIXELFORMAT_ARGB4444,
    6.62 +            SDL_PIXELFORMAT_ARGB1555,
    6.63 +            SDL_PIXELFORMAT_RGB565,
    6.64 +            SDL_PIXELFORMAT_RGB24
    6.65 +        },
    6.66 +#elif GLES2_ASSUME_BGRA8888
    6.67 +        7,
    6.68 +        {
    6.69 +            SDL_PIXELFORMAT_ABGR8888,
    6.70 +            SDL_PIXELFORMAT_ABGR4444,
    6.71 +            SDL_PIXELFORMAT_ABGR1555,
    6.72 +            SDL_PIXELFORMAT_BGR565,
    6.73 +            SDL_PIXELFORMAT_BGR24,
    6.74 +            SDL_PIXELFORMAT_ARGB8888
    6.75 +        },
    6.76 +#else
    6.77 +        6,
    6.78 +        {
    6.79 +            SDL_PIXELFORMAT_ABGR8888,
    6.80 +            SDL_PIXELFORMAT_ABGR4444,
    6.81 +            SDL_PIXELFORMAT_ABGR1555,
    6.82 +            SDL_PIXELFORMAT_BGR565,
    6.83 +            SDL_PIXELFORMAT_BGR24
    6.84 +        },
    6.85 +#endif
    6.86 +        0,
    6.87 +        0
    6.88 +    }
    6.89 +};
    6.90 +
    6.91 +/*************************************************************************************************
    6.92 + * Context structures                                                                            *
    6.93 + *************************************************************************************************/
    6.94 +
    6.95 +typedef struct GLES2_TextureData
    6.96 +{
    6.97 +    GLenum texture;
    6.98 +    GLenum texture_type;
    6.99 +    GLenum pixel_format;
   6.100 +    GLenum pixel_type;
   6.101 +    void *pixel_data;
   6.102 +    size_t pitch;
   6.103 +} GLES2_TextureData;
   6.104 +
   6.105 +typedef struct GLES2_ShaderCacheEntry
   6.106 +{
   6.107 +    GLuint id;
   6.108 +    GLES2_ShaderType type;
   6.109 +    const GLES2_ShaderInstance *instance;
   6.110 +    int references;
   6.111 +    struct GLES2_ShaderCacheEntry *prev;
   6.112 +    struct GLES2_ShaderCacheEntry *next;
   6.113 +} GLES2_ShaderCacheEntry;
   6.114 +
   6.115 +typedef struct GLES2_ShaderCache
   6.116 +{
   6.117 +    int count;
   6.118 +    GLES2_ShaderCacheEntry *head;
   6.119 +} GLES2_ShaderCache;
   6.120 +
   6.121 +typedef struct GLES2_ProgramCacheEntry
   6.122 +{
   6.123 +    GLuint id;
   6.124 +    SDL_BlendMode blend_mode;
   6.125 +    GLES2_ShaderCacheEntry *vertex_shader;
   6.126 +    GLES2_ShaderCacheEntry *fragment_shader;
   6.127 +    GLuint uniform_locations[16];
   6.128 +    struct GLES2_ProgramCacheEntry *prev;
   6.129 +    struct GLES2_ProgramCacheEntry *next;
   6.130 +} GLES2_ProgramCacheEntry;
   6.131 +
   6.132 +typedef struct GLES2_ProgramCache
   6.133 +{
   6.134 +    int count;
   6.135 +    GLES2_ProgramCacheEntry *head;
   6.136 +    GLES2_ProgramCacheEntry *tail;
   6.137 +} GLES2_ProgramCache;
   6.138 +
   6.139 +typedef enum
   6.140 +{
   6.141 +    GLES2_ATTRIBUTE_POSITION = 0,
   6.142 +    GLES2_ATTRIBUTE_TEXCOORD = 1
   6.143 +} GLES2_Attribute;
   6.144 +
   6.145 +typedef enum
   6.146 +{
   6.147 +    GLES2_UNIFORM_PROJECTION,
   6.148 +    GLES2_UNIFORM_TEXTURE,
   6.149 +    GLES2_UNIFORM_MODULATION,
   6.150 +    GLES2_UNIFORM_COLOR,
   6.151 +    GLES2_UNIFORM_COLORTABLE
   6.152 +} GLES2_Uniform;
   6.153 +
   6.154 +typedef enum
   6.155 +{
   6.156 +    GLES2_IMAGESOURCE_SOLID,
   6.157 +    GLES2_IMAGESOURCE_TEXTURE
   6.158 +} GLES2_ImageSource;
   6.159 +
   6.160 +typedef struct GLES2_DriverContext
   6.161 +{
   6.162 +    SDL_GLContext *context;
   6.163 +    int shader_format_count;
   6.164 +    GLenum *shader_formats;
   6.165 +    GLES2_ShaderCache shader_cache;
   6.166 +    GLES2_ProgramCache program_cache;
   6.167 +    GLES2_ProgramCacheEntry *current_program;
   6.168 +	SDL_bool updateSize;
   6.169 +} GLES2_DriverContext;
   6.170 +
   6.171 +#define GLES2_MAX_CACHED_PROGRAMS 8
   6.172 +
   6.173 +/*************************************************************************************************
   6.174 + * Renderer state APIs                                                                           *
   6.175 + *************************************************************************************************/
   6.176 +
   6.177 +static void GLES2_WindowEvent(SDL_Renderer * renderer,
   6.178 +                              const SDL_WindowEvent *event);
   6.179 +static int GLES2_ActivateRenderer(SDL_Renderer *renderer);
   6.180 +static int GLES2_DisplayModeChanged(SDL_Renderer *renderer);
   6.181 +static void GLES2_DestroyRenderer(SDL_Renderer *renderer);
   6.182 +
   6.183 +static SDL_GLContext SDL_CurrentContext = NULL;
   6.184 +
   6.185 +static int
   6.186 +GLES2_ActivateRenderer(SDL_Renderer * renderer)
   6.187 +{
   6.188 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.189 +    SDL_Window *window = renderer->window;
   6.190 +
   6.191 +    if (SDL_CurrentContext != rdata->context) {
   6.192 +        /* Null out the current program to ensure we set it again */
   6.193 +        rdata->current_program = NULL;
   6.194 +
   6.195 +        if (SDL_GL_MakeCurrent(window, rdata->context) < 0) {
   6.196 +            return -1;
   6.197 +        }
   6.198 +        SDL_CurrentContext = rdata->context;
   6.199 +    }
   6.200 +    if (rdata->updateSize) {
   6.201 +        int w, h;
   6.202 +
   6.203 +        SDL_GetWindowSize(window, &w, &h);
   6.204 +        glViewport(0, 0, w, h);
   6.205 +        rdata->updateSize = SDL_FALSE;
   6.206 +    }
   6.207 +    return 0;
   6.208 +}
   6.209 +
   6.210 +static void
   6.211 +GLES2_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
   6.212 +{
   6.213 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.214 +
   6.215 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
   6.216 +        /* Rebind the context to the window area */
   6.217 +        SDL_CurrentContext = NULL;
   6.218 +        rdata->updateSize = SDL_TRUE;
   6.219 +    }
   6.220 +}
   6.221 +
   6.222 +static void
   6.223 +GLES2_DestroyRenderer(SDL_Renderer *renderer)
   6.224 +{
   6.225 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.226 +    GLES2_ProgramCacheEntry *entry;
   6.227 +    GLES2_ProgramCacheEntry *next;
   6.228 +
   6.229 +    GLES2_ActivateRenderer(renderer);
   6.230 +
   6.231 +    /* Deallocate everything */
   6.232 +    entry = rdata->program_cache.head;
   6.233 +    while (entry)
   6.234 +    {
   6.235 +        glDeleteShader(entry->vertex_shader->id);
   6.236 +        glDeleteShader(entry->fragment_shader->id);
   6.237 +        SDL_free(entry->vertex_shader);
   6.238 +        SDL_free(entry->fragment_shader);
   6.239 +        glDeleteProgram(entry->id);
   6.240 +        next = entry->next;
   6.241 +        SDL_free(entry);
   6.242 +        entry = next;
   6.243 +    }
   6.244 +    SDL_GL_DeleteContext(rdata->context);
   6.245 +    SDL_free(rdata->shader_formats);
   6.246 +    SDL_free(renderer->driverdata);
   6.247 +    SDL_free(renderer);
   6.248 +}
   6.249 +
   6.250 +/*************************************************************************************************
   6.251 + * Texture APIs                                                                                  *
   6.252 + *************************************************************************************************/
   6.253 +
   6.254 +#define GL_BGR_EXT  0x80E0
   6.255 +#define GL_BGRA_EXT 0x80E1
   6.256 +
   6.257 +static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture);
   6.258 +static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture);
   6.259 +static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
   6.260 +                             void **pixels, int *pitch);
   6.261 +static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture);
   6.262 +static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
   6.263 +                               const void *pixels, int pitch);
   6.264 +
   6.265 +static int
   6.266 +GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
   6.267 +{
   6.268 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.269 +    GLES2_TextureData *tdata;
   6.270 +    GLenum format;
   6.271 +    GLenum type;
   6.272 +
   6.273 +    GLES2_ActivateRenderer(renderer);
   6.274 +
   6.275 +    /* Determine the corresponding GLES texture format params */
   6.276 +    switch (texture->format)
   6.277 +    {
   6.278 +    case SDL_PIXELFORMAT_BGR24:
   6.279 +        format = GL_RGB;
   6.280 +        type = GL_UNSIGNED_BYTE;
   6.281 +        break;
   6.282 +    case SDL_PIXELFORMAT_ABGR8888:
   6.283 +        format = GL_RGBA;
   6.284 +        type = GL_UNSIGNED_BYTE;
   6.285 +        break;
   6.286 +    case SDL_PIXELFORMAT_BGR565:
   6.287 +        format = GL_RGB;
   6.288 +        type = GL_UNSIGNED_SHORT_5_6_5;
   6.289 +        break;
   6.290 +    case SDL_PIXELFORMAT_ABGR1555:
   6.291 +        format = GL_RGBA;
   6.292 +        type = GL_UNSIGNED_SHORT_5_5_5_1;
   6.293 +        break;
   6.294 +    case SDL_PIXELFORMAT_ABGR4444:
   6.295 +        format = GL_RGBA;
   6.296 +        type = GL_UNSIGNED_SHORT_4_4_4_4;
   6.297 +        break;
   6.298 +#if GLES2_ASSUME_BGRA || GLES2_ASSUME_BGRA8888
   6.299 +    case SDL_PIXELFORMAT_ARGB8888:
   6.300 +        format = GL_BGRA_EXT;
   6.301 +        type = GL_UNSIGNED_BYTE;
   6.302 +        break;
   6.303 +#endif /* GLES2_ASSUME_BGRA || GLES2_ASSUME_BGRA8888 */
   6.304 +#if GLES2_ASSUME_BGRA
   6.305 +    case SDL_PIXELFORMAT_RGB24:
   6.306 +        format = GL_BGR_EXT;
   6.307 +        type = GL_UNSIGNED_BYTE;
   6.308 +        break;
   6.309 +    case SDL_PIXELFORMAT_RGB565:
   6.310 +        format = GL_BGR_EXT;
   6.311 +        type = GL_UNSIGNED_SHORT_5_6_5;
   6.312 +        break;
   6.313 +    case SDL_PIXELFORMAT_ARGB1555:
   6.314 +        format = GL_BGRA_EXT;
   6.315 +        type = GL_UNSIGNED_SHORT_5_5_5_1;
   6.316 +        break;
   6.317 +    case SDL_PIXELFORMAT_ARGB4444:
   6.318 +        format = GL_BGRA_EXT;
   6.319 +        type = GL_UNSIGNED_SHORT_4_4_4_4;
   6.320 +        break;
   6.321 +#endif /* GLES2_ASSUME_BGRA */
   6.322 +    default:
   6.323 +        SDL_SetError("Texture format not supported");
   6.324 +        return -1;
   6.325 +    }
   6.326 +
   6.327 +    /* Allocate a texture struct */
   6.328 +    tdata = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData));
   6.329 +    if (!tdata)
   6.330 +    {
   6.331 +        SDL_OutOfMemory();
   6.332 +        return -1;
   6.333 +    }
   6.334 +    tdata->texture = 0;
   6.335 +    tdata->texture_type = GL_TEXTURE_2D;
   6.336 +    tdata->pixel_format = format;
   6.337 +    tdata->pixel_type = type;
   6.338 +
   6.339 +    /* Allocate a blob for image data */
   6.340 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING)
   6.341 +    {
   6.342 +        tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   6.343 +        tdata->pixel_data = SDL_malloc(tdata->pitch * texture->h);
   6.344 +        if (!tdata->pixel_data)
   6.345 +        {
   6.346 +            SDL_OutOfMemory();
   6.347 +            SDL_free(tdata);
   6.348 +            return -1;
   6.349 +        }
   6.350 +    }
   6.351 +
   6.352 +    /* Allocate the texture */
   6.353 +    glGetError();
   6.354 +    glGenTextures(1, &tdata->texture);
   6.355 +    glActiveTexture(GL_TEXTURE0);
   6.356 +    glBindTexture(tdata->texture_type, tdata->texture);
   6.357 +    glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   6.358 +    glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   6.359 +    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   6.360 +    glTexParameteri(tdata->texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
   6.361 +    glTexImage2D(tdata->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL);
   6.362 +    if (glGetError() != GL_NO_ERROR)
   6.363 +    {
   6.364 +        SDL_SetError("Texture creation failed");
   6.365 +        glDeleteTextures(1, &tdata->texture);
   6.366 +        SDL_free(tdata);
   6.367 +        return -1;
   6.368 +    }
   6.369 +    texture->driverdata = tdata;
   6.370 +    return 0;
   6.371 +}
   6.372 +
   6.373 +static void
   6.374 +GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
   6.375 +{
   6.376 +    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   6.377 +
   6.378 +    GLES2_ActivateRenderer(renderer);
   6.379 +
   6.380 +    /* Destroy the texture */
   6.381 +    if (tdata)
   6.382 +    {
   6.383 +        glDeleteTextures(1, &tdata->texture);
   6.384 +        SDL_free(tdata->pixel_data);
   6.385 +        SDL_free(tdata);
   6.386 +        texture->driverdata = NULL;
   6.387 +    }
   6.388 +}
   6.389 +
   6.390 +static int
   6.391 +GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
   6.392 +                  void **pixels, int *pitch)
   6.393 +{
   6.394 +    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   6.395 +
   6.396 +    /* Retrieve the buffer/pitch for the specified region */
   6.397 +    *pixels = (Uint8 *)tdata->pixel_data +
   6.398 +              (tdata->pitch * rect->y) +
   6.399 +              (rect->x * SDL_BYTESPERPIXEL(texture->format));
   6.400 +    *pitch = tdata->pitch;
   6.401 +
   6.402 +    return 0;
   6.403 +}
   6.404 +
   6.405 +static void
   6.406 +GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
   6.407 +{
   6.408 +    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   6.409 +
   6.410 +    GLES2_ActivateRenderer(renderer);
   6.411 +
   6.412 +    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   6.413 +    glActiveTexture(GL_TEXTURE0);
   6.414 +    glBindTexture(tdata->texture_type, tdata->texture);
   6.415 +    glTexSubImage2D(tdata->texture_type, 0, 0, 0, texture->w, texture->h,
   6.416 +                    tdata->pixel_format, tdata->pixel_type, tdata->pixel_data);
   6.417 +}
   6.418 +
   6.419 +static int
   6.420 +GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect,
   6.421 +                    const void *pixels, int pitch)
   6.422 +{
   6.423 +    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   6.424 +    Uint8 *blob = NULL;
   6.425 +    Uint8 *src;
   6.426 +    int srcPitch;
   6.427 +    Uint8 *dest;
   6.428 +    int y;
   6.429 +
   6.430 +    GLES2_ActivateRenderer(renderer);
   6.431 +
   6.432 +    /* Bail out if we're supposed to update an empty rectangle */
   6.433 +    if (rect->w <= 0 || rect->h <= 0)
   6.434 +        return 0;
   6.435 +
   6.436 +    /* Reformat the texture data into a tightly packed array */
   6.437 +    srcPitch = rect->w * SDL_BYTESPERPIXEL(texture->format);
   6.438 +    src = (Uint8 *)pixels;
   6.439 +    if (pitch != srcPitch)
   6.440 +    {
   6.441 +        blob = (Uint8 *)SDL_malloc(srcPitch * rect->h);
   6.442 +        if (!blob)
   6.443 +        {
   6.444 +            SDL_OutOfMemory();
   6.445 +            return -1;
   6.446 +        }
   6.447 +        src = blob;
   6.448 +        for (y = 0; y < rect->h; ++y)
   6.449 +        {
   6.450 +            SDL_memcpy(src, pixels, srcPitch);
   6.451 +            src += srcPitch;
   6.452 +            pixels = (Uint8 *)pixels + pitch;
   6.453 +        }
   6.454 +        src = blob;
   6.455 +    }
   6.456 +
   6.457 +    /* Create a texture subimage with the supplied data */
   6.458 +    glGetError();
   6.459 +    glActiveTexture(GL_TEXTURE0);
   6.460 +    glBindTexture(tdata->texture_type, tdata->texture);
   6.461 +    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   6.462 +    glTexSubImage2D(tdata->texture_type,
   6.463 +                    0,
   6.464 +                    rect->x,
   6.465 +                    rect->y,
   6.466 +                    rect->w,
   6.467 +                    rect->h,
   6.468 +                    tdata->pixel_format,
   6.469 +                    tdata->pixel_type,
   6.470 +                    src);
   6.471 +    if (glGetError() != GL_NO_ERROR)
   6.472 +    {
   6.473 +        SDL_SetError("Failed to update texture");
   6.474 +        return -1;
   6.475 +    }
   6.476 +
   6.477 +    /* Update the (streaming) texture buffer, in one pass if possible */
   6.478 +    if (tdata->pixel_data)
   6.479 +    {
   6.480 +        dest = (Uint8 *)tdata->pixel_data +
   6.481 +               (tdata->pitch * rect->y) +
   6.482 +               (SDL_BYTESPERPIXEL(texture->format) * rect->x);
   6.483 +        if (rect->w == texture->w)
   6.484 +        {
   6.485 +            SDL_memcpy(dest, src, srcPitch * rect->h);
   6.486 +        }
   6.487 +        else
   6.488 +        {
   6.489 +            for (y = 0; y < rect->h; ++y)
   6.490 +            {
   6.491 +                SDL_memcpy(dest, src, srcPitch);
   6.492 +                src += srcPitch;
   6.493 +                dest += tdata->pitch;
   6.494 +            }
   6.495 +        }
   6.496 +    }
   6.497 +
   6.498 +    /* Clean up and return */
   6.499 +    SDL_free(blob);
   6.500 +    return 0;
   6.501 +}
   6.502 +
   6.503 +/*************************************************************************************************
   6.504 + * Shader management functions                                                                   *
   6.505 + *************************************************************************************************/
   6.506 +
   6.507 +static GLES2_ShaderCacheEntry *GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type,
   6.508 +                                                 SDL_BlendMode blendMode);
   6.509 +static void GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry);
   6.510 +static GLES2_ProgramCacheEntry *GLES2_CacheProgram(SDL_Renderer *renderer,
   6.511 +                                                   GLES2_ShaderCacheEntry *vertex,
   6.512 +                                                   GLES2_ShaderCacheEntry *fragment,
   6.513 +                                                   SDL_BlendMode blendMode);
   6.514 +static int GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source,
   6.515 +                               SDL_BlendMode blendMode);
   6.516 +static int GLES2_SetOrthographicProjection(SDL_Renderer *renderer);
   6.517 +
   6.518 +static GLES2_ProgramCacheEntry *
   6.519 +GLES2_CacheProgram(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *vertex,
   6.520 +                   GLES2_ShaderCacheEntry *fragment, SDL_BlendMode blendMode)
   6.521 +{
   6.522 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.523 +    GLES2_ProgramCacheEntry *entry;
   6.524 +    GLES2_ShaderCacheEntry *shaderEntry;
   6.525 +    GLint linkSuccessful;
   6.526 +
   6.527 +    /* Check if we've already cached this program */
   6.528 +    entry = rdata->program_cache.head;
   6.529 +    while (entry)
   6.530 +    {
   6.531 +        if (entry->vertex_shader == vertex && entry->fragment_shader == fragment)
   6.532 +            break;
   6.533 +        entry = entry->next;
   6.534 +    }
   6.535 +    if (entry)
   6.536 +    {
   6.537 +        if (rdata->program_cache.count > 1)
   6.538 +        {
   6.539 +            if (entry->next)
   6.540 +                entry->next->prev = entry->prev;
   6.541 +            if (entry->prev)
   6.542 +                entry->prev->next = entry->next;
   6.543 +            entry->prev = NULL;
   6.544 +            entry->next = rdata->program_cache.head;
   6.545 +            rdata->program_cache.head->prev = entry;
   6.546 +            rdata->program_cache.head = entry;
   6.547 +        }
   6.548 +        return entry;
   6.549 +    }
   6.550 +
   6.551 +    /* Create a program cache entry */
   6.552 +    entry = (GLES2_ProgramCacheEntry *)SDL_calloc(1, sizeof(GLES2_ProgramCacheEntry));
   6.553 +    if (!entry)
   6.554 +    {
   6.555 +        SDL_OutOfMemory();
   6.556 +        return NULL;
   6.557 +    }
   6.558 +    entry->vertex_shader = vertex;
   6.559 +    entry->fragment_shader = fragment;
   6.560 +    entry->blend_mode = blendMode;
   6.561 +    
   6.562 +    /* Create the program and link it */
   6.563 +    glGetError();
   6.564 +    entry->id = glCreateProgram();
   6.565 +    glAttachShader(entry->id, vertex->id);
   6.566 +    glAttachShader(entry->id, fragment->id);
   6.567 +    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_POSITION, "a_position");
   6.568 +    glBindAttribLocation(entry->id, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
   6.569 +    glLinkProgram(entry->id);
   6.570 +    glGetProgramiv(entry->id, GL_LINK_STATUS, &linkSuccessful);
   6.571 +    if (glGetError() != GL_NO_ERROR || !linkSuccessful)
   6.572 +    {
   6.573 +        SDL_SetError("Failed to link shader program");
   6.574 +        glDeleteProgram(entry->id);
   6.575 +        SDL_free(entry);
   6.576 +        return NULL;
   6.577 +    }
   6.578 +    
   6.579 +    /* Predetermine locations of uniform variables */
   6.580 +    entry->uniform_locations[GLES2_UNIFORM_PROJECTION] =
   6.581 +        glGetUniformLocation(entry->id, "u_projection");
   6.582 +    entry->uniform_locations[GLES2_UNIFORM_TEXTURE] =
   6.583 +        glGetUniformLocation(entry->id, "u_texture");
   6.584 +    entry->uniform_locations[GLES2_UNIFORM_MODULATION] =
   6.585 +        glGetUniformLocation(entry->id, "u_modulation");
   6.586 +    entry->uniform_locations[GLES2_UNIFORM_COLOR] =
   6.587 +        glGetUniformLocation(entry->id, "u_color");
   6.588 +    entry->uniform_locations[GLES2_UNIFORM_COLORTABLE] =
   6.589 +        glGetUniformLocation(entry->id, "u_colorTable");
   6.590 +
   6.591 +    /* Cache the linked program */
   6.592 +    if (rdata->program_cache.head)
   6.593 +    {
   6.594 +        entry->next = rdata->program_cache.head;
   6.595 +        rdata->program_cache.head->prev = entry;
   6.596 +    }
   6.597 +    else
   6.598 +    {
   6.599 +        rdata->program_cache.tail = entry;
   6.600 +    }
   6.601 +    rdata->program_cache.head = entry;
   6.602 +    ++rdata->program_cache.count;
   6.603 +
   6.604 +    /* Increment the refcount of the shaders we're using */
   6.605 +    ++vertex->references;
   6.606 +    ++fragment->references;
   6.607 +
   6.608 +    /* Evict the last entry from the cache if we exceed the limit */
   6.609 +    if (rdata->program_cache.count > GLES2_MAX_CACHED_PROGRAMS)
   6.610 +    {
   6.611 +        shaderEntry = rdata->program_cache.tail->vertex_shader;
   6.612 +        if (--shaderEntry->references <= 0)
   6.613 +            GLES2_EvictShader(renderer, shaderEntry);
   6.614 +        shaderEntry = rdata->program_cache.tail->fragment_shader;
   6.615 +        if (--shaderEntry->references <= 0)
   6.616 +            GLES2_EvictShader(renderer, shaderEntry);
   6.617 +        glDeleteProgram(rdata->program_cache.tail->id);
   6.618 +        rdata->program_cache.tail = rdata->program_cache.tail->prev;
   6.619 +        SDL_free(rdata->program_cache.tail->next);
   6.620 +        rdata->program_cache.tail->next = NULL;
   6.621 +        --rdata->program_cache.count;
   6.622 +    }
   6.623 +    return entry;
   6.624 +}
   6.625 +
   6.626 +static GLES2_ShaderCacheEntry *
   6.627 +GLES2_CacheShader(SDL_Renderer *renderer, GLES2_ShaderType type, SDL_BlendMode blendMode)
   6.628 +{
   6.629 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.630 +    const GLES2_Shader *shader;
   6.631 +    const GLES2_ShaderInstance *instance = NULL;
   6.632 +    GLES2_ShaderCacheEntry *entry = NULL;
   6.633 +    GLint compileSuccessful = GL_FALSE;
   6.634 +    int i, j;
   6.635 +
   6.636 +    /* Find the corresponding shader */
   6.637 +    shader = GLES2_GetShader(type, blendMode);
   6.638 +    if (!shader)
   6.639 +    {
   6.640 +        SDL_SetError("No shader matching the requested characteristics was found");
   6.641 +        return NULL;
   6.642 +    }
   6.643 +    
   6.644 +    /* Find a matching shader instance that's supported on this hardware */
   6.645 +    for (i = 0; i < shader->instance_count; ++i)
   6.646 +    {
   6.647 +        for (j = 0; j < rdata->shader_format_count; ++j)
   6.648 +        {
   6.649 +            if (!shader->instances)
   6.650 +                continue;
   6.651 +            if (shader->instances[i]->format != rdata->shader_formats[j])
   6.652 +                continue;
   6.653 +            instance = shader->instances[i];
   6.654 +            break;
   6.655 +        }
   6.656 +    }
   6.657 +    if (!instance)
   6.658 +    {
   6.659 +        SDL_SetError("The specified shader cannot be loaded on the current platform");
   6.660 +        return NULL;
   6.661 +    }
   6.662 +
   6.663 +    /* Check if we've already cached this shader */
   6.664 +    entry = rdata->shader_cache.head;
   6.665 +    while (entry)
   6.666 +    {
   6.667 +        if (entry->instance == instance)
   6.668 +            break;
   6.669 +        entry = entry->next;
   6.670 +    }
   6.671 +    if (entry)
   6.672 +        return entry;
   6.673 +
   6.674 +    /* Create a shader cache entry */
   6.675 +    entry = (GLES2_ShaderCacheEntry *)SDL_calloc(1, sizeof(GLES2_ShaderCacheEntry));
   6.676 +    if (!entry)
   6.677 +    {
   6.678 +        SDL_OutOfMemory();
   6.679 +        return NULL;
   6.680 +    }
   6.681 +    entry->type = type;
   6.682 +    entry->instance = instance;
   6.683 +
   6.684 +    /* Compile or load the selected shader instance */
   6.685 +    glGetError();
   6.686 +    entry->id = glCreateShader(instance->type);
   6.687 +    if (instance->format == (GLenum)-1)
   6.688 +    {
   6.689 +        glShaderSource(entry->id, 1, (const char **)&instance->data, &instance->length);
   6.690 +        glCompileShader(entry->id);
   6.691 +        glGetShaderiv(entry->id, GL_COMPILE_STATUS, &compileSuccessful);
   6.692 +    }
   6.693 +    else
   6.694 +    {
   6.695 +        glShaderBinary(1, &entry->id, instance->format, instance->data, instance->length);
   6.696 +        compileSuccessful = GL_TRUE;
   6.697 +    }
   6.698 +    if (glGetError() != GL_NO_ERROR || !compileSuccessful)
   6.699 +    {
   6.700 +        SDL_SetError("Failed to load the specified shader");
   6.701 +        glDeleteShader(entry->id);
   6.702 +        SDL_free(entry);
   6.703 +        return NULL;
   6.704 +    }
   6.705 +
   6.706 +    /* Link the shader entry in at the front of the cache */
   6.707 +    if (rdata->shader_cache.head)
   6.708 +    {
   6.709 +        entry->next = rdata->shader_cache.head;
   6.710 +        rdata->shader_cache.head->prev = entry;
   6.711 +    }
   6.712 +    rdata->shader_cache.head = entry;
   6.713 +    ++rdata->shader_cache.count;
   6.714 +    return entry;
   6.715 +}
   6.716 +
   6.717 +static void
   6.718 +GLES2_EvictShader(SDL_Renderer *renderer, GLES2_ShaderCacheEntry *entry)
   6.719 +{
   6.720 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.721 +
   6.722 +    /* Unlink the shader from the cache */
   6.723 +    if (entry->next)
   6.724 +        entry->next->prev = entry->prev;
   6.725 +    if (entry->prev)
   6.726 +        entry->prev->next = entry->next;
   6.727 +    if (rdata->shader_cache.head == entry)
   6.728 +        rdata->shader_cache.head = entry->next;
   6.729 +    --rdata->shader_cache.count;
   6.730 +
   6.731 +    /* Deallocate the shader */
   6.732 +    glDeleteShader(entry->id);
   6.733 +    SDL_free(entry);
   6.734 +}
   6.735 +
   6.736 +static int
   6.737 +GLES2_SelectProgram(SDL_Renderer *renderer, GLES2_ImageSource source, SDL_BlendMode blendMode)
   6.738 +{
   6.739 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.740 +    GLES2_ShaderCacheEntry *vertex = NULL;
   6.741 +    GLES2_ShaderCacheEntry *fragment = NULL;
   6.742 +    GLES2_ShaderType vtype, ftype;
   6.743 +    GLES2_ProgramCacheEntry *program;
   6.744 +
   6.745 +    /* Select an appropriate shader pair for the specified modes */
   6.746 +    vtype = GLES2_SHADER_VERTEX_DEFAULT;
   6.747 +    switch (source)
   6.748 +    {
   6.749 +    case GLES2_IMAGESOURCE_SOLID:
   6.750 +        ftype = GLES2_SHADER_FRAGMENT_SOLID_SRC;
   6.751 +        break;
   6.752 +    case GLES2_IMAGESOURCE_TEXTURE:
   6.753 +        ftype = GLES2_SHADER_FRAGMENT_TEXTURE_SRC;
   6.754 +        break;
   6.755 +    }
   6.756 +
   6.757 +    /* Load the requested shaders */
   6.758 +    vertex = GLES2_CacheShader(renderer, vtype, blendMode);
   6.759 +    if (!vertex)
   6.760 +        goto fault;
   6.761 +    fragment = GLES2_CacheShader(renderer, ftype, blendMode);
   6.762 +    if (!fragment)
   6.763 +        goto fault;
   6.764 +
   6.765 +    /* Check if we need to change programs at all */
   6.766 +    if (rdata->current_program &&
   6.767 +        rdata->current_program->vertex_shader == vertex &&
   6.768 +        rdata->current_program->fragment_shader == fragment)
   6.769 +        return 0;
   6.770 +
   6.771 +    /* Generate a matching program */
   6.772 +    program = GLES2_CacheProgram(renderer, vertex, fragment, blendMode);
   6.773 +    if (!program)
   6.774 +        goto fault;
   6.775 +
   6.776 +    /* Select that program in OpenGL */
   6.777 +    glGetError();
   6.778 +    glUseProgram(program->id);
   6.779 +    if (glGetError() != GL_NO_ERROR)
   6.780 +    {
   6.781 +        SDL_SetError("Failed to select program");
   6.782 +        goto fault;
   6.783 +    }
   6.784 +
   6.785 +    /* Set the current program */
   6.786 +    rdata->current_program = program;
   6.787 +
   6.788 +    /* Activate an orthographic projection */
   6.789 +    if (GLES2_SetOrthographicProjection(renderer) < 0)
   6.790 +        goto fault;
   6.791 +
   6.792 +    /* Clean up and return */
   6.793 +    return 0;
   6.794 +fault:
   6.795 +    if (vertex && vertex->references <= 0)
   6.796 +        GLES2_EvictShader(renderer, vertex);
   6.797 +    if (fragment && fragment->references <= 0)
   6.798 +        GLES2_EvictShader(renderer, fragment);
   6.799 +    rdata->current_program = NULL;
   6.800 +    return -1;
   6.801 +}
   6.802 +
   6.803 +static int
   6.804 +GLES2_SetOrthographicProjection(SDL_Renderer *renderer)
   6.805 +{
   6.806 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.807 +    SDL_Window *window = renderer->window;
   6.808 +    int w, h;
   6.809 +    GLfloat projection[4][4];
   6.810 +    GLuint locProjection;
   6.811 +
   6.812 +    /* Get the window width and height */
   6.813 +    SDL_GetWindowSize(window, &w, &h);
   6.814 +
   6.815 +    /* Prepare an orthographic projection */
   6.816 +    projection[0][0] = 2.0f / w;
   6.817 +    projection[0][1] = 0.0f;
   6.818 +    projection[0][2] = 0.0f;
   6.819 +    projection[0][3] = 0.0f;
   6.820 +    projection[1][0] = 0.0f;
   6.821 +    projection[1][1] = -2.0f / h;
   6.822 +    projection[1][2] = 0.0f;
   6.823 +    projection[1][3] = 0.0f;
   6.824 +    projection[2][0] = 0.0f;
   6.825 +    projection[2][1] = 0.0f;
   6.826 +    projection[2][2] = 1.0f;
   6.827 +    projection[2][3] = 0.0f;
   6.828 +    projection[3][0] = -1.0f;
   6.829 +    projection[3][1] = 1.0f;
   6.830 +    projection[3][2] = 0.0f;
   6.831 +    projection[3][3] = 1.0f;
   6.832 +
   6.833 +    /* Set the projection matrix */
   6.834 +    locProjection = rdata->current_program->uniform_locations[GLES2_UNIFORM_PROJECTION];
   6.835 +    glGetError();
   6.836 +    glUniformMatrix4fv(locProjection, 1, GL_FALSE, (GLfloat *)projection);
   6.837 +    if (glGetError() != GL_NO_ERROR)
   6.838 +    {
   6.839 +        SDL_SetError("Failed to set orthographic projection");
   6.840 +        return -1;
   6.841 +    }
   6.842 +    return 0;
   6.843 +}
   6.844 +
   6.845 +/*************************************************************************************************
   6.846 + * Rendering functions                                                                           *
   6.847 + *************************************************************************************************/
   6.848 +
   6.849 +static int GLES2_RenderClear(SDL_Renderer *renderer);
   6.850 +static int GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count);
   6.851 +static int GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count);
   6.852 +static int GLES2_RenderDrawRects(SDL_Renderer *renderer, const SDL_Rect **rects, int count);
   6.853 +static int GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect **rects, int count);
   6.854 +static int GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
   6.855 +                            const SDL_Rect *dstrect);
   6.856 +static void GLES2_RenderPresent(SDL_Renderer *renderer);
   6.857 +
   6.858 +static int
   6.859 +GLES2_RenderClear(SDL_Renderer *renderer)
   6.860 +{
   6.861 +    float r = (float)renderer->r / 255.0f;
   6.862 +    float g = (float)renderer->g / 255.0f;
   6.863 +    float b = (float)renderer->b / 255.0f;
   6.864 +    float a = (float)renderer->a / 255.0f;
   6.865 +
   6.866 +    GLES2_ActivateRenderer(renderer);
   6.867 +
   6.868 +    /* Clear the backbuffer with the selected color */
   6.869 +    glClearColor(r, g, b, a);
   6.870 +    glClear(GL_COLOR_BUFFER_BIT);
   6.871 +    return 0;
   6.872 +}
   6.873 +
   6.874 +static void
   6.875 +GLES2_SetBlendMode(int blendMode)
   6.876 +{
   6.877 +    switch (blendMode)
   6.878 +    {
   6.879 +    case SDL_BLENDMODE_NONE:
   6.880 +    default:
   6.881 +        glDisable(GL_BLEND);
   6.882 +        break;
   6.883 +    case SDL_BLENDMODE_BLEND:
   6.884 +        glEnable(GL_BLEND);
   6.885 +        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   6.886 +        break;
   6.887 +    case SDL_BLENDMODE_ADD:
   6.888 +        glEnable(GL_BLEND);
   6.889 +        glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   6.890 +        break;
   6.891 +    case SDL_BLENDMODE_MOD:
   6.892 +        glEnable(GL_BLEND);
   6.893 +        glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   6.894 +        break;
   6.895 +    }
   6.896 +}
   6.897 +
   6.898 +static int
   6.899 +GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
   6.900 +{
   6.901 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.902 +    GLfloat *vertices;
   6.903 +    SDL_BlendMode blendMode;
   6.904 +    int alpha;
   6.905 +    GLuint locColor;
   6.906 +    int idx;
   6.907 +
   6.908 +    GLES2_ActivateRenderer(renderer);
   6.909 +
   6.910 +    blendMode = renderer->blendMode;
   6.911 +    alpha = renderer->a;
   6.912 +
   6.913 +    /* Activate an appropriate shader and set the projection matrix */
   6.914 +    if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
   6.915 +        return -1;
   6.916 +
   6.917 +    /* Select the color to draw with */
   6.918 +    locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
   6.919 +    glGetError();
   6.920 +    glUniform4f(locColor,
   6.921 +                renderer->r / 255.0f,
   6.922 +                renderer->g / 255.0f,
   6.923 +                renderer->b / 255.0f,
   6.924 +                alpha / 255.0f);
   6.925 +
   6.926 +    /* Configure the correct blend mode */
   6.927 +    GLES2_SetBlendMode(blendMode);
   6.928 +
   6.929 +    /* Emit the specified vertices as points */
   6.930 +    vertices = SDL_stack_alloc(GLfloat, count * 2);
   6.931 +    for (idx = 0; idx < count; ++idx)
   6.932 +    {
   6.933 +        GLfloat x = (GLfloat)points[idx].x + 0.5f;
   6.934 +        GLfloat y = (GLfloat)points[idx].y + 0.5f;
   6.935 +
   6.936 +        vertices[idx * 2] = x;
   6.937 +        vertices[(idx * 2) + 1] = y;
   6.938 +    }
   6.939 +    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   6.940 +    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   6.941 +    glDrawArrays(GL_POINTS, 0, count);
   6.942 +    glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   6.943 +    SDL_stack_free(vertices);
   6.944 +    if (glGetError() != GL_NO_ERROR)
   6.945 +    {
   6.946 +        SDL_SetError("Failed to render lines");
   6.947 +        return -1;
   6.948 +    }
   6.949 +    return 0;
   6.950 +}
   6.951 +
   6.952 +static int
   6.953 +GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
   6.954 +{
   6.955 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   6.956 +    GLfloat *vertices;
   6.957 +    SDL_BlendMode blendMode;
   6.958 +    int alpha;
   6.959 +    GLuint locColor;
   6.960 +    int idx;
   6.961 +
   6.962 +    GLES2_ActivateRenderer(renderer);
   6.963 +
   6.964 +    blendMode = renderer->blendMode;
   6.965 +    alpha = renderer->a;
   6.966 +
   6.967 +    /* Activate an appropriate shader and set the projection matrix */
   6.968 +    if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
   6.969 +        return -1;
   6.970 +
   6.971 +    /* Select the color to draw with */
   6.972 +    locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
   6.973 +    glGetError();
   6.974 +    glUniform4f(locColor,
   6.975 +                renderer->r / 255.0f,
   6.976 +                renderer->g / 255.0f,
   6.977 +                renderer->b / 255.0f,
   6.978 +                alpha / 255.0f);
   6.979 +
   6.980 +    /* Configure the correct blend mode */
   6.981 +    GLES2_SetBlendMode(blendMode);
   6.982 +
   6.983 +    /* Emit a line strip including the specified vertices */
   6.984 +    vertices = SDL_stack_alloc(GLfloat, count * 2);
   6.985 +    for (idx = 0; idx < count; ++idx)
   6.986 +    {
   6.987 +        GLfloat x = (GLfloat)points[idx].x + 0.5f;
   6.988 +        GLfloat y = (GLfloat)points[idx].y + 0.5f;
   6.989 +
   6.990 +        vertices[idx * 2] = x;
   6.991 +        vertices[(idx * 2) + 1] = y;
   6.992 +    }
   6.993 +    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   6.994 +    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   6.995 +    glDrawArrays(GL_LINE_STRIP, 0, count);
   6.996 +    glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   6.997 +    SDL_stack_free(vertices);
   6.998 +    if (glGetError() != GL_NO_ERROR)
   6.999 +    {
  6.1000 +        SDL_SetError("Failed to render lines");
  6.1001 +        return -1;
  6.1002 +    }
  6.1003 +    return 0;
  6.1004 +}
  6.1005 +
  6.1006 +static int
  6.1007 +GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect **rects, int count)
  6.1008 +{
  6.1009 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
  6.1010 +    GLfloat vertices[8];
  6.1011 +    SDL_BlendMode blendMode;
  6.1012 +    int alpha;
  6.1013 +    GLuint locColor;
  6.1014 +    int idx;
  6.1015 +
  6.1016 +    GLES2_ActivateRenderer(renderer);
  6.1017 +
  6.1018 +    blendMode = renderer->blendMode;
  6.1019 +    alpha = renderer->a;
  6.1020 +
  6.1021 +    /* Activate an appropriate shader and set the projection matrix */
  6.1022 +    if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
  6.1023 +        return -1;
  6.1024 +
  6.1025 +    /* Select the color to draw with */
  6.1026 +    locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
  6.1027 +    glGetError();
  6.1028 +    glUniform4f(locColor,
  6.1029 +                renderer->r / 255.0f,
  6.1030 +                renderer->g / 255.0f,
  6.1031 +                renderer->b / 255.0f,
  6.1032 +                alpha / 255.0f);
  6.1033 +
  6.1034 +    /* Configure the correct blend mode */
  6.1035 +    GLES2_SetBlendMode(blendMode);
  6.1036 +
  6.1037 +    /* Emit a line loop for each rectangle */
  6.1038 +    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
  6.1039 +    for (idx = 0; idx < count; ++idx)
  6.1040 +    {
  6.1041 +        GLfloat xMin = (GLfloat)rects[idx]->x;
  6.1042 +        GLfloat xMax = (GLfloat)(rects[idx]->x + rects[idx]->w);
  6.1043 +        GLfloat yMin = (GLfloat)rects[idx]->y;
  6.1044 +        GLfloat yMax = (GLfloat)(rects[idx]->y + rects[idx]->h);
  6.1045 +
  6.1046 +        vertices[0] = xMin;
  6.1047 +        vertices[1] = yMin;
  6.1048 +        vertices[2] = xMax;
  6.1049 +        vertices[3] = yMin;
  6.1050 +        vertices[4] = xMin;
  6.1051 +        vertices[5] = yMax;
  6.1052 +        vertices[6] = xMax;
  6.1053 +        vertices[7] = yMax;
  6.1054 +        glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  6.1055 +        glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  6.1056 +    }
  6.1057 +    glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
  6.1058 +    if (glGetError() != GL_NO_ERROR)
  6.1059 +    {
  6.1060 +        SDL_SetError("Failed to render lines");
  6.1061 +        return -1;
  6.1062 +    }
  6.1063 +    return 0;
  6.1064 +}
  6.1065 +
  6.1066 +static int
  6.1067 +GLES2_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect,
  6.1068 +                 const SDL_Rect *dstrect)
  6.1069 +{
  6.1070 +    GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
  6.1071 +    GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
  6.1072 +    GLES2_ImageSource sourceType;
  6.1073 +    SDL_BlendMode blendMode;
  6.1074 +    int alpha;
  6.1075 +    GLfloat vertices[8];
  6.1076 +    GLfloat texCoords[8];
  6.1077 +    GLuint locTexture;
  6.1078 +    GLuint locModulation;
  6.1079 +    GLuint locColorTable;
  6.1080 +
  6.1081 +    GLES2_ActivateRenderer(renderer);
  6.1082 +
  6.1083 +    /* Activate an appropriate shader and set the projection matrix */
  6.1084 +    blendMode = texture->blendMode;
  6.1085 +    alpha = texture->a;
  6.1086 +    sourceType = GLES2_IMAGESOURCE_TEXTURE;
  6.1087 +    if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0)
  6.1088 +        return -1;
  6.1089 +
  6.1090 +    /* Select the target texture */
  6.1091 +    locTexture = rdata->current_program->uniform_locations[GLES2_UNIFORM_TEXTURE];
  6.1092 +    glGetError();
  6.1093 +    glActiveTexture(GL_TEXTURE0);
  6.1094 +    glBindTexture(tdata->texture_type, tdata->texture);
  6.1095 +    glUniform1i(locTexture, 0);
  6.1096 +
  6.1097 +    /* Configure texture blending */
  6.1098 +    GLES2_SetBlendMode(blendMode);
  6.1099 +
  6.1100 +    /* Configure color modulation */
  6.1101 +    locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
  6.1102 +    glUniform4f(locModulation,
  6.1103 +                texture->r / 255.0f,
  6.1104 +                texture->g / 255.0f,
  6.1105 +                texture->b / 255.0f,
  6.1106 +                alpha / 255.0f);
  6.1107 +
  6.1108 +    /* Emit the textured quad */
  6.1109 +    glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
  6.1110 +    glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
  6.1111 +    vertices[0] = (GLfloat)dstrect->x;
  6.1112 +    vertices[1] = (GLfloat)dstrect->y;
  6.1113 +    vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
  6.1114 +    vertices[3] = (GLfloat)dstrect->y;
  6.1115 +    vertices[4] = (GLfloat)dstrect->x;
  6.1116 +    vertices[5] = (GLfloat)(dstrect->y + dstrect->h);
  6.1117 +    vertices[6] = (GLfloat)(dstrect->x + dstrect->w);
  6.1118 +    vertices[7] = (GLfloat)(dstrect->y + dstrect->h);
  6.1119 +    glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
  6.1120 +    texCoords[0] = srcrect->x / (GLfloat)texture->w;
  6.1121 +    texCoords[1] = srcrect->y / (GLfloat)texture->h;
  6.1122 +    texCoords[2] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
  6.1123 +    texCoords[3] = srcrect->y / (GLfloat)texture->h;
  6.1124 +    texCoords[4] = srcrect->x / (GLfloat)texture->w;
  6.1125 +    texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  6.1126 +    texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
  6.1127 +    texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  6.1128 +    glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
  6.1129 +    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  6.1130 +    glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
  6.1131 +    glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
  6.1132 +    if (glGetError() != GL_NO_ERROR)
  6.1133 +    {
  6.1134 +        SDL_SetError("Failed to render texture");
  6.1135 +        return -1;
  6.1136 +    }
  6.1137 +    return 0;
  6.1138 +}
  6.1139 +
  6.1140 +static void
  6.1141 +GLES2_RenderPresent(SDL_Renderer *renderer)
  6.1142 +{
  6.1143 +    GLES2_ActivateRenderer(renderer);
  6.1144 +
  6.1145 +    /* Tell the video driver to swap buffers */
  6.1146 +    SDL_GL_SwapWindow(renderer->window);
  6.1147 +}
  6.1148 +
  6.1149 +/*************************************************************************************************
  6.1150 + * Renderer instantiation                                                                        *
  6.1151 + *************************************************************************************************/
  6.1152 +
  6.1153 +#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
  6.1154 +
  6.1155 +static SDL_Renderer *
  6.1156 +GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
  6.1157 +{
  6.1158 +    SDL_Renderer *renderer;
  6.1159 +    GLES2_DriverContext *rdata;
  6.1160 +    GLint nFormats;
  6.1161 +#ifndef ZUNE_HD
  6.1162 +    GLboolean hasCompiler;
  6.1163 +#endif
  6.1164 +
  6.1165 +    /* Create the renderer struct */
  6.1166 +    renderer = (SDL_Renderer *)SDL_calloc(1, sizeof(SDL_Renderer));
  6.1167 +    rdata = (GLES2_DriverContext *)SDL_calloc(1, sizeof(GLES2_DriverContext));
  6.1168 +    if (!renderer)
  6.1169 +    {
  6.1170 +        SDL_OutOfMemory();
  6.1171 +        SDL_free(renderer);
  6.1172 +        SDL_free(rdata);
  6.1173 +        return NULL;
  6.1174 +    }
  6.1175 +    renderer->info = GLES2_RenderDriver.info;
  6.1176 +    renderer->window = window;
  6.1177 +    renderer->driverdata = rdata;
  6.1178 +
  6.1179 +    /* Create the GL context */
  6.1180 +    rdata->context = SDL_GL_CreateContext(window);
  6.1181 +    if (!rdata->context)
  6.1182 +    {
  6.1183 +        SDL_free(renderer);
  6.1184 +        SDL_free(rdata);
  6.1185 +        return NULL;
  6.1186 +    }
  6.1187 +
  6.1188 +    /* Determine supported shader formats */
  6.1189 +    /* HACK: glGetInteger is broken on the Zune HD's compositor, so we just hardcode this */
  6.1190 +    glGetError();
  6.1191 +#ifdef ZUNE_HD
  6.1192 +    nFormats = 1;
  6.1193 +#else /* !ZUNE_HD */
  6.1194 +    glGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &nFormats);
  6.1195 +    glGetBooleanv(GL_SHADER_COMPILER, &hasCompiler);
  6.1196 +    if (hasCompiler)
  6.1197 +        ++nFormats;
  6.1198 +#endif /* ZUNE_HD */
  6.1199 +    rdata->shader_formats = (GLenum *)SDL_calloc(nFormats, sizeof(GLenum));
  6.1200 +    if (!rdata->shader_formats)
  6.1201 +    {
  6.1202 +        SDL_OutOfMemory();
  6.1203 +        SDL_free(renderer);
  6.1204 +        SDL_free(rdata);
  6.1205 +        return NULL;
  6.1206 +    }
  6.1207 +    rdata->shader_format_count = nFormats;
  6.1208 +#ifdef ZUNE_HD
  6.1209 +    rdata->shader_formats[0] = GL_NVIDIA_PLATFORM_BINARY_NV;
  6.1210 +#else /* !ZUNE_HD */
  6.1211 +    glGetIntegerv(GL_SHADER_BINARY_FORMATS, (GLint *)rdata->shader_formats);
  6.1212 +    if (glGetError() != GL_NO_ERROR)
  6.1213 +    {
  6.1214 +        SDL_SetError("Failed to query supported shader formats");
  6.1215 +        SDL_free(renderer);
  6.1216 +        SDL_free(rdata->shader_formats);
  6.1217 +        SDL_free(rdata);
  6.1218 +        return NULL;
  6.1219 +    }
  6.1220 +    if (hasCompiler)
  6.1221 +        rdata->shader_formats[nFormats - 1] = (GLenum)-1;
  6.1222 +#endif /* ZUNE_HD */
  6.1223 +
  6.1224 +    /* Populate the function pointers for the module */
  6.1225 +    renderer->WindowEvent         = &GLES2_WindowEvent;
  6.1226 +    renderer->CreateTexture       = &GLES2_CreateTexture;
  6.1227 +    renderer->UpdateTexture       = &GLES2_UpdateTexture;
  6.1228 +    renderer->LockTexture         = &GLES2_LockTexture;
  6.1229 +    renderer->UnlockTexture       = &GLES2_UnlockTexture;
  6.1230 +    renderer->RenderClear         = &GLES2_RenderClear;
  6.1231 +    renderer->RenderDrawPoints    = &GLES2_RenderDrawPoints;
  6.1232 +    renderer->RenderDrawLines     = &GLES2_RenderDrawLines;
  6.1233 +    renderer->RenderFillRects     = &GLES2_RenderFillRects;
  6.1234 +    renderer->RenderCopy          = &GLES2_RenderCopy;
  6.1235 +    renderer->RenderPresent       = &GLES2_RenderPresent;
  6.1236 +    renderer->DestroyTexture      = &GLES2_DestroyTexture;
  6.1237 +    renderer->DestroyRenderer     = &GLES2_DestroyRenderer;
  6.1238 +    return renderer;
  6.1239 +}
  6.1240 +
  6.1241 +#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
  6.1242 +
  6.1243 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/render/opengles2/SDL_shaders_gles2.c	Sun Feb 06 00:00:13 2011 -0800
     7.3 @@ -0,0 +1,550 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 2010 itsnotabigtruck.
     7.7 +
     7.8 +    Permission is hereby granted, free of charge, to any person obtaining a
     7.9 +    copy of this software and associated documentation files (the "Software"),
    7.10 +    to deal in the Software without restriction, including without limitation
    7.11 +    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    7.12 +    and/or sell copies of the Software, and to permit persons to whom the
    7.13 +    Software is furnished to do so, subject to the following conditions:
    7.14 +
    7.15 +    The above copyright notice and this permission notice shall be included in
    7.16 +    all copies or substantial portions of the Software.
    7.17 +
    7.18 +    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    7.19 +    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    7.20 +    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    7.21 +    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    7.22 +    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    7.23 +    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    7.24 +    DEALINGS IN THE SOFTWARE.
    7.25 +*/
    7.26 +
    7.27 +#include "SDL_config.h"
    7.28 +
    7.29 +#if SDL_VIDEO_RENDER_OGL_ES2
    7.30 +
    7.31 +#ifdef __IPHONEOS__
    7.32 +#include <OpenGLES/ES2/gl.h>
    7.33 +#include <OpenGLES/ES2/glext.h>
    7.34 +#else
    7.35 +#include <GLES2/gl2.h>
    7.36 +#include <GLES2/gl2ext.h>
    7.37 +#endif
    7.38 +#include "SDL_video.h"
    7.39 +#include "SDL_shaders_gles2.h"
    7.40 +#include "SDL_stdinc.h"
    7.41 +
    7.42 +/*************************************************************************************************
    7.43 + * Vertex/fragment shader source                                                                 *
    7.44 + *************************************************************************************************/
    7.45 +
    7.46 +static const Uint8 GLES2_VertexSrc_Default_[] = " \
    7.47 +    uniform mat4 u_projection; \
    7.48 +    attribute vec4 a_position; \
    7.49 +    attribute vec2 a_texCoord; \
    7.50 +    varying vec2 v_texCoord; \
    7.51 +    \
    7.52 +    void main() \
    7.53 +    { \
    7.54 +        v_texCoord = a_texCoord; \
    7.55 +        gl_Position = u_projection * a_position; \
    7.56 +        gl_PointSize = 1.0; \
    7.57 +    } \
    7.58 +";
    7.59 +
    7.60 +static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \
    7.61 +    precision mediump float; \
    7.62 +    uniform vec4 u_color; \
    7.63 +    \
    7.64 +    void main() \
    7.65 +    { \
    7.66 +        gl_FragColor = u_color; \
    7.67 +    } \
    7.68 +";
    7.69 +
    7.70 +static const Uint8 GLES2_FragmentSrc_TextureSrc_[] = " \
    7.71 +    precision mediump float; \
    7.72 +    uniform sampler2D u_texture; \
    7.73 +    uniform vec4 u_modulation; \
    7.74 +    varying vec2 v_texCoord; \
    7.75 +    \
    7.76 +    void main() \
    7.77 +    { \
    7.78 +        gl_FragColor = texture2D(u_texture, v_texCoord); \
    7.79 +        gl_FragColor *= u_modulation; \
    7.80 +    } \
    7.81 +";
    7.82 +
    7.83 +static const GLES2_ShaderInstance GLES2_VertexSrc_Default = {
    7.84 +    GL_VERTEX_SHADER,
    7.85 +    GLES2_SOURCE_SHADER,
    7.86 +    sizeof(GLES2_VertexSrc_Default_),
    7.87 +    GLES2_VertexSrc_Default_
    7.88 +};
    7.89 +
    7.90 +static const GLES2_ShaderInstance GLES2_FragmentSrc_SolidSrc = {
    7.91 +    GL_FRAGMENT_SHADER,
    7.92 +    GLES2_SOURCE_SHADER,
    7.93 +    sizeof(GLES2_FragmentSrc_SolidSrc_),
    7.94 +    GLES2_FragmentSrc_SolidSrc_
    7.95 +};
    7.96 +
    7.97 +static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureSrc = {
    7.98 +    GL_FRAGMENT_SHADER,
    7.99 +    GLES2_SOURCE_SHADER,
   7.100 +    sizeof(GLES2_FragmentSrc_TextureSrc_),
   7.101 +    GLES2_FragmentSrc_TextureSrc_
   7.102 +};
   7.103 +
   7.104 +/*************************************************************************************************
   7.105 + * Vertex/fragment shader binaries (NVIDIA Tegra 1/2)                                            *
   7.106 + *************************************************************************************************/
   7.107 +
   7.108 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.109 +
   7.110 +#define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
   7.111 +
   7.112 +static const Uint8 GLES2_VertexTegra_Default_[] = {
   7.113 +    243, 193, 1, 142, 31, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.114 +    0, 0, 46, 0, 0, 0, 48, 0, 0, 0, 2, 0, 0, 0, 85, 0, 0, 0, 2, 0, 0, 0, 24, 0, 0, 0, 3, 0, 0, 0,
   7.115 +    91, 0, 0, 0, 1, 0, 0, 0, 16, 0, 0, 0, 5, 0, 0, 0, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.116 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 95, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0,
   7.117 +    13, 0, 0, 0, 102, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.118 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.119 +    0, 0, 0, 16, 0, 0, 0, 104, 0, 0, 0, 1, 0, 0, 0, 32, 0, 0, 0, 17, 0, 0, 0, 112, 0, 0, 0, 0, 0,
   7.120 +    0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 112, 0, 0, 0, 80, 0, 0, 0, 80, 0, 0, 0, 19, 0, 0, 0, 132, 0,
   7.121 +    0, 0, 104, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.122 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 97,
   7.123 +    95, 112, 111, 115, 105, 116, 105, 111, 110, 0, 97, 95, 116, 101, 120, 67, 111, 111, 114, 100,
   7.124 +    0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 112, 114, 111, 106, 101, 99,
   7.125 +    116, 105, 111, 110, 0, 0, 0, 0, 0, 0, 0, 82, 139, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 80, 139, 0,
   7.126 +    0, 1, 0, 0, 0, 22, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 33, 0, 0, 0, 92, 139, 0, 0,
   7.127 +    1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 240, 0, 0, 0, 0, 0, 0, 1, 0,
   7.128 +    0, 0, 64, 0, 0, 0, 80, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 193, 0, 0, 0,
   7.129 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.130 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.131 +    0, 0, 0, 0, 128, 63, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 66, 24, 0, 6, 34, 108, 28,
   7.132 +    0, 0, 42, 16, 128, 0, 195, 192, 6, 129, 252, 255, 65, 96, 108, 28, 0, 0, 0, 0, 0, 1, 195, 192,
   7.133 +    6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 8, 1, 64, 0, 131, 192, 6, 1, 156, 159, 65, 96, 108,
   7.134 +    28, 0, 0, 85, 32, 0, 1, 195, 192, 6, 1, 252, 255, 33, 96, 108, 156, 31, 64, 0, 64, 64, 0, 131,
   7.135 +    192, 134, 1, 152, 31, 65, 96, 108, 156, 31, 64, 127, 48, 0, 1, 195, 192, 6, 129, 129, 255, 33,
   7.136 +    96
   7.137 +};
   7.138 +
   7.139 +static const Uint8 GLES2_FragmentTegra_None_SolidSrc_[] = {
   7.140 +    155, 191, 159, 1, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.141 +    0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75,
   7.142 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
   7.143 +    75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0,
   7.144 +    0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.145 +    22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4,
   7.146 +    0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0,
   7.147 +    0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0,
   7.148 +    0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0,
   7.149 +    0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.150 +    0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
   7.151 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0,
   7.152 +    0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0,
   7.153 +    0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0,
   7.154 +    0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
   7.155 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1,
   7.156 +    0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0, 0, 0,
   7.157 +    0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 0, 40, 0, 0, 0, 242, 65, 63,
   7.158 +    192, 200, 0, 0, 0, 242, 65, 63, 128, 168, 0, 0, 0, 242, 65, 63, 64, 72, 0, 0, 0, 242, 65, 63,
   7.159 +    1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0
   7.160 +};
   7.161 +
   7.162 +static const Uint8 GLES2_FragmentTegra_Alpha_SolidSrc_[] = {
   7.163 +    169, 153, 195, 28, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.164 +    0, 0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75,
   7.165 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
   7.166 +    75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0,
   7.167 +    0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.168 +    22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4,
   7.169 +    0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0,
   7.170 +    0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0,
   7.171 +    0, 220, 0, 0, 0, 220, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0,
   7.172 +    0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.173 +    0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
   7.174 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 118, 118, 17, 241, 0, 0, 0, 240, 0,
   7.175 +    0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0,
   7.176 +    0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 21, 32, 0, 0, 0, 0,
   7.177 +    0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
   7.178 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78,
   7.179 +    1, 0, 0, 0, 3, 0, 0, 0, 3, 0, 65, 37, 8, 0, 129, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 21, 0,
   7.180 +    0, 0, 0, 3, 0, 1, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 39, 0, 0, 0, 0, 0, 0, 0,
   7.181 +    0, 0, 0, 0, 0, 3, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0, 9, 0, 0, 0, 24, 0, 4, 40, 232, 231, 15,
   7.182 +    0, 0, 242, 65, 62, 194, 72, 1, 0, 0, 250, 65, 63, 194, 40, 1, 0, 0, 250, 65, 63, 192, 168, 1,
   7.183 +    0, 0, 242, 1, 64, 192, 168, 1, 0, 0, 242, 1, 68, 168, 32, 0, 0, 0, 50, 64, 0, 192, 168, 15,
   7.184 +    0, 0, 242, 1, 66, 168, 64, 0, 16, 0, 242, 65, 1, 232, 231, 15, 0, 0, 242, 65, 62, 168, 160,
   7.185 +    0, 0, 0, 50, 64, 2, 104, 192, 0, 0, 36, 48, 66, 4, 232, 231, 15, 0, 0, 242, 65, 62, 3, 0, 6,
   7.186 +    40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 41, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0
   7.187 +};
   7.188 +
   7.189 +static const Uint8 GLES2_FragmentTegra_Additive_SolidSrc_[] = {
   7.190 +    59, 71, 42, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0,
   7.191 +    0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75,
   7.192 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
   7.193 +    75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0,
   7.194 +    0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.195 +    22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4,
   7.196 +    0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0,
   7.197 +    0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0,
   7.198 +    0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0,
   7.199 +    0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.200 +    0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
   7.201 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 22, 22, 17, 241, 0, 0, 0, 240, 0,
   7.202 +    0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0,
   7.203 +    0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0,
   7.204 +    0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
   7.205 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78,
   7.206 +    1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0,
   7.207 +    0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 192, 200, 0, 0, 0, 26,
   7.208 +    0, 70, 192, 40, 0, 0, 0, 2, 0, 64, 192, 72, 0, 0, 0, 10, 0, 66, 192, 168, 0, 0, 0, 18, 0, 68,
   7.209 +    1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0
   7.210 +};
   7.211 +
   7.212 +static const Uint8 GLES2_FragmentTegra_Modulated_SolidSrc_[] = {
   7.213 +    37, 191, 49, 17, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0, 0,
   7.214 +    0, 8, 0, 0, 0, 8, 0, 0, 0, 2, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 75,
   7.215 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0,
   7.216 +    75, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 75, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 13, 0,
   7.217 +    0, 0, 82, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 14, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.218 +    22, 0, 0, 0, 84, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 92, 0, 0, 0, 1, 0, 0, 0, 4,
   7.219 +    0, 0, 0, 15, 0, 0, 0, 93, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 113, 0, 0, 0, 0, 0,
   7.220 +    0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 113, 0, 0,
   7.221 +    0, 108, 0, 0, 0, 108, 0, 0, 0, 20, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 0, 0,
   7.222 +    0, 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.223 +    0, 117, 95, 99, 111, 108, 111, 114, 0, 0, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
   7.224 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 32, 32, 17, 241, 0, 0, 0, 240, 0,
   7.225 +    0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0,
   7.226 +    0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0,
   7.227 +    0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
   7.228 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78,
   7.229 +    1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 0,
   7.230 +    0, 0, 0, 1, 0, 1, 39, 0, 0, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242,
   7.231 +    1, 70, 8, 32, 0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68,
   7.232 +    1, 0, 6, 40, 0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0
   7.233 +};
   7.234 +
   7.235 +static const Uint8 GLES2_FragmentTegra_None_TextureSrc_[] = {
   7.236 +    220, 217, 41, 211, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.237 +    0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
   7.238 +    82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
   7.239 +    0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0,
   7.240 +    13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4,
   7.241 +    0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0,
   7.242 +    0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0,
   7.243 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135,
   7.244 +    0, 0, 0, 120, 0, 0, 0, 120, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21,
   7.245 +    0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0,
   7.246 +    0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108,
   7.247 +    97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0,
   7.248 +    2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1,
   7.249 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0,
   7.250 +    0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
   7.251 +    0, 0, 1, 0, 0, 0, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240,
   7.252 +    0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, 0,
   7.253 +    0, 0, 1, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0,
   7.254 +    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.255 +    0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 65, 37, 0, 0, 0, 0, 1, 0,
   7.256 +    0, 21, 0, 0, 0, 0, 1, 0, 1, 38, 1, 0, 0, 0, 2, 0, 4, 38, 186, 81, 78, 16, 2, 1, 0, 0, 1, 0,
   7.257 +    1, 39, 0, 4, 0, 0, 1, 0, 1, 40, 1, 0, 0, 0, 8, 0, 4, 40, 104, 192, 0, 0, 0, 242, 1, 70, 8, 32,
   7.258 +    0, 0, 0, 242, 1, 64, 40, 64, 0, 0, 0, 242, 1, 66, 72, 160, 0, 0, 0, 242, 1, 68, 1, 0, 6, 40,
   7.259 +    0, 0, 0, 0, 1, 0, 1, 41, 5, 0, 2, 0
   7.260 +};
   7.261 +
   7.262 +static const Uint8 GLES2_FragmentTegra_Alpha_TextureSrc_[] = {
   7.263 +    71, 202, 114, 229, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.264 +    0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
   7.265 +    82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
   7.266 +    0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0,
   7.267 +    13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4,
   7.268 +    0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0,
   7.269 +    0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0,
   7.270 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135,
   7.271 +    0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21,
   7.272 +    0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0,
   7.273 +    0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108,
   7.274 +    97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0,
   7.275 +    2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1,
   7.276 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0,
   7.277 +    0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
   7.278 +    0, 0, 1, 118, 118, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0,
   7.279 +    240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0,
   7.280 +    1, 0, 0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16,
   7.281 +    0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.282 +    0, 0, 0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0,
   7.283 +    8, 0, 129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186,
   7.284 +    81, 78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0,
   7.285 +    0, 0, 16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0,
   7.286 +    0, 242, 1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 154, 192, 0, 0, 37, 34, 64, 3, 8, 32, 0, 0, 5, 58,
   7.287 +    208, 4, 40, 64, 0, 0, 5, 50, 208, 4, 72, 160, 0, 0, 37, 42, 208, 4, 2, 0, 6, 40, 0, 0, 0, 0,
   7.288 +    0, 0, 0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0
   7.289 +};
   7.290 +
   7.291 +static const Uint8 GLES2_FragmentTegra_Additive_TextureSrc_[] = {
   7.292 +    161, 234, 193, 234, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.293 +    0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
   7.294 +    82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
   7.295 +    0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0,
   7.296 +    13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4,
   7.297 +    0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0,
   7.298 +    0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0,
   7.299 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135,
   7.300 +    0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21,
   7.301 +    0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0,
   7.302 +    0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108,
   7.303 +    97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0,
   7.304 +    2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1,
   7.305 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0,
   7.306 +    0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
   7.307 +    0, 0, 1, 22, 22, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240,
   7.308 +    0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0,
   7.309 +    0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0,
   7.310 +    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.311 +    0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0,
   7.312 +    129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81,
   7.313 +    78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0,
   7.314 +    16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 104, 32, 1, 0, 0, 242, 1, 70, 8, 192, 1, 0, 0, 242,
   7.315 +    1, 64, 72, 64, 1, 0, 0, 242, 1, 68, 136, 192, 0, 0, 0, 26, 64, 4, 136, 32, 0, 0, 0, 2, 64, 7,
   7.316 +    136, 64, 0, 0, 0, 10, 64, 6, 136, 160, 0, 0, 0, 18, 64, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0, 0,
   7.317 +    0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0
   7.318 +};
   7.319 +
   7.320 +static const Uint8 GLES2_FragmentTegra_Modulated_TextureSrc_[] = {
   7.321 +    75, 132, 201, 227, 47, 109, 131, 38, 6, 0, 1, 0, 5, 0, 0, 0, 17, 0, 0, 0, 1, 0, 0, 0, 73, 0,
   7.322 +    0, 0, 34, 0, 0, 0, 36, 0, 0, 0, 2, 0, 0, 0, 82, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0,
   7.323 +    82, 0, 0, 0, 1, 0, 0, 0, 20, 0, 0, 0, 6, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0,
   7.324 +    0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 87, 0, 0, 0, 2, 0, 0, 0, 56, 0, 0, 0,
   7.325 +    13, 0, 0, 0, 101, 0, 0, 0, 4, 0, 0, 0, 16, 0, 0, 0, 14, 0, 0, 0, 105, 0, 0, 0, 1, 0, 0, 0, 4,
   7.326 +    0, 0, 0, 22, 0, 0, 0, 106, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 23, 0, 0, 0, 114, 0, 0, 0, 1, 0,
   7.327 +    0, 0, 4, 0, 0, 0, 15, 0, 0, 0, 115, 0, 0, 0, 1, 0, 0, 0, 80, 0, 0, 0, 17, 0, 0, 0, 135, 0, 0,
   7.328 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 135,
   7.329 +    0, 0, 0, 176, 0, 0, 0, 176, 0, 0, 0, 20, 0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21,
   7.330 +    0, 0, 0, 135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 109, 97, 110, 70, 73, 0, 0, 0, 0, 0, 0, 0, 0,
   7.331 +    0, 0, 0, 118, 95, 116, 101, 120, 67, 111, 111, 114, 100, 0, 117, 95, 109, 111, 100, 117, 108,
   7.332 +    97, 116, 105, 111, 110, 0, 117, 95, 116, 101, 120, 116, 117, 114, 101, 0, 0, 0, 0, 0, 0, 0,
   7.333 +    2, 0, 0, 0, 0, 0, 0, 0, 220, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 82, 139, 0, 0, 1, 0, 0, 0, 1,
   7.334 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 94, 139, 0, 0, 1, 0, 0, 0, 1, 0, 0,
   7.335 +    0, 2, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 5, 48, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0,
   7.336 +    0, 0, 1, 32, 32, 17, 241, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 240,
   7.337 +    0, 0, 0, 240, 0, 0, 0, 240, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 7, 0, 0, 0, 2, 0, 0, 0, 1, 0,
   7.338 +    0, 0, 2, 0, 0, 0, 21, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 16, 0, 0, 0, 16, 0, 0,
   7.339 +    0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   7.340 +    0, 0, 65, 82, 50, 48, 45, 66, 73, 78, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 65, 37, 0, 0, 0, 0, 8, 0,
   7.341 +    129, 0, 1, 0, 0, 21, 0, 0, 0, 0, 2, 0, 1, 38, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 4, 38, 186, 81,
   7.342 +    78, 16, 2, 1, 0, 0, 2, 0, 1, 39, 0, 4, 0, 0, 0, 0, 0, 0, 2, 0, 1, 40, 1, 0, 0, 0, 5, 0, 0, 0,
   7.343 +    16, 0, 4, 40, 40, 160, 1, 0, 0, 242, 1, 66, 8, 192, 1, 0, 0, 242, 1, 64, 104, 32, 1, 0, 0, 242,
   7.344 +    1, 70, 72, 64, 1, 0, 0, 242, 1, 68, 104, 192, 0, 0, 0, 242, 65, 4, 232, 32, 0, 0, 0, 242, 65,
   7.345 +    0, 40, 64, 0, 0, 0, 242, 65, 6, 72, 160, 0, 0, 0, 242, 65, 5, 2, 0, 6, 40, 0, 0, 0, 0, 0, 0,
   7.346 +    0, 0, 2, 0, 1, 41, 0, 0, 0, 0, 5, 0, 2, 0
   7.347 +};
   7.348 +
   7.349 +static const GLES2_ShaderInstance GLES2_VertexTegra_Default = {
   7.350 +    GL_VERTEX_SHADER,
   7.351 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.352 +    sizeof(GLES2_VertexTegra_Default_),
   7.353 +    GLES2_VertexTegra_Default_
   7.354 +};
   7.355 +
   7.356 +static const GLES2_ShaderInstance GLES2_FragmentTegra_None_SolidSrc = {
   7.357 +    GL_FRAGMENT_SHADER,
   7.358 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.359 +    sizeof(GLES2_FragmentTegra_None_SolidSrc_),
   7.360 +    GLES2_FragmentTegra_None_SolidSrc_
   7.361 +};
   7.362 +
   7.363 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_SolidSrc = {
   7.364 +    GL_FRAGMENT_SHADER,
   7.365 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.366 +    sizeof(GLES2_FragmentTegra_Alpha_SolidSrc_),
   7.367 +    GLES2_FragmentTegra_Alpha_SolidSrc_
   7.368 +};
   7.369 +
   7.370 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_SolidSrc = {
   7.371 +    GL_FRAGMENT_SHADER,
   7.372 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.373 +    sizeof(GLES2_FragmentTegra_Additive_SolidSrc_),
   7.374 +    GLES2_FragmentTegra_Additive_SolidSrc_
   7.375 +};
   7.376 +
   7.377 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_SolidSrc = {
   7.378 +    GL_FRAGMENT_SHADER,
   7.379 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.380 +    sizeof(GLES2_FragmentTegra_Modulated_SolidSrc_),
   7.381 +    GLES2_FragmentTegra_Modulated_SolidSrc_
   7.382 +};
   7.383 +
   7.384 +static const GLES2_ShaderInstance GLES2_FragmentTegra_None_TextureSrc = {
   7.385 +    GL_FRAGMENT_SHADER,
   7.386 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.387 +    sizeof(GLES2_FragmentTegra_None_TextureSrc_),
   7.388 +    GLES2_FragmentTegra_None_TextureSrc_
   7.389 +};
   7.390 +
   7.391 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Alpha_TextureSrc = {
   7.392 +    GL_FRAGMENT_SHADER,
   7.393 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.394 +    sizeof(GLES2_FragmentTegra_Alpha_TextureSrc_),
   7.395 +    GLES2_FragmentTegra_Alpha_TextureSrc_
   7.396 +};
   7.397 +
   7.398 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Additive_TextureSrc = {
   7.399 +    GL_FRAGMENT_SHADER,
   7.400 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.401 +    sizeof(GLES2_FragmentTegra_Additive_TextureSrc_),
   7.402 +    GLES2_FragmentTegra_Additive_TextureSrc_
   7.403 +};
   7.404 +
   7.405 +static const GLES2_ShaderInstance GLES2_FragmentTegra_Modulated_TextureSrc = {
   7.406 +    GL_FRAGMENT_SHADER,
   7.407 +    GL_NVIDIA_PLATFORM_BINARY_NV,
   7.408 +    sizeof(GLES2_FragmentTegra_Modulated_TextureSrc_),
   7.409 +    GLES2_FragmentTegra_Modulated_TextureSrc_
   7.410 +};
   7.411 +
   7.412 +#endif /* GLES2_INCLUDE_NVIDIA_SHADERS */
   7.413 +
   7.414 +/*************************************************************************************************
   7.415 + * Vertex/fragment shader definitions                                                            *
   7.416 + *************************************************************************************************/
   7.417 +
   7.418 +static GLES2_Shader GLES2_VertexShader_Default = {
   7.419 +    2,
   7.420 +    {
   7.421 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.422 +        &GLES2_VertexTegra_Default,
   7.423 +#endif
   7.424 +        &GLES2_VertexSrc_Default
   7.425 +    }
   7.426 +};
   7.427 +
   7.428 +static GLES2_Shader GLES2_FragmentShader_None_SolidSrc = {
   7.429 +    2,
   7.430 +    {
   7.431 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.432 +        &GLES2_FragmentTegra_None_SolidSrc,
   7.433 +#endif
   7.434 +        &GLES2_FragmentSrc_SolidSrc
   7.435 +    }
   7.436 +};
   7.437 +
   7.438 +static GLES2_Shader GLES2_FragmentShader_Alpha_SolidSrc = {
   7.439 +    2,
   7.440 +    {
   7.441 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.442 +        &GLES2_FragmentTegra_Alpha_SolidSrc,
   7.443 +#endif
   7.444 +        &GLES2_FragmentSrc_SolidSrc
   7.445 +    }
   7.446 +};
   7.447 +
   7.448 +static GLES2_Shader GLES2_FragmentShader_Additive_SolidSrc = {
   7.449 +    2,
   7.450 +    {
   7.451 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.452 +        &GLES2_FragmentTegra_Additive_SolidSrc,
   7.453 +#endif
   7.454 +        &GLES2_FragmentSrc_SolidSrc
   7.455 +    }
   7.456 +};
   7.457 +
   7.458 +static GLES2_Shader GLES2_FragmentShader_Modulated_SolidSrc = {
   7.459 +    2,
   7.460 +    {
   7.461 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.462 +        &GLES2_FragmentTegra_Modulated_SolidSrc,
   7.463 +#endif
   7.464 +        &GLES2_FragmentSrc_SolidSrc
   7.465 +    }
   7.466 +};
   7.467 +
   7.468 +static GLES2_Shader GLES2_FragmentShader_None_TextureSrc = {
   7.469 +    2,
   7.470 +    {
   7.471 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.472 +        &GLES2_FragmentTegra_None_TextureSrc,
   7.473 +#endif
   7.474 +        &GLES2_FragmentSrc_TextureSrc
   7.475 +    }
   7.476 +};
   7.477 +
   7.478 +static GLES2_Shader GLES2_FragmentShader_Alpha_TextureSrc = {
   7.479 +    2,
   7.480 +    {
   7.481 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.482 +        &GLES2_FragmentTegra_Alpha_TextureSrc,
   7.483 +#endif
   7.484 +        &GLES2_FragmentSrc_TextureSrc
   7.485 +    }
   7.486 +};
   7.487 +
   7.488 +static GLES2_Shader GLES2_FragmentShader_Additive_TextureSrc = {
   7.489 +    2,
   7.490 +    {
   7.491 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.492 +        &GLES2_FragmentTegra_Additive_TextureSrc,
   7.493 +#endif
   7.494 +        &GLES2_FragmentSrc_TextureSrc
   7.495 +    }
   7.496 +};
   7.497 +
   7.498 +static GLES2_Shader GLES2_FragmentShader_Modulated_TextureSrc = {
   7.499 +    2,
   7.500 +    {
   7.501 +#if GLES2_INCLUDE_NVIDIA_SHADERS
   7.502 +        &GLES2_FragmentTegra_Modulated_TextureSrc,
   7.503 +#endif
   7.504 +        &GLES2_FragmentSrc_TextureSrc
   7.505 +    }
   7.506 +};
   7.507 +
   7.508 +/*************************************************************************************************
   7.509 + * Shader selector                                                                               *
   7.510 + *************************************************************************************************/
   7.511 +
   7.512 +const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode)
   7.513 +{
   7.514 +    switch (type)
   7.515 +    {
   7.516 +    case GLES2_SHADER_VERTEX_DEFAULT:
   7.517 +        return &GLES2_VertexShader_Default;
   7.518 +    case GLES2_SHADER_FRAGMENT_SOLID_SRC:
   7.519 +        switch (blendMode)
   7.520 +        {
   7.521 +        case SDL_BLENDMODE_NONE:
   7.522 +            return &GLES2_FragmentShader_None_SolidSrc;
   7.523 +        case SDL_BLENDMODE_BLEND:
   7.524 +            return &GLES2_FragmentShader_Alpha_SolidSrc;
   7.525 +        case SDL_BLENDMODE_ADD:
   7.526 +            return &GLES2_FragmentShader_Additive_SolidSrc;
   7.527 +        case SDL_BLENDMODE_MOD:
   7.528 +            return &GLES2_FragmentShader_Modulated_SolidSrc;
   7.529 +        default:
   7.530 +            return NULL;
   7.531 +        }
   7.532 +    case GLES2_SHADER_FRAGMENT_TEXTURE_SRC:
   7.533 +        switch (blendMode)
   7.534 +        {
   7.535 +        case SDL_BLENDMODE_NONE:
   7.536 +            return &GLES2_FragmentShader_None_TextureSrc;
   7.537 +        case SDL_BLENDMODE_BLEND:
   7.538 +            return &GLES2_FragmentShader_Alpha_TextureSrc;
   7.539 +        case SDL_BLENDMODE_ADD:
   7.540 +            return &GLES2_FragmentShader_Additive_TextureSrc;
   7.541 +        case SDL_BLENDMODE_MOD:
   7.542 +            return &GLES2_FragmentShader_Modulated_TextureSrc;
   7.543 +        default:
   7.544 +            return NULL;
   7.545 +        }
   7.546 +    default:
   7.547 +        return NULL;
   7.548 +    }
   7.549 +}
   7.550 +
   7.551 +#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
   7.552 +
   7.553 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/render/opengles2/SDL_shaders_gles2.h	Sun Feb 06 00:00:13 2011 -0800
     8.3 @@ -0,0 +1,66 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 2010 itsnotabigtruck.
     8.7 +
     8.8 +    Permission is hereby granted, free of charge, to any person obtaining a
     8.9 +    copy of this software and associated documentation files (the "Software"),
    8.10 +    to deal in the Software without restriction, including without limitation
    8.11 +    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    8.12 +    and/or sell copies of the Software, and to permit persons to whom the
    8.13 +    Software is furnished to do so, subject to the following conditions:
    8.14 +
    8.15 +    The above copyright notice and this permission notice shall be included in
    8.16 +    all copies or substantial portions of the Software.
    8.17 +
    8.18 +    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    8.19 +    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    8.20 +    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    8.21 +    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    8.22 +    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    8.23 +    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    8.24 +    DEALINGS IN THE SOFTWARE.
    8.25 +*/
    8.26 +
    8.27 +#include "SDL_config.h"
    8.28 +
    8.29 +#if SDL_VIDEO_RENDER_OGL_ES2
    8.30 +
    8.31 +#ifndef SDL_shaderdata_h_
    8.32 +#define SDL_shaderdata_h_
    8.33 +
    8.34 +#ifdef __IPHONEOS__
    8.35 +#include <OpenGLES/ES2/gl.h>
    8.36 +#else
    8.37 +#include <GLES2/gl2.h>
    8.38 +#endif
    8.39 +
    8.40 +typedef struct GLES2_ShaderInstance
    8.41 +{
    8.42 +    GLenum type;
    8.43 +    GLenum format;
    8.44 +    int length;
    8.45 +    const void *data;
    8.46 +} GLES2_ShaderInstance;
    8.47 +
    8.48 +typedef struct GLES2_Shader
    8.49 +{
    8.50 +    int instance_count;
    8.51 +    const GLES2_ShaderInstance *instances[4];
    8.52 +} GLES2_Shader;
    8.53 +
    8.54 +typedef enum
    8.55 +{
    8.56 +    GLES2_SHADER_VERTEX_DEFAULT,
    8.57 +    GLES2_SHADER_FRAGMENT_SOLID_SRC,
    8.58 +    GLES2_SHADER_FRAGMENT_TEXTURE_SRC
    8.59 +} GLES2_ShaderType;
    8.60 +
    8.61 +#define GLES2_SOURCE_SHADER (GLenum)-1
    8.62 +
    8.63 +const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type, SDL_BlendMode blendMode);
    8.64 +
    8.65 +#endif /* SDL_shaderdata_h_ */
    8.66 +
    8.67 +#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
    8.68 +
    8.69 +/* vi: set ts=4 sw=4 expandtab: */