The settings used in creation of the graphics device. See GraphicsDeviceManager.PreparingDeviceSettings.
Example #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            GraphicsDeviceInformation gdi = obj as GraphicsDeviceInformation;

            if (gdi == null)
            {
                return(false);
            }

            return(deviceType == gdi.deviceType &&
                   presentationParameters == gdi.presentationParameters);
        }
Example #2
0
        /// <summary>
        /// Prevent the system from clearing the backbuffer each frame.
        /// </summary>
        public void PreparingDeviceSettingsHandler(object sender, EventArgs e)
        {
            PreparingDeviceSettingsEventArgs args = e as PreparingDeviceSettingsEventArgs;

            if (args != null)
            {
                Microsoft.Xna.Framework.GraphicsDeviceInformation info = args.GraphicsDeviceInformation;
                info.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PlatformContents;

                /*
                 * // PresentInterval.Two only works in full screen mode.
                 * if (BokuSettings.Settings.FullScreen)
                 * {
                 *  info.PresentationParameters.PresentationInterval = presentInterval;
                 * }
                 */
            }
        }
Example #3
0
        void IGraphicsDeviceManager.CreateDevice()
        {
            if (graphicsDevice != null)
            {
                return;
            }

            // Set the default device information
            GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();

            gdi.Adapter                = GraphicsAdapter.DefaultAdapter;
            gdi.GraphicsProfile        = GraphicsProfile;
            gdi.PresentationParameters = new PresentationParameters();
            gdi.PresentationParameters.DeviceWindowHandle = game.Window.Handle;
            gdi.PresentationParameters.DepthStencilFormat = PreferredDepthStencilFormat;
            gdi.PresentationParameters.IsFullScreen       = false;

            // Give the user a chance to change the initial settings
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );

            // Apply these settings to this GraphicsDeviceManager
            GraphicsProfile             = gdi.GraphicsProfile;
            PreferredBackBufferFormat   = gdi.PresentationParameters.BackBufferFormat;
            PreferredDepthStencilFormat = gdi.PresentationParameters.DepthStencilFormat;

            // Create the GraphicsDevice, hook the callbacks
            graphicsDevice = new GraphicsDevice(
                gdi.Adapter,
                gdi.GraphicsProfile,
                gdi.PresentationParameters
                );
            graphicsDevice.Disposing       += OnDeviceDisposing;
            graphicsDevice.DeviceResetting += OnDeviceResetting;
            graphicsDevice.DeviceReset     += OnDeviceReset;

            // Set device defaults
            ApplyChanges();

            // Call the DeviceCreated Event
            OnDeviceCreated(this, EventArgs.Empty);
        }
Example #4
0
        /// <summary>
        /// This populates a GraphicsDeviceInformation instance and invokes PreparingDeviceSettings to
        /// allow users to change the settings. Then returns that GraphicsDeviceInformation.
        /// Throws NullReferenceException if users set GraphicsDeviceInformation.PresentationParameters to null.
        /// </summary>
        private GraphicsDeviceInformation DoPreparingDeviceSettings()
        {
            var gdi = new GraphicsDeviceInformation();

            PrepareGraphicsDeviceInformation(gdi);

            if (PreparingDeviceSettings != null)
            {
                // this allows users to overwrite settings through the argument
                var args = new PreparingDeviceSettingsEventArgs(gdi);
                PreparingDeviceSettings(this, args);

                if (gdi.PresentationParameters == null || gdi.Adapter == null)
                {
                    throw new NullReferenceException("Members should not be set to null in PreparingDeviceSettingsEventArgs");
                }

                if (gdi.PresentationParameters.MultiSampleCount > 0)
                {
                    // Round down MultiSampleCount to the nearest power of two
                    // hack from http://stackoverflow.com/a/2681094
                    // Note: this will return an incorrect, but large value
                    // for very large numbers. That doesn't matter because
                    // the number will get clamped below anyway in this case.
                    var msc = gdi.PresentationParameters.MultiSampleCount;
                    msc  = msc | (msc >> 1);
                    msc  = msc | (msc >> 2);
                    msc  = msc | (msc >> 4);
                    msc -= (msc >> 1);

                    if (GraphicsDevice != null)
                    {
                        // and clamp it to what the device can handle
                        if (msc > GraphicsDevice.GraphicsCapabilities.MaxMultiSampleCount)
                        {
                            msc = GraphicsDevice.GraphicsCapabilities.MaxMultiSampleCount;
                        }
                    }
                    gdi.PresentationParameters.MultiSampleCount = msc;
                }
            }

            return(gdi);
        }
Example #5
0
        void IGraphicsDeviceManager.CreateDevice()
        {
            // Set the default device information
            GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();

            gdi.Adapter                = GraphicsAdapter.DefaultAdapter;
            gdi.GraphicsProfile        = GraphicsProfile;
            gdi.PresentationParameters = new PresentationParameters();
            gdi.PresentationParameters.DeviceWindowHandle = game.Window.Handle;
            gdi.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24;
            gdi.PresentationParameters.IsFullScreen       = false;

            // Give the user a chance to change the initial settings
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );

            // Apply these settings to this GraphicsDeviceManager
            GraphicsProfile             = gdi.GraphicsProfile;
            PreferredBackBufferFormat   = gdi.PresentationParameters.BackBufferFormat;
            PreferredDepthStencilFormat = gdi.PresentationParameters.DepthStencilFormat;

            // Create the GraphicsDevice, apply the initial settings.
            graphicsDevice = new GraphicsDevice(
                gdi.Adapter,
                gdi.GraphicsProfile,
                gdi.PresentationParameters
                );
            ApplyChanges();

            /* Set the new display orientation on the touch panel.
             *
             * TODO: In XNA this seems to be done as part of the
             * GraphicsDevice.DeviceReset event... we need to get
             * those working.
             */
            TouchPanel.DisplayOrientation =
                graphicsDevice.PresentationParameters.DisplayOrientation;

            // Call the DeviceCreated Event
            OnDeviceCreated(this, EventArgs.Empty);
        }
Example #6
0
        private void CreateDevice(GraphicsDeviceInformation gdi)
        {
            if (_graphicsDevice != null)
            {
                return;
            }

            _graphicsDevice     = new GraphicsDevice(gdi.Adapter, gdi.GraphicsProfile, this.PreferHalfPixelOffset, gdi.PresentationParameters);
            _shouldApplyChanges = false;

            // hook up reset events
            GraphicsDevice.DeviceReset     += (sender, args) => OnDeviceReset(args);
            GraphicsDevice.DeviceResetting += (sender, args) => OnDeviceResetting(args);

            // update the touchpanel display size when the graphicsdevice is reset
            _graphicsDevice.DeviceReset         += UpdateTouchPanel;
            _graphicsDevice.PresentationChanged += OnPresentationChanged;

            OnDeviceCreated(EventArgs.Empty);
        }
        /// <summary>
        /// This populates a GraphicsDeviceInformation instance and invokes PreparingDeviceSettings to
        /// allow users to change the settings. Then returns that GraphicsDeviceInformation.
        /// Throws NullReferenceException if users set GraphicsDeviceInformation.PresentationParameters to null.
        /// </summary>
        private GraphicsDeviceInformation DoPreparingDeviceSettings()
        {
            var gdi = new GraphicsDeviceInformation();

            PrepareGraphicsDeviceInformation(gdi);

            if (PreparingDeviceSettings != null)
            {
                // this allows users to overwrite settings through the argument
                var args = new PreparingDeviceSettingsEventArgs(gdi);
                PreparingDeviceSettings(this, args);

                if (gdi.PresentationParameters == null || gdi.Adapter == null)
                {
                    throw new NullReferenceException("Members should not be set to null in PreparingDeviceSettingsEventArgs");
                }
            }

            return(gdi);
        }
Example #8
0
 private void CreateDevice(GraphicsDeviceInformation newInfo)
 {
     if (device != null)
     {
         device.Dispose();
         device = null;
     }
     OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo));
     MassagePresentParameters(newInfo.PresentationParameters);
     try
     {
         ValidateGraphicsDeviceInformation(newInfo);
         device =
             new GraphicsDevice(newInfo.Adapter, newInfo.DeviceType, game.Window.Handle, newInfo.CreationOptions,
                                newInfo.PresentationParameters);
         this.device.DeviceResetting += new EventHandler(HandleDeviceResetting);
         this.device.DeviceReset     += new EventHandler(HandleDeviceReset);
         this.device.DeviceLost      += new EventHandler(HandleDeviceLost);
         this.device.Disposing       += new EventHandler(HandleDisposing);
     }
     catch (DeviceNotSupportedException exception)
     {
         throw new NoSuitableGraphicsDeviceException("", exception);
     }
     catch (DriverInternalErrorException exception2)
     {
         throw new NoSuitableGraphicsDeviceException("", exception2);
     }
     catch (ArgumentException exception3)
     {
         throw new NoSuitableGraphicsDeviceException("", exception3);
     }
     catch (Exception exception4)
     {
         throw new NoSuitableGraphicsDeviceException("", exception4);
     }
     OnDeviceCreated(this, EventArgs.Empty);
 }
Example #9
0
        private void Initialize()
        {
            _game.Window.SetSupportedOrientations(_supportedOrientations);

            var presentationParameters = new PresentationParameters();

            PreparePresentationParameters(presentationParameters);

            // Allow for any per-platform changes to the presentation.
            PlatformInitialize(presentationParameters);

            // TODO: Implement multisampling (aka anti-alising) for all platforms!
            if (PreparingDeviceSettings != null)
            {
                var gdi = new GraphicsDeviceInformation();
                gdi.GraphicsProfile        = GraphicsProfile; // Microsoft defaults this to Reach.
                gdi.Adapter                = GraphicsAdapter.DefaultAdapter;
                gdi.PresentationParameters = presentationParameters;
                var pe = new PreparingDeviceSettingsEventArgs(gdi);
                PreparingDeviceSettings(this, pe);
                presentationParameters = pe.GraphicsDeviceInformation.PresentationParameters;
                GraphicsProfile        = pe.GraphicsDeviceInformation.GraphicsProfile;
            }

            // Create and initialize the graphics device.
            _graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, presentationParameters);

            // Set the new display size on the touch panel.
            //
            // TODO: In XNA this seems to be done as part of the
            // GraphicsDevice.DeviceReset event... we need to get
            // those working.
            //
            TouchPanel.DisplayWidth       = _graphicsDevice.PresentationParameters.BackBufferWidth;
            TouchPanel.DisplayHeight      = _graphicsDevice.PresentationParameters.BackBufferHeight;
            TouchPanel.DisplayOrientation = _graphicsDevice.PresentationParameters.DisplayOrientation;
        }
		public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation)
		{
			_graphicsDeviceInformation = graphicsDeviceInformation;
		}
 /// <summary>
 /// Create a new instance of the event.
 /// </summary>
 /// <param name="graphicsDeviceInformation">The default settings to be used in device creation.</param>
 public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation)
 {
     GraphicsDeviceInformation = graphicsDeviceInformation;
 }
        private void Initialize()
        {
            var presentationParameters = new PresentationParameters();

            presentationParameters.DepthStencilFormat = DepthFormat.Depth24;

#if WINDOWS || WINRT
            _game.Window.SetSupportedOrientations(_supportedOrientations);

            presentationParameters.BackBufferFormat   = _preferredBackBufferFormat;
            presentationParameters.BackBufferWidth    = _preferredBackBufferWidth;
            presentationParameters.BackBufferHeight   = _preferredBackBufferHeight;
            presentationParameters.DepthStencilFormat = _preferredDepthStencilFormat;
            presentationParameters.IsFullScreen       = false;

#if WINDOWS_PHONE
            // Nothing to do!
#elif WINDOWS_UAP
            presentationParameters.DeviceWindowHandle = IntPtr.Zero;
            presentationParameters.SwapChainPanel     = this.SwapChainPanel;
#elif WINDOWS_STORE
            // The graphics device can use a XAML panel or a window
            // to created the default swapchain target.
            if (this.SwapChainBackgroundPanel != null)
            {
                presentationParameters.DeviceWindowHandle       = IntPtr.Zero;
                presentationParameters.SwapChainBackgroundPanel = this.SwapChainBackgroundPanel;
            }
            else
            {
                presentationParameters.DeviceWindowHandle       = _game.Window.Handle;
                presentationParameters.SwapChainBackgroundPanel = null;
            }
#else
            presentationParameters.DeviceWindowHandle = _game.Window.Handle;
#endif
#else
#if MONOMAC
            presentationParameters.IsFullScreen = _wantFullScreen;
#elif LINUX
            presentationParameters.IsFullScreen = _wantFullScreen;
#else
            // Set "full screen"  as default
            presentationParameters.IsFullScreen = true;
#endif // MONOMAC
#endif // WINDOWS || WINRT

            // TODO: Implement multisampling (aka anti-alising) for all platforms!
            if (PreparingDeviceSettings != null)
            {
                GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();
                gdi.GraphicsProfile        = GraphicsProfile; // Microsoft defaults this to Reach.
                gdi.Adapter                = GraphicsAdapter.DefaultAdapter;
                gdi.PresentationParameters = presentationParameters;
                PreparingDeviceSettingsEventArgs pe = new PreparingDeviceSettingsEventArgs(gdi);
                PreparingDeviceSettings(this, pe);
                presentationParameters = pe.GraphicsDeviceInformation.PresentationParameters;
                GraphicsProfile        = pe.GraphicsDeviceInformation.GraphicsProfile;
            }

            // Needs to be before ApplyChanges()
            _graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, presentationParameters);

#if !MONOMAC
            ApplyChanges();
#endif

            // Set the new display size on the touch panel.
            //
            // TODO: In XNA this seems to be done as part of the
            // GraphicsDevice.DeviceReset event... we need to get
            // those working.
            //
            TouchPanel.DisplayWidth       = _graphicsDevice.PresentationParameters.BackBufferWidth;
            TouchPanel.DisplayHeight      = _graphicsDevice.PresentationParameters.BackBufferHeight;
            TouchPanel.DisplayOrientation = _graphicsDevice.PresentationParameters.DisplayOrientation;
        }
        private void Initialize()
        {
            var presentationParameters = new PresentationParameters();

            presentationParameters.DepthStencilFormat = DepthFormat.Depth24;

#if (WINDOWS || WINRT) && !DESKTOPGL
            _game.Window.SetSupportedOrientations(_supportedOrientations);

            presentationParameters.BackBufferFormat   = _preferredBackBufferFormat;
            presentationParameters.BackBufferWidth    = _preferredBackBufferWidth;
            presentationParameters.BackBufferHeight   = _preferredBackBufferHeight;
            presentationParameters.DepthStencilFormat = _preferredDepthStencilFormat;
            presentationParameters.IsFullScreen       = false;

#if WINDOWS_UAP
            presentationParameters.DeviceWindowHandle = IntPtr.Zero;
            presentationParameters.SwapChainPanel     = this.SwapChainPanel;
#else
            presentationParameters.DeviceWindowHandle = _game.Window.Handle;
#endif
#else
#if MONOMAC || DESKTOPGL
            presentationParameters.IsFullScreen = _wantFullScreen;
#elif WEB
            presentationParameters.IsFullScreen = false;
#else
            // Set "full screen"  as default
            presentationParameters.IsFullScreen = true;
#endif // MONOMAC
#endif // WINDOWS || WINRT

            // TODO: Implement multisampling (aka anti-alising) for all platforms!
            var preparingDeviceSettingsHandler = PreparingDeviceSettings;

            if (preparingDeviceSettingsHandler != null)
            {
                GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();
                gdi.GraphicsProfile        = GraphicsProfile; // Microsoft defaults this to Reach.
                gdi.Adapter                = GraphicsAdapter.DefaultAdapter;
                gdi.PresentationParameters = presentationParameters;
                PreparingDeviceSettingsEventArgs pe = new PreparingDeviceSettingsEventArgs(gdi);
                preparingDeviceSettingsHandler(this, pe);
                presentationParameters = pe.GraphicsDeviceInformation.PresentationParameters;
                GraphicsProfile        = pe.GraphicsDeviceInformation.GraphicsProfile;
            }

            // Needs to be before ApplyChanges()
            _graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, this.PreferHalfPixelOffset, presentationParameters);

#if !MONOMAC
            ApplyChanges();
#endif

            // Set the new display size on the touch panel.
            //
            // TODO: In XNA this seems to be done as part of the
            // GraphicsDevice.DeviceReset event... we need to get
            // those working.
            //
            TouchPanel.DisplayWidth       = _graphicsDevice.PresentationParameters.BackBufferWidth;
            TouchPanel.DisplayHeight      = _graphicsDevice.PresentationParameters.BackBufferHeight;
            TouchPanel.DisplayOrientation = _graphicsDevice.PresentationParameters.DisplayOrientation;
        }
Example #14
0
        public void ApplyChanges()
        {
            /* Calling ApplyChanges() before CreateDevice() forces CreateDevice.
             * We can then return early since CreateDevice will call this again!
             * -flibit
             */
            if (graphicsDevice == null)
            {
                (this as IGraphicsDeviceManager).CreateDevice();
                return;
            }

            // ApplyChanges() calls with no actual changes should be ignored.
            if (!prefsChanged && !useResizedBackBuffer)
            {
                return;
            }

            // Recreate device information before resetting
            GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();

            gdi.Adapter                = graphicsDevice.Adapter;
            gdi.GraphicsProfile        = graphicsDevice.GraphicsProfile;
            gdi.PresentationParameters = graphicsDevice.PresentationParameters.Clone();

            bool supportsOrientations = FNAPlatform.SupportsOrientationChanges();

            /* Apply the GraphicsDevice changes to the new Parameters.
             * Note that PreparingDeviceSettings can override any of these!
             * -flibit
             */
            gdi.PresentationParameters.BackBufferFormat =
                PreferredBackBufferFormat;
            if (useResizedBackBuffer)
            {
                gdi.PresentationParameters.BackBufferWidth =
                    resizedBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    resizedBackBufferHeight;
                useResizedBackBuffer = false;
            }
            else
            {
                if (!supportsOrientations)
                {
                    gdi.PresentationParameters.BackBufferWidth =
                        PreferredBackBufferWidth;
                    gdi.PresentationParameters.BackBufferHeight =
                        PreferredBackBufferHeight;
                }
                else
                {
                    /* Flip the backbuffer dimensions to scale
                     * appropriately to the current orientation.
                     */
                    int min = Math.Min(PreferredBackBufferWidth, PreferredBackBufferHeight);
                    int max = Math.Max(PreferredBackBufferWidth, PreferredBackBufferHeight);

                    if (gdi.PresentationParameters.DisplayOrientation == DisplayOrientation.Portrait)
                    {
                        gdi.PresentationParameters.BackBufferWidth  = min;
                        gdi.PresentationParameters.BackBufferHeight = max;
                    }
                    else
                    {
                        gdi.PresentationParameters.BackBufferWidth  = max;
                        gdi.PresentationParameters.BackBufferHeight = min;
                    }
                }
            }
            gdi.PresentationParameters.DepthStencilFormat =
                PreferredDepthStencilFormat;
            gdi.PresentationParameters.IsFullScreen =
                IsFullScreen;
            gdi.PresentationParameters.PresentationInterval =
                SynchronizeWithVerticalRetrace ?
                PresentInterval.One :
                PresentInterval.Immediate;
            if (!PreferMultiSampling)
            {
                gdi.PresentationParameters.MultiSampleCount = 0;
            }
            else if (gdi.PresentationParameters.MultiSampleCount == 0)
            {
                /* XNA4 seems to have an upper limit of 8, but I'm willing to
                 * limit this only in GraphicsDeviceManager's default setting.
                 * If you want even higher values, Reset() with a custom value.
                 * -flibit
                 */
                gdi.PresentationParameters.MultiSampleCount = Math.Min(
                    graphicsDevice.GLDevice.MaxMultiSampleCount,
                    8
                    );
            }

            // Give the user a chance to override the above settings.
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );

            // Reset!
            if (supportsOrientations)
            {
                game.Window.SetSupportedOrientations(
                    INTERNAL_supportedOrientations
                    );
            }
            game.Window.BeginScreenDeviceChange(
                gdi.PresentationParameters.IsFullScreen
                );
            game.Window.EndScreenDeviceChange(
                gdi.Adapter.DeviceName,
                gdi.PresentationParameters.BackBufferWidth,
                gdi.PresentationParameters.BackBufferHeight
                );
            // FIXME: This should be before EndScreenDeviceChange! -flibit
            graphicsDevice.Reset(
                gdi.PresentationParameters,
                gdi.Adapter
                );
            prefsChanged = false;
        }
Example #15
0
        public void ApplyChanges()
        {
            // Calling ApplyChanges() before CreateDevice() should have no effect.
            if (graphicsDevice == null)
            {
                return;
            }

            // Recreate device information before resetting
            GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();

            gdi.Adapter                = GraphicsDevice.Adapter;
            gdi.GraphicsProfile        = GraphicsDevice.GraphicsProfile;
            gdi.PresentationParameters = GraphicsDevice.PresentationParameters.Clone();

            /* Apply the GraphicsDevice changes to the new Parameters.
             * Note that PreparingDeviceSettings can override any of these!
             * -flibit
             */
            gdi.PresentationParameters.BackBufferFormat =
                PreferredBackBufferFormat;
            if (useResizedBackBuffer)
            {
                gdi.PresentationParameters.BackBufferWidth =
                    resizedBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    resizedBackBufferHeight;
                useResizedBackBuffer = false;
            }
            else
            {
                gdi.PresentationParameters.BackBufferWidth =
                    PreferredBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    PreferredBackBufferHeight;
            }
            gdi.PresentationParameters.DepthStencilFormat =
                PreferredDepthStencilFormat;
            gdi.PresentationParameters.IsFullScreen =
                IsFullScreen;
            if (!PreferMultiSampling)
            {
                gdi.PresentationParameters.MultiSampleCount = 0;
            }
            else if (gdi.PresentationParameters.MultiSampleCount == 0)
            {
                /* XNA4 seems to have an upper limit of 8, but I'm willing to
                 * limit this only in GraphicsDeviceManager's default setting.
                 * If you want even higher values, Reset() with a custom value.
                 * -flibit
                 */
                gdi.PresentationParameters.MultiSampleCount = Math.Min(
                    GraphicsDevice.GLDevice.MaxMultiSampleCount,
                    8
                    );
            }

            // Give the user a chance to override the above settings.
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );

            // Reset!
            game.Window.BeginScreenDeviceChange(
                gdi.PresentationParameters.IsFullScreen
                );
            game.Window.EndScreenDeviceChange(
                gdi.Adapter.DeviceName,
                gdi.PresentationParameters.BackBufferWidth,
                gdi.PresentationParameters.BackBufferHeight
                );
            // FIXME: This should be before EndScreenDeviceChange! -flibit
            GraphicsDevice.Reset(
                gdi.PresentationParameters,
                gdi.Adapter
                );

            // Apply the PresentInterval.
            FNAPlatform.SetPresentationInterval(
                SynchronizeWithVerticalRetrace ?
                gdi.PresentationParameters.PresentationInterval :
                PresentInterval.Immediate
                );
        }
Example #16
0
 protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo)
 {
     return(true);//TODO
 }
        public override bool Equals(object obj)
        {
            GraphicsDeviceInformation information = obj as GraphicsDeviceInformation;

            if (information == null)
            {
                return(false);
            }
            if (!information.adapter.Equals(this.adapter))
            {
                return(false);
            }
            if (!information.createOptions.Equals(this.createOptions))
            {
                return(false);
            }
            if (!information.deviceType.Equals(this.deviceType))
            {
                return(false);
            }
            if (information.PresentationParameters.AutoDepthStencilFormat != this.PresentationParameters.AutoDepthStencilFormat)
            {
                return(false);
            }
            if (information.PresentationParameters.BackBufferCount != this.PresentationParameters.BackBufferCount)
            {
                return(false);
            }
            if (information.PresentationParameters.BackBufferFormat != this.PresentationParameters.BackBufferFormat)
            {
                return(false);
            }
            if (information.PresentationParameters.BackBufferHeight != this.PresentationParameters.BackBufferHeight)
            {
                return(false);
            }
            if (information.PresentationParameters.BackBufferWidth != this.PresentationParameters.BackBufferWidth)
            {
                return(false);
            }
            if (information.PresentationParameters.DeviceWindowHandle != this.PresentationParameters.DeviceWindowHandle)
            {
                return(false);
            }
            if (information.PresentationParameters.EnableAutoDepthStencil != this.PresentationParameters.EnableAutoDepthStencil)
            {
                return(false);
            }
            if (information.PresentationParameters.FullScreenRefreshRateInHz != this.PresentationParameters.FullScreenRefreshRateInHz)
            {
                return(false);
            }
            if (information.PresentationParameters.IsFullScreen != this.PresentationParameters.IsFullScreen)
            {
                return(false);
            }
            if (information.PresentationParameters.MultiSampleQuality != this.PresentationParameters.MultiSampleQuality)
            {
                return(false);
            }
            if (information.PresentationParameters.MultiSampleType != this.PresentationParameters.MultiSampleType)
            {
                return(false);
            }
            if (information.PresentationParameters.PresentationInterval != this.PresentationParameters.PresentationInterval)
            {
                return(false);
            }
            if (information.PresentationParameters.PresentOptions != this.PresentationParameters.PresentOptions)
            {
                return(false);
            }
            if (information.PresentationParameters.SwapEffect != this.PresentationParameters.SwapEffect)
            {
                return(false);
            }
            return(true);
        }
Example #18
0
 protected virtual bool CanResetDevice(
     GraphicsDeviceInformation newDeviceInfo
     )
 {
     throw new NotImplementedException();
 }
Example #19
0
        private void ChangeDevice(bool forceCreate)
        {
            if (game == null)
            {
                throw new InvalidOperationException(Resources.GraphicsComponentNotAttachedToGame);
            }
            CheckForAvailableSupportedHardware();
            inDeviceTransition = true;
            string screenDeviceName = game.Window.ScreenDeviceName;
            int    width            = game.Window.ClientBounds.Width;
            int    height           = game.Window.ClientBounds.Height;
            bool   flag             = false;

            try
            {
                GraphicsDeviceInformation graphicsDeviceInformation = FindBestDevice(forceCreate);
                game.Window.BeginScreenDeviceChange(graphicsDeviceInformation.PresentationParameters.IsFullScreen);
                flag = true;
                bool flag2 = true;
                if (!forceCreate && (device != null))
                {
                    OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation));
                    if (CanResetDevice(graphicsDeviceInformation))
                    {
                        try
                        {
                            GraphicsDeviceInformation information2 = graphicsDeviceInformation.Clone();
                            MassagePresentParameters(graphicsDeviceInformation.PresentationParameters);
                            ValidateGraphicsDeviceInformation(graphicsDeviceInformation);
                            device.Reset(information2.PresentationParameters);
                            flag2 = false;
                        }
                        catch
                        {
                        }
                    }
                }
                if (flag2)
                {
                    CreateDevice(graphicsDeviceInformation);
                }
                PresentationParameters presentationParameters = device.PresentationParameters;
                screenDeviceName   = device.CreationParameters.Adapter.DeviceName;
                isReallyFullScreen = presentationParameters.IsFullScreen;
                if (presentationParameters.BackBufferWidth != 0)
                {
                    width = presentationParameters.BackBufferWidth;
                }
                if (presentationParameters.BackBufferHeight != 0)
                {
                    height = presentationParameters.BackBufferHeight;
                }
                isDeviceDirty = false;
            }
            finally
            {
                if (flag)
                {
                    game.Window.EndScreenDeviceChange(screenDeviceName, width, height);
                }
                inDeviceTransition = false;
            }
        }
Example #20
0
        private void AddDevices(bool anySuitableDevice, List <GraphicsDeviceInformation> foundDevices)
        {
            IntPtr handle = game.Window.Handle;

            foreach (GraphicsAdapter adapter in GraphicsAdapter.Adapters)
            {
                if (!anySuitableDevice && !IsWindowOnAdapter(handle, adapter))
                {
                    continue;
                }
                foreach (DeviceType type in ValidDeviceTypes)
                {
                    try
                    {
                        GraphicsDeviceCapabilities capabilities = adapter.GetCapabilities(type);
                        if ((capabilities.DeviceCapabilities.IsDirect3D9Driver &&
                             (capabilities.MaxPixelShaderProfile >= MinimumPixelShaderProfile)) &&
                            (capabilities.MaxVertexShaderProfile >= MinimumVertexShaderProfile))
                        {
                            CreateOptions none = CreateOptions.None;
                            if (capabilities.DeviceCapabilities.SupportsHardwareTransformAndLight)
                            {
                                none |= CreateOptions.HardwareVertexProcessing;
                            }
                            else
                            {
                                none |= CreateOptions.SoftwareVertexProcessing;
                            }
                            GraphicsDeviceInformation baseDeviceInfo = new GraphicsDeviceInformation();
                            baseDeviceInfo.Adapter         = adapter;
                            baseDeviceInfo.DeviceType      = type;
                            baseDeviceInfo.CreationOptions = none;
                            baseDeviceInfo.PresentationParameters.DeviceWindowHandle        = IntPtr.Zero;
                            baseDeviceInfo.PresentationParameters.EnableAutoDepthStencil    = true;
                            baseDeviceInfo.PresentationParameters.BackBufferCount           = 1;
                            baseDeviceInfo.PresentationParameters.PresentOptions            = PresentOptions.None;
                            baseDeviceInfo.PresentationParameters.SwapEffect                = SwapEffect.Default;
                            baseDeviceInfo.PresentationParameters.FullScreenRefreshRateInHz = 0;
                            baseDeviceInfo.PresentationParameters.MultiSampleQuality        = 0;
                            baseDeviceInfo.PresentationParameters.MultiSampleType           = MultiSampleType.None;
                            baseDeviceInfo.PresentationParameters.IsFullScreen              = IsFullScreen;
                            baseDeviceInfo.PresentationParameters.PresentationInterval      = SynchronizeWithVerticalRetrace
                                                                                             ? PresentInterval.One
                                                                                             : PresentInterval.Immediate;
                            for (int i = 0; i < ValidAdapterFormats.Length; i++)
                            {
                                AddDevices(adapter, type, adapter.CurrentDisplayMode, baseDeviceInfo, foundDevices);
                                if (isFullScreen)
                                {
                                    foreach (DisplayMode mode in adapter.SupportedDisplayModes[ValidAdapterFormats[i]])
                                    {
                                        if ((mode.Width >= 640) && (mode.Height >= 480))
                                        {
                                            AddDevices(adapter, type, mode, baseDeviceInfo, foundDevices);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (DeviceNotSupportedException)
                    {
                    }
                }
            }
        }
Example #21
0
        private void INTERNAL_CreateGraphicsDeviceInformation(
            GraphicsDeviceInformation gdi
            )
        {
            /* Apply the GraphicsDevice changes to the new Parameters.
             * Note that PreparingDeviceSettings can override any of these!
             * -flibit
             */
            if (useResizedBackBuffer)
            {
                gdi.PresentationParameters.BackBufferWidth =
                    resizedBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    resizedBackBufferHeight;
                useResizedBackBuffer = false;
            }
            else
            {
                if (!supportsOrientations)
                {
                    gdi.PresentationParameters.BackBufferWidth =
                        PreferredBackBufferWidth;
                    gdi.PresentationParameters.BackBufferHeight =
                        PreferredBackBufferHeight;
                }
                else
                {
                    /* Flip the backbuffer dimensions to scale
                     * appropriately to the current orientation.
                     */
                    int min = Math.Min(PreferredBackBufferWidth, PreferredBackBufferHeight);
                    int max = Math.Max(PreferredBackBufferWidth, PreferredBackBufferHeight);

                    if (gdi.PresentationParameters.DisplayOrientation == DisplayOrientation.Portrait)
                    {
                        gdi.PresentationParameters.BackBufferWidth  = min;
                        gdi.PresentationParameters.BackBufferHeight = max;
                    }
                    else
                    {
                        gdi.PresentationParameters.BackBufferWidth  = max;
                        gdi.PresentationParameters.BackBufferHeight = min;
                    }
                }
            }
            gdi.PresentationParameters.BackBufferFormat =
                PreferredBackBufferFormat;
            gdi.PresentationParameters.DepthStencilFormat =
                PreferredDepthStencilFormat;
            gdi.PresentationParameters.IsFullScreen =
                IsFullScreen;
            gdi.PresentationParameters.PresentationInterval =
                SynchronizeWithVerticalRetrace ?
                PresentInterval.One :
                PresentInterval.Immediate;
            if (!PreferMultiSampling)
            {
                gdi.PresentationParameters.MultiSampleCount = 0;
            }
            else if (gdi.PresentationParameters.MultiSampleCount == 0)
            {
                /* XNA4 seems to have an upper limit of 8, but I'm willing to
                 * limit this only in GraphicsDeviceManager's default setting.
                 * If you want even higher values, Reset() with a custom value.
                 * -flibit
                 */
                int maxMultiSampleCount = 0;
                if (graphicsDevice != null)
                {
                    maxMultiSampleCount = FNA3D.FNA3D_GetMaxMultiSampleCount(
                        graphicsDevice.GLDevice,
                        gdi.PresentationParameters.BackBufferFormat,
                        8
                        );
                }
                gdi.PresentationParameters.MultiSampleCount = Math.Min(
                    maxMultiSampleCount,
                    8
                    );
            }
            gdi.GraphicsProfile = GraphicsProfile;

            // Give the user a chance to override the above settings.
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );
        }
Example #22
0
        private void ValidateGraphicsDeviceInformation(GraphicsDeviceInformation devInfo)
        {
            SurfaceFormat          format;
            GraphicsAdapter        adapter                = devInfo.Adapter;
            DeviceType             deviceType             = devInfo.DeviceType;
            bool                   enableAutoDepthStencil = devInfo.PresentationParameters.EnableAutoDepthStencil;
            DepthFormat            autoDepthStencilFormat = devInfo.PresentationParameters.AutoDepthStencilFormat;
            SurfaceFormat          backBufferFormat       = devInfo.PresentationParameters.BackBufferFormat;
            int                    backBufferWidth        = devInfo.PresentationParameters.BackBufferWidth;
            int                    backBufferHeight       = devInfo.PresentationParameters.BackBufferHeight;
            PresentationParameters presentationParameters = devInfo.PresentationParameters;
            SurfaceFormat          format4                = presentationParameters.BackBufferFormat;

            if (!presentationParameters.IsFullScreen)
            {
                format = adapter.CurrentDisplayMode.Format;
                if (SurfaceFormat.Unknown == presentationParameters.BackBufferFormat)
                {
                    format4 = format;
                }
            }
            else
            {
                SurfaceFormat format5 = presentationParameters.BackBufferFormat;
                if (format5 != SurfaceFormat.Color)
                {
                    if (format5 != SurfaceFormat.Bgra5551)
                    {
                        format = presentationParameters.BackBufferFormat;
                    }
                    else
                    {
                        format = SurfaceFormat.Bgr555;
                    }
                }
                else
                {
                    format = SurfaceFormat.Bgr32;
                }
            }
            if (-1 == Array.IndexOf <SurfaceFormat>(ValidBackBufferFormats, format4))
            {
                throw new ArgumentException(Resources.ValidateBackBufferFormatIsInvalid);
            }
            if (
                !adapter.CheckDeviceType(deviceType, format, presentationParameters.BackBufferFormat,
                                         presentationParameters.IsFullScreen))
            {
                throw new ArgumentException(Resources.ValidateDeviceType);
            }
            if ((presentationParameters.BackBufferCount < 0) || (presentationParameters.BackBufferCount > 3))
            {
                throw new ArgumentException(Resources.ValidateBackBufferCount);
            }
            if ((presentationParameters.BackBufferCount > 1) && (presentationParameters.SwapEffect == SwapEffect.Copy))
            {
                throw new ArgumentException(Resources.ValidateBackBufferCountSwapCopy);
            }
            switch (presentationParameters.SwapEffect)
            {
            case SwapEffect.Default:
            case SwapEffect.Flip:
            case SwapEffect.Copy:
            {
                int num3;
                if (
                    !adapter.CheckDeviceMultiSampleType(deviceType, format4, presentationParameters.IsFullScreen,
                                                        presentationParameters.MultiSampleType, out num3))
                {
                    throw new ArgumentException(Resources.ValidateMultiSampleTypeInvalid);
                }
                if (presentationParameters.MultiSampleQuality >= num3)
                {
                    throw new ArgumentException(Resources.ValidateMultiSampleQualityInvalid);
                }
                if ((presentationParameters.MultiSampleType != MultiSampleType.None) &&
                    (presentationParameters.SwapEffect != SwapEffect.Default))
                {
                    throw new ArgumentException(Resources.ValidateMultiSampleSwapEffect);
                }
                if (((presentationParameters.PresentOptions & PresentOptions.DiscardDepthStencil) !=
                     PresentOptions.None) && !presentationParameters.EnableAutoDepthStencil)
                {
                    throw new ArgumentException(Resources.ValidateAutoDepthStencilMismatch);
                }
                if (presentationParameters.EnableAutoDepthStencil)
                {
                    if (
                        !adapter.CheckDeviceFormat(deviceType, format, ResourceUsage.None, QueryUsages.None,
                                                   ResourceType.DepthStencilBuffer,
                                                   presentationParameters.AutoDepthStencilFormat))
                    {
                        throw new ArgumentException(Resources.ValidateAutoDepthStencilFormatInvalid);
                    }
                    if (
                        !adapter.CheckDepthStencilMatch(deviceType, format, format4,
                                                        presentationParameters.AutoDepthStencilFormat))
                    {
                        throw new ArgumentException(Resources.ValidateAutoDepthStencilFormatIncompatible);
                    }
                }
                if (!presentationParameters.IsFullScreen)
                {
                    if (presentationParameters.FullScreenRefreshRateInHz != 0)
                    {
                        throw new ArgumentException(Resources.ValidateRefreshRateInWindow);
                    }
                    switch (presentationParameters.PresentationInterval)
                    {
                    case PresentInterval.Default:
                    case PresentInterval.One:
                    case PresentInterval.Immediate:
                        return;
                    }
                    throw new ArgumentException(Resources.ValidatePresentationIntervalInWindow);
                }
                if (presentationParameters.FullScreenRefreshRateInHz == 0)
                {
                    throw new ArgumentException(Resources.ValidateRefreshRateInFullScreen);
                }
                GraphicsDeviceCapabilities capabilities = adapter.GetCapabilities(deviceType);
                switch (presentationParameters.PresentationInterval)
                {
                case PresentInterval.Default:
                case PresentInterval.One:
                case PresentInterval.Immediate:
                    goto Label_02E5;

                case PresentInterval.Two:
                case PresentInterval.Three:
                case PresentInterval.Four:
                    if ((capabilities.PresentInterval & presentationParameters.PresentationInterval) ==
                        PresentInterval.Default)
                    {
                        throw new ArgumentException(
                                  Resources.ValidatePresentationIntervalIncompatibleInFullScreen);
                    }
                    goto Label_02E5;
                }
                break;
            }

            default:
                throw new ArgumentException(Resources.ValidateSwapEffectInvalid);
            }
            throw new ArgumentException(Resources.ValidatePresentationIntervalInFullScreen);
Label_02E5:
            if (presentationParameters.IsFullScreen)
            {
                if ((presentationParameters.BackBufferWidth == 0) || (presentationParameters.BackBufferHeight == 0))
                {
                    throw new ArgumentException(Resources.ValidateBackBufferDimsFullScreen);
                }
                bool        flag2 = true;
                bool        flag3 = false;
                DisplayMode currentDisplayMode = adapter.CurrentDisplayMode;
                if (((currentDisplayMode.Format != format) &&
                     (currentDisplayMode.Width != presentationParameters.BackBufferHeight)) &&
                    ((currentDisplayMode.Height != presentationParameters.BackBufferHeight) &&
                     (currentDisplayMode.RefreshRate != presentationParameters.FullScreenRefreshRateInHz)))
                {
                    flag2 = false;
                    foreach (DisplayMode mode2 in adapter.SupportedDisplayModes[format])
                    {
                        if ((mode2.Width == presentationParameters.BackBufferWidth) &&
                            (mode2.Height == presentationParameters.BackBufferHeight))
                        {
                            flag3 = true;
                            if (mode2.RefreshRate == presentationParameters.FullScreenRefreshRateInHz)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                    }
                }
                if (!flag2 && flag3)
                {
                    throw new ArgumentException(Resources.ValidateBackBufferDimsModeFullScreen);
                }
                if (!flag2)
                {
                    throw new ArgumentException(Resources.ValidateBackBufferHzModeFullScreen);
                }
            }
            if (presentationParameters.EnableAutoDepthStencil != enableAutoDepthStencil)
            {
                throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup);
            }
            if (presentationParameters.EnableAutoDepthStencil)
            {
                if (presentationParameters.AutoDepthStencilFormat != autoDepthStencilFormat)
                {
                    throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup);
                }
                if (presentationParameters.BackBufferFormat != backBufferFormat)
                {
                    throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup);
                }
                if (presentationParameters.BackBufferWidth != backBufferWidth)
                {
                    throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup);
                }
                if (presentationParameters.BackBufferHeight != backBufferHeight)
                {
                    throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup);
                }
            }
        }