texture units now share default texture objects

This commit is contained in:
Brian Paul
1999-10-09 20:17:07 +00:00
parent 7ec8d588ab
commit 6e6d4c66bd
2 changed files with 34 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: context.c,v 1.10 1999/10/08 09:27:10 keithw Exp $ */ /* $Id: context.c,v 1.11 1999/10/09 20:17:07 brianp Exp $ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@@ -327,7 +327,7 @@ static void one_time_init( void )
*/ */
static struct gl_shared_state *alloc_shared_state( void ) static struct gl_shared_state *alloc_shared_state( void )
{ {
GLuint i; GLuint d;
struct gl_shared_state *ss; struct gl_shared_state *ss;
GLboolean outOfMemory; GLboolean outOfMemory;
@@ -341,16 +341,13 @@ static struct gl_shared_state *alloc_shared_state( void )
/* Default Texture objects */ /* Default Texture objects */
outOfMemory = GL_FALSE; outOfMemory = GL_FALSE;
for (i=0;i<MAX_TEXTURE_UNITS;i++) { for (d = 1 ; d <= 3 ; d++) {
GLuint d; ss->DefaultD[d] = gl_alloc_texture_object(ss, 0, d);
for (d = 1 ; d <= 3 ; d++) { if (!ss->DefaultD[d]) {
ss->DefaultD[d][i] = gl_alloc_texture_object(ss, 0, d); outOfMemory = GL_TRUE;
if (!ss->DefaultD[d][i]) { break;
outOfMemory = GL_TRUE;
break;
}
ss->DefaultD[d][i]->RefCount++; /* don't free if not in use */
} }
ss->DefaultD[d]->RefCount++; /* don't free if not in use */
} }
if (!ss->DisplayList || !ss->TexObjects || outOfMemory) { if (!ss->DisplayList || !ss->TexObjects || outOfMemory) {
@@ -359,14 +356,12 @@ static struct gl_shared_state *alloc_shared_state( void )
DeleteHashTable(ss->DisplayList); DeleteHashTable(ss->DisplayList);
if (ss->TexObjects) if (ss->TexObjects)
DeleteHashTable(ss->TexObjects); DeleteHashTable(ss->TexObjects);
for (i=0;i<MAX_TEXTURE_UNITS;i++) { if (ss->DefaultD[1])
if (ss->DefaultD[1][i]) gl_free_texture_object(ss, ss->DefaultD[1]);
gl_free_texture_object(ss, ss->DefaultD[1][i]); if (ss->DefaultD[2])
if (ss->DefaultD[2][i]) gl_free_texture_object(ss, ss->DefaultD[2]);
gl_free_texture_object(ss, ss->DefaultD[2][i]); if (ss->DefaultD[3])
if (ss->DefaultD[3][i]) gl_free_texture_object(ss, ss->DefaultD[3]);
gl_free_texture_object(ss, ss->DefaultD[3][i]);
}
free(ss); free(ss);
return NULL; return NULL;
} }
@@ -486,9 +481,9 @@ static void init_texture_unit( GLcontext *ctx, GLuint unit )
ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 ); ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 ); ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
texUnit->CurrentD[1] = ctx->Shared->DefaultD[1][unit]; texUnit->CurrentD[1] = ctx->Shared->DefaultD[1];
texUnit->CurrentD[2] = ctx->Shared->DefaultD[2][unit]; texUnit->CurrentD[2] = ctx->Shared->DefaultD[2];
texUnit->CurrentD[3] = ctx->Shared->DefaultD[3][unit]; texUnit->CurrentD[3] = ctx->Shared->DefaultD[3];
} }

View File

@@ -1,4 +1,4 @@
/* $Id: texobj.c,v 1.3 1999/10/08 09:27:11 keithw Exp $ */ /* $Id: texobj.c,v 1.4 1999/10/09 20:17:07 brianp Exp $ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@@ -71,6 +71,7 @@ gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name,
calloc(1,sizeof(struct gl_texture_object)); calloc(1,sizeof(struct gl_texture_object));
if (obj) { if (obj) {
/* init the non-zero fields */ /* init the non-zero fields */
obj->RefCount = 1;
obj->Name = name; obj->Name = name;
obj->Dimensions = dimensions; obj->Dimensions = dimensions;
obj->WrapS = GL_REPEAT; obj->WrapS = GL_REPEAT;
@@ -382,8 +383,8 @@ void gl_DeleteTextures( GLcontext *ctx, GLsizei n, const GLuint *texName)
GLuint d; GLuint d;
for (d = 1 ; d <= 3 ; d++) { for (d = 1 ; d <= 3 ; d++) {
if (unit->CurrentD[d]==t) { if (unit->CurrentD[d]==t) {
unit->CurrentD[d] = ctx->Shared->DefaultD[d][u]; unit->CurrentD[d] = ctx->Shared->DefaultD[d];
ctx->Shared->DefaultD[d][u]->RefCount++; ctx->Shared->DefaultD[d]->RefCount++;
t->RefCount--; t->RefCount--;
assert( t->RefCount >= 0 ); assert( t->RefCount >= 0 );
} }
@@ -436,7 +437,7 @@ void gl_BindTexture( GLcontext *ctx, GLenum target, GLuint texName )
return; return;
if (texName == 0) if (texName == 0)
newTexObj = ctx->Shared->DefaultD[unit][dim]; newTexObj = ctx->Shared->DefaultD[dim];
else { else {
struct HashTable *hash = ctx->Shared->TexObjects; struct HashTable *hash = ctx->Shared->TexObjects;
newTexObj = (struct gl_texture_object *) HashLookup(hash, texName); newTexObj = (struct gl_texture_object *) HashLookup(hash, texName);
@@ -453,8 +454,8 @@ void gl_BindTexture( GLcontext *ctx, GLenum target, GLuint texName )
} }
} }
oldTexObj->RefCount--;
newTexObj->RefCount++; newTexObj->RefCount++;
texUnit->CurrentD[dim] = newTexObj; texUnit->CurrentD[dim] = newTexObj;
/* If we've changed the CurrentD[123] texture object then update the /* If we've changed the CurrentD[123] texture object then update the
@@ -482,6 +483,17 @@ void gl_BindTexture( GLcontext *ctx, GLenum target, GLuint texName )
if (ctx->Driver.BindTexture) { if (ctx->Driver.BindTexture) {
(*ctx->Driver.BindTexture)( ctx, target, newTexObj ); (*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 );
}
gl_free_texture_object(ctx->Shared, oldTexObj);
}
}
} }