//-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain(ID3D11Device* pd3dDevice, IDXGISwapChain* /*pSwapChain*/, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* /*pUserContext*/) { HRESULT hr; V_RETURN(g_DialogResourceManager.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc)); V_RETURN(g_D3DSettingsDlg.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc)); g_nFrameWidth = pBackBufferSurfaceDesc->Width; g_nFrameHeight = pBackBufferSurfaceDesc->Height; // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams(XM_PI / 4, fAspectRatio, 0.1f, 5000.0f); g_Camera.SetWindow(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height); g_HUD.SetLocation(pBackBufferSurfaceDesc->Width - 170, 0); g_HUD.SetSize(170, 170); g_SampleUI.SetLocation(pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350); g_SampleUI.SetSize(170, 300); g_OIT.OnD3D11ResizedSwapChain(pBackBufferSurfaceDesc, pd3dDevice); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D10 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D10SwapChainResized( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr = S_OK; V_RETURN( g_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); V_RETURN( g_D3DSettingsDlg.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( 60.0f * ( D3DX_PI / 180.0f ), fAspectRatio, 0.1f, 100.0f ); g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 ); g_SampleUI.SetSize( 170, 300 ); // Update the sample count UpdateMSAASampleCounts( pd3dDevice, pBackBufferSurfaceDesc->Format ); // Create a render target g_BackBufferWidth = pBackBufferSurfaceDesc->Width; g_BackBufferHeight = pBackBufferSurfaceDesc->Height; V_RETURN( CreateRenderTarget( pd3dDevice, g_BackBufferWidth, g_BackBufferHeight, g_MSAASampleCount, 0 ) ); return hr; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); FLOAT fAspect = (FLOAT)pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; // Setup the camera's projection parameters XMMATRIX matProjection = XMMatrixPerspectiveFovLH( XM_PIDIV4, fAspect, 0.001f, 100.0f ); XMStoreFloat4x4A( &g_matProjection, matProjection ); g_pTerrainView->GetCamera()->SetProjParams( XM_PIDIV4, fAspect, 0.01f, 1000.0f ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); INT UIWidth = 250; INT UIHeight = 110; g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - UIWidth, pBackBufferSurfaceDesc->Height - UIHeight ); g_SampleUI.SetSize( UIWidth, UIHeight ); g_HalfClientWidthPixels = (FLOAT)pBackBufferSurfaceDesc->Width * 0.5f; g_HalfClientHeightPixels = (FLOAT)pBackBufferSurfaceDesc->Height * 0.5f; ResidencySampleRender::ResizeRenderView( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D10 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D10ResizedSwapChain(ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext) { HRESULT hr; V_RETURN(g_DialogResourceManager.OnD3D10ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc)); V_RETURN(g_D3DSettingsDlg.OnD3D10ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc)); // Setup the camera's projection parameters float fAspectRatio = 1.0;//pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams(D3DX_PI / 4, fAspectRatio, 0.1f, 10.0f); g_Camera.SetWindow(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height); g_Camera.SetButtonMasks(MOUSE_RIGHT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON); g_HUD.SetLocation(pBackBufferSurfaceDesc->Width - 170, 0); g_HUD.SetSize(170, 170); g_SampleUI.SetLocation(pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300); g_SampleUI.SetSize(170, 300); // resize the texture so that it fits to the current screen size UINT width = (DXUTIsAppRenderingWithD3D9()) ? DXUTGetD3D9BackBufferSurfaceDesc()->Width : DXUTGetDXGIBackBufferSurfaceDesc()->Width; UINT height = (DXUTIsAppRenderingWithD3D9()) ? DXUTGetD3D9BackBufferSurfaceDesc()->Height : DXUTGetDXGIBackBufferSurfaceDesc()->Height; g_vsObj->SetupTextures(pd3dDevice, g_pEffect10, width, height); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { UNREFERENCED_PARAMETER(pSwapChain); UNREFERENCED_PARAMETER(pUserContext); HRESULT hr; XMVECTOR vMeshExtents = g_Scene.GetSceneAABBMax() - g_Scene.GetSceneAABBMin(); XMVECTOR vMeshLength = XMVector3Length( vMeshExtents ); FLOAT fMeshLength = XMVectorGetByIndex( vMeshLength, 0); V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); V_RETURN( g_D3DSettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); g_fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT ) pBackBufferSurfaceDesc->Height; g_ViewerCamera.SetProjParams( XM_PI / 4, g_fAspectRatio, 0.05f, fMeshLength); g_Scene.OnResize(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 ); g_SampleUI.SetSize( 170, 300 ); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() ); // Setup the camera's projection parameters camera->OnResetDevice(pBackBufferSurfaceDesc); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 350, 0 ); g_HUD.SetSize( 360, 100 ); g_HUD.GetEditBox(IDC_CMD)->SetLocation(5,pBackBufferSurfaceDesc->Height-30); g_HUD.GetStatic(IDC_STATIC7)->SetLocation(5,pBackBufferSurfaceDesc->Height-60); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 350, 130 ); g_SampleUI.SetSize( 350, pBackBufferSurfaceDesc->Height - 130 ); //clear black part of screen clearRect.x1 = pBackBufferSurfaceDesc->Width - 360; clearRect.y1 = 0; clearRect.x2 = pBackBufferSurfaceDesc->Width; clearRect.y2 = pBackBufferSurfaceDesc->Height; return S_OK; }
//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9CreateDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D10DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D10DestroyDevice(); g_SettingsDlg.OnD3D10DestroyDevice(); DXUTGetGlobalResourceCache().OnDestroyDevice(); g_Terrain.OnDestroyDevice(); g_BallMesh.Destroy(); g_SkyMesh.Destroy(); SAFE_RELEASE( g_pFont10 ); SAFE_RELEASE( g_pSprite10 ); SAFE_DELETE( g_pTxtHelper ); SAFE_RELEASE( g_pEffect10 ); SAFE_RELEASE( g_pBasicDecl10 ); SAFE_RELEASE( g_pBallDecl10 ); SAFE_RELEASE( g_pGrassDecl10 ); SAFE_RELEASE( g_pHeightTexRV ); SAFE_RELEASE( g_pNormalTexRV ); SAFE_RELEASE( g_pGrassTexRV ); SAFE_RELEASE( g_pDirtTexRV ); SAFE_RELEASE( g_pGroundGrassTexRV ); SAFE_RELEASE( g_pMaskTexRV ); SAFE_RELEASE( g_pShadeNormalTexRV ); SAFE_RELEASE( g_pStreamDataVB10 ); SAFE_RELEASE( g_pGrassDataVB10 ); }
//-------------------------------------------------------------------------------------- // Handle messages to the application //-------------------------------------------------------------------------------------- LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) { UNREFERENCED_PARAMETER(pUserContext); // Pass messages to dialog resource manager calls so GUI state is updated correctly *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; // Pass messages to settings dialog if its active if( g_D3DSettingsDlg.IsActive() ) { g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam ); return 0; } // Give the dialogs a chance to handle the message first *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; // Pass all remaining windows messages to camera so it can respond to user input g_ViewerCamera.HandleMessages( hWnd, uMsg, wParam, lParam ); return 0; }
//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9CreateDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D9DestroyDevice(); g_SettingsDlg.OnD3D9DestroyDevice(); manipulator->Release(); }
//-------------------------------------------------------------------------------------- // Release D3D11 resources created in OnD3D11CreateDevice //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D11DestroyDevice(); g_D3DSettingsDlg.OnD3D11DestroyDevice(); //CDXUTDirectionWidget::StaticOnD3D11DestroyDevice(); DXUTGetGlobalResourceCache().OnDestroyDevice(); test.destroy(); tessplane.destroy(); lightsphere.destroy(); tesscube.destroy(); fuse.destroy(); deboard.destroy(); board1.destroy(); geo_alien.destroy(); FirePart.destroy(); SAFE_DELETE( g_pTxtHelper ); SAFE_RELEASE(g_DepthState); //g_Mesh11.Destroy(); // //SAFE_RELEASE( g_pVertexLayout11 ); //SAFE_RELEASE( g_pVertexBuffer ); //SAFE_RELEASE( g_pIndexBuffer ); //SAFE_RELEASE( g_pVertexShader ); //SAFE_RELEASE( g_pPixelShader ); //SAFE_RELEASE( g_pSamLinear ); /* SAFE_RELEASE( g_pcbVSPerObject ); SAFE_RELEASE( g_pcbPSPerObject ); SAFE_RELEASE( g_pcbPSPerFrame );*/ }
//-------------------------------------------------------------------------------------- // Before handling window messages, DXUT passes incoming windows // messages to the application through this callback function. If the application sets // *pbNoFurtherProcessing to TRUE, then DXUT will not process this message. //-------------------------------------------------------------------------------------- LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) { // Always allow dialog resource manager calls to handle global messages // so GUI state is updated correctly *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; if( g_SettingsDlg.IsActive() ) { g_SettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam ); return 0; } // Give the dialogs a chance to handle the message first *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; // Pass all remaining windows messages to camera so it can respond to user input g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam ); g_LightControl.HandleMessages( hWnd, uMsg, wParam, lParam ); return 0; }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() ); if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() ); V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) ); g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, NULL, NULL, 15 ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f ); g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350 ); g_SampleUI.SetSize( 170, 300 ); SCEMAN->SetActiveDevice( pd3dDevice ); SCEMAN->OnDeviceReset(); return S_OK; }
HRESULT CALLBACK OnD3D11ResizedSwapChain(ID3D11Device* d3dDevice, IDXGISwapChain* swapChain, const DXGI_SURFACE_DESC* backBufferSurfaceDesc, void* userContext) { HRESULT hr; V_RETURN(gDialogResourceManager.OnD3D11ResizedSwapChain(d3dDevice, backBufferSurfaceDesc)); V_RETURN(gD3DSettingsDlg.OnD3D11ResizedSwapChain(d3dDevice, backBufferSurfaceDesc)); gAspectRatio = backBufferSurfaceDesc->Width / (float)backBufferSurfaceDesc->Height; // NOTE: Complementary Z (1-z) buffer used here, so swap near/far! gViewerCamera.SetProjParams(D3DX_PI / 4.0f, gAspectRatio, 300.0f, 0.05f); // Standard HUDs const int border = 20; int y = border; for (int i = 0; i < HUD_EXPERT; ++i) { gHUD[i].SetLocation(backBufferSurfaceDesc->Width - gHUD[i].GetWidth() - border, y); y += gHUD[i].GetHeight() + border; } // Expert HUD gHUD[HUD_EXPERT].SetLocation(border, 80); // If there's no app, it'll pick this up when it gets lazily created so just ignore it if (gApp) { gApp->OnD3D11ResizedSwapChain(d3dDevice, backBufferSurfaceDesc); } return S_OK; }
//-------------------------------------------------------------------------------------- // This callback function will be called immediately after the Direct3D device has been // reset, which will happen after a lost device scenario. This is the best location to // create D3DPOOL_DEFAULT resources since these resources need to be reloaded whenever // the device is lost. Resources created here should be released in the OnLostDevice // callback. //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() ); if( g_pFont ) V_RETURN( g_pFont->OnResetDevice() ); if( g_pEffect ) V_RETURN( g_pEffect->OnResetDevice() ); g_LightControl.OnD3D9ResetDevice( pBackBufferSurfaceDesc ); g_Skybox.OnResetDevice( pBackBufferSurfaceDesc ); // Create a sprite to help batch calls when drawing many lines of text V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.001f, 1000.0f ); g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_RIGHT_BUTTON ); g_Camera.SetAttachCameraToModel( true ); g_Camera.SetRadius( 5.0f, 0.1f, 20.0f ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 300, pBackBufferSurfaceDesc->Height - 245 ); g_SampleUI.SetSize( 300, 300 ); return S_OK; }
//-------------------------------------------------------------------------------------- // Release D3D11 resources created in OnD3D11CreateDevice //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D11DestroyDevice(); g_D3DSettingsDlg.OnD3D11DestroyDevice(); DXUTGetGlobalResourceCache().OnDestroyDevice(); SAFE_DELETE( g_pTxtHelper ); SAFE_DELETE( g_pTxtHelper1 ); g_SceneMesh.Destroy(); g_Poles.Destroy(); SAFE_RELEASE( g_pSceneVS ); SAFE_RELEASE( g_pScenePS ); SAFE_RELEASE( g_pSM_VS ); SAFE_RELEASE( g_pcbConstants ); SAFE_RELEASE( g_pRSMDepthStencilTexture ); SAFE_RELEASE( g_pDepthStencilTextureDSV ); SAFE_RELEASE( g_pDepthTextureSRV ); SAFE_RELEASE( g_pSceneVertexLayout ); SAFE_RELEASE( g_pBlendStateNoBlend ); SAFE_RELEASE( g_pBlendStateColorWritesOff ); SAFE_RELEASE( g_pSamplePoint ); SAFE_RELEASE( g_pSamplePointCmp ); SAFE_RELEASE( g_pSampleLinear ); }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_D3DSettingsDlg.OnD3D9ResetDevice() ); if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() ); if( g_pEffect9 ) V_RETURN( g_pEffect9->OnResetDevice() ); // Create a sprite to help batch calls when drawing many lines of text V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) ); g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, 15 ); g_LightControl.OnD3D9ResetDevice( pBackBufferSurfaceDesc ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 2.0f, 4000.0f ); g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 ); g_SampleUI.SetSize( 170, 300 ); return S_OK; }
//-------------------------------------------------------------------------------------- // Create any D3D11 resources that depend on the back buffer //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height / 2; g_Context.m_Camera.SetProjParams(XM_PI / 4, fAspectRatio, 0.1f, 1000.0f); // g_Context.m_Camera.SetProjParams(XM_PI / 4, fAspectRatio, 0.1f, 10000.0f); g_Context.m_Light.SetRadius(10.0f); g_Context.m_Light.SetLightDirection(XMFLOAT3(0.6f, 0.4f, 0.3f)); g_Context.m_Light.SetButtonMask(MOUSE_RIGHT_BUTTON); g_Context.m_fbWidth = (float)pBackBufferSurfaceDesc->Width; g_Context.m_fbHeight = (float)pBackBufferSurfaceDesc->Height; // Set the location and size of the AMD standard HUD g_HUD.m_GUI.SetLocation( pBackBufferSurfaceDesc->Width - AMD::HUD::iDialogWidth, 0 ); g_HUD.m_GUI.SetSize( AMD::HUD::iDialogWidth, pBackBufferSurfaceDesc->Height ); g_HUD.OnResizedSwapChain( pBackBufferSurfaceDesc ); assert( D3D_OK == hr ); return S_OK; }
void CALLBACK on_resize(ID3D11Device* pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext) { dune::assert_hr(dlg_manager.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc)); for (size_t i = 0; i < dlg_manager.m_Dialogs.size(); ++i) dlg_manager.m_Dialogs[i]->SetLocation(pBackBufferSurfaceDesc->Width - 165, 0); }
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* noFurtherProcessing, void* userContext) { // Pass messages to dialog resource manager calls so GUI state is updated correctly *noFurtherProcessing = gDialogResourceManager.MsgProc(hWnd, uMsg, wParam, lParam ); if (*noFurtherProcessing) { return 0; } // Pass messages to settings dialog if its active if (gD3DSettingsDlg.IsActive()) { gD3DSettingsDlg.MsgProc(hWnd, uMsg, wParam, lParam); return 0; } // Give the dialogs a chance to handle the message first for (int i = 0; i < HUD_NUM; ++i) { *noFurtherProcessing = gHUD[i].MsgProc(hWnd, uMsg, wParam, lParam); if(*noFurtherProcessing) { return 0; } } // Pass all remaining windows messages to camera so it can respond to user input gViewerCamera.HandleMessages(hWnd, uMsg, wParam, lParam); return 0; }
//-------------------------------------------------------------------------------------- // Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) // or that are tied to the back buffer size //-------------------------------------------------------------------------------------- HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { HRESULT hr; V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() ); V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() ); if( g_pFont ) V_RETURN( g_pFont->OnResetDevice() ); if( g_pEffect ) V_RETURN( g_pEffect->OnResetDevice() ); // Create a sprite to help batch calls when drawing many lines of text V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) ); // Setup the camera's projection parameters float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height; g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f ); g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 ); g_HUD.SetSize( 170, 170 ); g_SampleUI.SetLocation( 0, 0 ); g_SampleUI.SetSize( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height ); g_SampleUI.GetControl( IDC_STATIC )->SetSize( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height * 6 / 10 ); g_SampleUI.GetControl( IDC_OUTPUT )->SetSize( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height / 4 ); g_SampleUI.GetControl( IDC_EDITBOX1 )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 230 ); g_SampleUI.GetControl( IDC_EDITBOX1 )->SetSize( pBackBufferSurfaceDesc->Width - 40, 32 ); if( g_SampleUI.GetControl( IDC_EDITBOX2 ) ) { g_SampleUI.GetControl( IDC_EDITBOX2 )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 280 ); g_SampleUI.GetControl( IDC_EDITBOX2 )->SetSize( pBackBufferSurfaceDesc->Width - 40, 45 ); } g_SampleUI.GetControl( IDC_ENABLEIME )->SetLocation( 130, pBackBufferSurfaceDesc->Height - 80 ); g_SampleUI.GetControl( IDC_DISABLEIME )->SetLocation( 220, pBackBufferSurfaceDesc->Height - 80 ); g_SampleUI.GetControl( IDC_SLIDER )->SetLocation( 10, pBackBufferSurfaceDesc->Height - 140 ); g_SampleUI.GetControl( IDC_CHECKBOX )->SetLocation( 120, pBackBufferSurfaceDesc->Height - 50 ); g_SampleUI.GetControl( IDC_CLEAREDIT )->SetLocation( 120, pBackBufferSurfaceDesc->Height - 25 ); g_SampleUI.GetControl( IDC_COMBOBOX )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 180 ); g_SampleUI.GetControl( IDC_RADIO1A )->SetLocation( pBackBufferSurfaceDesc->Width - 160, 100 ); g_SampleUI.GetControl( IDC_RADIO1B )->SetLocation( pBackBufferSurfaceDesc->Width - 160, 124 ); g_SampleUI.GetControl( IDC_RADIO1C )->SetLocation( pBackBufferSurfaceDesc->Width - 160, 148 ); g_SampleUI.GetControl( IDC_RADIO2A )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 100 ); g_SampleUI.GetControl( IDC_RADIO2B )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 76 ); g_SampleUI.GetControl( IDC_RADIO2C )->SetLocation( 20, pBackBufferSurfaceDesc->Height - 52 ); g_SampleUI.GetControl( IDC_LISTBOX )->SetLocation( pBackBufferSurfaceDesc->Width - 400, pBackBufferSurfaceDesc->Height - 180 ); g_SampleUI.GetControl( IDC_LISTBOX )->SetSize( 190, 96 ); g_SampleUI.GetControl( IDC_LISTBOXM )->SetLocation( pBackBufferSurfaceDesc->Width - 200, pBackBufferSurfaceDesc->Height - 180 ); g_SampleUI.GetControl( IDC_LISTBOXM )->SetSize( 190, 124 ); g_Mesh.RestoreDeviceObjects( pd3dDevice ); return S_OK; }
//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9CreateDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D9DestroyDevice(); g_SettingsDlg.OnD3D9DestroyDevice(); SAFE_RELEASE( g_pEffect9 ); SAFE_RELEASE( g_pFont9 ); }
// Handle messages to the application LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ) { // Pass messages to dialog resource manager calls so GUI state is updated correctly *pbNoFurtherProcessing = gDialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; // Pass messages to settings dialog if its active if( gD3DSettingsDlg.IsActive() ) { gD3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam ); return 0; } // Give the dialogs a chance to handle the message first *pbNoFurtherProcessing = gHUD.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; *pbNoFurtherProcessing = gSampleUI.MsgProc( hWnd, uMsg, wParam, lParam ); if( *pbNoFurtherProcessing ) return 0; return 0; }
//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9ResetDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9LostDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D9LostDevice(); g_SettingsDlg.OnD3D9LostDevice(); if( g_pFont9 ) g_pFont9->OnLostDevice(); SAFE_RELEASE( g_pSprite9 ); SAFE_DELETE( g_pTxtHelper ); }
//-------------------------------------------------------------------------------------- // Release D3D11 resources created in OnD3D11CreateDevice //-------------------------------------------------------------------------------------- void CALLBACK OnD3D11DestroyDevice( void* pUserContext ) { DXUTGetGlobalResourceCache().OnDestroyDevice(); dialogResourceManager.OnD3D11DestroyDevice(); vegetationRendering->release(); delete vegetationRendering; vegetationRendering = 0; }
void CALLBACK OnDestroyDevice(void* pUserContext) { g_DialogResourceManager.OnD3D9DestroyDevice(); SAFE_RELEASE(g_pFont); g_Board.OnDestroyDevice(); g_BackgroundQuad.Destroy(); }
//-------------------------------------------------------------------------------------- // Release D3D10 resources created in OnD3D10ResizedSwapChain //-------------------------------------------------------------------------------------- void CALLBACK OnD3D10SwapChainReleasing( void* pUserContext ) { g_DialogResourceManager.OnD3D10ReleasingSwapChain(); SAFE_RELEASE( g_pRenderTarget ); SAFE_RELEASE( g_pRTRV ); SAFE_RELEASE( g_pDSTarget ); SAFE_RELEASE( g_pDSRV ); }
HRESULT CALLBACK onCreateDevice(IDirect3DDevice9 *device, const D3DSURFACE_DESC *desc, void *userContext) { HRESULT hr; V_RETURN(dialogResourceManager.OnD3D9CreateDevice(device)); V_RETURN(D3DXCreateFont(device, 15, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Arial", &font)); return S_OK; }
//-------------------------------------------------------------------------------------- // Release D3D9 resources created in the OnD3D9CreateDevice callback //-------------------------------------------------------------------------------------- void CALLBACK OnD3D9DestroyDevice( void* pUserContext ) { g_DialogResourceManager.OnD3D9DestroyDevice(); g_D3DSettingsDlg.OnD3D9DestroyDevice(); CDXUTDirectionWidget::StaticOnD3D9DestroyDevice(); SAFE_RELEASE( g_pEffect9 ); SAFE_RELEASE( g_pFont9 ); SAFE_RELEASE( g_pMesh9 ); SAFE_RELEASE( g_pMeshTexture9 ); }
void CALLBACK OnLostDevice(void* pUserContext) { g_DialogResourceManager.OnD3D9LostDevice(); if(g_pFont) g_pFont->OnLostDevice(); SAFE_RELEASE(g_pTextSprite); g_Board.OnLostDevice(); g_BackgroundQuad.OnLostDevice(); }
void CALLBACK OnD3D11DestroyDevice(void* userContext) { DestroyApp(); DestroyScene(); gDialogResourceManager.OnD3D11DestroyDevice(); gD3DSettingsDlg.OnD3D11DestroyDevice(); DXUTGetGlobalResourceCache().OnDestroyDevice(); SAFE_DELETE(gTextHelper); }