src/render/opengles2/SDL_render_gles2.c
changeset 5355 cc2215cda170
parent 5333 5d3a2cd4e8c9
child 5402 5d102cd8aef3
equal deleted inserted replaced
5354:a606515be168 5355:cc2215cda170
    56     GLenum texture_type;
    56     GLenum texture_type;
    57     GLenum pixel_format;
    57     GLenum pixel_format;
    58     GLenum pixel_type;
    58     GLenum pixel_type;
    59     void *pixel_data;
    59     void *pixel_data;
    60     size_t pitch;
    60     size_t pitch;
       
    61     GLenum scaleMode;
    61 } GLES2_TextureData;
    62 } GLES2_TextureData;
    62 
    63 
    63 typedef struct GLES2_ShaderCacheEntry
    64 typedef struct GLES2_ShaderCacheEntry
    64 {
    65 {
    65     GLuint id;
    66     GLuint id;
   116 } GLES2_ImageSource;
   117 } GLES2_ImageSource;
   117 
   118 
   118 typedef struct GLES2_DriverContext
   119 typedef struct GLES2_DriverContext
   119 {
   120 {
   120     SDL_GLContext *context;
   121     SDL_GLContext *context;
       
   122     struct {
       
   123         int blendMode;
       
   124         GLenum scaleMode;
       
   125         SDL_bool tex_coords;
       
   126     } current;
       
   127 
   121     int shader_format_count;
   128     int shader_format_count;
   122     GLenum *shader_formats;
   129     GLenum *shader_formats;
   123     GLES2_ShaderCache shader_cache;
   130     GLES2_ShaderCache shader_cache;
   124     GLES2_ProgramCache program_cache;
   131     GLES2_ProgramCache program_cache;
   125     GLES2_ProgramCacheEntry *current_program;
   132     GLES2_ProgramCacheEntry *current_program;
   257     }
   264     }
   258     tdata->texture = 0;
   265     tdata->texture = 0;
   259     tdata->texture_type = GL_TEXTURE_2D;
   266     tdata->texture_type = GL_TEXTURE_2D;
   260     tdata->pixel_format = format;
   267     tdata->pixel_format = format;
   261     tdata->pixel_type = type;
   268     tdata->pixel_type = type;
       
   269     tdata->scaleMode = GL_LINEAR;
   262 
   270 
   263     /* Allocate a blob for image data */
   271     /* Allocate a blob for image data */
   264     if (texture->access == SDL_TEXTUREACCESS_STREAMING)
   272     if (texture->access == SDL_TEXTUREACCESS_STREAMING)
   265     {
   273     {
   266         tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   274         tdata->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
   785 
   793 
   786     return 0;
   794     return 0;
   787 }
   795 }
   788 
   796 
   789 static void
   797 static void
   790 GLES2_SetBlendMode(int blendMode)
   798 GLES2_SetBlendMode(GLES2_DriverContext *rdata, int blendMode)
   791 {
   799 {
   792     switch (blendMode)
   800     if (blendMode != rdata->current.blendMode) {
   793     {
   801         switch (blendMode) {
   794     case SDL_BLENDMODE_NONE:
   802         default:
   795     default:
   803         case SDL_BLENDMODE_NONE:
   796         glDisable(GL_BLEND);
   804             glDisable(GL_BLEND);
   797         break;
   805             break;
   798     case SDL_BLENDMODE_BLEND:
   806         case SDL_BLENDMODE_BLEND:
   799         glEnable(GL_BLEND);
   807             glEnable(GL_BLEND);
   800         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   808             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   801         break;
   809             break;
   802     case SDL_BLENDMODE_ADD:
   810         case SDL_BLENDMODE_ADD:
   803         glEnable(GL_BLEND);
   811             glEnable(GL_BLEND);
   804         glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   812             glBlendFunc(GL_SRC_ALPHA, GL_ONE);
   805         break;
   813             break;
   806     case SDL_BLENDMODE_MOD:
   814         case SDL_BLENDMODE_MOD:
   807         glEnable(GL_BLEND);
   815             glEnable(GL_BLEND);
   808         glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   816             glBlendFunc(GL_ZERO, GL_SRC_COLOR);
   809         break;
   817             break;
   810     }
   818         }
   811 }
   819         rdata->current.blendMode = blendMode;
   812 
   820     }
   813 static int
   821 }
   814 GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
   822 
   815 {
   823 static void
   816     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   824 GLES2_SetTexCoords(GLES2_DriverContext * rdata, SDL_bool enabled)
   817     GLfloat *vertices;
   825 {
   818     SDL_BlendMode blendMode;
   826     if (enabled != rdata->current.tex_coords) {
   819     int alpha;
   827         if (enabled) {
       
   828             glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
       
   829         } else {
       
   830             glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
       
   831         }
       
   832         rdata->current.tex_coords = enabled;
       
   833     }
       
   834 }
       
   835 
       
   836 static int
       
   837 GLES2_SetDrawingState(SDL_Renderer * renderer)
       
   838 {
       
   839     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
       
   840     int blendMode = renderer->blendMode;
   820     GLuint locColor;
   841     GLuint locColor;
   821     int idx;
   842 
       
   843     glGetError();
   822 
   844 
   823     GLES2_ActivateRenderer(renderer);
   845     GLES2_ActivateRenderer(renderer);
   824 
   846 
   825     blendMode = renderer->blendMode;
   847     GLES2_SetBlendMode(rdata, blendMode);
   826     alpha = renderer->a;
   848 
       
   849     GLES2_SetTexCoords(rdata, SDL_FALSE);
   827 
   850 
   828     /* Activate an appropriate shader and set the projection matrix */
   851     /* Activate an appropriate shader and set the projection matrix */
   829     if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
   852     if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
   830         return -1;
   853         return -1;
   831 
   854 
   832     /* Select the color to draw with */
   855     /* Select the color to draw with */
   833     locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
   856     locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
   834     glGetError();
       
   835     glUniform4f(locColor,
   857     glUniform4f(locColor,
   836                 renderer->r * inv255f,
   858                 renderer->r * inv255f,
   837                 renderer->g * inv255f,
   859                 renderer->g * inv255f,
   838                 renderer->b * inv255f,
   860                 renderer->b * inv255f,
   839                 alpha * inv255f);
   861                 renderer->a * inv255f);
   840 
   862     return 0;
   841     /* Configure the correct blend mode */
   863 }
   842     GLES2_SetBlendMode(blendMode);
   864 
       
   865 static int
       
   866 GLES2_RenderDrawPoints(SDL_Renderer *renderer, const SDL_Point *points, int count)
       
   867 {
       
   868     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
       
   869     GLfloat *vertices;
       
   870     int idx;
       
   871 
       
   872     if (GLES2_SetDrawingState(renderer) < 0) {
       
   873         return -1;
       
   874     }
   843 
   875 
   844     /* Emit the specified vertices as points */
   876     /* Emit the specified vertices as points */
   845     vertices = SDL_stack_alloc(GLfloat, count * 2);
   877     vertices = SDL_stack_alloc(GLfloat, count * 2);
   846     for (idx = 0; idx < count; ++idx)
   878     for (idx = 0; idx < count; ++idx)
   847     {
   879     {
   849         GLfloat y = (GLfloat)points[idx].y + 0.5f;
   881         GLfloat y = (GLfloat)points[idx].y + 0.5f;
   850 
   882 
   851         vertices[idx * 2] = x;
   883         vertices[idx * 2] = x;
   852         vertices[(idx * 2) + 1] = y;
   884         vertices[(idx * 2) + 1] = y;
   853     }
   885     }
   854     glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   886     glGetError();
   855     glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   887     glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   856     glDrawArrays(GL_POINTS, 0, count);
   888     glDrawArrays(GL_POINTS, 0, count);
   857     glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
   858     SDL_stack_free(vertices);
   889     SDL_stack_free(vertices);
   859     if (glGetError() != GL_NO_ERROR)
   890     if (glGetError() != GL_NO_ERROR)
   860     {
   891     {
   861         SDL_SetError("Failed to render lines");
   892         SDL_SetError("Failed to render lines");
   862         return -1;
   893         return -1;
   867 static int
   898 static int
   868 GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
   899 GLES2_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
   869 {
   900 {
   870     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   901     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   871     GLfloat *vertices;
   902     GLfloat *vertices;
   872     SDL_BlendMode blendMode;
       
   873     int alpha;
       
   874     GLuint locColor;
       
   875     int idx;
   903     int idx;
   876 
   904 
   877     GLES2_ActivateRenderer(renderer);
   905     if (GLES2_SetDrawingState(renderer) < 0) {
   878 
   906         return -1;
   879     blendMode = renderer->blendMode;
   907     }
   880     alpha = renderer->a;
       
   881 
       
   882     /* Activate an appropriate shader and set the projection matrix */
       
   883     if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
       
   884         return -1;
       
   885 
       
   886     /* Select the color to draw with */
       
   887     locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
       
   888     glGetError();
       
   889     glUniform4f(locColor,
       
   890                 renderer->r * inv255f,
       
   891                 renderer->g * inv255f,
       
   892                 renderer->b * inv255f,
       
   893                 alpha * inv255f);
       
   894 
       
   895     /* Configure the correct blend mode */
       
   896     GLES2_SetBlendMode(blendMode);
       
   897 
   908 
   898     /* Emit a line strip including the specified vertices */
   909     /* Emit a line strip including the specified vertices */
   899     vertices = SDL_stack_alloc(GLfloat, count * 2);
   910     vertices = SDL_stack_alloc(GLfloat, count * 2);
   900     for (idx = 0; idx < count; ++idx)
   911     for (idx = 0; idx < count; ++idx)
   901     {
   912     {
   903         GLfloat y = (GLfloat)points[idx].y + 0.5f;
   914         GLfloat y = (GLfloat)points[idx].y + 0.5f;
   904 
   915 
   905         vertices[idx * 2] = x;
   916         vertices[idx * 2] = x;
   906         vertices[(idx * 2) + 1] = y;
   917         vertices[(idx * 2) + 1] = y;
   907     }
   918     }
   908     glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
   919     glGetError();
   909     glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   920     glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   910     glDrawArrays(GL_LINE_STRIP, 0, count);
   921     glDrawArrays(GL_LINE_STRIP, 0, count);
   911     glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
   912     SDL_stack_free(vertices);
   922     SDL_stack_free(vertices);
   913     if (glGetError() != GL_NO_ERROR)
   923     if (glGetError() != GL_NO_ERROR)
   914     {
   924     {
   915         SDL_SetError("Failed to render lines");
   925         SDL_SetError("Failed to render lines");
   916         return -1;
   926         return -1;
   921 static int
   931 static int
   922 GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
   932 GLES2_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
   923 {
   933 {
   924     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   934     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   925     GLfloat vertices[8];
   935     GLfloat vertices[8];
   926     SDL_BlendMode blendMode;
       
   927     int alpha;
       
   928     GLuint locColor;
       
   929     int idx;
   936     int idx;
   930 
   937 
   931     GLES2_ActivateRenderer(renderer);
   938     if (GLES2_SetDrawingState(renderer) < 0) {
   932 
   939         return -1;
   933     blendMode = renderer->blendMode;
   940     }
   934     alpha = renderer->a;
   941 
   935 
   942     /* Emit a line loop for each rectangle */
   936     /* Activate an appropriate shader and set the projection matrix */
       
   937     if (GLES2_SelectProgram(renderer, GLES2_IMAGESOURCE_SOLID, blendMode) < 0)
       
   938         return -1;
       
   939 
       
   940     /* Select the color to draw with */
       
   941     locColor = rdata->current_program->uniform_locations[GLES2_UNIFORM_COLOR];
       
   942     glGetError();
   943     glGetError();
   943     glUniform4f(locColor,
       
   944                 renderer->r * inv255f,
       
   945                 renderer->g * inv255f,
       
   946                 renderer->b * inv255f,
       
   947                 alpha * inv255f);
       
   948 
       
   949     /* Configure the correct blend mode */
       
   950     GLES2_SetBlendMode(blendMode);
       
   951 
       
   952     /* Emit a line loop for each rectangle */
       
   953     glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
   954     for (idx = 0; idx < count; ++idx) {
   944     for (idx = 0; idx < count; ++idx) {
   955         const SDL_Rect *rect = &rects[idx];
   945         const SDL_Rect *rect = &rects[idx];
   956 
   946 
   957         GLfloat xMin = (GLfloat)rect->x;
   947         GLfloat xMin = (GLfloat)rect->x;
   958         GLfloat xMax = (GLfloat)(rect->x + rect->w);
   948         GLfloat xMax = (GLfloat)(rect->x + rect->w);
   968         vertices[6] = xMax;
   958         vertices[6] = xMax;
   969         vertices[7] = yMax;
   959         vertices[7] = yMax;
   970         glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   960         glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);
   971         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   961         glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   972     }
   962     }
   973     glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
   974     if (glGetError() != GL_NO_ERROR)
   963     if (glGetError() != GL_NO_ERROR)
   975     {
   964     {
   976         SDL_SetError("Failed to render lines");
   965         SDL_SetError("Failed to render lines");
   977         return -1;
   966         return -1;
   978     }
   967     }
   985 {
   974 {
   986     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   975     GLES2_DriverContext *rdata = (GLES2_DriverContext *)renderer->driverdata;
   987     GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   976     GLES2_TextureData *tdata = (GLES2_TextureData *)texture->driverdata;
   988     GLES2_ImageSource sourceType;
   977     GLES2_ImageSource sourceType;
   989     SDL_BlendMode blendMode;
   978     SDL_BlendMode blendMode;
   990     int alpha;
       
   991     GLfloat vertices[8];
   979     GLfloat vertices[8];
   992     GLfloat texCoords[8];
   980     GLfloat texCoords[8];
   993     GLuint locTexture;
   981     GLuint locTexture;
   994     GLuint locModulation;
   982     GLuint locModulation;
   995 
   983 
   996     GLES2_ActivateRenderer(renderer);
   984     GLES2_ActivateRenderer(renderer);
   997 
   985 
   998     /* Activate an appropriate shader and set the projection matrix */
   986     /* Activate an appropriate shader and set the projection matrix */
   999     blendMode = texture->blendMode;
   987     blendMode = texture->blendMode;
  1000     alpha = texture->a;
       
  1001     sourceType = GLES2_IMAGESOURCE_TEXTURE;
   988     sourceType = GLES2_IMAGESOURCE_TEXTURE;
  1002     if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0)
   989     if (GLES2_SelectProgram(renderer, sourceType, blendMode) < 0)
  1003         return -1;
   990         return -1;
  1004 
   991 
  1005     /* Select the target texture */
   992     /* Select the target texture */
  1007     glGetError();
   994     glGetError();
  1008     glActiveTexture(GL_TEXTURE0);
   995     glActiveTexture(GL_TEXTURE0);
  1009     glBindTexture(tdata->texture_type, tdata->texture);
   996     glBindTexture(tdata->texture_type, tdata->texture);
  1010     glUniform1i(locTexture, 0);
   997     glUniform1i(locTexture, 0);
  1011 
   998 
  1012     /* Configure texture blending */
   999     if (tdata->scaleMode != rdata->current.scaleMode) {
  1013     GLES2_SetBlendMode(blendMode);
  1000         glTexParameteri(tdata->texture_type, GL_TEXTURE_MIN_FILTER,
       
  1001                         tdata->scaleMode);
       
  1002         glTexParameteri(tdata->texture_type, GL_TEXTURE_MAG_FILTER,
       
  1003                         tdata->scaleMode);
       
  1004         rdata->current.scaleMode = tdata->scaleMode;
       
  1005     }
  1014 
  1006 
  1015     /* Configure color modulation */
  1007     /* Configure color modulation */
  1016     locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
  1008     locModulation = rdata->current_program->uniform_locations[GLES2_UNIFORM_MODULATION];
  1017     glUniform4f(locModulation,
  1009     glUniform4f(locModulation,
  1018                 texture->r * inv255f,
  1010                 texture->r * inv255f,
  1019                 texture->g * inv255f,
  1011                 texture->g * inv255f,
  1020                 texture->b * inv255f,
  1012                 texture->b * inv255f,
  1021                 alpha * inv255f);
  1013                 texture->a * inv255f);
       
  1014 
       
  1015     /* Configure texture blending */
       
  1016     GLES2_SetBlendMode(rdata, blendMode);
       
  1017 
       
  1018     GLES2_SetTexCoords(rdata, SDL_TRUE);
  1022 
  1019 
  1023     /* Emit the textured quad */
  1020     /* Emit the textured quad */
  1024     glEnableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
       
  1025     glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
  1026     vertices[0] = (GLfloat)dstrect->x;
  1021     vertices[0] = (GLfloat)dstrect->x;
  1027     vertices[1] = (GLfloat)dstrect->y;
  1022     vertices[1] = (GLfloat)dstrect->y;
  1028     vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
  1023     vertices[2] = (GLfloat)(dstrect->x + dstrect->w);
  1029     vertices[3] = (GLfloat)dstrect->y;
  1024     vertices[3] = (GLfloat)dstrect->y;
  1030     vertices[4] = (GLfloat)dstrect->x;
  1025     vertices[4] = (GLfloat)dstrect->x;
  1040     texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  1035     texCoords[5] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  1041     texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
  1036     texCoords[6] = (srcrect->x + srcrect->w) / (GLfloat)texture->w;
  1042     texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  1037     texCoords[7] = (srcrect->y + srcrect->h) / (GLfloat)texture->h;
  1043     glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
  1038     glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, texCoords);
  1044     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1039     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  1045     glDisableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
  1046     glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
       
  1047     if (glGetError() != GL_NO_ERROR)
  1040     if (glGetError() != GL_NO_ERROR)
  1048     {
  1041     {
  1049         SDL_SetError("Failed to render texture");
  1042         SDL_SetError("Failed to render texture");
  1050         return -1;
  1043         return -1;
  1051     }
  1044     }
  1064 /*************************************************************************************************
  1057 /*************************************************************************************************
  1065  * Renderer instantiation                                                                        *
  1058  * Renderer instantiation                                                                        *
  1066  *************************************************************************************************/
  1059  *************************************************************************************************/
  1067 
  1060 
  1068 #define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
  1061 #define GL_NVIDIA_PLATFORM_BINARY_NV 0x890B
       
  1062 
       
  1063 static void
       
  1064 GLES2_ResetState(SDL_Renderer *renderer)
       
  1065 {
       
  1066     GLES2_DriverContext *rdata = (GLES2_DriverContext *) renderer->driverdata;
       
  1067 
       
  1068     if (SDL_CurrentContext == rdata->context) {
       
  1069         GLES2_UpdateViewport(renderer);
       
  1070     } else {
       
  1071         GLES2_ActivateRenderer(renderer);
       
  1072     }
       
  1073 
       
  1074     rdata->current.blendMode = -1;
       
  1075     rdata->current.scaleMode = 0;
       
  1076     rdata->current.tex_coords = SDL_FALSE;
       
  1077 
       
  1078     glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
       
  1079     glDisableVertexAttribArray(GLES2_ATTRIBUTE_TEXCOORD);
       
  1080 }
  1069 
  1081 
  1070 static SDL_Renderer *
  1082 static SDL_Renderer *
  1071 GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
  1083 GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
  1072 {
  1084 {
  1073     SDL_Renderer *renderer;
  1085     SDL_Renderer *renderer;
  1164     renderer->RenderFillRects     = &GLES2_RenderFillRects;
  1176     renderer->RenderFillRects     = &GLES2_RenderFillRects;
  1165     renderer->RenderCopy          = &GLES2_RenderCopy;
  1177     renderer->RenderCopy          = &GLES2_RenderCopy;
  1166     renderer->RenderPresent       = &GLES2_RenderPresent;
  1178     renderer->RenderPresent       = &GLES2_RenderPresent;
  1167     renderer->DestroyTexture      = &GLES2_DestroyTexture;
  1179     renderer->DestroyTexture      = &GLES2_DestroyTexture;
  1168     renderer->DestroyRenderer     = &GLES2_DestroyRenderer;
  1180     renderer->DestroyRenderer     = &GLES2_DestroyRenderer;
       
  1181 
       
  1182     GLES2_ResetState(renderer);
       
  1183 
  1169     return renderer;
  1184     return renderer;
  1170 }
  1185 }
  1171 
  1186 
  1172 #endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
  1187 #endif /* SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED */
  1173 
  1188