public void LoadOpenGLTexture() { if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized) { return; } switch (format) { case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_SRGB): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC2_SRGB): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_SRGB): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_SNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_SNORM): //OpenTK doesn't load BC5 SNORM textures right so I'll use the same decompress method bntx has byte[] fixBC5 = DDS_Decompress.DecompressBC5(renderedTex.data, renderedTex.width, renderedTex.height, true, true); renderedTex.data = fixBC5; renderedTex.pixelInternalFormat = PixelInternalFormat.Rgba; renderedTex.pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TCS_R8_G8_B8_A8_UNORM): renderedTex.pixelInternalFormat = PixelInternalFormat.Rgba; renderedTex.pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; } renderedTex.display = loadImage(renderedTex); }
//Gets the decompressed byte[] public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, SurfaceFormat Format) { Bitmap decomp; if (Format == SurfaceFormat.BC1_UNORM) { decomp = DDS_Decompress.DecompressBC1(data, (int)Width, (int)Height, false); } else if (Format == SurfaceFormat.BC1_SRGB) { decomp = DDS_Decompress.DecompressBC1(data, (int)Width, (int)Height, true); } else if (Format == SurfaceFormat.BC3_UNORM) { decomp = DDS_Decompress.DecompressBC3(data, (int)Width, (int)Height, false); } else if (Format == SurfaceFormat.BC3_SRGB) { decomp = DDS_Decompress.DecompressBC3(data, (int)Width, (int)Height, true); } else if (Format == SurfaceFormat.BC4_UNORM) { decomp = DDS_Decompress.DecompressBC4(data, (int)Width, (int)Height, false); } else if (Format == SurfaceFormat.BC4_SNORM) { decomp = DDS_Decompress.DecompressBC4(data, (int)Width, (int)Height, true); } else if (Format == SurfaceFormat.BC5_UNORM) { decomp = DDS_Decompress.DecompressBC5(data, (int)Width, (int)Height, false); } else if (Format == SurfaceFormat.BC5_SNORM) { decomp = DDS_Decompress.DecompressBC5(data, (int)Width, (int)Height, true); } else if (Format == SurfaceFormat.R8_UNORM) { decomp = DDS_PixelDecode.DecodeR8G8(data, (int)Width, (int)Height); } else if (Format == SurfaceFormat.R8_G8_B8_A8_SRGB) { decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); } else if (Format == SurfaceFormat.R8_G8_B8_A8_UNORM) { decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); } else { decomp = Properties.Resources.TextureError; Console.WriteLine($"Format {Format} not supported!"); // throw new Exception($"Format {Format} not supported!"); } return(decomp); }
public static Bitmap DecodeBlock(byte[] data, uint Width, uint Height, int Format) { Bitmap decomp; switch (Format) { case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_UNORM): decomp = DDS_Decompress.DecompressBC1(data, (int)Width, (int)Height, false); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC1_SRGB): decomp = DDS_Decompress.DecompressBC1(data, (int)Width, (int)Height, true); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_UNORM): decomp = DDS_Decompress.DecompressBC3(data, (int)Width, (int)Height, false); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC3_SRGB): decomp = DDS_Decompress.DecompressBC3(data, (int)Width, (int)Height, true); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_UNORM): decomp = DDS_Decompress.DecompressBC4(data, (int)Width, (int)Height, false); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC4_SNORM): decomp = DDS_Decompress.DecompressBC4(data, (int)Width, (int)Height, true); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_UNORM): decomp = DDS_Decompress.DecompressBC5(data, (int)Width, (int)Height, false); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_T_BC5_SNORM): decomp = DDS_Decompress.DecompressBC5(data, (int)Width, (int)Height, true); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_SNORM): decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); break; case ((int)GTX.GX2SurfaceFormat.GX2_SURFACE_FORMAT_TC_R8_G8_B8_A8_UINT): decomp = DDS_PixelDecode.DecodeR8G8B8A8(data, (int)Width, (int)Height); break; default: decomp = Properties.Resources.TextureError; Console.WriteLine($"Format {Format} not supported!"); break; } return(decomp); }
public void LoadOpenGLTexture() { if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized) { return; } LoadTexture(Texture); if (mipmaps.Count <= 0) { throw new Exception("No texture data found"); } renderedGLTex.data = mipmaps[0][0]; renderedGLTex.width = (int)Texture.Width; renderedGLTex.height = (int)Texture.Height; switch (Texture.Format) { case SurfaceFormat.BC1_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case SurfaceFormat.BC1_SRGB: renderedGLTex.type = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case SurfaceFormat.BC2_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case SurfaceFormat.BC2_SRGB: renderedGLTex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; break; case SurfaceFormat.BC3_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case SurfaceFormat.BC3_SRGB: renderedGLTex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; break; case SurfaceFormat.BC4_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRedRgtc1; break; case SurfaceFormat.BC4_SNORM: renderedGLTex.type = PixelInternalFormat.CompressedSignedRedRgtc1; break; case SurfaceFormat.BC5_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRgRgtc2; break; case SurfaceFormat.BC5_SNORM: renderedGLTex.data = DDS_Decompress.DecompressBC5(mipmaps[0][0], (int)Texture.Width, (int)Texture.Height, true, true); renderedGLTex.type = PixelInternalFormat.Rgba; renderedGLTex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case SurfaceFormat.BC6_FLOAT: renderedGLTex.type = PixelInternalFormat.CompressedRgbBptcSignedFloat; break; case SurfaceFormat.BC6_UFLOAT: renderedGLTex.type = PixelInternalFormat.CompressedRgbBptcUnsignedFloat; break; case SurfaceFormat.BC7_SRGB: renderedGLTex.type = PixelInternalFormat.CompressedSrgbAlphaBptcUnorm; break; case SurfaceFormat.BC7_UNORM: renderedGLTex.type = PixelInternalFormat.CompressedRgbaBptcUnorm; break; case SurfaceFormat.R8_G8_B8_A8_SRGB: renderedGLTex.type = PixelInternalFormat.Rgba; renderedGLTex.utype = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; } renderedGLTex.display = loadImage(renderedGLTex); }