Add support for dds textures.

This commit is contained in:
Shpoike 2020-04-11 03:06:00 +01:00
parent 0a61068135
commit 2e1abf9fa7
7 changed files with 492 additions and 66 deletions

View file

@ -722,15 +722,18 @@ void Mod_LoadTextures (lump_t *l)
Sky_LoadTexture (tx, fmt, imgwidth, imgheight);
else if (tx->name[0] == '*') //warping texture
{
enum srcformat rfmt = SRC_RGBA;
fwidth = fheight = 0;
malloced = false;
//external textures -- first look in "textures/mapname/" then look in "textures/"
mark = Hunk_LowMark();
COM_StripExtension (loadmodel->name + 5, mapname, sizeof(mapname));
q_snprintf (filename, sizeof(filename), "textures/%s/#%s", mapname, tx->name+1); //this also replaces the '*' with a '#'
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &rfmt, &malloced);
if (!data)
{
q_snprintf (filename, sizeof(filename), "textures/#%s", tx->name+1);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &rfmt, &malloced);
}
//now load whatever we found
@ -738,7 +741,7 @@ void Mod_LoadTextures (lump_t *l)
{
q_strlcpy (texturename, filename, sizeof(texturename));
tx->gltexture = TexMgr_LoadImage (loadmodel, texturename, fwidth, fheight,
SRC_RGBA, data, filename, 0, TEXPREF_NONE);
rfmt, data, filename, 0, TEXPREF_NONE);
}
else //use the texture from the bsp file
{
@ -762,6 +765,9 @@ void Mod_LoadTextures (lump_t *l)
{
// ericw -- fence textures
int extraflags;
enum srcformat rfmt = SRC_RGBA;
fwidth = fheight = 0;
malloced = false;
extraflags = 0;
if (tx->name[0] == '{')
@ -772,34 +778,34 @@ void Mod_LoadTextures (lump_t *l)
mark = Hunk_LowMark ();
COM_StripExtension (loadmodel->name + 5, mapname, sizeof(mapname));
q_snprintf (filename, sizeof(filename), "textures/%s/%s", mapname, tx->name);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &rfmt, &malloced);
if (!data)
{
q_snprintf (filename, sizeof(filename), "textures/%s", tx->name);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &rfmt, &malloced);
}
//now load whatever we found
if (data) //load external image
{
tx->gltexture = TexMgr_LoadImage (loadmodel, filename, fwidth, fheight,
SRC_RGBA, data, filename, 0, TEXPREF_MIPMAP | extraflags );
rfmt, data, filename, 0, TEXPREF_MIPMAP | extraflags );
//now try to load glow/luma image from the same place
if (malloced)
free(data);
Hunk_FreeToLowMark (mark);
q_snprintf (filename2, sizeof(filename2), "%s_glow", filename);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &rfmt, &malloced);
if (!data)
{
q_snprintf (filename2, sizeof(filename2), "%s_luma", filename);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &rfmt, &malloced);
}
if (data)
tx->fullbright = TexMgr_LoadImage (loadmodel, filename2, fwidth, fheight,
SRC_RGBA, data, filename, 0, TEXPREF_MIPMAP | extraflags );
rfmt, data, filename, 0, TEXPREF_MIPMAP | extraflags );
}
else //use the texture from the bsp file
{
@ -2869,31 +2875,32 @@ void *Mod_LoadAllSkins (int numskins, daliasskintype_t *pskintype)
char filename[MAX_QPATH];
char filename2[MAX_QPATH];
byte *data;
int fwidth, fheight;
qboolean malloced;
int fwidth=0, fheight=0;
qboolean malloced=false;
enum srcformat fmt = SRC_RGBA;
q_snprintf (filename, sizeof(filename), "%s_%i", loadmodel->name, i);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename, &fwidth, &fheight, &fmt, &malloced);
//now load whatever we found
if (data) //load external image
{
pheader->gltextures[i][0] = TexMgr_LoadImage (loadmodel, filename, fwidth, fheight,
SRC_RGBA, data, filename, 0, TEXPREF_ALPHA|texflags|TEXPREF_MIPMAP );
fmt, data, filename, 0, TEXPREF_ALPHA|texflags|TEXPREF_MIPMAP );
//now try to load glow/luma image from the same place
if (malloced)
free(data);
Hunk_FreeToLowMark (mark);
q_snprintf (filename2, sizeof(filename2), "%s_glow", filename);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &fmt, &malloced);
if (!data)
{
q_snprintf (filename2, sizeof(filename2), "%s_luma", filename);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &malloced);
data = !gl_load24bit.value?NULL:Image_LoadImage (filename2, &fwidth, &fheight, &fmt, &malloced);
}
if (data)
pheader->fbtextures[i][0] = TexMgr_LoadImage (loadmodel, filename2, fwidth, fheight,
SRC_RGBA, data, filename, 0, TEXPREF_ALPHA|texflags|TEXPREF_MIPMAP );
fmt, data, filename, 0, TEXPREF_ALPHA|texflags|TEXPREF_MIPMAP );
else
pheader->fbtextures[i][0] = NULL;
}

View file

@ -196,12 +196,13 @@ void Sky_LoadSkyBox (const char *name)
//load textures
for (i=0; i<6; i++)
{
enum srcformat fmt;
mark = Hunk_LowMark ();
q_snprintf (filename, sizeof(filename), "gfx/env/%s%s", name, suf[i]);
data = Image_LoadImage (filename, &width, &height, &malloced);
data = Image_LoadImage (filename, &width, &height, &fmt, &malloced);
if (data)
{
skybox_textures[i] = TexMgr_LoadImage (cl.worldmodel, filename, width, height, SRC_RGBA, data, filename, 0, TEXPREF_NONE);
skybox_textures[i] = TexMgr_LoadImage (cl.worldmodel, filename, width, height, fmt, data, filename, 0, TEXPREF_NONE);
nonefound = false;
}
else

View file

@ -49,14 +49,15 @@ unsigned int d_8to24table_pants[256];
static struct
{
const char *mipextname;
int internalformat;
int format;
int type; //for non-compressed formats
int blockbytes;
int blockwidth;
int blockheight;
qboolean *supported;
const char *formatname; //full name
const char *mipextname; //four chars
int internalformat; //opengl's internal format (mostly sized formats)
int format; //for non-compressed formats (opengl's transcoding)
int type; //for non-compressed formats (opengl's transcoding)
int blockbytes; //bytes per block
int blockwidth; //width of a block (or 1 for non-block formats)
int blockheight; //height of a block (or 1 for non-block formats)
qboolean *supported; //pointer to some boolean that says whether some opengl extension is actually support or not.
} compressedformats[] =
{
{NULL}, //SRC_INDEXED
@ -64,37 +65,38 @@ static struct
{NULL}, //SRC_RGBA
{NULL}, //SRC_EXTERNAL
{"RGBA", GL_RGBA,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV, 4, 1, 1, NULL},
{"RGB", GL_RGB,GL_RGB,GL_UNSIGNED_BYTE, 3, 1, 1, NULL},
{"565", GL_RGB565,GL_RGB,GL_UNSIGNED_SHORT_5_6_5, 2, 1, 1, NULL},
{"4444", GL_RGBA4,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4, 2, 1, 1, NULL},
{"5551", GL_RGB5_A1,GL_RGBA,GL_UNSIGNED_SHORT_5_5_5_1, 2, 1, 1, NULL},
{"LUM8", GL_LUMINANCE8,GL_LUMINANCE,GL_UNSIGNED_BYTE, 1, 1, 1, NULL},
{"EXP5", GL_RGB9_E5,GL_RGB,GL_UNSIGNED_INT_5_9_9_9_REV, 4, 1, 1, &gl_texture_astc},
{"BC1", GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,0,0, 8, 4, 4, &gl_texture_s3tc},
{"BC2", GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,0,0, 16, 4, 4, &gl_texture_s3tc},
{"BC3", GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,0,0, 16, 4, 4, &gl_texture_s3tc},
{"BC4", GL_COMPRESSED_RED_RGTC1,0,0, 8, 4, 4, &gl_texture_rgtc},
{"BC5", GL_COMPRESSED_RG_RGTC2,0,0, 16, 4, 4, &gl_texture_rgtc},
{"BC6", GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,0,0, 16, 4, 4, &gl_texture_bptc},
{"BC7", GL_COMPRESSED_RGBA_BPTC_UNORM,0,0, 16, 4, 4, &gl_texture_bptc},
{"ETC1", GL_COMPRESSED_RGB8_ETC2,0,0, 8, 4, 4, &gl_texture_etc2},
{"ETC2", GL_COMPRESSED_RGB8_ETC2,0,0, 8, 4, 4, &gl_texture_etc2},
{"ETCP", GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,0,0,8, 4, 4, &gl_texture_etc2},
{"ETCA", GL_COMPRESSED_RGBA8_ETC2_EAC,0,0, 16, 4, 4, &gl_texture_etc2},
{"AST4", GL_COMPRESSED_RGBA_ASTC_4x4_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AS54", GL_COMPRESSED_RGBA_ASTC_5x4_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AST5", GL_COMPRESSED_RGBA_ASTC_5x5_KHR,0,0, 16, 5, 5, &gl_texture_astc},
{"AS65", GL_COMPRESSED_RGBA_ASTC_6x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AST6", GL_COMPRESSED_RGBA_ASTC_6x6_KHR,0,0, 16, 6, 6, &gl_texture_astc},
{"AS85", GL_COMPRESSED_RGBA_ASTC_8x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AS86", GL_COMPRESSED_RGBA_ASTC_8x6_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AST8", GL_COMPRESSED_RGBA_ASTC_8x8_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"AS05", GL_COMPRESSED_RGBA_ASTC_10x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AS06", GL_COMPRESSED_RGBA_ASTC_10x6_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AS08", GL_COMPRESSED_RGBA_ASTC_10x8_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"AST0", GL_COMPRESSED_RGBA_ASTC_10x10_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"AST2", GL_COMPRESSED_RGBA_ASTC_12x12_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"RGBA8", "RGBA", GL_RGBA,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8_REV, 4, 1, 1, NULL},
{"RGB8", "RGB", GL_RGB,GL_RGB,GL_UNSIGNED_BYTE, 3, 1, 1, NULL},
{"RGB565", "565", GL_RGB565,GL_RGB,GL_UNSIGNED_SHORT_5_6_5, 2, 1, 1, NULL},
{"RGBA4444", "4444", GL_RGBA4,GL_RGBA,GL_UNSIGNED_SHORT_4_4_4_4, 2, 1, 1, NULL},
{"RGBA5551", "5551", GL_RGB5_A1,GL_RGBA,GL_UNSIGNED_SHORT_5_5_5_1, 2, 1, 1, NULL},
{"L8", "LUM8", GL_LUMINANCE8,GL_LUMINANCE,GL_UNSIGNED_BYTE, 1, 1, 1, NULL},
{"E5BGR9", "EXP5", GL_RGB9_E5,GL_RGB,GL_UNSIGNED_INT_5_9_9_9_REV, 4, 1, 1, &gl_texture_astc},
{"BC1_RGBA", "BC1", GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,0,0, 8, 4, 4, &gl_texture_s3tc},
{"BC2_RGBA", "BC2", GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,0,0, 16, 4, 4, &gl_texture_s3tc},
{"BC3_RGBA", "BC3", GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,0,0, 16, 4, 4, &gl_texture_s3tc},
{"BC4_R", "BC4", GL_COMPRESSED_RED_RGTC1,0,0, 8, 4, 4, &gl_texture_rgtc},
{"BC5_RG", "BC5", GL_COMPRESSED_RG_RGTC2,0,0, 16, 4, 4, &gl_texture_rgtc},
{"BC6_RGB_UFLOAT","BC6",GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT,0,0, 16, 4, 4, &gl_texture_bptc},
{"BC7_RGBA", "BC7", GL_COMPRESSED_RGBA_BPTC_UNORM,0,0, 16, 4, 4, &gl_texture_bptc},
{"ETC1_RGB8", "ETC1", GL_COMPRESSED_RGB8_ETC2,0,0, 8, 4, 4, &gl_texture_etc2},
{"ETC2_RGB8", "ETC2", GL_COMPRESSED_RGB8_ETC2,0,0, 8, 4, 4, &gl_texture_etc2},
{"ETC2_RGB8A1", "ETCP", GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,0,0, 8, 4, 4, &gl_texture_etc2},
{"ETC2_RGB8A8", "ETCA", GL_COMPRESSED_RGBA8_ETC2_EAC,0,0, 16, 4, 4, &gl_texture_etc2},
{"ASTC_4X4", "AST4", GL_COMPRESSED_RGBA_ASTC_4x4_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_5X4", "AS54", GL_COMPRESSED_RGBA_ASTC_5x4_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_5X5", "AST5", GL_COMPRESSED_RGBA_ASTC_5x5_KHR,0,0, 16, 5, 5, &gl_texture_astc},
{"ASTC_6X5", "AS65", GL_COMPRESSED_RGBA_ASTC_6x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_6X6", "AST6", GL_COMPRESSED_RGBA_ASTC_6x6_KHR,0,0, 16, 6, 6, &gl_texture_astc},
{"ASTC_8X5", "AS85", GL_COMPRESSED_RGBA_ASTC_8x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_8X6", "AS86", GL_COMPRESSED_RGBA_ASTC_8x6_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_8X8", "AST8", GL_COMPRESSED_RGBA_ASTC_8x8_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"ASTC_10X5", "AS05", GL_COMPRESSED_RGBA_ASTC_10x5_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_10X6", "AS06", GL_COMPRESSED_RGBA_ASTC_10x6_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_10X8", "AS08", GL_COMPRESSED_RGBA_ASTC_10x8_KHR,0,0, 16, 4, 4, &gl_texture_astc},
{"ASTC_10X10", "AST0", GL_COMPRESSED_RGBA_ASTC_10x10_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"ASTC_12X10", "AST0", GL_COMPRESSED_RGBA_ASTC_12x10_KHR,0,0, 16, 8, 8, &gl_texture_astc},
{"ASTC_12X12", "AST2", GL_COMPRESSED_RGBA_ASTC_12x12_KHR,0,0, 16, 8, 8, &gl_texture_astc},
};
/*
@ -1205,6 +1207,18 @@ size_t TexMgr_ImageSize (int width, int height, enum srcformat format)
return mipbytes;
}
}
enum srcformat TexMgr_FormatForName (const char *code)
{
size_t i;
for (i = 0; i < sizeof(compressedformats)/sizeof(compressedformats[0]); i++)
{
if (!compressedformats[i].formatname)
continue;
if (!strcasecmp(code, compressedformats[i].formatname))
return i;
}
return SRC_EXTERNAL;
}
enum srcformat TexMgr_FormatForCode (const char *code)
{
size_t i;
@ -1398,6 +1412,7 @@ gltexture_t *TexMgr_LoadImage (qmodel_t *owner, const char *name, int width, int
gltexture_t *glt;
int mark;
qboolean malloced;
enum srcformat fmt;
if (isDedicated)
return NULL;
@ -1442,7 +1457,7 @@ gltexture_t *TexMgr_LoadImage (qmodel_t *owner, const char *name, int width, int
TexMgr_LoadLightmap (glt, data);
break;
case SRC_EXTERNAL:
data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height, &malloced); //simple file
data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height, &fmt, &malloced); //simple file
if (!data)
{
glt->source_width = glt->source_height = 1;
@ -1454,7 +1469,12 @@ gltexture_t *TexMgr_LoadImage (qmodel_t *owner, const char *name, int width, int
{
glt->width = glt->source_width;
glt->height = glt->source_height;
TexMgr_LoadImage32 (glt, (unsigned *)data);
if (fmt == SRC_RGBA)
TexMgr_LoadImage32 (glt, (unsigned *)data);
else if (fmt == SRC_INDEXED)
TexMgr_LoadImage8 (glt, data);
else
TexMgr_LoadImageCompressed (glt, data);
if (malloced)
free(data);
}
@ -1491,6 +1511,7 @@ void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
byte *src, *dst, *data = NULL, *translated;
int mark, size, i;
qboolean malloced = false;
enum srcformat fmt = glt->source_format;
//
// get source data
//
@ -1512,7 +1533,7 @@ void TexMgr_ReloadImage (gltexture_t *glt, int shirt, int pants)
fclose (f);
}
else if (glt->source_file[0] && !glt->source_offset)
data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height, &malloced); //simple file
data = Image_LoadImage (glt->source_file, (int *)&glt->source_width, (int *)&glt->source_height, &fmt, &malloced); //simple file
else if (!glt->source_file[0] && glt->source_offset)
data = (byte *) glt->source_offset; //image in memory

View file

@ -89,6 +89,7 @@ void TexMgr_NewGame (void);
void TexMgr_Init (void);
void TexMgr_DeleteTextureObjects (void);
enum srcformat TexMgr_FormatForCode (const char *code); //returns SRC_EXTERNAL when not known.
enum srcformat TexMgr_FormatForName (const char *name); //returns SRC_EXTERNAL when not known.
size_t TexMgr_ImageSize (int width, int height, enum srcformat format);
void TexMgr_BlockSize (enum srcformat format, int *bytes, int *width, int *height);

View file

@ -117,28 +117,422 @@ byte *Image_LoadPNG(FILE *f, int *width, int *height, qboolean *malloced)
#endif
}
/*spike -- start of dds loader
note that support for loading compressed mipchains is elsewhere. not all those listed here will work.
formats are dependant upon the user's hardware.
mip chains must be complete (no single-level images)
non-2d images are not supported.
dx10 dds files ARE supported (but probably won't be generated by your tools...), but bc7 is there if you want it (and the user's gpu drivers support it).
*/
typedef struct {
unsigned int dwSize;
unsigned int dwFlags;
unsigned int dwFourCC;
unsigned int bitcount;
unsigned int redmask;
unsigned int greenmask;
unsigned int bluemask;
unsigned int alphamask;
} ddspixelformat_t;
typedef struct {
unsigned int magic;
unsigned int dwSize;
unsigned int dwFlags;
unsigned int dwHeight;
unsigned int dwWidth;
unsigned int dwPitchOrLinearSize;
unsigned int dwDepth;
unsigned int dwMipMapCount;
unsigned int dwReserved1[11];
ddspixelformat_t ddpfPixelFormat;
unsigned int ddsCaps[4];
unsigned int dwReserved2;
} ddsheader_t;
typedef struct {
unsigned int dxgiformat;
unsigned int resourcetype; //0=unknown, 1=buffer, 2=1d, 3=2d, 4=3d
unsigned int miscflag; //singular... yeah. 4=cubemap.
unsigned int arraysize;
unsigned int miscflags2;
} dds10header_t;
static byte *Image_LoadDDS(FILE *f, int *width, int *height, enum srcformat *fmt)
{
const char *fname = loadfilename; //parameters as globals is a shitty practise, but I'm too lazy to fix up the other loaders too.
int nummips;
int mipnum;
int datasize;
byte *ret;
enum srcformat encoding = SRC_EXTERNAL;
ddsheader_t fmtheader;
dds10header_t fmt10header;
fread(&fmtheader, 1, sizeof(fmtheader), f);
if (fmtheader.magic != (('D'<<0)|('D'<<8)|('S'<<16)|(' '<<24)))
return NULL;
fmtheader.dwSize += sizeof(fmtheader.magic);
if (fmtheader.dwSize != sizeof(fmtheader))
return NULL; //corrupt/different version
memset(&fmt10header, 0, sizeof(fmt10header));
fmt10header.arraysize = (fmtheader.ddsCaps[1] & 0x200)?6:1; //cubemaps need 6 faces...
nummips = fmtheader.dwMipMapCount;
if (nummips < 1)
nummips = 1;
if (!(fmtheader.ddpfPixelFormat.dwFlags & 4))
{
#define IsPacked(bits,r,g,b,a) fmtheader.ddpfPixelFormat.bitcount==bits&&fmtheader.ddpfPixelFormat.redmask==r&&fmtheader.ddpfPixelFormat.greenmask==g&&fmtheader.ddpfPixelFormat.bluemask==b&&fmtheader.ddpfPixelFormat.alphamask==a
if (IsPacked(24, 0xff0000, 0x00ff00, 0x0000ff, 0))
encoding = TexMgr_FormatForName("BGR8");
else if (IsPacked(24, 0x000000, 0x00ff00, 0xff0000, 0))
encoding = TexMgr_FormatForName("RGB8");
else if (IsPacked(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000))
encoding = TexMgr_FormatForName("BGRA8");
else if (IsPacked(32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000))
encoding = TexMgr_FormatForName("RGBA8");
else if (IsPacked(32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0))
encoding = TexMgr_FormatForName("BGRX8");
else if (IsPacked(32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0))
encoding = TexMgr_FormatForName("RGBX8");
else if (IsPacked(32, 0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000))
encoding = TexMgr_FormatForName("A2BGR10");
else if (IsPacked(16, 0xf800, 0x07e0, 0x001f, 0))
encoding = TexMgr_FormatForName("RGB565");
else if (IsPacked(16, 0xf800, 0x07c0, 0x003e, 0x0001))
encoding = TexMgr_FormatForName("RGBA5551");
else if (IsPacked(16, 0x7c00, 0x03e0, 0x001f, 0x8000))
encoding = TexMgr_FormatForName("ARGB1555");
else if (IsPacked(16, 0xf000, 0x0f00, 0x00f0, 0x000f))
encoding = TexMgr_FormatForName("RGBA4444");
else if (IsPacked(16, 0x0f00, 0x00f0, 0x000f, 0xf000))
encoding = TexMgr_FormatForName("ARGB4444");
else if (IsPacked( 8, 0x000000ff, 0x00000000, 0x00000000, 0x00000000))
encoding = (fmtheader.ddpfPixelFormat.dwFlags&0x20000)?TexMgr_FormatForName("L8"):TexMgr_FormatForName("R8");
else if (IsPacked(16, 0x000000ff, 0x00000000, 0x00000000, 0x0000ff00))
encoding = TexMgr_FormatForName("L8A8");
if (encoding == SRC_EXTERNAL) //used as an error code
{
Con_Printf("Unsupported non-fourcc dds in %s\n", fname);
Con_Printf(" bits: %u\n", fmtheader.ddpfPixelFormat.bitcount);
Con_Printf(" red: %08x\n", fmtheader.ddpfPixelFormat.redmask);
Con_Printf("green: %08x\n", fmtheader.ddpfPixelFormat.greenmask);
Con_Printf(" blue: %08x\n", fmtheader.ddpfPixelFormat.bluemask);
Con_Printf("alpha: %08x\n", fmtheader.ddpfPixelFormat.alphamask);
Con_Printf(" used: %08x\n", fmtheader.ddpfPixelFormat.redmask^fmtheader.ddpfPixelFormat.greenmask^fmtheader.ddpfPixelFormat.bluemask^fmtheader.ddpfPixelFormat.alphamask);
return NULL;
}
#undef IsPacked
}
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('1'<<24)))
encoding = TexMgr_FormatForName("BC1_RGBA"); //alpha or not? Assume yes, and let the drivers decide.
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('2'<<24))) //dx3 with premultiplied alpha
{
// if (!(tex->flags & IF_PREMULTIPLYALPHA))
// return false;
encoding = TexMgr_FormatForName("BC2_RGBA");
}
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('3'<<24)))
{
// if (tex->flags & IF_PREMULTIPLYALPHA)
// return false;
encoding = TexMgr_FormatForName("BC2_RGBA");
}
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('4'<<24))) //dx5 with premultiplied alpha
{
// if (!(tex->flags & IF_PREMULTIPLYALPHA))
// return false;
encoding = TexMgr_FormatForName("BC3_RGBA");
}
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('T'<<16)|('5'<<24)))
{
// if (tex->flags & IF_PREMULTIPLYALPHA)
// return false;
encoding = TexMgr_FormatForName("BC3_RGBA");
}
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('A'<<0)|('T'<<8)|('I'<<16)|('1'<<24))
|| *(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('B'<<0)|('C'<<8)|('4'<<16)|('U'<<24)))
encoding = TexMgr_FormatForName("BC4_R");
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('A'<<0)|('T'<<8)|('I'<<16)|('2'<<24))
|| *(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('B'<<0)|('C'<<8)|('5'<<16)|('U'<<24)))
encoding = TexMgr_FormatForName("BC5_RG");
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('B'<<0)|('C'<<8)|('4'<<16)|('S'<<24)))
encoding = TexMgr_FormatForName("BC4_R_SNORM");
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('B'<<0)|('C'<<8)|('5'<<16)|('S'<<24)))
encoding = TexMgr_FormatForName("BC5_RG_SNORM");
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('E'<<0)|('T'<<8)|('C'<<16)|('2'<<24)))
encoding = TexMgr_FormatForName("ETC2_RGB");
else if (*(int*)&fmtheader.ddpfPixelFormat.dwFourCC == (('D'<<0)|('X'<<8)|('1'<<16)|('0'<<24)))
{
//this has some weird extra header with dxgi format types.
fread(&fmt10header, 1, sizeof(fmt10header), f);
switch(fmt10header.dxgiformat)
{
// case 0x0/*DXGI_FORMAT_UNKNOWN*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x1/*DXGI_FORMAT_R32G32B32A32_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x2/*DXGI_FORMAT_R32G32B32A32_FLOAT*/: encoding = TexMgr_FormatForName("RGBA32F"); break;
// case 0x3/*DXGI_FORMAT_R32G32B32A32_UINT*/: encoding = TexMgr_FormatForName("RGBA32_UINT"); break;
// case 0x4/*DXGI_FORMAT_R32G32B32A32_SINT*/: encoding = TexMgr_FormatForName("RGBA32_SINT"); break;
// case 0x5/*DXGI_FORMAT_R32G32B32_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x6/*DXGI_FORMAT_R32G32B32_FLOAT*/: encoding = TexMgr_FormatForName("RGB32F"); break;
// case 0x7/*DXGI_FORMAT_R32G32B32_UINT*/: encoding = TexMgr_FormatForName("RGB32_UINT"); break;
// case 0x8/*DXGI_FORMAT_R32G32B32_SINT*/: encoding = TexMgr_FormatForName("RGB32_SINT"); break;
// case 0x9/*DXGI_FORMAT_R16G16B16A16_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0xa/*DXGI_FORMAT_R16G16B16A16_FLOAT*/: encoding = TexMgr_FormatForName("RGBA16F"); break;
case 0xb/*DXGI_FORMAT_R16G16B16A16_UNORM*/: encoding = TexMgr_FormatForName("RGBA16"); break;
// case 0xc/*DXGI_FORMAT_R16G16B16A16_UINT*/: encoding = TexMgr_FormatForName("RGBA16_UINT"); break;
// case 0xd/*DXGI_FORMAT_R16G16B16A16_SNORM*/: encoding = TexMgr_FormatForName("RGBA16_SNORM"); break;
// case 0xe/*DXGI_FORMAT_R16G16B16A16_SINT*/: encoding = TexMgr_FormatForName("RGBA16_SINT"); break;
// case 0xf/*DXGI_FORMAT_R32G32_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x10/*DXGI_FORMAT_R32G32_FLOAT*/: encoding = TexMgr_FormatForName("RG32F"); break;
// case 0x11/*DXGI_FORMAT_R32G32_UINT*/: encoding = TexMgr_FormatForName("RG32_UINT"); break;
// case 0x12/*DXGI_FORMAT_R32G32_SINT*/: encoding = TexMgr_FormatForName("RG32_SINT"); break;
// case 0x13/*DXGI_FORMAT_R32G8X24_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x14/*DXGI_FORMAT_D32_FLOAT_S8X24_UINT*/: encoding = TexMgr_FormatForName("DEPTH32_8"); break;
// case 0x15/*DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS*/:encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x16/*DXGI_FORMAT_X32_TYPELESS_G8X24_UINT*/:encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x17/*DXGI_FORMAT_R10G10B10A2_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x18/*DXGI_FORMAT_R10G10B10A2_UNORM*/: encoding = TexMgr_FormatForName("A2BGR10"); break;
// case 0x19/*DXGI_FORMAT_R10G10B10A2_UINT*/: encoding = TexMgr_FormatForName("A2BGR10_UINT"); break;
case 0x1a/*DXGI_FORMAT_R11G11B10_FLOAT*/: encoding = TexMgr_FormatForName("B10G11R11F"); break;
// case 0x1b/*DXGI_FORMAT_R8G8B8A8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x1c/*DXGI_FORMAT_R8G8B8A8_UNORM*/: encoding = TexMgr_FormatForName("RGBA8"); break;
case 0x1d/*DXGI_FORMAT_R8G8B8A8_UNORM_SRGB*/: encoding = TexMgr_FormatForName("RGBA8_SRGB"); break;
// case 0x1e/*DXGI_FORMAT_R8G8B8A8_UINT*/: encoding = TexMgr_FormatForName("RGBA8_UINT"); break;
// case 0x1f/*DXGI_FORMAT_R8G8B8A8_SNORM*/: encoding = TexMgr_FormatForName("RGBA8_SNORM"); break;
// case 0x20/*DXGI_FORMAT_R8G8B8A8_SINT*/: encoding = TexMgr_FormatForName("RGBA8_SINT"); break;
// case 0x21/*DXGI_FORMAT_R16G16_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x22/*DXGI_FORMAT_R16G16_FLOAT*/: encoding = TexMgr_FormatForName("RG16F"); break;
// case 0x23/*DXGI_FORMAT_R16G16_UNORM*/: encoding = TexMgr_FormatForName("RG16"); break;
// case 0x24/*DXGI_FORMAT_R16G16_UINT*/: encoding = TexMgr_FormatForName("RG16_UINT"); break;
// case 0x25/*DXGI_FORMAT_R16G16_SNORM*/: encoding = TexMgr_FormatForName("RG16_SNORM"); break;
// case 0x26/*DXGI_FORMAT_R16G16_SINT*/: encoding = TexMgr_FormatForName("RG16_SINT"); break;
// case 0x27/*DXGI_FORMAT_R32_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x28/*DXGI_FORMAT_D32_FLOAT*/: encoding = TexMgr_FormatForName("DEPTH32"); break;
case 0x29/*DXGI_FORMAT_R32_FLOAT*/: encoding = TexMgr_FormatForName("R32F"); break;
// case 0x2a/*DXGI_FORMAT_R32_UINT*/: encoding = TexMgr_FormatForName("R32_UINT"); break;
// case 0x2b/*DXGI_FORMAT_R32_SINT*/: encoding = TexMgr_FormatForName("R32_SINT"); break;
// case 0x2c/*DXGI_FORMAT_R24G8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x2d/*DXGI_FORMAT_D24_UNORM_S8_UINT*/: encoding = TexMgr_FormatForName("DEPTH24_8"); break;
// case 0x2e/*DXGI_FORMAT_R24_UNORM_X8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x2f/*DXGI_FORMAT_X24_TYPELESS_G8_UINT*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x30/*DXGI_FORMAT_R8G8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x31/*DXGI_FORMAT_R8G8_UNORM*/: encoding = TexMgr_FormatForName("RG8"); break;
// case 0x32/*DXGI_FORMAT_R8G8_UINT*/: encoding = TexMgr_FormatForName("RG8_UINT"); break;
case 0x33/*DXGI_FORMAT_R8G8_SNORM*/: encoding = TexMgr_FormatForName("RG8_SNORM"); break;
// case 0x34/*DXGI_FORMAT_R8G8_SINT*/: encoding = TexMgr_FormatForName("RG8_SINT"); break;
// case 0x35/*DXGI_FORMAT_R16_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x36/*DXGI_FORMAT_R16_FLOAT*/: encoding = TexMgr_FormatForName("R16F"); break;
case 0x37/*DXGI_FORMAT_D16_UNORM*/: encoding = TexMgr_FormatForName("DEPTH16"); break;
case 0x38/*DXGI_FORMAT_R16_UNORM*/: encoding = TexMgr_FormatForName("R16"); break;
// case 0x39/*DXGI_FORMAT_R16_UINT*/: encoding = TexMgr_FormatForName("R16_UINT"); break;
// case 0x3a/*DXGI_FORMAT_R16_SNORM*/: encoding = TexMgr_FormatForName("R16_SNORM"); break;
// case 0x3b/*DXGI_FORMAT_R16_SINT*/: encoding = TexMgr_FormatForName("R16_SINT"); break;
// case 0x3c/*DXGI_FORMAT_R8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x3d/*DXGI_FORMAT_R8_UNORM*/: encoding = TexMgr_FormatForName("R8"); break;
// case 0x3e/*DXGI_FORMAT_R8_UINT*/: encoding = TexMgr_FormatForName("R8_UINT"); break;
case 0x3f/*DXGI_FORMAT_R8_SNORM*/: encoding = TexMgr_FormatForName("R8_SNORM"); break;
// case 0x40/*DXGI_FORMAT_R8_SINT*/: encoding = TexMgr_FormatForName("R8_SINT"); break;
case 0x41/*DXGI_FORMAT_A8_UNORM*/: encoding = TexMgr_FormatForName("A8"); break;
// case 0x42/*DXGI_FORMAT_R1_UNORM*/: encoding = TexMgr_FormatForName("R1"); break;
case 0x43/*DXGI_FORMAT_R9G9B9E5_SHAREDEXP*/: encoding = TexMgr_FormatForName("E5BGR9"); break;
// case 0x44/*DXGI_FORMAT_R8G8_B8G8_UNORM*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x45/*DXGI_FORMAT_G8R8_G8B8_UNORM*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x46/*DXGI_FORMAT_BC1_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x47/*DXGI_FORMAT_BC1_UNORM*/: encoding = TexMgr_FormatForName("BC1_RGBA"); break;
case 0x48/*DXGI_FORMAT_BC1_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BC1_RGBA_SRGB"); break;
// case 0x49/*DXGI_FORMAT_BC2_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x4a/*DXGI_FORMAT_BC2_UNORM*/: encoding = TexMgr_FormatForName("BC2_RGBA"); break;
case 0x4b/*DXGI_FORMAT_BC2_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BC2_RGBA_SRGB"); break;
// case 0x4c/*DXGI_FORMAT_BC3_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x4d/*DXGI_FORMAT_BC3_UNORM*/: encoding = TexMgr_FormatForName("BC3_RGBA"); break;
case 0x4e/*DXGI_FORMAT_BC3_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BC3_RGBA_SRGB"); break;
// case 0x4f/*DXGI_FORMAT_BC4_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x50/*DXGI_FORMAT_BC4_UNORM*/: encoding = TexMgr_FormatForName("BC4_R"); break;
case 0x51/*DXGI_FORMAT_BC4_SNORM*/: encoding = TexMgr_FormatForName("BC4_R_SNORM"); break;
// case 0x52/*DXGI_FORMAT_BC5_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x53/*DXGI_FORMAT_BC5_UNORM*/: encoding = TexMgr_FormatForName("BC5_RG"); break;
case 0x54/*DXGI_FORMAT_BC5_SNORM*/: encoding = TexMgr_FormatForName("BC5_RG_SNORM"); break;
case 0x55/*DXGI_FORMAT_B5G6R5_UNORM*/: encoding = TexMgr_FormatForName("RGB565"); break;
case 0x56/*DXGI_FORMAT_B5G5R5A1_UNORM*/: encoding = TexMgr_FormatForName("ARGB1555"); break;
case 0x57/*DXGI_FORMAT_B8G8R8A8_UNORM*/: encoding = TexMgr_FormatForName("BGRA8"); break;
case 0x58/*DXGI_FORMAT_B8G8R8X8_UNORM*/: encoding = TexMgr_FormatForName("BGRX8"); break;
// case 0x59/*DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM*/:encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x5a/*DXGI_FORMAT_B8G8R8A8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x5b/*DXGI_FORMAT_B8G8R8A8_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BGRA8_SRGB"); break;
// case 0x5c/*DXGI_FORMAT_B8G8R8X8_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x5d/*DXGI_FORMAT_B8G8R8X8_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BGRX8_SRGB"); break;
// case 0x5e/*DXGI_FORMAT_BC6H_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x5f/*DXGI_FORMAT_BC6H_UF16*/: encoding = TexMgr_FormatForName("BC6_RGB_UFLOAT"); break;
case 0x60/*DXGI_FORMAT_BC6H_SF16*/: encoding = TexMgr_FormatForName("BC6_RGB_SFLOAT"); break;
// case 0x61/*DXGI_FORMAT_BC7_TYPELESS*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x62/*DXGI_FORMAT_BC7_UNORM*/: encoding = TexMgr_FormatForName("BC7_RGBA"); break;
case 0x63/*DXGI_FORMAT_BC7_UNORM_SRGB*/: encoding = TexMgr_FormatForName("BC7_RGBA_SRGB"); break;
// case 0x64/*DXGI_FORMAT_AYUV*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x65/*DXGI_FORMAT_Y410*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x66/*DXGI_FORMAT_Y416*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x67/*DXGI_FORMAT_NV12*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x68/*DXGI_FORMAT_P010*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x69/*DXGI_FORMAT_P016*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6a/*DXGI_FORMAT_420_OPAQUE*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6b/*DXGI_FORMAT_YUY2*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6c/*DXGI_FORMAT_Y210*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6d/*DXGI_FORMAT_Y216*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6e/*DXGI_FORMAT_NV11*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x6f/*DXGI_FORMAT_AI44*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x70/*DXGI_FORMAT_IA44*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x71/*DXGI_FORMAT_P8*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x72/*DXGI_FORMAT_A8P8*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 0x73/*DXGI_FORMAT_B4G4R4A4_UNORM*/: encoding = TexMgr_FormatForName("ARGB4444"); break;
// case 0x82/*DXGI_FORMAT_P208*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x83/*DXGI_FORMAT_V208*/: encoding = TexMgr_FormatForName("INVALID"); break;
// case 0x84/*DXGI_FORMAT_V408*/: encoding = TexMgr_FormatForName("INVALID"); break;
case 134: encoding = TexMgr_FormatForName("ASTC_4X4"); break;
case 135: encoding = TexMgr_FormatForName("ASTC_4X4_SRGB"); break;
case 138: encoding = TexMgr_FormatForName("ASTC_5X4"); break;
case 139: encoding = TexMgr_FormatForName("ASTC_5X4_SRGB"); break;
case 142: encoding = TexMgr_FormatForName("ASTC_5X5"); break;
case 143: encoding = TexMgr_FormatForName("ASTC_5X5_SRGB"); break;
case 146: encoding = TexMgr_FormatForName("ASTC_6X5"); break;
case 147: encoding = TexMgr_FormatForName("ASTC_6X5_SRGB"); break;
case 150: encoding = TexMgr_FormatForName("ASTC_6X6"); break;
case 151: encoding = TexMgr_FormatForName("ASTC_6X6_SRGB"); break;
case 154: encoding = TexMgr_FormatForName("ASTC_8X5"); break;
case 155: encoding = TexMgr_FormatForName("ASTC_8X5_SRGB"); break;
case 158: encoding = TexMgr_FormatForName("ASTC_8X6"); break;
case 159: encoding = TexMgr_FormatForName("ASTC_8X6_SRGB"); break;
case 162: encoding = TexMgr_FormatForName("ASTC_8X8"); break;
case 163: encoding = TexMgr_FormatForName("ASTC_8X8_SRGB"); break;
case 166: encoding = TexMgr_FormatForName("ASTC_10X5"); break;
case 167: encoding = TexMgr_FormatForName("ASTC_10X5_SRGB"); break;
case 170: encoding = TexMgr_FormatForName("ASTC_10X6"); break;
case 171: encoding = TexMgr_FormatForName("ASTC_10X6_SRGB"); break;
case 174: encoding = TexMgr_FormatForName("ASTC_10X8"); break;
case 175: encoding = TexMgr_FormatForName("ASTC_10X8_SRGB"); break;
case 178: encoding = TexMgr_FormatForName("ASTC_10X10"); break;
case 179: encoding = TexMgr_FormatForName("ASTC_10X10_SRGB"); break;
case 182: encoding = TexMgr_FormatForName("ASTC_12X10"); break;
case 183: encoding = TexMgr_FormatForName("ASTC_12X10_SRGB"); break;
case 186: encoding = TexMgr_FormatForName("ASTC_12X12"); break;
case 187: encoding = TexMgr_FormatForName("ASTC_12X12_SRGB"); break;
default:
Con_Printf("Unsupported dds10 dxgi in %s - %u\n", fname, fmt10header.dxgiformat);
return NULL;
}
}
if (encoding == SRC_EXTERNAL) //used as an error code
{
Con_Printf("Unsupported encoding in %s - \"%c%c%c%c\"\n", fname,
((char*)&fmtheader.ddpfPixelFormat.dwFourCC)[0],
((char*)&fmtheader.ddpfPixelFormat.dwFourCC)[1],
((char*)&fmtheader.ddpfPixelFormat.dwFourCC)[2],
((char*)&fmtheader.ddpfPixelFormat.dwFourCC)[3]);
return NULL;
}
if ((fmtheader.ddsCaps[1] & 0x200) && (fmtheader.ddsCaps[1] & 0xfc00) != 0xfc00)
return NULL; //cubemap without all 6 faces defined.
if (fmtheader.ddsCaps[1] & 0x200)
{
if (fmt10header.arraysize % 6) //weird number of faces.
return NULL;
if (fmt10header.arraysize == 6)
{
//layers = 6;
return NULL; //don't try to load cubemaps.
}
else
{
//layers = fmt10header.arraysize;
return NULL; //don't try to load cubemap arrays.
}
}
else if (fmtheader.ddsCaps[1] & 0x200000)
{
if (fmt10header.arraysize != 1) //no 2d arrays
return NULL;
return NULL; //don't try to load 3d textures.
}
else
{
if (fmt10header.arraysize == 1)
; //yay, we can load 2d images.
else
return NULL; //don't try to load 2d arrays.
//layers = fmt10header.arraysize;
}
for (mipnum = 0; ; mipnum++)
{
int mipwidth = fmtheader.dwWidth >> mipnum;
int mipheight = fmtheader.dwHeight >> mipnum;
if (!mipwidth && !mipheight)
break;
mipwidth = q_max(1,mipwidth); //include the 1*1 mip with non-square textures.
mipheight = q_max(1,mipheight);
}
if (mipnum != nummips)
{
Con_Printf("%s: dds with incomplete mip chain\n", fname);
return NULL;
}
datasize = TexMgr_ImageSize(fmtheader.dwWidth, fmtheader.dwHeight, encoding);
if (!datasize)
return NULL; //werid/unsupported
//just read the mipchain into a new bit of memory and return that.
//note that layers and mips are awkward, but we don't support layers here so its just a densely packed pyramid.
ret = (byte *) Hunk_Alloc (datasize);
fread(ret, 1, datasize, f);
*width = fmtheader.dwWidth;
*height = fmtheader.dwHeight;
*fmt = encoding;
return ret;
}
/*spike -- end of dds loader*/
/*
============
Image_LoadImage
returns a pointer to hunk allocated RGBA data
returns a pointer to hunk allocated data. either RGBA8 or a compressed mip chain.
TODO: search order: tga png jpg pcx lmp
============
*/
byte *Image_LoadImage (const char *name, int *width, int *height, qboolean *malloced)
byte *Image_LoadImage (const char *name, int *width, int *height, enum srcformat *fmt, qboolean *malloced)
{
FILE *f;
char *prefixes[3] = {"", "textures/", "textures/"};
int i;
*malloced = false;
*fmt = SRC_RGBA;
for (i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); i++)
{
if (i == 2) //last resort...
name = COM_SkipPath(name);
q_snprintf (loadfilename, sizeof(loadfilename), "%s%s.dds", prefixes[i], name);
COM_FOpenFile (loadfilename, &f, NULL);
if (f)
return Image_LoadDDS (f, width, height, fmt);
q_snprintf (loadfilename, sizeof(loadfilename), "%s%s.tga", prefixes[i], name);
COM_FOpenFile (loadfilename, &f, NULL);
if (f)

View file

@ -28,7 +28,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//be sure to free the hunk after using these loading functions
byte *Image_LoadTGA (FILE *f, int *width, int *height);
byte *Image_LoadPCX (FILE *f, int *width, int *height);
byte *Image_LoadImage (const char *name, int *width, int *height, qboolean *malloced);
enum srcformat;
byte *Image_LoadImage (const char *name, int *width, int *height, enum srcformat *fmt, qboolean *malloced);
qboolean Image_WriteTGA (const char *name, byte *data, int width, int height, int bpp, qboolean upsidedown);
qboolean Image_WritePNG (const char *name, byte *data, int width, int height, int bpp, qboolean upsidedown);

View file

@ -1152,6 +1152,7 @@ static void P_LoadTexture(part_type_t *ptype, qboolean warn)
byte *data = NULL;
char filename[MAX_QPATH];
int fwidth=0, fheight=0;
enum srcformat fmt=SRC_RGBA;
int hunkmark;
char *texname = va("%s%s%s", ptype->texname, ptype->looks.premul?"_premul":"", ptype->looks.nearest?"_nearest":"");
qboolean malloced = false;
@ -1163,17 +1164,17 @@ static void P_LoadTexture(part_type_t *ptype, qboolean warn)
if (!data)
{
q_snprintf (filename, sizeof(filename), "textures/%s", ptype->texname);
data = Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = Image_LoadImage (filename, &fwidth, &fheight, &fmt, &malloced);
}
if (!data)
{
q_snprintf (filename, sizeof(filename), "%s", ptype->texname);
data = Image_LoadImage (filename, &fwidth, &fheight, &malloced);
data = Image_LoadImage (filename, &fwidth, &fheight, &fmt, &malloced);
}
if (data)
{
ptype->looks.texture = TexMgr_LoadImage(NULL, texname, fwidth, fheight, SRC_RGBA, data, filename, 0, (ptype->looks.premul?TEXPREF_PREMULTIPLY:0)|(ptype->looks.nearest?TEXPREF_NEAREST:TEXPREF_LINEAR)|TEXPREF_NOPICMIP|TEXPREF_ALPHA);
ptype->looks.texture = TexMgr_LoadImage(NULL, texname, fwidth, fheight, fmt, data, filename, 0, (ptype->looks.premul?TEXPREF_PREMULTIPLY:0)|(ptype->looks.nearest?TEXPREF_NEAREST:TEXPREF_LINEAR)|TEXPREF_NOPICMIP|TEXPREF_ALPHA);
}
if (malloced)
free(data);