[Glide64] Clean up GlideHQ/TxHiResCache.cpp

This commit is contained in:
zilmar 2016-02-05 04:35:02 +11:00
parent d8a35cbfba
commit d6722faee6
1 changed files with 888 additions and 883 deletions

View File

@ -135,7 +135,6 @@ boolean
TxHiResCache::load(boolean replace) /* 0 : reload, 1 : replace partial */ TxHiResCache::load(boolean replace) /* 0 : reload, 1 : replace partial */
{ {
if (!_path.empty() && !_ident.empty()) { if (!_path.empty() && !_ident.empty()) {
if (!replace) TxCache::clear(); if (!replace) TxCache::clear();
CPath dir_path(stdstr().FromUTF16(_path.c_str()).c_str(), ""); CPath dir_path(stdstr().FromUTF16(_path.c_str()).c_str(), "");
@ -388,9 +387,11 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
#endif #endif
if (!tex) { if (!tex) {
INFO(80, L"Error: missing _rgb.*!\n"); INFO(80, L"Error: missing _rgb.*!\n");
} else if (width != tmpwidth || height != tmpheight) { }
else if (width != tmpwidth || height != tmpheight) {
INFO(80, L"Error: _rgb.* and _a.* have mismatched width or height!\n"); INFO(80, L"Error: _rgb.* and _a.* have mismatched width or height!\n");
} else if (format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) { }
else if (format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) {
INFO(80, L"Error: _rgb.* or _a.* not in 32bit color!\n"); INFO(80, L"Error: _rgb.* or _a.* not in 32bit color!\n");
} }
if (tex) free(tex); if (tex) free(tex);
@ -431,7 +432,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
} }
free(tmptex); free(tmptex);
tmptex = NULL; tmptex = NULL;
} else { }
else {
/* clobber A comp. never a question of alpha. only RGB used. */ /* clobber A comp. never a question of alpha. only RGB used. */
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, L"-----\n");
@ -445,7 +447,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
} }
} }
} }
} else }
else
/* /*
* read in _all.png, _all.dds, _allciByRGBA.png, _allciByRGBA.dds * read in _all.png, _all.dds, _allciByRGBA.png, _allciByRGBA.dds
@ -593,7 +596,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
((uint32*)tex)[i * width + j] = ((r / numtexel) << 16) | ((uint32*)tex)[i * width + j] = ((r / numtexel) << 16) |
((g / numtexel) << 8) | ((g / numtexel) << 8) |
((b / numtexel)); ((b / numtexel));
} else { }
else {
((uint32*)tex)[i * width + j] = texel & 0x00ffffff; ((uint32*)tex)[i * width + j] = texel & 0x00ffffff;
} }
} }
@ -610,14 +614,16 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
if ((texel & 0xff000000) < 0x00000003) { if ((texel & 0xff000000) < 0x00000003) {
alphabits = 1; alphabits = 1;
fullalpha++; fullalpha++;
} else if ((texel & 0xff000000) < 0xfe000000) { }
else if ((texel & 0xff000000) < 0xfe000000) {
alphabits = 8; alphabits = 8;
} }
#else #else
if ((texel & 0xff000000) == 0x00000000) { if ((texel & 0xff000000) == 0x00000000) {
alphabits = 1; alphabits = 1;
fullalpha++; fullalpha++;
} else if ((texel & 0xff000000) != 0xff000000) { }
else if ((texel & 0xff000000) != 0xff000000) {
alphabits = 8; alphabits = 8;
} }
#endif #endif
@ -644,7 +650,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
else if (alphabits == 1) destformat = GR_TEXFMT_ARGB_1555; else if (alphabits == 1) destformat = GR_TEXFMT_ARGB_1555;
else destformat = GR_TEXFMT_ARGB_8888; else destformat = GR_TEXFMT_ARGB_8888;
#if !REDUCE_TEXTURE_FOOTPRINT #if !REDUCE_TEXTURE_FOOTPRINT
} else { }
else {
destformat = GR_TEXFMT_ARGB_8888; destformat = GR_TEXFMT_ARGB_8888;
} }
#endif #endif
@ -663,7 +670,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
if (alphabits == 0) { if (alphabits == 0) {
if (fmt == 4) destformat = GR_TEXFMT_ALPHA_8; if (fmt == 4) destformat = GR_TEXFMT_ALPHA_8;
else destformat = GR_TEXFMT_INTENSITY_8; else destformat = GR_TEXFMT_INTENSITY_8;
} else { }
else {
destformat = GR_TEXFMT_ALPHA_INTENSITY_88; destformat = GR_TEXFMT_ALPHA_INTENSITY_88;
} }
} }
@ -673,10 +681,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
/* /*
* Rice hi-res textures: end */ * Rice hi-res textures: end */
/* XXX: only ARGB8888 for now. comeback to this later... */ /* XXX: only ARGB8888 for now. comeback to this later... */
if (format == GR_TEXFMT_ARGB_8888) { if (format == GR_TEXFMT_ARGB_8888) {
#if TEXTURE_TILING #if TEXTURE_TILING
/* Glide64 style texture tiling */ /* Glide64 style texture tiling */
@ -708,7 +714,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
DBG_INFO(80, L"width > 256, minification ratio:%d %d x %d -> %d x %d\n", DBG_INFO(80, L"width > 256, minification ratio:%d %d x %d -> %d x %d\n",
ratio, width, height, width / ratio, height / ratio); ratio, width, height, width / ratio, height / ratio);
} }
} else { }
else {
/* normal minification to fit max texture size */ /* normal minification to fit max texture size */
if (width > _maxwidth || height > _maxheight) { if (width > _maxwidth || height > _maxheight) {
DBG_INFO(80, L"determine minification ratio to fit max texture size\n"); DBG_INFO(80, L"determine minification ratio to fit max texture size\n");
@ -745,7 +752,6 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
/* to tile or not to tile, that is the question */ /* to tile or not to tile, that is the question */
if (width > 256 && height <= 128 && (((width - 1) >> 8) + 1) * height <= 256) { if (width > 256 && height <= 128 && (((width - 1) >> 8) + 1) * height <= 256) {
if (width > _maxwidth) usetile = 1; if (width > _maxwidth) usetile = 1;
else { else {
/* tile if the tiled texture memory footprint is smaller */ /* tile if the tiled texture memory footprint is smaller */
@ -772,13 +778,13 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
/* 3dfx Glide3 tmpheight, W:H aspect ratio range (8:1 - 1:8) */ /* 3dfx Glide3 tmpheight, W:H aspect ratio range (8:1 - 1:8) */
if (tmpwidth > tmpheight) { if (tmpwidth > tmpheight) {
if (tmpwidth > (tmpheight << 3)) tmpheight = tmpwidth >> 3; if (tmpwidth > (tmpheight << 3)) tmpheight = tmpwidth >> 3;
} else { }
else {
if (tmpheight > (tmpwidth << 3)) tmpwidth = tmpheight >> 3; if (tmpheight > (tmpwidth << 3)) tmpwidth = tmpheight >> 3;
} }
usetile = (tilewidth * tileheight < tmpwidth * tmpheight); usetile = (tilewidth * tileheight < tmpwidth * tmpheight);
} }
} }
/* tile it! do the actual tiling into 256x256 size */ /* tile it! do the actual tiling into 256x256 size */
@ -794,7 +800,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
for (y = 0; y < height; y++) { for (y = 0; y < height; y++) {
if (x < ratio - 1) { if (x < ratio - 1) {
memcpy(&tmptex[offset << 2], &tex[(x * 256 + y * width) << 2], 256 << 2); memcpy(&tmptex[offset << 2], &tex[(x * 256 + y * width) << 2], 256 << 2);
} else { }
else {
for (z = 0; z < width - 256 * (ratio - 1); z++) { for (z = 0; z < width - 256 * (ratio - 1); z++) {
((uint32*)tmptex)[offset + z] = ((uint32*)tex)[x * 256 + y * width + z]; ((uint32*)tmptex)[offset + z] = ((uint32*)tex)[x * 256 + y * width + z];
} }
@ -928,14 +935,14 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
width = tmpwidth; width = tmpwidth;
height = tmpheight; height = tmpheight;
format = destformat = tmpformat; format = destformat = tmpformat;
} else { }
else {
free(tmptex); free(tmptex);
} }
} }
} }
}
} else { else {
#if POW2_TEXTURES #if POW2_TEXTURES
#if (POW2_TEXTURES == 2) #if (POW2_TEXTURES == 2)
/* 3dfx Glide3x aspect ratio (8:1 - 1:8) */ /* 3dfx Glide3x aspect ratio (8:1 - 1:8) */
@ -997,10 +1004,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
} }
} }
} }
} }
/* last minute validations */ /* last minute validations */
if (!tex || !chksum || !width || !height || !format || width > _maxwidth || height > _maxheight) { if (!tex || !chksum || !width || !height || !format || width > _maxwidth || height > _maxheight) {
#if !DEBUG #if !DEBUG
@ -1012,7 +1017,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
free(tex); free(tex);
tex = NULL; tex = NULL;
INFO(80, L"Error: bad format or size! %d x %d gfmt:%x\n", width, height, format); INFO(80, L"Error: bad format or size! %d x %d gfmt:%x\n", width, height, format);
} else { }
else {
INFO(80, L"Error: load failed!!\n"); INFO(80, L"Error: load failed!!\n");
} }
continue; continue;
@ -1063,7 +1069,6 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
} }
free(tex); free(tex);
} }
} while (TextureDir.FindNext()); } while (TextureDir.FindNext());
} }
return 1; return 1;