bool Display::resetDevice() { D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); HRESULT result = D3D_OK; bool lost = testDeviceLost(); int attempts = 3; while (lost && attempts > 0) { if (mDeviceEx) { Sleep(500); // Give the graphics driver some CPU time result = mDeviceEx->ResetEx(&presentParameters, NULL); } else { result = mDevice->TestCooperativeLevel(); while (result == D3DERR_DEVICELOST) { Sleep(100); // Give the graphics driver some CPU time result = mDevice->TestCooperativeLevel(); } if (result == D3DERR_DEVICENOTRESET) { result = mDevice->Reset(&presentParameters); } } lost = testDeviceLost(); attempts --; } if (FAILED(result)) { ERR("Reset/ResetEx failed multiple times: 0x%08X", result); return error(EGL_BAD_ALLOC, false); } // reset device defaults initializeDevice(); return true; }
LPDIRECT3DDEVICE D3DeviceFactory::createDevice(HWND hwnd, D3DPRESENT_PARAMETERS *param, UINT adapter) { // static if(s_direct3D == NULL) { initDirect3D(); } D3DPRESENT_PARAMETERS tmpParam; if(param == NULL) { tmpParam = getDefaultPresentParameters(hwnd, adapter); param = &tmpParam; } LPDIRECT3DDEVICE device; CHECKRESULT(s_direct3D->CreateDeviceEx(adapter ,D3DDEVTYPE_HAL ,hwnd ,D3DCREATE_SOFTWARE_VERTEXPROCESSING ,param ,NULL ,&device)); TRACE_CREATE(device); return device; }
bool Display::createDevice() { if (!isInitialized()) { return error(EGL_NOT_INITIALIZED, false); } D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES; HRESULT result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice); if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST) { return error(EGL_BAD_ALLOC, false); } if (FAILED(result)) { result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice); if (FAILED(result)) { ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_NOTAVAILABLE || result == D3DERR_DEVICELOST); return error(EGL_BAD_ALLOC, false); } } if (mD3d9Ex) { result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx); ASSERT(SUCCEEDED(result)); } initializeDevice(); return true; }