public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements,
                                                                    GraphicsDeviceCaps caps,
                                                                    GraphicsDeviceRequirements fallbacks,
                                                                    out bool fullyMatchReq)
        {
            if (caps == null)
            {
                caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements);
            }

            GraphicsDeviceSettings settings = new GraphicsDeviceSettings();

            settings.adapter = caps.Adapter;

            Type type = typeof(GraphicsDeviceSettings);

            GraphicsDeviceCaps.OutputCapsCompatibility reqComp      = caps.CheckCompatibility(requirements);
            GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks);

            fullyMatchReq = reqComp.FullMatch;

            // check reqs against caps
            if (reqComp.SupportDeviceType)
            {
                settings.devType = requirements.DeviceType;
            }
            else if (fallbackComp.SupportDeviceType)
            {
                settings.devType = fallbacks.DeviceType;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DeviceType"),
                                                  requirements.DeviceType, null);
            }

            if (reqComp.SupportDeviceFormat)
            {
                settings.devFormat = requirements.DisplayFormat;
            }
            else if (fallbackComp.SupportDeviceFormat)
            {
                settings.devFormat = fallbacks.DisplayFormat;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DeviceFormat"),
                                                  requirements.DisplayFormat, null);
            }

            if (reqComp.SupportDepthFormat)
            {
                settings.depthFormat = requirements.DepthFormats[0];
            }
            else if (fallbackComp.SupportDepthFormat)
            {
                settings.depthFormat = fallbacks.DepthFormats[0];
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("DepthFormat"),
                                                  requirements.DepthFormats[0], null);
            }

            if (caps.HardwareTnL && requirements.HardwareTnL)
            {
                settings.createFlags = CreateFlags.HardwareVertexProcessing;
            }
            else if (!requirements.HardwareTnL)
            {
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            }
            else if (!fallbacks.HardwareTnL)
            {
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("CreateFlags"),
                                                  requirements.HardwareTnL, null);
            }

            if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported)
            {
                settings.multisample = requirements.MultiSample;
            }
            else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported)
            {
                settings.multisample = fallbacks.MultiSample;
            }
            else
            {
                throw new OutputSettingsException(type.GetProperty("AntiAliasing"),
                                                  requirements.MultiSample, caps.AntiAliasing.MaxSupported);
            }

            return(settings);
        }
        public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements,
                                                                    GraphicsDeviceCaps caps,
                                                                    GraphicsDeviceRequirements fallbacks,
                                                                    out bool fullyMatchReq)
        {
            if (caps == null)
                caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements);

            GraphicsDeviceSettings settings = new GraphicsDeviceSettings();
            settings.adapter = caps.Adapter;

            Type type = typeof(GraphicsDeviceSettings);

            GraphicsDeviceCaps.OutputCapsCompatibility reqComp = caps.CheckCompatibility(requirements);
            GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks);

            fullyMatchReq = reqComp.FullMatch;

            // check reqs against caps
            if (reqComp.SupportDeviceType)
                settings.devType = requirements.DeviceType;
            else if (fallbackComp.SupportDeviceType)
                settings.devType = fallbacks.DeviceType;
            else
                throw new OutputSettingsException(type.GetProperty("DeviceType"),
                                                  requirements.DeviceType, null);

            if (reqComp.SupportDeviceFormat)
                settings.devFormat = requirements.DisplayFormat;
            else if (fallbackComp.SupportDeviceFormat)
                settings.devFormat = fallbacks.DisplayFormat;
            else
                throw new OutputSettingsException(type.GetProperty("DeviceFormat"),
                                                  requirements.DisplayFormat, null);

            if (reqComp.SupportDepthFormat)
                settings.depthFormat = requirements.DepthFormats[0];
            else if (fallbackComp.SupportDepthFormat)
                settings.depthFormat = fallbacks.DepthFormats[0];
            else
                throw new OutputSettingsException(type.GetProperty("DepthFormat"),
                                                  requirements.DepthFormats[0], null);

            if (caps.HardwareTnL && requirements.HardwareTnL)
                settings.createFlags = CreateFlags.HardwareVertexProcessing;
            else if (!requirements.HardwareTnL)
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            else if (!fallbacks.HardwareTnL)
                settings.createFlags = CreateFlags.SoftwareVertexProcessing;
            else
                throw new OutputSettingsException(type.GetProperty("CreateFlags"),
                                                  requirements.HardwareTnL, null);

            if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported)
                settings.multisample = requirements.MultiSample;
            else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported)
                settings.multisample = fallbacks.MultiSample;
            else
                throw new OutputSettingsException(type.GetProperty("AntiAliasing"),
                                                  requirements.MultiSample, caps.AntiAliasing.MaxSupported);

            return settings;
        }