Engines/FlatRedBallXNA/FlatRedBall/Graphics/GraphicsOptions.cs
/// <summary>
/// Resets the device if the device is not currently rendering, if the graphics device is not null, and if 
/// device resetting is not suspended.
/// </summary>
Resets the device if the device is not currently rendering, if the graphics device is not null, and if
device resetting is not suspended.
Resets the device if the device is not currently rendering if the graphics device is not null and if device resetting is not suspended .
public void ResetDevice()
        {
            if (mIsInAReset)
            {
                return;
            }
            #region If the Renderer.Graphics is null that means the engine is not loaded yet
            if (!mSuspendDeviceReset && Renderer.Graphics == null)
            {
                throw new InvalidOperationException("Can't reset the device right now because the Renderer's Graphics are null. " +
                    "Are you attempting to change the GraphicsOption's properties prior to the creation of FlatRedBallServices? " +
                    "If so you must call SuspendDeviceReset before changing properties, then ResumeDeviceReset after the properties " +
                    "are set, but before calling FlatRedBallServices.InitializeFlatRedBall.  Otherwise, move the property-changing " +
                    "code to after FlatRedBall is initialized.");
            }
            #endregion
            #region Else, check to make sure device resetting is not suspended and the GraphicsOptions are not loading
            else if (!mSuspendDeviceReset && !GraphicsOptions.IsLoading)
            {
                mIsInAReset = true;
                if (FlatRedBallServices.mGraphics != null)
                {
                    if(windowedFullscreenMode == WindowedFullscreenMode.Fullscreen)
                    {
                        ThrowExceptionIfFullScreenResolutionNotSupported(mResolutionWidth, mResolutionHeight);
                    }
                    FlatRedBallServices.mGraphics.PreferredBackBufferWidth = mResolutionWidth;
                    FlatRedBallServices.mGraphics.PreferredBackBufferHeight = mResolutionHeight;
                    FlatRedBallServices.mGraphics.PreferMultiSampling = mUseMultiSampling;
                    FlatRedBallServices.mGraphics.IsFullScreen = windowedFullscreenMode == WindowedFullscreenMode.Fullscreen;
#if DESKTOP_GL
                    http:
                    FlatRedBallServices.mGraphics.IsFullScreen = 
                        windowedFullscreenMode == WindowedFullscreenMode.Fullscreen || 
                        windowedFullscreenMode == WindowedFullscreenMode.FullscreenBorderless
                        ;
#else
                    FlatRedBallServices.mGraphics.IsFullScreen = windowedFullscreenMode == WindowedFullscreenMode.Fullscreen;
#endif
                    try
                    {
                        FlatRedBallServices.mGraphics.ApplyChanges();
                    }
                    finally
                    {
                        mIsInAReset = false;
                    }
                }
                PresentationParameters presParams = FlatRedBallServices.GraphicsDevice.PresentationParameters;
                SetPresentationParameters(ref presParams);
                if (FlatRedBallServices.mGraphics != null)
                {
    #if !MONODROID
                    while (FlatRedBallServices.mGraphics.GraphicsDevice.GraphicsDeviceStatus == GraphicsDeviceStatus.Lost ||
                        FlatRedBallServices.mGraphics.GraphicsDevice.GraphicsDeviceStatus == GraphicsDeviceStatus.NotReset)
                    {
                        int m = 3;
                        m += 32;
                        m /= 32;
                    }
    #endif
                }
    #if MONOGAME
                FlatRedBallServices.graphics_DeviceReset(null, null);
    #else
                FlatRedBallServices.GraphicsDevice.Reset(presParams);
    #endif
                Renderer.ForceSetBlendOperation();
                mIsInAReset = false;
            }
            #endregion
        }
public void ResetDevice ( ) { if ( mIsInAReset ) { return ; } region  If the Renderer.Graphics is null that means the engine is not loaded yet if ( ! mSuspendDeviceReset && Renderer . Graphics == null ) { throw new InvalidOperationException ( " " + " " + " " + " " + " " ) ; } endregion region  Else, check to make sure device resetting is not suspended and the GraphicsOptions are not loading else if ( ! mSuspendDeviceReset && ! GraphicsOptions . IsLoading ) { mIsInAReset = true ; if ( FlatRedBallServices . mGraphics != null ) { if ( windowedFullscreenMode == WindowedFullscreenMode . Fullscreen ) { ThrowExceptionIfFullScreenResolutionNotSupported ( mResolutionWidth , mResolutionHeight ) ; } FlatRedBallServices . mGraphics . PreferredBackBufferWidth = mResolutionWidth ; FlatRedBallServices . mGraphics . PreferredBackBufferHeight = mResolutionHeight ; FlatRedBallServices . mGraphics . PreferMultiSampling = mUseMultiSampling ; FlatRedBallServices . mGraphics . IsFullScreen = windowedFullscreenMode == WindowedFullscreenMode . Fullscreen ; if DESKTOP_GL http : FlatRedBallServices . mGraphics . IsFullScreen = windowedFullscreenMode == WindowedFullscreenMode . Fullscreen || windowedFullscreenMode == WindowedFullscreenMode . FullscreenBorderless ; else FlatRedBallServices . mGraphics . IsFullScreen = windowedFullscreenMode == WindowedFullscreenMode . Fullscreen ; endif try { FlatRedBallServices . mGraphics . ApplyChanges ( ) ; } finally { mIsInAReset = false ; } } PresentationParameters presParams = FlatRedBallServices . GraphicsDevice . PresentationParameters ; SetPresentationParameters ( ref presParams ) ; if ( FlatRedBallServices . mGraphics != null ) { if ! MONODROID while ( FlatRedBallServices . mGraphics . GraphicsDevice . GraphicsDeviceStatus == GraphicsDeviceStatus . Lost || FlatRedBallServices . mGraphics . GraphicsDevice . GraphicsDeviceStatus == GraphicsDeviceStatus . NotReset ) { int m = 3 ; m += 32 ; m /= 32 ; } endif } if MONOGAME FlatRedBallServices . graphics_DeviceReset ( null , null ) ; else FlatRedBallServices . GraphicsDevice . Reset ( presParams ) ; endif Renderer . ForceSetBlendOperation ( ) ; mIsInAReset = false ; } endregion }
Resets the device if the device is not currently rendering, if the graphics device is not null, and if
device resetting is not suspended.
Resets the device if the device is not currently rendering if the graphics device is not null and if device resetting is not suspended .
// Reset the graphics device manager // Set window size // for borderless the user must set the GraphicsDeviceManager.HardwareModeSwitch to false //community.monogame.net/t/how-to-implement-borderless-fullscreen-on-desktopgl-project/8359 // No longer needed since we are always going to use a sample quality of 0 //catch (Exception e) //{ //    int qualityLevels = 0; //    bool allowed = GraphicsAdapter.DefaultAdapter.CheckDeviceMultiSampleType(DeviceType.Hardware, //        SurfaceFormat.Color, false, mMultiSampleType, out qualityLevels); //    throw e; //} // Prepare the presentation parameters // Sets the presentation parameters // Reset the device // Resetting crashes monogame currently, but we can still react as if a reset happened // When the device resets the render states could get screwed up.  Force the  // blend state changes in case they were changed but nothing later changes them // back. // Hm, this seems to cause a crash because the mCurrentEffect isn't set yet //Renderer.ForceSetColorOperation(Renderer.ColorOperation);