From cea6f264cd529d7cdd6a46c671208fc2a2a1c123 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sun, 25 Aug 2019 20:46:19 -0400 Subject: [PATCH] Some swizzle pattern fixes (Also fixes bflim issues) --- .../BFRES/Bfres Structs/SubFiles/FTEX.cs | 5 +++-- File_Format_Library/FileFormats/Texture/BFLIM.cs | 8 +++++--- .../TextureUI/Importers/GX2/CreateGx2Texture.cs | 2 +- .../TextureUI/Importers/GX2/GTXTextureImporter.cs | 4 +--- .../Texture Decoding/Wii U/GX2.cs | 14 ++++++++++---- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs index 4828bb61..3ea54c4b 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FTEX.cs @@ -193,10 +193,10 @@ namespace Bfres.Structs if (texture != null && texture.MipCount == 1) ReplaceTexture(FileName, Format, texture.MipCount); else - ReplaceTexture(FileName, Format, 0, null, false, false, false); + ReplaceTexture(FileName, Format, 0,0, null, false, false, false); } - public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, TEX_FORMAT[] SupportedFormats = null, + public void ReplaceTexture(string FileName, TEX_FORMAT DefaultFormat = TEX_FORMAT.UNKNOWN, uint MipMapCount = 0, uint swizzlePattern = 0, TEX_FORMAT[] SupportedFormats = null, bool IsSwizzleReadOnly = false, bool IsTileModeReadOnly = false, bool IsFormatReadOnly = false) { string ext = System.IO.Path.GetExtension(FileName); @@ -216,6 +216,7 @@ namespace Bfres.Structs GTXImporterSettings setting = SetImporterSettings(FileName, DefaultFormat); setting.MipSwizzle = Tex2Swizzle; + setting.SwizzlePattern = swizzlePattern; GTXTextureImporter importer = new GTXTextureImporter(); diff --git a/File_Format_Library/FileFormats/Texture/BFLIM.cs b/File_Format_Library/FileFormats/Texture/BFLIM.cs index 42024266..b34e4fa6 100644 --- a/File_Format_Library/FileFormats/Texture/BFLIM.cs +++ b/File_Format_Library/FileFormats/Texture/BFLIM.cs @@ -268,7 +268,7 @@ namespace FirstPlugin if (ofd.ShowDialog() != DialogResult.OK) return; FTEX ftex = new FTEX(); - ftex.ReplaceTexture(ofd.FileName, TEX_FORMAT.BC3_UNORM_SRGB, 1, bflim.SupportedFormats, true, true, false); + ftex.ReplaceTexture(ofd.FileName, TEX_FORMAT.BC3_UNORM_SRGB, 1, 0, bflim.SupportedFormats, false, true, false); if (ftex.texture != null) { bflim.Text = ftex.texture.Name; @@ -310,11 +310,13 @@ namespace FirstPlugin public override void Replace(string FileName) { + uint swizzle = (image.Swizzle >> 8) & 7; + FTEX ftex = new FTEX(); - ftex.ReplaceTexture(FileName, Format, 1, SupportedFormats, true, true, false); + ftex.ReplaceTexture(FileName, Format, 1, swizzle, SupportedFormats, true, true, false); if (ftex.texture != null) { - image.Swizzle = (byte)ftex.texture.Swizzle; + image.Swizzle = ftex.texture.Swizzle; image.BflimFormat = FormatsWiiU.FirstOrDefault(x => x.Value == ftex.Format).Key; image.Height = (ushort)ftex.texture.Height; image.Width = (ushort)ftex.texture.Width; diff --git a/File_Format_Library/GUI/TextureUI/Importers/GX2/CreateGx2Texture.cs b/File_Format_Library/GUI/TextureUI/Importers/GX2/CreateGx2Texture.cs index ab6e027e..cbd1792d 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/GX2/CreateGx2Texture.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/GX2/CreateGx2Texture.cs @@ -20,7 +20,7 @@ namespace FirstPlugin setting.TexHeight, setting.Depth, (uint)setting.Format, - setting.Swizzle, + setting.SwizzlePattern, (uint)setting.SurfaceDim, setting.MipCount); } diff --git a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs index c35204c6..84a6c53e 100644 --- a/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs +++ b/File_Format_Library/GUI/TextureUI/Importers/GX2/GTXTextureImporter.cs @@ -279,9 +279,7 @@ namespace FirstPlugin } private void SwizzleNum_ValueChanged(object sender, EventArgs e) { - // SelectedTexSettings.Swizzle &= GX2.SwizzleMask; - // SelectedTexSettings.Swizzle |= (uint)SwizzleNum.Value << 8; - SelectedTexSettings.Swizzle = (uint)SwizzleNum.Value; + SelectedTexSettings.SwizzlePattern = (uint)SwizzleNum.Value; } /// diff --git a/Switch_Toolbox_Library/Texture Decoding/Wii U/GX2.cs b/Switch_Toolbox_Library/Texture Decoding/Wii U/GX2.cs index 13ea67c1..2bbc83dd 100644 --- a/Switch_Toolbox_Library/Texture Decoding/Wii U/GX2.cs +++ b/Switch_Toolbox_Library/Texture Decoding/Wii U/GX2.cs @@ -459,6 +459,10 @@ namespace Toolbox.Library else s = 0xd0000 | swizzle << 8; + s = 0xd0000 | swizzle << 8; + + Console.WriteLine("swizzle " + s); + uint blkWidth, blkHeight; if (GX2.IsFormatBCN((GX2SurfaceFormat)Format)) { @@ -537,10 +541,12 @@ namespace Toolbox.Library tiling1dLevel += 1; } - // if (tiling1dLevelSet) - // s |= (uint)(tiling1dLevel << 16); - // else - // s |= (uint)(13 << 16); + if (tiling1dLevelSet) + s |= (uint)(tiling1dLevel << 16); + else + s |= (uint)(13 << 16); + + Console.WriteLine("swizzle " + s); GX2.GX2Surface surf = new GX2.GX2Surface(); surf.depth = Depth;