/*
* Mesa 3-D graphics library
- * Version: 6.1
+ * Version: 6.2
*
* Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
*
/**
- * Initialize a texture object to default values.
+ * Initialize a new texture object to default values.
* \param obj the texture object
* \param name the texture name
* \param target the texture target
target == GL_TEXTURE_CUBE_MAP_ARB ||
target == GL_TEXTURE_RECTANGLE_NV);
+ _mesa_bzero(obj, sizeof(*obj));
/* init the non-zero fields */
_glthread_INIT_MUTEX(obj->Mutex);
- _mesa_bzero(obj, sizeof(*obj));
obj->RefCount = 1;
obj->Name = name;
obj->Target = target;
(void) ctx;
- assert(texObj);
-
_mesa_free_colortable_data(&texObj->Palette);
/* free the texture images */
}
ctx->NewState |= _NEW_TEXTURE;
- /* Decrement reference count and delete if zero */
- delObj->RefCount--;
- ASSERT(delObj->RefCount >= 0);
+ /* If user hasn't already tried to delete the texture... */
+ if (!delObj->DeletePending) {
+ delObj->DeletePending = GL_TRUE;
+ delObj->RefCount--;
+ ASSERT(delObj->RefCount >= 0);
+ }
+ /* See if we can really delete the texture now */
if (delObj->RefCount == 0) {
- ASSERT(delObj->Name != 0);
+ ASSERT(delObj->Name != 0); /* Never delete default tex objects */
_mesa_remove_texture_object(ctx, delObj);
ASSERT(ctx->Driver.DeleteTexture);
(*ctx->Driver.DeleteTexture)(ctx, delObj);
}
}
+
/**
* Bind a named texture to a texturing target.
*
_mesa_debug(ctx, "glBindTexture %s %d\n",
_mesa_lookup_enum_by_nr(target), (GLint) texName);
+ /*
+ * Get pointer to currently bound texture object (oldTexObj)
+ */
switch (target) {
case GL_TEXTURE_1D:
oldTexObj = texUnit->Current1D;
if (ctx->Driver.BindTexture)
(*ctx->Driver.BindTexture)( ctx, target, newTexObj );
+ /* Decrement the reference count on the old texture and check if it's
+ * time to delete it.
+ */
oldTexObj->RefCount--;
- assert(oldTexObj->RefCount >= 0);
+ ASSERT(oldTexObj->RefCount >= 0);
if (oldTexObj->RefCount == 0) {
- assert(oldTexObj->Name != 0);
+ ASSERT(oldTexObj->Name != 0);
+ ASSERT(oldTexObj->DeletePending);
_mesa_remove_texture_object(ctx, oldTexObj);
ASSERT(ctx->Driver.DeleteTexture);
(*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
}
}
+
/**
* Set texture priorities.
*