?? dxmutenum.cs
字號:
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.Windowed);
}
}
/// <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 AdapterDetails AdapterInformation; // Information about this adapter
public ArrayList displayModeList = new ArrayList(); // Array of display modes
public ArrayList deviceInfoList = new ArrayList(); // 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 Caps Caps; // Capabilities of the device
public ArrayList deviceSettingsList = new ArrayList(); // 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 ArrayList depthStencilFormatList = new ArrayList();
public ArrayList multiSampleTypeList = new ArrayList();
public ArrayList multiSampleQualityList = new ArrayList();
public ArrayList presentIntervalList = new ArrayList();
public ArrayList depthStencilConflictList = new ArrayList();
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 : IComparer
{
#region IComparer Members
/// <summary>
/// Compare two display modes
/// </summary>
public int Compare(object x, object y)
{
DisplayMode d1 = (DisplayMode)x;
DisplayMode d2 = (DisplayMode)y;
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>
class ManagedUtility
{
private ManagedUtility() { } // No creation
/// <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 + -