[Glide64] Clean up GlideHQ/TxHiResCache.cpp
This commit is contained in:
parent
d8a35cbfba
commit
d6722faee6
|
@ -71,9 +71,9 @@ TxHiResCache::~TxHiResCache()
|
||||||
/* dump cache to disk */
|
/* dump cache to disk */
|
||||||
std::wstring filename = _ident + L"_HIRESTEXTURES.dat";
|
std::wstring filename = _ident + L"_HIRESTEXTURES.dat";
|
||||||
|
|
||||||
CPath cachepath(stdstr().FromUTF16(_path.c_str()).c_str(),"");
|
CPath cachepath(stdstr().FromUTF16(_path.c_str()).c_str(), "");
|
||||||
cachepath.AppendDirectory("cache");
|
cachepath.AppendDirectory("cache");
|
||||||
int config = _options & (HIRESTEXTURES_MASK|COMPRESS_HIRESTEX|COMPRESSION_MASK|TILE_HIRESTEX|FORCE16BPP_HIRESTEX|GZ_HIRESTEXCACHE|LET_TEXARTISTS_FLY);
|
int config = _options & (HIRESTEXTURES_MASK | COMPRESS_HIRESTEX | COMPRESSION_MASK | TILE_HIRESTEX | FORCE16BPP_HIRESTEX | GZ_HIRESTEXCACHE | LET_TEXARTISTS_FLY);
|
||||||
|
|
||||||
TxCache::save(stdstr((std::string &)cachepath).ToUTF16().c_str(), filename.c_str(), config);
|
TxCache::save(stdstr((std::string &)cachepath).ToUTF16().c_str(), filename.c_str(), config);
|
||||||
}
|
}
|
||||||
|
@ -113,9 +113,9 @@ TxHiResCache::TxHiResCache(int maxwidth, int maxheight, int maxbpp, int options,
|
||||||
if (_options & DUMP_HIRESTEXCACHE) {
|
if (_options & DUMP_HIRESTEXCACHE) {
|
||||||
/* find it on disk */
|
/* find it on disk */
|
||||||
std::wstring filename = _ident + L"_HIRESTEXTURES.dat";
|
std::wstring filename = _ident + L"_HIRESTEXTURES.dat";
|
||||||
CPath cachepath(stdstr().FromUTF16(_path.c_str()).c_str(),"");
|
CPath cachepath(stdstr().FromUTF16(_path.c_str()).c_str(), "");
|
||||||
cachepath.AppendDirectory("cache");
|
cachepath.AppendDirectory("cache");
|
||||||
int config = _options & (HIRESTEXTURES_MASK|COMPRESS_HIRESTEX|COMPRESSION_MASK|TILE_HIRESTEX|FORCE16BPP_HIRESTEX|GZ_HIRESTEXCACHE|LET_TEXARTISTS_FLY);
|
int config = _options & (HIRESTEXTURES_MASK | COMPRESS_HIRESTEX | COMPRESSION_MASK | TILE_HIRESTEX | FORCE16BPP_HIRESTEX | GZ_HIRESTEXCACHE | LET_TEXARTISTS_FLY);
|
||||||
|
|
||||||
_haveCache = TxCache::load(stdstr((std::string &)cachepath).ToUTF16().c_str(), filename.c_str(), config);
|
_haveCache = TxCache::load(stdstr((std::string &)cachepath).ToUTF16().c_str(), filename.c_str(), config);
|
||||||
}
|
}
|
||||||
|
@ -135,10 +135,9 @@ 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(), "");
|
||||||
|
|
||||||
switch (_options & HIRESTEXTURES_MASK) {
|
switch (_options & HIRESTEXTURES_MASK) {
|
||||||
case GHQ_HIRESTEXTURES:
|
case GHQ_HIRESTEXTURES:
|
||||||
|
@ -173,7 +172,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
DBG_INFO(80, L"-----\n");
|
DBG_INFO(80, L"-----\n");
|
||||||
DBG_INFO(80, L"path: %s\n", stdstr(dir_path).ToUTF16().c_str());
|
DBG_INFO(80, L"path: %s\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
|
|
||||||
CPath TextureDir(dir_path,"");
|
CPath TextureDir(dir_path, "");
|
||||||
|
|
||||||
/* find it on disk */
|
/* find it on disk */
|
||||||
if (!TextureDir.DirectoryExists())
|
if (!TextureDir.DirectoryExists())
|
||||||
|
@ -212,7 +211,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
uint8 *tex = NULL;
|
uint8 *tex = NULL;
|
||||||
int tmpwidth = 0, tmpheight = 0;
|
int tmpwidth = 0, tmpheight = 0;
|
||||||
uint16 tmpformat = 0;
|
uint16 tmpformat = 0;
|
||||||
uint8 *tmptex= NULL;
|
uint8 *tmptex = NULL;
|
||||||
int untiled_width = 0, untiled_height = 0;
|
int untiled_width = 0, untiled_height = 0;
|
||||||
uint16 destformat = 0;
|
uint16 destformat = 0;
|
||||||
|
|
||||||
|
@ -236,8 +235,8 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
ident.assign(fname);
|
ident.assign(fname);
|
||||||
|
|
||||||
/* read in Rice's file naming convention */
|
/* read in Rice's file naming convention */
|
||||||
#define CRCFMTSIZ_LEN 13
|
#define CRCFMTSIZ_LEN 13
|
||||||
#define PALCRC_LEN 9
|
#define PALCRC_LEN 9
|
||||||
wcstombs(fname, stdstr(TextureDir.GetNameExtension()).ToUTF16().c_str(), MAX_PATH);
|
wcstombs(fname, stdstr(TextureDir.GetNameExtension()).ToUTF16().c_str(), MAX_PATH);
|
||||||
/* XXX case sensitivity fiasco!
|
/* XXX case sensitivity fiasco!
|
||||||
* files must use _a, _rgb, _all, _allciByRGBA, _ciByRGBA, _ci
|
* files must use _a, _rgb, _all, _allciByRGBA, _ciByRGBA, _ci
|
||||||
|
@ -253,11 +252,11 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
pfname == strstr(fname, ".bmp") ||
|
pfname == strstr(fname, ".bmp") ||
|
||||||
pfname == strstr(fname, ".dds")))
|
pfname == strstr(fname, ".dds")))
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
INFO(80, L"-----\n");
|
INFO(80, L"-----\n");
|
||||||
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
||||||
#endif
|
#endif
|
||||||
INFO(80, L"Error: not png or bmp or dds!\n");
|
INFO(80, L"Error: not png or bmp or dds!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -272,20 +271,20 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
pfname = 0;
|
pfname = 0;
|
||||||
}
|
}
|
||||||
if (!pfname) {
|
if (!pfname) {
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
INFO(80, L"-----\n");
|
INFO(80, L"-----\n");
|
||||||
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
||||||
#endif
|
#endif
|
||||||
INFO(80, L"Error: not Rice texture naming convention!\n");
|
INFO(80, L"Error: not Rice texture naming convention!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!chksum) {
|
if (!chksum) {
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
INFO(80, L"-----\n");
|
INFO(80, L"-----\n");
|
||||||
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
||||||
#endif
|
#endif
|
||||||
INFO(80, L"Error: crc32 = 0!\n");
|
INFO(80, L"Error: crc32 = 0!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -296,11 +295,11 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
chksum64 <<= 32;
|
chksum64 <<= 32;
|
||||||
chksum64 |= (uint64)chksum;
|
chksum64 |= (uint64)chksum;
|
||||||
if (TxCache::is_cached(chksum64)) {
|
if (TxCache::is_cached(chksum64)) {
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
INFO(80, L"-----\n");
|
INFO(80, L"-----\n");
|
||||||
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
||||||
#endif
|
#endif
|
||||||
INFO(80, L"Error: already cached! duplicate texture!\n");
|
INFO(80, L"Error: already cached! duplicate texture!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -329,25 +328,25 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
*/
|
*/
|
||||||
if (pfname == strstr(fname, "_rgb.") || pfname == strstr(fname, "_a.")) {
|
if (pfname == strstr(fname, "_rgb.") || pfname == strstr(fname, "_a.")) {
|
||||||
strcpy(pfname, "_rgb.png");
|
strcpy(pfname, "_rgb.png");
|
||||||
CPath TargetFile(dir_path,fname);
|
CPath TargetFile(dir_path, fname);
|
||||||
if (!TargetFile.Exists())
|
if (!TargetFile.Exists())
|
||||||
{
|
{
|
||||||
strcpy(pfname, "_rgb.bmp");
|
strcpy(pfname, "_rgb.bmp");
|
||||||
TargetFile = CPath(dir_path,fname);
|
TargetFile = CPath(dir_path, fname);
|
||||||
if (!TargetFile.Exists())
|
if (!TargetFile.Exists())
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
INFO(80, L"-----\n");
|
INFO(80, L"-----\n");
|
||||||
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
|
||||||
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
|
||||||
#endif
|
#endif
|
||||||
INFO(80, L"Error: missing _rgb.*! _a.* must be paired with _rgb.*!\n");
|
INFO(80, L"Error: missing _rgb.*! _a.* must be paired with _rgb.*!\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* _a.png */
|
/* _a.png */
|
||||||
strcpy(pfname, "_a.png");
|
strcpy(pfname, "_a.png");
|
||||||
TargetFile = CPath(dir_path,fname);
|
TargetFile = CPath(dir_path, fname);
|
||||||
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
||||||
tmptex = _txImage->readPNG(fp, &tmpwidth, &tmpheight, &tmpformat);
|
tmptex = _txImage->readPNG(fp, &tmpwidth, &tmpheight, &tmpformat);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -355,7 +354,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
if (!tmptex) {
|
if (!tmptex) {
|
||||||
/* _a.bmp */
|
/* _a.bmp */
|
||||||
strcpy(pfname, "_a.bmp");
|
strcpy(pfname, "_a.bmp");
|
||||||
TargetFile = CPath(dir_path,fname);
|
TargetFile = CPath(dir_path, fname);
|
||||||
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
||||||
tmptex = _txImage->readBMP(fp, &tmpwidth, &tmpheight, &tmpformat);
|
tmptex = _txImage->readBMP(fp, &tmpwidth, &tmpheight, &tmpformat);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -363,7 +362,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
}
|
}
|
||||||
/* _rgb.png */
|
/* _rgb.png */
|
||||||
strcpy(pfname, "_rgb.png");
|
strcpy(pfname, "_rgb.png");
|
||||||
TargetFile = CPath(dir_path,fname);
|
TargetFile = CPath(dir_path, fname);
|
||||||
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
||||||
tex = _txImage->readPNG(fp, &width, &height, &format);
|
tex = _txImage->readPNG(fp, &width, &height, &format);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -371,7 +370,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
if (!tex) {
|
if (!tex) {
|
||||||
/* _rgb.bmp */
|
/* _rgb.bmp */
|
||||||
strcpy(pfname, "_rgb.bmp");
|
strcpy(pfname, "_rgb.bmp");
|
||||||
TargetFile = CPath(dir_path,fname);
|
TargetFile = CPath(dir_path, fname);
|
||||||
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
||||||
tex = _txImage->readBMP(fp, &width, &height, &format);
|
tex = _txImage->readBMP(fp, &width, &height, &format);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
@ -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
|
||||||
|
@ -465,7 +468,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
pfname == strstr(fname, "_ciByRGBA.dds") ||
|
pfname == strstr(fname, "_ciByRGBA.dds") ||
|
||||||
#endif
|
#endif
|
||||||
pfname == strstr(fname, "_ci.bmp")) {
|
pfname == strstr(fname, "_ci.bmp")) {
|
||||||
CPath TargetFile(dir_path,fname);
|
CPath TargetFile(dir_path, fname);
|
||||||
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
if ((fp = fopen(TargetFile, "rb")) != NULL) {
|
||||||
if (strstr(fname, ".png")) tex = _txImage->readPNG(fp, &width, &height, &format);
|
if (strstr(fname, ".png")) tex = _txImage->readPNG(fp, &width, &height, &format);
|
||||||
else if (strstr(fname, ".dds")) tex = _txImage->readDDS(fp, &width, &height, &format);
|
else if (strstr(fname, ".dds")) tex = _txImage->readDDS(fp, &width, &height, &format);
|
||||||
|
@ -474,7 +477,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
}
|
}
|
||||||
/* XXX: auto-adjustment of dxt dds textures unsupported for now */
|
/* XXX: auto-adjustment of dxt dds textures unsupported for now */
|
||||||
if (tex && strstr(fname, ".dds")) {
|
if (tex && strstr(fname, ".dds")) {
|
||||||
const float aspectratio = (width > height) ? (float)width/(float)height : (float)height/(float)width;
|
const float aspectratio = (width > height) ? (float)width / (float)height : (float)height / (float)width;
|
||||||
if (!(aspectratio == 1.0 ||
|
if (!(aspectratio == 1.0 ||
|
||||||
aspectratio == 2.0 ||
|
aspectratio == 2.0 ||
|
||||||
aspectratio == 4.0 ||
|
aspectratio == 4.0 ||
|
||||||
|
@ -585,15 +588,16 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
if ((tmptexel[k] & 0xff000000) == 0xff000000) {
|
if ((tmptexel[k] & 0xff000000) == 0xff000000) {
|
||||||
r += ((tmptexel[k] & 0x00ff0000) >> 16);
|
r += ((tmptexel[k] & 0x00ff0000) >> 16);
|
||||||
g += ((tmptexel[k] & 0x0000ff00) >> 8);
|
g += ((tmptexel[k] & 0x0000ff00) >> 8);
|
||||||
b += ((tmptexel[k] & 0x000000ff) );
|
b += ((tmptexel[k] & 0x000000ff));
|
||||||
numtexel++;
|
numtexel++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (numtexel) {
|
if (numtexel) {
|
||||||
((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
|
||||||
|
@ -625,7 +631,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
if (intensity) {
|
if (intensity) {
|
||||||
int rcomp = (texel >> 16) & 0xff;
|
int rcomp = (texel >> 16) & 0xff;
|
||||||
int gcomp = (texel >> 8) & 0xff;
|
int gcomp = (texel >> 8) & 0xff;
|
||||||
int bcomp = (texel ) & 0xff;
|
int bcomp = (texel)& 0xff;
|
||||||
#if AGGRESSIVE_QUANTIZATION
|
#if AGGRESSIVE_QUANTIZATION
|
||||||
if (abs(rcomp - gcomp) > 8 || abs(rcomp - bcomp) > 8 || abs(gcomp - bcomp) > 8) intensity = 0;
|
if (abs(rcomp - gcomp) > 8 || abs(rcomp - bcomp) > 8 || abs(gcomp - bcomp) > 8) intensity = 0;
|
||||||
#else
|
#else
|
||||||
|
@ -638,13 +644,14 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
|
|
||||||
/* preparations based on above analysis */
|
/* preparations based on above analysis */
|
||||||
#if !REDUCE_TEXTURE_FOOTPRINT
|
#if !REDUCE_TEXTURE_FOOTPRINT
|
||||||
if (_maxbpp < 32 || _options & (FORCE16BPP_HIRESTEX|COMPRESSION_MASK)) {
|
if (_maxbpp < 32 || _options & (FORCE16BPP_HIRESTEX | COMPRESSION_MASK)) {
|
||||||
#endif
|
#endif
|
||||||
if (alphabits == 0) destformat = GR_TEXFMT_RGB_565;
|
if (alphabits == 0) destformat = GR_TEXFMT_RGB_565;
|
||||||
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
|
||||||
|
@ -655,7 +662,7 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
uint32 texel = ((uint32*)tex)[i];
|
uint32 texel = ((uint32*)tex)[i];
|
||||||
uint32 icomp = (((texel >> 16) & 0xff) +
|
uint32 icomp = (((texel >> 16) & 0xff) +
|
||||||
((texel >> 8) & 0xff) +
|
((texel >> 8) & 0xff) +
|
||||||
((texel ) & 0xff)) / 3;
|
((texel)& 0xff)) / 3;
|
||||||
((uint32*)tex)[i] = (icomp << 24) | (texel & 0x00ffffff);
|
((uint32*)tex)[i] = (icomp << 24) | (texel & 0x00ffffff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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];
|
||||||
}
|
}
|
||||||
|
@ -855,10 +862,10 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
#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) */
|
||||||
if (!_txReSample->nextPow2(&tex, &width , &height, 32, 1)) {
|
if (!_txReSample->nextPow2(&tex, &width, &height, 32, 1)) {
|
||||||
#else
|
#else
|
||||||
/* normal pow2 expansion */
|
/* normal pow2 expansion */
|
||||||
if (!_txReSample->nextPow2(&tex, &width , &height, 32, 0)) {
|
if (!_txReSample->nextPow2(&tex, &width, &height, 32, 0)) {
|
||||||
#endif
|
#endif
|
||||||
free(tex);
|
free(tex);
|
||||||
tex = NULL;
|
tex = NULL;
|
||||||
|
@ -928,21 +935,21 @@ 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) */
|
||||||
if (!_txReSample->nextPow2(&tex, &width , &height, 32, 1)) {
|
if (!_txReSample->nextPow2(&tex, &width, &height, 32, 1)) {
|
||||||
#else
|
#else
|
||||||
/* normal pow2 expansion */
|
/* normal pow2 expansion */
|
||||||
if (!_txReSample->nextPow2(&tex, &width , &height, 32, 0)) {
|
if (!_txReSample->nextPow2(&tex, &width, &height, 32, 0)) {
|
||||||
#endif
|
#endif
|
||||||
free(tex);
|
free(tex);
|
||||||
tex = NULL;
|
tex = NULL;
|
||||||
|
@ -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;
|
||||||
|
@ -1057,14 +1063,13 @@ boolean TxHiResCache::loadHiResTextures(LPCSTR dir_path, boolean replace)
|
||||||
if (_callback) {
|
if (_callback) {
|
||||||
wchar_t tmpbuf[MAX_PATH];
|
wchar_t tmpbuf[MAX_PATH];
|
||||||
mbstowcs(tmpbuf, fname, MAX_PATH);
|
mbstowcs(tmpbuf, fname, MAX_PATH);
|
||||||
(*_callback)(L"[%d] total mem:%.2fmb - %ls\n", _cache.size(), (float)_totalSize/1000000, tmpbuf);
|
(*_callback)(L"[%d] total mem:%.2fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, tmpbuf);
|
||||||
}
|
}
|
||||||
DBG_INFO(80, L"texture loaded!\n");
|
DBG_INFO(80, L"texture loaded!\n");
|
||||||
}
|
}
|
||||||
free(tex);
|
free(tex);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (TextureDir.FindNext());
|
} while (TextureDir.FindNext());
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
Loading…
Reference in New Issue