public static void SetChannelsByFormat(GX2SurfaceFormat Format, Texture tex) { switch (Format) { case GX2SurfaceFormat.T_BC5_UNorm: tex.CompSelR = GX2CompSel.ChannelR; tex.CompSelG = GX2CompSel.ChannelG; tex.CompSelB = GX2CompSel.Always1; //This is important for botw tex.CompSelA = GX2CompSel.Always1; break; case GX2SurfaceFormat.T_BC5_SNorm: tex.CompSelR = GX2CompSel.ChannelR; tex.CompSelG = GX2CompSel.ChannelG; tex.CompSelB = GX2CompSel.Always0; tex.CompSelA = GX2CompSel.Always1; break; case GX2SurfaceFormat.T_BC4_SNorm: case GX2SurfaceFormat.T_BC4_UNorm: tex.CompSelR = GX2CompSel.ChannelR; tex.CompSelG = GX2CompSel.ChannelR; tex.CompSelB = GX2CompSel.ChannelR; tex.CompSelA = GX2CompSel.ChannelR; break; } }
public static GX2CompSel[] SetChannelsByFormat(GX2SurfaceFormat Format) { GX2CompSel[] channels = new GX2CompSel[4]; switch (Format) { case GX2SurfaceFormat.T_BC5_UNorm: case GX2SurfaceFormat.T_BC5_SNorm: channels[0] = GX2CompSel.ChannelR; channels[1] = GX2CompSel.ChannelG; channels[2] = GX2CompSel.Always0; channels[3] = GX2CompSel.Always1; break; case GX2SurfaceFormat.T_BC4_SNorm: case GX2SurfaceFormat.T_BC4_UNorm: channels[0] = GX2CompSel.ChannelR; channels[1] = GX2CompSel.ChannelR; channels[2] = GX2CompSel.ChannelR; channels[3] = GX2CompSel.ChannelR; break; default: channels[0] = GX2CompSel.ChannelR; channels[1] = GX2CompSel.ChannelG; channels[2] = GX2CompSel.ChannelB; channels[3] = GX2CompSel.Always1; break; } return(channels); }
public static TEX_FORMAT ConvertFromGx2Format(GX2SurfaceFormat GX2Format) { switch (GX2Format) { case GX2SurfaceFormat.T_BC1_UNorm: return(TEX_FORMAT.BC1_UNORM); case GX2SurfaceFormat.T_BC1_SRGB: return(TEX_FORMAT.BC1_UNORM_SRGB); case GX2SurfaceFormat.T_BC2_UNorm: return(TEX_FORMAT.BC2_UNORM); case GX2SurfaceFormat.T_BC2_SRGB: return(TEX_FORMAT.BC2_UNORM_SRGB); case GX2SurfaceFormat.T_BC3_UNorm: return(TEX_FORMAT.BC3_UNORM); case GX2SurfaceFormat.T_BC3_SRGB: return(TEX_FORMAT.BC3_UNORM_SRGB); case GX2SurfaceFormat.T_BC4_UNorm: return(TEX_FORMAT.BC4_UNORM); case GX2SurfaceFormat.T_BC4_SNorm: return(TEX_FORMAT.BC4_SNORM); case GX2SurfaceFormat.T_BC5_UNorm: return(TEX_FORMAT.BC5_UNORM); case GX2SurfaceFormat.T_BC5_SNorm: return(TEX_FORMAT.BC5_SNORM); case GX2SurfaceFormat.TC_R5_G5_B5_A1_UNorm: return(TEX_FORMAT.B5G5R5A1_UNORM); case GX2SurfaceFormat.TC_A1_B5_G5_R5_UNorm: return(TEX_FORMAT.B5G5R5A1_UNORM); case GX2SurfaceFormat.TC_R4_G4_B4_A4_UNorm: return(TEX_FORMAT.B4G4R4A4_UNORM); case GX2SurfaceFormat.TCS_R5_G6_B5_UNorm: return(TEX_FORMAT.B5G6R5_UNORM); case GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB: return(TEX_FORMAT.R8G8B8A8_UNORM_SRGB); case GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNorm: return(TEX_FORMAT.R8G8B8A8_UNORM); case GX2SurfaceFormat.TCS_R10_G10_B10_A2_UNorm: return(TEX_FORMAT.R10G10B10A2_UNORM); case GX2SurfaceFormat.TC_R11_G11_B10_Float: return(TEX_FORMAT.R11G11B10_FLOAT); case GX2SurfaceFormat.TCD_R16_UNorm: return(TEX_FORMAT.R16_UNORM); case GX2SurfaceFormat.TCD_R32_Float: return(TEX_FORMAT.R32_FLOAT); case GX2SurfaceFormat.T_R4_G4_UNorm: return(TEX_FORMAT.R4G4_UNORM); case GX2SurfaceFormat.TC_R8_G8_UNorm: return(TEX_FORMAT.R8G8_UNORM); case GX2SurfaceFormat.TC_R8_G8_SNorm: return(TEX_FORMAT.R8G8_SNORM); case GX2SurfaceFormat.TC_R8_UNorm: return(TEX_FORMAT.R8_UNORM); case GX2SurfaceFormat.TC_R16_G16_B16_A16_Float: return(TEX_FORMAT.R16G16B16A16_FLOAT); case GX2SurfaceFormat.Invalid: throw new Exception("Invalid Format"); default: throw new Exception($"Cannot convert format {GX2Format}"); } }
private static DDS.DXGI_FORMAT GetCompressedDXGI_FORMAT(GX2SurfaceFormat Format) { switch (Format) { case GX2SurfaceFormat.T_BC1_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM); case GX2SurfaceFormat.T_BC1_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC1_UNORM_SRGB); case GX2SurfaceFormat.T_BC2_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM); case GX2SurfaceFormat.T_BC2_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC2_UNORM_SRGB); case GX2SurfaceFormat.T_BC3_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM); case GX2SurfaceFormat.T_BC3_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC3_UNORM_SRGB); case GX2SurfaceFormat.T_BC4_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_UNORM); case GX2SurfaceFormat.T_BC4_SNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC4_SNORM); case GX2SurfaceFormat.T_BC5_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_UNORM); case GX2SurfaceFormat.T_BC5_SNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_BC5_SNORM); default: throw new Exception($"Cannot convert format {Format}"); } }
private static DDS.DXGI_FORMAT GetUncompressedDXGI_FORMAT(GX2SurfaceFormat Format) { switch (Format) { case GX2SurfaceFormat.TC_A1_B5_G5_R5_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B5G5R5A1_UNORM); case GX2SurfaceFormat.TC_R4_G4_B4_A4_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM); case GX2SurfaceFormat.TCS_R5_G6_B5_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B5G6R5_UNORM); case GX2SurfaceFormat.TCS_R8_G8_B8_A8_SRGB: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); case GX2SurfaceFormat.TCS_R8_G8_B8_A8_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8B8A8_UNORM); case GX2SurfaceFormat.TCS_R10_G10_B10_A2_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R10G10B10A2_UNORM); case GX2SurfaceFormat.TC_R11_G11_B10_Float: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R11G11B10_FLOAT); case GX2SurfaceFormat.TCD_R16_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R16_UNORM); case GX2SurfaceFormat.TCD_R32_Float: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R32_FLOAT); case GX2SurfaceFormat.T_R4_G4_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_B4G4R4A4_UNORM); case GX2SurfaceFormat.TC_R8_G8_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8G8_UNORM); case GX2SurfaceFormat.TC_R8_UNorm: return(DDS.DXGI_FORMAT.DXGI_FORMAT_R8_UNORM); case GX2SurfaceFormat.Invalid: throw new Exception("Invalid Format"); default: throw new Exception($"Cannot convert format {Format}"); } }
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, GX2SurfaceFormat Format) { Bitmap decomp; try { if (Format == GX2SurfaceFormat.T_BC5_SNorm) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true)); } byte[] d = null; if (IsCompressedFormat(Format)) { d = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, GetCompressedDXGI_FORMAT(Format)); } else { d = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, GetUncompressedDXGI_FORMAT(Format)); } if (d != null) { decomp = BitmapExtension.GetBitmap(d, (int)Width, (int)Height); return(SwapBlueRedChannels(decomp)); } return(BitmapExtension.GetBitmap(d, (int)Width, (int)Height));; } catch { throw new Exception($"Bad size from format {Format}"); } }
private static bool IsCompressedFormat(GX2SurfaceFormat Format) { switch (Format) { case GX2SurfaceFormat.T_BC1_UNorm: case GX2SurfaceFormat.T_BC1_SRGB: case GX2SurfaceFormat.T_BC2_UNorm: case GX2SurfaceFormat.T_BC2_SRGB: case GX2SurfaceFormat.T_BC3_UNorm: case GX2SurfaceFormat.T_BC3_SRGB: case GX2SurfaceFormat.T_BC4_UNorm: case GX2SurfaceFormat.T_BC4_SNorm: case GX2SurfaceFormat.T_BC5_UNorm: case GX2SurfaceFormat.T_BC5_SNorm: return(true); default: return(false); } }
private TEX_FORMAT ConvertFormat(GX2SurfaceFormat Format) { return(TEX_FORMAT.UNKNOWN); }
public static Texture AddTexture(string name, List <byte[]> images, int width, int height, int mipCount, GX2SurfaceFormat format) { Texture tex = null; //Go through each texture as an array or depth surface List <byte[]> imageData = new List <byte[]>(); List <byte[]> mipData = new List <byte[]>(); for (int i = 0; i < images.Count; i++) { //Swizzle and create surface var surface = GX2.CreateGx2Texture(images[i], name, (uint)GX2TileMode.Mode2dTiledThin1, (uint)GX2AAMode.Mode1X, (uint)width, (uint)height, (uint)1, (uint)format, (uint)0, (uint)GX2SurfaceDim.Dim2D, (uint)mipCount ); //Apply first surface if (i == 0) { tex = FromGx2Surface(surface, name); } imageData.Add(surface.data); mipData.Add(surface.mipData); } tex.Data = Utils.CombineByteArray(imageData.ToArray()); tex.MipData = Utils.CombineByteArray(mipData.ToArray()); tex.ArrayLength = (uint)images.Count; imageData.Clear(); mipData.Clear(); return(tex); }
public static Texture AddTexture(string name, byte[] image, int width, int height, int mipCount, GX2SurfaceFormat format) { return(AddTexture(name, new List <byte[]>() { image }, width, height, mipCount, format)); }