Esempio n. 1
0
        public void ReadFTEX(Texture tex)
        {
            ImageKey         = "texture";
            SelectedImageKey = "texture";

            reserve = tex.Data;

            texture.width  = (int)tex.Width;
            texture.height = (int)tex.Height;
            format         = (int)tex.Format;
            int swizzle = (int)tex.Swizzle;
            int pitch   = (int)tex.Pitch;

            texture.data = Gtx.SwizzleBc(tex.Data, texture.width, texture.height, format, (int)tex.TileMode, pitch, swizzle);
            Text         = tex.Name;


            //Setup variables for treenode data

            width  = texture.width;
            height = texture.height;
            texture.mipMapCount = (int)tex.MipCount;

            FileData f = new FileData(tex.MipData);

            for (int level = 0; level < tex.MipCount; level++)
            {
                if (level != 0)
                {
                }

                //  byte[] mip = f.getSection((int)tex.MipOffsets[level - 1], (int)tex.MipOffsets[level + 1]);

                //  texture.mipMapData.Add(mip);
            }

            switch (format)
            {
            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc1Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc1Srgb):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc2Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc2Srgb):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc3Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc3Srgb):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc4Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc4Snorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc5Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTBc5Snorm):
                //OpenTK doesn't load BC5 SNORM textures right so I'll use the same decompress method bntx has
                byte[] fixBC5 = DDS_Decompress.DecompressBC5(texture.data, texture.width, texture.height, true);
                texture.data = fixBC5;
                texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;

                break;

            case ((int)Gtx.Gx2SurfaceFormat.Gx2SurfaceFormatTcsR8G8B8A8Unorm):
                texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                break;
            }
        }
Esempio n. 2
0
        private void LoadFormats(BRTI_Texture texture, uint format, int mipLevel, int width, int height)
        {
            switch (format >> 8)
            {
            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC1):
                texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC2):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC2");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC3):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC3");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC4):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRedRgtc1;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedSignedRedRgtc1;
                }
                else
                {
                    throw new Exception("Unsupported data type for BC4");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC5):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    //    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgRgtc2;


                    byte[] fixBC5 = DDS_Decompress.DecompressBC5(texture.mipmaps[mipLevel], width, height, true);
                    texture.mipmaps[mipLevel]   = fixBC5;
                    texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                    texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                }
                else
                {
                    Console.WriteLine("Unsupported data type for BC5");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC7):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM || DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.CompressedRgbaBptcUnorm;
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_R8_G8_B8_A8):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM || DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    texture.pixelInternalFormat = PixelInternalFormat.Rgba;
                    texture.pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.Rgba;
                }
                else
                {
                    throw new Exception("Unsupported data type for R8_G8_B8_A8");
                }
                break;
            }
        }