Exemplo n.º 1
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            texture.Format = ConvertToGx2Format(Format);
            texture.Width  = (uint)bitmap.Width;
            texture.Height = (uint)bitmap.Height;
            uint swizzle = (texture.Swizzle >> 8) & 7;

            if (MipCount != 1)
            {
                MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
                if (MipCount == 0)
                {
                    MipCount = 1;
                }
            }

            texture.MipCount   = MipCount;
            texture.MipOffsets = new uint[MipCount];

            try
            {
                //Create image block from bitmap first
                var data = GenerateMipsAndCompress(bitmap, MipCount, Format);

                bitmap.Dispose();

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, Text,
                                                   (uint)texture.TileMode,
                                                   (uint)texture.AAMode,
                                                   (uint)texture.Width,
                                                   (uint)texture.Height,
                                                   (uint)texture.Depth,
                                                   (uint)texture.Format,
                                                   (uint)swizzle,
                                                   (uint)texture.Dim,
                                                   (uint)texture.MipCount
                                                   );

                var tex = FromGx2Surface(surface, texture.Name);
                UpdateTex(tex);

                IsEdited = true;
                Read(texture);
                LoadOpenGLTexture();
                LibraryGUI.UpdateViewport();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Exemplo n.º 2
0
            public override void SetImageData(Bitmap bitmap, int ArrayLevel)
            {
                if (bitmap == null)
                {
                    return; //Image is likely disposed and not needed to be applied
                }
                RedChannel   = SetChannel(surface.compSel[0]);
                GreenChannel = SetChannel(surface.compSel[1]);
                BlueChannel  = SetChannel(surface.compSel[2]);
                AlphaChannel = SetChannel(surface.compSel[3]);

                surface.format = (uint)FTEX.ConvertToGx2Format(Format);
                surface.width  = (uint)bitmap.Width;
                surface.height = (uint)bitmap.Height;

                if (MipCount != 1)
                {
                    MipCount = GenerateMipCount(bitmap.Width, bitmap.Height);
                    if (MipCount == 0)
                    {
                        MipCount = 1;
                    }
                }

                surface.numMips   = MipCount;
                surface.mipOffset = new uint[MipCount];

                try
                {
                    //Create image block from bitmap first
                    var data = GenerateMipsAndCompress(bitmap, MipCount, Format);

                    //Swizzle and create surface
                    var NewSurface = GX2.CreateGx2Texture(data, Text,
                                                          (uint)surface.tileMode,
                                                          (uint)surface.aa,
                                                          (uint)surface.width,
                                                          (uint)surface.height,
                                                          (uint)surface.depth,
                                                          (uint)surface.format,
                                                          (uint)surface.swizzle,
                                                          (uint)surface.dim,
                                                          (uint)surface.numMips
                                                          );

                    ApplySurface(NewSurface);
                    IsEdited = true;
                    LoadOpenGLTexture();
                    LibraryGUI.Instance.UpdateViewport();
                }
                catch (Exception ex)
                {
                    STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
                }
            }
Exemplo n.º 3
0
 public static GX2.GX2Surface CreateGx2Texture(byte[] imageData, GTXImporterSettings setting)
 {
     return(GX2.CreateGx2Texture(imageData,
                                 setting.TexName,
                                 setting.tileMode,
                                 (uint)setting.AAMode,
                                 setting.TexWidth,
                                 setting.TexHeight,
                                 setting.Depth,
                                 (uint)setting.Format,
                                 setting.Swizzle,
                                 (uint)setting.SurfaceDim,
                                 setting.MipCount));
 }
Exemplo n.º 4
0
        public override void SetImageData(System.Drawing.Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null || image == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            MipCount = 1;
            var Gx2Format = FTEX.ConvertToGx2Format(Format);

            uint swizzle = (image.Swizzle >> 8) & 7;

            try
            {
                //Create image block from bitmap first
                var data = GenerateMipsAndCompress(bitmap, MipCount, Format);

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, Text,
                                                   (uint)image.TileMode,
                                                   (uint)0,
                                                   (uint)image.Width,
                                                   (uint)image.Height,
                                                   (uint)1,
                                                   (uint)Gx2Format,
                                                   (uint)swizzle,
                                                   (uint)1,
                                                   (uint)MipCount
                                                   );

                image.Swizzle     = surface.swizzle;
                image.BflimFormat = FormatsWiiU.FirstOrDefault(x => x.Value == Format).Key;
                image.Height      = (ushort)surface.height;
                image.Width       = (ushort)surface.width;

                Width  = image.Width;
                Height = image.Height;

                ImageData = surface.data;

                IsEdited = true;
                LoadOpenGLTexture();
                LibraryGUI.UpdateViewport();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Exemplo n.º 5
0
        public override void SetImageData(Bitmap bitmap, int ArrayLevel)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            uint Gx2Format = (uint)Bfres.Structs.FTEX.ConvertToGx2Format(Format);

            Width  = (uint)bitmap.Width;
            Height = (uint)bitmap.Height;

            MipCount = 1;
            uint[] MipOffsets = new uint[MipCount];

            try
            {
                //Create image block from bitmap first
                var data = GenerateMipsAndCompress(bitmap, MipCount, Format);

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, Text,
                                                   (uint)2,
                                                   (uint)0,
                                                   (uint)Width,
                                                   (uint)Height,
                                                   (uint)1,
                                                   (uint)Gx2Format,
                                                   (uint)Swizzle,
                                                   (uint)1,
                                                   (uint)MipCount
                                                   );

                TextureTGLP.Format      = (ushort)ConvertToGx2(Format);
                TextureTGLP.SheetHeight = (ushort)surface.height;
                TextureTGLP.SheetWidth  = (ushort)surface.width;
                TextureTGLP.SheetDataList[SheetIndex] = surface.data;

                IsEdited = true;
                UpdateEditor();
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + Text, "Error", ex.ToString());
            }
        }
Exemplo n.º 6
0
        public byte[] EncodeImage(STGenericTexture texture, byte[] data, uint width, uint height, int array, int mip)
        {
            //Swizzle and create surface
            var NewSurface = GX2.CreateGx2Texture(data, "",
                                                  (uint)TileMode,
                                                  (uint)AAMode,
                                                  (uint)width,
                                                  (uint)height,
                                                  (uint)1,
                                                  (uint)Format,
                                                  (uint)0,
                                                  (uint)SurfaceDimension,
                                                  (uint)texture.MipCount
                                                  );

            MipData = NewSurface.mipData;
            return(NewSurface.data);
        }
Exemplo n.º 7
0
        //For tex2
        public static void GenerateMipmaps(uint mipCount, TEX_FORMAT Format, Bitmap bitmap, Texture texture)
        {
            if (bitmap == null)
            {
                return; //Image is likely disposed and not needed to be applied
            }
            Console.WriteLine(texture.Name + " mipCount " + mipCount);
            texture.MipCount   = mipCount;
            texture.MipOffsets = new uint[mipCount];

            try
            {
                //Create image block from bitmap first
                var data = GenerateMipsAndCompress(bitmap, mipCount, Format);

                bitmap.Dispose();

                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(data, texture.Name,
                                                   (uint)texture.TileMode,
                                                   (uint)texture.AAMode,
                                                   (uint)texture.Width,
                                                   (uint)texture.Height,
                                                   (uint)texture.Depth,
                                                   (uint)texture.Format,
                                                   (uint)texture.Swizzle,
                                                   (uint)texture.Dim,
                                                   (uint)texture.MipCount
                                                   );

                var tex = FromGx2Surface(surface, texture.Name);
                texture.MipData    = tex.MipData;
                texture.MipOffsets = tex.MipOffsets;
                texture.MipCount   = tex.MipCount;
            }
            catch (Exception ex)
            {
                STErrorDialog.Show("Failed to swizzle and compress image " + texture.Name, "Error", ex.ToString());
            }
        }
Exemplo n.º 8
0
        public static Texture AddTexture(string name, List <byte[]> images, int width, int height, int mipCount, GX2SurfaceFormat format)
        {
            Texture tex = null;

            //Go through each texture as an array or depth surface
            List <byte[]> imageData = new List <byte[]>();
            List <byte[]> mipData   = new List <byte[]>();

            for (int i = 0; i < images.Count; i++)
            {
                //Swizzle and create surface
                var surface = GX2.CreateGx2Texture(images[i], name,
                                                   (uint)GX2TileMode.Mode2dTiledThin1,
                                                   (uint)GX2AAMode.Mode1X,
                                                   (uint)width,
                                                   (uint)height,
                                                   (uint)1,
                                                   (uint)format,
                                                   (uint)0,
                                                   (uint)GX2SurfaceDim.Dim2D,
                                                   (uint)mipCount
                                                   );

                //Apply first surface
                if (i == 0)
                {
                    tex = FromGx2Surface(surface, name);
                }

                imageData.Add(surface.data);
                mipData.Add(surface.mipData);
            }

            tex.Data        = Utils.CombineByteArray(imageData.ToArray());
            tex.MipData     = Utils.CombineByteArray(mipData.ToArray());
            tex.ArrayLength = (uint)images.Count;
            imageData.Clear();
            mipData.Clear();
            return(tex);
        }