private void OnRender(object sender, EventArgs e)
 {
     _gameTime.ElapsedGameTime = _stopwatch.Elapsed;
     _gameTime.TotalGameTime  += _gameTime.ElapsedGameTime;
     _stopwatch.Restart();
     if (CanBeginDraw())
     {
         try {
             _direct3DImage.Lock();
             if (_renderTarget == null)
             {
                 _renderTarget = CreateRenderTarget();
             }
             if (_renderTarget != null)
             {
                 GraphicsDevice.SetRenderTarget(_renderTarget);
                 SetViewport();
                 _viewModel?.Update(_gameTime);
                 _viewModel?.Draw(_gameTime);
                 GraphicsDevice.Flush();
                 _direct3DImage.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
             }
         } finally {
             _direct3DImage.Unlock();
             GraphicsDevice.SetRenderTarget(null);
         }
     }
 }
Esempio n. 2
0
        private void OnRender(object sender, EventArgs e)
        {
            // SHITPOINT
            //System.Windows.Point point = Mouse.GetPosition(this);
            //MapEditor.LastMousePosition = MapEditor.MousePosition;
            //MapEditor.MousePosition = new Vector2((float)point.X, (float)point.Y);
            _gameTime.ElapsedGameTime = _stopwatch.Elapsed;
            _gameTime.TotalGameTime  += _gameTime.ElapsedGameTime;
            _stopwatch.Restart();

            if (CanBeginDraw())
            {
                try
                {
                    _direct3DImage.Lock();

                    if (_renderTarget == null)
                    {
                        _renderTarget = CreateRenderTarget();
                    }

                    if (_renderTarget != null)
                    {
                        GraphicsDevice.SetRenderTarget(_renderTarget);
                        SetViewport();

                        ViewModel?.Update(_gameTime);
                        ViewModel?.Draw(_gameTime);

                        GraphicsDevice.Flush();
                        _direct3DImage.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
                    }
                }
                finally
                {
                    _direct3DImage.Unlock();
                    GraphicsDevice.SetRenderTarget(null);
                }
            }
        }