Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
CommonLib.cs
Go to the documentation of this file.
1 using System;
2 
3 namespace TextureTools.TexLibraries
4 {
5  /// <summary>
6  /// Class CommonLib
7  /// </summary>
8  public class CommonLib
9  {
10  /// <summary>
11  /// Calculates the mip level from a specified size.
12  /// </summary>
13  /// <param name="size">The size.</param>
14  /// <param name="minimumSizeLastMip">The minimum size of the last mip.</param>
15  /// <returns>The mip level.</returns>
16  /// <exception cref="System.ArgumentOutOfRangeException">Value must be > 0;size</exception>
17  public static int CalculateMipCountFromSize(int size, int minimumSizeLastMip = 4)
18  {
19  if (size <= 0)
20  {
21  throw new ArgumentOutOfRangeException("Value must be > 0", "size");
22  }
23 
24  if (minimumSizeLastMip <= 0)
25  {
26  throw new ArgumentOutOfRangeException("Value must be > 0", "minimumSizeLastMip");
27  }
28 
29  int level = 1;
30  while ((size/2) >= minimumSizeLastMip)
31  {
32  size = Math.Max(1, size / 2);
33  level++;
34  }
35  return level;
36  }
37 
38  /// <summary>
39  /// Calculates the mip level from a specified width,height,depth.
40  /// </summary>
41  /// <param name="width">The width.</param>
42  /// <param name="height">The height.</param>
43  /// <param name="depth">The depth.</param>
44  /// <param name="minimumSizeLastMip">The minimum size of the last mip.</param>
45  /// <returns>The mip level.</returns>
46  /// <exception cref="System.ArgumentOutOfRangeException">Value must be &gt; 0;size</exception>
47  public static int CalculateMipCount(int width, int height, int minimumSizeLastMip = 4)
48  {
49  return Math.Min(CalculateMipCountFromSize(width, minimumSizeLastMip), CalculateMipCountFromSize(height, minimumSizeLastMip));
50  }
51  }
52 }
static int CalculateMipCount(int width, int height, int minimumSizeLastMip=4)
Calculates the mip level from a specified width,height,depth.
Definition: CommonLib.cs:47
static int CalculateMipCountFromSize(int size, int minimumSizeLastMip=4)
Calculates the mip level from a specified size.
Definition: CommonLib.cs:17
_In_ size_t _In_ size_t size
Definition: DirectXTexP.h:175