diff options
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/context.c | 27 | ||||
-rw-r--r-- | src/mesa/main/texobj.c | 25 |
2 files changed, 23 insertions, 29 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 256257bd09f..2d39b526897 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -1,4 +1,4 @@ -/* $Id: context.c,v 1.132 2001/04/04 13:38:51 brianp Exp $ */ +/* $Id: context.c,v 1.133 2001/04/25 18:21:05 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -476,33 +476,21 @@ alloc_shared_state( void ) if (!ss->Default1D) { outOfMemory = GL_TRUE; } - else { - ss->Default1D->RefCount++; - } ss->Default2D = _mesa_alloc_texture_object(ss, 0, 2); if (!ss->Default2D) { outOfMemory = GL_TRUE; } - else { - ss->Default2D->RefCount++; - } ss->Default3D = _mesa_alloc_texture_object(ss, 0, 3); if (!ss->Default3D) { outOfMemory = GL_TRUE; } - else { - ss->Default1D->RefCount++; - } ss->DefaultCubeMap = _mesa_alloc_texture_object(ss, 0, 6); if (!ss->DefaultCubeMap) { outOfMemory = GL_TRUE; } - else { - ss->DefaultCubeMap->RefCount++; - } if (!ss->DisplayList || !ss->TexObjects || outOfMemory) { /* Ran out of memory at some point. Free everything and return NULL */ @@ -546,8 +534,7 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss ) _mesa_DeleteHashTable(ss->DisplayList); /* Free texture objects */ - while (ss->TexObjectList) - { + while (ss->TexObjectList) { if (ctx->Driver.DeleteTexture) (*ctx->Driver.DeleteTexture)( ctx, ss->TexObjectList ); /* this function removes from linked list too! */ @@ -1367,11 +1354,11 @@ _mesa_initialize_context( GLcontext *ctx, ctx->ReadBuffer = NULL; if (share_list) { - /* share the group of display lists of another context */ + /* share state with another context */ ctx->Shared = share_list->Shared; } else { - /* allocate new group of display lists */ + /* allocate new, unshared state */ ctx->Shared = alloc_shared_state(); if (!ctx->Shared) { return GL_FALSE; @@ -1381,6 +1368,12 @@ _mesa_initialize_context( GLcontext *ctx, ctx->Shared->RefCount++; _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); + /* Effectively bind the default textures to all texture units */ + ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS; + ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS; + ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS; + ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS; + init_attrib_groups( ctx ); if (visual->doubleBufferMode) { diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c index fc2915531b7..644d99a9e78 100644 --- a/src/mesa/main/texobj.c +++ b/src/mesa/main/texobj.c @@ -1,4 +1,4 @@ -/* $Id: texobj.c,v 1.47 2001/04/20 17:16:52 brianp Exp $ */ +/* $Id: texobj.c,v 1.48 2001/04/25 18:21:05 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -503,8 +503,10 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *texName) /* Decrement reference count and delete if zero */ delObj->RefCount--; - ASSERT( delObj->RefCount >= 0 ); + ASSERT(delObj->RefCount >= 0); + if (delObj->RefCount == 0) { + ASSERT(delObj->Name != 0); if (ctx->Driver.DeleteTexture) (*ctx->Driver.DeleteTexture)( ctx, delObj ); _mesa_free_texture_object(ctx->Shared, delObj); @@ -592,7 +594,8 @@ _mesa_BindTexture( GLenum target, GLuint texName ) /* error checking */ if (newTexObj->Dimensions > 0 && newTexObj->Dimensions != targetDim) { /* the named texture object's dimensions don't match the target */ - _mesa_error( ctx, GL_INVALID_OPERATION, "glBindTexture(wrong dimensionality)" ); + _mesa_error( ctx, GL_INVALID_OPERATION, + "glBindTexture(wrong dimensionality)" ); return; } } @@ -610,7 +613,6 @@ _mesa_BindTexture( GLenum target, GLuint texName ) newTexObj->RefCount++; - /* do the actual binding, but first flush outstanding vertices: */ FLUSH_VERTICES(ctx, _NEW_TEXTURE); @@ -636,15 +638,14 @@ _mesa_BindTexture( GLenum target, GLuint texName ) if (ctx->Driver.BindTexture) (*ctx->Driver.BindTexture)( ctx, target, newTexObj ); - if (oldTexObj->Name > 0) { - /* never delete default (id=0) texture objects */ - oldTexObj->RefCount--; - if (oldTexObj->RefCount <= 0) { - if (ctx->Driver.DeleteTexture) { - (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); - } - _mesa_free_texture_object(ctx->Shared, oldTexObj); + oldTexObj->RefCount--; + assert(oldTexObj->RefCount >= 0); + if (oldTexObj->RefCount == 0) { + assert(oldTexObj->Name != 0); + if (ctx->Driver.DeleteTexture) { + (*ctx->Driver.DeleteTexture)( ctx, oldTexObj ); } + _mesa_free_texture_object(ctx->Shared, oldTexObj); } } |