diff --git a/doomsday/client/include/resource/texture.h b/doomsday/client/include/resource/texture.h index 1558d38120..0f05aa80d3 100644 --- a/doomsday/client/include/resource/texture.h +++ b/doomsday/client/include/resource/texture.h @@ -21,24 +21,6 @@ #ifndef LIBDENG_RESOURCE_TEXTURE_H #define LIBDENG_RESOURCE_TEXTURE_H -/// @addtogroup resource -///@{ -typedef enum { - TEXTURE_ANALYSIS_FIRST = 0, - TA_COLORPALETTE = TEXTURE_ANALYSIS_FIRST, - TA_SPRITE_AUTOLIGHT, - TA_COLOR, ///< Average. - TA_COLOR_AMPLIFIED, ///< Average amplified (max component ==1). - TA_ALPHA, ///< Average. - TA_LINE_TOP_COLOR, ///< Average. - TA_LINE_BOTTOM_COLOR, ///< Average. - TEXTURE_ANALYSIS_COUNT -} texture_analysisid_t; - -#define VALID_TEXTURE_ANALYSISID(id) (\ - (int)(id) >= TEXTURE_ANALYSIS_FIRST && (int)(id) < TEXTURE_ANALYSIS_COUNT) -///@} - #include "TextureVariantSpec" #include #include @@ -79,6 +61,33 @@ class Texture }; Q_DECLARE_FLAGS(Flags, Flag) + /** + * Image analysis identifiers. + */ + enum AnalysisId + { + /// Color palette info. + ColorPaletteAnalysis, + + /// Brightest point for automatic light sources. + BrightPointAnalysis, + + /// Average color. + AverageColorAnalysis, + + /// Average color amplified (max component ==1). + AverageColorAmplifiedAnalysis, + + /// Average alpha. + AverageAlphaAnalysis, + + /// Average top line color. + AverageTopColorAnalysis, + + /// Average bottom line color. + AverageBottomColorAnalysis + }; + /** * Context-specialized variant. Encapsulates all context variant values * and logics pertaining to a specialized version of the @em superior @@ -293,23 +302,23 @@ class Texture void clearAnalyses(); /** - * Retrieve the value of an identified @a analysis data pointer. + * Retrieve the value of an identified @a analysisId data pointer. * @return Associated data pointer value. */ - void *analysisDataPointer(texture_analysisid_t analysis) const; + void *analysisDataPointer(AnalysisId analysisId) const; /** - * Set the value of an identified @a analysis data pointer. Ownership of + * Set the value of an identified @a analysisId data pointer. Ownership of * the data is not given to this instance. * * @note If already set the old value will be replaced (so if it points * to some dynamically constructed data/resource it is the caller's * responsibility to release it beforehand). * - * @param analysis Identifier of the data being attached. + * @param analysisId Identifier of the data being attached. * @param data Data to be attached. */ - void setAnalysisDataPointer(texture_analysisid_t analysis, void *data); + void setAnalysisDataPointer(AnalysisId analysisId, void *data); /** * Retrieve the value of the associated user data pointer. diff --git a/doomsday/client/src/gl/gl_texmanager.cpp b/doomsday/client/src/gl/gl_texmanager.cpp index 8f63cfd8f3..7b32ee97fc 100644 --- a/doomsday/client/src/gl/gl_texmanager.cpp +++ b/doomsday/client/src/gl/gl_texmanager.cpp @@ -2864,7 +2864,7 @@ void GL_ReleaseTexturesForRawImages() void GL_SetAllTexturesMinFilter(int /*minFilter*/) { /// @todo This is no longer correct logic. Changing the global minification - /// filter should not modify the uploaded texture content. + /// filter should not modify the uploaded texture content. } static void performImageAnalyses(de::Texture &tex, image_t const *image, @@ -2875,14 +2875,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Do we need color palette info? if(TST_GENERAL == spec.type && image->paletteId != 0) { - colorpalette_analysis_t *cp = reinterpret_cast(tex.analysisDataPointer(TA_COLORPALETTE)); + colorpalette_analysis_t *cp = reinterpret_cast(tex.analysisDataPointer(Texture::ColorPaletteAnalysis)); bool firstInit = (!cp); if(firstInit) { cp = (colorpalette_analysis_t*) M_Malloc(sizeof(*cp)); - if(!cp) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new ColorPaletteAnalysis.", (unsigned long) sizeof(*cp)); - tex.setAnalysisDataPointer(TA_COLORPALETTE, cp); + if(!cp) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new ColorPaletteAnalysis.", (unsigned long) sizeof(*cp)); + tex.setAnalysisDataPointer(Texture::ColorPaletteAnalysis, cp); } if(firstInit || forceUpdate) @@ -2892,14 +2892,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Calculate a point light source for Dynlight and/or Halo? if(TST_GENERAL == spec.type && TC_SPRITE_DIFFUSE == TS_GENERAL(spec)->context) { - pointlight_analysis_t *pl = reinterpret_cast(tex.analysisDataPointer(TA_SPRITE_AUTOLIGHT)); + pointlight_analysis_t *pl = reinterpret_cast(tex.analysisDataPointer(Texture::BrightPointAnalysis)); bool firstInit = (!pl); if(firstInit) { - pl = (pointlight_analysis_t*) M_Malloc(sizeof *pl); - if(!pl) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new PointLightAnalysis.", (unsigned long) sizeof(*pl)); - tex.setAnalysisDataPointer(TA_SPRITE_AUTOLIGHT, pl); + pl = (pointlight_analysis_t *) M_Malloc(sizeof *pl); + if(!pl) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new PointLightAnalysis.", (unsigned long) sizeof(*pl)); + tex.setAnalysisDataPointer(Texture::BrightPointAnalysis, pl); } if(firstInit || forceUpdate) @@ -2913,14 +2913,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, (TS_GENERAL(spec)->context == TC_SPRITE_DIFFUSE || TS_GENERAL(spec)->context == TC_UI)) { - averagealpha_analysis_t *aa = reinterpret_cast(tex.analysisDataPointer(TA_ALPHA)); + averagealpha_analysis_t *aa = reinterpret_cast(tex.analysisDataPointer(Texture::AverageAlphaAnalysis)); bool firstInit = (!aa); if(firstInit) { - aa = (averagealpha_analysis_t*) M_Malloc(sizeof(*aa)); - if(!aa) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new AverageAlphaAnalysis.", (unsigned long) sizeof(*aa)); - tex.setAnalysisDataPointer(TA_ALPHA, aa); + aa = (averagealpha_analysis_t *) M_Malloc(sizeof(*aa)); + if(!aa) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageAlphaAnalysis.", (unsigned long) sizeof(*aa)); + tex.setAnalysisDataPointer(Texture::AverageAlphaAnalysis, aa); } if(firstInit || forceUpdate) @@ -2950,14 +2950,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Average color for sky ambient color? if(TST_GENERAL == spec.type && TC_SKYSPHERE_DIFFUSE == TS_GENERAL(spec)->context) { - averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(TA_COLOR)); + averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(Texture::AverageColorAnalysis)); bool firstInit = (!ac); if(firstInit) { - ac = (averagecolor_analysis_t*) M_Malloc(sizeof(*ac)); - if(!ac) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); - tex.setAnalysisDataPointer(TA_COLOR, ac); + ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac)); + if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); + tex.setAnalysisDataPointer(Texture::AverageColorAnalysis, ac); } if(firstInit || forceUpdate) @@ -2978,14 +2978,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Amplified average color for plane glow? if(TST_GENERAL == spec.type && TC_MAPSURFACE_DIFFUSE == TS_GENERAL(spec)->context) { - averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(TA_COLOR_AMPLIFIED)); + averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(Texture::AverageColorAmplifiedAnalysis)); bool firstInit = (!ac); if(firstInit) { - ac = (averagecolor_analysis_t*) M_Malloc(sizeof(*ac)); - if(!ac) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); - tex.setAnalysisDataPointer(TA_COLOR_AMPLIFIED, ac); + ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac)); + if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); + tex.setAnalysisDataPointer(Texture::AverageColorAmplifiedAnalysis, ac); } if(firstInit || forceUpdate) @@ -3007,14 +3007,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Average top line color for sky sphere fadeout? if(TST_GENERAL == spec.type && TC_SKYSPHERE_DIFFUSE == TS_GENERAL(spec)->context) { - averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(TA_LINE_TOP_COLOR)); + averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(Texture::AverageTopColorAnalysis)); bool firstInit = (!ac); if(firstInit) { - ac = (averagecolor_analysis_t*) M_Malloc(sizeof(*ac)); - if(!ac) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); - tex.setAnalysisDataPointer(TA_LINE_TOP_COLOR, ac); + ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac)); + if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); + tex.setAnalysisDataPointer(Texture::AverageTopColorAnalysis, ac); } if(firstInit || forceUpdate) @@ -3035,14 +3035,14 @@ static void performImageAnalyses(de::Texture &tex, image_t const *image, // Average bottom line color for sky sphere fadeout? if(TST_GENERAL == spec.type && TC_SKYSPHERE_DIFFUSE == TS_GENERAL(spec)->context) { - averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(TA_LINE_BOTTOM_COLOR)); + averagecolor_analysis_t *ac = reinterpret_cast(tex.analysisDataPointer(Texture::AverageBottomColorAnalysis)); bool firstInit = (!ac); if(firstInit) { - ac = (averagecolor_analysis_t*) M_Malloc(sizeof(*ac)); - if(!ac) Con_Error("Textures::performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); - tex.setAnalysisDataPointer(TA_LINE_BOTTOM_COLOR, ac); + ac = (averagecolor_analysis_t *) M_Malloc(sizeof(*ac)); + if(!ac) Con_Error("performImageAnalyses: Failed on allocation of %lu bytes for new AverageColorAnalysis.", (unsigned long) sizeof(*ac)); + tex.setAnalysisDataPointer(Texture::AverageBottomColorAnalysis, ac); } if(firstInit || forceUpdate) @@ -3170,9 +3170,9 @@ void GL_ReleaseVariantTexture(texturevariant_s *tex) static int releaseGLTexturesByColorPaletteWorker(de::Texture &tex, void *parameters) { - colorpalette_analysis_t* cp = reinterpret_cast(tex.analysisDataPointer(TA_COLORPALETTE)); - colorpaletteid_t paletteId = *(colorpaletteid_t *)parameters; DENG_ASSERT(parameters); + colorpalette_analysis_t *cp = reinterpret_cast(tex.analysisDataPointer(Texture::ColorPaletteAnalysis)); + colorpaletteid_t paletteId = *(colorpaletteid_t *)parameters; if(cp && cp->paletteId == paletteId) { diff --git a/doomsday/client/src/render/lumobj.cpp b/doomsday/client/src/render/lumobj.cpp index ba49949672..2a50eb7939 100644 --- a/doomsday/client/src/render/lumobj.cpp +++ b/doomsday/client/src/render/lumobj.cpp @@ -749,8 +749,8 @@ static void addLuminous(mobj_t *mo) MaterialSnapshot const &ms = mat->prepare(Rend_SpriteMaterialSpec()); if(!ms.hasTexture(MTU_PRIMARY)) return; // An invalid sprite texture? - pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_SPRITE_AUTOLIGHT); - if(!pl) throw Error("addLuminous", QString("Texture \"%1\" has no TA_SPRITE_AUTOLIGHT analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); + pl = reinterpret_cast(ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(Texture::BrightPointAnalysis)); + if(!pl) throw Error("addLuminous", QString("Texture \"%1\" has no BrightPointAnalysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); size = pl->brightMul; yOffset = ms.dimensions().height() * pl->originY; @@ -963,8 +963,8 @@ static void createGlowLightForSurface(Surface &suf) MaterialSnapshot const &ms = suf.material->prepare(Rend_MapSurfaceMaterialSpec()); if(!(ms.glowStrength() > .001f)) break; - averagecolor_analysis_t const *avgColorAmplified = (averagecolor_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_COLOR_AMPLIFIED); - if(!avgColorAmplified) throw Error("createGlowLightForSurface", QString("Texture \"%1\" has no TA_COLOR_AMPLIFIED analysis)").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); + averagecolor_analysis_t const *avgColorAmplified = reinterpret_cast(ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(Texture::AverageColorAmplifiedAnalysis)); + if(!avgColorAmplified) throw Error("createGlowLightForSurface", QString("Texture \"%1\" has no AverageColorAmplifiedAnalysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); // @note Plane lights do not spread so simply link to all BspLeafs of this sector. lumobj_t *lum = createLuminous(LT_PLANE, sec->bspLeafs[0]); diff --git a/doomsday/client/src/render/r_things.cpp b/doomsday/client/src/render/r_things.cpp index 49bf12cf5c..7154c873cf 100644 --- a/doomsday/client/src/render/r_things.cpp +++ b/doomsday/client/src/render/r_things.cpp @@ -546,12 +546,12 @@ float R_ShadowStrength(mobj_t *mo) // Ensure we've prepared this. MaterialSnapshot const &ms = mat->prepare(Rend_SpriteMaterialSpec()); - averagealpha_analysis_t const *aa = (averagealpha_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_ALPHA); + averagealpha_analysis_t const *aa = (averagealpha_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(Texture::AverageAlphaAnalysis); float weightedSpriteAlpha; if(!aa) { QByteArray uri = ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri().asText().toUtf8(); - Con_Error("R_ShadowStrength: Texture \"%s\" has no TA_ALPHA analysis", uri.constData()); + Con_Error("R_ShadowStrength: Texture \"%s\" has no AverageAlphaAnalysis", uri.constData()); } // We use an average which factors in the coverage ratio @@ -1289,11 +1289,11 @@ void R_ProjectSprite(mobj_t *mo) // Ensure we have up-to-date information about the material. MaterialSnapshot const &ms = mat->prepare(Rend_SpriteMaterialSpec()); - pointlight_analysis_t const *pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(TA_SPRITE_AUTOLIGHT); + pointlight_analysis_t const *pl = (pointlight_analysis_t const *) ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer(Texture::BrightPointAnalysis); if(!pl) { QByteArray uri = ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri().asText().toUtf8(); - Con_Error("R_ProjectSprite: Texture \"%s\" has no TA_SPRITE_AUTOLIGHT analysis", uri.constData()); + Con_Error("R_ProjectSprite: Texture \"%s\" has no BrightPointAnalysis", uri.constData()); } lumobj_t const *lum = LO_GetLuminous(mo->lumIdx); diff --git a/doomsday/client/src/render/sky.cpp b/doomsday/client/src/render/sky.cpp index 8c0d9bf7d5..e1175b174f 100644 --- a/doomsday/client/src/render/sky.cpp +++ b/doomsday/client/src/render/sky.cpp @@ -219,18 +219,18 @@ static void calculateSkyAmbientColor() if(ms.hasTexture(MTU_PRIMARY)) { Texture const &tex = ms.texture(MTU_PRIMARY).generalCase(); - averagecolor_analysis_t const *avgColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_COLOR); - if(!avgColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_COLOR analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); + averagecolor_analysis_t const *avgColor = reinterpret_cast(tex.analysisDataPointer(Texture::AverageColorAnalysis)); + if(!avgColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no AverageColorAnalysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri())); if(i == firstSkyLayer) { - averagecolor_analysis_t const *avgLineColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_LINE_TOP_COLOR); - if(!avgLineColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_TOP_COLOR analysis").arg(tex.manifest().composeUri())); + averagecolor_analysis_t const *avgLineColor = reinterpret_cast(tex.analysisDataPointer(Texture::AverageTopColorAnalysis)); + if(!avgLineColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no AverageTopColorAnalysis").arg(tex.manifest().composeUri())); V3f_Copy(topCapColor.rgb, avgLineColor->color.rgb); - avgLineColor = (averagecolor_analysis_t const *) tex.analysisDataPointer(TA_LINE_BOTTOM_COLOR); - if(!avgLineColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no TA_LINE_BOTTOM_COLOR analysis").arg(tex.manifest().composeUri())); + avgLineColor = reinterpret_cast(tex.analysisDataPointer(Texture::AverageBottomColorAnalysis)); + if(!avgLineColor) throw Error("calculateSkyAmbientColor", QString("Texture \"%1\" has no AverageBottomColorAnalysis").arg(tex.manifest().composeUri())); V3f_Copy(bottomCapColor.rgb, avgLineColor->color.rgb); } @@ -826,10 +826,10 @@ static void configureRenderHemisphereStateForLayer(int layer, hemispherecap_t se if(setupCap != HC_NONE) { - averagecolor_analysis_t const *avgLineColor = (averagecolor_analysis_t const *) - ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer((setupCap == HC_TOP? TA_LINE_TOP_COLOR : TA_LINE_BOTTOM_COLOR)); + averagecolor_analysis_t const *avgLineColor = reinterpret_cast + (ms.texture(MTU_PRIMARY).generalCase().analysisDataPointer((setupCap == HC_TOP? Texture::AverageTopColorAnalysis : Texture::AverageBottomColorAnalysis))); float const fadeoutLimit = Sky_LayerFadeoutLimit(layer); - if(!avgLineColor) throw Error("configureRenderHemisphereStateForLayer", QString("Texture \"%1\" has no %2 analysis").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri()).arg(setupCap == HC_TOP? "TA_LINE_TOP_COLOR" : "TA_LINE_BOTTOM_COLOR")); + if(!avgLineColor) throw Error("configureRenderHemisphereStateForLayer", QString("Texture \"%1\" has no %2").arg(ms.texture(MTU_PRIMARY).generalCase().manifest().composeUri()).arg(setupCap == HC_TOP? "AverageTopColorAnalysis" : "AverageBottomColorAnalysis")); V3f_Copy(rs.capColor.rgb, avgLineColor->color.rgb); // Is the colored fadeout in use? diff --git a/doomsday/client/src/resource/r_data.cpp b/doomsday/client/src/resource/r_data.cpp index 586bd715d6..4a58f917f3 100644 --- a/doomsday/client/src/resource/r_data.cpp +++ b/doomsday/client/src/resource/r_data.cpp @@ -243,7 +243,7 @@ DENG_EXTERN_C boolean R_GetPatchInfo(patchid_t id, patchinfo_t *info) info->id = id; info->flags.isCustom = tex.flags().testFlag(Texture::Custom); - averagealpha_analysis_t *aa = reinterpret_cast(tex.analysisDataPointer(TA_ALPHA)); + averagealpha_analysis_t *aa = reinterpret_cast(tex.analysisDataPointer(Texture::AverageAlphaAnalysis)); info->flags.isEmpty = aa && FEQUAL(aa->alpha, 0); info->geometry.size.width = tex.width(); diff --git a/doomsday/client/src/resource/texture.cpp b/doomsday/client/src/resource/texture.cpp index d1350c3a71..992c0f4a6f 100644 --- a/doomsday/client/src/resource/texture.cpp +++ b/doomsday/client/src/resource/texture.cpp @@ -26,9 +26,12 @@ #include "resource/compositetexture.h" #include #include +#include #include "Texture" +typedef QMap Analyses; + namespace de { DENG2_PIMPL(Texture) @@ -50,18 +53,16 @@ DENG2_PIMPL(Texture) /// World origin offset in map coordinate space units. QPoint origin; - /// Table of analyses object ptrs, used for various purposes depending - /// on the variant specification. - void *analyses[TEXTURE_ANALYSIS_COUNT]; + /// Image analysis data, used for various purposes according to context. + Analyses analyses; Instance(Public &a, TextureManifest &_manifest) : Base(a), manifest(_manifest), userData(0) - { - std::memset(analyses, 0, sizeof(analyses)); - } + {} ~Instance() { + self.clearAnalyses(); clearVariants(); } @@ -108,16 +109,6 @@ TextureManifest &Texture::manifest() const return d->manifest; } -void Texture::clearAnalyses() -{ - for(uint i = uint(TEXTURE_ANALYSIS_FIRST); i < uint(TEXTURE_ANALYSIS_COUNT); ++i) - { - texture_analysisid_t analysis = texture_analysisid_t(i); - void* data = analysisDataPointer(analysis); - if(data) M_Free(data); - setAnalysisDataPointer(analysis, 0); - } -} void Texture::setUserDataPointer(void *newUserData) { @@ -223,24 +214,37 @@ void Texture::clearVariants() d->clearVariants(); } -void *Texture::analysisDataPointer(texture_analysisid_t analysisId) const +void Texture::clearAnalyses() +{ + foreach(void *data, d->analyses) + { + M_Free(data); + } + d->analyses.clear(); +} + +void *Texture::analysisDataPointer(AnalysisId analysisId) const { - DENG2_ASSERT(VALID_TEXTURE_ANALYSISID(analysisId)); - return d->analyses[analysisId]; + if(!d->analyses.contains(analysisId)) return 0; + return d->analyses.value(analysisId); } -void Texture::setAnalysisDataPointer(texture_analysisid_t analysisId, void *data) +void Texture::setAnalysisDataPointer(AnalysisId analysisId, void *newData) { - DENG2_ASSERT(VALID_TEXTURE_ANALYSISID(analysisId)); - if(d->analyses[analysisId] && data) + LOG_AS("Texture::attachAnalysis"); + void *existingData = analysisDataPointer(analysisId); + if(existingData) { #if _DEBUG - LOG_AS("Texture::attachAnalysis"); - LOG_DEBUG("Image analysis (id:%i) already present for \"%s\" (replaced).") - << int(analysisId) << d->manifest.composeUri(); + if(newData) + { + LOG_DEBUG("Image analysis (id:%i) already present for \"%s\", (will replace).") + << int(analysisId) << d->manifest.composeUri(); + } #endif + M_Free(existingData); } - d->analyses[analysisId] = data; + d->analyses.insert(analysisId, newData); } Texture::Flags Texture::flags() const