From 8208d9c20d6c96b2efe4d28eb8a15a228fb4ed3c Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 10 Jan 2012 15:46:46 +0000 Subject: [PATCH] TextureVariant: Record the source of the uploaded graphic Presently the source is identified using a set of ids, one for each logical source type (i.e., original or external). Ultimately these identifiers should be replaced with references to the actual files they were loaded from (thereby enabling us to reverse lookup all textures uploaded from a given addon, for example). --- .../engine/portable/include/gl_texmanager.h | 28 +-- .../engine/portable/include/texturevariant.h | 15 +- .../include/texturevariantspecification.h | 9 + doomsday/engine/portable/src/gl_texmanager.c | 223 +++++++++--------- doomsday/engine/portable/src/texturevariant.c | 18 +- 5 files changed, 165 insertions(+), 128 deletions(-) diff --git a/doomsday/engine/portable/include/gl_texmanager.h b/doomsday/engine/portable/include/gl_texmanager.h index 7331890ebe..2469072d2f 100644 --- a/doomsday/engine/portable/include/gl_texmanager.h +++ b/doomsday/engine/portable/include/gl_texmanager.h @@ -188,30 +188,22 @@ void GL_UploadTextureContent(const struct texturecontent_s* content); uint8_t* GL_LoadImage(struct image_s* img, const char* filePath); uint8_t* GL_LoadImageStr(struct image_s* img, const ddstring_t* filePath); -/** - * Image loading routines: - * @return The outcome: - * 0 = not prepared - * 1 = found and prepared a lump resource. - * 2 = found and prepared an external resource. - */ - -byte GL_LoadRawTex(struct image_s* image, const rawtex_t* r); +TexSource GL_LoadRawTex(struct image_s* image, const rawtex_t* r); -byte GL_LoadExtTexture(struct image_s* image, const char* name, gfxmode_t mode); -byte GL_LoadExtTextureEX(struct image_s* image, const char* searchPath, const char* optionalSuffix, - boolean quiet); +TexSource GL_LoadExtTexture(struct image_s* image, const char* name, gfxmode_t mode); +TexSource GL_LoadExtTextureEX(struct image_s* image, const char* searchPath, + const char* optionalSuffix, boolean quiet); -byte GL_LoadFlatLump(struct image_s* image, DFile* file); +TexSource GL_LoadFlatLump(struct image_s* image, DFile* file); -byte GL_LoadPatchLumpAsPatch(struct image_s* image, DFile* file, int tclass, int tmap, - int border, Texture* tex); +TexSource GL_LoadPatchLumpAsPatch(struct image_s* image, DFile* file, int tclass, + int tmap, int border, Texture* tex); -byte GL_LoadDetailTextureLump(struct image_s* image, DFile* file); +TexSource GL_LoadDetailTextureLump(struct image_s* image, DFile* file); -byte GL_LoadPatchComposite(struct image_s* image, Texture* tex); +TexSource GL_LoadPatchComposite(struct image_s* image, Texture* tex); -byte GL_LoadPatchCompositeAsSky(struct image_s* image, Texture* tex, boolean zeroMask); +TexSource GL_LoadPatchCompositeAsSky(struct image_s* image, Texture* tex, boolean zeroMask); /** * Compare the given TextureVariantSpecifications and determine whether they can diff --git a/doomsday/engine/portable/include/texturevariant.h b/doomsday/engine/portable/include/texturevariant.h index ad0eae38f2..d0d509b2ce 100644 --- a/doomsday/engine/portable/include/texturevariant.h +++ b/doomsday/engine/portable/include/texturevariant.h @@ -41,17 +41,26 @@ typedef struct texturevariant_s TextureVariant; /** * @param generalCase Texture from which this variant is derived. - * @param spec Specification used to derive this variant. Ownership of - * specifcation is NOT given to the resultant TextureVariant + * @param spec Specification used to derive this variant. Ownership + * is NOT given to the resultant TextureVariant */ TextureVariant* TextureVariant_New(struct texture_s* generalCase, - texturevariantspecification_t* spec); + TexSource source, texturevariantspecification_t* spec); void TextureVariant_Delete(TextureVariant* tex); /// @return Superior Texture of which this is a derivative. struct texture_s* TextureVariant_GeneralCase(const TextureVariant* tex); +/// @return Source of this variant. +TexSource TextureVariant_Source(const TextureVariant* tex); + +/** + * Change the source of this variant. + * @param source New TextureSource. + */ +void TextureVariant_SetSource(TextureVariant* tex, TexSource source); + /// @return TextureVariantSpecification used to derive this variant. texturevariantspecification_t* TextureVariant_Spec(const TextureVariant* tex); diff --git a/doomsday/engine/portable/include/texturevariantspecification.h b/doomsday/engine/portable/include/texturevariantspecification.h index bd5c4d4467..51bed89ba0 100644 --- a/doomsday/engine/portable/include/texturevariantspecification.h +++ b/doomsday/engine/portable/include/texturevariantspecification.h @@ -24,6 +24,15 @@ #ifndef LIBDENG_GL_TEXTUREVARIANTSPECIFICATION_H #define LIBDENG_GL_TEXTUREVARIANTSPECIFICATION_H +/** + * Texture (content) Source. + */ +typedef enum { + TEXS_NONE, /// Not a valid source. + TEXS_ORIGINAL, /// An "original". + TEXS_EXTERNAL /// An "external" replacement. +} TexSource; + typedef enum { TC_UNKNOWN = -1, TEXTUREVARIANTUSAGECONTEXT_FIRST = 0, diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c index bb3176e9c0..177c266c75 100644 --- a/doomsday/engine/portable/src/gl_texmanager.c +++ b/doomsday/engine/portable/src/gl_texmanager.c @@ -660,11 +660,11 @@ static void uploadContentUnmanaged(uploadcontentmethod_t uploadMethod, uploadContent(uploadMethod, content); } -static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* baseSpec, +static TexSource loadSourceImage(Texture* tex, const texturevariantspecification_t* baseSpec, image_t* image) { const variantspecification_t* spec; - byte loadResult = 0; + TexSource source = TEXS_NONE; assert(tex && baseSpec && image); spec = TS_GENERAL(baseSpec); @@ -685,11 +685,11 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b FLATS_RESOURCE_NAMESPACE_NAME":%s;" TEXTURES_RESOURCE_NAMESPACE_NAME":flat-%s;", Str_Text(path), Str_Text(path)); - loadResult = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); + source = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); Str_Free(&searchPath); Str_Delete(path); } - if(0 == loadResult) + if(source == TEXS_NONE) { const Uri* resourcePath = Textures_ResourcePath(Textures_Id(tex)); lumpnum_t lumpNum = -1; @@ -705,7 +705,7 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b if(F_IsValidLumpNum(lumpNum)) { DFile* file = F_OpenLump(lumpNum); - loadResult = GL_LoadFlatLump(image, file); + source = GL_LoadFlatLump(image, file); F_Delete(file); } } @@ -730,11 +730,11 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b Str_Init(&searchPath); Str_Appendf(&searchPath, PATCHES_RESOURCE_NAMESPACE_NAME":%s;", Str_Text(path)); - loadResult = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); + source = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); Str_Free(&searchPath); Str_Delete(path); } - if(0 == loadResult) + if(source == TEXS_NONE) { const Uri* resourcePath = Textures_ResourcePath(Textures_Id(tex)); if(!Str_CompareIgnoreCase(Uri_Scheme(resourcePath), "Lumps")) @@ -743,7 +743,7 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b if(F_IsValidLumpNum(lumpNum)) { DFile* file = F_OpenLump(lumpNum); - loadResult = GL_LoadPatchLumpAsPatch(image, file, tclass, tmap, spec->border, tex); + source = GL_LoadPatchLumpAsPatch(image, file, tclass, tmap, spec->border, tex); F_Delete(file); } } @@ -778,11 +778,11 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b } Str_Appendf(&searchPath, PATCHES_RESOURCE_NAMESPACE_NAME":%s", Str_Text(path)); - loadResult = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); + source = GL_LoadExtTextureEX(image, Str_Text(&searchPath), Str_Text(&suffix), true/*quiet please*/); Str_Free(&searchPath); Str_Delete(path); } - if(0 == loadResult) + if(source == TEXS_NONE) { const Uri* resourcePath = Textures_ResourcePath(Textures_Id(tex)); if(!Str_CompareIgnoreCase(Uri_Scheme(resourcePath), "Lumps")) @@ -791,7 +791,7 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b if(F_IsValidLumpNum(lumpNum)) { DFile* file = F_OpenLump(lumpNum); - loadResult = GL_LoadPatchLumpAsPatch(image, file, tclass, tmap, spec->border, tex); + source = GL_LoadPatchLumpAsPatch(image, file, tclass, tmap, spec->border, tex); F_Delete(file); } } @@ -803,7 +803,7 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b if(Str_CompareIgnoreCase(Uri_Scheme(resourcePath), "Lumps")) { ddstring_t* searchPath = Uri_ComposePath(resourcePath); - loadResult = GL_LoadExtTextureEX(image, Str_Text(searchPath), NULL, true/*quiet please*/); + source = GL_LoadExtTextureEX(image, Str_Text(searchPath), NULL, true/*quiet please*/); Str_Delete(searchPath); } else @@ -812,7 +812,7 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b if(lumpNum >= 0) { DFile* file = F_OpenLump(lumpNum); - loadResult = GL_LoadDetailTextureLump(image, file); + source = GL_LoadDetailTextureLump(image, file); F_Delete(file); } } @@ -827,15 +827,15 @@ static byte loadSourceImage(Texture* tex, const texturevariantspecification_t* b case TN_MODELREFLECTIONSKINS: { const Uri* resourcePath = Textures_ResourcePath(Textures_Id(tex)); ddstring_t* path = Uri_ComposePath(resourcePath); - loadResult = GL_LoadExtTextureEX(image, Str_Text(path), NULL, true/*quiet please*/); + source = GL_LoadExtTextureEX(image, Str_Text(path), NULL, true/*quiet please*/); Str_Delete(path); break; } default: Con_Error("Textures::loadSourceImage: Unknown texture namespace %i.", (int) Textures_Namespace(Textures_Id(tex))); - return 0; // Unreachable. + exit(1); // Unreachable. } - return loadResult; + return source; } static uploadcontentmethod_t prepareVariant(TextureVariant* tex, image_t* image) @@ -1512,15 +1512,15 @@ uint8_t* GL_LoadImageFromFile(image_t* img, DFile* file) uint8_t* GL_LoadImage(image_t* img, const char* filePath) { DFile* file = F_Open(filePath, "rb"); - uint8_t* result = NULL; + uint8_t* pixels = NULL; assert(img); if(file) { - result = GL_LoadImageFromFile(img, file); + pixels = GL_LoadImageFromFile(img, file); F_Delete(file); } - return result; + return pixels; } uint8_t* GL_LoadImageStr(image_t* img, const ddstring_t* filePath) @@ -2063,8 +2063,8 @@ void GL_UploadTextureContent(const texturecontent_t* content) } } -byte GL_LoadExtTextureEX(image_t* image, const char* searchPath, const char* optionalSuffix, - boolean silent) +TexSource GL_LoadExtTextureEX(image_t* image, const char* searchPath, + const char* optionalSuffix, boolean silent) { ddstring_t foundPath; assert(image && searchPath); @@ -2074,17 +2074,17 @@ byte GL_LoadExtTextureEX(image_t* image, const char* searchPath, const char* opt { Str_Free(&foundPath); if(!silent) Con_Message("GL_LoadExtTextureEX: Warning, failed to locate \"%s\"\n", searchPath); - return 0; + return TEXS_NONE; } if(GL_LoadImage(image, Str_Text(&foundPath))) { Str_Free(&foundPath); - return 2; + return TEXS_EXTERNAL; } Str_Free(&foundPath); if(!silent) Con_Message("GL_LoadExtTextureEX: Warning, failed to load \"%s\"\n", F_PrettyPath(searchPath)); - return 0; + return TEXS_NONE; } DGLuint GL_PrepareLSTexture(lightingtexid_t which) @@ -2128,10 +2128,10 @@ DGLuint GL_PrepareSysFlareTexture(flaretexid_t flare) return sysFlareTextures[flare].tex; } -byte GL_LoadExtTexture(image_t* image, const char* name, gfxmode_t mode) +TexSource GL_LoadExtTexture(image_t* image, const char* name, gfxmode_t mode) { + TexSource source = TEXS_NONE; ddstring_t foundPath; - byte result = 0; Str_Init(&foundPath); if(F_FindResource2(RC_GRAPHIC, name, &foundPath) != 0 && @@ -2146,10 +2146,10 @@ byte GL_LoadExtTexture(image_t* image, const char* name, gfxmode_t mode) { GL_ConvertToLuminance(image, true); } - result = 2; // External. + source = TEXS_EXTERNAL; } Str_Free(&foundPath); - return result; + return source; } // Posts are runs of non masked source pixels. @@ -2294,14 +2294,14 @@ static boolean palettedIsMasked(const uint8_t* pixels, int width, int height) return false; } -byte GL_LoadDetailTextureLump(image_t* image, DFile* file) +TexSource GL_LoadDetailTextureLump(image_t* image, DFile* file) { - byte result = 0; + TexSource source = TEXS_NONE; assert(image && file); - if(0 != GL_LoadImageFromFile(image, file)) + if(GL_LoadImageFromFile(image, file)) { - result = 1; + source = TEXS_ORIGINAL; } else { // It must be an old-fashioned "raw" image. @@ -2323,7 +2323,7 @@ byte GL_LoadDetailTextureLump(image_t* image, DFile* file) case 64 * 64: image->size.width = image->size.height = 64; break; default: Con_Error("GL_LoadDetailTextureLump: Must be 256x256, 128x128 or 64x64.\n"); - return 0; // Unreachable. + exit(1); // Unreachable. } image->pixelSize = 1; @@ -2336,22 +2336,23 @@ byte GL_LoadDetailTextureLump(image_t* image, DFile* file) // Load the raw image data. DFile_Read(file, image->pixels, fileLength); - result = 1; + source = TEXS_ORIGINAL; } - return result; + return source; } -byte GL_LoadFlatLump(image_t* image, DFile* file) +TexSource GL_LoadFlatLump(image_t* image, DFile* file) { - byte result = 0; + TexSource source = TEXS_NONE; assert(image && file); - if(0 != GL_LoadImageFromFile(image, file)) + if(GL_LoadImageFromFile(image, file)) { - result = 1; + source = TEXS_EXTERNAL; } else - { // A DOOM flat. + { + // A DOOM flat. #define FLAT_WIDTH 64 #define FLAT_HEIGHT 64 @@ -2374,25 +2375,26 @@ byte GL_LoadFlatLump(image_t* image, DFile* file) // Load the raw image data. DFile_Read(file, image->pixels, fileLength); - result = 1; + source = TEXS_ORIGINAL; #undef FLAT_HEIGHT #undef FLAT_WIDTH } - return result; + return source; } -static byte loadPatchLump(image_t* image, DFile* file, int tclass, int tmap, int border) +static TexSource loadPatchLump(image_t* image, DFile* file, int tclass, int tmap, int border) { - byte result = 0; + TexSource source = TEXS_NONE; assert(image && file); - if(0 != GL_LoadImageFromFile(image, file)) + if(GL_LoadImageFromFile(image, file)) { - result = 2; + source = TEXS_EXTERNAL; } else - { // A DOOM patch. + { + // A DOOM patch. size_t fileLength = DFile_Length(file); if(fileLength > sizeof(doompatch_header_t)) { @@ -2414,25 +2416,25 @@ static byte loadPatchLump(image_t* image, DFile* file, int tclass, int tmap, int border, border, tclass, tmap, false); if(palettedIsMasked(image->pixels, image->size.width, image->size.height)) image->flags |= IMGF_IS_MASKED; - result = 1; + source = TEXS_ORIGINAL; } F_CacheChangeTag(DFile_File(file), 0, PU_CACHE); } - if(!result) + if(source == TEXS_NONE) { Con_Message("Warning: Lump \"%s\" does not appear to be a valid Patch.\n", F_PrettyPath(Str_Text(AbstractFile_Path(DFile_File(file))))); - return result; + return source; } } - return result; + return source; } -byte GL_LoadPatchLumpAsPatch(image_t* image, DFile* file, int tclass, int tmap, int border, +TexSource GL_LoadPatchLumpAsPatch(image_t* image, DFile* file, int tclass, int tmap, int border, Texture* tex) { - byte result = loadPatchLump(image, file, tclass, tmap, border); - if(1 == result && tex) + TexSource source = loadPatchLump(image, file, tclass, tmap, border); + if(source == TEXS_ORIGINAL && tex) { // Loaded from a lump assumed to be in DOOM's Patch format. patchtex_t* pTex = (patchtex_t*)Texture_UserData(tex); @@ -2445,7 +2447,7 @@ byte GL_LoadPatchLumpAsPatch(image_t* image, DFile* file, int tclass, int tmap, pTex->offY = -SHORT(hdr.topOffset); } } - return MIN_OF(1, result); + return source; } DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap, @@ -2475,7 +2477,7 @@ DGLuint GL_PrepareExtTexture(const char* name, gfxmode_t mode, int useMipmap, return texture; } -byte GL_LoadPatchComposite(image_t* image, Texture* tex) +TexSource GL_LoadPatchComposite(image_t* image, Texture* tex) { patchcompositetex_t* texDef; int i; @@ -2517,10 +2519,10 @@ byte GL_LoadPatchComposite(image_t* image, Texture* tex) if(palettedIsMasked(image->pixels, image->size.width, image->size.height)) image->flags |= IMGF_IS_MASKED; - return 1; + return TEXS_ORIGINAL; } -byte GL_LoadPatchCompositeAsSky(image_t* image, Texture* tex, boolean zeroMask) +TexSource GL_LoadPatchCompositeAsSky(image_t* image, Texture* tex, boolean zeroMask) { patchcompositetex_t* texDef; int i, width, height, offX, offY; @@ -2591,13 +2593,13 @@ byte GL_LoadPatchCompositeAsSky(image_t* image, Texture* tex, boolean zeroMask) if(zeroMask) image->flags |= IMGF_IS_MASKED; - return 1; + return TEXS_ORIGINAL; } -byte GL_LoadRawTex(image_t* image, const rawtex_t* r) +TexSource GL_LoadRawTex(image_t* image, const rawtex_t* r) { ddstring_t searchPath, foundPath; - byte result = 0; + TexSource source = TEXS_NONE; assert(image); @@ -2607,17 +2609,18 @@ byte GL_LoadRawTex(image_t* image, const rawtex_t* r) if(F_FindResourceStr2(RC_GRAPHIC, &searchPath, &foundPath) != 0 && GL_LoadImage(image, Str_Text(&foundPath))) - { // "External" image loaded. - result = 2; + { + // "External" image loaded. + source = TEXS_EXTERNAL; } else if(r->lumpNum >= 0) { DFile* file = F_OpenLump(r->lumpNum); if(file) { - if(0 != GL_LoadImageFromFile(image, file)) + if(GL_LoadImageFromFile(image, file)) { - result = 1; + source = TEXS_ORIGINAL; } else { // It must be an old-fashioned "raw" image. @@ -2637,7 +2640,7 @@ byte GL_LoadRawTex(image_t* image, const rawtex_t* r) image->size.width = RAW_WIDTH; image->size.height = (int) (fileLength / image->size.width); image->pixelSize = 1; - result = 1; + source = TEXS_ORIGINAL; #undef RAW_HEIGHT #undef RAW_WIDTH @@ -2649,7 +2652,7 @@ byte GL_LoadRawTex(image_t* image, const rawtex_t* r) Str_Free(&searchPath); Str_Free(&foundPath); - return result; + return source; } DGLuint GL_PrepareRawTexture(rawtex_t* raw) @@ -2660,13 +2663,13 @@ DGLuint GL_PrepareRawTexture(rawtex_t* raw) if(!raw->tex) { image_t image; - byte result; // Clear any old values. memset(&image, 0, sizeof(image)); - if(2 == (result = GL_LoadRawTex(&image, raw))) - { // Loaded an external raw texture. + if(GL_LoadRawTex(&image, raw) == TEXS_EXTERNAL) + { + // Loaded an external raw texture. raw->tex = GL_NewTextureWithParams2(image.pixelSize == 4? DGL_RGBA : DGL_RGB, image.size.width, image.size.height, image.pixels, 0, 0, GL_NEAREST, (filterUI ? GL_LINEAR : GL_NEAREST), 0 /*no anisotropy*/, @@ -3133,12 +3136,11 @@ static void performImageAnalyses(Texture* tex, const image_t* image, } } -static TextureVariant* tryLoadImageAndPrepareVariant(Texture* tex, - texturevariantspecification_t* spec, TextureVariant* variant, - byte* result) +static boolean tryLoadImageAndPrepareVariant(Texture* tex, + texturevariantspecification_t* spec, TextureVariant** variant) { uploadcontentmethod_t uploadMethod; - byte loadResult = 0; + TexSource source; image_t image; assert(initedOk && spec); @@ -3155,36 +3157,34 @@ static TextureVariant* tryLoadImageAndPrepareVariant(Texture* tex, Str_Init(&searchPath); Str_Appendf(&searchPath, TEXTURES_RESOURCE_NAMESPACE_NAME":%s;", Str_Text(&texDef->name)); - loadResult = GL_LoadExtTextureEX(&image, Str_Text(&searchPath), Str_Text(&suffix), true); + source = GL_LoadExtTextureEX(&image, Str_Text(&searchPath), Str_Text(&suffix), true); Str_Free(&searchPath); } - if(0 == loadResult) + if(source == TEXS_NONE) { if(TC_SKYSPHERE_DIFFUSE != TS_GENERAL(spec)->context) { - loadResult = GL_LoadPatchComposite(&image, tex); + source = GL_LoadPatchComposite(&image, tex); } else { - loadResult = GL_LoadPatchCompositeAsSky(&image, tex, - (TS_GENERAL(spec)->flags & TSF_ZEROMASK) != 0); + const boolean zeroMask = !!(TS_GENERAL(spec)->flags & TSF_ZEROMASK); + source = GL_LoadPatchCompositeAsSky(&image, tex, zeroMask); } } } else { - loadResult = loadSourceImage(tex, spec, &image); + source = loadSourceImage(tex, spec, &image); } - if(result) *result = loadResult; - - if(0 == loadResult) + if(source == TEXS_NONE) { // No image found/failed to load. //Con_Message("Warning:Textures::tryLoadImageAndPrepareVariant: No image found for " - // "\"%s\"\n", Texture_Name(tex)); - return NULL; + // "\"%s\"\n", Texture_Name(tex)); + return false; } // Are we setting the logical dimensions to the actual pixel dimensions? @@ -3204,25 +3204,26 @@ static TextureVariant* tryLoadImageAndPrepareVariant(Texture* tex, performImageAnalyses(tex, &image, spec, true /*Always update*/); // Do we need to allocate a variant? - if(!variant) + if(!*variant) { DGLuint newGLName = GL_GetReservedTextureName(); - variant = TextureVariant_New(tex, spec); - TextureVariant_SetGLName(variant, newGLName); - Texture_AddVariant(tex, variant); + *variant = TextureVariant_New(tex, source, spec); + TextureVariant_SetGLName(*variant, newGLName); + Texture_AddVariant(tex, *variant); } // Are we re-preparing a released texture? - else if(0 == TextureVariant_GLName(variant)) + else if(0 == TextureVariant_GLName(*variant)) { DGLuint newGLName = GL_GetReservedTextureName(); - TextureVariant_SetGLName(variant, newGLName); + TextureVariant_SetSource(*variant, source); + TextureVariant_SetGLName(*variant, newGLName); } // (Re)Prepare the variant according to specification. switch(spec->type) { - case TST_GENERAL: uploadMethod = prepareVariant(variant, &image); break; - case TST_DETAIL: uploadMethod = prepareDetailVariant(variant, &image); break; + case TST_GENERAL: uploadMethod = prepareVariant(*variant, &image); break; + case TST_DETAIL: uploadMethod = prepareDetailVariant(*variant, &image); break; default: Con_Error("tryLoadImageAndPrepareVariant: Invalid spec type %i.", spec->type); exit(1); // Unreachable. @@ -3236,7 +3237,7 @@ static TextureVariant* tryLoadImageAndPrepareVariant(Texture* tex, Uri* uri = Textures_ComposeUri(Textures_Id(tex)); ddstring_t* path = Uri_ToString(uri); Con_Printf("Prepared TextureVariant (name:\"%s\" glName:%u)%s\n", - Str_Text(path), (unsigned int) TextureVariant_GLName(variant), + Str_Text(path), (unsigned int) TextureVariant_GLName(*variant), (METHOD_IMMEDIATE == uploadMethod)? " while not busy!" : ""); Str_Delete(path); Uri_Delete(uri); @@ -3249,7 +3250,7 @@ static TextureVariant* tryLoadImageAndPrepareVariant(Texture* tex, ) #endif - return variant; + return true; } static TextureVariant* findVariantForSpec(Texture* tex, @@ -3274,27 +3275,37 @@ static TextureVariant* findVariantForSpec(Texture* tex, } const TextureVariant* GL_PrepareTextureVariant2(Texture* tex, texturevariantspecification_t* spec, - preparetextureresult_t* returnOutcome) + preparetextureresult_t* outcome) { // Have we already prepared something suitable? TextureVariant* variant = findVariantForSpec(tex, spec); if(variant && TextureVariant_IsPrepared(variant)) { - if(returnOutcome) *returnOutcome = PTR_FOUND; + if(outcome) *outcome = PTR_FOUND; } else - { // Suffer the cache miss and attempt to (re)prepare a variant. - byte loadResult; - - variant = tryLoadImageAndPrepareVariant(tex, spec, variant, &loadResult); + { + // Suffer the cache miss and attempt to (re)prepare a variant. + boolean loadedOk = tryLoadImageAndPrepareVariant(tex, spec, &variant); - if(returnOutcome) - switch(loadResult) + if(outcome) { - case 1: *returnOutcome = PTR_UPLOADED_ORIGINAL; break; - case 2: *returnOutcome = PTR_UPLOADED_EXTERNAL; break; - default: *returnOutcome = PTR_NOTFOUND; break; + if(loadedOk) + { + switch(TextureVariant_Source(variant)) + { + case TEXS_ORIGINAL: *outcome = PTR_UPLOADED_ORIGINAL; break; + case TEXS_EXTERNAL: *outcome = PTR_UPLOADED_EXTERNAL; break; + default: + Con_Error("GL_PrepareTextureVariant2: Unknown TexSource %i.", (int)TextureVariant_Source(variant)); + exit(1); // Unreachable. + } + } + else + { + *outcome = PTR_NOTFOUND; + } } } diff --git a/doomsday/engine/portable/src/texturevariant.c b/doomsday/engine/portable/src/texturevariant.c index 58c1ff324f..ba8d7e598d 100644 --- a/doomsday/engine/portable/src/texturevariant.c +++ b/doomsday/engine/portable/src/texturevariant.c @@ -32,6 +32,9 @@ struct texturevariant_s { /// Superior Texture of which this is a derivative. struct texture_s* generalCase; + /// Source of this texture. + TexSource source; + /// @see textureVariantFlags int flags; @@ -45,7 +48,7 @@ struct texturevariant_s { texturevariantspecification_t* spec; }; -TextureVariant* TextureVariant_New(Texture* generalCase, +TextureVariant* TextureVariant_New(Texture* generalCase, TexSource source, texturevariantspecification_t* spec) { TextureVariant* tex; @@ -61,6 +64,7 @@ TextureVariant* TextureVariant_New(Texture* generalCase, (unsigned long) sizeof(*tex)); tex->generalCase = generalCase; + tex->source = source; tex->spec = spec; tex->flags = 0; tex->s = tex->t = 0; @@ -80,6 +84,18 @@ struct texture_s* TextureVariant_GeneralCase(const TextureVariant* tex) return tex->generalCase; } +TexSource TextureVariant_Source(const TextureVariant* tex) +{ + assert(tex); + return tex->source; +} + +void TextureVariant_SetSource(TextureVariant* tex, TexSource source) +{ + assert(tex); + tex->source = source; +} + boolean TextureVariant_IsMasked(const TextureVariant* tex) { assert(tex);