-/* $Id: texobj.c,v 1.11 2000/01/24 16:19:55 brianp Exp $ */
/*
* Mesa 3-D graphics library
/* insert into linked list */
if (shared) {
+ _glthread_LOCK_MUTEX(shared->Mutex);
obj->Next = shared->TexObjectList;
shared->TexObjectList = obj;
+ _glthread_UNLOCK_MUTEX(shared->Mutex);
}
if (name > 0) {
/* unlink t from the linked list */
if (shared) {
+ _glthread_LOCK_MUTEX(shared->Mutex);
tprev = NULL;
tcurr = shared->TexObjectList;
while (tcurr) {
tprev = tcurr;
tcurr = tcurr->Next;
}
+ _glthread_UNLOCK_MUTEX(shared->Mutex);
}
if (t->Name) {
GLuint i;
for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
if (t->Image[i]) {
- gl_free_texture_image( t->Image[i] );
+ _mesa_free_texture_image( t->Image[i] );
}
}
}
t->Complete = GL_TRUE; /* be optimistic */
/* Always need level zero image */
- if (!t->Image[0] || !t->Image[0]->Data) {
+ if (!t->Image[0]) {
t->Complete = GL_FALSE;
return;
}
/* Test dimension-independent attributes */
for (i = minLevel; i <= maxLevel; i++) {
if (t->Image[i]) {
- if (!t->Image[i]->Data) {
- t->Complete = GL_FALSE;
- return;
- }
if (t->Image[i]->Format != t->Image[0]->Format) {
t->Complete = GL_FALSE;
return;
t->Complete = GL_FALSE;
return;
}
- if (!t->Image[i]->Data) {
- t->Complete = GL_FALSE;
- return;
- }
if (t->Image[i]->Width2 != width ) {
t->Complete = GL_FALSE;
return;
}
+_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
+
/*
* Execute glGenTextures
return;
}
+
+ /*
+ * This must be atomic (generation and allocation of texture IDs)
+ */
+ _glthread_LOCK_MUTEX(GenTexturesLock);
+
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
/* Return the texture names */
GLuint dims = 0;
(void) gl_alloc_texture_object(ctx->Shared, name, dims);
}
+
+ _glthread_UNLOCK_MUTEX(GenTexturesLock);
}
t = (struct gl_texture_object *)
_mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
if (t) {
+ /* First check if this texture is currently bound.
+ * If so, unbind it and decrement the reference count.
+ */
GLuint u;
- for (u=0; u<MAX_TEXTURE_UNITS; u++) {
+ for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
GLuint d;
for (d = 1 ; d <= 3 ; d++) {
- if (unit->CurrentD[d]==t) {
+ if (unit->CurrentD[d] == t) {
unit->CurrentD[d] = ctx->Shared->DefaultD[d];
ctx->Shared->DefaultD[d]->RefCount++;
t->RefCount--;
- assert( t->RefCount >= 0 );
+ ASSERT( t->RefCount >= 0 );
}
}
}
- /* tell device driver to delete texture */
- if (ctx->Driver.DeleteTexture) {
- (*ctx->Driver.DeleteTexture)( ctx, t );
- }
-
- if (t->RefCount==0) {
+ /* Decrement reference count and delete if zero */
+ t->RefCount--;
+ ASSERT( t->RefCount >= 0 );
+ if (t->RefCount == 0) {
+ if (ctx->Driver.DeleteTexture)
+ (*ctx->Driver.DeleteTexture)( ctx, t );
gl_free_texture_object(ctx->Shared, t);
}
}
newTexObj = ctx->Shared->DefaultD[dim];
else {
struct _mesa_HashTable *hash = ctx->Shared->TexObjects;
- newTexObj = (struct gl_texture_object *) HashLookup(hash, texName);
+ newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName);
if (!newTexObj)
newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim);