示例#1
0
        public static Texture Encode(Bitmap bitmap, TextureFormat format, bool generateMipMaps)
        {
            int width  = bitmap.Width;
            int height = bitmap.Height;

            if (TextureFormatUtilities.IsCompressed(format))
            {
                width  = AlignmentUtilities.AlignToNextPowerOfTwo(bitmap.Width);
                height = AlignmentUtilities.AlignToNextPowerOfTwo(bitmap.Height);
            }

            Texture texture;

            if (generateMipMaps && TextureFormatUtilities.IsCompressed(format))
            {
                texture = new Texture(width, height, format, 1, ( int )Math.Log(Math.Max(width, height), 2) + 1);
            }

            else
            {
                texture = new Texture(width, height, format);
            }

            for (int i = 0; i < texture.MipMapCount; i++)
            {
                Encode(texture[i], bitmap);
            }

            return(texture);
        }
示例#2
0
 internal SubTexture(int width, int height, TextureFormat format, int id)
 {
     Width  = Math.Max(1, width);
     Height = Math.Max(1, height);
     Format = format;
     Id     = id;
     Data   = new byte[TextureFormatUtilities.CalculateDataSize(width, height, format)];
 }
 public static string GetFileName(Texture texture)
 {
     if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
     {
         return(texture.Name + ".png");
     }
     else
     {
         return(texture.Name + ".dds");
     }
 }
        public static void SaveTextures(TextureSet textures, string outputDirectory)
        {
            Directory.CreateDirectory(outputDirectory);

            foreach (var texture in textures.Textures)
            {
                if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
                {
                    TextureDecoder.DecodeToPNG(texture, Path.Combine(outputDirectory, texture.Name + ".png"));
                }
                else
                {
                    TextureDecoder.DecodeToDDS(texture, Path.Combine(outputDirectory, texture.Name + ".dds"));
                }
            }
        }