/// <summary>Called when the adapter changes</summary> private void OnAdapterChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; // Store the adapter index globalSettings.AdapterOrdinal = (uint)(int)cb.GetSelectedData(); // Remove all the items from the device type deviceCombo.Clear(); // Get the adapter information EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo(); // Add each device type to the combo list foreach (EnumDeviceInformation edi in adapterInfo.deviceInfoList) { if (!deviceCombo.ContainsItem(edi.DeviceType.ToString())) { deviceCombo.AddItem(edi.DeviceType.ToString(), edi.DeviceType); } } deviceCombo.SetSelectedByData(globalSettings.DeviceType); // Device type was changed update OnDeviceChanged(deviceCombo, e); }
/// <summary> /// Enumerates D3D devices for a particular adapter. /// </summary> private static void EnumerateDevices(EnumAdapterInformation adapterInfo, ArrayList adapterFormatList) { // Ignore any exceptions while looking for these device types DirectXException.IgnoreExceptions(); // Enumerate each Direct3D device type for (uint i = 0; i < deviceTypeArray.Length; i++) { // Create a new device information object EnumDeviceInformation deviceInfo = new EnumDeviceInformation(); // Store the type deviceInfo.DeviceType = deviceTypeArray[i]; // Try to get the capabilities deviceInfo.Caps = Manager.GetDeviceCaps((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType); // Get information about each device combination on this device EnumerateDeviceCombos(adapterInfo, deviceInfo, adapterFormatList); // Do we have any device combinations? if (deviceInfo.deviceSettingsList.Count > 0) { // Yes, add it adapterInfo.deviceInfoList.Add(deviceInfo); } } // Turn exception handling back on DirectXException.EnableExceptions(); }
/// <summary>Called when the resolution changes</summary> private void OnResolutionChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; // Set the resolution uint data = (uint)cb.GetSelectedData(); int width = NativeMethods.LoWord(data); int height = NativeMethods.HiWord(data); globalSettings.presentParams.BackBufferWidth = width; globalSettings.presentParams.BackBufferHeight = height; int refreshRate = globalSettings.presentParams.FullScreenRefreshRateInHz; // Update the refresh rate list refreshCombo.Clear(); EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo(); Format adapterFormat = globalSettings.AdapterFormat; foreach (DisplayMode dm in adapterInfo.displayModeList) { if (dm.Format == adapterFormat && dm.Width == width && dm.Height == height) { AddRefreshRate(dm.RefreshRate); } } // select and update refreshCombo.SetSelectedByData(refreshRate); OnRefreshRateChanged(refreshCombo, e); }
/// <summary>Called when the adapter format changes</summary> private void OnAdapterFormatChange(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; Format adapterFormat = (Format)cb.GetSelectedData(); // Resolutions resolution.Clear(); EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo(); foreach (DisplayMode dm in adapterInfo.displayModeList) { if (dm.Format == adapterFormat) { AddResolution((short)dm.Width, (short)dm.Height); } } uint currentResolution = NativeMethods.MakeUInt32( (short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight); resolution.SetSelectedByData(currentResolution); // Resolution changed OnResolutionChanged(resolution, e); // Back buffer formats backBufferCombo.Clear(); EnumDeviceInformation edi = GetCurrentDeviceInfo(); bool hasWindowedBackBuffer = false; bool isWindowed = windowedButton.IsChecked; foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (edsc.IsWindowed == isWindowed && edsc.AdapterFormat == globalSettings.AdapterFormat) { hasWindowedBackBuffer = true; if (!backBufferCombo.ContainsItem(edsc.BackBufferFormat.ToString())) { backBufferCombo.AddItem(edsc.BackBufferFormat.ToString(), edsc.BackBufferFormat); } } } // Update back buffer backBufferCombo.SetSelectedByData(globalSettings.presentParams.BackBufferFormat); OnBackBufferChanged(backBufferCombo, e); if (!hasWindowedBackBuffer) { dialog.SetControlEnable((int)SettingsDialogControlIds.Windowed, false); if (globalSettings.presentParams.Windowed) { SetWindowed(false); OnWindowedFullscreenChanged(null, e); } } }
/// <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>Changes the UI defaults to the current device settings</summary> public void Refresh() { // Get some information globalSettings = parent.DeviceSettings.Clone(); System.Drawing.Rectangle client = parent.WindowClientRectangle; windowWidth = (uint)client.Width; windowHeight = (uint)client.Height; // Fill the UI with the current settings if (!deviceCombo.ContainsItem(globalSettings.DeviceType.ToString())) { deviceCombo.AddItem(globalSettings.DeviceType.ToString(), globalSettings.DeviceType.ToString()); } SetWindowed(globalSettings.presentParams.Windowed); clipBox.IsChecked = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0); if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString())) { adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat); } AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight); AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz); if (!backBufferCombo.ContainsItem(globalSettings.presentParams.BackBufferFormat.ToString())) { backBufferCombo.AddItem(globalSettings.presentParams.BackBufferFormat.ToString(), globalSettings.presentParams.BackBufferFormat); } if (!depthStencilCombo.ContainsItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString())) { depthStencilCombo.AddItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString(), globalSettings.presentParams.AutoDepthStencilFormat); } if (!multiSampleTypeCombo.ContainsItem(globalSettings.presentParams.MultiSample.ToString())) { multiSampleTypeCombo.AddItem(globalSettings.presentParams.MultiSample.ToString(), globalSettings.presentParams.MultiSample); } if (!multiSampleQualityCombo.ContainsItem(globalSettings.presentParams.MultiSampleQuality.ToString())) { multiSampleQualityCombo.AddItem(globalSettings.presentParams.MultiSampleQuality.ToString(), globalSettings.presentParams.MultiSampleQuality); } if (!presentCombo.ContainsItem(globalSettings.presentParams.PresentationInterval.ToString())) { presentCombo.AddItem(globalSettings.presentParams.PresentationInterval.ToString(), globalSettings.presentParams.PresentationInterval); } BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) { AddVertexProcessing(CreateFlags.PureDevice); } else if (flags.HardwareVertexProcessing) { AddVertexProcessing(CreateFlags.HardwareVertexProcessing); } else if (flags.SoftwareVertexProcessing) { AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); } else if (flags.MixedVertexProcessing) { AddVertexProcessing(CreateFlags.MixedVertexProcessing); } // Get the adapters list from Enumeration object ArrayList adapterInfoList = Enumeration.AdapterInformationList; if (adapterInfoList.Count == 0) { throw new NoCompatibleDevicesException(); } adapterCombo.Clear(); // Add all of the adapters for (int iAdapter = 0; iAdapter < adapterInfoList.Count; iAdapter++) { EnumAdapterInformation adapterInfo = adapterInfoList[iAdapter] as EnumAdapterInformation; if (!adapterCombo.ContainsItem(adapterInfo.UniqueDescription)) { adapterCombo.AddItem(adapterInfo.UniqueDescription, iAdapter); } } adapterCombo.SetSelectedByData(globalSettings.AdapterOrdinal); // The adapter changed, call the handler OnAdapterChanged(adapterCombo, EventArgs.Empty); Dialog.SetRefreshTime((float)FrameworkTimer.GetTime()); }
/// <summary> /// Enumerates D3D devices for a particular adapter. /// </summary> private static void EnumerateDevices(EnumAdapterInformation adapterInfo, ArrayList adapterFormatList) { // Ignore any exceptions while looking for these device types DirectXException.IgnoreExceptions(); // Enumerate each Direct3D device type for(uint i = 0; i < deviceTypeArray.Length; i++) { // Create a new device information object EnumDeviceInformation deviceInfo = new EnumDeviceInformation(); // Store the type deviceInfo.DeviceType = deviceTypeArray[i]; // Try to get the capabilities deviceInfo.Caps = Manager.GetDeviceCaps((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType); // Get information about each device combination on this device EnumerateDeviceCombos( adapterInfo, deviceInfo, adapterFormatList); // Do we have any device combinations? if (deviceInfo.deviceSettingsList.Count > 0) { // Yes, add it adapterInfo.deviceInfoList.Add(deviceInfo); } } // Turn exception handling back on DirectXException.EnableExceptions(); }
/// <summary> /// Enumerates device combinations for a particular device. /// </summary> private static void EnumerateDeviceCombos(EnumAdapterInformation adapterInfo, EnumDeviceInformation deviceInfo, ArrayList adapterFormatList) { // Find out which adapter formats are supported by this device foreach(Format adapterFormat in adapterFormatList) { for(int i = 0; i < backbufferFormatsArray.Length; i++) { // Go through each windowed mode for (int windowedIndex = 0; windowedIndex < 2; windowedIndex++) { bool isWindowedIndex = (windowedIndex == 1); if ((!isWindowedIndex) && (adapterInfo.displayModeList.Count == 0)) continue; // Nothing here if (!Manager.CheckDeviceType((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType, adapterFormat, backbufferFormatsArray[i], isWindowedIndex)) continue; // Unsupported // Do we require post pixel shader blending? if (isPostPixelShaderBlendingRequired) { // If the backbuffer format doesn't support Usage.QueryPostPixelShaderBlending // then alpha test, pixel fog, render-target blending, color write enable, and dithering // are not supported. if (!Manager.CheckDeviceFormat((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType, adapterFormat, Usage.QueryPostPixelShaderBlending, ResourceType.Textures, backbufferFormatsArray[i])) continue; // Unsupported } // If an application callback function has been provided, make sure this device // is acceptable to the app. if (deviceCreationInterface != null) { if (!deviceCreationInterface.IsDeviceAcceptable(deviceInfo.Caps, adapterFormat, backbufferFormatsArray[i],isWindowedIndex)) continue; // Application doesn't like this device } // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed // DeviceCombo that is supported by the system and acceptable to the app. We still // need to find one or more suitable depth/stencil buffer format, // multisample type, and present interval. EnumDeviceSettingsCombo deviceCombo = new EnumDeviceSettingsCombo(); // Store the information deviceCombo.AdapterOrdinal = adapterInfo.AdapterOrdinal; deviceCombo.DeviceType = deviceInfo.DeviceType; deviceCombo.AdapterFormat = adapterFormat; deviceCombo.BackBufferFormat = backbufferFormatsArray[i]; deviceCombo.IsWindowed = isWindowedIndex; // Build the depth stencil format and multisample type list BuildDepthStencilFormatList(deviceCombo); BuildMultiSampleTypeList(deviceCombo); if (deviceCombo.multiSampleTypeList.Count == 0) { // Nothing to do continue; } // Build the conflict and present lists BuildConflictList(deviceCombo); BuildPresentIntervalList(deviceInfo, deviceCombo); deviceCombo.adapterInformation = adapterInfo; deviceCombo.deviceInformation = deviceInfo; // Add the combo to the list of devices deviceInfo.deviceSettingsList.Add(deviceCombo); } } } }
// Implementation /// <summary> /// Enumerates available D3D adapters, devices, modes, etc /// </summary> public static void Enumerate(IDeviceCreation acceptableCallback) { DisplayModeSorter sorter = new DisplayModeSorter(); try { // Store the callback deviceCreationInterface = acceptableCallback; // Clear the adapter information stored currently adapterInformationList.Clear(); ArrayList adapterFormatList = new ArrayList(); // Look through every adapter on the system foreach(AdapterInformation ai in Manager.Adapters) { EnumAdapterInformation adapterInfo = new EnumAdapterInformation(); // Store some information adapterInfo.AdapterOrdinal = (uint)ai.Adapter; // Ordinal adapterInfo.AdapterInformation = ai.Information; // Information // Get list of all display modes on this adapter. // Also build a temporary list of all display adapter formats. adapterFormatList.Clear(); // Now check to see which formats are supported for(int i = 0; i < allowedFormats.Length; i++) { // Check each of the supported display modes for this format foreach(DisplayMode dm in ai.SupportedDisplayModes[allowedFormats[i]]) { if ( (dm.Width < minimumWidth) || (dm.Height < minimumHeight) || (dm.Width > maximumWidth) || (dm.Height > maximumHeight) || (dm.RefreshRate < minimumRefresh) || (dm.RefreshRate > maximumRefresh) ) { continue; // This format isn't valid } // Add this to the list adapterInfo.displayModeList.Add(dm); // Add this to the format list if it doesn't already exist if (!adapterFormatList.Contains(dm.Format)) { adapterFormatList.Add(dm.Format); } } } // Get the adapter display mode DisplayMode currentAdapterMode = ai.CurrentDisplayMode; // Check to see if this format is in the list if (!adapterFormatList.Contains(currentAdapterMode.Format)) { adapterFormatList.Add(currentAdapterMode.Format); } // Sort the display mode list adapterInfo.displayModeList.Sort(sorter); // Get information for each device with this adapter EnumerateDevices(adapterInfo, adapterFormatList); // If there was at least one device on the adapter, and it's compatible // add it to the list if (adapterInfo.deviceInfoList.Count > 0) { adapterInformationList.Add(adapterInfo); } } // See if all of the descriptions are unique bool isUnique = true; for(int i = 0; i < adapterInformationList.Count; i++) { for (int j = i+1; j < adapterInformationList.Count; j++) { EnumAdapterInformation eai1 = adapterInformationList[i] as EnumAdapterInformation; EnumAdapterInformation eai2 = adapterInformationList[j] as EnumAdapterInformation; if (string.Compare(eai1.AdapterInformation.Description, eai2.AdapterInformation.Description, true) == 0) { isUnique = false; break; } } if (!isUnique) break; } // Now fill the unique description for(int i = 0; i < adapterInformationList.Count; i++) { EnumAdapterInformation eai1 = adapterInformationList[i] as EnumAdapterInformation; eai1.UniqueDescription = eai1.AdapterInformation.Description; // If the descriptions aren't unique, append the adapter ordinal if (!isUnique) eai1.UniqueDescription += string.Format(" (#{0})", eai1.AdapterOrdinal); } } catch (TypeLoadException) { // Couldn't load the manager class, no Direct is available. throw new NoDirect3DException(); } }
// Implementation /// <summary> /// Enumerates available D3D adapters, devices, modes, etc /// </summary> public static void Enumerate(IDeviceCreation acceptableCallback) { DisplayModeSorter sorter = new DisplayModeSorter(); try { // Store the callback deviceCreationInterface = acceptableCallback; // Clear the adapter information stored currently adapterInformationList.Clear(); ArrayList adapterFormatList = new ArrayList(); // Look through every adapter on the system foreach (AdapterInformation ai in Manager.Adapters) { EnumAdapterInformation adapterInfo = new EnumAdapterInformation(); // Store some information adapterInfo.AdapterOrdinal = (uint)ai.Adapter; // Ordinal adapterInfo.AdapterInformation = ai.Information; // Information // Get list of all display modes on this adapter. // Also build a temporary list of all display adapter formats. adapterFormatList.Clear(); // Now check to see which formats are supported for (int i = 0; i < allowedFormats.Length; i++) { // Check each of the supported display modes for this format foreach (DisplayMode dm in ai.SupportedDisplayModes[allowedFormats[i]]) { if ((dm.Width < minimumWidth) || (dm.Height < minimumHeight) || (dm.Width > maximumWidth) || (dm.Height > maximumHeight) || (dm.RefreshRate < minimumRefresh) || (dm.RefreshRate > maximumRefresh)) { continue; // This format isn't valid } // Add this to the list adapterInfo.displayModeList.Add(dm); // Add this to the format list if it doesn't already exist if (!adapterFormatList.Contains(dm.Format)) { adapterFormatList.Add(dm.Format); } } } // Get the adapter display mode DisplayMode currentAdapterMode = ai.CurrentDisplayMode; // Check to see if this format is in the list if (!adapterFormatList.Contains(currentAdapterMode.Format)) { adapterFormatList.Add(currentAdapterMode.Format); } // Sort the display mode list adapterInfo.displayModeList.Sort(sorter); // Get information for each device with this adapter EnumerateDevices(adapterInfo, adapterFormatList); // If there was at least one device on the adapter, and it's compatible // add it to the list if (adapterInfo.deviceInfoList.Count > 0) { adapterInformationList.Add(adapterInfo); } } // See if all of the descriptions are unique bool isUnique = true; for (int i = 0; i < adapterInformationList.Count; i++) { for (int j = i + 1; j < adapterInformationList.Count; j++) { EnumAdapterInformation eai1 = adapterInformationList[i] as EnumAdapterInformation; EnumAdapterInformation eai2 = adapterInformationList[j] as EnumAdapterInformation; if (string.Compare(eai1.AdapterInformation.Description, eai2.AdapterInformation.Description, true) == 0) { isUnique = false; break; } } if (!isUnique) { break; } } // Now fill the unique description for (int i = 0; i < adapterInformationList.Count; i++) { EnumAdapterInformation eai1 = adapterInformationList[i] as EnumAdapterInformation; eai1.UniqueDescription = eai1.AdapterInformation.Description; // If the descriptions aren't unique, append the adapter ordinal if (!isUnique) { eai1.UniqueDescription += string.Format(" (#{0})", eai1.AdapterOrdinal); } } } catch (TypeLoadException) { // Couldn't load the manager class, no Direct is available. throw new NoDirect3DException(); } }
/// <summary> /// Enumerates device combinations for a particular device. /// </summary> private static void EnumerateDeviceCombos(EnumAdapterInformation adapterInfo, EnumDeviceInformation deviceInfo, ArrayList adapterFormatList) { // Find out which adapter formats are supported by this device foreach (Format adapterFormat in adapterFormatList) { for (int i = 0; i < backbufferFormatsArray.Length; i++) { // Go through each windowed mode for (int windowedIndex = 0; windowedIndex < 2; windowedIndex++) { bool isWindowedIndex = (windowedIndex == 1); if ((!isWindowedIndex) && (adapterInfo.displayModeList.Count == 0)) { continue; // Nothing here } if (!Manager.CheckDeviceType((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType, adapterFormat, backbufferFormatsArray[i], isWindowedIndex)) { continue; // Unsupported } // Do we require post pixel shader blending? if (isPostPixelShaderBlendingRequired) { // If the backbuffer format doesn't support Usage.QueryPostPixelShaderBlending // then alpha test, pixel fog, render-target blending, color write enable, and dithering // are not supported. if (!Manager.CheckDeviceFormat((int)adapterInfo.AdapterOrdinal, deviceInfo.DeviceType, adapterFormat, Usage.QueryPostPixelShaderBlending, ResourceType.Textures, backbufferFormatsArray[i])) { continue; // Unsupported } } // If an application callback function has been provided, make sure this device // is acceptable to the app. if (deviceCreationInterface != null) { if (!deviceCreationInterface.IsDeviceAcceptable(deviceInfo.Caps, adapterFormat, backbufferFormatsArray[i], isWindowedIndex)) { continue; // Application doesn't like this device } } // At this point, we have an adapter/device/adapterformat/backbufferformat/iswindowed // DeviceCombo that is supported by the system and acceptable to the app. We still // need to find one or more suitable depth/stencil buffer format, // multisample type, and present interval. EnumDeviceSettingsCombo deviceCombo = new EnumDeviceSettingsCombo(); // Store the information deviceCombo.AdapterOrdinal = adapterInfo.AdapterOrdinal; deviceCombo.DeviceType = deviceInfo.DeviceType; deviceCombo.AdapterFormat = adapterFormat; deviceCombo.BackBufferFormat = backbufferFormatsArray[i]; deviceCombo.IsWindowed = isWindowedIndex; // Build the depth stencil format and multisample type list BuildDepthStencilFormatList(deviceCombo); BuildMultiSampleTypeList(deviceCombo); if (deviceCombo.multiSampleTypeList.Count == 0) { // Nothing to do continue; } // Build the conflict and present lists BuildConflictList(deviceCombo); BuildPresentIntervalList(deviceInfo, deviceCombo); deviceCombo.adapterInformation = adapterInfo; deviceCombo.deviceInformation = deviceInfo; // Add the combo to the list of devices deviceInfo.deviceSettingsList.Add(deviceCombo); } } } }