Improve Valve Texture File (.vtf) support, still disabled by default.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5547 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2019-09-22 03:25:09 +00:00
parent 131a6be4bc
commit 2498024a77

View file

@ -4953,25 +4953,57 @@ static struct pendingtextureinfo *Image_ReadVTFFile(unsigned int flags, const ch
return NULL;
version = (vtf->major<<16)|vtf->minor;
if (version >= 0x00070003)
return NULL; //we don't support the whole resources thing.
if (version > 0x00070005)
{
Con_Printf("%s: VTF version %i.%i is not supported\n", fname, vtf->major, vtf->minor);
return NULL;
}
lrfmt = (vtf->lowresfmt_misaligned[0]<<0)|(vtf->lowresfmt_misaligned[1]<<16)|(vtf->lowresfmt_misaligned[2]<<16)|(vtf->lowresfmt_misaligned[3]<<24);
vmffmt = vtf->imgformat;
mips = NULL;
if (version >= 0x00070003)
{
int i;
struct
{
unsigned int rtype;
unsigned int rdata; //usually an offset.
} *restable = (void*)(filedata+sizeof(*vtf));
for (i = 0; i < vtf->numresources; i++, restable++)
{
if ((restable->rtype & 0x00ffffff) == 0x30)
{
mips = Z_Malloc(sizeof(*mips));
mips->extrafree = filedata;
filedata += restable->rdata;
break;
}
//other unknown resource types.
}
}
if (!mips)
{
mips = Z_Malloc(sizeof(*mips));
mips->extrafree = filedata;
//skip the header
filedata += vtf->headersize;
//and skip the low-res image too.
if (vtf->lowreswidth && vtf->lowresheight)
Image_BlockSizeForEncoding(ImageVTF_VtfToFTE(lrfmt), &bb, &bw, &bh);
else
bb=bw=bh=1;
datasize = ((vtf->lowreswidth+bw-1)/bw) * ((vtf->lowresheight+bh-1)/bh) * bb;
filedata += datasize;
}
mips = Z_Malloc(sizeof(*mips));
//now handle the high-res image
if (mips)
{
mips->type = (vtf->flags & 0x4000)?PTI_CUBEMAP:PTI_2D;
mips->extrafree = filedata;
filedata += vtf->headersize; //skip the header
filedata += datasize; //and skip the low-res image too.
mips->encoding = ImageVTF_VtfToFTE(vmffmt);
Image_BlockSizeForEncoding(mips->encoding, &bb, &bw, &bh);
@ -5023,6 +5055,7 @@ static struct pendingtextureinfo *Image_ReadVTFFile(unsigned int flags, const ch
}
}
}
}
return mips;
}
#endif
@ -10063,6 +10096,10 @@ static void Image_LoadHiResTextureWorker(void *ctx, void *data, size_t a, size_t
#ifdef IMAGEFMT_DDS
if (!mips)
mips = Image_ReadDDSFile(tex->flags, altname, buf, fsize);
#endif
#ifdef IMAGEFMT_VTF
if (!mips)
mips = Image_ReadVTFFile(tex->flags, altname, buf, fsize);
#endif
if (!mips)
BZ_Free(buf);