From fdb3acf016bd320ae15c89610b72ecdb806cff57 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 27 Jan 2006 03:42:56 +0000 Subject: [PATCH] added _swrast_eject_texture_images() --- src/mesa/swrast/s_context.c | 39 +++++++++++++++++++++++++++++++++++++ src/mesa/swrast/swrast.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index a1fb2d27f22..9eb81832dd3 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -32,6 +32,7 @@ #include "colormac.h" #include "mtypes.h" #include "program.h" +#include "teximage.h" #include "swrast.h" #include "s_blend.h" #include "s_context.h" @@ -406,6 +407,44 @@ _swrast_validate_texture_images(GLcontext *ctx) } +/** + * Free the texture image data attached to all currently enabled + * textures. Meant to be called by device drivers when transitioning + * from software to hardware rendering. + */ +void +_swrast_eject_texture_images(GLcontext *ctx) +{ + GLuint u; + + if (!ctx->Texture._EnabledUnits) { + /* no textures enabled */ + return; + } + + for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) { + if (ctx->Texture.Unit[u]._ReallyEnabled) { + struct gl_texture_object *texObj = ctx->Texture.Unit[u]._Current; + ASSERT(texObj); + if (texObj) { + GLuint numFaces = (texObj->Target == GL_TEXTURE_CUBE_MAP) ? 6 : 1; + GLuint face; + for (face = 0; face < numFaces; face++) { + GLuint lvl; + for (lvl = texObj->BaseLevel; lvl <= texObj->_MaxLevel; lvl++) { + struct gl_texture_image *texImg = texObj->Image[face][lvl]; + if (texImg && texImg->Data) { + _mesa_free_texmemory(texImg->Data); + texImg->Data = NULL; + } + } + } + } + } + } +} + + static void _swrast_sleep( GLcontext *ctx, GLbitfield new_state ) diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 9e63db02482..0587df3127a 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -244,6 +244,10 @@ _swrast_copy_texsubimage3d(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height); +extern void +_swrast_eject_texture_images(GLcontext *ctx); + + /** * The driver interface for the software rasterizer. * XXX this may go away.