OpenGL ES renderer state fixes. Now GL_TEXTURE_2D is not enabled by default.
authorMike Gorchak <lestat@i.com.ua>
Thu, 14 May 2009 10:54:34 +0000
changeset 31226c98826d88b0
parent 3121 4a28c7c985b2
child 3123 60301ed80050
OpenGL ES renderer state fixes. Now GL_TEXTURE_2D is not enabled by default.
src/video/SDL_renderer_gles.c
     1.1 --- a/src/video/SDL_renderer_gles.c	Thu May 07 12:50:55 2009 +0000
     1.2 +++ b/src/video/SDL_renderer_gles.c	Thu May 14 10:54:34 2009 +0000
     1.3 @@ -103,9 +103,10 @@
     1.4       (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
     1.5        SDL_TEXTURESCALEMODE_SLOW), 2,
     1.6       {
     1.7 -      SDL_PIXELFORMAT_RGB24,
     1.8 -      SDL_PIXELFORMAT_ABGR8888,
     1.9 -      },
    1.10 +      /* OpenGL ES 1.x supported formats list */
    1.11 +      SDL_PIXELFORMAT_BGR24,
    1.12 +      SDL_PIXELFORMAT_ABGR8888
    1.13 +     },
    1.14       0,
    1.15       0}
    1.16  };
    1.17 @@ -182,7 +183,7 @@
    1.18  {
    1.19  
    1.20  #define SDL_PROC(ret,func,params) \
    1.21 -	data->func = func;
    1.22 +    data->func = func;
    1.23  #include "SDL_glesfuncs.h"
    1.24  #undef SDL_PROC
    1.25  
    1.26 @@ -301,7 +302,6 @@
    1.27      data->blendMode = -1;
    1.28      data->glDisable(GL_DEPTH_TEST);
    1.29      data->glDisable(GL_CULL_FACE);
    1.30 -    data->glEnable(GL_TEXTURE_2D);
    1.31      data->updateSize = SDL_TRUE;
    1.32  
    1.33      return renderer;
    1.34 @@ -351,7 +351,7 @@
    1.35  }
    1.36  
    1.37  static int
    1.38 -GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    1.39 +GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
    1.40  {
    1.41      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    1.42      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.43 @@ -362,30 +362,16 @@
    1.44      GLenum result;
    1.45  
    1.46      switch (texture->format) {
    1.47 -    case SDL_PIXELFORMAT_INDEX1LSB:
    1.48 -    case SDL_PIXELFORMAT_INDEX1MSB:
    1.49 -    case SDL_PIXELFORMAT_INDEX8:
    1.50 -    case SDL_PIXELFORMAT_RGB332:
    1.51 -    case SDL_PIXELFORMAT_RGB444:
    1.52 -    case SDL_PIXELFORMAT_RGB555:
    1.53 -    case SDL_PIXELFORMAT_ARGB4444:
    1.54 -    case SDL_PIXELFORMAT_ARGB1555:
    1.55      case SDL_PIXELFORMAT_BGR24:
    1.56 -    case SDL_PIXELFORMAT_BGR888:
    1.57 -    case SDL_PIXELFORMAT_RGB888:
    1.58 -    case SDL_PIXELFORMAT_RGBA8888:
    1.59 -    case SDL_PIXELFORMAT_ARGB2101010:
    1.60 -    case SDL_PIXELFORMAT_ARGB8888:
    1.61 -    case SDL_PIXELFORMAT_RGB24:
    1.62 -        internalFormat = GL_RGB;
    1.63 -        format = GL_RGB;
    1.64 -        type = GL_UNSIGNED_BYTE;
    1.65 -        break;
    1.66 +         internalFormat = GL_RGB;
    1.67 +         format = GL_RGB;
    1.68 +         type = GL_UNSIGNED_BYTE;
    1.69 +         break;
    1.70      case SDL_PIXELFORMAT_ABGR8888:
    1.71 -        internalFormat = GL_RGBA;
    1.72 -        format = GL_RGBA;
    1.73 -        type = GL_UNSIGNED_BYTE;
    1.74 -        break;
    1.75 +         internalFormat = GL_RGBA;
    1.76 +         format = GL_RGBA;
    1.77 +         type = GL_UNSIGNED_BYTE;
    1.78 +         break;
    1.79          /*
    1.80             These formats would be supported if SDL had the necessary pixel formats
    1.81             case SDL_PIXELFORMAT_BGR565:
    1.82 @@ -403,7 +389,7 @@
    1.83             format = GL_RGBA;
    1.84             type = GL_UNSIGNED_SHORT_4_4_4_4;
    1.85             break;
    1.86 -         */
    1.87 +        */
    1.88      default:
    1.89          SDL_SetError("Unsupported texture format");
    1.90          return -1;
    1.91 @@ -428,6 +414,7 @@
    1.92      texture->driverdata = data;
    1.93  
    1.94      renderdata->glGetError();
    1.95 +    renderdata->glEnable(GL_TEXTURE_2D);
    1.96      renderdata->glGenTextures(1, &data->texture);
    1.97  
    1.98      data->type = GL_TEXTURE_2D;
    1.99 @@ -451,6 +438,7 @@
   1.100  
   1.101      renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
   1.102                               texture_h, 0, format, type, NULL);
   1.103 +    renderdata->glDisable(GL_TEXTURE_2D);
   1.104  
   1.105      result = renderdata->glGetError();
   1.106      if (result != GL_NO_ERROR) {
   1.107 @@ -545,18 +533,20 @@
   1.108  }
   1.109  
   1.110  static int
   1.111 -GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   1.112 -                   const SDL_Rect * rect, const void *pixels, int pitch)
   1.113 +GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
   1.114 +                   const SDL_Rect *rect, const void *pixels, int pitch)
   1.115  {
   1.116      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
   1.117      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   1.118      GLenum result;
   1.119  
   1.120 +    renderdata->glGetError();
   1.121 +    renderdata->glEnable(data->type);
   1.122      SetupTextureUpdate(renderdata, texture, pitch);
   1.123 -    renderdata->glGetError();
   1.124      renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
   1.125                                  rect->h, data->format, data->formattype,
   1.126                                  pixels);
   1.127 +    renderdata->glDisable(data->type);
   1.128      result = renderdata->glGetError();
   1.129      if (result != GL_NO_ERROR) {
   1.130          GLES_SetError("glTexSubImage2D()", result);
   1.131 @@ -651,6 +641,8 @@
   1.132      data->glDrawArrays(GL_POINTS, 0, 1);
   1.133      data->glDisableClientState(GL_VERTEX_ARRAY);
   1.134  
   1.135 +    data->glDisable(GL_BLEND);
   1.136 +
   1.137      return 0;
   1.138  }
   1.139  
   1.140 @@ -677,6 +669,8 @@
   1.141      data->glDrawArrays(GL_LINES, 0, 2);
   1.142      data->glDisableClientState(GL_VERTEX_ARRAY);
   1.143  
   1.144 +    data->glDisable(GL_BLEND);
   1.145 +
   1.146      return 0;
   1.147  }
   1.148  
   1.149 @@ -712,6 +706,8 @@
   1.150      data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.151      data->glDisableClientState(GL_VERTEX_ARRAY);
   1.152  
   1.153 +    data->glDisable(GL_BLEND);
   1.154 +
   1.155      return 0;
   1.156  }
   1.157  
   1.158 @@ -728,6 +724,8 @@
   1.159      void *temp_buffer;          /* used for reformatting dirty rect pixels */
   1.160      void *temp_ptr;
   1.161  
   1.162 +    data->glEnable(GL_TEXTURE_2D);
   1.163 +
   1.164      if (texturedata->dirty.list) {
   1.165          SDL_DirtyRect *dirty;
   1.166          void *pixels;
   1.167 @@ -767,7 +765,6 @@
   1.168      }
   1.169  
   1.170      data->glBindTexture(texturedata->type, texturedata->texture);
   1.171 -    data->glEnable(GL_TEXTURE_2D);
   1.172  
   1.173      if (texture->modMode) {
   1.174          data->glColor4f((GLfloat) texture->r * inv255f,
   1.175 @@ -851,14 +848,17 @@
   1.176          data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
   1.177          data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   1.178          data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   1.179 +        data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   1.180 +        data->glDisableClientState(GL_VERTEX_ARRAY);
   1.181 +    }
   1.182  
   1.183 -    }
   1.184 +    data->glDisable(GL_TEXTURE_2D);
   1.185  
   1.186      return 0;
   1.187  }
   1.188  
   1.189  static void
   1.190 -GLES_RenderPresent(SDL_Renderer * renderer)
   1.191 +GLES_RenderPresent(SDL_Renderer *renderer)
   1.192  {
   1.193      SDL_GL_SwapWindow(renderer->window);
   1.194  }
   1.195 @@ -890,7 +890,6 @@
   1.196  
   1.197      if (data) {
   1.198          if (data->context) {
   1.199 -            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
   1.200              SDL_GL_DeleteContext(data->context);
   1.201          }
   1.202          SDL_free(data);