// TODO: optional: refresh rate, multisampling, driver type (hardware vs ref vs WARP) HRESULT QD3D10Widget::initialize( int width, int height ) { QSize size( width, height ); resize( size ); HRESULT hr = createSwapChainAndDevice( width, height ); if( SUCCEEDED( hr ) ) { hr = createBackBufferRenderTargetView(); if( SUCCEEDED( hr ) ) { hr = createDepthStencilBuffers( width, height ); if( SUCCEEDED( hr ) ) { // set render targets m_pDevice->OMSetRenderTargets( 1, &m_pBackBufferRenderTargetView, m_pDepthStencilView ); // setup viewport D3D10_VIEWPORT viewport = D3D10Utils::createViewport( width, height ); m_pDevice->RSSetViewports( 1, &viewport ); } } } initializeD3D(); m_bD3DInitialized = true; return hr; }
D3DPresentEngine::D3DPresentEngine() : QObject() , m_mutex(QMutex::Recursive) , m_deviceResetToken(0) , m_D3D9(0) , m_device(0) , m_deviceManager(0) , m_surface(0) , m_glContext(0) , m_offscreenSurface(0) , m_eglDisplay(0) , m_eglConfig(0) , m_eglSurface(0) , m_glTexture(0) , m_texture(0) , m_egl(0) { ZeroMemory(&m_displayMode, sizeof(m_displayMode)); HRESULT hr = initializeD3D(); if (SUCCEEDED(hr)) { hr = createD3DDevice(); if (FAILED(hr)) qWarning("Failed to create D3D device"); } else { qWarning("Failed to initialize D3D"); } }
INT APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hInstPrev, LPSTR lpCmdLine, INT nCmdShow) { INT posX = 25; INT posY = 25; unsigned INT width = 1024; unsigned INT height = 768; //声明窗口类 WNDCLASSEX wc = {}; wc.cbSize = sizeof(wc); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = wndProc; wc.hInstance = hInstance; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszClassName = WND_CLASS01; //注册窗口类 if (!RegisterClassEx(&wc)) return 0; //创建窗口,载入注册的窗口类 HWND hwnd = CreateWindowEx(WS_EX_ACCEPTFILES, WND_CLASS01, WND_NAME01, WS_CAPTION, posX, posY, posX + width, posY + height, 0, 0, hInstance, NULL); if (initializeD3D(hwnd)) { //将窗口设置为可见 ShowWindow(hwnd, nCmdShow); MSG msg = {}; while (msg.message != WM_QUIT) { if (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { renderScene(); } } } shutDown(); UnregisterClass(WND_CLASS01, hInstance); return 0; }