Name some texture symbols, mostly relating to LODs

This commit is contained in:
Ryan Dwyer committed 2023-08-26 12:20:04 +10:00
1 parent 38345c1672
commit 79a94b29ce
7 files changed
+147 -147

No files matched your search

+36 -36
View File
@@ -268,7 +268,7 @@ s32 texGetWidthAtLod(struct tex *tex, s32 lod)
return width; return width;
} }
if (tex->unk0c_02) { if (tex->hasloddata) {
for (i = 0; i < g_TexCacheCount; i++) { for (i = 0; i < g_TexCacheCount; i++) {
if (tex->texturenum == g_TexCacheItems[i].texturenum) { if (tex->texturenum == g_TexCacheItems[i].texturenum) {
return g_TexCacheItems[i].widths[lod - 1]; return g_TexCacheItems[i].widths[lod - 1];
@@ -294,7 +294,7 @@ s32 texGetHeightAtLod(struct tex *tex, s32 lod)
return height; return height;
} }
if (tex->unk0c_02) { if (tex->hasloddata) {
for (i = 0; i < g_TexCacheCount; i++) { for (i = 0; i < g_TexCacheCount; i++) {
if (tex->texturenum == g_TexCacheItems[i].texturenum) { if (tex->texturenum == g_TexCacheItems[i].texturenum) {
return g_TexCacheItems[i].heights[lod - 1]; return g_TexCacheItems[i].heights[lod - 1];
@@ -339,7 +339,7 @@ s32 texGetSizeInBytes(struct tex *tex, s32 lod)
void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg) void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg)
{ {
s32 depth = tex->depth; s32 depth = tex->depth;
s32 maxlod = tex->maxlod ? tex->maxlod : 1; s32 numlods = tex->numlods ? tex->numlods : 1;
s32 lod; s32 lod;
*lenarg = 0; *lenarg = 0;
@@ -354,7 +354,7 @@ void tex0f173e50(struct tex *tex, s32 *deptharg, s32 *lenarg)
*deptharg = G_IM_SIZ_16b; *deptharg = G_IM_SIZ_16b;
} }
for (lod = 0; lod < maxlod; lod++) { for (lod = 0; lod < numlods; lod++) {
*lenarg += texGetSizeInBytes(tex, lod) * 4; *lenarg += texGetSizeInBytes(tex, lod) * 4;
} }
} }
@@ -415,10 +415,10 @@ Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s3
tex0f173f48(0), sp88 - s0->unk04_08, shifts); tex0f173f48(0), sp88 - s0->unk04_08, shifts);
} }
uls = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + 0; uls = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0;
ult = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + 0; ult = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + 0;
lrs = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + ((tex->width - 1) << 2); lrs = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->width - 1) << 2);
lrt = (arg2 == 2 && !tex->unk0c_02 ? 2 : 0) + ((tex->height - 1) << 2); lrt = (arg2 == 2 && !tex->hasloddata ? 2 : 0) + ((tex->height - 1) << 2);
if (tex0f173b8c(0, uls, ult, lrs, lrt)) { if (tex0f173b8c(0, uls, ult, lrs, lrt)) {
gDPSetTileSize(gdl++, 0, uls, ult, lrs, lrt); gDPSetTileSize(gdl++, 0, uls, ult, lrs, lrt);
@@ -429,7 +429,7 @@ Gfx *tex0f173f78(Gfx *gdl, struct tex *tex, s32 arg2, s32 shifts, s32 shiftt, s3
Gfx *tex0f1742e4(Gfx *arg0, Gfx *arg1, struct tex *tex, bool arg3) Gfx *tex0f1742e4(Gfx *arg0, Gfx *arg1, struct tex *tex, bool arg3)
{ {
s32 lod = tex->maxlod ? tex->maxlod - 1 : 0; s32 lod = tex->numlods ? tex->numlods - 1 : 0;
if (arg3) { if (arg3) {
if (arg1 != NULL) { if (arg1 != NULL) {
@@ -518,17 +518,17 @@ Gfx *tex0f1743a0(Gfx *gdl, struct tex *tex, s32 arg2)
Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, u32 arg7) Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s32 arg6, u32 arg7)
{ {
u32 tmem; u32 tmem;
s32 maxlod; s32 numlods;
s32 tile; s32 tile;
tmem = arg7; tmem = arg7;
maxlod = tex->maxlod; numlods = tex->numlods;
if (arg6 >= 0 && arg6 < maxlod) { if (arg6 >= 0 && arg6 < numlods) {
maxlod = arg6; numlods = arg6;
} }
for (tile = arg5; tile < maxlod + arg5 && tile < 6; tile++) { for (tile = arg5; tile < numlods + arg5 && tile < 6; tile++) {
s32 stack[2]; s32 stack[2];
s32 lod = tile - arg5; s32 lod = tile - arg5;
u32 masks = tex0f173f18(texGetWidthAtLod(tex, lod)); u32 masks = tex0f173f18(texGetWidthAtLod(tex, lod));
@@ -539,7 +539,7 @@ Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar
s32 lrs; s32 lrs;
s32 lrt; s32 lrt;
s32 bytes = texGetSizeInBytes(tex, lod); s32 bytes = texGetSizeInBytes(tex, lod);
s32 sp7c = tex->unk0c_02; bool hasloddata = tex->hasloddata;
if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) {
gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT);
@@ -551,10 +551,10 @@ Gfx *tex0f1747a4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar
tex0f173f48(arg2), masks, tile - arg5); tex0f173f48(arg2), masks, tile - arg5);
} }
uls = (arg4 == 2 && sp7c == 0 ? 2 : 0) + 0; uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0;
ult = (arg4 == 2 && sp7c == 0 ? 2 : 0) + 0; ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0;
lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && sp7c == 0 ? 2 : 0); lrs = ((texGetWidthAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0);
lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && sp7c == 0 ? 2 : 0); lrt = ((texGetHeightAtLod(tex, lod) - 1) << 2) + (arg4 == 2 && hasloddata == false ? 2 : 0);
if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { if (tex0f173b8c(tile, uls, ult, lrs, lrt)) {
gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt);
@@ -635,12 +635,12 @@ Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ti
s32 ult; s32 ult;
s32 lrs; s32 lrs;
s32 lrt; s32 lrt;
s32 sp50; bool hasloddata;
masks = tex0f173f18(tex->width); masks = tex0f173f18(tex->width);
maskt = tex0f173f18(tex->height); maskt = tex0f173f18(tex->height);
line = texGetLineSizeInBytes(tex, 0); line = texGetLineSizeInBytes(tex, 0);
sp50 = tex->unk0c_02; hasloddata = tex->hasloddata;
if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) { if (texSetLutMode(tex->lutmodeindex << G_MDSFT_TEXTLUT)) {
gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT); gDPSetTextureLUT(gdl++, tex->lutmodeindex << G_MDSFT_TEXTLUT);
@@ -652,10 +652,10 @@ Gfx *tex0f174f30(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ti
tex0f173f48(arg2), masks, G_TX_NOLOD); tex0f173f48(arg2), masks, G_TX_NOLOD);
} }
uls = (arg4 == 2 && sp50 == 0 ? 2 : 0) + 0; uls = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0;
ult = (arg4 == 2 && sp50 == 0 ? 2 : 0) + 0; ult = (arg4 == 2 && hasloddata == false ? 2 : 0) + 0;
lrs = (arg4 == 2 && sp50 == 0 ? 2 : 0) + ((tex->width - 1) << 2); lrs = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->width - 1) << 2);
lrt = (arg4 == 2 && sp50 == 0 ? 2 : 0) + ((tex->height - 1) << 2); lrt = (arg4 == 2 && hasloddata == false ? 2 : 0) + ((tex->height - 1) << 2);
if (tex0f173b8c(tile, uls, ult, lrs, lrt)) { if (tex0f173b8c(tile, uls, ult, lrs, lrt)) {
gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt); gDPSetTileSize(gdl++, tile, uls, ult, lrs, lrt);
@@ -677,9 +677,9 @@ Gfx *tex0f1751e4(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar
gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0);
sp34 += tex->maxlod; sp34 += tex->numlods;
if (!arg5 && tex->maxlod == 1) { if (!arg5 && tex->numlods == 1) {
gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0);
} }
@@ -711,9 +711,9 @@ Gfx *tex0f175308(Gfx *gdl, struct tex *tex1, s32 arg2, s32 arg3, s32 arg4, struc
gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size);
sp38 += tex1->maxlod; sp38 += tex1->numlods;
if (!arg9 && tex1->maxlod == 1) { if (!arg9 && tex1->numlods == 1) {
gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size); gdl = tex0f1747a4(gdl, tex1, arg2, arg3, arg4, sp38, -1, size);
} }
@@ -740,9 +740,9 @@ Gfx *tex0f175490(Gfx *gdl, struct tex *tex, s32 arg2, s32 arg3, s32 arg4, s32 ar
gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0);
sp34 += tex->maxlod; sp34 += tex->numlods;
if (!arg8 && tex->maxlod == 1) { if (!arg8 && tex->numlods == 1) {
gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0); gdl = tex0f1747a4(gdl, tex, arg2, arg3, arg4, sp34, -1, 0);
} }
@@ -1111,13 +1111,13 @@ s32 texLoadFromGdl(Gfx *arg0, s32 gdlsizeinbytes, Gfx *arg2, struct texpool *poo
return (uintptr_t) s6 - (uintptr_t) arg2; return (uintptr_t) s6 - (uintptr_t) arg2;
} }
void texCopyGdls(Gfx *src, Gfx *dst, s32 arg2) void texCopyGdls(Gfx *src, Gfx *dst, s32 count)
{ {
arg2 = (arg2 >> 3); count = (count >> 3);
src = src + (arg2 - 1); src = src + (count - 1);
dst = dst + (arg2 - 1); dst = dst + (count - 1);
while (arg2--) { while (count--) {
dst->force_structure_alignment = src->force_structure_alignment; dst->force_structure_alignment = src->force_structure_alignment;
dst--; dst--;
src--; src--;
+89 -88
View File
@@ -17,9 +17,9 @@ struct texpool g_TexSharedPool;
struct texcacheitem g_TexCacheItems[150]; struct texcacheitem g_TexCacheItems[150];
s32 g_TexCacheCount; s32 g_TexCacheCount;
s32 g_TexNumToLoad; s32 g_TexNumToLoad;
u8 *var800ab540; u8 *g_TexBitstring;
u32 var800ab544; u32 g_TexAccumValue;
s32 var800ab548; s32 g_TexAccumNumBits;
u32 var800ab54c; u32 var800ab54c;
u32 g_TexBase; u32 g_TexBase;
u8 *g_TextureConfigSegment; u8 *g_TextureConfigSegment;
@@ -141,7 +141,7 @@ void func0f16e810(u32 arg0)
* *
* The zlib data is prefixed with the standard 5-byte rarezip header. * The zlib data is prefixed with the standard 5-byte rarezip header.
*/ */
s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5) s32 texInflateZlib(u8 *src, u8 *dst, bool hasloddata, s32 numlods, struct texpool *pool, bool unusedarg)
{ {
s32 i; s32 i;
s32 imagebytesout; s32 imagebytesout;
@@ -153,9 +153,9 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
s32 width; s32 width;
s32 height; s32 height;
s32 numcolours; s32 numcolours;
u8 *end; u8 *loddst;
u8 *start; u8 *lodsrc;
s32 j; s32 lod;
u8 scratch2[0x800]; u8 scratch2[0x800];
u16 palette[256]; u16 palette[256];
u8 scratch[5120]; u8 scratch[5120];
@@ -165,16 +165,16 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
texSetBitstring(src); texSetBitstring(src);
if (arg2 && forcenumimages) { if (hasloddata && numlods) {
numimages = forcenumimages; numimages = numlods;
} else { } else {
numimages = 1; numimages = 1;
} }
pool->rightpos->maxlod = forcenumimages; pool->rightpos->numlods = numlods;
pool->rightpos->unk0c_02 = arg2; pool->rightpos->hasloddata = hasloddata;
if (arg2) { if (hasloddata) {
writetocache = true; writetocache = true;
for (i = 0; i < g_TexCacheCount; i++) { for (i = 0; i < g_TexCacheCount; i++) {
@@ -193,11 +193,11 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
foundthething = false; foundthething = false;
for (j = 0; j < numimages; j++) { for (lod = 0; lod < numimages; lod++) {
width = texReadBits(8); width = texReadBits(8);
height = texReadBits(8); height = texReadBits(8);
if (j == 0) { if (lod == 0) {
pool->rightpos->width = width; pool->rightpos->width = width;
pool->rightpos->height = height; pool->rightpos->height = height;
pool->rightpos->unk0a = numcolours - 1; pool->rightpos->unk0a = numcolours - 1;
@@ -205,19 +205,19 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
pool->rightpos->depth = g_TexFormatDepths[format]; pool->rightpos->depth = g_TexFormatDepths[format];
pool->rightpos->lutmodeindex = g_TexFormatLutModes[format] >> G_MDSFT_TEXTLUT; pool->rightpos->lutmodeindex = g_TexFormatLutModes[format] >> G_MDSFT_TEXTLUT;
} else if (writetocache) { } else if (writetocache) {
g_TexCacheItems[g_TexCacheCount].widths[j - 1] = width; g_TexCacheItems[g_TexCacheCount].widths[lod - 1] = width;
g_TexCacheItems[g_TexCacheCount].heights[j - 1] = height; g_TexCacheItems[g_TexCacheCount].heights[lod - 1] = height;
} }
if (rzipInflate(var800ab540, scratch2, scratch) == 0) { if (rzipInflate(g_TexBitstring, scratch2, scratch) == 0) {
#if VERSION < VERSION_NTSC_1_0 #if VERSION < VERSION_NTSC_1_0
char message[128]; char message[128];
sprintf(message, "DMA-Crash %s %d Ram: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", sprintf(message, "DMA-Crash %s %d Ram: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
"texdecompress.c", 357, "texdecompress.c", 357,
var800ab540[0], var800ab540[1], var800ab540[2], var800ab540[3], g_TexBitstring[0], g_TexBitstring[1], g_TexBitstring[2], g_TexBitstring[3],
var800ab540[4], var800ab540[5], var800ab540[6], var800ab540[7], g_TexBitstring[4], g_TexBitstring[5], g_TexBitstring[6], g_TexBitstring[7],
var800ab540[8], var800ab540[9], var800ab540[10], var800ab540[11], g_TexBitstring[8], g_TexBitstring[9], g_TexBitstring[10], g_TexBitstring[11],
var800ab540[12], var800ab540[13], var800ab540[14], var800ab540[15]); g_TexBitstring[12], g_TexBitstring[13], g_TexBitstring[14], g_TexBitstring[15]);
crashSetMessage(message); crashSetMessage(message);
CRASH(); CRASH();
#endif #endif
@@ -226,19 +226,19 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
imagebytesout = texAlignIndices(scratch2, width, height, format, &dst[totalbytesout]); imagebytesout = texAlignIndices(scratch2, width, height, format, &dst[totalbytesout]);
texSetBitstring(rzipGetSomething()); texSetBitstring(rzipGetSomething());
if (arg2 == 1) { if (hasloddata == true) {
if (IS4MB() && j == 2 && !foundthething) { if (IS4MB() && lod == 2 && !foundthething) {
pool->rightpos->maxlod = j; pool->rightpos->numlods = lod;
foundthething = true; foundthething = true;
} }
if (totalbytesout + imagebytesout > 0x800 || foundthething) { if (totalbytesout + imagebytesout > 0x800 || foundthething) {
if (!foundthething) { if (!foundthething) {
pool->rightpos->maxlod = j; pool->rightpos->numlods = lod;
foundthething = true; foundthething = true;
} }
} else { } else {
texSwapAltRowBytes(&dst[totalbytesout], width, height, format); texSwizzle(&dst[totalbytesout], width, height, format);
totalbytesout += imagebytesout; totalbytesout += imagebytesout;
} }
} else { } else {
@@ -256,41 +256,43 @@ s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpoo
} }
} }
if (!arg2) { // If the texture data doesn't contain multiple LODs but the header has a numlods value,
if (forcenumimages >= 2) { // generate the other LODs by shrinking the image.
if (!hasloddata) {
if (numlods >= 2) {
s32 tmpwidth = width; s32 tmpwidth = width;
s32 tmpheight = height; s32 tmpheight = height;
start = dst; lodsrc = dst;
end = &dst[totalbytesout]; loddst = &dst[totalbytesout];
for (j = 1; j < forcenumimages; j++) { for (lod = 1; lod < numlods; lod++) {
imagebytesout = texShrinkPaletted(start, end, tmpwidth, tmpheight, format, palette, numcolours); imagebytesout = texShrinkPaletted(lodsrc, loddst, tmpwidth, tmpheight, format, palette, numcolours);
if (IS4MB() && j == 2) { if (IS4MB() && lod == 2) {
pool->rightpos->maxlod = j; pool->rightpos->numlods = lod;
break; break;
} }
if (totalbytesout + imagebytesout > 0x800) { if (totalbytesout + imagebytesout > 0x800) {
pool->rightpos->maxlod = j; pool->rightpos->numlods = lod;
break; break;
} }
texSwapAltRowBytes(start, tmpwidth, tmpheight, format); texSwizzle(lodsrc, tmpwidth, tmpheight, format);
totalbytesout += imagebytesout; totalbytesout += imagebytesout;
tmpwidth = (tmpwidth + 1) >> 1; tmpwidth = (tmpwidth + 1) >> 1;
tmpheight = (tmpheight + 1) >> 1; tmpheight = (tmpheight + 1) >> 1;
start = end; lodsrc = loddst;
end += imagebytesout; loddst += imagebytesout;
} }
texSwapAltRowBytes(start, tmpwidth, tmpheight, format); texSwizzle(lodsrc, tmpwidth, tmpheight, format);
} else { } else {
texSwapAltRowBytes(dst, width, height, format); texSwizzle(dst, width, height, format);
} }
} }
@@ -678,7 +680,7 @@ s32 texFindClosestColourIndexIA(u16 *palette, s32 numcolours, s32 intensity, s32
* h = height in pixels * h = height in pixels
* c = compression method (see TEXCOMPMETHOD constants) * c = compression method (see TEXCOMPMETHOD constants)
*/ */
s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5) s32 texInflateNonZlib(u8 *src, u8 *dst, bool hasloddata, s32 numlods, struct texpool *pool, bool unusedarg)
{ {
u8 scratch[0x2000]; u8 scratch[0x2000];
u8 lookup[0x1000]; u8 lookup[0x1000];
@@ -693,18 +695,18 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex
s32 imagebytesout; s32 imagebytesout;
s32 format; s32 format;
s32 value; s32 value;
u8 *start; u8 *lodsrc;
u8 *end; u8 *loddst;
bool writetocache = false; bool writetocache = false;
texSetBitstring(src); texSetBitstring(src);
numimages = arg2 && forcenumimages ? forcenumimages : 1; numimages = hasloddata && numlods ? numlods : 1;
pool->rightpos->maxlod = forcenumimages; pool->rightpos->numlods = numlods;
pool->rightpos->unk0c_02 = arg2; pool->rightpos->hasloddata = hasloddata;
if (arg2) { if (hasloddata) {
writetocache = true; writetocache = true;
for (i = 0; i < g_TexCacheCount; i++) { for (i = 0; i < g_TexCacheCount; i++) {
@@ -807,17 +809,17 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex
break; break;
} }
if (arg2 == 1) { if (hasloddata == true) {
texSwapAltRowBytes(&dst[totalbytesout], width, height, format); texSwizzle(&dst[totalbytesout], width, height, format);
} }
imagebytesout = (imagebytesout + 7) & ~7; imagebytesout = (imagebytesout + 7) & ~7;
totalbytesout += imagebytesout; totalbytesout += imagebytesout;
if (var800ab548 == 0) { if (g_TexAccumNumBits == 0) {
var800ab540++; g_TexBitstring++;
} else { } else {
var800ab548 = 0; g_TexAccumNumBits = 0;
} }
} }
@@ -838,32 +840,34 @@ s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct tex
} }
} }
if (!arg2) { // If the texture data doesn't contain multiple LODs but the header has a numlods value,
if (forcenumimages >= 2) { // generate the other LODs by shrinking the image.
if (!hasloddata) {
if (numlods >= 2) {
s32 tmpwidth = width; s32 tmpwidth = width;
s32 tmpheight = height; s32 tmpheight = height;
start = dst; lodsrc = dst;
if (1); if (1);
end = &dst[totalbytesout]; loddst = &dst[totalbytesout];
for (i = 1; i < forcenumimages; i++) { for (i = 1; i < numlods; i++) {
imagebytesout = texShrinkNonPaletted(start, end, tmpwidth, tmpheight, format); imagebytesout = texShrinkNonPaletted(lodsrc, loddst, tmpwidth, tmpheight, format);
texSwapAltRowBytes(start, tmpwidth, tmpheight, format); texSwizzle(lodsrc, tmpwidth, tmpheight, format);
totalbytesout += imagebytesout; totalbytesout += imagebytesout;
tmpwidth = (tmpwidth + 1) >> 1; tmpwidth = (tmpwidth + 1) >> 1;
tmpheight = (tmpheight + 1) >> 1; tmpheight = (tmpheight + 1) >> 1;
start = end; lodsrc = loddst;
end += imagebytesout; loddst += imagebytesout;
} }
texSwapAltRowBytes(start, tmpwidth, tmpheight, format); texSwizzle(lodsrc, tmpwidth, tmpheight, format);
} else { } else {
texSwapAltRowBytes(dst, width, height, format); texSwizzle(dst, width, height, format);
} }
} }
@@ -1902,48 +1906,45 @@ s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *look
} }
/** /**
* For every second row, swap the bytes within that row. * For every second row, swap every pair of words within that row.
*
* For textures with 32-bit colour values (in GBI format), swap every pair
* within each word. For all other textures, swap every byte within each pair.
*/ */
void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format) void texSwizzle(u8 *dst, s32 width, s32 height, s32 format)
{ {
s32 x; s32 x;
s32 y; s32 y;
s32 alignedwidth; s32 wordsperrow;
u32 *row = (u32 *)dst; u32 *row = (u32 *)dst;
s32 tmp; s32 tmp;
switch (format) { switch (format) {
case TEXFORMAT_RGBA32: case TEXFORMAT_RGBA32:
case TEXFORMAT_RGB24: case TEXFORMAT_RGB24:
alignedwidth = (width + 3) & 0xffc; wordsperrow = (width + 3) & 0xffc;
break; break;
case TEXFORMAT_RGBA16: case TEXFORMAT_RGBA16:
case TEXFORMAT_RGB15: case TEXFORMAT_RGB15:
case TEXFORMAT_IA16: case TEXFORMAT_IA16:
alignedwidth = ((width + 3) & 0xffc) >> 1; wordsperrow = ((width + 3) & 0xffc) >> 1;
break; break;
case TEXFORMAT_IA8: case TEXFORMAT_IA8:
case TEXFORMAT_I8: case TEXFORMAT_I8:
case TEXFORMAT_RGBA16_CI8: case TEXFORMAT_RGBA16_CI8:
case TEXFORMAT_IA16_CI8: case TEXFORMAT_IA16_CI8:
alignedwidth = ((width + 7) & 0xff8) >> 2; wordsperrow = ((width + 7) & 0xff8) >> 2;
break; break;
case TEXFORMAT_IA4: case TEXFORMAT_IA4:
case TEXFORMAT_I4: case TEXFORMAT_I4:
case TEXFORMAT_RGBA16_CI4: case TEXFORMAT_RGBA16_CI4:
case TEXFORMAT_IA16_CI4: case TEXFORMAT_IA16_CI4:
alignedwidth = ((width + 0xf) & 0xff0) >> 3; wordsperrow = ((width + 0xf) & 0xff0) >> 3;
break; break;
} }
row += alignedwidth; row += wordsperrow;
if (format == TEXFORMAT_RGBA32 || format == TEXFORMAT_RGB24) { if (format == TEXFORMAT_RGBA32 || format == TEXFORMAT_RGB24) {
for (y = 1; y < height; y += 2) { for (y = 1; y < height; y += 2) {
for (x = 0; x < alignedwidth; x += 4) { for (x = 0; x < wordsperrow; x += 4) {
tmp = row[x + 0]; tmp = row[x + 0];
row[x + 0] = row[x + 2]; row[x + 0] = row[x + 2];
row[x + 2] = tmp; row[x + 2] = tmp;
@@ -1953,17 +1954,17 @@ void texSwapAltRowBytes(u8 *dst, s32 width, s32 height, s32 format)
row[x + 3] = tmp; row[x + 3] = tmp;
} }
row += alignedwidth * 2; row += wordsperrow * 2;
} }
} else { } else {
for (y = 1; y < height; y += 2) { for (y = 1; y < height; y += 2) {
for (x = 0; x < alignedwidth; x += 2) { for (x = 0; x < wordsperrow; x += 2) {
tmp = row[x + 0]; tmp = row[x + 0];
row[x + 0] = row[x + 1]; row[x + 0] = row[x + 1];
row[x + 1] = tmp; row[x + 1] = tmp;
} }
row += alignedwidth * 2; row += wordsperrow * 2;
} }
} }
} }
@@ -2080,7 +2081,7 @@ void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2)
texLoad((s32 *)((s32)bytes + 4), pool, arg2); texLoad((s32 *)((s32)bytes + 4), pool, arg2);
} }
bytes += 8; bytes += sizeof(Gfx);
} }
} }
@@ -2121,13 +2122,13 @@ extern u8 _texturesdataSegmentRomStart;
* z = texture is compressed with zlib * z = texture is compressed with zlib
* l = number of levels of detail within the texture * l = number of levels of detail within the texture
*/ */
void texLoad(s32 *updateword, struct texpool *pool, bool arg2) void texLoad(s32 *updateword, struct texpool *pool, bool unusedarg)
{ {
u8 compbuffer[4 * 1024 + 0x40]; u8 compbuffer[4 * 1024 + 0x40];
u8 *compptr; u8 *compptr;
s32 sp14a8; s32 hasloddata;
s32 iszlib; s32 iszlib;
s32 lod; s32 numlods;
struct tex *tex; struct tex *tex;
u8 *alignedcompbuffer; u8 *alignedcompbuffer;
u32 stack; u32 stack;
@@ -2184,12 +2185,12 @@ void texLoad(s32 *updateword, struct texpool *pool, bool arg2)
compptr = (u8 *) alignedcompbuffer + (thisoffset & 7); compptr = (u8 *) alignedcompbuffer + (thisoffset & 7);
thisoffset = 0; thisoffset = 0;
sp14a8 = (*compptr & 0x80) >> 7; hasloddata = (*compptr & 0x80) >> 7;
iszlib = (*compptr & 0x40) >> 6; iszlib = (*compptr & 0x40) >> 6;
lod = *compptr & 0x3f; numlods = *compptr & 0x3f;
if (lod > 5) { if (numlods > 5) {
lod = 5; numlods = 5;
} }
compptr++; compptr++;
@@ -2241,9 +2242,9 @@ void texLoad(s32 *updateword, struct texpool *pool, bool arg2)
// Extract the texture data to the allocation (pool->leftpos) // Extract the texture data to the allocation (pool->leftpos)
if (iszlib) { if (iszlib) {
bytesout = texInflateZlib(compptr, pool->leftpos, sp14a8, lod, pool, arg2); bytesout = texInflateZlib(compptr, pool->leftpos, hasloddata, numlods, pool, unusedarg);
} else { } else {
bytesout = texInflateNonZlib(compptr, pool->leftpos, sp14a8, lod, pool, arg2); bytesout = texInflateNonZlib(compptr, pool->leftpos, hasloddata, numlods, pool, unusedarg);
} }
// If we're using the shared pool, the data must be copied out of // If we're using the shared pool, the data must be copied out of
+11 -11
View File
@@ -11,24 +11,24 @@
#include "textureconfig.h" #include "textureconfig.h"
#include "types.h" #include "types.h"
void texSetBitstring(u8 *arg0) void texSetBitstring(u8 *bitstring)
{ {
var800ab540 = arg0; g_TexBitstring = bitstring;
var800ab544 = 0; g_TexAccumValue = 0;
var800ab548 = 0; g_TexAccumNumBits = 0;
} }
s32 texReadBits(s32 arg0) s32 texReadBits(s32 wantnumbits)
{ {
while (var800ab548 < arg0) { while (g_TexAccumNumBits < wantnumbits) {
var800ab544 = *var800ab540 | var800ab544 << 8; g_TexAccumValue = g_TexAccumValue << 8 | *g_TexBitstring;
var800ab540++; g_TexBitstring++;
var800ab548 += 8; g_TexAccumNumBits += 8;
} }
var800ab548 -= arg0; g_TexAccumNumBits -= wantnumbits;
return var800ab544 >> var800ab548 & ((1 << arg0) - 1); return (g_TexAccumValue >> g_TexAccumNumBits) & ((1 << wantnumbits) - 1);
} }
extern u8 *g_TextureConfigSegment; extern u8 *g_TextureConfigSegment;
+2 -2
View File
@@ -448,7 +448,7 @@ void texSelect(Gfx **gdlptr, struct textureconfig *tconfig, u32 arg2, s32 arg3,
depth = tconfig->depth; depth = tconfig->depth;
} }
if (tex && tex->unk0c_02) { if (tex && tex->hasloddata) {
tex0f173e50(tex, &depth2, &lrs); tex0f173e50(tex, &depth2, &lrs);
} else { } else {
switch (depth) { switch (depth) {
@@ -541,7 +541,7 @@ void texSelect(Gfx **gdlptr, struct textureconfig *tconfig, u32 arg2, s32 arg3,
s32 line; s32 line;
if (tile > 0) { if (tile > 0) {
if (tex && tex->unk0c_02) { if (tex && tex->hasloddata) {
width = texGetWidthAtLod(tex, tile); width = texGetWidthAtLod(tex, tile);
height = texGetHeightAtLod(tex, tile); height = texGetHeightAtLod(tex, tile);
} else { } else {
+3 -3
View File
@@ -253,9 +253,9 @@ extern struct texture *g_Textures;
extern struct texpool g_TexSharedPool; extern struct texpool g_TexSharedPool;
extern struct texcacheitem g_TexCacheItems[150]; extern struct texcacheitem g_TexCacheItems[150];
extern s32 g_TexCacheCount; extern s32 g_TexCacheCount;
extern u8 *var800ab540; extern u8 *g_TexBitstring;
extern u32 var800ab544; extern u32 g_TexAccumValue;
extern s32 var800ab548; extern s32 g_TexAccumNumBits;
extern s32 g_TexNumConfigs; extern s32 g_TexNumConfigs;
extern struct tex **g_TexWords; extern struct tex **g_TexWords;
extern struct textureconfig *g_TexWallhitConfigs; extern struct textureconfig *g_TexWallhitConfigs;
+4 -4
View File
@@ -5,7 +5,7 @@
#include "types.h" #include "types.h"
void func0f16e810(u32 arg0); void func0f16e810(u32 arg0);
s32 texInflateZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5); s32 texInflateZlib(u8 *src, u8 *dst, bool arg2, s32 forcenumimages, struct texpool *pool, s32 unusedarg);
s32 texAlignIndices(u8 *arg0, s32 width, s32 height, s32 format, u8 *dst); s32 texAlignIndices(u8 *arg0, s32 width, s32 height, s32 format, u8 *dst);
s32 texGetAverageRed(u16 colour1, u16 colour2, u16 colour3, u16 colour4); s32 texGetAverageRed(u16 colour1, u16 colour2, u16 colour3, u16 colour4);
s32 texGetAverageGreen(u16 colour1, u16 colour2, u16 colour3, u16 colour4); s32 texGetAverageGreen(u16 colour1, u16 colour2, u16 colour3, u16 colour4);
@@ -14,7 +14,7 @@ s32 texGetAverageAlpha(u16 colour1, u16 colour2, u16 colour3, u16 colour4);
s32 texShrinkPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format, u16 *palette, s32 numcolours); s32 texShrinkPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format, u16 *palette, s32 numcolours);
s32 texFindClosestColourIndexRGBA(u8 *palette, s32 numcolours, s32 r, s32 g, s32 b, s32 a); s32 texFindClosestColourIndexRGBA(u8 *palette, s32 numcolours, s32 r, s32 g, s32 b, s32 a);
s32 texFindClosestColourIndexIA(u16 *palette, s32 numcolours, s32 intensity, s32 alpha); s32 texFindClosestColourIndexIA(u16 *palette, s32 numcolours, s32 intensity, s32 alpha);
s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 arg5); s32 texInflateNonZlib(u8 *src, u8 *dst, s32 arg2, s32 forcenumimages, struct texpool *pool, s32 unusedarg);
s32 texShrinkNonPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format); s32 texShrinkNonPaletted(u8 *src, u8 *dst, s32 srcwidth, s32 srcheight, s32 format);
void texInflateHuffman(u8 *dst, s32 numiterations, s32 chansize); void texInflateHuffman(u8 *dst, s32 numiterations, s32 chansize);
void texInflateRle(u8 *arg0, s32 arg1); void texInflateRle(u8 *arg0, s32 arg1);
@@ -25,14 +25,14 @@ s32 texReadUncompressed(u8 *dst, s32 width, s32 height, s32 format);
s32 texChannelsToPixels(u8 *src, s32 width, s32 height, u8 *dst, s32 format); s32 texChannelsToPixels(u8 *src, s32 width, s32 height, u8 *dst, s32 format);
s32 texInflateLookup(s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format); s32 texInflateLookup(s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format);
s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format); s32 texInflateLookupFromBuffer(u8 *src, s32 width, s32 height, u8 *dst, u8 *lookup, s32 numcolours, s32 format);
void texSwapAltRowBytes(u8 *arg0, s32 width, s32 height, s32 format); void texSwizzle(u8 *arg0, s32 width, s32 height, s32 format);
void texBlur(u8 *pixels, s32 width, s32 height, s32 method, s32 chansize); void texBlur(u8 *pixels, s32 width, s32 height, s32 method, s32 chansize);
void texInitPool(struct texpool *pool, u8 *start, s32 len); void texInitPool(struct texpool *pool, u8 *start, s32 len);
struct tex *texFindInPool(s32 texturenum, struct texpool *pool); struct tex *texFindInPool(s32 texturenum, struct texpool *pool);
s32 texGetPoolFreeBytes(struct texpool *pool); s32 texGetPoolFreeBytes(struct texpool *pool);
u8 *texGetPoolLeftPos(struct texpool *pool); u8 *texGetPoolLeftPos(struct texpool *pool);
void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2); void texLoadFromDisplayList(Gfx *gdl, struct texpool *pool, s32 arg2);
void texLoad(s32 *updateword, struct texpool *pool, bool arg2); void texLoad(s32 *updateword, struct texpool *pool, bool unusedarg);
void texLoadFromConfigs(struct textureconfig *configs, s32 numconfigs, struct texpool *pool, s32 arg3); void texLoadFromConfigs(struct textureconfig *configs, s32 numconfigs, struct texpool *pool, s32 arg3);
void texLoadFromTextureNum(u32 arg0, struct texpool *pool); void texLoadFromTextureNum(u32 arg0, struct texpool *pool);
+2 -3
View File
@@ -5952,16 +5952,15 @@ struct awardmetrics {
struct tex { struct tex {
/*0x00*/ u16 texturenum : 12; /*0x00*/ u16 texturenum : 12;
/*0x00*/ u16 unk00_0c : 4;
/*0x04*/ u8 *data; /*0x04*/ u8 *data;
/*0x08*/ u8 width; /*0x08*/ u8 width;
/*0x09*/ u8 height; /*0x09*/ u8 height;
/*0x0a*/ u8 unk0a; /*0x0a*/ u8 unk0a;
/*0x0b*/ u8 maxlod : 3; /*0x0b*/ u8 numlods : 3;
/*0x0b*/ u8 gbiformat : 3; /*0x0b*/ u8 gbiformat : 3;
/*0x0b*/ u8 depth : 2; /*0x0b*/ u8 depth : 2;
/*0x0c*/ u32 lutmodeindex : 2; /*0x0c*/ u32 lutmodeindex : 2;
/*0x0c*/ u32 unk0c_02 : 1; /*0x0c*/ u32 hasloddata : 1;
/*0x0c*/ u32 unk0c_03 : 1; /*0x0c*/ u32 unk0c_03 : 1;
/*0x0c*/ u32 next : 24; /*0x0c*/ u32 next : 24;
}; };