示例#1
0
        private void btnTest1_Click(object sender, EventArgs e)
        {
            PropertyGridSimpleDemoClass gcd = new PropertyGridSimpleDemoClass();

            //prpG.SelectedObject = null;
            prpG.SelectedObject = gcd;
            lblTest.Text        = "Test 1";
        }
示例#2
0
        public BRTI(FileData f) //Docs thanks to gdkchan!!
        {
            ImageKey         = "texture";
            SelectedImageKey = "texture";

            if (!f.readString(4).Equals("BRTI"))
            {
                throw new Exception("Error reading Texture");
            }

            int  BRTISize1 = f.readInt();
            long BRTISize2 = (f.readInt() | f.readInt() << 32);

            surf = new Swizzle.Surface();

            surf.tileMode = (sbyte)f.readByte();
            surf.dim      = (sbyte)f.readByte();
            ushort Flags = (ushort)f.readShort();

            surf.swizzle = (ushort)f.readShort();
            surf.numMips = (ushort)f.readShort();
            uint unk18 = (uint)f.readInt();

            surf.format = (uint)f.readInt();
            byte DataType = (byte)(surf.format & 0xFF);
            uint unk20    = (uint)f.readInt();

            surf.width  = f.readInt();
            surf.height = f.readInt();
            surf.depth  = f.readInt();
            int FaceCount = f.readInt();

            surf.sizeRange = f.readInt();
            uint unk38 = (uint)f.readInt();
            uint unk3C = (uint)f.readInt();
            uint unk40 = (uint)f.readInt();
            uint unk44 = (uint)f.readInt();
            uint unk48 = (uint)f.readInt();
            uint unk4C = (uint)f.readInt();

            surf.imageSize = f.readInt();
            surf.alignment = f.readInt();
            int ChannelType = f.readInt();
            int TextureType = f.readInt();

            Text = f.readString((f.readOffset() | f.readOffset() << 32) + ExternalFiles.DataOffset + 2, -1);
            long ParentOffset = f.readOffset() | f.readOffset() << 32;
            long PtrsOffset   = f.readOffset() | f.readOffset() << 32;

            Console.WriteLine($"ParentOffset {ParentOffset} PtrsOffset {PtrsOffset}");

            f.seek((int)PtrsOffset + ExternalFiles.DataOffset);
            long dataOff = f.readOffset() | f.readOffset() << 32;

            surf.data = f.getSection((int)dataOff + ExternalFiles.DataOffset, surf.imageSize);
            //Console.WriteLine(surf.data.Length + " " + dataOff.ToString("x") + " " + surf.imageSize);

            uint blk_dim   = Formats.blk_dims(surf.format >> 8);
            uint blkWidth  = blk_dim >> 4;
            uint blkHeight = blk_dim & 0xF;

            uint bpp = Formats.bpps(surf.format >> 8);

            Console.WriteLine($"{Text} Height {surf.height}wdith = {surf.width}allignment = {surf.alignment}blkwidth = {blkWidth}blkheight = {blkHeight}blkdims = {blk_dim} format = {surf.format} datatype = {DataType} dataoffset = {dataOff}");


            // byte[] result = surf.data;



            byte[] result = Swizzle.deswizzle((uint)surf.width, (uint)surf.height, blkWidth, blkHeight, bpp, (uint)surf.tileMode, (uint)surf.alignment, surf.sizeRange, surf.data, 0);


            uint width  = Swizzle.DIV_ROUND_UP((uint)surf.width, blkWidth);
            uint height = Swizzle.DIV_ROUND_UP((uint)surf.height, blkHeight);

            byte[] result_ = new byte[width * height * bpp];

            Array.Copy(result, 0, result_, 0, width * height * bpp);



            tex.mipmaps.Add(result_);
            tex.width  = surf.width;
            tex.height = surf.height;

            //File.WriteAllBytes(dataOff.ToString("x") + ".bin" ,data);

            PropertyGridSimpleDemoClass propgrid = new PropertyGridSimpleDemoClass();

            switch (surf.format >> 8)
            {
            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC1):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                    propgrid.Format = "FORMAT_T_BC1_UNORM";
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    tex.type        = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt1Ext;
                    propgrid.Format = "FORMAT_T_BC1_SRGB";
                }
                else
                {
                    throw new Exception("Unsupported data type");
                }

                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC2):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    tex.type = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                }

                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    tex.type = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
                }

                else
                {
                    throw new Exception("Unsupported data type");
                }
                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC3):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                    propgrid.Format = "FORMAT_T_BC3_UNORM";
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SRGB)
                {
                    tex.type        = PixelInternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
                    propgrid.Format = "FORMAT_T_BC3_SRGB";
                }
                else
                {
                    throw new Exception("Unsupported data type");
                }

                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC4):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedRedRgtc1;
                    propgrid.Format = "FORMAT_T_BC4_UNORM";
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedSignedRedRgtc1;
                    propgrid.Format = "FORMAT_T_BC4_SNORM";
                }
                else
                {
                    throw new Exception("Unsupported data type");
                }

                break;

            case ((uint)Formats.BNTXImageFormat.IMAGE_FORMAT_BC5):
                if (DataType == (byte)Formats.BNTXImageTypes.UNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedRedRgtc1;
                    propgrid.Format = "FORMAT_T_BC5_UNORM";
                }
                else if (DataType == (byte)Formats.BNTXImageTypes.SNORM)
                {
                    tex.type        = PixelInternalFormat.CompressedSignedRedRgtc1;
                    propgrid.Format = "FORMAT_T_BC5_SNORM";
                }
                else
                {
                    Console.WriteLine("Unsupported data type");
                }

                break;

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

                break;

            default:
                MessageBox.Show($"Error! Unsupported texture type for {Text}", "Error");
                break;
            }

            tex.load();



            //Property grid stuff
        }