opengl: Don't enable/disable texturing except when actually rendering.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 22 Mar 2020 14:32:47 -0400
changeset 136641c73cc1e4a3a
parent 13663 37af808e6222
child 13666 83df8de77e12
opengl: Don't enable/disable texturing except when actually rendering.

Otherwise our cached state goes out of sync when updating a texture. Since
these state changes aren't necessary, they were removed instead of updating
the cached state.

Fixes Bugzilla #4998.
src/render/opengl/SDL_render_gl.c
     1.1 --- a/src/render/opengl/SDL_render_gl.c	Sun Mar 22 11:01:14 2020 -0700
     1.2 +++ b/src/render/opengl/SDL_render_gl.c	Sun Mar 22 14:32:47 2020 -0400
     1.3 @@ -585,7 +585,6 @@
     1.4  
     1.5          renderdata->glGenTextures(1, &data->utexture);
     1.6          renderdata->glGenTextures(1, &data->vtexture);
     1.7 -        renderdata->glEnable(textype);
     1.8  
     1.9          renderdata->glBindTexture(textype, data->utexture);
    1.10          renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
    1.11 @@ -610,8 +609,6 @@
    1.12                                      GL_CLAMP_TO_EDGE);
    1.13          renderdata->glTexImage2D(textype, 0, internalFormat, (texture_w+1)/2,
    1.14                                   (texture_h+1)/2, 0, format, type, NULL);
    1.15 -
    1.16 -        renderdata->glDisable(textype);
    1.17      }
    1.18  
    1.19      if (texture->format == SDL_PIXELFORMAT_NV12 ||
    1.20 @@ -619,8 +616,6 @@
    1.21          data->nv12 = SDL_TRUE;
    1.22  
    1.23          renderdata->glGenTextures(1, &data->utexture);
    1.24 -        renderdata->glEnable(textype);
    1.25 -
    1.26          renderdata->glBindTexture(textype, data->utexture);
    1.27          renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER,
    1.28                                      scaleMode);
    1.29 @@ -632,7 +627,6 @@
    1.30                                      GL_CLAMP_TO_EDGE);
    1.31          renderdata->glTexImage2D(textype, 0, GL_LUMINANCE_ALPHA, (texture_w+1)/2,
    1.32                                   (texture_h+1)/2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
    1.33 -        renderdata->glDisable(textype);
    1.34      }
    1.35  
    1.36      return GL_CheckError("", renderer);
    1.37 @@ -653,7 +647,6 @@
    1.38  
    1.39      renderdata->drawstate.texture = NULL;  /* we trash this state. */
    1.40  
    1.41 -    renderdata->glEnable(textype);
    1.42      renderdata->glBindTexture(textype, data->texture);
    1.43      renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    1.44      renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, (pitch / texturebpp));
    1.45 @@ -696,7 +689,6 @@
    1.46                                      (rect->w + 1)/2, (rect->h + 1)/2,
    1.47                                      GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
    1.48      }
    1.49 -    renderdata->glDisable(textype);
    1.50  
    1.51      return GL_CheckError("glTexSubImage2D()", renderer);
    1.52  }
    1.53 @@ -716,7 +708,6 @@
    1.54  
    1.55      renderdata->drawstate.texture = NULL;  /* we trash this state. */
    1.56  
    1.57 -    renderdata->glEnable(textype);
    1.58      renderdata->glBindTexture(textype, data->texture);
    1.59      renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    1.60      renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch);
    1.61 @@ -735,7 +726,6 @@
    1.62      renderdata->glTexSubImage2D(textype, 0, rect->x/2, rect->y/2,
    1.63                                  (rect->w + 1)/2, (rect->h + 1)/2,
    1.64                                  data->format, data->formattype, Vplane);
    1.65 -    renderdata->glDisable(textype);
    1.66  
    1.67      return GL_CheckError("glTexSubImage2D()", renderer);
    1.68  }
    1.69 @@ -776,15 +766,12 @@
    1.70      GL_TextureData *data = (GL_TextureData *) texture->driverdata;
    1.71      GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
    1.72  
    1.73 -    renderdata->glEnable(textype);
    1.74      renderdata->glBindTexture(textype, data->texture);
    1.75      renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
    1.76      renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
    1.77 -    renderdata->glDisable(textype);
    1.78  
    1.79      if (texture->format == SDL_PIXELFORMAT_YV12 ||
    1.80          texture->format == SDL_PIXELFORMAT_IYUV) {
    1.81 -        renderdata->glEnable(textype);
    1.82          renderdata->glBindTexture(textype, data->utexture);
    1.83          renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
    1.84          renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
    1.85 @@ -792,16 +779,13 @@
    1.86          renderdata->glBindTexture(textype, data->vtexture);
    1.87          renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
    1.88          renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
    1.89 -        renderdata->glDisable(textype);
    1.90      }
    1.91  
    1.92      if (texture->format == SDL_PIXELFORMAT_NV12 ||
    1.93          texture->format == SDL_PIXELFORMAT_NV21) {
    1.94 -        renderdata->glEnable(textype);
    1.95          renderdata->glBindTexture(textype, data->utexture);
    1.96          renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
    1.97          renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
    1.98 -        renderdata->glDisable(textype);
    1.99      }
   1.100  }
   1.101