public GraphicsDevice( IWindow window ) { d3d = new SharpDX.Direct3D9.Direct3D (); IntPtr handle = ( window.Handle as System.Windows.Forms.Form ).Handle; this.window = window; d3dpp = new SharpDX.Direct3D9.PresentParameters ( 800, 600, SharpDX.Direct3D9.Format.A8R8G8B8, 1, SharpDX.Direct3D9.MultisampleType.None, 0, SharpDX.Direct3D9.SwapEffect.Discard, handle, true, true, SharpDX.Direct3D9.Format.D24S8, SharpDX.Direct3D9.PresentFlags.None, 0, SharpDX.Direct3D9.PresentInterval.Immediate ); try { d3dDevice = new SharpDX.Direct3D9.Device ( d3d, 0, SharpDX.Direct3D9.DeviceType.Hardware, handle, SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing, d3dpp ); } catch { d3dDevice = new SharpDX.Direct3D9.Device ( d3d, 0, SharpDX.Direct3D9.DeviceType.Hardware, handle, SharpDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, d3dpp ); } Information = new GraphicsDeviceInformation ( d3d ); BackBuffer = new BackBuffer ( this ); ImmediateContext = new GraphicsContext ( this ); //window.Resize += ( object sender, EventArgs e ) => { ResizeBackBuffer ( ( int ) window.ClientSize.X, ( int ) window.ClientSize.Y ); }; }
/// <summary> /// Resets the type, size, and format of the swap chain with all other surfaces persistent. /// </summary> /// <param name="presentationParametersRef">A reference describing the new presentation parameters.</param> /// <param name="fullScreenDisplayMode">The full screen display mode.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT IDirect3DDevice9Ex::ResetEx([In] D3DPRESENT_PARAMETERS* pPresentationParameters,[In] void* pFullscreenDisplayMode)</unmanaged> public void ResetEx(ref SharpDX.Direct3D9.PresentParameters presentationParametersRef, DisplayModeEx fullScreenDisplayMode) { unsafe { var native = DisplayModeEx.__NewNative(); fullScreenDisplayMode.__MarshalTo(ref native); ResetEx(ref presentationParametersRef, new IntPtr(&native)); } }
public D3D9() { var presentparams = new SharpDX.Direct3D9.PresentParameters { Windowed = true, SwapEffect = SharpDX.Direct3D9.SwapEffect.Discard, DeviceWindowHandle = GetDesktopWindow(), PresentationInterval = SharpDX.Direct3D9.PresentInterval.Default }; const SharpDX.Direct3D9.CreateFlags deviceFlags = SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing | SharpDX.Direct3D9.CreateFlags.Multithreaded | SharpDX.Direct3D9.CreateFlags.FpuPreserve; direct3d = new SharpDX.Direct3D9.Direct3DEx(); device = new SharpDX.Direct3D9.DeviceEx(direct3d, 0, SharpDX.Direct3D9.DeviceType.Hardware, IntPtr.Zero, deviceFlags, presentparams); }
void StartD3D() { context = new SharpDX.Direct3D9.Direct3DEx(); // Ref: https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/wpf-and-direct3d9-interoperation var presentparams = new SharpDX.Direct3D9.PresentParameters { Windowed = true, SwapEffect = SharpDX.Direct3D9.SwapEffect.Discard, //DeviceWindowHandle = GetDesktopWindow(), PresentationInterval = SharpDX.Direct3D9.PresentInterval.Default, BackBufferHeight = 1, BackBufferWidth = 1, BackBufferFormat = SharpDX.Direct3D9.Format.Unknown }; device = new SharpDX.Direct3D9.DeviceEx(context, this.adapterIndex, SharpDX.Direct3D9.DeviceType.Hardware, IntPtr.Zero, SharpDX.Direct3D9.CreateFlags.HardwareVertexProcessing | SharpDX.Direct3D9.CreateFlags.Multithreaded | SharpDX.Direct3D9.CreateFlags.FpuPreserve, presentparams); }
/// <summary> /// Resets the type, size, and format of the swap chain with all other surfaces persistent. /// </summary> /// <param name="presentationParametersRef">A reference describing the new presentation parameters.</param> /// <returns> /// A <see cref="SharpDX.Result"/> object describing the result of the operation. /// </returns> /// <unmanaged>HRESULT IDirect3DDevice9Ex::ResetEx([In] D3DPRESENT_PARAMETERS* pPresentationParameters,[In] void* pFullscreenDisplayMode)</unmanaged> public void ResetEx(ref SharpDX.Direct3D9.PresentParameters presentationParametersRef) { ResetEx(ref presentationParametersRef, IntPtr.Zero); }
/// <summary> /// <p>Retrieves the presentation parameters associated with a swap chain.</p> /// </summary> /// <param name="presentationParametersRef"><dd> <p>Pointer to the presentation parameters. See <strong><see cref="SharpDX.Direct3D9.PresentParameters"/></strong>.</p> </dd></param> /// <returns><p>If the method succeeds, the return value is <see cref="SharpDX.Direct3D9.ResultCode.Success"/>. If the method fails, the return value can be <see cref="SharpDX.Direct3D9.ResultCode.InvalidCall"/>. </p></returns> /// <remarks> /// <p>This method can be used to see the presentation parameters of the parent swap chain of a surface (a back buffer, for instance). The parent swap chain can be retrieved with <strong><see cref="SharpDX.Direct3D9.Surface.GetContainer"/></strong>.</p> /// </remarks> /// <include file='.\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IDirect3DSwapChain9::GetPresentParameters']/*"/> /// <msdn-id>bb205906</msdn-id> /// <unmanaged>HRESULT IDirect3DSwapChain9::GetPresentParameters([Out] D3DPRESENT_PARAMETERS* pPresentationParameters)</unmanaged> /// <unmanaged-short>IDirect3DSwapChain9::GetPresentParameters</unmanaged-short> internal void GetPresentParameters(out SharpDX.Direct3D9.PresentParameters presentationParametersRef) { unsafe { presentationParametersRef = new SharpDX.Direct3D9.PresentParameters(); SharpDX.Result __result__; fixed (void* presentationParametersRef_ = &presentationParametersRef) __result__= SharpDX.Direct3D9.LocalInterop.Calliint(_nativePointer, presentationParametersRef_,((void**)(*(void**)_nativePointer))[9]); __result__.CheckError(); } }