Beispiel #1
0
        /// <summary>
        /// Present the results to the swap chain.
        /// </summary>
        public virtual void Present()
        {
            // The application may optionally specify "dirty" or "scroll" rects to improve efficiency
            // in certain scenarios.  In this sample, however, we do not utilize those features.
            var parameters = new SharpDX.DXGI.PresentParameters();

            try
            {
                // The first argument instructs DXGI to block until VSync, putting the application
                // to sleep until the next VSync. This ensures we don't waste any cycles rendering
                // frames that will never be displayed to the screen.
                swapChain.Present(1, SharpDX.DXGI.PresentFlags.None, parameters);
            }
            catch (SharpDX.SharpDXException ex)
            {
                // TODO PLUG CODE HERE TO REINITIALIZE

                // If the device was removed either by a disconnect or a driver upgrade, we 
                // must completely reinitialize the renderer.
                if (ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceRemoved
                    || ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceReset)
                    DeviceManager.Initialize(DeviceManager.Dpi);
                else
                    throw;
            }
        }
        /// <summary>
        /// Present the results to the swap chain.
        /// </summary>
        public virtual void Present()
        {
            // The application may optionally specify "dirty" or "scroll" rects to improve efficiency
            // in certain scenarios.  In this sample, however, we do not utilize those features.
            var parameters = new SharpDX.DXGI.PresentParameters();

            try
            {
                // The first argument instructs DXGI to block until VSync, putting the application
                // to sleep until the next VSync. This ensures we don't waste any cycles rendering
                // frames that will never be displayed to the screen.
                swapChain.Present(1, SharpDX.DXGI.PresentFlags.None, parameters);
            }
            catch (SharpDX.SharpDXException ex)
            {
                // TODO PLUG CODE HERE TO REINITIALIZE

                // If the device was removed either by a disconnect or a driver upgrade, we
                // must completely reinitialize the renderer.
                if (ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceRemoved ||
                    ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceReset)
                {
                    deviceManager.InitializeDeviceDependentResources();
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Present the back buffer of the swap chain.
        /// </summary>
        public virtual void Present()
        {
            // The application may optionally specify "dirty" or "scroll" rects to improve efficiency
            // in certain scenarios. In this sample we do not utilize those features.
            var parameters = new SharpDX.DXGI.PresentParameters();

            try
            {
                // If enabled the first argument instructs DXGI to block until VSync,
                // putting the application to sleep until the next VSync.
                // This ensures we don't waste any CPU/GPU cycles rendering frames that will never
                // be displayed to the screen.
                _swapChain.Present((VSync ? 1 : 0), SharpDX.DXGI.PresentFlags.None, parameters);
            }
            catch (SharpDX.SharpDXException ex)
            {
                // If the device was removed either by a disconnect or a driver upgrade, we
                // must completely reinitialize the renderer.
                if (ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceRemoved ||
                    ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceReset)
                {
                    DeviceManager.Initialize(DeviceManager.Dpi);
                }
                else
                {
                    throw;
                }
            }
        }
Beispiel #4
0
        /// <summary>	
        /// [This documentation is preliminary and is subject to change.]	
        /// </summary>	
        /// <param name="syncInterval"><para>An integer that specifies how to synchronize presentation of a frame with the vertical blank.</para> <para>For the bit-block transfer (bitblt) model, values are:</para>  0 - The presentation occurs immediately, there is no synchronization. 1,2,3,4 - Synchronize presentation after the nth vertical blank.  <para>For the flip model, values are:</para>  0 - Discard this frame if you submitted a more recent presentation. n &gt; 0 - Synchronize presentation for at least n vertical blanks.  <para>For an example that shows how sync-interval values affect a flip presentation queue, see Remarks.</para> <para>If the update region straddles more than one output (each represented by <see cref="SharpDX.DXGI.Output1"/>), Present1 performs the synchronization to the output that contains the largest subrectangle of the target window's client area.</para></param>	
        /// <param name="presentFlags"><para>An integer value that contains swap-chain presentation options. These options are defined by the DXGI_PRESENT constants.</para></param>	
        /// <param name="presentParametersRef"><para>A reference to a <see cref="SharpDX.DXGI.PresentParameters"/> structure that describes updated rectangles and scroll information of the frame to present.</para></param>	
        /// <returns>Possible return values include: <see cref="SharpDX.Result.Ok"/>, <see cref="SharpDX.DXGI.ResultCode.DeviceRemoved"/> , <see cref="SharpDX.DXGI.DXGIStatus.Occluded"/>, <see cref="SharpDX.DXGI.ResultCode.InvalidCall"/>, or E_OUTOFMEMORY.</returns>	
        /// <remarks>	
        /// An application can use Present1 to optimize presentation by specifying scroll and dirty rectangles. When the runtime has information about these rectangles, the runtime can then perform necessary bitblts during presentation more efficiently and pass this metadata to the Desktop Window Manager (DWM). The DWM can then use the metadata to optimize presentation and pass the metadata to indirect displays and terminal servers to optimize traffic over the wire. An application must confine its modifications to only the dirty regions that it passes to Present1, as well as modify the entire dirty region to avoid undefined resource contents from being exposed.For flip presentation model swap chains that you create with the <see cref="SharpDX.DXGI.SwapEffect.FlipSequential"/> value set, a successful presentation results in an unbind of back buffer 0 from the graphics pipeline, except for when you pass the <see cref="SharpDX.DXGI.PresentFlags.DoNotSequence"/> flag in the Flags parameter.Flip presentation model queueSuppose the following frames with sync-interval values are queued from oldest (A) to newest (E) before you call Present1.A: 3, B: 0, C: 0, D: 1, E: 0When you call Present1, the runtime shows frame A for 3 vertical blank intervals, then frame D for 1 vertical blank interval, and then frame E until you submit a new presentation. The runtime discards frames C and D.	
        /// </remarks>	
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IDXGISwapChain1::Present1']/*"/>	
        /// <unmanaged>HRESULT IDXGISwapChain1::Present1([In] unsigned int SyncInterval,[In] unsigned int PresentFlags,[In] const void* pPresentParameters)</unmanaged>	
        public unsafe void Present(int syncInterval, PresentFlags presentFlags, PresentParameters presentParameters)
        {
            bool hasScrollRectangle = presentParameters.ScrollRectangle.HasValue;
            bool hasScrollOffset = presentParameters.ScrollOffset.HasValue;

            var scrollRectangle = hasScrollRectangle ? presentParameters.ScrollRectangle.Value : Rectangle.Empty;
            var scrollOffset = hasScrollOffset? presentParameters.ScrollOffset.Value : default(Point);

            fixed (void* pDirtyRects = presentParameters.DirtyRectangles)
            {
                var native = default(PresentParameters.__Native);
                native.DirtyRectsCount = presentParameters.DirtyRectangles != null ? presentParameters.DirtyRectangles.Length : 0;
                native.PDirtyRects = (IntPtr)pDirtyRects;
                native.PScrollRect = hasScrollRectangle ? new IntPtr(&scrollRectangle) : IntPtr.Zero;
                native.PScrollOffset = hasScrollOffset ? new IntPtr(&scrollOffset) : IntPtr.Zero;

                Present1(syncInterval, presentFlags, new IntPtr(&native));
            }
        }
Beispiel #5
0
        /// <summary>
        /// [This documentation is preliminary and is subject to change.]
        /// </summary>
        /// <param name="syncInterval"><para>An integer that specifies how to synchronize presentation of a frame with the vertical blank.</para> <para>For the bit-block transfer (bitblt) model, values are:</para>  0 - The presentation occurs immediately, there is no synchronization. 1,2,3,4 - Synchronize presentation after the nth vertical blank.  <para>For the flip model, values are:</para>  0 - Discard this frame if you submitted a more recent presentation. n &gt; 0 - Synchronize presentation for at least n vertical blanks.  <para>For an example that shows how sync-interval values affect a flip presentation queue, see Remarks.</para> <para>If the update region straddles more than one output (each represented by <see cref="SharpDX.DXGI.Output1"/>), Present1 performs the synchronization to the output that contains the largest subrectangle of the target window's client area.</para></param>
        /// <param name="presentFlags"><para>An integer value that contains swap-chain presentation options. These options are defined by the DXGI_PRESENT constants.</para></param>
        /// <param name="presentParameters"><para>A reference to a <see cref="SharpDX.DXGI.PresentParameters"/> structure that describes updated rectangles and scroll information of the frame to present.</para></param>
        /// <returns>Possible return values include: <see cref="SharpDX.Result.Ok"/>, <see cref="SharpDX.DXGI.ResultCode.DeviceRemoved"/> , <see cref="SharpDX.DXGI.DXGIStatus.Occluded"/>, <see cref="SharpDX.DXGI.ResultCode.InvalidCall"/>, or E_OUTOFMEMORY.</returns>
        /// <remarks>
        /// An application can use Present1 to optimize presentation by specifying scroll and dirty rectangles. When the runtime has information about these rectangles, the runtime can then perform necessary bitblts during presentation more efficiently and pass this metadata to the Desktop Window Manager (DWM). The DWM can then use the metadata to optimize presentation and pass the metadata to indirect displays and terminal servers to optimize traffic over the wire. An application must confine its modifications to only the dirty regions that it passes to Present1, as well as modify the entire dirty region to avoid undefined resource contents from being exposed.For flip presentation model swap chains that you create with the <see cref="SharpDX.DXGI.SwapEffect.FlipSequential"/> value set, a successful presentation results in an unbind of back buffer 0 from the graphics pipeline, except for when you pass the <see cref="SharpDX.DXGI.PresentFlags.DoNotSequence"/> flag in the Flags parameter.Flip presentation model queueSuppose the following frames with sync-interval values are queued from oldest (A) to newest (E) before you call Present1.A: 3, B: 0, C: 0, D: 1, E: 0When you call Present1, the runtime shows frame A for 3 vertical blank intervals, then frame D for 1 vertical blank interval, and then frame E until you submit a new presentation. The runtime discards frames C and D.
        /// </remarks>
        /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IDXGISwapChain1::Present1']/*"/>
        /// <unmanaged>HRESULT IDXGISwapChain1::Present1([In] unsigned int SyncInterval,[In] unsigned int PresentFlags,[In] const void* pPresentParameters)</unmanaged>
        public unsafe void Present(int syncInterval, PresentFlags presentFlags, PresentParameters presentParameters)
        {
            bool hasScrollRectangle = presentParameters.ScrollRectangle.HasValue;
            bool hasScrollOffset    = presentParameters.ScrollOffset.HasValue;

            var scrollRectangle = hasScrollRectangle ? presentParameters.ScrollRectangle.Value : Rectangle.Empty;
            var scrollOffset    = hasScrollOffset ? presentParameters.ScrollOffset.Value : default(Point);

            fixed(void *pDirtyRects = presentParameters.DirtyRectangles)
            {
                var native = default(PresentParameters.__Native);

                native.DirtyRectsCount = presentParameters.DirtyRectangles != null ? presentParameters.DirtyRectangles.Length : 0;
                native.PDirtyRects     = (IntPtr)pDirtyRects;
                native.PScrollRect     = hasScrollRectangle ? new IntPtr(&scrollRectangle) : IntPtr.Zero;
                native.PScrollOffset   = hasScrollOffset ? new IntPtr(&scrollOffset) : IntPtr.Zero;

                Present1(syncInterval, presentFlags, new IntPtr(&native));
            }
        }
Beispiel #6
0
        public void Present()
        {
            if (!_ready) return;
            var pp = new PresentParameters()
            {
                DirtyRectangles = null,
                ScrollOffset = null,
                ScrollRectangle = null
            };

            // Present
            _swap.Present(1, PresentFlags.None, pp);
            _context.DiscardView(_rtv);
        }
        /// <summary>
        /// Called when the composition target request a rendering operation.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Parameters.</param>
        private void CompositionTarget_Rendering(object sender, object e)
        {
            this.OnRender();

            PresentParameters parameters = new PresentParameters();

            try
            {
                swapChain.Present(1, PresentFlags.None, parameters);
            }
            catch (SharpDXException ex)
            {
                if (ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceRemoved
                    || ex.ResultCode == SharpDX.DXGI.ResultCode.DeviceReset)
                {
                    this.CreateDeviceDependentResources();
                    this.CreateSizeDependentResources();
                }
                else
                {
                    throw;
                }
            }
        }