summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mesa/main/attrib.c86
-rw-r--r--src/mesa/main/attrib.h4
-rw-r--r--src/mesa/main/context.c4
-rw-r--r--src/mesa/main/texobj.c10
-rw-r--r--src/mesa/main/texstate.c18
5 files changed, 112 insertions, 10 deletions
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 70c93c5986e..df40b88052e 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -343,7 +343,9 @@ _mesa_PushAttrib(GLbitfield mask)
* inadvertantly get deleted.
*/
#ifdef DEBUG
- printf("MESA PUSH TEX ATTRIB, INCR REF COUNT BY %d\n", ctx->Const.MaxTextureUnits);
+ printf("%lu: MESA PUSH TEX ATTRIB, INCR REF COUNT BY %d\n",
+ _glthread_GetID(),
+ ctx->Const.MaxTextureUnits);
#endif
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
@@ -798,7 +800,9 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
* inside the attribute state stack.
*/
#ifdef DEBUG
- printf("MESA POP TEX ATTRIB, DECR REF COUNT BY %d\n", ctx->Const.MaxTextureUnits);
+ printf("%lu: MESA POP TEX ATTRIB, DECR REF COUNT BY %d\n",
+ _glthread_GetID(),
+ ctx->Const.MaxTextureUnits);
#endif
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
ctx->Texture.Unit[u].Current1D->RefCount--;
@@ -1409,6 +1413,84 @@ _mesa_PopClientAttrib(void)
}
+static struct gl_texture_object *
+get_texobj(GLcontext *ctx, GLenum target, GLuint name)
+{
+ struct gl_texture_object *texObj;
+ if (name) {
+ texObj = _mesa_lookup_texture(ctx, name);
+ }
+ else {
+ switch (target) {
+ case GL_TEXTURE_1D:
+ texObj = ctx->Shared->Default1D;
+ break;
+ case GL_TEXTURE_2D:
+ texObj = ctx->Shared->Default2D;
+ break;
+ case GL_TEXTURE_3D:
+ texObj = ctx->Shared->Default3D;
+ break;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ texObj = ctx->Shared->DefaultCubeMap;
+ break;
+ case GL_TEXTURE_RECTANGLE_NV:
+ texObj = ctx->Shared->DefaultRect;
+ break;
+ default:
+ abort();
+ }
+ }
+ return texObj;
+}
+
+
+void
+_mesa_free_attrib_data(GLcontext *ctx)
+{
+#ifdef DEBUG
+ printf("%lu: MESA FREEING ATTRIB STACK DATA\n",
+ _glthread_GetID());
+#endif
+ while (ctx->AttribStackDepth > 0) {
+ struct gl_attrib_node *attr, *next;
+
+ ctx->AttribStackDepth--;
+ attr = ctx->AttribStack[ctx->AttribStackDepth];
+
+ while (attr) {
+ struct gl_texture_attrib *texAttrib
+ = (struct gl_texture_attrib *) attr->data;
+ GLuint u;
+
+ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
+ struct gl_texture_unit *unit = &texAttrib->Unit[u];
+ struct gl_texture_object *texObj;
+ texObj = get_texobj(ctx, GL_TEXTURE_1D, unit->Saved1D.Name);
+ MESA_REF_TEXOBJ(&texObj, NULL);
+ texObj = get_texobj(ctx, GL_TEXTURE_2D, unit->Saved2D.Name);
+ MESA_REF_TEXOBJ(&texObj, NULL);
+ texObj = get_texobj(ctx, GL_TEXTURE_3D, unit->Saved3D.Name);
+ MESA_REF_TEXOBJ(&texObj, NULL);
+ texObj = get_texobj(ctx, GL_TEXTURE_CUBE_MAP, unit->SavedCubeMap.Name);
+ MESA_REF_TEXOBJ(&texObj, NULL);
+ texObj = get_texobj(ctx, GL_TEXTURE_RECTANGLE_NV, unit->SavedRect.Name);
+ MESA_REF_TEXOBJ(&texObj, NULL);
+ }
+
+ next = attr->next;
+ _mesa_free(attr->data);
+ _mesa_free(attr);
+ attr = next;
+ }
+ }
+#ifdef DEBUG
+ printf("%lu: MESA DONE FREEING ATTRIB STACK DATA\n",
+ _glthread_GetID());
+#endif
+}
+
+
void _mesa_init_attrib( GLcontext *ctx )
{
/* Renderer and client attribute stacks */
diff --git a/src/mesa/main/attrib.h b/src/mesa/main/attrib.h
index 09d75196b23..ea28859e9ff 100644
--- a/src/mesa/main/attrib.h
+++ b/src/mesa/main/attrib.h
@@ -58,10 +58,14 @@ _mesa_PopClientAttrib( void );
extern void
_mesa_init_attrib( GLcontext *ctx );
+extern void
+_mesa_free_attrib_data( GLcontext *ctx );
+
#else
/** No-op */
#define _mesa_init_attrib( c ) ((void)0)
+#define _mesa_free_attrib_data( c ) ((void)0)
#endif
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 75ca54f20fe..64f3a7ffbc5 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1194,7 +1194,8 @@ _mesa_free_context_data( GLcontext *ctx )
if (ctx->AttribStackDepth > 0) {
#ifdef DEBUG
- printf("MESA: DESTROY CONTEXT WITH NON-EMPTRY ATTRIB STACK!\n");
+ printf("%lu: MESA: DESTROY CONTEXT WITH NON-EMPTRY ATTRIB STACK!\n",
+ _glthread_GetID());
#endif
}
@@ -1204,6 +1205,7 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_unreference_framebuffer(&ctx->DrawBuffer);
_mesa_unreference_framebuffer(&ctx->ReadBuffer);
+ _mesa_free_attrib_data(ctx);
_mesa_free_lighting_data( ctx );
_mesa_free_eval_data( ctx );
_mesa_free_texture_data( ctx );
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 86ad208b90b..fa14d919125 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -155,7 +155,9 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
GLuint i, face;
#ifdef DEBUG
- printf("MESA TEX DELETE %p (%u)\n", (void*) texObj, texObj->Name);
+ printf("%lu: MESA TEX DELETE %p (%u) REF COUNT = %d\n",
+ _glthread_GetID(),
+ (void*) texObj, texObj->Name, texObj->RefCount);
#endif
(void) ctx;
@@ -280,7 +282,8 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
oldTex->RefCount--;
#ifdef DEBUG
- printf("MESA TEX REF DECR %p (%u) to %d from %s\n",
+ printf("%lu: MESA TEX REF DECR %p (%u) to %d from %s\n",
+ _glthread_GetID(),
(void*) oldTex, oldTex->Name, oldTex->RefCount, where);
#endif
@@ -313,7 +316,8 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
tex->RefCount++;
#ifdef DEBUG
- printf("MESA TEX REF INCR %p (%u) to %d from %s\n",
+ printf("%lu: MESA TEX REF INCR %p (%u) to %d from %s\n",
+ _glthread_GetID(),
(void*) tex, tex->Name, tex->RefCount, where);
#endif
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 0589fe89efc..c4b678bf37d 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -3109,12 +3109,22 @@ _mesa_init_texture(GLcontext *ctx)
/**
- * Free dynamically-allocted texture data attached to the given context.
+ * Free dynamically-allocated texture data attached to the given context.
*/
void
_mesa_free_texture_data(GLcontext *ctx)
{
- GLuint i;
+ GLuint u;
+
+ /* unreference current textures */
+ for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
+ struct gl_texture_unit *unit = ctx->Texture.Unit + u;
+ MESA_REF_TEXOBJ(&unit->Current1D, NULL);
+ MESA_REF_TEXOBJ(&unit->Current2D, NULL);
+ MESA_REF_TEXOBJ(&unit->Current3D, NULL);
+ MESA_REF_TEXOBJ(&unit->CurrentCubeMap, NULL);
+ MESA_REF_TEXOBJ(&unit->CurrentRect, NULL);
+ }
/* Free proxy texture objects */
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D );
@@ -3123,8 +3133,8 @@ _mesa_free_texture_data(GLcontext *ctx)
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap );
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect );
- for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
- _mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
+ for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++)
+ _mesa_free_colortable_data( &ctx->Texture.Unit[u].ColorTable );
_mesa_TexEnvProgramCacheDestroy( ctx );
}