コード例 #1
0
 public SubTexture(int width, int height, TextureFormat format)
 {
     Width  = Math.Max(1, width);
     Height = Math.Max(1, height);
     Format = format;
     Data   = new byte[TextureFormatUtilities.CalculateDataSize(width, height, format)];
 }
コード例 #2
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);
        }
コード例 #3
0
 public static string GetFileName(Texture texture)
 {
     if (!TextureFormatUtilities.IsCompressed(texture.Format) || texture.IsYCbCr)
     {
         return(texture.Name + ".png");
     }
     return(texture.Name + ".dds");
 }
コード例 #4
0
        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"));
                }
            }
        }