// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using SharpDX.Mathematics.Interop; namespace SharpDX.DXGI { public partial class SwapChain { /// /// Creates a swap chain. /// /// /// If you attempt to create a swap chain in full-screen mode, and full-screen mode is unavailable, the swap chain will be created in windowed mode and DXGI_STATUS_OCCLUDED will be returned. If the buffer width or the buffer height are zero, the sizes will be inferred from the output window size in the swap-chain description. Since the target output cannot be chosen explicitly when the swap-chain is created, you should not create a full-screen swap chain. This can reduce presentation performance if the swap chain size and the output window size do not match. Here are two ways to ensure the sizes match: Create a windowed swap chain and then set it full-screen using . Save a reference to the swap-chain immediately after creation, and use it to get the output window size during a WM_SIZE event. Then resize the swap chain buffers (with ) during the transition from windowed to full-screen. If the swap chain is in full-screen mode, before you release it, you must use {{SetFullscreenState}} to switch it to windowed mode. For more information about releasing a swap chain, see the Destroying a Swap Chain section of {{DXGI Overview}}. /// /// a reference to a . /// A reference to the device that will write 2D images to the swap chain. /// A reference to the swap-chain description (see ). /// HRESULT IDXGIFactory::CreateSwapChain([In] IUnknown* pDevice,[In] DXGI_SWAP_CHAIN_DESC* pDesc,[Out] IDXGISwapChain** ppSwapChain) /// bb174537 /// HRESULT IDXGIFactory::CreateSwapChain([In] IUnknown* pDevice,[In] DXGI_SWAP_CHAIN_DESC* pDesc,[Out, Fast] IDXGISwapChain** ppSwapChain) /// IDXGIFactory::CreateSwapChain public SwapChain(Factory factory, ComObject device, SwapChainDescription description) : base(IntPtr.Zero) { factory.CreateSwapChain(device, ref description, this); } /// /// Access one of the swap-chain back buffers. /// /// The interface of the surface to resolve from the back buffer /// A zero-based buffer index. If the swap effect is not DXGI_SWAP_EFFECT_SEQUENTIAL, this method only has access to the first buffer; for this case, set the index to zero. /// /// Returns a reference to a back-buffer interface. /// /// bb174570 /// HRESULT IDXGISwapChain::GetBuffer([In] unsigned int Buffer,[In] const GUID& riid,[Out] void** ppSurface) /// IDXGISwapChain::GetBuffer public T GetBackBuffer(int index) where T : ComObject { IntPtr temp; GetBuffer(index, Utilities.GetGuidFromType(typeof (T)), out temp); return FromPointer(temp); } /// ///

Gets performance statistics about the last render frame.

///
/// ///

You cannot use GetFrameStatistics for swap chains that both use the bit-block transfer (bitblt) presentation model and draw in windowed mode.

You can only use GetFrameStatistics for swap chains that either use the flip presentation model or draw in full-screen mode. You set the value in the SwapEffect member of the structure to specify that the swap chain uses the flip presentation model.

///
/// /// bb174573 /// GetFrameStatistics /// GetFrameStatistics /// HRESULT IDXGISwapChain::GetFrameStatistics([Out] DXGI_FRAME_STATISTICS* pStats) public SharpDX.DXGI.FrameStatistics FrameStatistics { get { SharpDX.DXGI.FrameStatistics output; SharpDX.Result result = TryGetFrameStatistics(out output); result.CheckError(); return output; } } /// /// Gets or sets a value indicating whether the swapchain is in fullscreen. /// /// /// true if this swapchain is in fullscreen; otherwise, false. /// /// bb174574 /// HRESULT IDXGISwapChain::GetFullscreenState([Out] BOOL* pFullscreen,[Out] IDXGIOutput** ppTarget) /// IDXGISwapChain::GetFullscreenState public bool IsFullScreen { get { RawBool isFullScreen; Output output; GetFullscreenState(out isFullScreen, out output); if (output != null) output.Dispose(); return isFullScreen; } set { SetFullscreenState(value, null); } } /// ///

[Starting with Direct3D 11.1, we recommend not to use Present anymore to present a rendered image. Instead, use . For more info, see Remarks.]

Presents a rendered image to the user.

///
/// No documentation. /// No documentation. ///

Possible return values include: , or (see DXGI_ERROR), (see ), or D3DDDIERR_DEVICEREMOVED.

Note??The Present method can return either or D3DDDIERR_DEVICEREMOVED if a video card has been physically removed from the computer, or a driver upgrade for the video card has occurred.

/// ///

Starting with Direct3D 11.1, we recommend to instead use because you can then use dirty rectangles and the scroll rectangle in the swap chain presentation and as such use less memory bandwidth and as a result less system power. For more info about using dirty rectangles and the scroll rectangle in swap chain presentation, see Using dirty rectangles and the scroll rectangle in swap chain presentation.

For the best performance when flipping swap-chain buffers in a full-screen application, see Full-Screen Application Performance Hints.

Because calling Present might cause the render thread to wait on the message-pump thread, be careful when calling this method in an application that uses multiple threads. For more details, see Multithreading Considerations.

Differences between Direct3D 9 and Direct3D 10:

Specifying in the Flags parameter is analogous to IDirect3DDevice9::TestCooperativeLevel in Direct3D 9.

?

For flip presentation model swap chains that you create with the value set, a successful presentation unbinds back buffer 0 from the graphics pipeline, except for when you pass the flag in the Flags parameter.

For info about how data values change when you present content to the screen, see Converting data for the color space.

///
/// /// bb174576 /// HRESULT IDXGISwapChain::Present([In] unsigned int SyncInterval,[In] DXGI_PRESENT_FLAGS Flags) /// IDXGISwapChain::Present public SharpDX.Result Present(int syncInterval, SharpDX.DXGI.PresentFlags flags) { unsafe { SharpDX.Result result; result = TryPresent(syncInterval, flags); result.CheckError(); return result; } } } }