Пример #1
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                // FIXME: MonoGame cannot read backbuffer
                //if (Screen != null)
                //    graphicsDevice.ResolveBackBuffer(Screen);
                PopupWindowMaterial.SetState(graphicsDevice, Screen);
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);
                SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, null, null, null, null);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
Пример #2
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                var oldTargets = graphicsDevice.GetRenderTargets();
                if (Viewer.Settings.WindowGlass)
                {
                    graphicsDevice.SetRenderTarget(Screen);
                    graphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer | ClearOptions.Stencil, Color.Transparent, 1, 0);
                    PopupWindowMaterial.SetState(graphicsDevice, oldTargets[0].RenderTarget as RenderTarget2D);
                }
                else
                {
                    PopupWindowMaterial.SetState(graphicsDevice, null);
                }
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);
                SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
                if (Viewer.Settings.WindowGlass)
                {
                    graphicsDevice.SetRenderTargets(oldTargets);
                    SpriteBatchMaterial.SetState(graphicsDevice, null);
                    SpriteBatchMaterial.SpriteBatch.Draw(Screen, Vector2.Zero, Color.White);
                    SpriteBatchMaterial.ResetState(graphicsDevice);
                }
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
Пример #3
0
        public override void Draw(GraphicsDevice graphicsDevice)
        {
            // Nothing visible? Nothing more to do!
            if (!VisibleWindows.Any())
            {
                return;
            }

            // Construct a view where (0, 0) is the top-left and (width, height) is
            // bottom-right, so that popups can act more like normal window things.
            XNAView = Matrix.CreateTranslation(-ScreenSize.X / 2, -ScreenSize.Y / 2, 0) *
                      Matrix.CreateTranslation(-0.5f, -0.5f, 0) *
                      Matrix.CreateScale(1, -1, 1);
            // Project into a flat view of the same size as the viewport.
            XNAProjection = Matrix.CreateOrthographic(ScreenSize.X, ScreenSize.Y, 0, 100);

            var rs = graphicsDevice.RenderState;

            foreach (var window in VisibleWindows)
            {
                var xnaWorld = window.XNAWorld;

                if (Screen != null)
                {
                    graphicsDevice.ResolveBackBuffer(Screen);
                }
                PopupWindowMaterial.SetState(graphicsDevice, Screen);
                PopupWindowMaterial.Render(graphicsDevice, window, ref xnaWorld, ref XNAView, ref XNAProjection);
                PopupWindowMaterial.ResetState(graphicsDevice);

                SpriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
                window.Draw(SpriteBatch);
                SpriteBatch.End();
            }
            // For performance, we call SpriteBatch.Begin() with SaveStateMode.None above, but we now need to restore
            // the state ourselves.
            rs.AlphaBlendEnable  = false;
            rs.AlphaFunction     = CompareFunction.Always;
            rs.AlphaTestEnable   = false;
            rs.DepthBufferEnable = true;
            rs.DestinationBlend  = Blend.Zero;
            rs.SourceBlend       = Blend.One;
        }