Ejemplo n.º 1
0
        private string HandleDeviceReset()
        {
            bool needsReset = false;

            switch (GraphicsDevice.GraphicsDeviceStatus)
            {
            case GraphicsDeviceStatus.Lost:
                return("Graphics device lost");

            case GraphicsDeviceStatus.NotReset:
                needsReset = true;
                break;

            default:
                PresentationParameters pp = GraphicsDevice.PresentationParameters;
                needsReset = (ClientSize.Width > pp.BackBufferWidth) || (ClientSize.Height > pp.BackBufferHeight);
                break;
            }

            if (needsReset)
            {
                try {
                    _deviceService.ResetDevice(ClientSize.Width, ClientSize.Height);
                }
                catch (Exception e) {
                    return("Graphics device reset failed\n\n" + e);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private bool HandleDeviceReset()
        {
            bool deviceNeedsReset = false;

            switch (_graphicsDeviceService.GraphicsDevice.GraphicsDeviceStatus)
            {
            case GraphicsDeviceStatus.Lost:
                // If the graphics device is lost, we cannot use it at all.
                return(false);

            case GraphicsDeviceStatus.NotReset:
                // If device is in the not-reset state, we should try to reset it.
                deviceNeedsReset = true;
                break;
            }

            if (deviceNeedsReset)
            {
                Debug.WriteLine("Resetting Device");
                _graphicsDeviceService.ResetDevice((int)ActualWidth, (int)ActualHeight);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        bool HandleDeviceReset()
        {
            bool deviceNeedsReset = false;

            switch (GraphicsDeviceService.GraphicsDevice.GraphicsDeviceStatus)
            {
            case GraphicsDeviceStatus.Lost:
                // If the graphics device is lost, we cannot use it at all.
                return(false);

            case GraphicsDeviceStatus.NotReset:
                // If device is in the not-reset state, we should try to reset it.
                deviceNeedsReset = true;
                break;

            default:
                // If the device state is ok, check whether it is big enough.
                PresentationParameters pp = GraphicsDeviceService.GraphicsDevice.PresentationParameters;
                deviceNeedsReset = ((int)ActualWidth > pp.BackBufferWidth) || ((int)ActualHeight > pp.BackBufferHeight);
                break;
            }

            if (deviceNeedsReset)
            {
                Debug.WriteLine("Resetting Device");
                GraphicsDeviceService.ResetDevice((int)ActualWidth, (int)ActualHeight);
                deviceNeedsReset = false;
                return(false);
            }

            return(true);
        }
 private void XnaWindowHost_SizeChanged(object sender, SizeChangedEventArgs e)
 {
     // If we have a reference to the GraphicsDeviceService, we must reset it based on our updated size
     if (graphicsService != null)
     {
         graphicsService.ResetDevice((int)ActualWidth, (int)ActualHeight);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Helper used by <see cref="OnCompositionTargetRendering"/>.
        /// This checks the graphics device status,
        /// making sure it is big enough for drawing the current control, and
        /// that the device is not lost. Returns an error string if the device
        /// could not be reset.
        /// </summary>
        private GraphicsDeviceResetStatus HandleDeviceReset(int width, int height)
        {
            bool deviceNeedsReset;

            switch (_graphicsService.GraphicsDevice.GraphicsDeviceStatus)
            {
            case GraphicsDeviceStatus.Lost:
                // If the graphics device is lost, we cannot use it at all.
                return(GraphicsDeviceResetStatus.Lost);

            case GraphicsDeviceStatus.NotReset:
                // If device is in the not-reset state, we should try to reset it.
                deviceNeedsReset = true;
                break;

            default:
                // If the device state is ok, check whether it is big enough.
                PresentationParameters pp = _graphicsService.GraphicsDevice.PresentationParameters;

                deviceNeedsReset = (width > pp.BackBufferWidth) ||
                                   (height > pp.BackBufferHeight);
                break;
            }

            // Do we need to reset the device?
            if (deviceNeedsReset)
            {
                try
                {
                    _graphicsService.ResetDevice(width, height);
                }
                catch
                {
                    return(GraphicsDeviceResetStatus.ResetFailed);
                }
            }

            return(GraphicsDeviceResetStatus.Normal);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Helper used by BeginDraw. This checks the graphics device status,
        /// making sure it is big enough for drawing the current control, and
        /// that the device is not lost. Returns an error string if the device
        /// could not be reset.
        /// </summary>
        string HandleDeviceReset()
        {
            bool deviceNeedsReset = false;

            switch (GraphicsDevice.GraphicsDeviceStatus)
            {
            case GraphicsDeviceStatus.Lost:
                // If the graphics device is lost, we cannot use it at all.
                return("Graphics device lost");

            case GraphicsDeviceStatus.NotReset:
                // If device is in the not-reset state, we should try to reset it.
                deviceNeedsReset = true;
                break;

            default:
                // If the device state is ok, check whether it is big enough.
                PresentationParameters pp = GraphicsDevice.PresentationParameters;

                deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) ||
                                   (ClientSize.Height > pp.BackBufferHeight);
                break;
            }

            // Do we need to reset the device?
            if (deviceNeedsReset)
            {
                try
                {
                    graphicsDeviceService.ResetDevice(ClientSize.Width,
                                                      ClientSize.Height);
                }
                catch (Exception e)
                {
                    return("Graphics device reset failed\n\n" + e);
                }
            }

            return(null);
        }