public void LoadTextures() { textureImageList.Images.Clear(); textureListView.Items.Clear(); textureListView.LargeImageList = textureImageList; textureListView.FullRowSelect = true; int CurTex = 0; foreach (BNTX bntx in PluginRuntime.bntxContainers) { foreach (TextureData item in bntx.Textures.Values) { ListViewItem it = new ListViewItem(); it.Text = item.Text; it.ImageIndex = CurTex++; textureListView.Items.Add(it); TextureData tex = bntx.Textures[item.Text]; tex.LoadOpenGLTexture(); RenderableTex renderedTex = tex.RenderableTex; Bitmap temp = RenderableTex.GLTextureToBitmap(renderedTex, renderedTex.display); textureImageList.Images.Add(tex.Text, temp); var dummy = textureImageList.Handle; temp.Dispose(); } } }
public static int getImageSize(RenderableTex t) { switch (t.pixelInternalFormat) { case PixelInternalFormat.CompressedRgbaS3tcDxt1Ext: case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext: case PixelInternalFormat.CompressedRedRgtc1: case PixelInternalFormat.CompressedSignedRedRgtc1: return(t.width * t.height / 2); case PixelInternalFormat.CompressedRgbaS3tcDxt3Ext: case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext: case PixelInternalFormat.CompressedRgbaS3tcDxt5Ext: case PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext: case PixelInternalFormat.CompressedSignedRgRgtc2: case PixelInternalFormat.CompressedRgRgtc2: return(t.width * t.height); case PixelInternalFormat.Rgba: return(t.data.Length); default: return(t.data.Length); } }
public void DisposeRenderable() { if (RenderableTex != null && Runtime.UseOpenGL) { RenderableTex.Dispose(); RenderableTex = null; } }
public void DisposeRenderable() { if (RenderableTex != null) { RenderableTex.Dispose(); RenderableTex = null; } }
public void LoadCustomTexture(STGenericTexture GenericTexture) { if (GenericTexture.RenderableTex == null || !GenericTexture.RenderableTex.GLInitialized) { GenericTexture.LoadOpenGLTexture(); } CustomCubemap = GenericTexture.RenderableTex; }
public STGenericTexture() { RenderableTex = new RenderableTex(); RenderableTex.GLInitialized = false; RedChannel = STChannelType.Red; GreenChannel = STChannelType.Green; BlueChannel = STChannelType.Blue; AlphaChannel = STChannelType.Alpha; }
public void LoadOpenGLTexture() { if (RenderableTex == null) { RenderableTex = new RenderableTex(); } RenderableTex.GLInitialized = false; RenderableTex.LoadOpenGLTexture(this); }
public unsafe Bitmap GLTextureToBitmap(RenderableTex t, int id) { Bitmap bitmap = new Bitmap(t.width, t.height); System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, t.width, t.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.BindTexture(TextureTarget.Texture2D, id); GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bitmapData.Scan0); bitmap.UnlockBits(bitmapData); return(bitmap); }
public void LoadOpenGLTexture() { if (!Runtime.UseOpenGL) { return; } if (RenderableTex == null) { RenderableTex = new RenderableTex(); } RenderableTex.GLInitialized = false; RenderableTex.LoadOpenGLTexture(this); }
public static int loadImage(RenderableTex t) { int texID = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, texID); if (t.pixelInternalFormat != PixelInternalFormat.Rgba) { GL.CompressedTexImage2D <byte>(TextureTarget.Texture2D, 0, (InternalFormat)t.pixelInternalFormat, t.width, t.height, 0, getImageSize(t), t.data); //Debug.WriteLine(GL.GetError()); } else { GL.TexImage2D <byte>(TextureTarget.Texture2D, 0, t.pixelInternalFormat, t.width, t.height, 0, t.pixelFormat, PixelType.UnsignedByte, t.data); } GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); return(texID); }
private Bitmap DecodeNotDirectXTex(byte[] data, uint Width, uint Height, TEX_FORMAT Format) { if (Format == TEX_FORMAT.R8G8B8A8_UNORM) { return(BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.R8G8B8A8_UNORM_SRGB) { return(BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.BC1_UNORM) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC1_UNORM_SRGB) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC3_UNORM_SRGB) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC3_UNORM) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC4_UNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC4_SNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC5_UNORM) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC7_UNORM) { return(BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height)); } else if (Format == TEX_FORMAT.BC7_UNORM_SRGB) { return(BitmapExtension.GetBitmap(CSharpImageLibrary.DDS.Dxt.DecompressBc7(data, (int)Width, (int)Height), (int)Width, (int)Height)); } else { if (Runtime.UseOpenGL) { Runtime.OpenTKInitialized = true; if (RenderableTex == null || !RenderableTex.GLInitialized) { LoadOpenGLTexture(); } return(RenderableTex.ToBitmap()); } } return(null); }
public void LoadTexture(STGenericTexture tex) { RenderableTex renderedTex = tex.RenderableTex; }
/// <summary> /// Gets a <see cref="Bitmap"/> given an array and mip index. /// </summary> /// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param> /// <param name="MipLevel">The index of the mip level.</param> /// <returns></returns> public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0) { uint width = Math.Max(1, Width >> MipLevel); uint height = Math.Max(1, Height >> MipLevel); byte[] data = GetImageData(ArrayLevel, MipLevel); try { if (data == null) { throw new Exception("Data is null!"); } if (PlatformSwizzle == PlatformSwizzle.Platform_3DS && !IsCompressed(Format)) { var Image = BitmapExtension.GetBitmap(ConvertBgraToRgba(CTR_3DS.DecodeBlock(data, (int)width, (int)height, Format)), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Image.RotateFlip(RotateFlipType.RotateNoneFlipY); //It's upside down for some reason so flip it return(Image); } switch (Format) { case TEX_FORMAT.R4G4_UNORM: return(BitmapExtension.GetBitmap(R4G4.Decompress(data, (int)width, (int)height, false), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); case TEX_FORMAT.BC5_SNORM: return(DDSCompressor.DecompressBC5(data, (int)width, (int)height, true)); case TEX_FORMAT.ETC1: return(BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, false), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); case TEX_FORMAT.ETC1_A4: return(BitmapExtension.GetBitmap(ETC1.ETC1Decompress(data, (int)width, (int)height, true), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); default: return(BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)); } } catch (Exception ex) { Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); try { if (Format == TEX_FORMAT.BC1_UNORM) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC1_UNORM_SRGB) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC3_UNORM_SRGB) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC3_UNORM) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC4_UNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC4_SNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC5_UNORM) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false)); } else { if (Runtime.UseOpenGL) { Runtime.OpenTKInitialized = true; LoadOpenGLTexture(); return(RenderableTex.GLTextureToBitmap(RenderableTex)); } } } catch { Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); } return(null); } }
public void Read(Texture tex) { ImageKey = "Texture"; SelectedImageKey = "Texture"; Text = tex.Name; texture = tex; Width = tex.Width; Height = tex.Height; Format = ConvertFormat(tex.Format); format = (int)tex.Format; int swizzle = (int)tex.Swizzle; int pitch = (int)tex.Pitch; uint bpp = GTX.surfaceGetBitsPerPixel((uint)format) >> 3; GTX.GX2Surface surf = new GTX.GX2Surface(); surf.bpp = bpp; surf.height = tex.Height; surf.width = tex.Width; surf.aa = (uint)tex.AAMode; surf.alignment = tex.Alignment; surf.depth = tex.Depth; surf.dim = (uint)tex.Dim; surf.format = (uint)tex.Format; surf.use = (uint)tex.Use; surf.pitch = tex.Pitch; surf.data = tex.Data; surf.numMips = tex.MipCount; surf.mipOffset = tex.MipOffsets; surf.mipData = tex.MipData; surf.tileMode = (uint)tex.TileMode; surf.swizzle = tex.Swizzle; //Determine tex2 botw files to get mip maps string Tex1 = GetFilePath(); if (Tex1.Contains(".Tex1")) { string Tex2 = Tex1.Replace(".Tex1", ".Tex2"); Console.WriteLine(Tex2); if (System.IO.File.Exists(Tex2)) { ResFile resFile2 = new ResFile(new System.IO.MemoryStream( EveryFileExplorer.YAZ0.Decompress(Tex2))); if (resFile2.Textures.ContainsKey(tex.Name)) { surf.mipData = resFile2.Textures[tex.Name].MipData; surf.mipOffset = resFile2.Textures[tex.Name].MipOffsets; } } } if (surf.mipData == null) { surf.numMips = 1; } List <byte[]> mips = GTX.Decode(surf); Surfaces.Add(new Surface() { mipmaps = mips }); RenderableTex.LoadOpenGLTexture(this); }
/// <summary> /// Gets a <see cref="Bitmap"/> given an array and mip index. /// </summary> /// <param name="ArrayIndex">The index of the surface/array. Cubemaps will have 6</param> /// <param name="MipLevel">The index of the mip level.</param> /// <returns></returns> public Bitmap GetBitmap(int ArrayLevel = 0, int MipLevel = 0) { uint width = Math.Max(1, Width >> MipLevel); uint height = Math.Max(1, Height >> MipLevel); byte[] data = GetImageData(ArrayLevel, MipLevel); try { if (data == null) { throw new Exception("Data is null!"); } if (Format == TEX_FORMAT.BC5_SNORM) { return(DDSCompressor.DecompressBC5(data, (int)width, (int)height, true)); } Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format), (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); return(bitmap); } catch (Exception ex) { Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); try { if (Format == TEX_FORMAT.BC1_UNORM) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC1_UNORM_SRGB) { return(DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC3_UNORM_SRGB) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC3_UNORM) { return(DDSCompressor.DecompressBC3(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC4_UNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, false)); } else if (Format == TEX_FORMAT.BC4_SNORM) { return(DDSCompressor.DecompressBC4(data, (int)Width, (int)Height, true)); } else if (Format == TEX_FORMAT.BC5_UNORM) { return(DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, false)); } else { Runtime.OpenTKInitialized = true; LoadOpenGLTexture(); return(RenderableTex.GLTextureToBitmap(RenderableTex)); } } catch { Forms.STErrorDialog.Show($"Texture failed to load!", "Texture [GetBitmap({MipLevel},{ArrayLevel})]", DebugInfo() + " \n" + ex); } return(null); } /* try * { * Bitmap bitmap = BitmapExtension.GetBitmap(DecodeBlock(data, width, height, Format), * (int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); * * return bitmap; * } * catch (Exception ex) * { * MessageBox.Show($"Failed to texture {Text} \n{DebugInfo()}\n {ex.ToString()}"); * return null; * }*/ }
public STGenericTexture() { RenderableTex = new RenderableTex(); RenderableTex.GLInitialized = false; }