Esempio n. 1
0
        public void ReadVibranceSettings(GraphicsAdapter graphicsAdapter, out int vibranceWindowsLevel, out bool affectPrimaryMonitorOnly, out List<ApplicationSetting> applicationSettings)
        {
            int defaultLevel = 0;
            int maxLevel = 0;
            if (graphicsAdapter == GraphicsAdapter.Nvidia)
            {
                defaultLevel = NvidiaDynamicVibranceProxy.NvapiDefaultLevel;
                maxLevel = NvidiaDynamicVibranceProxy.NvapiMaxLevel;
            }
            if (graphicsAdapter == GraphicsAdapter.Amd)
            {
                // todo
                defaultLevel = 100;
                maxLevel = 300;
            }

            if (!IsFileExisting(_fileName) || !IsFileExisting(_fileNameApplicationSettings))
            {
                vibranceWindowsLevel = defaultLevel;
                affectPrimaryMonitorOnly = false;
                applicationSettings = new List<ApplicationSetting>();
                return;
            }

            string szDefault = "";

            StringBuilder szValueInactive = new StringBuilder(1024);
            GetPrivateProfileString(SzSectionName,
                SzKeyNameInactive,
                szDefault,
                szValueInactive,
                Convert.ToUInt32(szValueInactive.Capacity),
                _fileName);

            StringBuilder szValueRefreshRate = new StringBuilder(1024);
            GetPrivateProfileString(SzSectionName,
                SzKeyNameRefreshRate,
                szDefault,
                szValueRefreshRate,
                Convert.ToUInt32(szValueRefreshRate.Capacity),
                _fileName);

            StringBuilder szValueAffectPrimaryMonitorOnly = new StringBuilder(1024);
            GetPrivateProfileString(SzSectionName,
                SzKeyNameAffectPrimaryMonitorOnly,
                szDefault,
                szValueAffectPrimaryMonitorOnly,
                Convert.ToUInt32(szValueAffectPrimaryMonitorOnly.Capacity),
                _fileName);

            try
            {
                vibranceWindowsLevel = int.Parse(szValueInactive.ToString());
                affectPrimaryMonitorOnly = bool.Parse(szValueAffectPrimaryMonitorOnly.ToString());
            }
            catch (Exception)
            {
                vibranceWindowsLevel = defaultLevel;
                affectPrimaryMonitorOnly = false;
                applicationSettings = new List<ApplicationSetting>();
                return;
            }

            if (vibranceWindowsLevel < defaultLevel || vibranceWindowsLevel > maxLevel)
                vibranceWindowsLevel = defaultLevel;

            try
            {
                var reader = System.Xml.XmlReader.Create(_fileNameApplicationSettings);
                XmlSerializer serializer = new XmlSerializer(typeof(List<ApplicationSetting>));
                applicationSettings = (List<ApplicationSetting>)serializer.Deserialize(reader);
                reader.Close();
            }
            catch (Exception)
            {
                applicationSettings = new List<ApplicationSetting>();
            }
        }
        public void readVibranceSettings(GraphicsAdapter graphicsAdapter, out int vibranceIngameLevel, out int vibranceWindowsLevel, out bool keepActive, out int refreshRate, out bool affectPrimaryMonitorOnly)
        {
            int defaultLevel = 0; 
            int maxLevel = 0;
            int defaultRefreshRate = 0;
            int minRefreshRate = 0;
            if (graphicsAdapter == GraphicsAdapter.NVIDIA)
            {
                defaultLevel = NvidiaVibranceProxy.NVAPI_DEFAULT_LEVEL;
                maxLevel = NvidiaVibranceProxy.NVAPI_MAX_LEVEL;
                defaultRefreshRate = NvidiaVibranceProxy.NVAPI_DEFAULT_REFRESH_RATE;
                minRefreshRate = NvidiaVibranceProxy.NVAPI_MIN_REFRESH_RATE;
            }


            if (!isFileExisting(fileName))
            {
                vibranceIngameLevel = defaultLevel;
                vibranceWindowsLevel = defaultLevel;
                refreshRate = defaultRefreshRate;
                keepActive = false;
                affectPrimaryMonitorOnly = false;
                return;
            }

            string szDefault = "";

            StringBuilder szValueActive = new StringBuilder(1024);
            
            GetPrivateProfileString(szSectionName,
                szKeyNameActive,
                szDefault,
                szValueActive,
                Convert.ToUInt32(szValueActive.Capacity),
                fileName);

            StringBuilder szValueInactive = new StringBuilder(1024);
            GetPrivateProfileString(szSectionName,
                szKeyNameInactive,
                szDefault,
                szValueInactive,
                Convert.ToUInt32(szValueInactive.Capacity),
                fileName);

            StringBuilder szValueRefreshRate = new StringBuilder(1024);
            GetPrivateProfileString(szSectionName,
                szKeyNameRefreshRate,
                szDefault,
                szValueRefreshRate,
                Convert.ToUInt32(szValueRefreshRate.Capacity),
                fileName);


            StringBuilder szValueKeepActive = new StringBuilder(1024);
            GetPrivateProfileString(szSectionName,
                szKeyNameKeepActive,
                szDefault,
                szValueKeepActive,
                Convert.ToUInt32(szValueKeepActive.Capacity),
                fileName);

            StringBuilder szValueAffectPrimaryMonitorOnly = new StringBuilder(1024);
            GetPrivateProfileString(szSectionName,
                szKeyNameAffectPrimaryMonitorOnly,
                szDefault,
                szValueAffectPrimaryMonitorOnly,
                Convert.ToUInt32(szValueAffectPrimaryMonitorOnly.Capacity),
                fileName);

            try
            {
                vibranceWindowsLevel = int.Parse(szValueInactive.ToString());
                vibranceIngameLevel = int.Parse(szValueActive.ToString());
                refreshRate = int.Parse(szValueRefreshRate.ToString());
                keepActive = bool.Parse(szValueKeepActive.ToString());
                affectPrimaryMonitorOnly = bool.Parse(szValueAffectPrimaryMonitorOnly.ToString());
            }
            catch (Exception)
            {
                vibranceIngameLevel = defaultLevel;
                vibranceWindowsLevel = defaultLevel;
                refreshRate = defaultRefreshRate;
                keepActive = false;
                affectPrimaryMonitorOnly = false;
                return;
            }

            if (vibranceWindowsLevel < defaultLevel || vibranceWindowsLevel > maxLevel)
                vibranceWindowsLevel = defaultLevel;
            if (vibranceIngameLevel < defaultLevel || vibranceIngameLevel > maxLevel)
                vibranceIngameLevel = maxLevel;
            if (refreshRate < minRefreshRate)
                refreshRate = defaultRefreshRate;
        }
 private static void InitializeInternal()
 {
     defaultAdapter = new GraphicsAdapter();
     adapters = new [] { defaultAdapter };
 }
 private static void InitializeInternal()
 {
     defaultAdapter = new GraphicsAdapter();
     adapters       = new [] { defaultAdapter };
 }
Esempio n. 5
0
 public abstract GraphicsDevice CreateGraphicsDevice(PresentationParameters presentationParameters, GraphicsAdapter adapter);
Esempio n. 6
0
        void graphics_PreparingDeviceSettings(object sender,
                                              PreparingDeviceSettingsEventArgs e)
        {
            int             quality     = 0;
            GraphicsAdapter adapter     = e.GraphicsDeviceInformation.Adapter;
            SurfaceFormat   format      = adapter.CurrentDisplayMode.Format;
            DisplayMode     currentmode = adapter.CurrentDisplayMode;

            PresentationParameters pp =
                e.GraphicsDeviceInformation.PresentationParameters;

#if XBOX
            pp.MultiSampleQuality = 0;
            pp.MultiSampleType    =
                MultiSampleType.FourSamples;
            pp.BackBufferWidth        = 1280;
            pp.BackBufferHeight       = 720;
            pp.BackBufferFormat       = SurfaceFormat.Bgr32;
            pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8Single;
            pp.EnableAutoDepthStencil = true;
            return;
#endif

            // Set a window size compatible with the current screen
            if (currentmode.Width < 800)
            {
                pp.BackBufferWidth  = 640;
                pp.BackBufferHeight = 480;
            }
            else if (currentmode.Width < 1024)
            {
                pp.BackBufferWidth  = 800;
                pp.BackBufferHeight = 600;
            }
            else if (currentmode.Width < 1280)
            {
                pp.BackBufferWidth  = 1024;
                pp.BackBufferHeight = 768;
            }
            else // Xbox, or a PC with a big screen
            {
                pp.BackBufferWidth  = 1280;
                pp.BackBufferHeight = 720;
            }

            // Xbox 360 and most PCs support FourSamples/0 (4x)
            // and TwoSamples/0 (2x) antialiasing.
            // Check for 4xAA
            if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format,
                                                   false, MultiSampleType.FourSamples, out quality))
            {
                // even if a greater quality is returned, we only want quality 0
                pp.MultiSampleQuality = 0;
                pp.MultiSampleType    = MultiSampleType.FourSamples;
            }
            // Check for 2xAA
            else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware,
                                                        format, false, MultiSampleType.TwoSamples, out quality))
            {
                // even if a greater quality is returned, we only want quality 0
                pp.MultiSampleQuality = 0;
                pp.MultiSampleType    = MultiSampleType.TwoSamples;
            }

            // Does this video card support Depth24Stencil8Single
            // for the back buffer?
            if (adapter.CheckDeviceFormat(DeviceType.Hardware,
                                          adapter.CurrentDisplayMode.Format, TextureUsage.None,
                                          QueryUsages.None, ResourceType.RenderTarget,
                                          DepthFormat.Depth24Stencil8Single))
            {
                // if so, let's use that
                pp.AutoDepthStencilFormat = DepthFormat.Depth24Stencil8Single;
                pp.EnableAutoDepthStencil = true;
            }
            return;
        }
Esempio n. 7
0
        //Initialize
        protected override void Initialize()
        {
            System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.RealTime;

            //Set the windows forms, and directX graphics buffer to match the screen of the host computer
            int             maxHeight = 0; int maxWidth = 0; // vars to choose the max width and height
            GraphicsAdapter g = graphics.GraphicsDevice.Adapter;

            foreach (DisplayMode dm in g.SupportedDisplayModes)
            {
                if (maxHeight < dm.Height)
                {
                    maxHeight = dm.Height;
                }
                if (maxWidth < dm.Width)
                {
                    maxWidth = dm.Width;
                }
            }
            graphics.PreferredBackBufferHeight = maxHeight;
            graphics.PreferredBackBufferWidth  = maxWidth;

            //Configure DirectX graphics device
            graphics.GraphicsDevice.DepthStencilState = DepthStencilState.None;
            graphics.PreferMultiSampling = false;  //Set to true to have smooth texture edges
            GraphicsDevice.PresentationParameters.PresentationInterval = PresentInterval.One;
            graphics.ApplyChanges();

            //Merge directX drawing buffer with GDI+ drawing surface
            int[] margins = new int[] { 0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight };
            User32.DwmExtendFrameIntoClientArea(Window.Handle, ref margins);
            //xna game form
            form                   = System.Windows.Forms.Control.FromHandle(Window.Handle).FindForm();
            form.Visible           = true;
            form.AllowTransparency = true;
            //form.BackColor = System.Drawing.Color.Transparent;
            form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            form.TransparencyKey = form.BackColor;
            form.TopMost         = true;
            form.DesktopLocation = new System.Drawing.Point(0, 0);
            form.ClientSize      = new System.Drawing.Size(GraphicsDevice.DisplayMode.Width, GraphicsDevice.DisplayMode.Height);

            //Create a new directX spritebatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Initialize SSVEP (Using DirectX)
            SSVEP_DirectX_Advanced_V2 ssvepDX = new SSVEP_DirectX_Advanced_V2(this);

            ssvepDX.Initialize(form, spriteBatch);
            Components.Add(ssvepDX);

            switch (selectedApp)
            {
            case 0:
                var appControl = new BCI_Logic.BCI2000_Control.AnyApp.AdvancedControl(this);
                Components.Add(appControl);
                break;

            case 1:
                var appControl1 = new BCI_Logic.BCI2000_Control.AnyApp.BasicControl(this);
                Components.Add(appControl1);
                break;

            case 2:
                var appControl2 = new WowControl(this, "World Of Warcraft");
                Components.Add(appControl2);
                break;

            case 3:
                var appControl3 = new SpecificAppControl(this, "Google Earth");
                Components.Add(appControl3);
                break;

            case 4:
                var appControl4 = new CursorControl(this);
                Components.Add(appControl4);
                break;

            case 5:
                var appControl5 = new BCI_Logic.BCI2000_Control.AnyApp.AdvancedControl(this);
                Components.Add(appControl5);
                break;
            }


            //Cursor practice
            // InitCursor();
            //mousePos.X=GraphicsDevice.Viewport.Width / 2;
            //mousePos.Y=GraphicsDevice.Viewport.Height / 2;
            //Mouse.SetPosition(mousePos.X,mousePos.Y);

            base.Initialize();
        }
Esempio n. 8
0
 /// <summary>
 /// Measures the bounds of box and children, recursively.
 /// </summary>
 public void PerformLayout()
 {
     using var ig = new GraphicsAdapter();
     _htmlContainerInt.PerformLayout(ig);
 }
Esempio n. 9
0
        static void Main(string[] args)
        {
            bool  result = false;
            Mutex mutex  = new Mutex(true, "vibranceGUI~Mutex", out result);

            if (!result)
            {
                MessageBox.Show("You can run vibranceGUI only once at a time!", MessageBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            NativeMethods.SetDllDirectory(CommonUtils.GetVibrance_GUI_AppDataPath());

            GraphicsAdapter adapter     = GraphicsAdapterHelper.GetAdapter();
            Form            vibranceGui = null;

            if (adapter == GraphicsAdapter.Amd)
            {
                Func <List <ApplicationSetting>, Dictionary <string, Tuple <ResolutionModeWrapper, List <ResolutionModeWrapper> > >, IVibranceProxy> getProxy = (x, y) => new AmdDynamicVibranceProxy(Environment.Is64BitOperatingSystem
                    ? new AmdAdapter64()
                    : (IAmdAdapter) new AmdAdapter32(), x, y);
                vibranceGui = new VibranceGUI(getProxy,
                                              100,
                                              0,
                                              300,
                                              100,
                                              x => x.ToString());
            }
            else if (adapter == GraphicsAdapter.Nvidia)
            {
                const string nvidiaAdapterName = "vibranceDLL.dll";
                string       resourceName      = $"{typeof(Program).Namespace}.NVIDIA.{nvidiaAdapterName}";
                CommonUtils.LoadUnmanagedLibraryFromResource(
                    Assembly.GetExecutingAssembly(),
                    resourceName,
                    nvidiaAdapterName);
                Marshal.PrelinkAll(typeof(NvidiaDynamicVibranceProxy));

                vibranceGui = new VibranceGUI(
                    (x, y) => new NvidiaDynamicVibranceProxy(x, y),
                    NvidiaDynamicVibranceProxy.NvapiDefaultLevel,
                    NvidiaDynamicVibranceProxy.NvapiDefaultLevel,
                    NvidiaDynamicVibranceProxy.NvapiMaxLevel,
                    NvidiaDynamicVibranceProxy.NvapiDefaultLevel,
                    x => NvidiaVibranceValueWrapper.Find(x).Percentage);
            }
            else if (adapter == GraphicsAdapter.Unknown)
            {
                string errorMessage = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                if (MessageBox.Show(ErrorGraphicsAdapterUnknown + errorMessage,
                                    MessageBoxCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("https://twitter.com/juvlarN");
                }
                return;
            }
            else if (adapter == GraphicsAdapter.Ambiguous)
            {
                if (MessageBox.Show(ErrorGraphicsAdapterAmbiguous, MessageBoxCaption, MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://www.guru3d.com/files-details/display-driver-uninstaller-download.html");
                }
                return;
            }
            if (args.Contains("-minimized"))
            {
                vibranceGui.WindowState = FormWindowState.Minimized;
                ((VibranceGUI)vibranceGui).SetAllowVisible(false);
            }
            vibranceGui.Text += String.Format(" ({0}, {1})", adapter.ToString().ToUpper(), Application.ProductVersion);
            Application.Run(vibranceGui);

            GC.KeepAlive(mutex);
        }
Esempio n. 10
0
            public static SurfaceFormat SelectRenderTargetMode(bool preferFloat)
            {
                // Check stencil formats
                GraphicsAdapter adapter       = GraphicsAdapter.DefaultAdapter;
                SurfaceFormat   displayFormat = adapter.CurrentDisplayMode.Format;

                DepthFormat depthFormat = SelectStencilMode(displayFormat);

                SurfaceFormat surfaceFormat = SurfaceFormat.Color;

                if (preferFloat)
                {
                    if (adapter.CheckDepthStencilMatch(
                            DeviceType.Hardware,
                            displayFormat,
                            SurfaceFormat.Single,
                            depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.Single;
                    }
                    else if (adapter.CheckDepthStencilMatch(
                                 DeviceType.Hardware,
                                 displayFormat,
                                 SurfaceFormat.HalfSingle,
                                 depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.HalfSingle;
                    }
                    else if (adapter.CheckDepthStencilMatch(
                                 DeviceType.Hardware,
                                 displayFormat,
                                 SurfaceFormat.Color,
                                 depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.Color;
                    }
                    else if (adapter.CheckDepthStencilMatch(
                                 DeviceType.Reference,
                                 displayFormat,
                                 SurfaceFormat.Single,
                                 depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.Single;
                    }
                    else if (adapter.CheckDepthStencilMatch(
                                 DeviceType.Reference,
                                 displayFormat,
                                 SurfaceFormat.HalfSingle,
                                 depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.HalfSingle;
                    }
                    else if (adapter.CheckDepthStencilMatch(
                                 DeviceType.Reference,
                                 displayFormat,
                                 SurfaceFormat.Color,
                                 depthFormat))
                    {
                        surfaceFormat = SurfaceFormat.Color;
                    }
                    else
                    {
                        surfaceFormat = SurfaceFormat.Unknown;
                    }
                }

                return(surfaceFormat);
            }
Esempio n. 11
0
            public static DepthFormat SelectStencilMode(
                SurfaceFormat renderTargetFormat)
            {
                // Check stencil formats
                GraphicsAdapter adapter = GraphicsAdapter.DefaultAdapter;
                SurfaceFormat   format  = adapter.CurrentDisplayMode.Format;

                DepthFormat depthFormat = DepthFormat.Unknown;


                if (adapter.CheckDepthStencilMatch(
                        DeviceType.Hardware,
                        format,
                        renderTargetFormat,
                        DepthFormat.Depth24Stencil8))
                {
                    depthFormat = DepthFormat.Depth24Stencil8;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Hardware,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth24Stencil8Single))
                {
                    depthFormat = DepthFormat.Depth24Stencil8Single;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Hardware,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth24Stencil4))
                {
                    depthFormat = DepthFormat.Depth24Stencil4;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Hardware,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth15Stencil1))
                {
                    depthFormat = DepthFormat.Depth15Stencil1;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Reference,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth24Stencil8))
                {
                    depthFormat = DepthFormat.Depth24Stencil8;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Reference,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth24Stencil8Single))
                {
                    depthFormat = DepthFormat.Depth24Stencil8Single;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Reference,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth24Stencil4))
                {
                    depthFormat = DepthFormat.Depth24Stencil4;
                }
                else if (adapter.CheckDepthStencilMatch(
                             DeviceType.Reference,
                             format,
                             renderTargetFormat,
                             DepthFormat.Depth15Stencil1))
                {
                    depthFormat = DepthFormat.Depth15Stencil1;
                }

                return(depthFormat);
            }
Esempio n. 12
0
        protected void AddDeviceWithDefaultDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var displayMode = new DisplayMode(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));

            AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
        }
Esempio n. 13
0
        private void ChangeOrCreateDevice(bool forceCreate)
        {
            if (forceCreate)
            {
                // Make sure that all GraphicsAdapter are cleared and removed when device is disposed.
                // and re-initialized them
                GraphicsAdapter.Reset();
            }

            isChangingDevice = true;
            int width  = game.Window.ClientBounds.Width;
            int height = game.Window.ClientBounds.Height;

            OnDeviceChangeBegin(this, EventArgs.Empty);

            bool isBeginScreenDeviceChange = false;

            try
            {
                // Notifies the game window for the new orientation
                game.Window.SetSupportedOrientations(SelectOrientation(supportedOrientations, PreferredBackBufferWidth, PreferredBackBufferHeight, true));

                var graphicsDeviceInformation = FindBestDevice(forceCreate);
                game.Window.BeginScreenDeviceChange(graphicsDeviceInformation.PresentationParameters.IsFullScreen);
                isBeginScreenDeviceChange = true;
                bool needToCreateNewDevice = true;

                // If we are not forced to create a new device and this is already an existing GraphicsDevice
                // try to reset and resize it.
                if (!forceCreate && GraphicsDevice != null)
                {
                    OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation));
                    if (CanResetDevice(graphicsDeviceInformation))
                    {
                        try
                        {
                            var newWidth       = graphicsDeviceInformation.PresentationParameters.BackBufferWidth;
                            var newHeight      = graphicsDeviceInformation.PresentationParameters.BackBufferHeight;
                            var newFormat      = graphicsDeviceInformation.PresentationParameters.BackBufferFormat;
                            var newOutputIndex = graphicsDeviceInformation.PresentationParameters.PreferredFullScreenOutputIndex;

                            GraphicsDevice.Presenter.PrefferedFullScreenOutputIndex = newOutputIndex;
                            GraphicsDevice.Presenter.Resize(newWidth, newHeight, newFormat, graphicsDeviceInformation.PresentationParameters.RefreshRate);

                            // Change full screen if needed
                            GraphicsDevice.Presenter.IsFullScreen = graphicsDeviceInformation.PresentationParameters.IsFullScreen;

                            needToCreateNewDevice = false;
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex);
                        }
                    }
                }

                // If we still need to create a device, then we need to create it
                if (needToCreateNewDevice)
                {
                    CreateDevice(graphicsDeviceInformation);
                }

                var presentationParameters = GraphicsDevice.Presenter.Description;
                isReallyFullScreen = presentationParameters.IsFullScreen;
                if (presentationParameters.BackBufferWidth != 0)
                {
                    width = presentationParameters.BackBufferWidth;
                }

                if (presentationParameters.BackBufferHeight != 0)
                {
                    height = presentationParameters.BackBufferHeight;
                }

                deviceSettingsChanged = false;

                OnDeviceChangeEnd(this, EventArgs.Empty);
            }
            finally
            {
                if (isBeginScreenDeviceChange)
                {
                    game.Window.EndScreenDeviceChange(width, height);
                }

                currentWindowOrientation = game.Window.CurrentOrientation;
                isChangingDevice         = false;
            }
        }
Esempio n. 14
0
        void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            //XBOX
            //e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 0;
            //e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType = MultiSampleType.FourSamples; //AA 4x
            //e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType = MultiSampleType.TwoSamples; //AA 2x

            //PC
            GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
            SurfaceFormat   format  = adapter.CurrentDisplayMode.Format;

            if (_supersample == 16) //try 16x AA
            {
                if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, ConfigReader.Instance.GetValueAsBool("Fullscreen"), MultiSampleType.SixteenSamples))
                {
                    //supports 16x AA
                    graphics.PreferMultiSampling = true;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 0;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType    = MultiSampleType.SixteenSamples;
                }
                else
                {
                    _supersample = 8;  //8x AA not supported, go to 4x AA
                }
            }

            if (_supersample == 8) //try 8x AA
            {
                if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, ConfigReader.Instance.GetValueAsBool("Fullscreen"), MultiSampleType.EightSamples))
                {
                    //supports 8x AA
                    graphics.PreferMultiSampling = true;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 0;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType    = MultiSampleType.EightSamples;
                }
                else
                {
                    _supersample = 4;  //8x AA not supported, go to 4x AA
                }
            }

            //if (_supersample > 4) _supersample = 4; //max supported for render targets...

            if (_supersample == 4) //try 4x AA
            {
                if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, ConfigReader.Instance.GetValueAsBool("Fullscreen"), MultiSampleType.FourSamples))
                {
                    //supports 4x AA
                    graphics.PreferMultiSampling = true;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 0;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType    = MultiSampleType.FourSamples;
                }
                else
                {
                    _supersample = 2;  //4x AA not supported, go to 2x AA
                }
            }

            if (_supersample == 2) //try 2x AA
            {
                if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, ConfigReader.Instance.GetValueAsBool("Fullscreen"), MultiSampleType.FourSamples))
                {
                    //supports 2x AA
                    graphics.PreferMultiSampling = true;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 0;
                    e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType    = MultiSampleType.TwoSamples;
                }
                else
                {
                    _supersample = 1;  //2x AA not supported, use no AA
                }
            }

            return;
        }