1
0
mirror of synced 2025-02-25 22:38:07 +01:00

Automatically generate GX2 mipoffsets if null or empty

This commit is contained in:
KillzXGaming 2019-07-29 14:55:43 -04:00
parent 691d4c7d35
commit f58efacbef
5 changed files with 33 additions and 1 deletions

View File

@ -626,6 +626,8 @@ namespace Bfres.Structs
case TEX_FORMAT.B8G8R8A8_UNORM_SRGB: return GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB;
case TEX_FORMAT.R32G8X24_FLOAT: return GX2SurfaceFormat.T_R32_Float_X8_X24;
case TEX_FORMAT.R32G32B32A32_FLOAT: return GX2SurfaceFormat.TC_R32_G32_B32_A32_Float;
case TEX_FORMAT.R32G32B32A32_UINT: return GX2SurfaceFormat.TC_R32_G32_B32_A32_UInt;
case TEX_FORMAT.R32G32B32A32_SINT: return GX2SurfaceFormat.TC_R32_G32_B32_A32_SInt;
default:
throw new Exception($"Cannot convert format {texFormat}");
}
@ -661,6 +663,8 @@ namespace Bfres.Structs
case GX2SurfaceFormat.TC_R8_UNorm: return TEX_FORMAT.R8_UNORM;
case GX2SurfaceFormat.TC_R32_G32_B32_A32_Float: return TEX_FORMAT.R32G32B32A32_FLOAT;
case GX2SurfaceFormat.TC_R16_G16_B16_A16_Float: return TEX_FORMAT.R16G16B16A16_FLOAT;
case GX2SurfaceFormat.TC_R32_G32_B32_A32_SInt: return TEX_FORMAT.R32G32B32A32_SINT;
case GX2SurfaceFormat.TC_R32_G32_B32_A32_UInt: return TEX_FORMAT.R32G32B32A32_UINT;
case GX2SurfaceFormat.Invalid: throw new Exception("Invalid Format");
default:
throw new Exception($"Cannot convert format {GX2Format}");

View File

@ -15,7 +15,7 @@ namespace FirstPlugin
public FileType FileType { get; set; } = FileType.Image;
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "G1T Texture" };
public string[] Description { get; set; } = new string[] { "G1T Textre" };
public string[] Extension { get; set; } = new string[] { "*.g1t" };
public string FileName { get; set; }
public string FilePath { get; set; }

View File

@ -622,6 +622,31 @@ namespace Toolbox.Library
return GX2TexRegisters.CreateTexRegs(surface.width, surface.height, surface.numMips, surface.format, surface.tileMode, surface.pitch, surface.compSel);
}
public static uint[] GenerateMipOffsets(GX2Surface tex)
{
var surfOut = GX2.getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, 1, 1, tex.tileMode, 0, 0);
uint imageSize = (uint)surfOut.surfSize;
uint mipSize = 0;
List<uint> mipOffsets = new List<uint>();
for (int mipLevel = 0; mipLevel < tex.numMips; mipLevel++)
{
if (mipLevel != 0)
{
surfOut = GX2.getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, 1, 1, tex.tileMode, 0, mipLevel);
if (mipLevel == 1)
mipOffsets.Add(imageSize);
else
mipOffsets.Add(mipSize);
byte[] dataAlignBytes = new byte[RoundUp(mipSize, surfOut.baseAlign) - mipSize];
mipSize += (uint)(surfOut.surfSize + dataAlignBytes.Length);
}
}
return mipOffsets.ToArray();
}
public static byte[] Decode(GX2Surface tex, int ArrayIndex = -1, int MipIndex = -1, string DebugTextureName = "")
{
uint blkWidth, blkHeight;
@ -636,6 +661,9 @@ namespace Toolbox.Library
blkHeight = 1;
}
if (tex.mipOffset == null || tex.mipOffset.Length == 0)
tex.mipOffset = GenerateMipOffsets(tex);
var ImageSurfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, 0);
uint bpp = DIV_ROUND_UP(ImageSurfInfo.bpp, 8);