Пример #1
0
        /// <summary>
        /// Regenerates the internal deviceModes list.
        /// </summary>
        private void RefreshDeviceModes()
        {
            this.deviceModes.Clear();

            // See which adapter formats are supported by this device
            foreach (DisplayMode displayMode in this.adapter.DisplayModes)
            {
                foreach (Format backBufferFormat in DisplayDevice.backBufferFormats)
                {
                    //	HACK: replace this line
                    //					if (GraphicsUtility.GetAlphaChannelBits(backBufferFormat) < AppMinAlphaChannelBits)
                    //						continue;

                    foreach (bool isWindowed in DisplayDevice.isWindowedArray)
                    {
                        if (!Manager.CheckDeviceType(this.adapter.Ordinal, this.deviceType,
                                                     displayMode.Format, backBufferFormat, isWindowed))
                        {
                            continue;
                        }

                        DisplayDeviceMode newDeviceMode = new DisplayDeviceMode(this,
                                                                                displayMode.Format, backBufferFormat, isWindowed);

                        //	add the device mode if it is valid for actual use
                        if ((newDeviceMode.MultiSampleTypes.Count > 0) &&
                            (newDeviceMode.VertexProcessingTypes.Count > 0) &&
                            (newDeviceMode.PresentIntervals.Count > 0))
                        {
                            this.deviceModes.Add(newDeviceMode);
                        }
                    }
                }
            }
        }
Пример #2
0
        public Boolean FindBestFullScreenMode(Boolean requiresHardware, Boolean requiresReference)
        {
            // For fullscreen, default to first HAL DeviceCombo that supports the current desktop
            // display mode, or any display mode if HAL is not compatible with the desktop mode, or
            // non-HAL if no HAL is available
            DisplayMode adapterDesktopDisplayMode     = new DisplayMode();
            DisplayMode bestAdapterDesktopDisplayMode = new DisplayMode();
            DisplayMode bestDisplayMode = new DisplayMode();

            bestAdapterDesktopDisplayMode.Width       = 0;
            bestAdapterDesktopDisplayMode.Height      = 0;
            bestAdapterDesktopDisplayMode.Format      = 0;
            bestAdapterDesktopDisplayMode.RefreshRate = 0;

            DisplayAdapter    bestAdapter    = null;
            DisplayDevice     bestDevice     = null;
            DisplayDeviceMode bestDeviceMode = null;

            foreach (DisplayAdapter displayAdapter in hardwareInfo.DisplayAdapters)
            {
                adapterDesktopDisplayMode = Manager.Adapters[displayAdapter.Ordinal].CurrentDisplayMode;
                foreach (DisplayDevice displayDevice in displayAdapter.DisplayDevices)
                {
                    if (requiresHardware && displayDevice.DeviceType != DeviceType.Hardware)
                    {
                        continue;
                    }
                    if (requiresReference && displayDevice.DeviceType != DeviceType.Reference)
                    {
                        continue;
                    }
                    foreach (DisplayDeviceMode deviceMode in displayDevice.DeviceModes)
                    {
                        bool adapterMatchesBackBuffer = (deviceMode.BackBufferFormat == deviceMode.AdapterFormat);
                        bool adapterMatchesDesktop    = (deviceMode.AdapterFormat == adapterDesktopDisplayMode.Format);
                        if (deviceMode.IsWindowed)
                        {
                            continue;
                        }
                        // If we haven't found a compatible set yet, or if this set
                        // is better (because it's a HAL, and/or because formats match better),
                        // save it
                        if (bestDeviceMode == null ||
                            bestDeviceMode.DeviceType != DeviceType.Hardware && displayDevice.DeviceType == DeviceType.Hardware ||
                            bestDeviceMode.DeviceType == DeviceType.Hardware && bestDeviceMode.AdapterFormat != adapterDesktopDisplayMode.Format && adapterMatchesDesktop ||
                            bestDeviceMode.DeviceType == DeviceType.Hardware && adapterMatchesDesktop && adapterMatchesBackBuffer)
                        {
                            bestAdapterDesktopDisplayMode = adapterDesktopDisplayMode;
                            bestAdapter    = displayAdapter;
                            bestDevice     = displayDevice;
                            bestDeviceMode = deviceMode;
                            if (displayDevice.DeviceType == DeviceType.Hardware && adapterMatchesDesktop && adapterMatchesBackBuffer)

                            {
                                // This fullscreen device combo looks great -- take it
                                goto EndFullScreenDeviceComboSearch;
                            }
                            // Otherwise keep looking for a better fullscreen device combo
                        }
                    }
                }
            }
EndFullScreenDeviceComboSearch:
            if (bestDeviceMode == null)
            {
                return(false);
            }

            // Need to find a display mode on the best adapter that uses pBestDeviceCombo->AdapterFormat
            // and is as close to bestAdapterDesktopDisplayMode's res as possible
            bestDisplayMode.Width       = 0;
            bestDisplayMode.Height      = 0;
            bestDisplayMode.Format      = 0;
            bestDisplayMode.RefreshRate = 0;
            foreach (DisplayMode displayMode in bestAdapter.DisplayModes)
            {
                if (displayMode.Format != bestDeviceMode.AdapterFormat)
                {
                    continue;
                }
                if (displayMode.Width == bestAdapterDesktopDisplayMode.Width &&
                    displayMode.Height == bestAdapterDesktopDisplayMode.Height &&
                    displayMode.RefreshRate == bestAdapterDesktopDisplayMode.RefreshRate)
                {
                    // found a perfect match, so stop
                    bestDisplayMode = displayMode;
                    break;
                }
                else if (displayMode.Width == bestAdapterDesktopDisplayMode.Width &&
                         displayMode.Height == bestAdapterDesktopDisplayMode.Height &&
                         displayMode.RefreshRate > bestDisplayMode.RefreshRate)
                {
                    // refresh rate doesn't match, but width/height match, so keep this
                    // and keep looking
                    bestDisplayMode = displayMode;
                }
                else if (bestDisplayMode.Width == bestAdapterDesktopDisplayMode.Width)
                {
                    // width matches, so keep this and keep looking
                    bestDisplayMode = displayMode;
                }
                else if (bestDisplayMode.Width == 0)
                {
                    // we don't have anything better yet, so keep this and keep looking
                    bestDisplayMode = displayMode;
                }
            }
            graphicsSettings.FullScreenDisplayAdapter = bestAdapter;
            graphicsSettings.FullScreenDisplayDevice  = bestDevice;
            graphicsSettings.FullScreenDeviceMode     = bestDeviceMode;

            graphicsSettings.IsWindowed            = false;
            graphicsSettings.FullScreenDisplayMode = bestDisplayMode;
            //if (hardwareInfo.AppUsesDepthBuffer)
            graphicsSettings.FullScreenDepthStencilBufferFormat = (DepthFormat)bestDeviceMode.DepthStencilFormats[0];
            graphicsSettings.FullScreenMultiSampleType          = (MultiSampleType)bestDeviceMode.MultiSampleTypes[0];
            graphicsSettings.FullScreenMultiSampleQuality       = 0;
            graphicsSettings.FullScreenVertexProcessingType     = (VertexProcessingType)bestDeviceMode.VertexProcessingTypes[0];
            graphicsSettings.FullScreenPresentInterval          = (PresentInterval)bestDeviceMode.PresentIntervals[0];
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Regenerates the internal deviceModes list.
        /// </summary>
        private void RefreshDeviceModes()
        {
            this.deviceModes.Clear();

            // See which adapter formats are supported by this device
            foreach (DisplayMode displayMode in this.adapter.DisplayModes)
            {
                foreach (Format backBufferFormat in DisplayDevice.backBufferFormats)
                {
                    //	HACK: replace this line
                    //					if (GraphicsUtility.GetAlphaChannelBits(backBufferFormat) < AppMinAlphaChannelBits)
                    //						continue;

                    foreach (bool isWindowed in DisplayDevice.isWindowedArray)
                    {
                        if (!Manager.CheckDeviceType(this.adapter.Ordinal, this.deviceType,
                            displayMode.Format, backBufferFormat, isWindowed))
                            continue;

                        DisplayDeviceMode newDeviceMode = new DisplayDeviceMode(this,
                            displayMode.Format, backBufferFormat, isWindowed);

                        //	add the device mode if it is valid for actual use
                        if ((newDeviceMode.MultiSampleTypes.Count > 0) &&
                            (newDeviceMode.VertexProcessingTypes.Count > 0) &&
                            (newDeviceMode.PresentIntervals.Count > 0))
                            this.deviceModes.Add(newDeviceMode);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Sets up GraphicsSettings with best available windowed mode, subject to
        /// the doesRequireHardware and doesRequireReference constraints.
        /// </summary>
        /// <param name="requiresHardware">Does the device require hardware support.</param>
        /// <param name="requiresReference">Does the device require the ref device.</param>
        /// <returns>true if a mode is found, false otherwise.</returns>
        public Boolean FindBestWindowedMode(Boolean requiresHardware, Boolean requiresReference)
        {
            // Get display mode of primary adapter (which is assumed to be where the window
            // will appear)
            DisplayMode primaryDesktopDisplayMode = Manager.Adapters[0].CurrentDisplayMode;

            DisplayAdapter    bestAdapter    = null;
            DisplayDevice     bestDevice     = null;
            DisplayDeviceMode bestDeviceMode = null;

            foreach (DisplayAdapter displayAdapter in this.hardwareInfo.DisplayAdapters)
            {
                foreach (DisplayDevice displayDevice in displayAdapter.DisplayDevices)
                {
                    if (requiresHardware && displayDevice.DeviceType != DeviceType.Hardware)
                    {
                        continue;
                    }
                    if (requiresReference && displayDevice.DeviceType != DeviceType.Reference)
                    {
                        continue;
                    }

                    foreach (DisplayDeviceMode deviceMode in displayDevice.DeviceModes)
                    {
                        bool adapterMatchesBackBuffer = (deviceMode.BackBufferFormat == deviceMode.AdapterFormat);
                        if (!deviceMode.IsWindowed)
                        {
                            continue;
                        }
                        if (deviceMode.AdapterFormat != primaryDesktopDisplayMode.Format)
                        {
                            continue;
                        }
                        // If we haven't found a compatible DeviceCombo yet, or if this set
                        // is better (because it's a HAL, and/or because formats match better),
                        // save it
                        if (bestDeviceMode == null ||
                            bestDeviceMode.DeviceType != DeviceType.Hardware &&
                            displayDevice.DeviceType == DeviceType.Hardware ||
                            deviceMode.DeviceType == DeviceType.Hardware && adapterMatchesBackBuffer)
                        {
                            bestAdapter    = displayAdapter;
                            bestDevice     = displayDevice;
                            bestDeviceMode = deviceMode;
                            if (displayDevice.DeviceType == DeviceType.Hardware && adapterMatchesBackBuffer)
                            {
                                // This windowed device combo looks great -- take it
                                goto EndWindowedDeviceComboSearch;
                            }
                            // Otherwise keep looking for a better windowed device combo
                        }
                    }
                }
            }
EndWindowedDeviceComboSearch:
            if (bestDeviceMode == null)
            {
                return(false);
            }

            this.graphicsSettings.WindowedDisplayAdapter = bestAdapter;
            this.graphicsSettings.WindowedDisplayDevice  = bestDevice;
            this.graphicsSettings.WindowedDeviceMode     = bestDeviceMode;
            this.graphicsSettings.IsWindowed             = true;
            this.graphicsSettings.WindowedDisplayMode    = primaryDesktopDisplayMode;
            this.graphicsSettings.WindowedWidth          = this.viewport.ClientRectangle.Right - this.viewport.ClientRectangle.Left;
            this.graphicsSettings.WindowedHeight         = this.viewport.ClientRectangle.Bottom - this.viewport.ClientRectangle.Top;
            //	todo: fix depth buffer setting
            //if (Direct3DEnumerator.AppUsesDepthBuffer)
            graphicsSettings.WindowedDepthStencilBufferFormat  = (DepthFormat)bestDeviceMode.DepthStencilFormats[0];
            this.graphicsSettings.WindowedMultiSampleType      = (MultiSampleType)bestDeviceMode.MultiSampleTypes[0];
            this.graphicsSettings.WindowedMultiSampleQuality   = 0;
            this.graphicsSettings.WindowedVertexProcessingType = (VertexProcessingType)bestDeviceMode.VertexProcessingTypes[0];
            this.graphicsSettings.WindowedPresentInterval      = (PresentInterval)bestDeviceMode.PresentIntervals[0];

            return(true);
        }