+ gl_backend_rebindtextures = false;
+ GL_SetupTextureState();
+ CHECKGLERROR
+ }
+
+ for (unitnum = 0;unitnum < backendimageunits;unitnum++)
+ {
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ // update 1d texture binding
+ if (unit->t1d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ qglDisable(GL_TEXTURE_1D);CHECKGLERROR
+ }
+ unit->t1d = 0;
+ qglBindTexture(GL_TEXTURE_1D, unit->t1d);CHECKGLERROR
+ }
+ // update 2d texture binding
+ if (unit->t2d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ qglDisable(GL_TEXTURE_2D);CHECKGLERROR
+ }
+ unit->t2d = 0;
+ qglBindTexture(GL_TEXTURE_2D, unit->t2d);CHECKGLERROR
+ }
+ // update 3d texture binding
+ if (unit->t3d)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ qglDisable(GL_TEXTURE_3D);CHECKGLERROR
+ }
+ unit->t3d = 0;
+ qglBindTexture(GL_TEXTURE_3D, unit->t3d);CHECKGLERROR
+ }
+ // update cubemap texture binding
+ if (unit->tcubemap)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ qglDisable(GL_TEXTURE_CUBE_MAP_ARB);CHECKGLERROR
+ }
+ unit->tcubemap = 0;
+ qglBindTexture(GL_TEXTURE_CUBE_MAP_ARB, unit->tcubemap);CHECKGLERROR
+ }
+ // update rectangle texture binding
+ if (unit->trectangle)
+ {
+ GL_ActiveTexture(unitnum);
+ if (unitnum < backendunits)
+ {
+ qglDisable(GL_TEXTURE_RECTANGLE_ARB);CHECKGLERROR
+ }
+ unit->trectangle = 0;
+ qglBindTexture(GL_TEXTURE_RECTANGLE_ARB, unit->trectangle);CHECKGLERROR
+ }
+ }
+ for (unitnum = 0;unitnum < backendarrayunits;unitnum++)
+ {
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ // texture array unit is disabled, disable the array
+ if (unit->arrayenabled)
+ {
+ unit->arrayenabled = false;
+ GL_ClientActiveTexture(unitnum);
+ qglDisableClientState(GL_TEXTURE_COORD_ARRAY);CHECKGLERROR
+ }
+ }
+ for (unitnum = 0;unitnum < backendunits;unitnum++)
+ {
+ gltextureunit_t *unit = gl_state.units + unitnum;
+ // no texmatrix specified, revert to identity
+ if (unit->texmatrixenabled)
+ {
+ unit->texmatrixenabled = false;
+ unit->matrix = identitymatrix;
+ CHECKGLERROR
+ GL_ActiveTexture(unitnum);
+ qglMatrixMode(GL_TEXTURE);CHECKGLERROR
+ qglLoadIdentity();CHECKGLERROR
+ qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
+ }
+ if (gl_combine.integer)
+ {
+ // GL_ARB_texture_env_combine
+ if (unit->combinergb != GL_MODULATE)
+ {
+ unit->combinergb = GL_MODULATE;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, unit->combinergb);CHECKGLERROR
+ }
+ if (unit->combinealpha != GL_MODULATE)
+ {
+ unit->combinealpha = GL_MODULATE;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, unit->combinealpha);CHECKGLERROR
+ }
+ if (unit->rgbscale != 1)
+ {
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, (unit->rgbscale = 1));CHECKGLERROR
+ }
+ if (unit->alphascale != 1)
+ {
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_ALPHA_SCALE, (unit->alphascale = 1));CHECKGLERROR
+ }
+ }
+ else
+ {
+ // normal GL texenv
+ if (unit->combinergb != GL_MODULATE)
+ {
+ unit->combinergb = GL_MODULATE;
+ GL_ActiveTexture(unitnum);
+ qglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, unit->combinergb);CHECKGLERROR
+ }
+ }