diff --git a/doomsday/build/codeblocks/doomsday.cbp b/doomsday/build/codeblocks/doomsday.cbp index d0084229f4..228bc9f7e5 100644 --- a/doomsday/build/codeblocks/doomsday.cbp +++ b/doomsday/build/codeblocks/doomsday.cbp @@ -366,6 +366,7 @@ + diff --git a/doomsday/build/win32/vs8/doomsday.vcproj b/doomsday/build/win32/vs8/doomsday.vcproj index 67f5096b5f..ad4bb0c959 100644 --- a/doomsday/build/win32/vs8/doomsday.vcproj +++ b/doomsday/build/win32/vs8/doomsday.vcproj @@ -3265,6 +3265,10 @@ RelativePath="..\..\..\engine\portable\include\texturevariant.h" > + + diff --git a/doomsday/engine/portable/include/gl_texmanager.h b/doomsday/engine/portable/include/gl_texmanager.h index 9a207666b9..14ecba62ca 100644 --- a/doomsday/engine/portable/include/gl_texmanager.h +++ b/doomsday/engine/portable/include/gl_texmanager.h @@ -33,6 +33,7 @@ #include "r_model.h" #include "gl_model.h" #include "gl_defer.h" +#include "texturevariantspecification.h" #define TEXQ_BEST 8 #define MINTEXWIDTH 8 @@ -42,7 +43,7 @@ struct image_s; struct texturecontent_s; struct texture_s; struct texturevariant_s; -struct texturevariantspecification_s; +texturevariantspecification_t; extern int ratioLimit; extern int mipmapping, filterUI, texQuality, filterSprites; @@ -242,7 +243,7 @@ boolean GL_OptimalTextureSize(int width, int height, boolean noStretch, * * @param spec Specification to echo. */ -void GL_PrintTextureVariantSpecification(const struct texturevariantspecification_s* spec); +void GL_PrintTextureVariantSpecification(const texturevariantspecification_t* spec); /** * Prepare a TextureVariantSpecification according to usage context. @@ -252,29 +253,29 @@ void GL_PrintTextureVariantSpecification(const struct texturevariantspecificatio * @return Ptr to a rationalized and valid TextureVariantSpecification * or @c NULL if out of memory. */ -struct texturevariantspecification_s* GL_TextureVariantSpecificationForContext( - const struct texture_s* tex, void* context); +texturevariantspecification_t* GL_TextureVariantSpecificationForContext( + texturespecificationtype_t type, textureusagecontext_t tc, void* context); struct texturevariant_s* GL_FindSuitableTextureVariant(struct texture_s* tex, - const struct texturevariantspecification_s* spec); + const texturevariantspecification_t* spec); void GL_ReleaseGLTexturesForTexture(struct texture_s* tex); struct texture_s* GL_ToTexture(textureid_t id); /** - * Attempt to prepare (upload to GL) an instance of Texture which fulfills - * the variant specification defined by the usage context. + * Attempt to prepare a variant of Texture which fulfills the specification + * defined by the usage context. * - * @param context Usage-specific context data (if any). + * @param spec Variant specification for the proposed usage context. * @param result Result of this process: * @c 0== Failed: No suitable variant could be found/prepared. * @c 1== Success: Suitable variant prepared from an original resource. * @c 2== Success: Suitable variant prepared from a replacement resource. * @return Prepared variant if successful else @c NULL. */ -const struct texturevariant_s* GL_PrepareTexture(textureid_t id, void* context, - byte* result); +const struct texturevariant_s* GL_PrepareTexture(textureid_t id, + texturevariantspecification_t* spec, byte* result); const struct texture_s* GL_CreateTexture(const char* name, uint index, texturenamespaceid_t texNamespace); diff --git a/doomsday/engine/portable/include/p_material.h b/doomsday/engine/portable/include/p_material.h index 43f355efa4..ad8e063950 100644 --- a/doomsday/engine/portable/include/p_material.h +++ b/doomsday/engine/portable/include/p_material.h @@ -28,16 +28,6 @@ struct texturevariant_s; -typedef struct material_load_params_s { - boolean prepareForSkySphere; - int tmap, tclass; - boolean pSprite; - struct { - byte flags; /// @see textureFlags - byte border; - } tex; -} material_load_params_t; - // Material texture unit idents: enum { MTU_PRIMARY, diff --git a/doomsday/engine/portable/include/p_materialmanager.h b/doomsday/engine/portable/include/p_materialmanager.h index 11de08e3d0..375e66170d 100644 --- a/doomsday/engine/portable/include/p_materialmanager.h +++ b/doomsday/engine/portable/include/p_materialmanager.h @@ -28,6 +28,7 @@ #include "gl_texmanager.h" #include "def_data.h" #include "p_material.h" +#include "texturevariantspecification.h" void P_MaterialsRegister(void); @@ -88,7 +89,8 @@ const ded_reflection_t* Materials_Reflection(materialnum_t num); const ded_decor_t* Materials_Decoration(materialnum_t num); const ded_ptcgen_t* Materials_PtcGen(materialnum_t num); -byte Materials_Prepare(struct material_snapshot_s* snapshot, material_t* mat, boolean smoothed, struct material_load_params_s* params); +byte Materials_Prepare(struct material_snapshot_s* snapshot, material_t* mat, + boolean smoothed, texturevariantspecification_t* texSpec); int Materials_AnimGroupCount(void); void Materials_ResetAnimGroups(void); diff --git a/doomsday/engine/portable/include/rend_main.h b/doomsday/engine/portable/include/rend_main.h index 05cbd0f097..c44e3161cf 100644 --- a/doomsday/engine/portable/include/rend_main.h +++ b/doomsday/engine/portable/include/rend_main.h @@ -44,6 +44,7 @@ extern float rendLightDistanceAttentuation; extern float lightModRange[255]; extern int devRendSkyMode; extern float glowingTextures; +extern int useShinySurfaces; void Rend_Register(void); void Rend_Init(void); diff --git a/doomsday/engine/portable/include/texturevariant.h b/doomsday/engine/portable/include/texturevariant.h index 4723e09331..ed29aed057 100644 --- a/doomsday/engine/portable/include/texturevariant.h +++ b/doomsday/engine/portable/include/texturevariant.h @@ -25,62 +25,15 @@ #ifndef LIBDENG_GL_TEXTUREVARIANT_H #define LIBDENG_GL_TEXTUREVARIANT_H -struct texture_s; - -/** - * @defGroup textureFlags Texture Flags - */ -/*@{*/ -#define TF_ZEROMASK 0x1 // Zero the alpha of loaded textures. -#define TF_NO_COMPRESSION 0x2 // Do not compress the loaded textures. -#define TF_UPSCALE_AND_SHARPEN 0x4 -#define TF_MONOCHROME 0x8 -/*@}*/ +#include "texturevariantspecification.h" -typedef enum { - TEXTURESPECIFICATIONTYPE_FIRST = 0, - TS_SYSTEM = TEXTURESPECIFICATIONTYPE_FIRST, - TS_FLAT, - TS_PATCHCOMPOSITE, - TS_PATCHSPRITE, - TS_PATCH, - TS_DETAIL, - TS_REFLECTION, - TS_MASK, - TS_MODELSKIN, - TS_MODELREFLECTIONSKIN, - TS_LIGHTMAP, - TS_FLAREMAP, - TEXTURESPECIFICATIONTYPE_LAST = TS_FLAREMAP -} texturespecificationtype_t; - -#define TEXTURESPECIFICATIONTYPE_COUNT (\ - TEXTURESPECIFICATIONTYPE_LAST + 1 - TEXTURESPECIFICATIONTYPE_FIRST ) - -#define VALID_TEXTURESPECIFICATIONTYPE(t) (\ - (t) >= TEXTURESPECIFICATIONTYPE_FIRST && (t) <= TEXTURESPECIFICATIONTYPE_LAST) - -typedef struct texturevariantspecification_s { - texturespecificationtype_t type; - byte flags; /// @see textureFlags - byte border; /// In pixels, added to all four edges of the texture. - boolean prepareForSkySphere; - union { - struct { - boolean pSprite; // @c true, iff this is for use as a psprite. - int tclass, tmap; // Color translation. - } sprite; - struct { - float contrast; - } detail; - } data; // type-specific data. -} texturevariantspecification_t; +struct texture_s; typedef enum { TEXTUREVARIANT_ANALYSIS_FIRST = 0, TA_SPRITE_AUTOLIGHT = TEXTUREVARIANT_ANALYSIS_FIRST, - TA_WORLD_AMBIENTLIGHT, - TA_SKY_TOPCOLOR, + TA_MAP_AMBIENTLIGHT, + TA_SKY_SPHEREFADECOLOR, TEXTUREVARIANT_ANALYSIS_COUNT } texturevariant_analysisid_t; diff --git a/doomsday/engine/portable/include/texturevariantspecification.h b/doomsday/engine/portable/include/texturevariantspecification.h new file mode 100644 index 0000000000..c3a1b8f1b1 --- /dev/null +++ b/doomsday/engine/portable/include/texturevariantspecification.h @@ -0,0 +1,99 @@ +/**\file image.h + *\section License + * License: GPL + * Online License Link: http://www.gnu.org/licenses/gpl.html + * + *\author Copyright © 2003-2011 Jaakko Keränen + *\author Copyright © 2005-2011 Daniel Swanson + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef LIBDENG_GL_TEXTUREVARIANTSPECIFICATION_H +#define LIBDENG_GL_TEXTUREVARIANTSPECIFICATION_H + +typedef struct material_load_params_s { + int tmap, tclass; + struct { + byte flags; /// @see textureFlags + byte border; + } tex; +} material_load_params_t; + +typedef enum { + TC_UNKNOWN = -1, + TEXTUREUSAGECONTEXT_FIRST = 0, + TC_UI = TEXTUREUSAGECONTEXT_FIRST, + TC_MAPSURFACE_DIFFUSE, + TC_MAPSURFACE_REFLECTION, + TC_MAPSURFACE_REFLECTIONMASK, + TC_MAPSURFACE_LIGHTMAP, + TC_MAPSURFACE_DETAIL, + TC_SPRITE_DIFFUSE, + TC_MODELSKIN_DIFFUSE, + TC_MODELSKIN_REFLECTION, + TC_HALO_LUMINANCE, + TC_PSPRITE_DIFFUSE, + TC_SKYSPHERE_DIFFUSE, + TEXTUREUSAGECONTEXT_LAST = TC_SKYSPHERE_DIFFUSE +} textureusagecontext_t; + +#define TEXTUREUSAGECONTEXT_COUNT (\ + TEXTUREUSAGECONTEXT_LAST + 1 - TEXTUREUSAGECONTEXT_FIRST ) + +#define VALID_TEXTUREUSAGECONTEXT(tc) (\ + (tc) >= TEXTUREUSAGECONTEXT_FIRST && (tc) <= TEXTUREUSAGECONTEXT_LAST) + +/** + * @defGroup textureFlags Texture Flags + */ +/*@{*/ +#define TF_ZEROMASK 0x1 // Zero the alpha of loaded textures. +#define TF_NO_COMPRESSION 0x2 // Do not compress the loaded textures. +#define TF_UPSCALE_AND_SHARPEN 0x4 +#define TF_MONOCHROME 0x8 +/*@}*/ + +typedef enum { + TEXTURESPECIFICATIONTYPE_FIRST = 0, + TS_DEFAULT = TEXTURESPECIFICATIONTYPE_FIRST, + TS_TRANSLATED, + TS_DETAIL, + TEXTURESPECIFICATIONTYPE_LAST = TS_DETAIL +} texturespecificationtype_t; + +#define TEXTURESPECIFICATIONTYPE_COUNT (\ + TEXTURESPECIFICATIONTYPE_LAST + 1 - TEXTURESPECIFICATIONTYPE_FIRST ) + +#define VALID_TEXTURESPECIFICATIONTYPE(t) (\ + (t) >= TEXTURESPECIFICATIONTYPE_FIRST && (t) <= TEXTURESPECIFICATIONTYPE_LAST) + +typedef struct texturevariantspecification_s { + textureusagecontext_t context; + texturespecificationtype_t type; + byte flags; /// @see textureFlags + byte border; /// In pixels, added to all four edges of the texture. + union { + struct { + int tclass, tmap; // Color translation. + } translated; + struct { + float contrast; + } detail; + } data; // type-specific data. +} texturevariantspecification_t; + +#endif /* LIBDENG_GL_TEXTUREVARIANTSPECIFICATION_H */ diff --git a/doomsday/engine/portable/src/def_read.c b/doomsday/engine/portable/src/def_read.c index f617d54776..236cd93bb2 100644 --- a/doomsday/engine/portable/src/def_read.c +++ b/doomsday/engine/portable/src/def_read.c @@ -1779,8 +1779,8 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* sourceFile) RV_FLT("Shininess", ref->shininess) RV_VEC("Min color", ref->minColor, 3) RV_BLENDMODE("Blending mode", ref->blendMode) - RV_URI("Shiny map", &ref->shinyMap, 0) - RV_URI("Mask map", &ref->maskMap, 0) + RV_URI("Shiny map", &ref->shinyMap, LIGHTMAPS_RESOURCE_NAMESPACE_NAME) + RV_URI("Mask map", &ref->maskMap, LIGHTMAPS_RESOURCE_NAMESPACE_NAME) RV_FLT("Mask width", ref->maskWidth) RV_FLT("Mask height", ref->maskHeight) if(ISLABEL("Material")) diff --git a/doomsday/engine/portable/src/filedirectory.c b/doomsday/engine/portable/src/filedirectory.c index 2ffa152562..db36bf91d7 100644 --- a/doomsday/engine/portable/src/filedirectory.c +++ b/doomsday/engine/portable/src/filedirectory.c @@ -604,8 +604,8 @@ boolean FileDirectoryNode_MatchDirectory(const filedirectory_node_t* node, while((pos = strrchr(dir, delimiter)) != 0) { // Does this match? - if(Str_Length(&node->path) < Str_Length(searchPath) || - strnicmp(Str_Text(&node->path), Str_Text(searchPath), + if(Str_Length(&node->path) < (strlen(pos)-1) || + strnicmp(Str_Text(&node->path), pos + 1, Str_Length(&node->path) - (node->type == FDT_DIRECTORY? 1:0))) return false; @@ -620,8 +620,8 @@ boolean FileDirectoryNode_MatchDirectory(const filedirectory_node_t* node, }} // Anything remaining is the root directory or file; but does it match? - if(Str_Length(&node->path) < Str_Length(searchPath) || - strnicmp(Str_Text(&node->path), Str_Text(searchPath), + if(Str_Length(&node->path) < strlen(dir) || + strnicmp(Str_Text(&node->path), dir, Str_Length(&node->path) - (node->type == FDT_DIRECTORY? 1:0))) return false; diff --git a/doomsday/engine/portable/src/gl_main.c b/doomsday/engine/portable/src/gl_main.c index 9ff3dc2d9b..d311733bad 100644 --- a/doomsday/engine/portable/src/gl_main.c +++ b/doomsday/engine/portable/src/gl_main.c @@ -1035,7 +1035,7 @@ void GL_SetMaterial(material_t* mat) return; // \fixme we need a "NULL material". Con_Error("GL_SetMaterial: No usage context specified."); - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); } @@ -1045,10 +1045,9 @@ void GL_SetPSprite(material_t* mat) material_snapshot_t ms; memset(¶ms, 0, sizeof(params)); - params.pSprite = true; params.tex.border = 1; - Materials_Prepare(&ms, mat, true, ¶ms); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_PSPRITE_DIFFUSE, ¶ms)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -1065,7 +1064,7 @@ void GL_SetTranslatedSprite(material_t* mat, int tclass, int tmap) params.tclass = tclass; params.tex.border = 1; - Materials_Prepare(&ms, mat, true, ¶ms); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_TRANSLATED, TC_SPRITE_DIFFUSE, ¶ms)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); } diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c index 607da9bda4..41f3207610 100644 --- a/doomsday/engine/portable/src/gl_texmanager.c +++ b/doomsday/engine/portable/src/gl_texmanager.c @@ -184,25 +184,20 @@ static int compareVariantSpecifications(const texturevariantspecification_t* a, { if(a->type != b->type) return 1; - - if(a->type != TS_DETAIL) - { - if(a->prepareForSkySphere != b->prepareForSkySphere) - return 1; - if(a->flags != b->flags) - return 1; - if(a->border != b->border) - return 1; - } + /// \todo We can be a bit cleverer here... + if(a->context != b->context) + return 1; + if(a->flags != b->flags) + return 1; + if(a->border != b->border) + return 1; switch(a->type) { - case TS_PATCHSPRITE: - if(a->data.sprite.pSprite != b->data.sprite.pSprite) - return 1; - if(a->data.sprite.tclass != b->data.sprite.tclass) + case TS_TRANSLATED: + if(a->data.translated.tclass != b->data.translated.tclass) return 1; - if(a->data.sprite.tmap != b->data.sprite.tmap) + if(a->data.translated.tmap != b->data.translated.tmap) return 1; break; case TS_DETAIL: @@ -216,11 +211,13 @@ static int compareVariantSpecifications(const texturevariantspecification_t* a, static texturevariantspecification_t* applyVariantSpecification( texturevariantspecification_t* spec, texturespecificationtype_t type, - const void* context) + textureusagecontext_t tc, const void* context) { - assert(spec && VALID_TEXTURESPECIFICATIONTYPE(type)); + assert(spec && (tc == TC_UNKNOWN || VALID_TEXTUREUSAGECONTEXT(tc)) && + VALID_TEXTURESPECIFICATIONTYPE(type)); memset(spec, 0, sizeof(texturevariantspecification_t)); spec->type = type; + spec->context = tc; if(spec->type == TS_DETAIL) { float contrast = context? *((float*) context) : 1; @@ -233,45 +230,20 @@ static texturevariantspecification_t* applyVariantSpecification( { const material_load_params_t* params = (const material_load_params_t*) context; spec->flags = params->tex.flags; - spec->prepareForSkySphere = params->prepareForSkySphere; spec->border = params->tex.border; - if(spec->type == TS_PATCHSPRITE) + if(spec->type == TS_TRANSLATED) { - spec->data.sprite.tmap = params->tmap; - spec->data.sprite.tclass = params->tclass; - spec->data.sprite.pSprite = params->pSprite; + spec->data.translated.tmap = params->tmap; + spec->data.translated.tclass = params->tclass; } } return spec; } static void initVariantSpecificationForContext(texturevariantspecification_t* spec, - texturenamespaceid_t texNamespace, void* context) + texturespecificationtype_t type, textureusagecontext_t tc, void* context) { - assert(spec && VALID_TEXTURENAMESPACE(texNamespace)); - { - texturespecificationtype_t type; - switch(texNamespace) - { - case TN_SYSTEM: type = TS_SYSTEM; - case TN_FLATS: type = TS_FLAT; break; - case TN_TEXTURES: type = TS_PATCHCOMPOSITE; break; - case TN_SPRITES: type = TS_PATCHSPRITE; break; - case TN_PATCHES: type = TS_PATCH; break; - case TN_DETAILS: type = TS_DETAIL; break; - case TN_REFLECTIONS: type = TS_REFLECTION; break; - case TN_MASKS: type = TS_MASK; break; - case TN_MODELSKINS: type = TS_MODELSKIN; break; - case TN_MODELREFLECTIONSKINS: type = TS_MODELREFLECTIONSKIN; break; - case TN_LIGHTMAPS: type = TS_LIGHTMAP; break; - case TN_FLAREMAPS: type = TS_FLAREMAP; break; - default: - Con_Error("Textures::initVariantSpecificationForContext: Unknown namespace: %i", - (int) texNamespace); - return; // Unreachable. - } - applyVariantSpecification(spec, type, context); - } + applyVariantSpecification(spec, type, tc, context); } static texturevariantspecification_t* linkVariantSpecification( @@ -291,7 +263,7 @@ static texturevariantspecification_t* linkVariantSpecification( } } -static texturevariantspecification_t* findVariantSpecification(texturenamespaceid_t texNamespace, +static texturevariantspecification_t* findVariantSpecification( const texturevariantspecification_t* tpl, boolean canCreate) { assert(texInited && tpl); @@ -462,9 +434,9 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) const texture_t* generalCase = TextureVariant_GeneralCase(tex); const texturevariantspecification_t* spec = TextureVariant_Spec(tex); byte loadResult = 0; - switch(spec->type) + switch(Texture_Namespace(generalCase)) { - case TS_FLAT: + case TN_FLATS: // Attempt to load an external replacement for this flat? if(!noHighResTex && (loadExtAlways || highResWithPWAD || Texture_IsFromIWAD(generalCase))) { @@ -480,7 +452,7 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) if(0 == loadResult) loadResult = GL_LoadFlatLump(img, generalCase); break; - case TS_PATCH: + case TN_PATCHES: // Attempt to load an external replacement for this patch? if(!noHighResTex && (loadExtAlways || highResWithPWAD || Texture_IsFromIWAD(generalCase))) { @@ -496,7 +468,14 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) if(0 == loadResult) loadResult = GL_LoadDoomPatchLump(img, generalCase, (spec->flags & TF_UPSCALE_AND_SHARPEN) != 0); break; - case TS_PATCHSPRITE: + case TN_SPRITES: { + int tclass = 0, tmap = 0; + if(TS_TRANSLATED == spec->type) + { + tclass = spec->data.translated.tclass; + tmap = spec->data.translated.tmap; + } + // Attempt to load an external replacement for this sprite? if(!noHighResPatches) { @@ -507,14 +486,14 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) // Prefer psprite or translated versions if available. Str_Init(&searchPath); - if(spec->data.sprite.pSprite) + if(TC_PSPRITE_DIFFUSE == spec->context) { Str_Appendf(&searchPath, PATCHES_RESOURCE_NAMESPACE_NAME":%s-hud;", sprTex->name); } - else if(spec->data.sprite.tclass || spec->data.sprite.tmap) - { // Translated. + else if(tclass || tmap) + { Str_Appendf(&searchPath, PATCHES_RESOURCE_NAMESPACE_NAME":%s-table%i%i;", - sprTex->name, spec->data.sprite.tclass, spec->data.sprite.tmap); + sprTex->name, tclass, tmap); } Str_Appendf(&searchPath, PATCHES_RESOURCE_NAMESPACE_NAME":%s", sprTex->name); @@ -523,10 +502,11 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) Str_Free(&searchPath); } if(0 == loadResult) - loadResult = GL_LoadSpriteLump(img, generalCase, spec->data.sprite.pSprite, - spec->data.sprite.tclass, spec->data.sprite.tmap, spec->border); + loadResult = GL_LoadSpriteLump(img, generalCase, TC_PSPRITE_DIFFUSE == spec->context, + tclass, tmap, spec->border); break; - case TS_DETAIL: { + } + case TN_DETAILS: { int idx = Texture_TypeIndex(generalCase); const detailtex_t* dTex; assert(idx >= 0 && idx < detailTexturesCount); @@ -543,21 +523,21 @@ static byte loadSourceImage(image_t* img, const texturevariant_t* tex) } break; } - case TS_SYSTEM: - case TS_REFLECTION: - case TS_MASK: - case TS_LIGHTMAP: - case TS_FLAREMAP: - case TS_MODELSKIN: - case TS_MODELREFLECTIONSKIN: { + case TN_SYSTEM: + case TN_REFLECTIONS: + case TN_MASKS: + case TN_LIGHTMAPS: + case TN_FLAREMAPS: + case TN_MODELSKINS: + case TN_MODELREFLECTIONSKINS: { ddstring_t* path = Uri_ComposePath(searchPath(Texture_Namespace(generalCase), Texture_TypeIndex(generalCase))); loadResult = GL_LoadExtTextureEX(img, Str_Text(path), NULL, false); Str_Delete(path); break; } default: - Con_Error("Textures::loadSourceImage: Unknown texture specification type %i.", - (int) spec->type); + Con_Error("Textures::loadSourceImage: Unknown texture namespace %i.", + (int) Texture_Namespace(generalCase)); return 0; // Unreachable. } return loadResult; @@ -574,7 +554,7 @@ static byte prepareTextureVariant(texturevariant_t* tex) boolean noCompression = (specType != TS_DETAIL? (spec->flags & TF_NO_COMPRESSION) != 0 : false); boolean scaleSharp = (specType != TS_DETAIL? (spec->flags & TF_UPSCALE_AND_SHARPEN) != 0 : false); int magFilter, minFilter, anisoFilter, wrapS, wrapT, grayMipmap = 0, flags = 0; - boolean noSmartFilter = false, didDefer = false; + boolean noSmartFilter = false, didDefer = false, loadedPaletted = false; dgltexformat_t dglFormat; boolean alphaChannel; byte loadResult = 0; @@ -583,10 +563,10 @@ static byte prepareTextureVariant(texturevariant_t* tex) float s, t; // Load in the raw source image. - if(specType == TS_PATCHCOMPOSITE) + if(TN_TEXTURES == Texture_Namespace(TextureVariant_GeneralCase(tex))) { loadResult = GL_LoadDoomTexture(&image, TextureVariant_GeneralCase(tex), - spec->prepareForSkySphere, (spec->flags & TF_ZEROMASK) != 0); + spec->context == TC_SKYSPHERE_DIFFUSE, (spec->flags & TF_ZEROMASK) != 0); } else { @@ -600,9 +580,15 @@ static byte prepareTextureVariant(texturevariant_t* tex) return loadResult; } + { texturenamespaceid_t texNamespace = Texture_Namespace(TextureVariant_GeneralCase(tex)); + if(TN_FLATS == texNamespace || TN_TEXTURES == texNamespace || + TN_PATCHES == texNamespace || TN_SPRITES == texNamespace) + loadedPaletted = true; + } + if(image.pixelSize == 1) { - if(monochrome && !scaleSharp && (specType == TS_PATCH || specType == TS_PATCHSPRITE)) + if(monochrome && !scaleSharp) GL_DeSaturatePalettedImage(image.pixels, R_GetColorPalette(0), image.width, image.height); if(specType == TS_DETAIL) @@ -631,7 +617,7 @@ static byte prepareTextureVariant(texturevariant_t* tex) image.originalBits = 32; } - if(monochrome && (specType == TS_PATCH || specType == TS_PATCHSPRITE)) + if(monochrome) Desaturate(image.pixels, image.width, image.height, image.pixelSize); newPixels = GL_SmartFilter(scaleMethod, image.pixels, image.width, image.height, 0, &image.width, &image.height); @@ -646,7 +632,7 @@ static byte prepareTextureVariant(texturevariant_t* tex) //BlackOutlines(image.pixels, image.width, image.height, image.pixelSize); // Back to indexed+alpha? - if(monochrome && (specType == TS_PATCH || specType == TS_PATCHSPRITE)) + if(monochrome) { // No. We'll convert from RGB(+A) to Luminance(+A) and upload as is. // Replace the old buffer. GL_ConvertToLuminance(&image); @@ -671,9 +657,9 @@ static byte prepareTextureVariant(texturevariant_t* tex) if(fillOutlines /*&& !scaleSharp*/ && (image.flags & IMGF_IS_MASKED) && image.pixelSize == 1) ColorOutlinesIdx(image.pixels, image.width, image.height); } - else + else if(image.pixelSize > 2) { - if(monochrome && specType == TS_PATCH && image.pixelSize > 2) + if(monochrome) { GL_ConvertToLuminance(&image); AmplifyLuma(image.pixels, image.width, image.height, image.pixelSize == 2); @@ -705,7 +691,7 @@ static byte prepareTextureVariant(texturevariant_t* tex) } // Lightmaps and flare textures should always be monochrome images. - if((specType == TS_LIGHTMAP || (specType == TS_FLAREMAP && image.pixelSize != 4)) && + if((spec->context == TC_MAPSURFACE_LIGHTMAP || (spec->context == TC_HALO_LUMINANCE && image.pixelSize != 4)) && !(image.flags & IMGF_IS_MASKED)) { // An alpha channel is required. If one is not in the image data, we'll generate it. @@ -713,30 +699,23 @@ static byte prepareTextureVariant(texturevariant_t* tex) } // Disable compression? - if(noCompression || (image.width < 128 && image.height < 128) || specType == TS_FLAREMAP || specType == TS_REFLECTION) + if(noCompression || (image.width < 128 || image.height < 128) || + spec->context == TC_HALO_LUMINANCE || spec->context == TC_MAPSURFACE_REFLECTION) flags |= TXCF_NO_COMPRESSION; - if(!(specType == TS_MASK || specType == TS_REFLECTION || specType == TS_LIGHTMAP) && - (image.pixelSize > 2 || specType == TS_MODELSKIN)) + if(spec->context == TC_MODELSKIN_DIFFUSE) flags |= TXCF_APPLY_GAMMACORRECTION; - if(specType == TS_PATCHSPRITE /*|| specType == TS_PATCH*/) - flags |= TXCF_UPLOAD_ARG_NOSTRETCH; - - if(!monochrome && !(specType == TS_DETAIL || specType == TS_SYSTEM || specType == TS_REFLECTION || specType == TS_MASK)) - flags |= TXCF_EASY_UPLOAD; - - if(!monochrome) + if(image.pixelSize > 2) { - if(specType == TS_PATCHSPRITE || specType == TS_MODELSKIN || specType == TS_MODELREFLECTIONSKIN) - { - if(image.pixelSize > 1) - flags |= TXCF_UPLOAD_ARG_RGBDATA; - } - else if(image.pixelSize > 2 && !(specType == TS_REFLECTION || specType == TS_MASK || specType == TS_LIGHTMAP)) - flags |= TXCF_UPLOAD_ARG_RGBDATA; + if(spec->context == TC_MAPSURFACE_DIFFUSE || spec->context == TC_SPRITE_DIFFUSE || + spec->context == TC_PSPRITE_DIFFUSE || spec->context == TC_SKYSPHERE_DIFFUSE) + flags |= TXCF_APPLY_GAMMACORRECTION; } + if(spec->context == TC_SPRITE_DIFFUSE) + flags |= TXCF_UPLOAD_ARG_NOSTRETCH; + if(specType == TS_DETAIL) { /** @@ -747,17 +726,56 @@ static byte prepareTextureVariant(texturevariant_t* tex) grayMipmap = MINMAX_OF(0, spec->data.detail.contrast * 255, 255); flags |= TXCF_GRAY_MIPMAP; } - else if(!(specType == TS_REFLECTION || specType == TS_PATCH || - specType == TS_LIGHTMAP || specType == TS_FLAREMAP || - (specType == TS_PATCHSPRITE && spec->data.sprite.pSprite))) + + switch(spec->context) + { + case TC_MAPSURFACE_DIFFUSE: + //case TC_MAPSURFACE_REFLECTION: + case TC_MAPSURFACE_REFLECTIONMASK: + //case TC_MAPSURFACE_LIGHTMAP: + case TC_SPRITE_DIFFUSE: + case TC_MODELSKIN_DIFFUSE: + //case TC_MODELSKIN_REFLECTION: flags |= TXCF_MIPMAP; + break; + default: break; + } - if(specType == TS_PATCHCOMPOSITE || specType == TS_PATCH || - specType == TS_PATCHSPRITE || specType == TS_FLAT) - alphaChannel = ((/*loadResult == 2 &&*/ image.pixelSize == 4) || - (/*loadResult == 1 &&*/ image.pixelSize == 1 && (image.flags & IMGF_IS_MASKED))); - else - alphaChannel = image.pixelSize != 3 && !(specType == TS_MASK || specType == TS_REFLECTION); + alphaChannel = false; + if(TS_DETAIL != specType) + { + if(!monochrome) + { + texturenamespaceid_t texNamespace = Texture_Namespace(TextureVariant_GeneralCase(tex)); + if(!(TN_SYSTEM == texNamespace || TN_REFLECTIONS == texNamespace || TN_MASKS == texNamespace)) + //if(!(specType == TS_SYSTEM || specType == TS_REFLECTION || specType == TS_MASK)) + flags |= TXCF_EASY_UPLOAD; + } + + if(loadedPaletted) + { + if(!monochrome && image.pixelSize > 1) + flags |= TXCF_UPLOAD_ARG_RGBDATA; + + if((image.pixelSize == 1 && (image.flags & IMGF_IS_MASKED)) || + image.pixelSize == 4) + alphaChannel = true; + } + else + { + if(!monochrome && image.pixelSize > 2 && + !(TC_MAPSURFACE_REFLECTIONMASK == spec->context || + TC_MAPSURFACE_LIGHTMAP == spec->context)) + flags |= TXCF_UPLOAD_ARG_RGBDATA; + + if(!(TC_MAPSURFACE_REFLECTIONMASK == spec->context || + TC_MAPSURFACE_REFLECTION == spec->context)) + { + if(image.pixelSize == 2 || image.pixelSize == 4) + alphaChannel = true; + } + } + } if(alphaChannel) flags |= TXCF_UPLOAD_ARG_ALPHACHANNEL; @@ -769,48 +787,84 @@ static byte prepareTextureVariant(texturevariant_t* tex) { dglFormat = ( image.pixelSize == 2 ? DGL_LUMINANCE_PLUS_A8 : DGL_LUMINANCE ); } - else if(specType == TS_FLAT || specType == TS_PATCHCOMPOSITE || specType == TS_PATCH || specType == TS_PATCHSPRITE) - { - dglFormat = ( image.pixelSize > 1? - ( alphaChannel? DGL_RGBA : DGL_RGB) : - ( alphaChannel? DGL_COLOR_INDEX_8_PLUS_A8 : DGL_COLOR_INDEX_8 ) ); - } - else if(specType == TS_MODELSKIN || specType == TS_MODELREFLECTIONSKIN) - { - dglFormat = ( alphaChannel? DGL_RGBA : DGL_RGB ); - } else { - dglFormat = ( image.pixelSize == 2 ? DGL_LUMINANCE_PLUS_A8 : - image.pixelSize == 3 ? DGL_RGB : - image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ); + if(loadedPaletted) + { + if(image.pixelSize == 1) + dglFormat = alphaChannel? DGL_COLOR_INDEX_8_PLUS_A8 : DGL_COLOR_INDEX_8; + else + dglFormat = alphaChannel? DGL_RGBA : DGL_RGB; + } + else + { + dglFormat = ( image.pixelSize == 2 ? DGL_LUMINANCE_PLUS_A8 : + image.pixelSize == 3 ? DGL_RGB : + image.pixelSize == 4 ? DGL_RGBA : DGL_LUMINANCE ); + } } - if(specType == TS_FLAT || specType == TS_PATCHCOMPOSITE || specType == TS_MASK) + switch(spec->context) + { + case TC_MAPSURFACE_DIFFUSE: + case TC_MAPSURFACE_REFLECTIONMASK: + case TC_MAPSURFACE_LIGHTMAP: + case TC_MAPSURFACE_DETAIL: magFilter = glmode[texMagMode]; - else if(specType == TS_PATCHSPRITE) + break; + case TC_SPRITE_DIFFUSE: + case TC_MODELSKIN_DIFFUSE: magFilter = filterSprites ? GL_LINEAR : GL_NEAREST; - else + break; + default: magFilter = GL_LINEAR; + break; + } - if(specType == TS_DETAIL) + switch(spec->context) + { + case TC_MAPSURFACE_DIFFUSE: + //case TC_MAPSURFACE_REFLECTION: + case TC_MAPSURFACE_REFLECTIONMASK: + //case TC_MAPSURFACE_LIGHTMAP: + minFilter = glmode[mipmapping]; + break; + case TC_MAPSURFACE_DETAIL: minFilter = GL_LINEAR_MIPMAP_LINEAR; - else if(specType == TS_PATCH || (specType == TS_PATCHSPRITE && spec->data.sprite.pSprite)) + break; + case TC_UI: minFilter = GL_NEAREST; - else if(specType == TS_LIGHTMAP || specType == TS_FLAREMAP || specType == TS_REFLECTION) + break; + default: minFilter = GL_LINEAR; - else - minFilter = glmode[mipmapping]; + break; + } - if(specType == TS_PATCH || specType == TS_FLAREMAP || (specType == TS_PATCHSPRITE && spec->data.sprite.pSprite)) + switch(spec->context) + { + case TC_UI: + case TC_PSPRITE_DIFFUSE: + case TC_HALO_LUMINANCE: anisoFilter = 0 /*no anisotropic filtering*/; - else - anisoFilter = texAniso; /// \fixme is "best" truely a suitable default for ALL texture types? + break; + default: + anisoFilter = texAniso; /// \fixme is "best" truely a suitable default? + break; + } - if(specType == TS_PATCH || specType == TS_PATCHSPRITE || specType == TS_LIGHTMAP || specType == TS_FLAREMAP) + switch(spec->context) + { + case TC_UI: + case TC_SPRITE_DIFFUSE: + case TC_PSPRITE_DIFFUSE: + case TC_HALO_LUMINANCE: + case TC_MAPSURFACE_LIGHTMAP: wrapS = wrapT = GL_CLAMP_TO_EDGE; - else + break; + default: wrapS = wrapT = GL_REPEAT; + break; + } glName = GL_NewTextureWithParams3(dglFormat, image.width, image.height, image.pixels, flags, grayMipmap, minFilter, magFilter, anisoFilter, wrapS, @@ -831,8 +885,8 @@ static byte prepareTextureVariant(texturevariant_t* tex) * coordinates are calculated as width/CeilPow2(width), or 1 if larger * than the maximum texture size. */ - if(specType == TS_PATCHSPRITE && GL_state.features.texNonPowTwo && - (spec->data.sprite.pSprite || !(flags & TXCF_UPLOAD_ARG_NOSTRETCH)) && + if((spec->context == TC_SPRITE_DIFFUSE || spec->context == TC_PSPRITE_DIFFUSE) && + GL_state.features.texNonPowTwo && !(flags & TXCF_UPLOAD_ARG_NOSTRETCH) && !(image.width < MINTEXWIDTH || image.height < MINTEXHEIGHT)) { s = t = 1; @@ -847,17 +901,17 @@ static byte prepareTextureVariant(texturevariant_t* tex) TextureVariant_SetCoords(tex, s, t); TextureVariant_SetMasked(tex, (image.flags & IMGF_IS_MASKED) != 0); - if(!(specType == TS_DETAIL || specType == TS_PATCHSPRITE) && - spec->prepareForSkySphere) + switch(spec->context) { + case TC_SKYSPHERE_DIFFUSE: { averagecolor_analysis_t* avgTopColor; - if(NULL == (avgTopColor = (averagecolor_analysis_t*)TextureVariant_Analysis(tex, TA_SKY_TOPCOLOR))) + if(NULL == (avgTopColor = (averagecolor_analysis_t*)TextureVariant_Analysis(tex, TA_SKY_SPHEREFADECOLOR))) { if(NULL == (avgTopColor = (averagecolor_analysis_t*) malloc(sizeof(*avgTopColor)))) Con_Error("Textures::prepareTextureVariant: Failed on allocation of %lu bytes for " "new AverageColorAnalysis.", (unsigned int) sizeof(*avgTopColor)); - TextureVariant_AddAnalysis(tex, TA_SKY_TOPCOLOR, avgTopColor); + TextureVariant_AddAnalysis(tex, TA_SKY_SPHEREFADECOLOR, avgTopColor); } // Average color for glow planes and top line color. @@ -869,10 +923,9 @@ static byte prepareTextureVariant(texturevariant_t* tex) { FindAverageLineColorIdx(image.pixels, image.width, image.height, 0, 0, false, avgTopColor->color); } - } - - if(specType == TS_PATCHSPRITE && !spec->data.sprite.pSprite) - { + break; + } + case TC_SPRITE_DIFFUSE: { pointlight_analysis_t* pl; if(NULL == (pl = (pointlight_analysis_t*)TextureVariant_Analysis(tex, TA_SPRITE_AUTOLIGHT))) @@ -885,18 +938,17 @@ static byte prepareTextureVariant(texturevariant_t* tex) // Calculate light source properties. GL_CalcLuminance(image.pixels, image.width, image.height, image.pixelSize, 0, &pl->originX, &pl->originY, pl->color, &pl->brightMul); - } - - if(specType == TS_FLAT || specType == TS_PATCHCOMPOSITE) - { + break; + } + case TC_MAPSURFACE_DIFFUSE: { ambientlight_analysis_t* al; - if(NULL == (al = (ambientlight_analysis_t*)TextureVariant_Analysis(tex, TA_WORLD_AMBIENTLIGHT))) + if(NULL == (al = (ambientlight_analysis_t*)TextureVariant_Analysis(tex, TA_MAP_AMBIENTLIGHT))) { if(NULL == (al = (ambientlight_analysis_t*) malloc(sizeof(*al)))) Con_Error("Textures::prepareTextureVariant: Failed on allocation of %lu bytes for " "new AmbientLightAnalysis.", (unsigned int) sizeof(*al)); - TextureVariant_AddAnalysis(tex, TA_WORLD_AMBIENTLIGHT, al); + TextureVariant_AddAnalysis(tex, TA_MAP_AMBIENTLIGHT, al); } if(image.pixelSize > 1) @@ -909,6 +961,9 @@ static byte prepareTextureVariant(texturevariant_t* tex) } memcpy(al->colorAmplified, al->color, sizeof(al->colorAmplified)); amplify(al->colorAmplified); + break; + } + default: break; } GL_DestroyImagePixels(&image); @@ -1044,20 +1099,37 @@ void GL_ResetTextureManager(void) GL_ClearTextureMemory(); } -void GL_PrintTextureVariantSpecification(const struct texturevariantspecification_s* spec) -{ +void GL_PrintTextureVariantSpecification(const texturevariantspecification_t* spec) +{ + static const char* textureUsageContextNames[TEXTUREUSAGECONTEXT_COUNT] = { + /* TC_UI */ { "ui" }, + /* TC_MAPSURFACE_DIFFUSE */ { "mapsurface_diffuse" }, + /* TC_MAPSURFACE_REFLECTION */ { "mapsurface_reflection" }, + /* TC_MAPSURFACE_REFLECTIONMASK */ { "mapsurface_reflectionmask" }, + /* TC_MAPSURFACE_LIGHTMAP */ { "mapsurface_lightmap" }, + /* TC_MAPSURFACE_DETAIL */ { "mapsurface_detail" }, + /* TC_SPRITE_DIFFUSE */ { "sprite_diffuse" }, + /* TC_MODELSKIN_DIFFUSE */ { "modelskin_diffuse" }, + /* TC_MODELSKIN_REFLECTION */ { "modelskin_reflection" }, + /* TC_HALO_LUMINANCE */ { "halo_luminance" }, + /* TC_PSPRITE_DIFFUSE */ { "psprite_diffuse" }, + /* TC_SKYSPHERE_DIFFUSE */ { "skysphere_diffuse" } + }; + if(NULL == spec) return; + + assert(VALID_TEXTUREUSAGECONTEXT(spec->context)); Con_Printf("type:%i context:%s flags:%i border:%i\n", (int) spec->type, - spec->prepareForSkySphere? "skysphere" : "unknown", spec->flags, + textureUsageContextNames[spec->context-TEXTUREUSAGECONTEXT_FIRST], spec->flags, spec->border); switch(spec->type) { case TS_DETAIL: - Con_Printf("glt_detail(contrast:%g)\n", spec->data.detail.contrast); + Con_Printf("ts_detail(contrast:%g)\n", spec->data.detail.contrast); break; - case TS_PATCHSPRITE: - Con_Printf("glt_sprite(tclass:%i tmap:%i isPSprite:%s)\n", spec->data.sprite.tclass, - spec->data.sprite.tmap, spec->data.sprite.pSprite? "true":"false"); + case TS_TRANSLATED: + Con_Printf("ts_translated(tclass:%i tmap:%i)\n", spec->data.translated.tclass, + spec->data.translated.tmap); break; default: break; @@ -1065,14 +1137,13 @@ void GL_PrintTextureVariantSpecification(const struct texturevariantspecificatio } texturevariantspecification_t* GL_TextureVariantSpecificationForContext( - const texture_t* tex, void* context) + texturespecificationtype_t type, textureusagecontext_t tc, void* context) { static texturevariantspecification_t tpl; - texturenamespaceid_t texNamespace = Texture_Namespace(tex); if(!texInited) Con_Error("GL_TextureVariantSpecificationForContext: Textures collection not yet initialized."); - initVariantSpecificationForContext(&tpl, texNamespace, context); - return findVariantSpecification(texNamespace, &tpl, true); + initVariantSpecificationForContext(&tpl, type, tc, context); + return findVariantSpecification(&tpl, true); } void GL_DestroyTextures(void) @@ -1372,6 +1443,9 @@ DGLuint GL_UploadTexture2(const texturecontent_t* content) uint8_t* buffer = NULL, *rgbaOriginal = NULL, *idxBuffer = NULL; boolean freeOriginal; boolean freeBuffer; + boolean oldCompression = GL_state.currentUseTexCompression; + + GL_SetTextureCompression((content->flags & TXCF_NO_COMPRESSION) == 0); // Number of color components in the destination image. comps = (alphaChannel ? 4 : 3); @@ -1506,6 +1580,8 @@ DGLuint GL_UploadTexture2(const texturecontent_t* content) if(freeBuffer) free(buffer); + GL_SetTextureCompression(oldCompression); + return content->name; } @@ -2271,7 +2347,7 @@ DGLuint GL_GetLightMapTexture(const dduri_t* uri) if(0 != (lmap = R_GetLightMap(uri))) { const texturevariant_t* tex; - if((tex = GL_PrepareTexture(lmap->id, 0, 0))) + if((tex = GL_PrepareTexture(lmap->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_LIGHTMAP, NULL), 0))) return TextureVariant_GLName(tex); } } @@ -2295,7 +2371,7 @@ DGLuint GL_GetFlareTexture(const dduri_t* uri, int oldIdx) if((fTex = R_GetFlareTexture(uri))) { const texturevariant_t* tex; - if((tex = GL_PrepareTexture(fTex->id, 0, 0))) + if((tex = GL_PrepareTexture(fTex->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_HALO_LUMINANCE, NULL), 0))) return TextureVariant_GLName(tex); } } @@ -2320,7 +2396,7 @@ DGLuint GL_PreparePatch(patchtex_t* patchTex) params.tex.flags |= TF_UPSCALE_AND_SHARPEN; params.tex.border = 1; } - if((tex = GL_PrepareTexture(patchTex->texId, ¶ms, NULL))) + if((tex = GL_PrepareTexture(patchTex->texId, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UI, ¶ms), NULL))) return TextureVariant_GLName(tex); } return 0; @@ -2601,11 +2677,10 @@ uint GL_TextureIndexForUri(const dduri_t* uri) return GL_TextureIndexForUri2(uri, false); } -const texturevariant_t* GL_PrepareTexture(textureid_t id, void* context, - byte* result) +const texturevariant_t* GL_PrepareTexture(textureid_t id, + texturevariantspecification_t* spec, byte* result) { texture_t* tex = getTexture(id); - texturevariantspecification_t* spec = GL_TextureVariantSpecificationForContext(tex, context); texturevariant_t* variant = NULL; boolean variantIsNew = false; byte loadResult; diff --git a/doomsday/engine/portable/src/p_materialmanager.c b/doomsday/engine/portable/src/p_materialmanager.c index eb3c03e98a..7a16f89c37 100644 --- a/doomsday/engine/portable/src/p_materialmanager.c +++ b/doomsday/engine/portable/src/p_materialmanager.c @@ -972,7 +972,7 @@ static __inline void setTexUnit(material_snapshot_t* ss, byte unit, } byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean smoothed, - material_load_params_t* params) + texturevariantspecification_t* texSpec) { materialnum_t num; if((num = Materials_ToMaterialNum(mat))) @@ -997,7 +997,7 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s byte result; // Pick the instance matching the specified context. - layerTextures[i] = GL_PrepareTexture(ml->tex, params, &result); + layerTextures[i] = GL_PrepareTexture(ml->tex, texSpec, &result); if(result) tmpResult = result; @@ -1030,12 +1030,12 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s float contrast = detail->strength * detailFactor; // Pick an instance matching the specified context. - detailTex = GL_PrepareTexture(dTex->id, &contrast, 0); + detailTex = GL_PrepareTexture(dTex->id, GL_TextureVariantSpecificationForContext(TS_DETAIL, TC_MAPSURFACE_DETAIL, &contrast), 0); } } // Do we need to prepare a shiny texture (and possibly a mask)? - if(reflection) + if(reflection && useShinySurfaces) { shinytex_t* sTex; masktex_t* mTex; @@ -1049,14 +1049,14 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s if((sTex = R_GetShinyTexture(reflection->shinyMap))) { // Pick an instance matching the specified context. - shinyTex = GL_PrepareTexture(sTex->id, 0, 0); + shinyTex = GL_PrepareTexture(sTex->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_REFLECTION, NULL), 0); } if(shinyTex && // Don't bother searching unless the above succeeds. (mTex = R_GetMaskTexture(reflection->maskMap))) { // Pick an instance matching the specified context. - shinyMaskTex = GL_PrepareTexture(mTex->id, 0, 0); + shinyMaskTex = GL_PrepareTexture(mTex->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_REFLECTIONMASK, NULL), 0); } } } @@ -1094,10 +1094,10 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s snapshot->isOpaque = !TextureVariant_IsMasked(layerTextures[0]); - if(params && (params->prepareForSkySphere)) + if(TC_SKYSPHERE_DIFFUSE == texSpec->context) { const averagecolor_analysis_t* avgTopColor = (const averagecolor_analysis_t*) - TextureVariant_Analysis(layerTextures[0], TA_SKY_TOPCOLOR); + TextureVariant_Analysis(layerTextures[0], TA_SKY_SPHEREFADECOLOR); assert(avgTopColor); snapshot->topColor[CR] = avgTopColor->color[CR]; snapshot->topColor[CG] = avgTopColor->color[CG]; @@ -1109,10 +1109,10 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s } /// \fixme what about the other texture types? - if(TN_TEXTURES == Texture_Namespace(tex) || TN_FLATS == Texture_Namespace(tex)) + if(TC_MAPSURFACE_DIFFUSE == texSpec->context) { const ambientlight_analysis_t* ambientLight = (const ambientlight_analysis_t*) - TextureVariant_Analysis(layerTextures[0], TA_WORLD_AMBIENTLIGHT); + TextureVariant_Analysis(layerTextures[0], TA_MAP_AMBIENTLIGHT); assert(ambientLight); snapshot->color[CR] = ambientLight->color[CR]; snapshot->color[CG] = ambientLight->color[CG]; @@ -1147,7 +1147,7 @@ byte Materials_Prepare(material_snapshot_t* snapshot, material_t* mat, boolean s if(detailScale > .001f) scale *= detailScale; - setTexUnit(snapshot, MTU_DETAIL, BM_NORMAL, GL_LINEAR, detailTex, 1.f / width * scale, 1.f / height * scale, 0, 0, 1); + setTexUnit(snapshot, MTU_DETAIL, BM_NORMAL, texMagMode?GL_LINEAR:GL_NEAREST, detailTex, 1.f / width * scale, 1.f / height * scale, 0, 0, 1); } // Setup the reflection (aka shiny) texturing pass(es)? @@ -1178,7 +1178,7 @@ const ded_reflection_t* Materials_Reflection(materialnum_t num) { const materialbind_t* mb = bindForMaterial(Materials_ToMaterial(num)); if(!mb->prepared) - Materials_Prepare(NULL, mb->mat, false, 0); + Materials_Prepare(NULL, mb->mat, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); return mb->reflection[mb->prepared? mb->prepared-1:0]; } return 0; @@ -1190,7 +1190,7 @@ const ded_detailtexture_t* Materials_Detail(materialnum_t num) { const materialbind_t* mb = bindForMaterial(Materials_ToMaterial(num)); if(!mb->prepared) - Materials_Prepare(NULL, mb->mat, false, 0); + Materials_Prepare(NULL, mb->mat, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); return mb->detail[mb->prepared? mb->prepared-1:0]; } return 0; @@ -1202,7 +1202,7 @@ const ded_decor_t* Materials_Decoration(materialnum_t num) { const materialbind_t* mb = bindForMaterial(Materials_ToMaterial(num)); if(!mb->prepared) - Materials_Prepare(NULL, mb->mat, false, 0); + Materials_Prepare(NULL, mb->mat, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); return mb->decoration[mb->prepared? mb->prepared-1:0]; } return 0; @@ -1214,7 +1214,7 @@ const ded_ptcgen_t* Materials_PtcGen(materialnum_t num) { const materialbind_t* mb = bindForMaterial(Materials_ToMaterial(num)); if(!mb->prepared) - Materials_Prepare(NULL, mb->mat, false, 0); + Materials_Prepare(NULL, mb->mat, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); return mb->ptcGen[mb->prepared? mb->prepared-1:0]; } return 0; diff --git a/doomsday/engine/portable/src/p_surface.c b/doomsday/engine/portable/src/p_surface.c index b14fe1e323..73c2f882f1 100644 --- a/doomsday/engine/portable/src/p_surface.c +++ b/doomsday/engine/portable/src/p_surface.c @@ -112,7 +112,7 @@ boolean Surface_SetMaterial(surface_t* suf, material_t* mat) { material_snapshot_t ms; const ded_decor_t* decor; - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); if(ms.glowing > 0) R_SurfaceListAdd(glowingSurfaceList, suf); decor = Materials_Decoration(Materials_ToMaterialNum(mat)); diff --git a/doomsday/engine/portable/src/r_data.c b/doomsday/engine/portable/src/r_data.c index 6eadbb78e6..212220c8b5 100644 --- a/doomsday/engine/portable/src/r_data.c +++ b/doomsday/engine/portable/src/r_data.c @@ -2029,7 +2029,7 @@ uint R_CreateSkinTex(const dduri_t* skin, boolean isShinySkin) return 0; // Have we already created one for this? - if((id = R_GetSkinNumForName(skin))) + if(0 != (id = R_GetSkinNumForName(skin))) return id; if(M_NumDigits(numSkinNames + 1) > 8) @@ -2323,7 +2323,7 @@ void R_PrecacheMobjNum(int num) static void addToSurfaceLists(surface_t* suf, material_t* mat) { material_snapshot_t ms; - Materials_Prepare(&ms, mat, true, 0); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); if(ms.glowing > 0) R_SurfaceListAdd(glowingSurfaceList, suf); if(ms.decorated) @@ -2411,7 +2411,7 @@ void R_PrecacheMap(void) material_t* mat = Materials_ToMaterial(i+1); if(mat->inFlags & MATIF_PRECACHE) { - Materials_Prepare(NULL, mat, true, 0); + Materials_Prepare(NULL, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UNKNOWN, NULL)); } } @@ -2459,8 +2459,8 @@ detailtex_t* R_CreateDetailTexture(const ded_detailtexture_t* def) char name[9]; // Have we already created one for this? - if((dTex = R_GetDetailTexture(def->detailTex, def->isExternal))) - return NULL; + if(NULL != (dTex = R_GetDetailTexture(def->detailTex, def->isExternal))) + return dTex; if(M_NumDigits(detailTexturesCount + 1) > 8) { @@ -2527,8 +2527,8 @@ lightmap_t* R_CreateLightMap(const dduri_t* path) return 0; // Not a lightmap // Have we already created one for this? - if((lmap = R_GetLightMap(path))) - return 0; + if(NULL != (lmap = R_GetLightMap(path))) + return lmap; if(M_NumDigits(lightmapTexturesCount + 1) > 8) { @@ -2606,8 +2606,8 @@ flaretex_t* R_CreateFlareTexture(const dduri_t* path) return 0; // Don't create a flaretex for this // Have we already created one for this? - if((fTex = R_GetFlareTexture(path))) - return 0; + if(NULL != (fTex = R_GetFlareTexture(path))) + return fTex; if(M_NumDigits(flareTexturesCount + 1) > 8) { @@ -2676,8 +2676,8 @@ shinytex_t* R_CreateShinyTexture(const dduri_t* uri) char name[9]; // Have we already created one for this? - if((sTex = R_GetShinyTexture(uri)) == 0) - return 0; + if(NULL != (sTex = R_GetShinyTexture(uri))) + return sTex; if(M_NumDigits(shinyTexturesCount + 1) > 8) { @@ -2747,8 +2747,8 @@ masktex_t* R_CreateMaskTexture(const dduri_t* uri, short width, short height) char name[9]; // Have we already created one for this? - if((mTex = R_GetMaskTexture(uri)) == 0) - return 0; + if(NULL != (mTex = R_GetMaskTexture(uri))) + return mTex; if(M_NumDigits(maskTexturesCount + 1) > 8) { diff --git a/doomsday/engine/portable/src/r_draw.c b/doomsday/engine/portable/src/r_draw.c index 1329188937..44a055a157 100644 --- a/doomsday/engine/portable/src/r_draw.c +++ b/doomsday/engine/portable/src/r_draw.c @@ -236,8 +236,10 @@ void R_DrawViewBorder(void) if(mat) { material_snapshot_t ms; - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UI, NULL)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), (filterUI ? GL_LINEAR : GL_NEAREST)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); GL_DrawCutRectTiled(0, 0, port->width, port->height, ms.width, ms.height, 0, 0, viewwindowx - border, viewwindowy - border, viewwidth + 2 * border, viewheight + 2 * border); diff --git a/doomsday/engine/portable/src/r_lgrid.c b/doomsday/engine/portable/src/r_lgrid.c index 58108b8b8c..88ede4e6ef 100644 --- a/doomsday/engine/portable/src/r_lgrid.c +++ b/doomsday/engine/portable/src/r_lgrid.c @@ -109,7 +109,7 @@ void LG_Register(void) { C_VAR_INT("rend-bias-grid", &lgEnabled, 0, 0, 1); - C_VAR_INT("rend-bias-grid-debug", &lgShowDebug, 0, 0, 1); + C_VAR_INT("rend-bias-grid-debug", &lgShowDebug, CVF_NO_ARCHIVE, 0, 1); C_VAR_FLOAT("rend-bias-grid-debug-size", &lgDebugSize, 0, .1f, 100); diff --git a/doomsday/engine/portable/src/r_lumobjs.c b/doomsday/engine/portable/src/r_lumobjs.c index 3688ffd613..abe38b7f99 100644 --- a/doomsday/engine/portable/src/r_lumobjs.c +++ b/doomsday/engine/portable/src/r_lumobjs.c @@ -407,7 +407,7 @@ if(!mat) #endif // Ensure we have up-to-date information about the material. - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); tex = ms.units[MTU_PRIMARY].tex; pl = (const pointlight_analysis_t*) TextureVariant_Analysis(tex, TA_SPRITE_AUTOLIGHT); if(NULL == pl) @@ -589,7 +589,7 @@ static __inline void setGlowLightProps(lumobj_t* l, surface_t* surface) assert(l && surface); { material_snapshot_t ms; - Materials_Prepare(&ms, surface->material, true, 0); + Materials_Prepare(&ms, surface->material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); V3_Copy(LUM_PLANE(l)->normal, ((plane_t*)surface->owner)->PS_normal); V3_Copy(LUM_PLANE(l)->color, ms.colorAmplified); LUM_PLANE(l)->intensity = ms.glowing; diff --git a/doomsday/engine/portable/src/r_model.c b/doomsday/engine/portable/src/r_model.c index 02d8d2203e..82d4a7659c 100644 --- a/doomsday/engine/portable/src/r_model.c +++ b/doomsday/engine/portable/src/r_model.c @@ -806,7 +806,7 @@ static void R_ScaleModelToSprite(modeldef_t* mf, int sprite, int frame) if(!spr->numFrames || spr->spriteFrames == NULL) return; - Materials_Prepare(&ms, spr->spriteFrames[frame].mats[0], true, NULL); + Materials_Prepare(&ms, spr->spriteFrames[frame].mats[0], true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); sprTex = R_SpriteTextureByIndex(Texture_TypeIndex(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex))); assert(NULL != sprTex); @@ -1282,7 +1282,7 @@ void R_PrecacheModelSkins(modeldef_t* modef) memset(¶ms, 0, sizeof(params)); params.tex.flags = (!mdl->allowTexComp? TF_NO_COMPRESSION : 0); - GL_PrepareTexture(sn->id, ¶ms, NULL); + GL_PrepareTexture(sn->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MODELSKIN_DIFFUSE, ¶ms), NULL); } } diff --git a/doomsday/engine/portable/src/r_sky.c b/doomsday/engine/portable/src/r_sky.c index a5b0902e77..5b009f97d1 100644 --- a/doomsday/engine/portable/src/r_sky.c +++ b/doomsday/engine/portable/src/r_sky.c @@ -167,12 +167,11 @@ static void prepareSkySphere(void) material = Materials_ToMaterial(slayer->material); memset(¶ms, 0, sizeof(params)); - params.prepareForSkySphere = true; params.tex.flags = TF_NO_COMPRESSION; if(slayer->flags & SLF_MASKED) params.tex.flags |= TF_ZEROMASK; - Materials_Prepare(&ms, material, false, ¶ms); + Materials_Prepare(&ms, material, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, ¶ms)); slayer->tex = TextureVariant_GLName(ms.units[MTU_PRIMARY].tex); Texture_Dimensions(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex), diff --git a/doomsday/engine/portable/src/r_things.c b/doomsday/engine/portable/src/r_things.c index 173401d44e..bcc40dc15f 100644 --- a/doomsday/engine/portable/src/r_things.c +++ b/doomsday/engine/portable/src/r_things.c @@ -631,7 +631,7 @@ boolean R_GetSpriteInfo(int sprite, int frame, spriteinfo_t* info) memset(¶ms, 0, sizeof(params)); params.tex.border = 1; - Materials_Prepare(&ms, mat, false, ¶ms); + Materials_Prepare(&ms, mat, false, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, ¶ms)); sprTex = R_SpriteTextureByIndex(Texture_TypeIndex(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex))); assert(NULL != sprTex); @@ -669,7 +669,7 @@ float R_VisualRadius(mobj_t* mo) // Use the sprite frame's width. // @fixme What about rotation? - Materials_Prepare(&ms, R_GetMaterialForSprite(mo->sprite, mo->frame), true, NULL); + Materials_Prepare(&ms, R_GetMaterialForSprite(mo->sprite, mo->frame), true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); return ms.width / 2; } @@ -886,7 +886,7 @@ static void setupSpriteParamsForVisSprite(rendspriteparams_t *params, mparams.tclass = transClass; mparams.tex.border = 1; - Materials_Prepare(&ms, mat, true, &mparams); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_TRANSLATED, TC_SPRITE_DIFFUSE, &mparams)); sprTex = R_SpriteTextureByIndex(Texture_TypeIndex(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex))); assert(NULL != sprTex); @@ -1134,7 +1134,7 @@ void R_ProjectSprite(mobj_t* mo) mparams.tclass = tclass; mparams.tex.border = 1; - Materials_Prepare(&ms, mat, true, &mparams); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_TRANSLATED, TC_SPRITE_DIFFUSE, &mparams)); sprTex = R_SpriteTextureByIndex(Texture_TypeIndex(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex))); assert(NULL != sprTex); @@ -1456,7 +1456,7 @@ if(!mat) #endif // Ensure we have up-to-date information about the material. - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); tex = ms.units[MTU_PRIMARY].tex; pl = (const pointlight_analysis_t*) TextureVariant_Analysis(tex, TA_SPRITE_AUTOLIGHT); if(NULL == pl) diff --git a/doomsday/engine/portable/src/r_world.c b/doomsday/engine/portable/src/r_world.c index 95ca362494..f384520180 100644 --- a/doomsday/engine/portable/src/r_world.c +++ b/doomsday/engine/portable/src/r_world.c @@ -1454,7 +1454,7 @@ boolean R_IsGlowingPlane(const plane_t* pln) { material_t* mat = pln->surface.material; material_snapshot_t ms; - Materials_Prepare(&ms, mat, true, 0); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); return ((mat && (mat->flags & MATF_NO_DRAW)) || ms.glowing > 0 || R_IsSkySurface(&pln->surface)); } diff --git a/doomsday/engine/portable/src/rend_console.c b/doomsday/engine/portable/src/rend_console.c index a723aff03c..998d15806f 100644 --- a/doomsday/engine/portable/src/rend_console.c +++ b/doomsday/engine/portable/src/rend_console.c @@ -495,7 +495,7 @@ static void drawConsoleBackground(int x, int y, int w, int h, float gtosMulY, { material_snapshot_t ms; - Materials_Prepare(&ms, consoleBackgroundMaterial, Con_IsActive(), 0); + Materials_Prepare(&ms, consoleBackgroundMaterial, Con_IsActive(), GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UI, NULL)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); /** * Make sure the current texture will be tiled. diff --git a/doomsday/engine/portable/src/rend_fakeradio.c b/doomsday/engine/portable/src/rend_fakeradio.c index f4bf0a932d..827305d801 100644 --- a/doomsday/engine/portable/src/rend_fakeradio.c +++ b/doomsday/engine/portable/src/rend_fakeradio.c @@ -1484,7 +1484,7 @@ static uint radioEdgeHackType(const linedef_t* line, const sector_t* front, cons { material_snapshot_t ms; rtexmapunit_t rTU[NUM_TEXMAP_UNITS]; - Materials_Prepare(&ms, pln->PS_material, true, 0); + Materials_Prepare(&ms, pln->PS_material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); if(ms.glowing > 0) return; diff --git a/doomsday/engine/portable/src/rend_main.c b/doomsday/engine/portable/src/rend_main.c index f3f9aad902..9920a87ef0 100644 --- a/doomsday/engine/portable/src/rend_main.c +++ b/doomsday/engine/portable/src/rend_main.c @@ -420,7 +420,7 @@ boolean Rend_DoesMidTextureFillGap(linedef_t *line, int backside, boolean ignore material_snapshot_t ms; // Ensure we have up to date info. - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); if(ignoreAlpha || (ms.isOpaque && !side->SW_middleblendmode && side->SW_middlergba[3] >= 1)) { @@ -1163,9 +1163,10 @@ boolean RLIT_DynLightWrite(const dynlight_t* dyn, void* data) static float getSnapshots(material_snapshot_t* msA, material_snapshot_t* msB, material_t* mat) { - float interPos = 0; + texturevariantspecification_t* texSpec = GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL); + float interPos = 0; - Materials_Prepare(msA, mat, true, NULL); + Materials_Prepare(msA, mat, true, texSpec); // Smooth Texture Animation? if(msB) @@ -1177,7 +1178,7 @@ static float getSnapshots(material_snapshot_t* msA, material_snapshot_t* msB, !(!usingFog && mat->inter < 0)) { // Prepare the inter texture. - Materials_Prepare(msB, mat->next, false, NULL); + Materials_Prepare(msB, mat->next, false, texSpec); interPos = mat->inter; } } @@ -2043,7 +2044,7 @@ static void renderPlane(subsector_t* ssec, planetype_t type, { material_snapshot_t ms; surface_t* suf = &ssec->sector->planes[elmIdx]->surface; - Materials_Prepare(&ms, suf->material, true, 0); + Materials_Prepare(&ms, suf->material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); params.glowing = ms.glowing; } @@ -2297,7 +2298,7 @@ static boolean rendSegSection(subsector_t* ssec, seg_t* seg, else { material_snapshot_t ms; - Materials_Prepare(&ms, surface->material, true, 0); + Materials_Prepare(&ms, surface->material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); glowing = ms.glowing; } @@ -2956,7 +2957,7 @@ static void prepareSkyMaskSurface(rendpolytype_t polyType, size_t count, rvertex // In devRendSkyMode mode we render all polys destined for the skymask as // regular world polys (with a few obvious properties). - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MAPSURFACE_DIFFUSE, NULL)); rTU[TU_PRIMARY].tex = TextureVariant_GLName(ms.units[MTU_PRIMARY].tex); rTU[TU_PRIMARY].magMode = ms.units[MTU_PRIMARY].magMode; @@ -4997,7 +4998,7 @@ static void Rend_RenderBoundingBoxes(void) glDisable(GL_CULL_FACE); mat = Materials_ToMaterial(Materials_IndexForName(MN_SYSTEM_NAME":bbox")); - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); GL_BlendMode(BM_ADD); diff --git a/doomsday/engine/portable/src/rend_model.c b/doomsday/engine/portable/src/rend_model.c index 72babafabf..ddd14745db 100644 --- a/doomsday/engine/portable/src/rend_model.c +++ b/doomsday/engine/portable/src/rend_model.c @@ -47,6 +47,7 @@ #include "net_main.h" // for gametic #include "texturevariant.h" +#include "texture.h" // MACROS ------------------------------------------------------------------ @@ -701,7 +702,7 @@ static void Mod_RenderSubModel(uint number, const rendmodelparams_t* params) { const skinname_t* sn = R_GetSkinNameByIndex(mf->sub[number].shinySkin); const texturevariant_t* tex; - if(NULL != sn && NULL != (tex = GL_PrepareTexture(sn->id, NULL, NULL))) + if(NULL != sn && NULL != (tex = GL_PrepareTexture(sn->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MODELSKIN_DIFFUSE, NULL), NULL))) { shinyTexture = TextureVariant_GLName(tex); } @@ -781,7 +782,7 @@ static void Mod_RenderSubModel(uint number, const rendmodelparams_t* params) { material_snapshot_t ms; - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MODELSKIN_DIFFUSE, NULL)); skinTexture = TextureVariant_GLName(ms.units[MTU_PRIMARY].tex); } else @@ -807,7 +808,7 @@ static void Mod_RenderSubModel(uint number, const rendmodelparams_t* params) memset(¶ms, 0, sizeof(params)); params.tex.flags = (!mdl->allowTexComp? TF_NO_COMPRESSION : 0); - if((tex = GL_PrepareTexture(sn->id, ¶ms, NULL))) + if((tex = GL_PrepareTexture(sn->id, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_MODELSKIN_DIFFUSE, ¶ms), NULL))) skinTexture = TextureVariant_GLName(tex); } } diff --git a/doomsday/engine/portable/src/rend_sky.c b/doomsday/engine/portable/src/rend_sky.c index 3a49f980f4..d48499893f 100644 --- a/doomsday/engine/portable/src/rend_sky.c +++ b/doomsday/engine/portable/src/rend_sky.c @@ -276,10 +276,9 @@ void Rend_SkyRenderer(int hemi, const rendskysphereparams_t* params) MN_SYSTEM_NAME":missing" )); memset(&p, 0, sizeof(p)); - p.prepareForSkySphere = true; p.tex.flags = TF_NO_COMPRESSION | TF_ZEROMASK; - Materials_Prepare(&ms, material, true, &p); + Materials_Prepare(&ms, material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SKYSPHERE_DIFFUSE, &p)); tex = TextureVariant_GLName(ms.units[MTU_PRIMARY].tex); magMode = ms.units[MTU_PRIMARY].magMode; Texture_Dimensions(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex), diff --git a/doomsday/engine/portable/src/rend_sprite.c b/doomsday/engine/portable/src/rend_sprite.c index 122f50194b..b2f069b70c 100644 --- a/doomsday/engine/portable/src/rend_sprite.c +++ b/doomsday/engine/portable/src/rend_sprite.c @@ -268,10 +268,9 @@ static void setupPSpriteParams(rendpspriteparams_t* params, vispsprite_t* spr) flip = sprFrame->flip[0]; memset(&mparams, 0, sizeof(mparams)); - mparams.pSprite = true; mparams.tex.border = 1; - Materials_Prepare(&ms, sprFrame->mats[0], true, &mparams); + Materials_Prepare(&ms, sprFrame->mats[0], true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_PSPRITE_DIFFUSE, &mparams)); sprTex = R_SpriteTextureByIndex(Texture_TypeIndex(TextureVariant_GeneralCase(ms.units[MTU_PRIMARY].tex))); assert(NULL != sprTex); @@ -356,7 +355,7 @@ void Rend_DrawPSprite(const rendpspriteparams_t *params) material_t* mat = Materials_ToMaterial(Materials_IndexForName(MN_SYSTEM_NAME":gray")); material_snapshot_t ms; - Materials_Prepare(&ms, mat, true, NULL); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_SPRITE_DIFFUSE, NULL)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); glEnable(GL_TEXTURE_2D); } @@ -868,10 +867,9 @@ void Rend_RenderSprite(const rendspriteparams_t* params) memset(&mparams, 0, sizeof(mparams)); mparams.tmap = (renderTextures == 1? params->tMap : 0); mparams.tclass = (renderTextures == 1? params->tClass : 0); - mparams.pSprite = false; mparams.tex.border = 1; - Materials_Prepare(&ms, mat, true, &mparams); + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_TRANSLATED, TC_SPRITE_DIFFUSE, &mparams)); GL_BindTexture(TextureVariant_GLName(ms.units[MTU_PRIMARY].tex), ms.units[MTU_PRIMARY].magMode); glEnable(GL_TEXTURE_2D); } diff --git a/doomsday/engine/portable/src/ui2_main.c b/doomsday/engine/portable/src/ui2_main.c index 0fb5e50e13..1b4985d339 100644 --- a/doomsday/engine/portable/src/ui2_main.c +++ b/doomsday/engine/portable/src/ui2_main.c @@ -524,7 +524,7 @@ static void drawPageBackground(fi_page_t* p, float x, float y, float width, floa if(p->_bg.material) { material_snapshot_t ms; - Materials_Prepare(&ms, p->_bg.material, true, NULL); + Materials_Prepare(&ms, p->_bg.material, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UI, NULL)); tex = TextureVariant_GLName(ms.units[MTU_PRIMARY].tex); } else @@ -994,9 +994,9 @@ static void drawPicFrame(fidata_pic_t* p, uint frame, const float _origin[3], memset(&ms, 0, sizeof(ms)); memset(¶ms, 0, sizeof(params)); - params.pSprite = false; params.tex.border = 1; - Materials_Prepare(&ms, mat, true, ¶ms); + + Materials_Prepare(&ms, mat, true, GL_TextureVariantSpecificationForContext(TS_DEFAULT, TC_UI, ¶ms)); if(ms.units[MTU_PRIMARY].tex) {