Exemplo n.º 1
0
 private void Update(GraphicsScreen screen, TimeSpan deltaTime)
 {
   // If your graphics screen has any objects that need to be updated before 
   // rendering, you can do this here. This method is called once per frame if 
   // the graphics screen is visible.
 }
Exemplo n.º 2
0
        private void OnLoaded(object sender, RoutedEventArgs eventArgs)
        {
            if (GraphicsService == null)
                return;

            _textureGraphicsScreen = new TextureGraphicsScreen(GraphicsService);
            GraphicsScreens = new GraphicsScreen[] { _textureGraphicsScreen };
            UpdateGraphicsScreen();
        }
Exemplo n.º 3
0
        protected override void OnActivated(ActivationEventArgs eventArgs)
        {
            if (eventArgs.Opened)
            {
                // Initialize graphics screens.
                var graphicsService = _editor.Services.GetInstance<IGraphicsService>().ThrowIfMissing();
                GraphicsScreens = new GraphicsScreen[]
                {
                    new TriangleGraphicsScreen(graphicsService),
                    new DebugGraphicsScreen(_editor.Services) { ShowTitleSafeArea = true }
                };
            }

            base.OnActivated(eventArgs);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Renders all visible <see cref="GraphicsScreen" />s.
        /// </summary>
        /// <param name="screens">The graphics screens.</param>
        private void RenderScreens(IList <GraphicsScreen> screens)
        {
            if (GraphicsDevice == null || GraphicsDevice.IsDisposed)
            {
                return;
            }

            // Create temporary list because original collection may be modified during update.
            try
            {
                CopyScreens(screens, _tempScreens);

                // ----- Render screens from back to front.
                var            finalViewport     = _context.Viewport;
                var            finalRenderTarget = _context.RenderTarget;
                GraphicsScreen screenThatRequiresSourceTexture = null; // The next screen that needs the previous screens as source.
                int            numberOfScreens = _tempScreens.Count;
                for (int i = GetIndexOfFirstVisibleScreen(_tempScreens); i < numberOfScreens; i++)
                {
                    var screen = _tempScreens[i];

                    if (screen == screenThatRequiresSourceTexture)
                    {
                        Debug.Assert(_context.RenderTarget != null, "Previous graphics screens should have been rendered into an off-screen render target.");
                        Debug.Assert(_context.SourceTexture == null, "The RenderContext.SourceTexture should have been recycled.");

                        _context.SourceTexture          = _context.RenderTarget;
                        _context.RenderTarget           = finalRenderTarget;
                        screenThatRequiresSourceTexture = null;
                    }

                    if (screenThatRequiresSourceTexture == null)
                    {
                        // Check if one of the next screens needs the current output in an off-screen render target.
                        for (int j = i + 1; j < numberOfScreens; j++)
                        {
                            var topScreen = _tempScreens[j];
                            if (topScreen.IsVisible && topScreen.RenderPreviousScreensToTexture)
                            {
                                screenThatRequiresSourceTexture = topScreen;
                                var format = topScreen.SourceTextureFormat;

                                // If not specified, choose default values for width and height.
                                if (!format.Width.HasValue)
                                {
                                    format.Width = finalViewport.Width;
                                }
                                if (!format.Height.HasValue)
                                {
                                    format.Height = finalViewport.Height;
                                }

                                _context.RenderTarget = RenderTargetPool.Obtain2D(format);
                                break;
                            }
                        }
                    }

                    GraphicsDevice.SetRenderTarget(_context.RenderTarget);

                    // For the back buffer we use the special viewport. Off-screen render targets
                    // always use the full size.
                    if (_context.RenderTarget == finalRenderTarget)
                    {
                        GraphicsDevice.Viewport = finalViewport;
                    }

                    // Make sure the viewport in the render context is up-to-date.
                    // (Note: SetRenderTarget() always resets GraphicsDevice.Viewport.)
                    _context.Viewport = GraphicsDevice.Viewport;

                    screen.Render(_context);

                    if (_context.SourceTexture != null)
                    {
                        RenderTargetPool.Recycle(_context.SourceTexture as RenderTarget2D);
                        _context.SourceTexture = null;
                    }
                }

                Debug.Assert(_context.SourceTexture == null, "The RenderContext.SourceTexture should have been recycled.");
                Debug.Assert(_context.RenderTarget == finalRenderTarget, "The last graphics screen must render into the back buffer.");
            }
            finally
            {
                // If GraphicsScreen.Render() throws, let's at least clear _tempScreens, so we can try again
                // in the next frame.
                _tempScreens.Clear();
            }
        }