/// <summary>Called when the device type changes</summary> private void OnDeviceChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; globalSettings.DeviceType = (DeviceType)cb.GetSelectedData(); // Update windowed/full screen radio buttons bool hasWindowCombo = false; bool hasFullscreen = false; EnumDeviceInformation edi = GetCurrentDeviceInfo(); // See if there are any windowed/fullscreen combos foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (edsc.IsWindowed) { hasWindowCombo = true; } else { hasFullscreen = true; } } // Set the controls enable/disable property based on whether they are available or not dialog.SetControlEnable((int)SettingsDialogControlIds.Windowed, hasWindowCombo); dialog.SetControlEnable((int)SettingsDialogControlIds.Fullscreen, hasFullscreen); SetWindowed(globalSettings.presentParams.Windowed && hasWindowCombo); OnWindowedFullscreenChanged(null, e); }
/// <summary> /// Adds all present intervals that are compatible with the device and app /// to the given device combo /// </summary> private static void BuildPresentIntervalList(EnumDeviceInformation deviceInfo, EnumDeviceSettingsCombo deviceCombo) { for (int i = 0; i < presentIntervalList.Count; i++) { PresentInterval pi = (PresentInterval)presentIntervalList[i]; if (deviceCombo.IsWindowed) { if ((pi == PresentInterval.Two) || (pi == PresentInterval.Three) || (pi == PresentInterval.Four)) { // These intervals are never supported in windowed mode continue; } } // Not that PresentInterval.Default is zero so you can't do a bitwise // check for it, it's always available if ((pi == PresentInterval.Default) || ((deviceInfo.Caps.PresentationIntervals & pi) != 0)) { deviceCombo.presentIntervalList.Add(pi); } } }
/// <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 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> /// 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>Called when the fullscreen or windowed item changes</summary> private void OnWindowedFullscreenChanged(object sender, EventArgs e) { bool isWindowed = windowedButton.IsChecked; globalSettings.presentParams.Windowed = isWindowed; // Set the control enabled or disabled properties dialog.SetControlEnable((int)SettingsDialogControlIds.AdapterFormatLabel, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.ResolutionLabel, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.RefreshRateLabel, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.AdapterFormat, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.Resolution, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.RefreshRate, !isWindowed); dialog.SetControlEnable((int)SettingsDialogControlIds.DeviceClip, isWindowed); bool deviceClip = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0); // If windowed, get the appropriate adapter format from Direct3D if (globalSettings.presentParams.Windowed) { DisplayMode mode = Manager.Adapters[(int)globalSettings.AdapterOrdinal].CurrentDisplayMode; globalSettings.AdapterFormat = mode.Format; globalSettings.presentParams.BackBufferWidth = mode.Width; globalSettings.presentParams.BackBufferHeight = mode.Height; globalSettings.presentParams.FullScreenRefreshRateInHz = mode.RefreshRate; } // Update the clip check box clipBox.IsChecked = deviceClip; // Update the adapter format list adapterFormatCombo.Clear(); EnumDeviceInformation edi = GetCurrentDeviceInfo(); if (isWindowed) { if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString())) { adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat); } } else { // Add all the supported formats foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (!adapterFormatCombo.ContainsItem(edsc.AdapterFormat.ToString())) { adapterFormatCombo.AddItem(edsc.AdapterFormat.ToString(), edsc.AdapterFormat); } } } adapterFormatCombo.SetSelectedByData(globalSettings.AdapterFormat); // Adapter format changed, update there OnAdapterFormatChange(adapterFormatCombo, EventArgs.Empty); // Update resolution if (isWindowed) { resolution.Clear(); AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight); } resolution.SetSelectedByData(NativeMethods.MakeUInt32( (short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight)); // Resolution changed OnResolutionChanged(resolution, EventArgs.Empty); // Update refresh if (isWindowed) { refreshCombo.Clear(); AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz); } // Select the correct refresh rate refreshCombo.SetSelectedByData(globalSettings.presentParams.FullScreenRefreshRateInHz); // refresh rate changed OnRefreshRateChanged(refreshCombo, EventArgs.Empty); }
/// <summary>Called when the back buffer format changes</summary> private void OnBackBufferChanged(object sender, EventArgs e) { ComboBox cb = sender as ComboBox; globalSettings.presentParams.BackBufferFormat = (Format)backBufferCombo.GetSelectedData(); // Store formats Format adapterFormat = globalSettings.AdapterFormat; Format backFormat = globalSettings.presentParams.BackBufferFormat; EnumDeviceInformation edi = GetCurrentDeviceInfo(); // Get possible vertex processing bool isAllowSoftware = Enumeration.IsSoftwareVertexProcessingPossible; bool isAllowHardware = Enumeration.IsHardwareVertexProcessingPossible; bool isAllowPure = Enumeration.IsPureHardwareVertexProcessingPossible; bool isAllowMixed = Enumeration.IsMixedVertexProcessingPossible; foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList) { if (edsc.IsWindowed == globalSettings.presentParams.Windowed && edsc.AdapterFormat == adapterFormat && edsc.BackBufferFormat == backFormat) { // Clear the depth stencil buffer depthStencilCombo.Clear(); depthStencilCombo.IsEnabled = (globalSettings.presentParams.EnableAutoDepthStencil); if (globalSettings.presentParams.EnableAutoDepthStencil) { foreach (Format f in edsc.depthStencilFormatList) { if (!depthStencilCombo.ContainsItem(f.ToString())) { depthStencilCombo.AddItem(f.ToString(), f); } } depthStencilCombo.SetSelectedByData(globalSettings.presentParams.AutoDepthStencilFormat); } else { if (!depthStencilCombo.ContainsItem("(not used)")) { depthStencilCombo.AddItem("(not used)", null); } } OnDepthStencilChanged(depthStencilCombo, e); // Now remove all the vertex processing information vertexCombo.Clear(); if (isAllowPure) { AddVertexProcessing(CreateFlags.PureDevice); } if (isAllowHardware) { AddVertexProcessing(CreateFlags.HardwareVertexProcessing); } if (isAllowSoftware) { AddVertexProcessing(CreateFlags.SoftwareVertexProcessing); } if (isAllowMixed) { AddVertexProcessing(CreateFlags.MixedVertexProcessing); } // Select the right one BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags); if (flags.PureDevice) { vertexCombo.SetSelectedByData(CreateFlags.PureDevice); } else if (flags.HardwareVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.HardwareVertexProcessing); } else if (flags.SoftwareVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.SoftwareVertexProcessing); } else if (flags.MixedVertexProcessing) { vertexCombo.SetSelectedByData(CreateFlags.MixedVertexProcessing); } OnVertexProcessingChanged(vertexCombo, e); // Now present intervals presentCombo.Clear(); foreach (PresentInterval pf in edsc.presentIntervalList) { if (!presentCombo.ContainsItem(pf.ToString())) { presentCombo.AddItem(pf.ToString(), pf); } } presentCombo.SetSelectedByData(globalSettings.presentParams.PresentationInterval); OnPresentIntervalChanged(presentCombo, 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> /// 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); } } } }
/// <summary> /// Adds all present intervals that are compatible with the device and app /// to the given device combo /// </summary> private static void BuildPresentIntervalList(EnumDeviceInformation deviceInfo, EnumDeviceSettingsCombo deviceCombo) { for (int i = 0; i < presentIntervalList.Count; i++) { PresentInterval pi = (PresentInterval)presentIntervalList[i]; if (deviceCombo.IsWindowed) { if ( (pi == PresentInterval.Two) || (pi == PresentInterval.Three) || (pi == PresentInterval.Four) ) { // These intervals are never supported in windowed mode continue; } } // Not that PresentInterval.Default is zero so you can't do a bitwise // check for it, it's always available if ( (pi == PresentInterval.Default) || ((deviceInfo.Caps.PresentationIntervals & pi) != 0)) { deviceCombo.presentIntervalList.Add(pi); } } }
/// <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); } } } }