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 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); }