Start to impliment backend for depth/3D textures
This commit is contained in:
parent
9735fb0ce6
commit
f7d674fe18
@ -563,7 +563,7 @@ namespace Bfres.Structs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
format = (int)texture.Format;
|
format = (int)texture.Format;
|
||||||
int swizzle = (int)texture.Swizzle;
|
int swizzle = (int)texture.Swizzle;
|
||||||
|
@ -66,7 +66,7 @@ namespace FirstPlugin
|
|||||||
return TextureImage.PaletteData;
|
return TextureImage.PaletteData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return TextureImage.ImageData;
|
return TextureImage.ImageData;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ namespace FirstPlugin
|
|||||||
IGZStructure.TextureInfo.ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
IGZStructure.TextureInfo.ImageData = GenerateMipsAndCompress(bitmap, MipCount, Format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
||||||
return TegraX1Swizzle.GetImageData(this, IGZStructure.TextureInfo.ImageData, ArrayLevel, MipLevel, 1);
|
return TegraX1Swizzle.GetImageData(this, IGZStructure.TextureInfo.ImageData, ArrayLevel, MipLevel, 1);
|
||||||
|
@ -926,7 +926,7 @@ namespace FirstPlugin
|
|||||||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
uint GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM;
|
uint GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM;
|
||||||
|
|
||||||
|
@ -679,7 +679,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -635,7 +635,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
int swizzle = (int)Swizzle;
|
int swizzle = (int)Swizzle;
|
||||||
int pitch = (int)0;
|
int pitch = (int)0;
|
||||||
|
@ -678,7 +678,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
uint bpp = GetBytesPerPixel(Format);
|
uint bpp = GetBytesPerPixel(Format);
|
||||||
|
|
||||||
|
@ -113,4 +113,45 @@ namespace Grezzo.CmbEnums
|
|||||||
ONE_MINUS_SRC_B = 0x8585,
|
ONE_MINUS_SRC_B = 0x8585,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public enum FresnelSelector
|
||||||
|
{
|
||||||
|
No = 25280,
|
||||||
|
Pri = 25281,
|
||||||
|
Sec = 25282,
|
||||||
|
PriSec = 25283
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum LayerConfig
|
||||||
|
{
|
||||||
|
LayerConfig0 = 25264,
|
||||||
|
LayerConfig1 = 25265,
|
||||||
|
LayerConfig2 = 25266,
|
||||||
|
LayerConfig3 = 25267,
|
||||||
|
LayerConfig4 = 25268,
|
||||||
|
LayerConfig5 = 25269,
|
||||||
|
LayerConfig6 = 25270,
|
||||||
|
LayerConfig7 = 25271,
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum LUTInput : ushort
|
||||||
|
{
|
||||||
|
CosNormalHalf = 25248,
|
||||||
|
CosViewHalf = 25249,
|
||||||
|
CosNormalView = 25250,
|
||||||
|
CosLightNormal = 25251,
|
||||||
|
CosLightSpot = 25252,
|
||||||
|
CosPhi = 25253
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum StencilOp
|
||||||
|
{
|
||||||
|
Keep = 7680,
|
||||||
|
Zero = 0,
|
||||||
|
Replace = 7681,
|
||||||
|
Increment = 7682,
|
||||||
|
Decrement = 7683,
|
||||||
|
Invert = 5386,
|
||||||
|
IncrementWrap = 34055,
|
||||||
|
DecrementWrap = 34055
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ namespace FirstPlugin
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (ContainerParent.Platform == GT1Platform.WiiU)
|
if (ContainerParent.Platform == GT1Platform.WiiU)
|
||||||
{
|
{
|
||||||
|
@ -179,11 +179,8 @@ namespace LayoutBXLYT
|
|||||||
bntx = BinaryContainers.Values.FirstOrDefault();
|
bntx = BinaryContainers.Values.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
int startIndex = bntx.Textures.Count - 1;
|
|
||||||
var importedTextures = bntx.ImportTexture();
|
var importedTextures = bntx.ImportTexture();
|
||||||
|
|
||||||
Console.WriteLine("startIndex " + startIndex);
|
|
||||||
|
|
||||||
//Load all the additional textues
|
//Load all the additional textues
|
||||||
for (int i = 0; i < importedTextures.Count; i++)
|
for (int i = 0; i < importedTextures.Count; i++)
|
||||||
textures.Add(importedTextures[i]);
|
textures.Add(importedTextures[i]);
|
||||||
|
@ -107,7 +107,7 @@ namespace FirstPlugin.LuigisMansion.DarkMoon
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ namespace FirstPlugin.LuigisMansion3
|
|||||||
UpdateProperties();
|
UpdateProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
uint blkHeight = STGenericTexture.GetBlockHeight(Format);
|
uint blkHeight = STGenericTexture.GetBlockHeight(Format);
|
||||||
uint blkDepth = STGenericTexture.GetBlockDepth(Format);
|
uint blkDepth = STGenericTexture.GetBlockDepth(Format);
|
||||||
@ -245,7 +245,7 @@ namespace FirstPlugin.LuigisMansion3
|
|||||||
Console.WriteLine("blockHeight " + blockHeight);
|
Console.WriteLine("blockHeight " + blockHeight);
|
||||||
Console.WriteLine("BlockHeightLog2 " + BlockHeightLog2);
|
Console.WriteLine("BlockHeightLog2 " + BlockHeightLog2);
|
||||||
|
|
||||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, BlockHeightLog2, 1);
|
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TEX_FORMAT[] SupportedFormats
|
public override TEX_FORMAT[] SupportedFormats
|
||||||
|
@ -192,7 +192,7 @@ namespace FirstPlugin.NLG
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ namespace FirstPlugin.PunchOutWii
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
//Gets the raw image data in bytes
|
//Gets the raw image data in bytes
|
||||||
//Gets decoded automatically
|
//Gets decoded automatically
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||||
}
|
}
|
||||||
|
@ -420,7 +420,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -586,7 +586,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (image.Is3DS)
|
if (image.Is3DS)
|
||||||
{
|
{
|
||||||
|
@ -1236,7 +1236,8 @@ namespace FirstPlugin
|
|||||||
Text = tex.Name;
|
Text = tex.Name;
|
||||||
Width = tex.Width;
|
Width = tex.Width;
|
||||||
Height = tex.Height;
|
Height = tex.Height;
|
||||||
ArrayCount = (uint)tex.TextureData.Count;
|
ArrayCount = tex.Depth;
|
||||||
|
// ArrayCount = (uint)tex.TextureData.Count;
|
||||||
MipCount = (uint)tex.TextureData[0].Count;
|
MipCount = (uint)tex.TextureData[0].Count;
|
||||||
Format = ConvertFormat(tex.Format);
|
Format = ConvertFormat(tex.Format);
|
||||||
|
|
||||||
@ -1672,7 +1673,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
int target = 1;
|
int target = 1;
|
||||||
if (ParentBNTX != null && ParentBNTX is BNTX && ParentBNTX.BinaryTexFile != null)
|
if (ParentBNTX != null && ParentBNTX is BNTX && ParentBNTX.BinaryTexFile != null)
|
||||||
@ -1696,34 +1697,43 @@ namespace FirstPlugin
|
|||||||
int linesPerBlockHeight = (1 << (int)Texture.BlockHeightLog2) * 8;
|
int linesPerBlockHeight = (1 << (int)Texture.BlockHeightLog2) * 8;
|
||||||
uint bpp = GetBytesPerPixel(Format);
|
uint bpp = GetBytesPerPixel(Format);
|
||||||
|
|
||||||
|
uint numDepth = 1;
|
||||||
|
if (Depth > 1)
|
||||||
|
numDepth = Depth;
|
||||||
|
|
||||||
for (int arrayLevel = 0; arrayLevel < Texture.TextureData.Count; arrayLevel++)
|
return TegraX1Swizzle.GetImageData(this, Texture.TextureData[0][0], ArrayLevel, MipLevel, DepthLevel, target, Texture.TileMode == TileMode.LinearAligned);
|
||||||
|
|
||||||
|
for (int depthLevel = 0; depthLevel < numDepth; depthLevel++)
|
||||||
{
|
{
|
||||||
int blockHeightShift = 0;
|
for (int arrayLevel = 0; arrayLevel < Texture.TextureData.Count; arrayLevel++)
|
||||||
|
|
||||||
for (int mipLevel = 0; mipLevel < Texture.TextureData[arrayLevel].Count; mipLevel++)
|
|
||||||
{
|
{
|
||||||
uint width = (uint)Math.Max(1, Texture.Width >> mipLevel);
|
int blockHeightShift = 0;
|
||||||
uint height = (uint)Math.Max(1, Texture.Height >> mipLevel);
|
|
||||||
uint depth = (uint)Math.Max(1, Texture.Depth >> mipLevel);
|
|
||||||
|
|
||||||
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
|
for (int mipLevel = 0; mipLevel < Texture.TextureData[arrayLevel].Count; mipLevel++)
|
||||||
|
{
|
||||||
|
uint width = (uint)Math.Max(1, Texture.Width >> mipLevel);
|
||||||
|
uint height = (uint)Math.Max(1, Texture.Height >> mipLevel);
|
||||||
|
uint depth = (uint)Math.Max(1, Texture.Depth >> mipLevel);
|
||||||
|
|
||||||
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
|
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
|
||||||
blockHeightShift += 1;
|
|
||||||
|
|
||||||
Console.WriteLine($"{width} {height} {depth} {blkWidth} {blkHeight} {blkDepth} {target} {bpp} {Texture.TileMode} {(int)Math.Max(0, Texture.BlockHeightLog2 - blockHeightShift)} {Texture.TextureData[arrayLevel][mipLevel].Length}");
|
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
|
||||||
byte[] result = TegraX1Swizzle.deswizzle(width, height, depth, blkWidth, blkHeight, blkDepth, target, bpp, (uint)Texture.TileMode, (int)Math.Max(0, Texture.BlockHeightLog2 - blockHeightShift), Texture.TextureData[arrayLevel][mipLevel]);
|
blockHeightShift += 1;
|
||||||
//Create a copy and use that to remove uneeded data
|
|
||||||
byte[] result_ = new byte[size];
|
|
||||||
Array.Copy(result, 0, result_, 0, size);
|
|
||||||
|
|
||||||
result = null;
|
Console.WriteLine($"{width} {height} {depth} {blkWidth} {blkHeight} {blkDepth} {target} {bpp} {Texture.TileMode} {(int)Math.Max(0, Texture.BlockHeightLog2 - blockHeightShift)} {Texture.TextureData[arrayLevel][mipLevel].Length}");
|
||||||
|
byte[] result = TegraX1Swizzle.deswizzle(width, height, depth, blkWidth, blkHeight, blkDepth, target, bpp, (uint)Texture.TileMode, (int)Math.Max(0, Texture.BlockHeightLog2 - blockHeightShift), Texture.TextureData[arrayLevel][mipLevel]);
|
||||||
|
//Create a copy and use that to remove uneeded data
|
||||||
|
byte[] result_ = new byte[size];
|
||||||
|
Array.Copy(result, 0, result_, 0, size);
|
||||||
|
|
||||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel)
|
result = null;
|
||||||
return result_;
|
|
||||||
|
if (ArrayLevel == arrayLevel && MipLevel == mipLevel && DepthLevel == depthLevel)
|
||||||
|
return result_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -182,7 +182,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
//Gets the raw image data in bytes
|
//Gets the raw image data in bytes
|
||||||
//Gets decoded automatically
|
//Gets decoded automatically
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return CtpkTexture.ImageData;
|
return CtpkTexture.ImageData;
|
||||||
}
|
}
|
||||||
|
@ -668,7 +668,7 @@ namespace FirstPlugin
|
|||||||
LibraryGUI.UpdateViewport();
|
LibraryGUI.UpdateViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
RedChannel = SetChannel(surface.compSel[0]);
|
RedChannel = SetChannel(surface.compSel[0]);
|
||||||
GreenChannel = SetChannel(surface.compSel[1]);
|
GreenChannel = SetChannel(surface.compSel[1]);
|
||||||
|
@ -385,7 +385,7 @@ namespace FirstPlugin
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (Gx2HeaderData != null)
|
if (Gx2HeaderData != null)
|
||||||
{
|
{
|
||||||
|
@ -427,6 +427,7 @@ namespace FirstPlugin
|
|||||||
//Seek to next one
|
//Seek to next one
|
||||||
reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
|
reader.Seek(mipPos + 0x40, System.IO.SeekOrigin.Begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.Seek(0, System.IO.SeekOrigin.Begin);
|
reader.Seek(0, System.IO.SeekOrigin.Begin);
|
||||||
ImageData = reader.ReadBytes(imagesize);
|
ImageData = reader.ReadBytes(imagesize);
|
||||||
}
|
}
|
||||||
@ -572,12 +573,12 @@ namespace FirstPlugin
|
|||||||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (!IsSwizzled)
|
if (!IsSwizzled)
|
||||||
return DDS.GetArrayFaces(this, ImageData,1)[ArrayLevel].mipmaps[0];
|
return DDS.GetArrayFaces(this, ImageData,1)[ArrayLevel].mipmaps[0];
|
||||||
|
|
||||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, 1);
|
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, DepthLevel, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
STToolStripItem useSizeRestrictions = new STToolStripItem("UseSizeRestrictions");
|
STToolStripItem useSizeRestrictions = new STToolStripItem("UseSizeRestrictions");
|
||||||
|
@ -206,7 +206,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,8 @@ namespace FirstPlugin
|
|||||||
texWrapper.ImageData = reader.getSection(image.ImageOffset,
|
texWrapper.ImageData = reader.getSection(image.ImageOffset,
|
||||||
(uint)Decode_Gamecube.GetDataSize(GXFormat, (int)image.Width, (int)image.Height));
|
(uint)Decode_Gamecube.GetDataSize(GXFormat, (int)image.Width, (int)image.Height));
|
||||||
|
|
||||||
|
Console.WriteLine($"PaletteHeaderOffset {PaletteHeaderOffset}");
|
||||||
|
|
||||||
//Palette is sometimes unused to check
|
//Palette is sometimes unused to check
|
||||||
if (PaletteHeaderOffset != 0)
|
if (PaletteHeaderOffset != 0)
|
||||||
{
|
{
|
||||||
@ -200,7 +202,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
return Decode_Gamecube.GetMipLevel(ImageData, Width, Height, MipCount, (uint)MipLevel, Format);
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
if (PlatformSwizzle == PlatformSwizzle.Platform_Switch)
|
||||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
||||||
|
@ -308,7 +308,7 @@ namespace FirstPlugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool hasShownDialog = false;
|
private bool hasShownDialog = false;
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (Texture.ImageData == null)
|
if (Texture.ImageData == null)
|
||||||
{
|
{
|
||||||
@ -324,7 +324,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
var BlockHeightLog2 = Texture.Info.textureLayout & 7;
|
var BlockHeightLog2 = Texture.Info.textureLayout & 7;
|
||||||
|
|
||||||
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, BlockHeightLog2, 1);
|
return TegraX1Swizzle.GetImageData(this, Texture.ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -728,7 +728,7 @@ namespace FirstPlugin
|
|||||||
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
ImageData = Utils.CombineByteArray(mipmaps.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
return TegraX1Swizzle.GetImageData(this, ImageData, ArrayLevel, MipLevel, (int)Target);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
for (int m = 0; m < Meshes.Count; m++)
|
for (int m = 0; m < Meshes.Count; m++)
|
||||||
{
|
{
|
||||||
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).Material.IsTransparent)
|
if (((CMB.CMBMaterialWrapper)Meshes[m].GetMaterial()).CMBMaterial.IsTransparent)
|
||||||
transparent.Add(Meshes[m]);
|
transparent.Add(Meshes[m]);
|
||||||
else
|
else
|
||||||
opaque.Add(Meshes[m]);
|
opaque.Add(Meshes[m]);
|
||||||
@ -88,7 +88,7 @@ namespace FirstPlugin
|
|||||||
|
|
||||||
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
|
public override void SetRenderData(STGenericMaterial mat, ShaderProgram shader, STGenericObject m)
|
||||||
{
|
{
|
||||||
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).Material;
|
var cmbMaterial = ((CMB.CMBMaterialWrapper)mat).CMBMaterial;
|
||||||
var cmbMesh = ((CMB.CmbMeshWrapper)m);
|
var cmbMesh = ((CMB.CmbMeshWrapper)m);
|
||||||
|
|
||||||
bool HasNoNormals = cmbMesh.Shape.Normal.VertexData == null || cmbMesh.Shape.Normal.VertexData.Length == 0;
|
bool HasNoNormals = cmbMesh.Shape.Normal.VertexData == null || cmbMesh.Shape.Normal.VertexData.Length == 0;
|
||||||
|
@ -208,7 +208,7 @@ namespace Toolbox.Library
|
|||||||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return DataBlock;
|
return DataBlock;
|
||||||
}
|
}
|
||||||
|
@ -816,15 +816,15 @@ namespace Toolbox.Library
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool SwitchSwizzle = false;
|
public bool SwitchSwizzle = false;
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (IsAtscFormat(Format))
|
if (IsAtscFormat(Format))
|
||||||
SwitchSwizzle = true;
|
SwitchSwizzle = true;
|
||||||
|
|
||||||
if (SwitchSwizzle)
|
if (SwitchSwizzle)
|
||||||
return TegraX1Swizzle.GetImageData(this, bdata, ArrayLevel, MipLevel);
|
return TegraX1Swizzle.GetImageData(this, bdata, ArrayLevel, MipLevel, DepthLevel);
|
||||||
|
|
||||||
return GetArrayFaces(this, ArrayCount)[ArrayLevel].mipmaps[MipLevel];
|
return GetArrayFaces(this, ArrayCount, DepthLevel)[ArrayLevel].mipmaps[MipLevel];
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
|
public override void SetImageData(Bitmap bitmap, int ArrayLevel)
|
||||||
@ -985,8 +985,12 @@ namespace Toolbox.Library
|
|||||||
|
|
||||||
uint formatSize = GetBytesPerPixel(tex.Format);
|
uint formatSize = GetBytesPerPixel(tex.Format);
|
||||||
|
|
||||||
|
uint numDepth = 1;
|
||||||
|
if (tex.Depth > 1)
|
||||||
|
numDepth = tex.Depth;
|
||||||
|
|
||||||
uint Offset = 0;
|
uint Offset = 0;
|
||||||
for (byte d = 0; d < tex.Depth; ++d)
|
for (byte d = 0; d < numDepth; ++d)
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < Length; ++i)
|
for (byte i = 0; i < Length; ++i)
|
||||||
{
|
{
|
||||||
@ -1021,7 +1025,7 @@ namespace Toolbox.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Surface> GetArrayFaces(DDS dds, uint Length)
|
public static List<Surface> GetArrayFaces(DDS dds, uint Length, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
using (FileReader reader = new FileReader(dds.bdata))
|
using (FileReader reader = new FileReader(dds.bdata))
|
||||||
{
|
{
|
||||||
@ -1034,32 +1038,37 @@ namespace Toolbox.Library
|
|||||||
dds.header.mipmapCount = 1;
|
dds.header.mipmapCount = 1;
|
||||||
|
|
||||||
uint Offset = 0;
|
uint Offset = 0;
|
||||||
for (byte i = 0; i < Length; ++i)
|
for (byte d = 0; d < dds.Depth; ++d)
|
||||||
{
|
{
|
||||||
var Surface = new STGenericTexture.Surface();
|
for (byte i = 0; i < Length; ++i)
|
||||||
|
|
||||||
uint MipWidth = dds.header.width, MipHeight = dds.header.height;
|
|
||||||
for (int j = 0; j < dds.header.mipmapCount; ++j)
|
|
||||||
{
|
{
|
||||||
MipWidth = (uint)Math.Max(1, dds.header.width >> j);
|
var Surface = new STGenericTexture.Surface();
|
||||||
MipHeight = (uint)Math.Max(1, dds.header.height >> j);
|
|
||||||
|
|
||||||
uint size = (MipWidth * MipHeight); //Total pixels
|
uint MipWidth = dds.header.width, MipHeight = dds.header.height;
|
||||||
if (isBlock)
|
for (int j = 0; j < dds.header.mipmapCount; ++j)
|
||||||
{
|
{
|
||||||
size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
|
MipWidth = (uint)Math.Max(1, dds.header.width >> j);
|
||||||
if (size < formatSize)
|
MipHeight = (uint)Math.Max(1, dds.header.height >> j);
|
||||||
size = formatSize;
|
|
||||||
}
|
uint size = (MipWidth * MipHeight); //Total pixels
|
||||||
else
|
if (isBlock)
|
||||||
{
|
{
|
||||||
size = (uint)(size * (GetBytesPerPixel(dds.Format))); //Bytes per pixel
|
size = ((MipWidth + 3) >> 2) * ((MipHeight + 3) >> 2) * formatSize;
|
||||||
|
if (size < formatSize)
|
||||||
|
size = formatSize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = (uint)(size * (GetBytesPerPixel(dds.Format))); //Bytes per pixel
|
||||||
|
}
|
||||||
|
|
||||||
|
Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
|
||||||
|
Offset += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface.mipmaps.Add(reader.getSection((int)Offset, (int)size));
|
if (d == DepthLevel)
|
||||||
Offset += size;
|
Surfaces.Add(Surface);
|
||||||
}
|
}
|
||||||
Surfaces.Add(Surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Surfaces;
|
return Surfaces;
|
||||||
|
@ -104,7 +104,7 @@ namespace Toolbox.Library
|
|||||||
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
throw new NotImplementedException("Cannot set image data! Operation not implemented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
if (TargaImage == null || TargaImage.Image == null) return new byte[0];
|
if (TargaImage == null || TargaImage.Image == null) return new byte[0];
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ namespace Toolbox.Library
|
|||||||
ImageData = DDSCompressor.EncodePixelBlock(Data, bitmap.Width, bitmap.Width, DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
|
ImageData = DDSCompressor.EncodePixelBlock(Data, bitmap.Width, bitmap.Width, DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0)
|
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
return ImageData;
|
return ImageData;
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ namespace Toolbox.Library
|
|||||||
|
|
||||||
public string DataSize { get { return STMath.GetFileSize(DataSizeInBytes, 5); } }
|
public string DataSize { get { return STMath.GetFileSize(DataSizeInBytes, 5); } }
|
||||||
|
|
||||||
public abstract byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0);
|
public abstract byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0);
|
||||||
|
|
||||||
private byte[] paletteData = new byte[0];
|
private byte[] paletteData = new byte[0];
|
||||||
|
|
||||||
@ -493,18 +493,40 @@ namespace Toolbox.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bitmap GetBitmap3D(int ArrayLevel = 0, int MipLevel = 0)
|
||||||
|
{
|
||||||
|
List<Bitmap> images = new List<Bitmap>();
|
||||||
|
for (int i = 0; i < Depth; i++)
|
||||||
|
images.Add(GetBitmap(ArrayLevel, MipLevel, i));
|
||||||
|
|
||||||
|
//Combine images in a horizontal pattern
|
||||||
|
uint width = Width * Depth;
|
||||||
|
var newBitmap = new Bitmap((int)width, (int)Height);
|
||||||
|
using (Graphics grfx = Graphics.FromImage(newBitmap))
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
foreach (var image in images) {
|
||||||
|
grfx.DrawImage(image, x, 0);
|
||||||
|
x += image.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newBitmap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="Bitmap"/> given an array and mip index.
|
/// Gets a <see cref="Bitmap"/> given an array and mip index.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param>
|
/// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param>
|
||||||
/// <param name="MipLevel">The index of the mip level.</param>
|
/// <param name="MipLevel">The index of the mip level.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0)
|
public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0)
|
||||||
{
|
{
|
||||||
uint width = Math.Max(1, Width >> MipLevel);
|
uint width = Math.Max(1, Width >> MipLevel);
|
||||||
uint height = Math.Max(1, Height >> MipLevel);
|
uint height = Math.Max(1, Height >> MipLevel);
|
||||||
byte[] data = GetImageData(ArrayLevel, MipLevel);
|
byte[] data = GetImageData(ArrayLevel, MipLevel, DepthLevel);
|
||||||
byte[] paletteData = GetPaletteData();
|
byte[] paletteData = GetPaletteData();
|
||||||
|
if (Format == TEX_FORMAT.R8G8B8A8_UNORM) return BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)width, (int)height);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -68,16 +68,16 @@ namespace Toolbox.Library
|
|||||||
return MipMapSizes;
|
return MipMapSizes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int target = 1, bool LinearTileMode = false)
|
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int DepthLevel, int target = 1, bool LinearTileMode = false)
|
||||||
{
|
{
|
||||||
uint blkHeight = STGenericTexture.GetBlockHeight(texture.Format);
|
uint blkHeight = STGenericTexture.GetBlockHeight(texture.Format);
|
||||||
uint blkDepth = STGenericTexture.GetBlockDepth(texture.Format);
|
uint blkDepth = STGenericTexture.GetBlockDepth(texture.Format);
|
||||||
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(texture.Height, blkHeight));
|
uint blockHeight = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(texture.Height, blkHeight));
|
||||||
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
|
uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;
|
||||||
return GetImageData(texture, ImageData, ArrayLevel, MipLevel, BlockHeightLog2, target, LinearTileMode);
|
return GetImageData(texture, ImageData, ArrayLevel, MipLevel, DepthLevel, BlockHeightLog2, target, LinearTileMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, uint BlockHeightLog2, int target = 1, bool LinearTileMode = false)
|
public static byte[] GetImageData(STGenericTexture texture, byte[] ImageData, int ArrayLevel, int MipLevel, int DepthLevel, uint BlockHeightLog2, int target = 1, bool LinearTileMode = false)
|
||||||
{
|
{
|
||||||
uint bpp = STGenericTexture.GetBytesPerPixel(texture.Format);
|
uint bpp = STGenericTexture.GetBytesPerPixel(texture.Format);
|
||||||
uint blkWidth = STGenericTexture.GetBlockWidth(texture.Format);
|
uint blkWidth = STGenericTexture.GetBlockWidth(texture.Format);
|
||||||
@ -90,68 +90,73 @@ namespace Toolbox.Library
|
|||||||
uint TileMode = 0;
|
uint TileMode = 0;
|
||||||
if (LinearTileMode)
|
if (LinearTileMode)
|
||||||
TileMode = 1;
|
TileMode = 1;
|
||||||
|
uint numDepth = 1;
|
||||||
|
if (texture.Depth > 1)
|
||||||
|
numDepth = texture.Depth;
|
||||||
|
|
||||||
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
|
int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;
|
||||||
|
|
||||||
uint ArrayOffset = 0;
|
uint ArrayOffset = 0;
|
||||||
for (int arrayLevel = 0; arrayLevel < texture.ArrayCount; arrayLevel++)
|
for (int depthLevel = 0; depthLevel < numDepth; depthLevel++)
|
||||||
{
|
{
|
||||||
uint SurfaceSize = 0;
|
for (int arrayLevel = 0; arrayLevel < texture.ArrayCount; arrayLevel++)
|
||||||
int blockHeightShift = 0;
|
|
||||||
|
|
||||||
List<uint> MipOffsets = new List<uint>();
|
|
||||||
|
|
||||||
for (int mipLevel = 0; mipLevel < texture.MipCount; mipLevel++)
|
|
||||||
{
|
{
|
||||||
uint width = (uint)Math.Max(1, texture.Width >> mipLevel);
|
uint SurfaceSize = 0;
|
||||||
uint height = (uint)Math.Max(1, texture.Height >> mipLevel);
|
int blockHeightShift = 0;
|
||||||
uint depth = (uint)Math.Max(1, texture.Depth >> mipLevel);
|
|
||||||
|
|
||||||
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
|
List<uint> MipOffsets = new List<uint>();
|
||||||
|
|
||||||
Console.WriteLine($"size " + size);
|
for (int mipLevel = 0; mipLevel < texture.MipCount; mipLevel++)
|
||||||
|
|
||||||
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
|
|
||||||
blockHeightShift += 1;
|
|
||||||
|
|
||||||
|
|
||||||
uint width__ = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth);
|
|
||||||
uint height__ = TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight);
|
|
||||||
|
|
||||||
//Calculate the mip size instead
|
|
||||||
byte[] AlignedData = new byte[(TegraX1Swizzle.round_up(SurfaceSize, DataAlignment) - SurfaceSize)];
|
|
||||||
SurfaceSize += (uint)AlignedData.Length;
|
|
||||||
MipOffsets.Add(SurfaceSize);
|
|
||||||
|
|
||||||
//Get the first mip offset and current one and the total image size
|
|
||||||
int msize = (int)((MipOffsets[0] + ImageData.Length - MipOffsets[mipLevel]) / texture.ArrayCount);
|
|
||||||
|
|
||||||
byte[] data_ = Utils.SubArray(ImageData, ArrayOffset + MipOffsets[mipLevel], (uint)msize);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Pitch = TegraX1Swizzle.round_up(width__ * bpp, 64);
|
uint width = (uint)Math.Max(1, texture.Width >> mipLevel);
|
||||||
SurfaceSize += Pitch * TegraX1Swizzle.round_up(height__, Math.Max(1, blockHeight >> blockHeightShift) * 8);
|
uint height = (uint)Math.Max(1, texture.Height >> mipLevel);
|
||||||
|
uint depth = (uint)Math.Max(1, texture.Depth >> mipLevel);
|
||||||
|
|
||||||
byte[] result = TegraX1Swizzle.deswizzle(width, height, depth, blkWidth, blkHeight, blkDepth, target, bpp, TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), data_);
|
uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;
|
||||||
//Create a copy and use that to remove uneeded data
|
|
||||||
byte[] result_ = new byte[size];
|
|
||||||
Array.Copy(result, 0, result_, 0, size);
|
|
||||||
result = null;
|
|
||||||
|
|
||||||
if (ArrayLevel == arrayLevel && MipLevel == mipLevel)
|
Console.WriteLine($"size " + size);
|
||||||
return result_;
|
|
||||||
}
|
if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
|
||||||
catch (Exception e)
|
blockHeightShift += 1;
|
||||||
{
|
|
||||||
System.Windows.Forms.MessageBox.Show($"Failed to swizzle texture {texture.Text}!");
|
|
||||||
Console.WriteLine(e);
|
uint width__ = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth);
|
||||||
|
uint height__ = TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight);
|
||||||
return new byte[0];
|
|
||||||
|
//Calculate the mip size instead
|
||||||
|
byte[] AlignedData = new byte[(TegraX1Swizzle.round_up(SurfaceSize, DataAlignment) - SurfaceSize)];
|
||||||
|
SurfaceSize += (uint)AlignedData.Length;
|
||||||
|
MipOffsets.Add(SurfaceSize);
|
||||||
|
|
||||||
|
//Get the first mip offset and current one and the total image size
|
||||||
|
int msize = (int)((MipOffsets[0] + ImageData.Length - MipOffsets[mipLevel]) / texture.ArrayCount);
|
||||||
|
|
||||||
|
byte[] data_ = Utils.SubArray(ImageData, ArrayOffset + MipOffsets[mipLevel], (uint)msize);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Pitch = TegraX1Swizzle.round_up(width__ * bpp, 64);
|
||||||
|
SurfaceSize += Pitch * TegraX1Swizzle.round_up(height__, Math.Max(1, blockHeight >> blockHeightShift) * 8);
|
||||||
|
|
||||||
|
byte[] result = TegraX1Swizzle.deswizzle(width, height, depth, blkWidth, blkHeight, blkDepth, target, bpp, TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), data_);
|
||||||
|
//Create a copy and use that to remove uneeded data
|
||||||
|
byte[] result_ = new byte[size];
|
||||||
|
Array.Copy(result, 0, result_, 0, size);
|
||||||
|
result = null;
|
||||||
|
|
||||||
|
if (ArrayLevel == arrayLevel && MipLevel == mipLevel && DepthLevel == depthLevel)
|
||||||
|
return result_;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
System.Windows.Forms.MessageBox.Show($"Failed to swizzle texture {texture.Text}!");
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
ArrayOffset += (uint)(ImageData.Length / texture.ArrayCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayOffset += (uint)(ImageData.Length / texture.ArrayCount);
|
|
||||||
}
|
}
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
@ -222,7 +227,7 @@ namespace Toolbox.Library
|
|||||||
|
|
||||||
for (uint y = 0; y < height; y++)
|
for (uint y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (uint x = 0; x < width; x++)
|
for (uint x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
uint pos;
|
uint pos;
|
||||||
uint pos_;
|
uint pos_;
|
||||||
|
Loading…
Reference in New Issue
Block a user