BOOL CDxtexApp::HandlePossibleLostDevice(VOID) { HRESULT hr; if( !m_bDeviceLost ) return TRUE; // ok to render hr = m_pd3ddev->TestCooperativeLevel(); if( hr == D3DERR_DEVICELOST ) return FALSE; // not ready to reset, but not ok to render if( hr == D3DERR_DEVICENOTRESET ) { InvalidateDeviceObjects(); D3DPRESENT_PARAMETERS presentParams; ZeroMemory(&presentParams, sizeof(presentParams)); presentParams.Windowed = TRUE; presentParams.SwapEffect = D3DSWAPEFFECT_COPY; presentParams.BackBufferWidth = 8; presentParams.BackBufferHeight = 8; presentParams.BackBufferFormat = D3DFMT_UNKNOWN; hr = m_pd3ddev->Reset( &presentParams ); if( FAILED( hr ) ) return FALSE; RestoreDeviceObjects(); m_bDeviceLost = FALSE; } return TRUE; }
//----------------------------------------------------------------------------- // Name: DrawText() // Desc: Draws 2D text //----------------------------------------------------------------------------- HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor, TCHAR* strText, DWORD dwFlags ) { if( m_pd3dDevice == NULL || strText == NULL ) return E_FAIL; // Setup renderstate RestoreDeviceObjects(); // Set filter states if( dwFlags & D3DFONT_FILTERED ) { m_pd3dDevice->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTFN_LINEAR); m_pd3dDevice->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTFG_LINEAR); } FLOAT fStartX = sx; // Fill vertex buffer FONT2DVERTEX* pVertices = NULL; DWORD dwNumTriangles = 0; pVertices = &m_VB[0]; while( *strText ) { TCHAR c = *strText++; if( c == _T('\n') ) { sx = fStartX; sy += (m_fTexCoords[0][3]-m_fTexCoords[0][1])*m_dwTexHeight; } if( c < _T(' ') ) continue; FLOAT tx1 = m_fTexCoords[c-32][0]; FLOAT ty1 = m_fTexCoords[c-32][1]; FLOAT tx2 = m_fTexCoords[c-32][2]; FLOAT ty2 = m_fTexCoords[c-32][3]; FLOAT w = (tx2-tx1) * m_dwTexWidth / m_fTextScale; FLOAT h = (ty2-ty1) * m_dwTexHeight / m_fTextScale; *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+h-0.5f,0.5f,2.0f), dwColor, tx1, ty2 ); *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+h-0.5f,0.5f,2.0f), dwColor, tx2, ty2 ); *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+0-0.5f,sy+0-0.5f,0.5f,2.0f), dwColor, tx1, ty1 ); *pVertices++ = InitFont2DVertex( D3DXVECTOR4(sx+w-0.5f,sy+0-0.5f,0.5f,2.0f), dwColor, tx2, ty1 ); dwNumTriangles += 2; m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, &m_VB[0], dwNumTriangles*2, D3DDP_WAIT); pVertices = &m_VB[0]; dwNumTriangles = 0L; sx += w; } return S_OK; }
//----------------------------------------------------------------------------- // Name: Init() // Desc: //----------------------------------------------------------------------------- HRESULT CParticleSystem::Init( LPDIRECT3DDEVICE9 pd3dDevice ) { HRESULT hr; // Initialize the particle system if( FAILED( hr = RestoreDeviceObjects( pd3dDevice ) ) ) return hr; // Get max point size D3DCAPS9 d3dCaps; pd3dDevice->GetDeviceCaps( &d3dCaps ); m_fMaxPointSize = d3dCaps.MaxPointSize; // Check and see if we can change the size of point sprites // in hardware by sending D3DFVF_PSIZE with the FVF. if( d3dCaps.FVFCaps & D3DFVFCAPS_PSIZE ) m_bDeviceSupportsPSIZE = true; else m_bDeviceSupportsPSIZE = false; // Load Texture Map for particles if( FAILED( D3DXCreateTextureFromFile( pd3dDevice, m_chTexFile, &m_ptexParticle ) ) ) return E_FAIL; return S_OK; }
/********************Public*Routine****************************************\ * Render * \**************************************************************************/ HRESULT CHall::Render( IDirect3DDevice9* pDevice) { HRESULT hr = S_OK; if( !pDevice ) { return E_POINTER; } try { CHECK_HR( hr = RestoreDeviceObjects( pDevice ), DbgMsg("CHall::Render: failed in RestoreDeviceObjects",hr)); if( m_pFloor ) { CHECK_HR( hr = m_pFloor->Render( pDevice ), DbgMsg("CHall::Render: failed to render the floor",hr)); } if( m_pWall ) { CHECK_HR( hr = m_pWall->Render( pDevice ), DbgMsg("CHall::Render: failed to render the wall",hr)); } } catch( HRESULT hr1 ) { hr = hr1; } return hr; }
void CWndGHTeleporter::OnInitialUpdate() { CWndNeuz::OnInitialUpdate(); RestoreDeviceObjects(); m_pOK = (CWndButton*)GetDlgItem( WIDC_BUTTON_OK ); m_pFire = (CWndButton*)GetDlgItem( WIDC_BUTTON_FIRE ); m_nCtrlId[0] = WIDC_SLOT1; m_nCtrlId[1] = WIDC_SLOT2; m_nCtrlId[2] = WIDC_SLOT3; m_nCtrlId[3] = WIDC_SLOT4; m_nCtrlId[4] = WIDC_SLOT5; HOUSING_ITEM kItem; kItem.m_nType = EMPTY_SLOT; m_cWndItems.resize( MAX_TELEPORTER_SLOT, kItem ); RefreshItems( ); // 윈도를 중앙으로 옮기는 부분. CRect rectRoot = m_pWndRoot->GetLayoutRect(); CRect rectWindow = GetWindowRect(); CPoint point( rectRoot.right - rectWindow.Width(), 110 ); Move( point ); MoveParentCenter(); }
HRESULT RacorX5::InitDeviceObjects() { HRESULT hr; if (m_D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { m_iVP = D3DCREATE_HARDWARE_VERTEXPROCESSING; } else { m_iVP = D3DCREATE_SOFTWARE_VERTEXPROCESSING; } hr = ConfirmDevice(&m_D3DCaps, m_iVP, D3DFMT_UNKNOWN); if (FAILED(hr)) { MessageBox(m_hWnd, L"ConfirmDevice failed!", L"Error", 0); return E_FAIL; } m_dpps.BackBufferWidth = m_iWidth; m_dpps.BackBufferHeight = m_iHeight; m_dpps.BackBufferFormat = D3DFMT_A8R8G8B8; m_dpps.BackBufferCount = 1; m_dpps.MultiSampleType = D3DMULTISAMPLE_NONE; m_dpps.SwapEffect = D3DSWAPEFFECT_DISCARD; m_dpps.hDeviceWindow = m_hWnd; m_dpps.Windowed = m_bWindowed; m_dpps.EnableAutoDepthStencil = TRUE; m_dpps.AutoDepthStencilFormat = D3DFMT_D24S8; m_dpps.Flags = 0; m_dpps.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_dpps.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; RestoreDeviceObjects(); return S_OK; }
void CWndSelectAwakeCase::OnInitialUpdate() { CWndNeuz::OnInitialUpdate(); // 여기에 코딩하세요 // 윈도를 중앙으로 옮기는 부분. CRect rectRoot = m_pWndRoot->GetLayoutRect(); CRect rectWindow = GetWindowRect(); CPoint point( rectRoot.right - rectWindow.Width(), 110 ); Move( point ); MoveParentCenter(); ItemProp* pProp = (ItemProp*)prj.GetItemProp( m_dwItemIndex ); if( pProp ) m_pTexture = CWndBase::m_textureMng.AddTexture( g_Neuz.m_pd3dDevice, MakePath( DIR_ITEM, pProp->szIcon ), 0xffff00ff ); m_pTexGuage = CWndBase::m_textureMng.AddTexture( g_Neuz.m_pd3dDevice, MakePath( DIR_THEME, "Wndguage.tga" ), 0xffff00ff ); if( !m_pTexGuage ) Error( "CWndSelectAwakeCase::OnInitialUpdate m_pTexGuage(Wndguage.tga) is NULL" ); AddWndStyle( WBS_MODAL ); RestoreDeviceObjects( ); }
HRESULT ParticleSystem::init( LPDIRECT3DDEVICE9 pd3dDevice ) { HRESULT hr; // Initialize the particle system if( FAILED( hr = RestoreDeviceObjects( pd3dDevice ) ) ) return hr; return S_OK; }
Terrain::Terrain(LPDIRECT3DDEVICE9 pd3dDevice, float x, float y, float z, std::string sTextureFile, std::string sTerrainFile) : RenderObj(x, y, z) { m_pd3dDevice = pd3dDevice; m_bRenderFrame = false; m_sTextureFile = sTextureFile; m_sTerrainFile = sTerrainFile; m_fMinDistance = 5.0f; RestoreDeviceObjects(); }
void CWndPartyCtrl::OnInitialUpdate() { CRect rect = GetWindowRect(); m_wndScrollBar.AddWndStyle( WBS_DOCKING ); m_wndScrollBar.Create( WBS_VERT, rect, this, 1000 );//,m_pSprPack,-1); m_nFontHeight = 20;//GetFontHeight( &g_2DRender ); RestoreDeviceObjects(); m_texGauEmptyNormal.LoadTexture( m_pApp->m_pd3dDevice, MakePath( DIR_THEME, "GauEmptySmall.bmp" ), 0xffff00ff, TRUE ); m_texGauFillNormal.LoadTexture( m_pApp->m_pd3dDevice, MakePath( DIR_THEME, "GauFillSmall.bmp" ), 0xffff00ff, TRUE ); }
// 처음 이 함수를 부르면 윈도가 열린다. BOOL CWndCommand::Initialize( CWndBase* pWndParent, DWORD /*dwWndId*/ ) { CRect rectWindow = m_pWndRoot->GetWindowRect(); CRect rect( 0, 0, 150, 200 ); SetTitle( _T( "World" ) ); CWndBase::Create( WBS_TOPMOST | WBS_VSCROLL, rect, pWndParent, APP_COMMAND ); AdjustWndBase(); RestoreDeviceObjects(); return TRUE; }
bool CStdGL::CreatePrimarySurfaces(unsigned int, unsigned int, int iColorDepth, unsigned int) { // store options bool ok = RestoreDeviceObjects(); // - AMD GPUs have supported OpenGL 2.1 since 2007 // - nVidia GPUs have supported OpenGL 2.1 since 2005 // - Intel integrated GPUs have supported OpenGL 2.1 since Clarkdale (maybe earlier). // And we've already been using features from OpenGL 2.1. Nobody has complained yet. // So checking for 2.1 support should be fine. if (!GLEW_VERSION_2_1) { return Error(" gl: OpenGL Version 2.1 or higher required. A better graphics driver will probably help."); } return ok; }
HRESULT HelloShadowVolume::InitDeviceObjects() { m_dpps.AutoDepthStencilFormat = D3DFMT_D24S8; m_dpps.BackBufferCount = 1; m_dpps.BackBufferFormat = D3DFMT_A8R8G8B8; m_dpps.BackBufferWidth = m_iWidth; m_dpps.BackBufferHeight = m_iHeight; m_dpps.EnableAutoDepthStencil = TRUE; m_dpps.Flags = 0; m_dpps.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; m_dpps.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_dpps.hDeviceWindow = m_hWnd; m_dpps.Windowed = true; m_dpps.MultiSampleType = D3DMULTISAMPLE_NONE; m_dpps.SwapEffect = D3DSWAPEFFECT_DISCARD; return RestoreDeviceObjects(); }
Cube::Cube(LPDIRECT3DDEVICE9 pd3dDevice, float x, float y, float z, float fWidth, float fHeight, float fDepth, bool bBlending) : RenderObj(x, y, z) { this->m_pd3dDevice = pd3dDevice; this->m_fWidth = fWidth; this->m_fHeight = fHeight; this->m_fDepth = fDepth; this->m_bBlending = bBlending; RestoreDeviceObjects(); ZeroMemory(&m_d3dMaterial, sizeof(D3DMATERIAL9)); m_d3dMaterial.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_d3dMaterial.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); m_d3dMaterial.Specular = D3DXCOLOR(0.3f, 0.3f, 0.3f, 1.0f); m_d3dMaterial.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); m_d3dMaterial.Power = 100.0f; }
//----------------------------------------------------------------------------- // Name: MsgProc() // Desc: Message proc function to handle key and menu input //----------------------------------------------------------------------------- LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { // Pass mouse messages to the ArcBall so it can build internal matrices m_ArcBall.HandleMouseMessages( hWnd, uMsg, wParam, lParam ); // Trap the context menu if( WM_CONTEXTMENU==uMsg ) return 0; if( uMsg == WM_COMMAND ) { // Toggle mesh optimization if( LOWORD(wParam) == IDM_SHOWNONOPTIMIZEDMESH ) { m_bShowVertexCacheOptimized = FALSE; m_bShowStripReordered = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWVCACHEOPTIMIZED ) { m_bShowVertexCacheOptimized = TRUE; m_bShowStripReordered = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWSTRIPREORDERED ) { m_bShowVertexCacheOptimized = FALSE; m_bShowStripReordered = TRUE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWNONOPTIMIZEDMESH, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWVCACHEOPTIMIZED, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWSTRIPREORDERED, MF_CHECKED ); } // Toggle strips else if( LOWORD(wParam) == IDM_SHOWTRILIST ) { m_bShowStrips = FALSE; m_bShowSingleStrip = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWONESTRIP ) { m_bShowStrips = FALSE; m_bShowSingleStrip = TRUE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_CHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_UNCHECKED ); } else if( LOWORD(wParam) == IDM_SHOWMANYSTRIPS ) { m_bShowStrips = TRUE; m_bShowSingleStrip = FALSE; CheckMenuItem( GetMenu(hWnd), IDM_SHOWTRILIST, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWONESTRIP, MF_UNCHECKED ); CheckMenuItem( GetMenu(hWnd), IDM_SHOWMANYSTRIPS, MF_CHECKED ); } // Toggle vertex buffer mode else if( LOWORD(wParam) == IDM_DYNAMICVB ) { if (m_dwMemoryOptions == D3DXMESH_DYNAMIC) { m_dwMemoryOptions = D3DXMESH_MANAGED; CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_UNCHECKED ); } else { m_dwMemoryOptions = D3DXMESH_DYNAMIC; CheckMenuItem( GetMenu(hWnd), IDM_DYNAMICVB, MF_CHECKED ); } // Destroy and recreate everything InvalidateDeviceObjects(); RestoreDeviceObjects(); } else if( LOWORD(wParam) == IDM_FORCE32BYTEVERTEX ) { m_bForce32ByteFVF = !m_bForce32ByteFVF; CheckMenuItem( GetMenu(hWnd), IDM_FORCE32BYTEVERTEX, m_bForce32ByteFVF ? MF_CHECKED : MF_UNCHECKED ); // Destroy and recreate everything InvalidateDeviceObjects(); DeleteDeviceObjects(); InitDeviceObjects(); RestoreDeviceObjects(); } // Handle the open file command else if( LOWORD(wParam) == IDM_OPENFILE ) { TCHAR g_strFilename[512] = _T(""); // Display the OpenFileName dialog. Then, try to load the specified file OPENFILENAME ofn = { sizeof(OPENFILENAME), NULL, NULL, _T(".X Files (.x)\0*.x\0\0"), NULL, 0, 1, m_strMeshFilename, 512, g_strFilename, 512, m_strInitialDir, _T("Open Mesh File"), OFN_FILEMUSTEXIST, 0, 1, NULL, 0, NULL, NULL }; if( TRUE == GetOpenFileName( &ofn ) ) { _tcscpy( m_strInitialDir, m_strMeshFilename ); TCHAR* pLastSlash = _tcsrchr( m_strInitialDir, _T('\\') ); if( pLastSlash ) *pLastSlash = 0; SetCurrentDirectory( m_strInitialDir ); // Destroy and recreate everything InvalidateDeviceObjects(); DeleteDeviceObjects(); InitDeviceObjects(); RestoreDeviceObjects(); } } else if ((LOWORD(wParam) >= ID_OPTIONS_DISPLAY1) && (LOWORD(wParam) <= ID_OPTIONS_DISPLAY36)) { // uncheck old item CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_UNCHECKED ); // calc new item m_cObjectsPerSide = LOWORD(wParam) - ID_OPTIONS_DISPLAY1 + 1; // check new item CheckMenuItem( GetMenu(hWnd), ID_OPTIONS_DISPLAY1 + (m_cObjectsPerSide-1), MF_CHECKED ); } } return CD3DApplication::MsgProc( hWnd, uMsg, wParam, lParam ); }
//----------------------------------------------------------------------------- // Name: Initialize3DEnvironment() // Desc: Usually this function is not overridden. Here's what this function does: // - Sets the windowed flag to be either windowed or fullscreen // - Sets parameters for z-buffer depth and back buffer // - Creates the D3D device // - Sets the window position (if windowed, that is) // - Makes some determinations as to the abilites of the driver (HAL, etc) // - Sets up some cursor stuff // - Calls InitDeviceObjects() // - Calls RestoreDeviceObjects() // - If all goes well, m_bActive is set to TRUE, and the function returns // - Otherwise, initialization is reattempted using the reference device //----------------------------------------------------------------------------- HRESULT CMyD3DApplication::Initialize3DEnvironment() { HRESULT hr; D3DAdapterInfo* pAdapterInfo = m_d3dSettings.PAdapterInfo(); D3DDeviceInfo* pDeviceInfo = m_d3dSettings.PDeviceInfo(); m_bWindowed = m_d3dSettings.IsWindowed; // Prepare window for possible windowed/fullscreen change AdjustWindowForChange(); // Set up the presentation parameters BuildPresentParamsFromSettings(); if( pDeviceInfo->Caps.PrimitiveMiscCaps & D3DPMISCCAPS_NULLREFERENCE ) { // Warn user about null ref device that can't render anything DisplayErrorMsg( D3DAPPERR_NULLREFDEVICE, 0 ); } DWORD behaviorFlags; if (m_d3dSettings.GetVertexProcessingType() == SOFTWARE_VP) behaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == MIXED_VP) behaviorFlags = D3DCREATE_MIXED_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; else if (m_d3dSettings.GetVertexProcessingType() == PURE_HARDWARE_VP) behaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE; else behaviorFlags = 0; // TODO: throw exception // Add multithreaded flag if requested by app if( m_bCreateMultithreadDevice ) behaviorFlags |= D3DCREATE_MULTITHREADED; // Create the device hr = m_pD3D->CreateDevice( m_d3dSettings.AdapterOrdinal(), pDeviceInfo->DevType, m_hWndFocus, behaviorFlags, &m_d3dpp, &m_pd3dDevice ); if( SUCCEEDED(hr) ) { // When moving from fullscreen to windowed mode, it is important to // adjust the window size after recreating the device rather than // beforehand to ensure that you get the window size you want. For // example, when switching from 640x480 fullscreen to windowed with // a 1000x600 window on a 1024x768 desktop, it is impossible to set // the window size to 1000x600 until after the display mode has // changed to 1024x768, because windows cannot be larger than the // desktop. if( m_bWindowed ) { SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_HIDEWINDOW ); } // Store device Caps m_pd3dDevice->GetDeviceCaps( &m_d3dCaps ); m_dwCreateFlags = behaviorFlags; // Store device description if( pDeviceInfo->DevType == D3DDEVTYPE_REF ) lstrcpy( m_strDeviceStats, TEXT("REF") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcpy( m_strDeviceStats, TEXT("HAL") ); else if( pDeviceInfo->DevType == D3DDEVTYPE_SW ) lstrcpy( m_strDeviceStats, TEXT("SW") ); if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING && behaviorFlags & D3DCREATE_PUREDEVICE ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (pure hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated pure hw vp)") ); } else if( behaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (hw vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated hw vp)") ); } else if( behaviorFlags & D3DCREATE_MIXED_VERTEXPROCESSING ) { if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) lstrcat( m_strDeviceStats, TEXT(" (mixed vp)") ); else lstrcat( m_strDeviceStats, TEXT(" (simulated mixed vp)") ); } else if( behaviorFlags & D3DCREATE_SOFTWARE_VERTEXPROCESSING ) { lstrcat( m_strDeviceStats, TEXT(" (sw vp)") ); } if( pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { // Be sure not to overflow m_strDeviceStats when appending the adapter // description, since it can be long. Note that the adapter description // is initially CHAR and must be converted to TCHAR. lstrcat( m_strDeviceStats, TEXT(": ") ); const int cchDesc = sizeof(pAdapterInfo->AdapterIdentifier.Description); TCHAR szDescription[cchDesc]; DXUtil_ConvertAnsiStringToGenericCch( szDescription, pAdapterInfo->AdapterIdentifier.Description, cchDesc ); int maxAppend = sizeof(m_strDeviceStats) / sizeof(TCHAR) - lstrlen( m_strDeviceStats ) - 1; _tcsncat( m_strDeviceStats, szDescription, maxAppend ); } // Store render target surface desc LPDIRECT3DSURFACE9 pBackBuffer = NULL; m_pd3dDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer ); pBackBuffer->GetDesc( &m_d3dsdBackBuffer ); pBackBuffer->Release(); // Set up the fullscreen cursor if( m_bShowCursorWhenFullscreen && !m_bWindowed ) { HCURSOR hCursor; #ifdef _WIN64 hCursor = (HCURSOR)GetClassLongPtr( m_hWnd, GCLP_HCURSOR ); #else hCursor = (HCURSOR)ULongToHandle( GetClassLong( m_hWnd, GCL_HCURSOR ) ); #endif D3DUtil_SetDeviceCursor( m_pd3dDevice, hCursor, true ); m_pd3dDevice->ShowCursor( true ); } // Confine cursor to fullscreen window if( m_bClipCursorWhenFullscreen ) { if (!m_bWindowed ) { RECT rcWindow; GetWindowRect( m_hWnd, &rcWindow ); ClipCursor( &rcWindow ); } else { ClipCursor( NULL ); } } // Initialize the app's device-dependent objects hr = InitDeviceObjects(); if( FAILED(hr) ) { DeleteDeviceObjects(); } else { m_bDeviceObjectsInited = true; hr = RestoreDeviceObjects(); if( FAILED(hr) ) { InvalidateDeviceObjects(); } else { m_bDeviceObjectsRestored = true; return S_OK; } } // Cleanup before we try again Cleanup3DEnvironment(); } // If that failed, fall back to the reference rasterizer if( hr != D3DAPPERR_MEDIANOTFOUND && hr != HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) && pDeviceInfo->DevType == D3DDEVTYPE_HAL ) { if (FindBestWindowedMode(false, true)) { m_bWindowed = true; AdjustWindowForChange(); // Make sure main window isn't topmost, so error message is visible SetWindowPos( m_hWnd, HWND_NOTOPMOST, m_rcWindowBounds.left, m_rcWindowBounds.top, ( m_rcWindowBounds.right - m_rcWindowBounds.left ), ( m_rcWindowBounds.bottom - m_rcWindowBounds.top ), SWP_SHOWWINDOW ); // Let the user know we are switching from HAL to the reference rasterizer DisplayErrorMsg( hr, MSGWARN_SWITCHEDTOREF ); hr = Initialize3DEnvironment(); } } return hr; }
HRESULT CDirect3D::Resize3DEnvironment(void) { // Release all vidmem objects HRESULT hr; #if LOG_D3D LOG_MSG("D3D:Resize3DEnvironment() called"); #endif if(FAILED(hr=InvalidateDeviceObjects())) { LOG_MSG("D3D:Failed to invalidate objects"); return hr; } // Reset the device reset_device: Bitu i = 20; // Don't bother too much, when device is already lost if(deviceLost) i = 5; deviceLost = false; if(FAILED(hr=pD3DDevice9->Reset(&d3dpp))) { if(hr==D3DERR_DEVICELOST) { while((hr=pD3DDevice9->TestCooperativeLevel()) != D3DERR_DEVICENOTRESET) { if(hr==D3DERR_DRIVERINTERNALERROR) { LOG_MSG("D3D:Driver internal error when resetting device!"); return hr; } #if LOG_D3D LOG_MSG("D3D:Wait for D3D device to become available..."); #endif Sleep(50); i--; if(i == 0) { deviceLost = true; #if LOG_D3D LOG_MSG("D3D:Giving up on D3D wait..."); #endif // Return ok or dosbox will quit, we'll try to reset the device later return S_OK; } } #if LOG_D3D LOG_MSG("D3D:Performing another reset..."); #endif goto reset_device; } else { LOG_MSG("D3D:Failed to reset device!"); return hr; } } backbuffer_clear_countdown = 2; if (d3dpp.BackBufferCount == 2) backbuffer_clear_countdown++; #if 0 // Clear all backbuffers pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); pD3DDevice9->Present(NULL, NULL, NULL, NULL); pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); if(d3dpp.BackBufferCount == 2) { pD3DDevice9->Present(NULL, NULL, NULL, NULL); pD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); } #endif #if LOG_D3D LOG_MSG("D3D:Mode: %dx%d (x %.2fx%.2f) --> scaled size: %dx%d", dwWidth, dwHeight, (float)dwScaledWidth/dwWidth, (float)dwScaledHeight/dwHeight, dwScaledWidth, dwScaledHeight); #endif return RestoreDeviceObjects(); }