Example #1
0
        public GraphicsDeviceManager(Game game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("The game cannot be null!");
            }

            this.game = game;

            INTERNAL_supportedOrientations = DisplayOrientation.Default;

            INTERNAL_preferredBackBufferHeight = DefaultBackBufferHeight;
            INTERNAL_preferredBackBufferWidth  = DefaultBackBufferWidth;

            INTERNAL_preferredBackBufferFormat   = SurfaceFormat.Color;
            INTERNAL_preferredDepthStencilFormat = DepthFormat.Depth24;

            INTERNAL_synchronizeWithVerticalRetrace = true;

            INTERNAL_preferMultiSampling = false;

            if (game.Services.GetService(typeof(IGraphicsDeviceManager)) != null)
            {
                throw new ArgumentException("Graphics Device Manager Already Present");
            }

            game.Services.AddService(typeof(IGraphicsDeviceManager), this);
            game.Services.AddService(typeof(IGraphicsDeviceService), this);

            prefsChanged                   = true;
            useResizedBackBuffer           = false;
            supportsOrientations           = FNAPlatform.SupportsOrientationChanges();
            game.Window.ClientSizeChanged += INTERNAL_OnClientSizeChanged;
        }
Example #2
0
        internal GraphicsDeviceManager(Game game)
        {
            if (game == null)
            {
                throw new ArgumentNullException("The game cannot be null!");
            }

            if (Instance != null)
            {
                throw new InvalidOperationException("GraphicsDeviceManager already created!");
            }

            this.game = game;

            INTERNAL_supportedOrientations = DisplayOrientation.Default;

            INTERNAL_preferredBackBufferHeight = DefaultBackBufferHeight;
            INTERNAL_preferredBackBufferWidth  = DefaultBackBufferWidth;

            INTERNAL_preferredBackBufferFormat   = SurfaceFormat.Color;
            INTERNAL_preferredDepthStencilFormat = DepthFormat.Depth24;

            INTERNAL_synchronizeWithVerticalRetrace = true;

            INTERNAL_preferMultiSampling = false;

            prefsChanged                   = true;
            useResizedBackBuffer           = false;
            supportsOrientations           = FNAPlatform.SupportsOrientationChanges();
            game.Window.ClientSizeChanged += INTERNAL_OnClientSizeChanged;
        }
Example #3
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;
        }