Beispiel #1
0
        public void InitializeEventCount()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var resettingCount = 0;
            var resetCount     = 0;
            var preparingCount = 0;
            var createdCount   = 0;
            var devDispCount   = 0;
            var dispCount      = 0;

            gdm.DeviceResetting         += (s, a) => resettingCount++;
            gdm.DeviceReset             += (s, a) => resetCount++;
            gdm.PreparingDeviceSettings += (s, a) => preparingCount++;
            gdm.DeviceCreated           += (s, a) => createdCount++;
            gdm.DeviceDisposing         += (s, a) => devDispCount++;
            // TODO remove MonoMac
#if !MONOMAC
            gdm.Disposed += (s, a) => dispCount++;
#endif

            game.InitializeOnly();

            Assert.AreEqual(0, resettingCount);
            Assert.AreEqual(0, resetCount);
            Assert.AreEqual(1, preparingCount);
            Assert.AreEqual(1, createdCount);
            Assert.AreEqual(0, devDispCount);
            Assert.AreEqual(0, dispCount);

            game.Dispose();
        }
Beispiel #2
0
        public void ApplyChangesReturnsWhenNoSetterCalled()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.PreInitializeWith += (sender, args) =>
            {
                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    invoked = true;
                };
            };

            game.InitializeOnly();

            gdm.ApplyChanges();
            Assert.IsFalse(invoked);

            // this proves that XNA does not check for equality, but just registers that setters are used
            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;

            gdm.ApplyChanges();
            Assert.That(invoked);

            game.Dispose();
        }
Beispiel #3
0
        public void PreparingDeviceSettingsArgsPresentationParametersAreApplied()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.PreInitializeWith += (sender, args) =>
            {
                Assert.AreEqual(RenderTargetUsage.DiscardContents,
                                gdm.GraphicsDevice.PresentationParameters.RenderTargetUsage);

                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    a.GraphicsDeviceInformation.GraphicsProfile = GraphicsProfile.HiDef;
                    a.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
                    invoked = true;
                };
            };

            game.InitializeOnly();

            // make a change so ApplyChanges actually does something
            gdm.PreferredBackBufferWidth = 100;
            gdm.ApplyChanges();

            Assert.That(invoked);
            Assert.AreEqual(RenderTargetUsage.PreserveContents, gdm.GraphicsDevice.PresentationParameters.RenderTargetUsage);

            game.Dispose();
        }
Beispiel #4
0
        public void ApplyChangesResetsDevice()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var count = 0;

            gdm.DeviceReset += (sender, args) => count++;

            game.InitializeOnly();

            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;
            gdm.ApplyChanges();
            Assert.AreEqual(1, count);

            game.Dispose();
        }
Beispiel #5
0
        public void PreparingDeviceSettingsArgsThrowsWhenPPSetToNull()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            gdm.PreparingDeviceSettings += (s, a) =>
            {
                a.GraphicsDeviceInformation.PresentationParameters = null;
                invoked = true;
            };

            Assert.Throws(Is.InstanceOf(typeof(Exception)), () => game.InitializeOnly());
            Assert.That(invoked);

            game.Dispose();
        }
Beispiel #6
0
        public void DoNotModifyPresentationParametersDirectly()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            game.InitializeWith += (sender, args) =>
            {
                var gd = game.GraphicsDevice;

                var oldpp = gd.PresentationParameters;
                gdm.PreferredBackBufferWidth = 100;
                gdm.ApplyChanges();
                var newpp = gd.PresentationParameters;
                Assert.AreNotSame(oldpp, newpp);
            };

            game.InitializeOnly();
            game.Dispose();
        }
Beispiel #7
0
        public void PreparingDeviceSettingsEventChangeGraphicsProfile()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            Assert.AreEqual(GraphicsProfile.Reach, gdm.GraphicsProfile);

            game.InitializeOnly();

            var invoked = false;

            gdm.PreparingDeviceSettings += (s, a) =>
            {
                a.GraphicsDeviceInformation.GraphicsProfile = GraphicsProfile.HiDef;
                invoked = true;
            };

            // make sure that changing the graphics profile creates a new device and does not reset
            var creationCount = 0;

            gdm.DeviceCreated += (sender, args) => creationCount++;
            var resetCount = 0;

            gdm.DeviceReset += (sender, args) => resetCount++;

            // make a change so ApplyChanges actually does something
            gdm.PreferredBackBufferWidth = 100;
            gdm.ApplyChanges();

            // assert that PreparingDeviceSettings is invoked, but the GraphicsProfile of the gdm did not change
            Assert.That(invoked);
            Assert.AreEqual(GraphicsProfile.Reach, gdm.GraphicsProfile);
            Assert.AreEqual(GraphicsProfile.HiDef, gdm.GraphicsDevice.GraphicsProfile);

            Assert.AreEqual(creationCount, 1);
            Assert.AreEqual(resetCount, 0);

            game.Dispose();
        }
Beispiel #8
0
        public void ApplyChangesInvokesPreparingDeviceSettings()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.InitializeWith += (sender, args) =>
            {
                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    invoked = true;
                };
            };

            game.InitializeOnly();

            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;
            gdm.ApplyChanges();
            Assert.That(invoked);

            game.Dispose();
        }
Beispiel #9
0
        public void PreparingDeviceSettings()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var count = 0;

            gdm.PreparingDeviceSettings += (sender, args) =>
            {
                Assert.NotNull(args.GraphicsDeviceInformation);

                Assert.NotNull(args.GraphicsDeviceInformation.Adapter);
                Assert.AreEqual(GraphicsProfile.Reach, args.GraphicsDeviceInformation.GraphicsProfile);

                var pp = args.GraphicsDeviceInformation.PresentationParameters;
                Assert.NotNull(pp);

                Assert.AreEqual(800, pp.BackBufferWidth);
                Assert.AreEqual(480, pp.BackBufferHeight);
                Assert.AreEqual(SurfaceFormat.Color, pp.BackBufferFormat);
                Assert.AreEqual(DepthFormat.Depth24, pp.DepthStencilFormat);
                Assert.False(pp.IsFullScreen);
                Assert.AreEqual(PresentInterval.One, pp.PresentationInterval);
                Assert.AreEqual(new Rectangle(0, 0, 800, 480), pp.Bounds);
                Assert.AreNotEqual(IntPtr.Zero, pp.DeviceWindowHandle);
                Assert.AreEqual(DisplayOrientation.Default, pp.DisplayOrientation);
                Assert.AreEqual(RenderTargetUsage.DiscardContents, pp.RenderTargetUsage);
                Assert.AreEqual(0, pp.MultiSampleCount);

                count++;
            };

            game.InitializeOnly();
            Assert.AreEqual(1, count);
            game.Dispose();
        }
Beispiel #10
0
        public void DeviceDisposingInvokedAfterDeviceDisposed()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            gdm.DeviceDisposing += (sender, args) =>
            {
                invoked = true;
                Assert.IsTrue(gdm.GraphicsDevice.IsDisposed);
            };

            game.InitializeOnly();

            Assert.IsFalse(gdm.GraphicsDevice.IsDisposed);
            Assert.IsFalse(invoked);
            // change the graphics profile so the current device needs to be disposed
            gdm.GraphicsProfile = GraphicsProfile.HiDef;
            gdm.ApplyChanges();
            Assert.IsTrue(invoked);

            game.Dispose();
        }