Exemple #1
0
                public void LoadTexture()
                {
                    mipmaps.Clear();

                    Console.WriteLine(Format);

                    uint blk_dim   = XTXFormats.blk_dims((uint)((int)Format >> 8));
                    uint blkWidth  = blk_dim >> 4;
                    uint blkHeight = blk_dim & 0xF;

                    uint blockHeight     = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
                    uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;

                    int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;

                    int TileMode = 0;

                    uint bpp = XTXFormats.bpps((uint)Format);

                    int blockHeightShift = 0;

                    for (int mipLevel = 0; mipLevel < MipCount; mipLevel++)
                    {
                        uint width  = (uint)Math.Max(1, Width >> mipLevel);
                        uint height = (uint)Math.Max(1, Height >> mipLevel);

                        //  uint size = width * height * bpp;
                        uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;

                        byte[] mipData = GetMipBlock(MipOffsets[mipLevel], size);

                        if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
                        {
                            blockHeightShift += 1;
                        }

                        byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, (int)Target, bpp, (uint)TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), mipData);
                        //Create a copy and use that to remove uneeded data
                        byte[] result_ = new byte[size];
                        Array.Copy(result, 0, result_, 0, size);

                        mipmaps.Add(result_);
                        Console.WriteLine("bpp " + bpp);
                        Console.WriteLine("result_ " + size);
                        Console.WriteLine("width " + width);
                        Console.WriteLine("height " + height);
                    }
                }
Exemple #2
0
            public void LoadTexture()
            {
                Surfaces.Clear();

                Console.WriteLine(Format);

                uint blk_dim   = XTXFormats.blk_dims((uint)((int)Format >> 8));
                uint blkWidth  = blk_dim >> 4;
                uint blkHeight = blk_dim & 0xF;

                uint blockHeight     = TegraX1Swizzle.GetBlockHeight(TegraX1Swizzle.DIV_ROUND_UP(Height, blkHeight));
                uint BlockHeightLog2 = (uint)Convert.ToString(blockHeight, 2).Length - 1;

                int linesPerBlockHeight = (1 << (int)BlockHeightLog2) * 8;

                int TileMode = 0;

                uint          bpp  = XTXFormats.bpps((uint)Format);
                List <byte[]> mips = new List <byte[]>();

                int blockHeightShift = 0;

                for (int mipLevel = 0; mipLevel < MipOffsets.Length; mipLevel++)
                {
                    uint width  = (uint)Math.Max(1, Width >> mipLevel);
                    uint height = (uint)Math.Max(1, Height >> mipLevel);

                    //  uint size = width * height * bpp;
                    uint size = TegraX1Swizzle.DIV_ROUND_UP(width, blkWidth) * TegraX1Swizzle.DIV_ROUND_UP(height, blkHeight) * bpp;

                    byte[] Output = new byte[size];

                    uint mipOffset;
                    if (mipLevel != 0)
                    {
                        mipOffset = (MipOffsets[mipLevel - 1]);
                        if (mipLevel == 1)
                        {
                            mipOffset -= (uint)size;
                        }

                        Array.Copy(ImageData, mipOffset, Output, 0, size);
                    }
                    else
                    {
                        Output = ImageData;
                    }

                    byte[] output = new byte[size];
                    Console.WriteLine(mipLevel + " " + size);

                    if (TegraX1Swizzle.pow2_round_up(TegraX1Swizzle.DIV_ROUND_UP(height, blkWidth)) < linesPerBlockHeight)
                    {
                        blockHeightShift += 1;
                    }

                    byte[] result = TegraX1Swizzle.deswizzle(width, height, blkWidth, blkHeight, (int)Target, bpp, (uint)TileMode, (int)Math.Max(0, BlockHeightLog2 - blockHeightShift), Output);
                    //Create a copy and use that to remove uneeded data
                    byte[] result_ = new byte[size];
                    Array.Copy(result, 0, result_, 0, size);

                    mips.Add(result_);
                }
                Surfaces.Add(new Surface()
                {
                    mipmaps = mips
                });
            }