Fix missing target overrides

bug: 74112713

Change-Id: I28eed9d8fe390dd94b49c0b99bb168e5abf0efc0
(cherry picked from commit be41d0d275a9dee262b7e04c0cff38f947642a34)
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 31f2c2a..c37be1c 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -2770,6 +2770,10 @@
     state->setBoundTextureInternalFormat(stateTarget, (GLint)internalformat);
     state->setBoundTextureDims(stateTarget, level, width, height, 1);
 
+    if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
+        ctx->override2DTextureTarget(target);
+    }
+
     if (ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER)) {
         ctx->glCompressedTexImage2DOffsetAEMU(
                 ctx, target, level, internalformat,
@@ -2781,6 +2785,10 @@
                 width, height, border,
                 imageSize, data);
     }
+
+    if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
+        ctx->restore2DTextureTarget(target);
+    }
 }
 
 void GL2Encoder::s_glCompressedTexSubImage2D(void* self, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data) {
@@ -2805,6 +2813,10 @@
                  GL_INVALID_OPERATION);
     SET_ERROR_IF(xoffset < 0 || yoffset < 0, GL_INVALID_VALUE);
 
+    if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
+        ctx->override2DTextureTarget(target);
+    }
+
     if (ctx->boundBuffer(GL_PIXEL_UNPACK_BUFFER)) {
         ctx->glCompressedTexSubImage2DOffsetAEMU(
                 ctx, target, level,
@@ -2818,6 +2830,10 @@
                 width, height, format,
                 imageSize, data);
     }
+
+    if (target == GL_TEXTURE_2D || target == GL_TEXTURE_EXTERNAL_OES) {
+        ctx->restore2DTextureTarget(target);
+    }
 }
 
 void GL2Encoder::s_glBindBufferRange(void* self, GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size) {
@@ -3414,7 +3430,16 @@
     state->setBoundTextureInternalFormat(target, internalformat);
     state->setBoundTextureDims(target, -1, width, height, 1);
     state->setBoundTextureImmutableFormat(target);
+
+    if (target == GL_TEXTURE_2D) {
+        ctx->override2DTextureTarget(target);
+    }
+
     ctx->m_glTexStorage2D_enc(ctx, target, levels, internalformat, width, height);
+
+    if (target == GL_TEXTURE_2D) {
+        ctx->restore2DTextureTarget(target);
+    }
 }
 
 void GL2Encoder::s_glTransformFeedbackVaryings(void* self, GLuint program, GLsizei count, const char** varyings, GLenum bufferMode) {
@@ -4199,7 +4224,15 @@
                    GLESv2Validation::filterableTexFormat(ctx, internalformat)),
                  GL_INVALID_OPERATION);
 
+    if (target == GL_TEXTURE_2D) {
+        ctx->override2DTextureTarget(target);
+    }
+
     ctx->m_glGenerateMipmap_enc(ctx, target);
+
+    if (target == GL_TEXTURE_2D) {
+        ctx->restore2DTextureTarget(target);
+    }
 }
 
 void GL2Encoder::s_glBindSampler(void* self, GLuint unit, GLuint sampler) {