public static int CalculateMipLevels(int width, int height, int depth, MipMapCount mipLevels)
        {
            if (mipLevels > 1)
            {
                if (!IsPow2(width) || !IsPow2(height) || !IsPow2(depth))
                {
                    throw new InvalidOperationException("Width/Height/Depth must be power of 2");
                }

                var maxMips = CountMips(width, height, depth);
                if (mipLevels > maxMips)
                {
                    throw new InvalidOperationException($"MipLevels must be <= {maxMips}");
                }
            }
            else if (mipLevels == 0)
            {
                if (!IsPow2(width) || !IsPow2(height) || !IsPow2(depth))
                {
                    throw new InvalidOperationException("Width/Height/Depth must be power of 2");
                }

                mipLevels = CountMips(width, height, depth);
            }
            else
            {
                mipLevels = 1;
            }
            return(mipLevels);
        }
 public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
 {
     if (mipLevels > 1)
     {
         var maxMips = CountMips(width, height);
         if (mipLevels > maxMips)
         {
             throw new InvalidOperationException($"MipLevels must be <= {maxMips}");
         }
     }
     else if (mipLevels == 0)
     {
         mipLevels = CountMips(width, height);
     }
     else
     {
         mipLevels = 1;
     }
     return(mipLevels);
 }
Exemple #3
0
 private static ImageDescription CreateDescription(TextureDimension dimension, int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, int arraySize)
 {
     return(new ImageDescription
     {
         Width = width,
         Height = height,
         Depth = depth,
         ArraySize = arraySize,
         Dimension = dimension,
         Format = format,
         MipLevels = mipMapCount
     });
 }
Exemple #4
0
 public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.Texture3D, width, width, depth, mipMapCount, format, 1), dataPointer, 0, null, false));
 }
Exemple #5
0
 public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.TextureCube, width, width, 1, mipMapCount, format, 6), dataPointer, 0, null, false));
 }
Exemple #6
0
 public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.Texture2D, width, height, 1, mipMapCount, format, arraySize), dataPointer, 0, null, false));
 }
Exemple #7
0
 public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format)
 {
     return(New3D(width, height, depth, mipMapCount, format, IntPtr.Zero));
 }
Exemple #8
0
 public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format)
 {
     return(NewCube(width, mipMapCount, format, IntPtr.Zero));
 }
Exemple #9
0
 public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
 {
     return(New2D(width, height, mipMapCount, format, arraySize, IntPtr.Zero));
 }