+static void
+unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
+{
+ GLuint u;
+
+ for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
+ struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
+ struct gl_texture_object **curr = NULL;
+
+ if (texObj == unit->Current1D) {
+ curr = &unit->Current1D;
+ unit->Current1D = ctx->Shared->Default1D;
+ }
+ else if (texObj == unit->Current2D) {
+ curr = &unit->Current2D;
+ unit->Current2D = ctx->Shared->Default2D;
+ }
+ else if (texObj == unit->Current3D) {
+ curr = &unit->Current3D;
+ unit->Current3D = ctx->Shared->Default3D;
+ }
+ else if (texObj == unit->CurrentCubeMap) {
+ curr = &unit->CurrentCubeMap;
+ unit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
+ }
+ else if (texObj == unit->CurrentRect) {
+ curr = &unit->CurrentRect;
+ unit->CurrentRect = ctx->Shared->DefaultRect;
+ }
+ else if (texObj == unit->Current1DArray) {
+ curr = &unit->Current1DArray;
+ unit->CurrentRect = ctx->Shared->Default1DArray;
+ }
+ else if (texObj == unit->Current2DArray) {
+ curr = &unit->Current1DArray;
+ unit->CurrentRect = ctx->Shared->Default2DArray;
+ }
+
+ if (curr) {
+ (*curr)->RefCount++;
+ texObj->RefCount--;
+ if (texObj == unit->_Current)
+ unit->_Current = *curr;
+ }
+ }
+}
+
+
+/**
+ * Delete named textures.
+ *
+ * \param n number of textures to be deleted.
+ * \param textures array of texture IDs to be deleted.
+ *
+ * \sa glDeleteTextures().
+ *
+ * If we're about to delete a texture that's currently bound to any
+ * texture unit, unbind the texture first. Decrement the reference
+ * count on the texture object and delete it if it's zero.
+ * Recall that texture objects can be shared among several rendering
+ * contexts.
+ */
+void GLAPIENTRY
+_mesa_DeleteTextures( GLsizei n, const GLuint *textures)