示例#1
0
        public Direct3DDevice9 CreateDevice(int adapter, D3DDEVTYPE deviceType, IntPtr hFocusWindow, D3DCREATE behaviorFlags, params D3DPRESENT_PARAMETERS[] pPresentationParameters)
        {
            IntPtr nativePointer;

            CreateDevice_(adapter, deviceType, hFocusWindow, behaviorFlags, pPresentationParameters, out nativePointer).CheckError();
            return(new Direct3DDevice9(nativePointer));
        }
示例#2
0
        //-----------------------------------------------------------------------------
        // 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);
            }
        }
示例#3
0
        /// <unmanaged>HRESULT IDirect3D9::CreateDevice([In] unsigned int Adapter,[In] D3DDEVTYPE DeviceType,[In] HWND hFocusWindow,[In] D3DCREATE BehaviorFlags,[In, Buffer] D3DPRESENT_PARAMETERS* pPresentationParameters,[Out, Fast] IDirect3DDevice9** ppReturnedDeviceInterface)</unmanaged>
        private unsafe HRESULT CreateDevice_(int adapter, D3DDEVTYPE deviceType, IntPtr hFocusWindow, D3DCREATE behaviorFlags, D3DPRESENT_PARAMETERS[] pPresentationParameters, out IntPtr ppReturnedDeviceInterface)
        {
            var     result = IntPtr.Zero;
            HRESULT hr;

            fixed(void *ptr = pPresentationParameters)
            {
                //result = calli(System.Int32(System.Void*,System.Int32,System.Int32,System.Void*,System.Int32,System.Void*,System.Void*), this._nativePointer, adapter, deviceType, (void*)hFocusWindow, behaviorFlags, ptr, &zero, *(*(IntPtr*)this._nativePointer + (IntPtr)16 * (IntPtr)sizeof(void*)));
                hr = (HRESULT)NativeHelper.CalliInt32(16, _nativePointer, adapter, (int)deviceType, (void *)hFocusWindow, (int)behaviorFlags, ptr, &result);
            }

            ppReturnedDeviceInterface = result;
            return(hr);
        }