public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { int swizzle = (int)Swizzle; int pitch = (int)0; uint bpp = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3; GX2.GX2Surface surf = new GX2.GX2Surface(); surf.bpp = bpp; surf.height = Height; surf.width = Width; surf.aa = (uint)0; surf.alignment = Alignment; surf.depth = Depth; surf.dim = 0x1; surf.format = GX2Format; surf.use = 0x1; surf.pitch = 0; surf.data = data; surf.mipData = data; surf.numMips = MipCount; surf.tileMode = TileMode; surf.swizzle = Swizzle; surf.imageSize = ImageSize; // GX2.GenerateMipSurfaceData(surf); return(GX2.Decode(surf, ArrayLevel, MipLevel)); }
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { format = (int)texture.Format; int swizzle = (int)texture.Swizzle; int pitch = (int)texture.Pitch; uint bpp = GX2.surfaceGetBitsPerPixel((uint)format) >> 3; RedChannel = GX2ChanneToGeneric(texture.CompSelR); GreenChannel = GX2ChanneToGeneric(texture.CompSelG); BlueChannel = GX2ChanneToGeneric(texture.CompSelB); AlphaChannel = GX2ChanneToGeneric(texture.CompSelA); UpdateMipMaps(); GX2.GX2Surface surf = new GX2.GX2Surface(); surf.bpp = bpp; surf.height = texture.Height; surf.width = texture.Width; surf.aa = (uint)texture.AAMode; surf.alignment = texture.Alignment; surf.depth = texture.Depth; surf.dim = (uint)texture.Dim; surf.format = (uint)texture.Format; surf.use = (uint)texture.Use; surf.pitch = texture.Pitch; surf.data = texture.Data; surf.numMips = MipCount; surf.mipOffset = texture.MipOffsets; surf.mipData = texture.MipData; surf.tileMode = (uint)texture.TileMode; surf.swizzle = texture.Swizzle; surf.numArray = texture.ArrayLength; if (Tex2Swizzle != 0) { surf.mip_swizzle = Tex2Swizzle; } if (surf.mipData == null) { surf.numMips = 1; } var surfaces = GX2.Decode(surf); if (ArrayLevel >= surfaces.Count) { throw new Exception("Invalid amount of surfaces decoded!"); } if (surfaces.Count == 0) { throw new Exception("Surfaces came out empty!"); } return(surfaces[ArrayLevel][MipLevel]); }
public byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0, int DepthLevel = 0) { format = (int)texture.Format; int swizzle = (int)texture.Swizzle; int pitch = (int)texture.Pitch; uint bpp = GX2.surfaceGetBitsPerPixel((uint)format) >> 3; RedChannel = GX2ChanneToGeneric(texture.CompSelR); GreenChannel = GX2ChanneToGeneric(texture.CompSelG); BlueChannel = GX2ChanneToGeneric(texture.CompSelB); AlphaChannel = GX2ChanneToGeneric(texture.CompSelA); UpdateMipMaps(); GX2.GX2Surface surf = new GX2.GX2Surface(); surf.bpp = bpp; surf.height = texture.Height; surf.width = texture.Width; surf.aa = (uint)texture.AAMode; surf.alignment = texture.Alignment; surf.depth = texture.Depth; surf.dim = (uint)texture.Dim; surf.format = (uint)texture.Format; surf.use = (uint)texture.Use; surf.pitch = texture.Pitch; surf.data = texture.Data; surf.numMips = MipCount; surf.mipOffset = texture.MipOffsets; surf.mipData = texture.MipData; surf.tileMode = (uint)texture.TileMode; surf.swizzle = texture.Swizzle; surf.numArray = texture.ArrayLength; if (Tex2Swizzle != 0) { surf.mip_swizzle = Tex2Swizzle; } if (surf.mipData == null) { surf.numMips = 1; } return(GX2.Decode(surf, ArrayLevel, MipLevel)); }
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { int swizzle = (int)Swizzle; int pitch = (int)0; uint bpp = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3; GX2.GX2Surface surf = new GX2.GX2Surface(); surf.bpp = bpp; surf.height = Height; surf.width = Width; surf.aa = (uint)0; surf.alignment = Alignment; surf.depth = Depth; surf.dim = 0x1; surf.format = GX2Format; surf.use = 0x1; surf.pitch = 0; surf.data = data; surf.numMips = MipCount; surf.mipOffset = new uint[MipCount]; surf.mipData = null; surf.tileMode = TileMode; surf.swizzle = Swizzle; surf.imageSize = ImageSize; // GX2.GenerateMipSurfaceData(surf); foreach (var mipoffset in surf.mipOffset) { Console.WriteLine($"mipoffset {mipoffset}"); } var surfaces = GX2.Decode(surf); return(surfaces[ArrayLevel][MipLevel]); }
private void ReadGx2(FileReader reader) { reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; header = new GTXHeader(); header.Read(reader); Console.WriteLine("header size " + header.HeaderSize); uint surfBlockType; uint dataBlockType; uint mipBlockType; uint vertexShaderHeader = 0x03; uint vertexShaderProgram = 0x05; uint pixelShaderHeader = 0x06; uint pixelShaderProgram = 0x07; uint geometryShaderHeader = 0x08; uint geometryShaderProgram = 0x09; uint userDataBlock = 0x10; if (header.MajorVersion == 6 && header.MinorVersion == 0) { surfBlockType = 0x0A; dataBlockType = 0x0B; mipBlockType = 0x0C; } else if (header.MajorVersion == 6 || header.MajorVersion == 7) { surfBlockType = 0x0B; dataBlockType = 0x0C; mipBlockType = 0x0D; } else { throw new Exception($"Unsupported GTX version {header.MajorVersion}"); } if (header.GpuVersion != 2) { throw new Exception($"Unsupported GPU version {header.GpuVersion}"); } reader.Position = header.HeaderSize; bool blockB = false; bool blockC = false; uint ImageInfo = 0; uint images = 0; while (reader.Position < reader.BaseStream.Length) { Console.WriteLine("BLOCK POS " + reader.Position + " " + reader.BaseStream.Length); GTXDataBlock block = new GTXDataBlock(); block.Read(reader); blocks.Add(block); bool BlockIsEmpty = block.BlockType == BlockType.AlignData || block.BlockType == BlockType.EndOfFile; //Here we use "if" instead of "case" statements as types vary between versions if ((uint)block.BlockType == surfBlockType) { ImageInfo += 1; blockB = true; var surface = new SurfaceInfoParse(); surface.Read(new FileReader(block.data)); if (surface.tileMode == 0 || surface.tileMode > 16) { throw new Exception($"Invalid tileMode {surface.tileMode}!"); } if (surface.numMips > 14) { throw new Exception($"Invalid number of mip maps {surface.numMips}!"); } TextureData textureData = new TextureData(); textureData.surface = surface; textureData.MipCount = surface.numMips; textureData.ArrayCount = surface.depth; textureData.Text = "Texture" + ImageInfo; Nodes.Add(textureData); textures.Add(textureData); } else if ((uint)block.BlockType == dataBlockType) { images += 1; blockC = true; data.Add(block.data); } else if ((uint)block.BlockType == mipBlockType) { mipMaps.Add(block.data); } else if ((uint)block.BlockType == vertexShaderHeader) { Nodes.Add(new BlockDisplay(block.data) { Text = "Vertex Shader Header" }); } else if ((uint)block.BlockType == vertexShaderProgram) { Nodes.Add(new BlockDisplay(block.data) { Text = "Vertex Shader Program" }); } else if ((uint)block.BlockType == pixelShaderHeader) { Nodes.Add(new BlockDisplay(block.data) { Text = "Pixel Shader Header" }); } else if ((uint)block.BlockType == pixelShaderProgram) { Nodes.Add(new BlockDisplay(block.data) { Text = "Pixel Shader Program" }); } else if ((uint)block.BlockType == geometryShaderHeader) { Nodes.Add(new BlockDisplay(block.data) { Text = "Geometry Shader Header" }); } else if ((uint)block.BlockType == geometryShaderProgram) { Nodes.Add(new BlockDisplay(block.data) { Text = "Geometry Shader Program" }); } else if (!BlockIsEmpty) { Nodes.Add(new BlockDisplay(block.data) { Text = $"Block Type {block.BlockType.ToString("X")}" }); } } if (textures.Count != data.Count) { throw new Exception($"Bad size! {textures.Count} {data.Count}"); } int curTex = 0; int curMip = 0; foreach (var node in Nodes) { if (node is TextureData) { TextureData tex = (TextureData)node; tex.surface.data = data[curTex]; tex.surface.bpp = GX2.surfaceGetBitsPerPixel(tex.surface.format) >> 3; tex.Format = FTEX.ConvertFromGx2Format((Syroot.NintenTools.Bfres.GX2.GX2SurfaceFormat)tex.surface.format); tex.Width = tex.surface.width; tex.Height = tex.surface.height; if (tex.surface.numMips > 1) { tex.surface.mipData = mipMaps[curMip++]; } else { tex.surface.mipData = new byte[0]; } if (tex.surface.mipData == null) { tex.surface.numMips = 1; } curTex++; } } }
public override byte[] GetImageData(int ArrayLevel = 0, int MipLevel = 0) { uint GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM; switch (SurfFormat) { case SurfaceFormat.T_BC1_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC1_UNORM; Format = TEX_FORMAT.BC1_UNORM; break; case SurfaceFormat.T_BC1_SRGB: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC1_SRGB; Format = TEX_FORMAT.BC1_UNORM_SRGB; break; case SurfaceFormat.T_BC2_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC2_UNORM; Format = TEX_FORMAT.BC2_UNORM; break; case SurfaceFormat.T_BC2_SRGB: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC2_SRGB; Format = TEX_FORMAT.BC2_UNORM_SRGB; break; case SurfaceFormat.T_BC3_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC3_UNORM; Format = TEX_FORMAT.BC3_UNORM; break; case SurfaceFormat.T_BC3_SRGB: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC3_SRGB; Format = TEX_FORMAT.BC3_UNORM_SRGB; break; case SurfaceFormat.T_BC4_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC4_UNORM; Format = TEX_FORMAT.BC4_UNORM; break; case SurfaceFormat.T_BC4_SNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC4_SNORM; Format = TEX_FORMAT.BC4_SNORM; break; case SurfaceFormat.T_BC5_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_UNORM; Format = TEX_FORMAT.BC5_UNORM; break; case SurfaceFormat.T_BC5_SNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.T_BC5_SNORM; Format = TEX_FORMAT.BC5_SNORM; break; case SurfaceFormat.TC_R8_G8_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.TC_R8_G8_UNORM; Format = TEX_FORMAT.R8G8_UNORM; break; case SurfaceFormat.TCS_R8_G8_B8_A8_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNORM; Format = TEX_FORMAT.R8G8B8A8_UNORM; break; case SurfaceFormat.TCS_R8_G8_B8_A8: GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNORM; Format = TEX_FORMAT.R8G8B8A8_UNORM; break; case SurfaceFormat.TC_R8_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.TC_R8_UNORM; Format = TEX_FORMAT.R8_UNORM; break; case SurfaceFormat.TCS_R5_G6_B5_UNORM: GX2Format = (uint)GX2.GX2SurfaceFormat.TCS_R5_G6_B5_UNORM; Format = TEX_FORMAT.B5G6R5_UNORM; break; default: throw new Exception("Format unsupported! " + SurfFormat); } int swizzle = (int)Swizzle; int pitch = (int)0; uint bpp = GX2.surfaceGetBitsPerPixel(GX2Format) >> 3; GX2.GX2Surface surf = new GX2.GX2Surface(); surf.bpp = bpp; surf.height = Height; surf.width = Width; surf.aa = (uint)0; surf.alignment = 0; surf.depth = Depth; surf.dim = 0x1; surf.format = GX2Format; surf.use = 0x1; surf.pitch = 0; surf.data = data; surf.numMips = 1; surf.mipOffset = new uint[0]; surf.mipData = null; surf.tileMode = TileMode; surf.swizzle = Swizzle; surf.imageSize = ImageSize; var surfaces = GX2.Decode(surf); return(surfaces[ArrayLevel][MipLevel]); }