예제 #1
0
        /// <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);
                }
            }
        }
예제 #2
0
        /// <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();
        }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
                    }
                }
            }
        }