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;
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)
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);