Пример #1
0
        public bool Render(IPresentationTarget presentationTarget, IList <GraphicsScreen> screens)
        {
            ThrowIfDisposed();

            if (presentationTarget == null)
            {
                throw new ArgumentNullException("presentationTarget");
            }
            if (screens == null)
            {
                throw new ArgumentNullException("screens");
            }
            if (_context == null)
            {
                throw new GraphicsException("GraphicsManager.Update(TimeSpan) has not been called. The graphics service needs to be updated before content can be rendered.");
            }

            if (GraphicsDevice.PresentationParameters.IsFullScreen ||
                !presentationTarget.IsVisible ||
                presentationTarget.Width <= 0 ||
                presentationTarget.Height <= 0)
            {
                return(false);
            }

            _context.PresentationTarget = presentationTarget;

            Viewport originalViewport = GraphicsDevice.Viewport;

            try
            {
                if (presentationTarget.BeginRender(_context))
                {
                    RenderScreens(screens);
                }
            }
            finally
            {
                presentationTarget.EndRender(_context);

                GraphicsDevice.Viewport     = originalViewport;
                _context.Viewport           = originalViewport;
                _context.PresentationTarget = null;
            }

            return(true);
        }
Пример #2
0
        public bool Present(IPresentationTarget presentationTarget)
        {
            ThrowIfDisposed();

            if (presentationTarget == null)
            {
                throw new ArgumentNullException("presentationTarget");
            }

            // Similar to Render(IPresentationTarget) but without RenderScreens().
            if (GraphicsDevice.PresentationParameters.IsFullScreen ||
                !presentationTarget.IsVisible ||
                presentationTarget.Width <= 0 ||
                presentationTarget.Height <= 0 ||
                presentationTarget.Handle == IntPtr.Zero)
            {
                return(false);
            }

            var       presentationParameters = GraphicsDevice.PresentationParameters;
            int       width           = Math.Min(presentationTarget.Width, presentationParameters.BackBufferWidth);
            int       height          = Math.Min(presentationTarget.Height, presentationParameters.BackBufferHeight);
            Rectangle sourceRectangle = new Rectangle(0, 0, width, height);

            try
            {
#if !MONOGAME
                GraphicsDevice.Present(sourceRectangle, null, presentationTarget.Handle);
                return(true);
#else
                throw new NotImplementedException("MonoGame builds support only D3DImagePresentationTargets.");
#endif
            }
            // ReSharper disable EmptyGeneralCatchClause
            catch
            {
                // Do nothing. This happens when the layout of the window changes during rendering.
                // For example, when the user docks windows an OutOfVideoMemoryException might occur.
            }
            // ReSharper restore EmptyGeneralCatchClause

            return(false);
        }
Пример #3
0
 public bool Render(IPresentationTarget presentationTarget)
 {
   return Render(presentationTarget, Screens);
 }
Пример #4
0
    public bool Present(IPresentationTarget presentationTarget)
    {
      ThrowIfDisposed();

      if (presentationTarget == null)
        throw new ArgumentNullException("presentationTarget");

      // Similar to Render(IPresentationTarget) but without RenderScreens().
      if (GraphicsDevice.PresentationParameters.IsFullScreen
          || !presentationTarget.IsVisible
          || presentationTarget.Width <= 0
          || presentationTarget.Height <= 0
          || presentationTarget.Handle == IntPtr.Zero)
      {
        return false;
      }

      var presentationParameters = GraphicsDevice.PresentationParameters;
      int width = Math.Min(presentationTarget.Width, presentationParameters.BackBufferWidth);
      int height = Math.Min(presentationTarget.Height, presentationParameters.BackBufferHeight);
      Rectangle sourceRectangle = new Rectangle(0, 0, width, height);
      try
      {
#if !MONOGAME
        GraphicsDevice.Present(sourceRectangle, null, presentationTarget.Handle);
        return true;
#else
        throw new NotImplementedException("MonoGame builds support only D3DImagePresentationTargets.");
#endif
      }
      // ReSharper disable EmptyGeneralCatchClause
      catch
      {
        // Do nothing. This happens when the layout of the window changes during rendering.
        // For example, when the user docks windows an OutOfVideoMemoryException might occur.
      }
      // ReSharper restore EmptyGeneralCatchClause

      return false;
    }
Пример #5
0
    public bool Render(IPresentationTarget presentationTarget, IList<GraphicsScreen> screens)
    {
      ThrowIfDisposed();

      if (presentationTarget == null)
        throw new ArgumentNullException("presentationTarget");
      if (screens == null)
        throw new ArgumentNullException("screens");
      if (_context == null)
        throw new GraphicsException("GraphicsManager.Update(TimeSpan) has not been called. The graphics service needs to be updated before content can be rendered.");

      if (GraphicsDevice.PresentationParameters.IsFullScreen
          || !presentationTarget.IsVisible
          || presentationTarget.Width <= 0
          || presentationTarget.Height <= 0)
      {
        return false;
      }

      _context.PresentationTarget = presentationTarget;

      Viewport originalViewport = GraphicsDevice.Viewport;
      try
      {
        if (presentationTarget.BeginRender(_context))
          RenderScreens(screens);
      }
      finally
      {
        presentationTarget.EndRender(_context);

        GraphicsDevice.Viewport = originalViewport;
        _context.Viewport = originalViewport;
        _context.PresentationTarget = null;
      }

      return true;
    }
Пример #6
0
 public bool Render(IPresentationTarget presentationTarget)
 {
   return Render(presentationTarget, Screens);
 }