📄 wdxmutenum.cs
字号:
/// <summary>
/// Get the adapter information for a specific adapter
/// </summary>
public static EnumAdapterInformation GetAdapterInformation(uint ordinal)
{
foreach (EnumAdapterInformation eai in adapterInformationList)
{
if (eai.AdapterOrdinal == ordinal)
{
return eai;
}
}
// Never found it
return null;
}
/// <summary>
/// Get a specific device information for a device and type
/// </summary>
public static EnumDeviceInformation GetDeviceInfo(uint ordinal, DeviceType deviceType)
{
EnumAdapterInformation info = GetAdapterInformation(ordinal);
if (info != null)
{
foreach (EnumDeviceInformation edi in info.deviceInfoList)
{
// Is this the right device type?
if (edi.DeviceType == deviceType)
{
return edi;
}
}
}
// Never found it
return null;
}
/// <summary>
/// Returns a specific device combination
/// </summary>
public static EnumDeviceSettingsCombo GetDeviceSettingsCombo(uint ordinal, DeviceType deviceType,
Format adapterFormat, Format backBufferFormat, bool isWindowed)
{
EnumDeviceInformation info = GetDeviceInfo(ordinal, deviceType);
if (info != null)
{
foreach (EnumDeviceSettingsCombo edsc in info.deviceSettingsList)
{
// Is this the right settings combo?
if ((edsc.AdapterFormat == adapterFormat) &&
(edsc.BackBufferFormat == backBufferFormat) &&
(edsc.IsWindowed == isWindowed))
{
return edsc;
}
}
}
// Never found it
return null;
}
/// <summary>
/// Returns a specific device combination from a device settings object
/// </summary>
public static EnumDeviceSettingsCombo GetDeviceSettingsCombo(DeviceSettings settings)
{
return GetDeviceSettingsCombo(settings.AdapterOrdinal, settings.DeviceType, settings.AdapterFormat,
settings.presentParams.BackBufferFormat, settings.presentParams.IsWindowed);
}
}
/// <summary>
/// Class describing an adapter which contains a unique adapter ordinal that
/// is installed on the system.
/// </summary>
public class EnumAdapterInformation
{
public uint AdapterOrdinal; // Ordinal for this adapter
public AdapterInformation AdapterInformation; // Information about this adapter
public List<DisplayMode> displayModeList = new List<DisplayMode>(); // Array of display modes
public List<EnumDeviceInformation> deviceInfoList = new List<EnumDeviceInformation>(); // Array of device information
public string UniqueDescription; // Unique description of this device
}
/// <summary>
/// Class describing a Direct3D device that contains a
/// unique supported device type
/// </summary>
public class EnumDeviceInformation
{
public uint AdapterOrdinal; // Ordinal for this adapter
public DeviceType DeviceType; // Type of the device
public Capabilities Caps; // Capabilities of the device
public List<EnumDeviceSettingsCombo> deviceSettingsList = new List<EnumDeviceSettingsCombo>(); // Array with unique set of adapter format, back buffer format, and windowed
}
/// <summary>
/// Class describing device settings that contain a unique combination
/// of adapter format, back buffer format, and windowed that is compatible
/// with a particular Direct3D device and the application
/// </summary>
public class EnumDeviceSettingsCombo
{
public uint AdapterOrdinal;
public DeviceType DeviceType;
public Format AdapterFormat;
public Format BackBufferFormat;
public bool IsWindowed;
// Array lists
public List<DepthFormat> depthStencilFormatList = new List<DepthFormat>();
public List<MultiSampleType> multiSampleTypeList = new List<MultiSampleType>();
public List<int> multiSampleQualityList = new List<int>();
public List<PresentInterval> presentIntervalList = new List<PresentInterval>();
public List<EnumDepthStencilMultisampleConflict> depthStencilConflictList = new List<EnumDepthStencilMultisampleConflict>();
public EnumAdapterInformation adapterInformation = null;
public EnumDeviceInformation deviceInformation = null;
}
/// <summary>
/// A depth/stencil buffer format that is incompatible
/// with a multisample type
/// </summary>
public struct EnumDepthStencilMultisampleConflict
{
public DepthFormat DepthStencilFormat;
public MultiSampleType MultisampleType;
}
/// <summary>
/// Used to sort display modes
/// </summary>
public class DisplayModeSorter : System.Collections.Generic.IComparer<DisplayMode>
{
#region IComparer<DisplayMode> Members
public int Compare(DisplayMode d1, DisplayMode d2)
{
if (d1.Width > d2.Width)
return +1;
if (d1.Width < d2.Width)
return -1;
if (d1.Height > d2.Height)
return +1;
if (d1.Height < d2.Height)
return -1;
if (d1.Format > d2.Format)
return +1;
if (d1.Format < d2.Format)
return -1;
if (d1.RefreshRate > d2.RefreshRate)
return +1;
if (d1.RefreshRate < d2.RefreshRate)
return -1;
// They must be the same, return 0
return 0;
}
#endregion
}
#region Helper Utility Class
/// <summary>
/// Helper methods
/// </summary>
static class ManagedUtility
{
/// <summary>
/// Gets the number of ColorChanelBits from a format
/// </summary>
public static uint GetColorChannelBits(Format format)
{
switch (format)
{
case Format.R8G8B8:
case Format.A8R8G8B8:
case Format.X8R8G8B8:
return 8;
case Format.R5G6B5:
case Format.X1R5G5B5:
case Format.A1R5G5B5:
return 5;
case Format.A4R4G4B4:
case Format.X4R4G4B4:
return 4;
case Format.R3G3B2:
case Format.A8R3G3B2:
return 2;
case Format.A2B10G10R10:
case Format.A2R10G10B10:
return 10;
default:
return 0;
}
}
/// <summary>
/// Gets the number of alpha channel bits
/// </summary>
public static uint GetAlphaChannelBits(Format format)
{
switch (format)
{
case Format.X8R8G8B8:
case Format.R8G8B8:
case Format.R5G6B5:
case Format.X1R5G5B5:
case Format.R3G3B2:
case Format.X4R4G4B4:
return 0;
case Format.A8R3G3B2:
case Format.A8R8G8B8:
return 8;
case Format.A1R5G5B5:
return 1;
case Format.A4R4G4B4:
return 4;
case Format.A2B10G10R10:
case Format.A2R10G10B10:
return 2;
default:
return 0;
}
}
/// <summary>
/// Gets the number of depth bits
/// </summary>
public static uint GetDepthBits(DepthFormat format)
{
switch (format)
{
case DepthFormat.D16:
case DepthFormat.D16Lockable:
return 16;
case DepthFormat.D15S1:
return 15;
case DepthFormat.D24X8:
case DepthFormat.D24S8:
case DepthFormat.D24X4S4:
case DepthFormat.D24SingleS8:
return 24;
case DepthFormat.D32:
case DepthFormat.D32SingleLockable:
return 32;
default:
return 0;
}
}
/// <summary>
/// Gets the number of stencil bits
/// </summary>
public static uint GetStencilBits(DepthFormat format)
{
switch (format)
{
case DepthFormat.D16:
case DepthFormat.D16Lockable:
case DepthFormat.D24X8:
case DepthFormat.D32:
case DepthFormat.D32SingleLockable:
return 0;
case DepthFormat.D15S1:
return 1;
case DepthFormat.D24X4S4:
return 4;
case DepthFormat.D24SingleS8:
case DepthFormat.D24S8:
return 8;
default:
return 0;
}
}
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -