private byte[] DecodeWithoutOpenGLDecoder(byte[] ImageData, uint width, uint height, STGenericTexture GenericTexture) { if (!UseOpenGLDecoder) { return(STGenericTexture.ConvertBgraToRgba( STGenericTexture.DecodeBlock(ImageData, width, height, GenericTexture.Format, GenericTexture.GetPaletteData(), GenericTexture.Parameters, GenericTexture.PaletteFormat, GenericTexture.PlatformSwizzle))); } switch (GenericTexture.Format) { case TEX_FORMAT.BC1_UNORM: case TEX_FORMAT.BC1_UNORM_SRGB: case TEX_FORMAT.BC2_UNORM: case TEX_FORMAT.BC2_UNORM_SRGB: case TEX_FORMAT.BC3_UNORM: case TEX_FORMAT.BC3_UNORM_SRGB: case TEX_FORMAT.BC5_UNORM: case TEX_FORMAT.BC6H_SF16: case TEX_FORMAT.BC6H_UF16: case TEX_FORMAT.BC7_UNORM: case TEX_FORMAT.BC7_UNORM_SRGB: case TEX_FORMAT.R8G8B8A8_UNORM: case TEX_FORMAT.R8G8B8A8_UNORM_SRGB: return(ImageData); case TEX_FORMAT.BC5_SNORM: return(DDSCompressor.DecompressBC5(ImageData, (int)width, (int)height, true, true)); default: if (Runtime.UseDirectXTexDecoder) { return(STGenericTexture.ConvertBgraToRgba( STGenericTexture.DecodeBlock(ImageData, width, height, GenericTexture.Format, GenericTexture.GetPaletteData(), GenericTexture.Parameters, GenericTexture.PaletteFormat, GenericTexture.PlatformSwizzle))); } else { return(ImageData); } } }
public void LoadOpenGLTexture(STGenericTexture GenericTexture) { if (!Runtime.OpenTKInitialized || GLInitialized || Runtime.UseLegacyGL) { return; } if (GenericTexture.ArrayCount <= 0) { throw new Exception($"No texture data found with texture {GenericTexture.Text}"); } width = (int)GenericTexture.Width; height = (int)GenericTexture.Height; data = GenericTexture.GetImageData(0, 0); if (data.Length <= 0) { throw new Exception("Data is empty!"); } switch (GenericTexture.Format) { case TEX_FORMAT.BC1_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case TEX_FORMAT.BC1_UNORM_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext; break; case TEX_FORMAT.BC2_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case TEX_FORMAT.BC2_UNORM_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext; break; case TEX_FORMAT.BC3_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case TEX_FORMAT.BC3_UNORM_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext; break; case TEX_FORMAT.BC4_UNORM: case TEX_FORMAT.BC4_SNORM: //Convert to rgb to prevent red output //While shaders could prevent this, converting is easier and works fine across all editors data = STGenericTexture.DecodeBlock(data, GenericTexture.Width, GenericTexture.Height, GenericTexture.Format, GenericTexture.PlatformSwizzle); pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; // pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1; // pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1; break; case TEX_FORMAT.BC5_SNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2; data = DDSCompressor.DecompressBC5(GenericTexture.GetImageData(0, 0), (int)GenericTexture.Width, (int)GenericTexture.Height, true, true); pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case TEX_FORMAT.BC5_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2; break; case TEX_FORMAT.BC6H_UF16: pixelInternalFormat = PixelInternalFormat.CompressedRgbBptcUnsignedFloat; break; case TEX_FORMAT.BC6H_SF16: pixelInternalFormat = PixelInternalFormat.CompressedRgbBptcSignedFloat; break; case TEX_FORMAT.BC7_UNORM: pixelInternalFormat = PixelInternalFormat.CompressedRgbaBptcUnorm; break; case TEX_FORMAT.BC7_UNORM_SRGB: pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaBptcUnorm; break; case TEX_FORMAT.R8G8B8A8_UNORM: pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; case TEX_FORMAT.R8G8B8A8_UNORM_SRGB: pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; default: data = STGenericTexture.DecodeBlock(data, GenericTexture.Width, GenericTexture.Height, GenericTexture.Format, GenericTexture.PlatformSwizzle); pixelInternalFormat = PixelInternalFormat.Rgba; pixelFormat = OpenTK.Graphics.OpenGL.PixelFormat.Rgba; break; } GLInitialized = true; TexID = loadImage(this); }