From d0da30722fe8f95748c89ca36aff783fb6bfa7fe Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 1 Jun 2020 07:12:22 +0000 Subject: [PATCH] Refactor external texture loading for Q1BSP to set the texture dimensions correctly and also remove some dead code. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12621 d7cf8633-e32d-0410-b094-e92efae38249 --- model_brush.c | 73 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/model_brush.c b/model_brush.c index ebafea72..05b25ded 100644 --- a/model_brush.c +++ b/model_brush.c @@ -1810,13 +1810,20 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb) if (name[j] >= 'A' && name[j] <= 'Z') name[j] += 'a' - 'A'; - // LadyHavoc: backup the texture_t because q3 shader loading overwrites it + tx = loadmodel->data_textures + i; + // try to load shader or external textures, but first we have to backup the texture_t because shader loading overwrites it even if it fails backuptex = loadmodel->data_textures[i]; - if (name[0] && Mod_LoadTextureFromQ3Shader(loadmodel->mempool, loadmodel->name, loadmodel->data_textures + i, name, false, false, 0, MATERIALFLAG_WALL)) + if (name[0] && (Mod_LoadTextureFromQ3Shader(loadmodel->mempool, loadmodel->name, loadmodel->data_textures + i, va(vabuf, sizeof(vabuf), "%s/%s", mapname, name), false, false, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, MATERIALFLAG_WALL) || + Mod_LoadTextureFromQ3Shader(loadmodel->mempool, loadmodel->name, loadmodel->data_textures + i, va(vabuf, sizeof(vabuf), "%s" , name), false, false, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, MATERIALFLAG_WALL))) + { + // set the width/height fields which are used for parsing texcoords in this bsp format + tx->width = mtwidth; + tx->height = mtheight; continue; + } + // no luck with loading shaders or external textures - restore the in-progress texture loading loadmodel->data_textures[i] = backuptex; - tx = loadmodel->data_textures + i; strlcpy(tx->name, name, sizeof(tx->name)); tx->width = mtwidth; tx->height = mtheight; @@ -1859,8 +1866,26 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb) if (cls.state != ca_dedicated) { - // LadyHavoc: HL sky textures are entirely different than quake - if (!loadmodel->brush.ishlbsp && !strncmp(tx->name, "sky", 3) && mtwidth == mtheight * 2) + // did not find external texture via shader loading, load it from the bsp or wad3 + if (loadmodel->brush.ishlbsp) + { + // internal texture overrides wad + unsigned char* pixels, * freepixels; + pixels = freepixels = NULL; + if (mtdata) + pixels = W_ConvertWAD3TextureBGRA(&miptexsb); + if (pixels == NULL) + pixels = freepixels = W_GetTextureBGRA(tx->name); + if (pixels != NULL) + { + tx->width = image_width; + tx->height = image_height; + tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, pixels, image_width, image_height, image_width, image_height, CRC_Block(pixels, image_width * image_height * 4), true); + } + if (freepixels) + Mem_Free(freepixels); + } + else if (!strncmp(tx->name, "sky", 3) && mtwidth == mtheight * 2) { data = loadimagepixelsbgra(gamemode == GAME_TENEBRAE ? tx->name : va(vabuf, sizeof(vabuf), "textures/%s/%s", mapname, tx->name), false, false, false, NULL); if (!data) @@ -1873,41 +1898,9 @@ static void Mod_Q1BSP_LoadTextures(sizebuf_t *sb) else if (mtdata != NULL) R_Q1BSP_LoadSplitSky(mtdata, mtwidth, mtheight, 1); } - else - { - skinframe_t *skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va(vabuf, sizeof(vabuf), "textures/%s/%s", mapname, tx->name), TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, false, false); - if (!skinframe) - skinframe = R_SkinFrame_LoadExternal(gamemode == GAME_TENEBRAE ? tx->name : va(vabuf, sizeof(vabuf), "textures/%s", tx->name), TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP | TEXF_COMPRESS, false, false); - if (skinframe) - tx->offsetmapping = OFFSETMAPPING_DEFAULT; // allow offsetmapping on external textures without a q3 shader - if (!skinframe) - { - // did not find external texture, load it from the bsp or wad3 - if (loadmodel->brush.ishlbsp) - { - // internal texture overrides wad - unsigned char *pixels, *freepixels; - pixels = freepixels = NULL; - if (mtdata) - pixels = W_ConvertWAD3TextureBGRA(&miptexsb); - if (pixels == NULL) - pixels = freepixels = W_GetTextureBGRA(tx->name); - if (pixels != NULL) - { - tx->width = image_width; - tx->height = image_height; - skinframe = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_ALPHA | TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, pixels, image_width, image_height, image_width, image_height, CRC_Block(pixels, image_width * image_height * 4), true); - } - if (freepixels) - Mem_Free(freepixels); - } - else if (mtdata) // texture included - skinframe = R_SkinFrame_LoadInternalQuake(tx->name, TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, false, r_fullbrights.integer, mtdata, tx->width, tx->height); - } - // if skinframe is still NULL the "missing" texture has already been assigned to this - if (skinframe) - tx->materialshaderpass->skinframes[0] = skinframe; - } + else if (mtdata) // texture included + tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalQuake(tx->name, TEXF_MIPMAP | TEXF_ISWORLD | TEXF_PICMIP, false, r_fullbrights.integer, mtdata, tx->width, tx->height); + // if mtdata is NULL, the "missing" texture has already been assigned to this // LadyHavoc: some Tenebrae textures get replaced by black if (!strncmp(tx->name, "*glassmirror", 12)) // Tenebrae tx->materialshaderpass->skinframes[0] = R_SkinFrame_LoadInternalBGRA(tx->name, TEXF_MIPMAP | TEXF_ALPHA, zerotrans, 1, 1, 0, 0, 0, false); -- 2.39.2