GLES2: disable texcoord when not using it (see bug #5235)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c
index 1b25e73..6a03706 100644
--- a/src/render/opengles2/SDL_render_gles2.c
+++ b/src/render/opengles2/SDL_render_gles2.c
@@ -857,6 +857,45 @@ GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture
return 0;
}
+static void
+SetTextureState(GLES2_RenderData *data, SDL_Texture *texture)
+{
+ if (texture != data->drawstate.texture) {
+ if ((texture != NULL) != data->drawstate.texturing) {
+ if (texture == NULL) {
+ data->glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
+ data->drawstate.texturing = SDL_FALSE;
+ } else {
+ data->glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
+ data->drawstate.texturing = SDL_TRUE;
+ }
+ }
+
+ if (texture) {
+ GLES2_TextureData *tdata = (GLES2_TextureData *) texture->driverdata;
+#if SDL_HAVE_YUV
+ if (tdata->yuv) {
+ data->glActiveTexture(GL_TEXTURE2);
+ data->glBindTexture(tdata->texture_type, tdata->texture_v);
+
+ data->glActiveTexture(GL_TEXTURE1);
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+
+ data->glActiveTexture(GL_TEXTURE0);
+ } else if (tdata->nv12) {
+ data->glActiveTexture(GL_TEXTURE1);
+ data->glBindTexture(tdata->texture_type, tdata->texture_u);
+
+ data->glActiveTexture(GL_TEXTURE0);
+ }
+#endif
+ data->glBindTexture(tdata->texture_type, tdata->texture);
+ }
+
+ data->drawstate.texture = texture;
+ }
+}
+
static int
SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_ImageSource imgsrc, void *vertices)
{
@@ -898,40 +937,7 @@ SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_I
data->drawstate.cliprect_dirty = SDL_FALSE;
}
- if (texture != data->drawstate.texture) {
- if ((texture != NULL) != data->drawstate.texturing) {
- if (texture == NULL) {
- data->glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
- data->drawstate.texturing = SDL_FALSE;
- } else {
- data->glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
- data->drawstate.texturing = SDL_TRUE;
- }
- }
-
- if (texture) {
- GLES2_TextureData *tdata = (GLES2_TextureData *) texture->driverdata;
-#if SDL_HAVE_YUV
- if (tdata->yuv) {
- data->glActiveTexture(GL_TEXTURE2);
- data->glBindTexture(tdata->texture_type, tdata->texture_v);
-
- data->glActiveTexture(GL_TEXTURE1);
- data->glBindTexture(tdata->texture_type, tdata->texture_u);
-
- data->glActiveTexture(GL_TEXTURE0);
- } else if (tdata->nv12) {
- data->glActiveTexture(GL_TEXTURE1);
- data->glBindTexture(tdata->texture_type, tdata->texture_u);
-
- data->glActiveTexture(GL_TEXTURE0);
- }
-#endif
- data->glBindTexture(tdata->texture_type, tdata->texture);
- }
-
- data->drawstate.texture = texture;
- }
+ SetTextureState(data, texture);
if (texture) {
stride = sizeof(SDL_Vertex);
@@ -1352,7 +1358,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
GLES2_ActivateRenderer(renderer);
- renderdata->drawstate.texture = NULL; /* we trash this state. */
+ SetTextureState(renderdata, NULL); /* we trash this state. */
/* Determine the corresponding GLES texture format params */
switch (texture->format)
@@ -1581,7 +1587,7 @@ GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect
return 0;
}
- data->drawstate.texture = NULL; /* we trash this state. */
+ SetTextureState(data, NULL); /* we trash this state. */
/* Create a texture subimage with the supplied data */
data->glBindTexture(tdata->texture_type, tdata->texture);
@@ -1664,7 +1670,7 @@ GLES2_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
- data->drawstate.texture = NULL; /* we trash this state. */
+ SetTextureState(data, NULL); /* we trash this state. */
data->glBindTexture(tdata->texture_type, tdata->texture_v);
GLES2_TexSubImage2D(data, tdata->texture_type,
@@ -1715,7 +1721,7 @@ GLES2_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
- data->drawstate.texture = NULL; /* we trash this state. */
+ SetTextureState(data, NULL); /* we trash this state. */
data->glBindTexture(tdata->texture_type, tdata->texture_u);
GLES2_TexSubImage2D(data, tdata->texture_type,
@@ -1836,7 +1842,7 @@ GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
GLES2_ActivateRenderer(renderer);
if (data->drawstate.texture == texture) {
- data->drawstate.texture = NULL;
+ SetTextureState(data, NULL);
}
if (data->drawstate.target == texture) {
data->drawstate.target = NULL;