Esempio n. 1
0
        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();
                }
            }
        }
        /// <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);
            }
        }
Esempio n. 3
0
        /// <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;
             *     }*/
        }