Skip to content

Commit

Permalink
ResourceSystem: Cleanup prepared GL texture release
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Dec 6, 2013
1 parent 920c760 commit 74de24c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 73 deletions.
23 changes: 0 additions & 23 deletions doomsday/client/include/resource/resourcesystem.h
Expand Up @@ -644,29 +644,6 @@ class ResourceSystem : public de::System
*/
void releaseGLTexturesByScheme(de::String schemeName);

/**
* Release all GL-textures prepared using @a colorPalette.
*/
void releaseGLTexturesFor(ColorPalette const &colorPalette);

/**
* Release all GL-textures associated with the specified variant @a texture.
*/
void releaseGLTexturesFor(de::TextureVariant &texture);

/**
* Release all GL-textures associated with the specified @a texture.
*/
void releaseGLTexturesFor(de::Texture &texture);

/**
* Release all variants of @a tex which match @a spec.
*
* @param texture Logical Texture to process. Can be @c NULL, in which case this is a null-op.
* @param spec Specification to match. Comparision mode is exact and not fuzzy.
*/
void releaseGLTexturesFor(de::Texture &texture, TextureVariantSpec &spec);

/**
* Prepare a material variant specification in accordance to the specified
* usage context. If incomplete context information is supplied, suitable
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/include/resource/texture.h
Expand Up @@ -366,6 +366,13 @@ class Texture
*/
uint variantCount() const;

/**
* Release prepared GL-textures for identified variants.
*
* @param spec If non-zero release only for variants derived with this spec.
*/
void releaseGLTextures(TextureVariantSpec *spec = 0);

#endif // __CLIENT__

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/compositebitmapfont.cpp
Expand Up @@ -190,7 +190,7 @@ void CompositeBitmapFont::glDeinit()
{
Glyph *ch = &d->glyphs[i];
if(!ch->tex) continue;
App_ResourceSystem().releaseGLTexturesFor(*ch->tex);
ch->tex->release();
ch->tex = 0;
}
}
Expand Down
58 changes: 10 additions & 48 deletions doomsday/client/src/resource/resourcesystem.cpp
Expand Up @@ -1872,7 +1872,15 @@ DENG2_PIMPL(ResourceSystem)
/// Observes ColorPalette ColorTableChange
void colorPaletteColorTableChanged(ColorPalette &colorPalette)
{
self.releaseGLTexturesFor(colorPalette);
// Release all GL-textures prepared using @a colorPalette.
foreach(Texture *texture, textures)
{
colorpalette_analysis_t *cp = reinterpret_cast<colorpalette_analysis_t *>(texture->analysisDataPointer(Texture::ColorPaletteAnalysis));
if(cp && cp->paletteId == colorpaletteid_t(colorPalette.id()))
{
texture->releaseGLTextures();
}
}
}

#endif // __CLIENT__
Expand Down Expand Up @@ -2620,16 +2628,6 @@ ResourceSystem::AllTextures const &ResourceSystem::allTextures() const

#ifdef __CLIENT__

static int releaseGLTexture(TextureVariant &variant, TextureVariantSpec *spec = 0)
{
if(!spec || spec == &variant.spec())
{
variant.release();
if(spec) return true; // We're done.
}
return 0; // Continue iteration.
}

void ResourceSystem::releaseAllSystemGLTextures()
{
if(novideo) return;
Expand Down Expand Up @@ -2686,42 +2684,6 @@ void ResourceSystem::releaseAllGLTextures()
releaseAllSystemGLTextures();
}

void ResourceSystem::releaseGLTexturesFor(ColorPalette const &colorPalette)
{
foreach(Texture *texture, d->textures)
{
colorpalette_analysis_t *cp = reinterpret_cast<colorpalette_analysis_t *>(texture->analysisDataPointer(Texture::ColorPaletteAnalysis));
if(cp && cp->paletteId == colorpaletteid_t(colorPalette.id()))
{
releaseGLTexturesFor(*texture);
}
}
}

void ResourceSystem::releaseGLTexturesFor(TextureVariant &tex)
{
releaseGLTexture(tex);
}

void ResourceSystem::releaseGLTexturesFor(Texture &texture)
{
foreach(TextureVariant *variant, texture.variants())
{
releaseGLTexture(*variant);
}
}

void ResourceSystem::releaseGLTexturesFor(Texture &texture, TextureVariantSpec &spec)
{
foreach(TextureVariant *variant, texture.variants())
{
if(releaseGLTexture(*variant, &spec))
{
break;
}
}
}

void ResourceSystem::releaseGLTexturesByScheme(String schemeName)
{
if(schemeName.isEmpty()) return;
Expand All @@ -2732,7 +2694,7 @@ void ResourceSystem::releaseGLTexturesByScheme(String schemeName)
TextureManifest &manifest = iter.next();
if(manifest.hasTexture())
{
releaseGLTexturesFor(manifest.texture());
manifest.texture().releaseGLTextures();
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions doomsday/client/src/resource/texture.cpp
Expand Up @@ -253,6 +253,21 @@ void Texture::clearVariants()
}
}

void Texture::releaseGLTextures(TextureVariantSpec *spec)
{
foreach(TextureVariant *variant, variants())
{
if(!spec || spec == &variant->spec())
{
variant->release();
if(spec)
{
break;
}
}
}
}

#endif // __CLIENT__

void Texture::clearAnalyses()
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/src/resource/texturescheme.cpp
Expand Up @@ -251,7 +251,7 @@ TextureManifest &TextureScheme::declare(Path const &path,
{
#ifdef __CLIENT__
/// @todo Update any Materials (and thus Surfaces) which reference this.
App_ResourceSystem().releaseGLTexturesFor(newManifest->texture());
newManifest->texture().releaseGLTextures();
#endif
}

Expand Down

0 comments on commit 74de24c

Please sign in to comment.