Beispiel #1
0
        /// <summary>
        /// Calculates the number of miplevels for a Texture 2D.
        /// </summary>
        /// <param name="width">The width of the texture.</param>
        /// <param name="height">The height of the texture.</param>
        /// <param name="depth">The depth of the texture.</param>
        /// <param name="mipLevels">A <see cref="MipMapCount"/>, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels.</param>
        /// <returns>The number of miplevels.</returns>
        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");
                }

                int maxMips = CountMips(width, height, depth);
                if (mipLevels > maxMips)
                {
                    throw new InvalidOperationException(String.Format("MipLevels must be <= {0}", 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);
        }
Beispiel #2
0
 /// <summary>
 /// Calculates the number of miplevels for a Texture 2D.
 /// </summary>
 /// <param name="width">The width of the texture.</param>
 /// <param name="height">The height of the texture.</param>
 /// <param name="mipLevels">A <see cref="MipMapCount"/>, set to true to calculates all mipmaps, to false to calculate only 1 miplevel, or > 1 to calculate a specific amount of levels.</param>
 /// <returns>The number of miplevels.</returns>
 public static int CalculateMipLevels(int width, int height, MipMapCount mipLevels)
 {
     if (mipLevels > 1)
     {
         int maxMips = CountMips(width, height);
         if (mipLevels > maxMips)
         {
             throw new InvalidOperationException(String.Format("MipLevels must be <= {0}", maxMips));
         }
     }
     else if (mipLevels == 0)
     {
         mipLevels = CountMips(width, height);
     }
     else
     {
         mipLevels = 1;
     }
     return(mipLevels);
 }
Beispiel #3
0
 /// <summary>
 /// Creates a new instance of a 3D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 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));
 }
Beispiel #4
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,
     });
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new instance of a Cube <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 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));
 }
Beispiel #6
0
 /// <summary>
 /// Creates a new instance of a 2D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="arraySize">Size of the array.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 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));
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new instance of a 3D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <returns>A new image.</returns>
 public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format)
 {
     return(New3D(width, height, depth, mipMapCount, format, IntPtr.Zero));
 }
Beispiel #8
0
 /// <summary>
 /// Creates a new instance of a Cube <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <returns>A new image.</returns>
 public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format)
 {
     return(NewCube(width, mipMapCount, format, IntPtr.Zero));
 }
Beispiel #9
0
 /// <summary>
 /// Creates a new instance of a 2D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="arraySize">Size of the array.</param>
 /// <returns>A new image.</returns>
 public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
 {
     return(New2D(width, height, mipMapCount, format, arraySize, IntPtr.Zero));
 }