private void CreateDevice() { if (m_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; /* Windows Vista runs much more performant with the IDirect3DDevice9Ex */ if (IsVistaOrBetter) { m_d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); } else/* Windows XP */ { m_d3d.CreateDevice(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, out dev); } m_device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
private static void CreateDevice() { if (_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; _d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, _hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); _device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
private void CreateDevice() { if (m_device != null) { return; } var param = new D3DPRESENT_PARAMETERS { Windowed = 1, Flags = ((short)D3DPRESENTFLAG.D3DPRESENTFLAG_VIDEO), BackBufferFormat = D3DFORMAT.D3DFMT_X8R8G8B8, SwapEffect = D3DSWAPEFFECT.D3DSWAPEFFECT_COPY }; /* The COM pointer to our D3D Device */ IntPtr dev; /* Windows Vista runs much more performant with the IDirect3DDevice9Ex */ int hr = 0; if (m_d3dEx != null) { hr = m_d3dEx.CreateDeviceEx(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, IntPtr.Zero, out dev); } else/* Windows XP */ { hr = m_d3d.CreateDevice(0, D3DDEVTYPE.D3DDEVTYPE_HAL, m_hWnd, CreateFlags.D3DCREATE_SOFTWARE_VERTEXPROCESSING | CreateFlags.D3DCREATE_MULTITHREADED, ref param, out dev); } if (dev == IntPtr.Zero) { throw new WPFMediaKitException($"Cannot create D3D device ({hr:X}). Do you have D3D acceleration enabled for your graphics card?"); } m_device = (IDirect3DDevice9)Marshal.GetObjectForIUnknown(dev); Marshal.Release(dev); }
//----------------------------------------------------------------------------- // CreateD3DDevice // // Creates the Direct3D device. //----------------------------------------------------------------------------- protected void CreateD3DDevice() { IntPtr hwnd = IntPtr.Zero; IntPtr hMonitor = IntPtr.Zero; int uAdapterID = 0; D3DCREATE vp = 0; D3DCAPS9 ddCaps; IDirect3DDevice9Ex pDevice = null; // Hold the lock because we might be discarding an exisiting device. lock (this) { if ((m_pD3D9 == null) || (m_pDeviceManager == null)) { throw new COMException("D3DPresentEngine::CreateD3DDevice", (int)HResult.MF_E_NOT_INITIALIZED); } hwnd = GetDesktopWindow(); // Note: The presenter creates additional swap chains to present the // video frames. Therefore, it does not use the device's implicit // swap chain, so the size of the back buffer here is 1 x 1. D3DPRESENT_PARAMETERS pp = new D3DPRESENT_PARAMETERS(); pp.BackBufferWidth = 1; pp.BackBufferHeight = 1; pp.Windowed = true; pp.SwapEffect = D3DSWAPEFFECT.Copy; pp.BackBufferFormat = D3DFORMAT.Unknown; pp.hDeviceWindow = hwnd; pp.Flags = D3DPRESENTFLAG.Video; pp.PresentationInterval = D3DPRESENT_INTERVAL.Default; // Find the monitor for this window. if (m_hwnd != IntPtr.Zero) { hMonitor = MonitorFromWindow(m_hwnd, MonitorFlags.DefaultToNearest); // Find the corresponding adapter. FindAdapter(m_pD3D9 as IDirect3D9, hMonitor, out uAdapterID); } // Get the device caps for this adapter. m_pD3D9.GetDeviceCaps(uAdapterID, D3DDEVTYPE.HAL, out ddCaps); if ((ddCaps.DevCaps & D3DDEVCAPS.HWTRANSFORMANDLIGHT) > 0) { vp = D3DCREATE.HardwareVertexProcessing; } else { vp = D3DCREATE.SoftwareVertexProcessing; } // Create the device. m_pD3D9.CreateDeviceEx( uAdapterID, D3DDEVTYPE.HAL, pp.hDeviceWindow, vp | D3DCREATE.NoWindowChanges | D3DCREATE.MultiThreaded | D3DCREATE.FPU_PRESERVE, pp, null, out pDevice ); // Get the adapter display mode. m_pD3D9.GetAdapterDisplayMode(uAdapterID, out m_DisplayMode); // Reset the D3DDeviceManager with the new device m_pDeviceManager.ResetDevice(pDevice, m_DeviceResetToken); if (m_pDevice != pDevice) { SafeRelease(m_pDevice); m_pDevice = pDevice; } //SafeRelease(pDevice); } }