/// <inheritdoc/>
        bool IPresentationTarget.BeginRender(RenderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var graphicsDevice = GraphicsService.GraphicsDevice;

            if (_renderTarget == null ||
                _renderTarget.GraphicsDevice != graphicsDevice ||
                _requiresResize)
            {
                if (_renderTarget == null)
                {
                    _renderTarget = new SwapChainRenderTarget(
                        graphicsDevice,
                        this,
                        _width,
                        _height,
                        _compositionScaleX,
                        _compositionScaleY,
                        false,
                        SurfaceFormat.Color,
                        DepthFormat.Depth24Stencil8,
                        0,
                        RenderTargetUsage.PreserveContents,
                        PresentInterval.Default);
                }
                else
                {
                    _renderTarget.Resize(_width, _height, _compositionScaleX, _compositionScaleY);
                }

                _requiresResize = false;
            }

            graphicsDevice.SetRenderTarget(_renderTarget);
            context.RenderTarget = _renderTarget;
            context.Viewport     = new Viewport(0, 0, _renderTarget.Width, _renderTarget.Height);
            _rendering           = true;
            return(true);
        }
Beispiel #2
0
    /// <inheritdoc/>
    bool IPresentationTarget.BeginRender(RenderContext context)
    {
      if (context == null)
        throw new ArgumentNullException("context");

      var graphicsDevice = GraphicsService.GraphicsDevice;
      int width = ClientSize.Width;
      int height = ClientSize.Height;


      if (_renderTarget == null
          || _renderTarget.GraphicsDevice != graphicsDevice
          || _renderTarget.Width != width
          || _renderTarget.Height != height)
      {
        if (_renderTarget == null)
          _renderTarget = new SwapChainRenderTarget(graphicsDevice, Handle, width, height);
        else
          _renderTarget.Resize(width, height);
      }

      graphicsDevice.SetRenderTarget(_renderTarget);
      context.RenderTarget = _renderTarget;
#else
      bool deviceNeedsReset;
      switch (graphicsDevice.GraphicsDeviceStatus)
      {
        case GraphicsDeviceStatus.Lost:
          return false;

        case GraphicsDeviceStatus.NotReset:
          deviceNeedsReset = true;
          break;

        default:
          var presentationParameters = graphicsDevice.PresentationParameters;
          deviceNeedsReset = (width > presentationParameters.BackBufferWidth)
                             || (height > presentationParameters.BackBufferHeight);
          break;
      }

      if (deviceNeedsReset)
      {
        try
        {
          var presentationParameters = graphicsDevice.PresentationParameters;
          presentationParameters.BackBufferWidth = Math.Max(width, presentationParameters.BackBufferWidth);
          presentationParameters.BackBufferHeight = Math.Max(height, presentationParameters.BackBufferHeight);
          graphicsDevice.Reset(presentationParameters);
        }
        catch (Exception)
        {
          return false;
        }
      }


      context.Viewport = new Viewport(0, 0, width, height);
      _rendering = true;
      return true;
    }