0001:
0002:
0003:
0004:
0005:
0006: #define STRICT
0007: #include "stdafx.h"
0008: #include "resource.h"
0009: #include "CheckDeviceFormatViewer.h"
0010:
0011:
0012:
0013:
0014:
0015:
0016:
0017: TCHAR* g_strAppTitle = _T( "CheckDeviceFormatViewer" );
0018: CApp g_App;
0019: HINSTANCE g_hInst = NULL;
0020: CAppForm* g_AppFormView = NULL;
0021:
0022:
0023:
0024:
0025:
0026:
0027:
0028: IMPLEMENT_DYNCREATE( CAppDoc, CDocument )
0029: IMPLEMENT_DYNCREATE( CAppFrameWnd, CFrameWnd )
0030: IMPLEMENT_DYNCREATE( CAppForm, CFormView )
0031:
0032:
0033:
0034:
0035: BEGIN_MESSAGE_MAP( CApp, CWinApp )
0036:
0037:
0038: END_MESSAGE_MAP()
0039:
0040:
0041:
0042:
0043: BEGIN_MESSAGE_MAP( CAppForm, CFormView )
0044:
0045: ON_COMMAND( IDC_VIEWFULLSCREEN, OnToggleFullScreen )
0046: ON_BN_CLICKED(IDC_CHANGEDEVICE, OnChangeDevice)
0047:
0048:
0049: ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButtonCheckDeviceFormat)
0050: END_MESSAGE_MAP()
0051:
0052:
0053:
0054:
0055: BEGIN_MESSAGE_MAP(CAppDoc, CDocument)
0056:
0057:
0058:
0059:
0060: END_MESSAGE_MAP()
0061:
0062:
0063:
0064:
0065: BEGIN_MESSAGE_MAP(CAppFrameWnd, CFrameWnd)
0066:
0067: ON_COMMAND(IDM_CHANGEDEVICE, OnChangeDevice)
0068:
0069: END_MESSAGE_MAP()
0070:
0071: static const MyUsage s_usage[] = {
0072: {D3DUSAGE_RENDERTARGET, "D3DUSAGE_RENDERTARGET"},
0073: {D3DUSAGE_DEPTHSTENCIL,"D3DUSAGE_DEPTHSTENCIL"},
0074: {D3DUSAGE_DYNAMIC,"D3DUSAGE_DYNAMIC"},
0075:
0076:
0077:
0078:
0079: {D3DUSAGE_AUTOGENMIPMAP,"D3DUSAGE_AUTOGENMIPMAP"},
0080: {D3DUSAGE_DMAP,"D3DUSAGE_DMAP"},
0081: {0,""}
0082: };
0083: const MyUsage *CAppForm::m_Usages=s_usage;
0084:
0085: static const MyFormat s_format[] = {
0086: {D3DFMT_R8G8B8,"D3DFMT_R8G8B8"},
0087: {D3DFMT_A8R8G8B8,"D3DFMT_A8R8G8B8"},
0088: {D3DFMT_X8R8G8B8,"D3DFMT_X8R8G8B8"},
0089: {D3DFMT_R5G6B5,"D3DFMT_R5G6B5"},
0090: {D3DFMT_X1R5G5B5,"D3DFMT_X1R5G5B5"},
0091: {D3DFMT_A1R5G5B5,"D3DFMT_A1R5G5B5"},
0092: {D3DFMT_A4R4G4B4,"D3DFMT_A4R4G4B4"},
0093: {D3DFMT_R3G3B2,"D3DFMT_R3G3B2"},
0094: {D3DFMT_A8,"D3DFMT_A8"},
0095: {D3DFMT_A8R3G3B2,"D3DFMT_A8R3G3B2"},
0096: {D3DFMT_X4R4G4B4,"D3DFMT_X4R4G4B4"},
0097: {D3DFMT_A2B10G10R10,"D3DFMT_A2B10G10R10"},
0098: {D3DFMT_A8B8G8R8,"D3DFMT_A8B8G8R8"},
0099: {D3DFMT_X8B8G8R8,"D3DFMT_X8B8G8R8"},
0100: {D3DFMT_G16R16,"D3DFMT_G16R16"},
0101: {D3DFMT_A2R10G10B10,"D3DFMT_A2R10G10B10"},
0102: {D3DFMT_A16B16G16R16,"D3DFMT_A16B16G16R16"},
0103:
0104: {D3DFMT_A8P8,"D3DFMT_A8P8"},
0105: {D3DFMT_P8,"D3DFMT_P8"},
0106:
0107: {D3DFMT_L8,"D3DFMT_L8"},
0108: {D3DFMT_A8L8,"D3DFMT_A8L8"},
0109: {D3DFMT_A4L4,"D3DFMT_A4L4"},
0110:
0111: {D3DFMT_V8U8,"D3DFMT_V8U8"},
0112: {D3DFMT_L6V5U5,"D3DFMT_L6V5U5"},
0113: {D3DFMT_X8L8V8U8,"D3DFMT_X8L8V8U8"},
0114: {D3DFMT_Q8W8V8U8,"D3DFMT_Q8W8V8U8"},
0115: {D3DFMT_V16U16,"D3DFMT_V16U16"},
0116: {D3DFMT_A2W10V10U10,"D3DFMT_A2W10V10U10"},
0117:
0118: {D3DFMT_UYVY,"D3DFMT_UYVY"},
0119: {D3DFMT_R8G8_B8G8,"D3DFMT_R8G8_B8G8"},
0120: {D3DFMT_YUY2,"D3DFMT_YUY2"},
0121: {D3DFMT_G8R8_G8B8,"D3DFMT_G8R8_G8B8"},
0122: {D3DFMT_DXT1,"D3DFMT_DXT1"},
0123: {D3DFMT_DXT2,"D3DFMT_DXT2"},
0124: {D3DFMT_DXT3,"D3DFMT_DXT3"},
0125: {D3DFMT_DXT4,"D3DFMT_DXT4"},
0126: {D3DFMT_DXT5,"D3DFMT_DXT5"},
0127:
0128: {D3DFMT_D16_LOCKABLE,"D3DFMT_D16_LOCKABLE"},
0129: {D3DFMT_D32,"D3DFMT_D32"},
0130: {D3DFMT_D15S1,"D3DFMT_D15S1"},
0131: {D3DFMT_D24S8,"D3DFMT_D24S8"},
0132: {D3DFMT_D24X8,"D3DFMT_D24X8"},
0133: {D3DFMT_D24X4S4,"D3DFMT_D24X4S4"},
0134: {D3DFMT_D16,"D3DFMT_D16"},
0135:
0136: {D3DFMT_D32F_LOCKABLE,"D3DFMT_D32F_LOCKABLE"},
0137: {D3DFMT_D24FS8,"D3DFMT_D24FS8"},
0138:
0139:
0140: {D3DFMT_L16,"D3DFMT_L16"},
0141:
0142: {D3DFMT_Q16W16V16U16,"D3DFMT_Q16W16V16U16"},
0143:
0144: {D3DFMT_MULTI2_ARGB8,"D3DFMT_MULTI2_ARGB8"},
0145:
0146:
0147:
0148: {D3DFMT_R16F,"D3DFMT_R16F"},
0149: {D3DFMT_G16R16F,"D3DFMT_G16R16F"},
0150: {D3DFMT_A16B16G16R16F,"D3DFMT_A16B16G16R16F"},
0151:
0152:
0153: {D3DFMT_R32F,"D3DFMT_R32F"},
0154: {D3DFMT_G32R32F,"D3DFMT_G32R32F"},
0155: {D3DFMT_A32B32G32R32F,"D3DFMT_A32B32G32R32F"},
0156:
0157: {D3DFMT_CxV8U8,"D3DFMT_CxV8U8"},
0158:
0159:
0160: {D3DFMT_FORCE_DWORD,"D3DFMT_FORCE_DWORD"},
0161: };
0162: const MyFormat *CAppForm::m_Formats = (const MyFormat*)s_format;
0163:
0164:
0165:
0166:
0167:
0168:
0169:
0170:
0171:
0172:
0173:
0174: CAppForm::CAppForm()
0175: :CFormView( IDD_FORMVIEW )
0176: , m_bCheckRenderTarget(TRUE)
0177: , m_bCheckDepthStencil(FALSE)
0178: , m_bCheckDynamic(FALSE)
0179: , m_bCheckAutoGenMipmap(FALSE)
0180: , m_bCheckDMap(FALSE)
0181: , m_iResourceType(0)
0182: {
0183:
0184:
0185:
0186:
0187: g_AppFormView = this;
0188: m_hwndRenderWindow = NULL;
0189: m_hwndRenderFullScreen = NULL;
0190: m_hWndTopLevelParent = NULL;
0191:
0192:
0193: m_dwCreationWidth = 500;
0194: m_dwCreationHeight = 375;
0195: m_strWindowTitle = TEXT( "CheckDeviceFormatViewer" );
0196: m_d3dEnumeration.AppUsesDepthBuffer = TRUE;
0197: m_bStartFullscreen = false;
0198: m_bShowCursorWhenFullscreen = false;
0199:
0200: m_pFont = NULL;
0201: m_bLoadingApp = TRUE;
0202:
0203: ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
0204: m_fWorldRotX = 0.0f;
0205: m_fWorldRotY = 0.0f;
0206:
0207: for(m_nFormat=0; this->m_Formats[m_nFormat].val!=D3DFMT_FORCE_DWORD; m_nFormat++);
0208: m_pbResult = new BOOL[m_nFormat];
0209: for(int i=0; i<m_nFormat; i++) m_pbResult[i] = FALSE;
0210: }
0211:
0212:
0213:
0214:
0215:
0216:
0217:
0218:
0219:
0220:
0221:
0222:
0223: HRESULT CAppForm::OneTimeSceneInit()
0224: {
0225:
0226:
0227: m_bLoadingApp = FALSE;
0228:
0229: return S_OK;
0230: }
0231:
0232:
0233:
0234:
0235:
0236:
0237:
0238:
0239:
0240:
0241:
0242:
0243:
0244:
0245: HRESULT CAppForm::ConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior,
0246: D3DFORMAT Format )
0247: {
0248: UNREFERENCED_PARAMETER( pCaps );
0249: UNREFERENCED_PARAMETER( dwBehavior );
0250: UNREFERENCED_PARAMETER( Format );
0251: BOOL bCapsAcceptable;
0252:
0253:
0254: bCapsAcceptable = TRUE;
0255:
0256: if( bCapsAcceptable )
0257: return S_OK;
0258: else
0259: return E_FAIL;
0260: }
0261:
0262:
0263:
0264:
0265:
0266:
0267:
0268:
0269:
0270:
0271:
0272:
0273:
0274:
0275: HRESULT CAppForm::InitDeviceObjects()
0276: {
0277:
0278: HRESULT hr;
0279:
0280:
0281: HDC hDC = ::GetDC( NULL );
0282: int nHeight = -MulDiv( 12, GetDeviceCaps(hDC, LOGPIXELSY), 72 );
0283: ::ReleaseDC( NULL, hDC );
0284: if( FAILED( hr = D3DXCreateFont( m_pd3dDevice, nHeight, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET,
0285: OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
0286: TEXT("Arial"), &m_pFont ) ) )
0287: return DXTRACE_ERR( "D3DXCreateFont", hr );
0288: return S_OK;
0289: }
0290:
0291:
0292:
0293:
0294:
0295:
0296:
0297:
0298:
0299:
0300:
0301:
0302:
0303: HRESULT CAppForm::RestoreDeviceObjects()
0304: {
0305:
0306:
0307:
0308: D3DMATERIAL9 mtrl;
0309: D3DUtil_InitMaterial( mtrl, 1.0f, 0.0f, 0.0f );
0310: m_pd3dDevice->SetMaterial( &mtrl );
0311:
0312:
0313: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
0314: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
0315: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
0316: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
0317: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
0318: m_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
0319: m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
0320: m_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
0321:
0322:
0323: m_pd3dDevice->SetRenderState( D3DRS_DITHERENABLE, FALSE );
0324: m_pd3dDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
0325: m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
0326: m_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0x000F0F0F );
0327:
0328:
0329: D3DXMATRIX matIdentity;
0330: D3DXMatrixIdentity( &matIdentity );
0331: m_pd3dDevice->SetTransform( D3DTS_WORLD, &matIdentity );
0332:
0333:
0334:
0335:
0336:
0337: D3DXMATRIX matView;
0338: D3DXVECTOR3 vFromPt = D3DXVECTOR3( 0.0f, 0.0f, -5.0f );
0339: D3DXVECTOR3 vLookatPt = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
0340: D3DXVECTOR3 vUpVec = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
0341: D3DXMatrixLookAtLH( &matView, &vFromPt, &vLookatPt, &vUpVec );
0342: m_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
0343:
0344:
0345: D3DXMATRIX matProj;
0346: FLOAT fAspect = ((FLOAT)m_d3dsdBackBuffer.Width) / m_d3dsdBackBuffer.Height;
0347: D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, fAspect, 1.0f, 100.0f );
0348: m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
0349:
0350:
0351: D3DLIGHT9 light;
0352: D3DUtil_InitLight( light, D3DLIGHT_DIRECTIONAL, -1.0f, -1.0f, 2.0f );
0353: m_pd3dDevice->SetLight( 0, &light );
0354: m_pd3dDevice->LightEnable( 0, TRUE );
0355: m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
0356:
0357: if( m_pFont )
0358: m_pFont->OnResetDevice();
0359:
0360: return S_OK;
0361: }
0362:
0363:
0364:
0365:
0366:
0367:
0368:
0369:
0370:
0371: HRESULT CAppForm::FrameMove()
0372: {
0373:
0374:
0375:
0376: UpdateInput( &m_UserInput );
0377:
0378:
0379: D3DXMATRIX matWorld;
0380: D3DXMATRIX matRotY;
0381: D3DXMATRIX matRotX;
0382:
0383: if( m_UserInput.bRotateLeft && !m_UserInput.bRotateRight )
0384: m_fWorldRotY += m_fElapsedTime;
0385: else if( m_UserInput.bRotateRight && !m_UserInput.bRotateLeft )
0386: m_fWorldRotY -= m_fElapsedTime;
0387:
0388: if( m_UserInput.bRotateUp && !m_UserInput.bRotateDown )
0389: m_fWorldRotX += m_fElapsedTime;
0390: else if( m_UserInput.bRotateDown && !m_UserInput.bRotateUp )
0391: m_fWorldRotX -= m_fElapsedTime;
0392:
0393: D3DXMatrixRotationX( &matRotX, m_fWorldRotX );
0394: D3DXMatrixRotationY( &matRotY, m_fWorldRotY );
0395:
0396: D3DXMatrixMultiply( &matWorld, &matRotX, &matRotY );
0397: m_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
0398:
0399: return S_OK;
0400: }
0401:
0402:
0403:
0404:
0405:
0406:
0407:
0408:
0409: void CAppForm::UpdateInput( UserInput* pUserInput )
0410: {
0411: pUserInput->bRotateUp = ( m_bActive && (GetAsyncKeyState( VK_UP ) & 0x8000) == 0x8000 );
0412: pUserInput->bRotateDown = ( m_bActive && (GetAsyncKeyState( VK_DOWN ) & 0x8000) == 0x8000 );
0413: pUserInput->bRotateLeft = ( m_bActive && (GetAsyncKeyState( VK_LEFT ) & 0x8000) == 0x8000 );
0414: pUserInput->bRotateRight = ( m_bActive && (GetAsyncKeyState( VK_RIGHT ) & 0x8000) == 0x8000 );
0415: }
0416:
0417:
0418:
0419:
0420:
0421:
0422:
0423:
0424:
0425:
0426: HRESULT CAppForm::Render()
0427: {
0428:
0429: m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
0430: 0x000000ff, 1.0f, 0L );
0431:
0432:
0433: if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
0434: {
0435:
0436:
0437:
0438: RenderText();
0439:
0440:
0441: m_pd3dDevice->EndScene();
0442: }
0443:
0444: return S_OK;
0445: }
0446:
0447:
0448:
0449:
0450:
0451:
0452:
0453:
0454: HRESULT CAppForm::RenderText()
0455: {
0456: D3DCOLOR fontColor = D3DCOLOR_ARGB(255,255,255,0);
0457: TCHAR szMsg[MAX_PATH] = TEXT("");
0458: RECT rct;
0459: ZeroMemory( &rct, sizeof(rct) );
0460:
0461: rct.left = 2;
0462: rct.right = m_d3dsdBackBuffer.Width - 20;
0463:
0464:
0465: INT nNextLine = 40;
0466:
0467: lstrcpy( szMsg, m_strDeviceStats );
0468: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0469: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0470:
0471: lstrcpy( szMsg, m_strFrameStats );
0472: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0473: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0474: #if 0
0475:
0476: nNextLine = m_d3dsdBackBuffer.Height;
0477: wsprintf( szMsg, TEXT("Arrow keys: Up=%d Down=%d Left=%d Right=%d"),
0478: m_UserInput.bRotateUp, m_UserInput.bRotateDown, m_UserInput.bRotateLeft, m_UserInput.bRotateRight );
0479: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0480: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0481: sprintf( szMsg, TEXT("World State: %0.3f, %0.3f"),
0482: m_fWorldRotX, m_fWorldRotY );
0483: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0484: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0485: lstrcpy( szMsg, TEXT("Use arrow keys to update input") );
0486: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0487: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0488: lstrcpy( szMsg, TEXT("Press 'F2' to configure display") );
0489: nNextLine -= 20; rct.top = nNextLine; rct.bottom = rct.top + 20;
0490: m_pFont->DrawText( NULL, szMsg, -1, &rct, DT_NOCLIP, fontColor );
0491: #endif
0492: return S_OK;
0493: }
0494:
0495:
0496:
0497:
0498:
0499:
0500:
0501:
0502: void CAppForm::DoDataExchange(CDataExchange* pDX)
0503: {
0504: CFormView::DoDataExchange(pDX);
0505:
0506:
0507: DDX_Check(pDX, IDC_CHECK_RENDERTARGET, m_bCheckRenderTarget);
0508: DDX_Check(pDX, IDC_CHECK_DEPTHSTENCIL, m_bCheckDepthStencil);
0509: DDX_Check(pDX, IDC_CHECK_DYNAMIC, m_bCheckDynamic);
0510: DDX_Check(pDX, IDC_CHECK_AUTOGENMIPMAP, m_bCheckAutoGenMipmap);
0511: DDX_Check(pDX, IDC_CHECK_DMAP, m_bCheckDMap);
0512: DDX_CBIndex(pDX, IDC_COMBO_RESOURCE_TYPE, m_iResourceType);
0513: }
0514:
0515:
0516:
0517:
0518:
0519:
0520:
0521:
0522: LRESULT CAppForm::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
0523: {
0524: return CFormView ::WindowProc(message, wParam, lParam);
0525: }
0526:
0527:
0528:
0529:
0530:
0531:
0532:
0533:
0534: void CAppFrameWnd::OnChangeDevice()
0535: {
0536: g_AppFormView->OnChangeDevice();
0537: }
0538:
0539:
0540:
0541:
0542:
0543:
0544:
0545:
0546: HRESULT CAppForm::InvalidateDeviceObjects()
0547: {
0548:
0549: if( m_pFont )
0550: m_pFont->OnLostDevice();
0551:
0552: return S_OK;
0553: }
0554:
0555:
0556:
0557:
0558:
0559:
0560:
0561:
0562:
0563:
0564: HRESULT CAppForm::DeleteDeviceObjects()
0565: {
0566:
0567: SAFE_RELEASE( m_pFont );
0568:
0569: return S_OK;
0570: }
0571:
0572:
0573:
0574:
0575:
0576:
0577:
0578:
0579:
0580:
0581: HRESULT CAppForm::FinalCleanup()
0582: {
0583:
0584: return S_OK;
0585: }
0586:
0587:
0588:
0589:
0590:
0591:
0592:
0593:
0594:
0595:
0596: BOOL CApp::InitInstance()
0597: {
0598:
0599: AddDocTemplate( new CSingleDocTemplate( IDR_MAINFRAME,
0600: RUNTIME_CLASS(CAppDoc),
0601: RUNTIME_CLASS(CAppFrameWnd),
0602: RUNTIME_CLASS(CAppForm) ) );
0603:
0604:
0605:
0606: CCommandLineInfo cmdInfo;
0607: ParseCommandLine( cmdInfo );
0608: if( !ProcessShellCommand( cmdInfo ) )
0609: return FALSE;
0610:
0611: if( !g_AppFormView->IsReady() )
0612: return FALSE;
0613:
0614: g_AppFormView->GetParentFrame()->RecalcLayout();
0615: g_AppFormView->ResizeParentToFit( FALSE );
0616:
0617: m_pMainWnd->SetWindowText( g_strAppTitle );
0618: m_pMainWnd->UpdateWindow();
0619:
0620: return TRUE;
0621: }
0622:
0623:
0624:
0625:
0626:
0627:
0628:
0629:
0630: BOOL CAppFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
0631: {
0632: BOOL bResult = CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
0633:
0634: LoadAccelTable( MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
0635:
0636: return bResult;
0637: }
0638:
0639:
0640:
0641:
0642:
0643:
0644:
0645:
0646: BOOL CApp::OnIdle( LONG )
0647: {
0648:
0649: if( m_pMainWnd->IsIconic() )
0650: return FALSE;
0651:
0652: TCHAR strStatsPrev[200];
0653:
0654: lstrcpy(strStatsPrev, g_AppFormView->PstrFrameStats());
0655:
0656:
0657: if( g_AppFormView->IsReady() )
0658: {
0659: g_AppFormView->CheckForLostFullscreen();
0660: g_AppFormView->RenderScene();
0661: }
0662:
0663:
0664: return TRUE;
0665: }
0666:
0667:
0668:
0669:
0670:
0671:
0672:
0673:
0674:
0675: BOOL CAppFrameWnd::PreCreateWindow( CREATESTRUCT& cs )
0676: {
0677: cs.style = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX;
0678:
0679: return CFrameWnd::PreCreateWindow( cs );
0680: }
0681:
0682:
0683:
0684:
0685:
0686:
0687:
0688:
0689: CAppForm::~CAppForm()
0690: {
0691: Cleanup3DEnvironment();
0692: SAFE_RELEASE( m_pD3D );
0693: FinalCleanup();
0694:
0695: SAFE_DELETE_ARRAY(m_pbResult);
0696: }
0697:
0698:
0699:
0700:
0701:
0702:
0703:
0704:
0705: void CAppForm::OnToggleFullScreen()
0706: {
0707: ToggleFullscreen();
0708: }
0709:
0710:
0711:
0712:
0713:
0714:
0715:
0716:
0717:
0718:
0719: VOID CAppForm::OnChangeDevice()
0720: {
0721: Pause(true);
0722:
0723: UserSelectNewDevice();
0724:
0725:
0726: UpdateUIForDeviceCapabilites();
0727:
0728: Pause(false);
0729: }
0730:
0731:
0732:
0733:
0734:
0735:
0736:
0737:
0738: HRESULT CAppForm::AdjustWindowForChange()
0739: {
0740: if( m_bWindowed )
0741: {
0742: ::ShowWindow( m_hwndRenderFullScreen, SW_HIDE );
0743: CD3DApplication::m_hWnd = m_hwndRenderWindow;
0744: }
0745: else
0746: {
0747: if( ::IsIconic( m_hwndRenderFullScreen ) )
0748: ::ShowWindow( m_hwndRenderFullScreen, SW_RESTORE );
0749: ::ShowWindow( m_hwndRenderFullScreen, SW_SHOW );
0750: CD3DApplication::m_hWnd = m_hwndRenderFullScreen;
0751: }
0752:
0753: return S_OK;
0754: }
0755:
0756:
0757:
0758:
0759:
0760:
0761:
0762:
0763:
0764: LRESULT CALLBACK FullScreenWndProc( HWND hWnd, UINT msg, WPARAM wParam,
0765: LPARAM lParam )
0766: {
0767: if( msg == WM_CLOSE )
0768: {
0769:
0770: g_AppFormView->OnToggleFullScreen();
0771: g_App.GetMainWnd()->PostMessage( WM_CLOSE, 0, 0 );
0772: }
0773: else if( msg == WM_SETCURSOR )
0774: {
0775: SetCursor( NULL );
0776: }
0777: else if( msg == WM_KEYUP && wParam == VK_ESCAPE )
0778: {
0779:
0780: g_AppFormView->OnToggleFullScreen();
0781: }
0782:
0783: return DefWindowProc( hWnd, msg, wParam, lParam );
0784: }
0785:
0786:
0787:
0788:
0789:
0790:
0791:
0792:
0793:
0794: HRESULT CAppForm::CheckForLostFullscreen()
0795: {
0796: HRESULT hr;
0797:
0798: if( m_bWindowed )
0799: return S_OK;
0800:
0801: if( FAILED( hr = m_pd3dDevice->TestCooperativeLevel() ) )
0802: ForceWindowed();
0803:
0804: return S_OK;
0805: }
0806:
0807:
0808:
0809:
0810:
0811:
0812:
0813:
0814:
0815: VOID CAppForm::UpdateUIForDeviceCapabilites()
0816: {
0817:
0818: DWORD dwCaps = m_d3dCaps.RasterCaps;
0819: UNREFERENCED_PARAMETER( dwCaps );
0820: }
0821:
0822:
0823:
0824:
0825:
0826:
0827:
0828:
0829:
0830:
0831: VOID CAppForm::OnInitialUpdate()
0832: {
0833:
0834: CFormView::OnInitialUpdate();
0835:
0836:
0837: m_hWndTopLevelParent = GetTopLevelParent()->GetSafeHwnd();
0838:
0839:
0840: m_hwndRenderWindow = GetDlgItem(IDC_RENDERVIEW)->GetSafeHwnd();
0841:
0842:
0843: WNDCLASS wndClass = { CS_HREDRAW | CS_VREDRAW, FullScreenWndProc, 0, 0, NULL,
0844: NULL, NULL, (HBRUSH)GetStockObject(WHITE_BRUSH), NULL,
0845: _T("Fullscreen Window") };
0846: RegisterClass( &wndClass );
0847:
0848:
0849:
0850:
0851:
0852: m_hwndRenderFullScreen = CreateWindow( _T("Fullscreen Window"), NULL,
0853: WS_POPUP, CW_USEDEFAULT,
0854: CW_USEDEFAULT, 100, 100,
0855: m_hWndTopLevelParent, 0L, NULL, 0L );
0856:
0857:
0858:
0859: CD3DApplication::m_hWnd = m_hwndRenderWindow;
0860: CD3DApplication::m_hWndFocus = m_hwndRenderFullScreen;
0861: CD3DApplication::Create( AfxGetInstanceHandle() );
0862:
0863:
0864: }
0865:
0866:
0867:
0868:
0869:
0870: void CAppForm::OnBnClickedButtonCheckDeviceFormat()
0871: {
0872: this->UpdateData();
0873:
0874:
0875: DWORD usage = 0;
0876: if(m_bCheckRenderTarget) usage |= D3DUSAGE_RENDERTARGET;
0877: if(m_bCheckDepthStencil) usage |= D3DUSAGE_DEPTHSTENCIL;
0878: if(m_bCheckDynamic) usage |= D3DUSAGE_DYNAMIC;
0879: if(m_bCheckAutoGenMipmap) usage |= D3DUSAGE_AUTOGENMIPMAP;
0880: if(m_bCheckDMap) usage |= D3DUSAGE_DMAP;
0881:
0882:
0883: D3DRESOURCETYPE source_type = D3DRTYPE_TEXTURE;
0884: switch(m_iResourceType){
0885: case 0: source_type = D3DRTYPE_TEXTURE; break;
0886: case 1: source_type = D3DRTYPE_VOLUMETEXTURE; break;
0887: case 2: source_type = D3DRTYPE_CUBETEXTURE; break;
0888: case 3: source_type = D3DRTYPE_SURFACE; break;
0889: default: source_type = D3DRTYPE_TEXTURE; break;
0890: }
0891:
0892:
0893: D3DFORMAT adapterFormat = m_d3dSettings.DisplayMode().Format;
0894:
0895: char buf[256];
0896: char *strResult = new char[m_nFormat*256];
0897: strResult[0] = '\0';
0898:
0899: for(int i = 0; i<m_nFormat; i++){
0900: HRESULT hr;
0901: hr = m_pD3D->CheckDeviceFormat( m_d3dCaps.AdapterOrdinal,
0902: m_d3dCaps.DeviceType,
0903: adapterFormat,
0904: usage,
0905: source_type,
0906: this->m_Formats[i].val );
0907:
0908: m_pbResult[i] = FALSE;
0909: if(usage & D3DUSAGE_AUTOGENMIPMAP){
0910:
0911: if(hr!=D3DOK_NOAUTOGEN){
0912: m_pbResult[i] = TRUE;
0913: }
0914: }else{
0915:
0916: if(SUCCEEDED(hr)){
0917: m_pbResult[i] = TRUE;
0918: }
0919: }
0920:
0921: wsprintf (buf, "%s %s\r\n", m_pbResult[i]?"○":"×", this->m_Formats[i].text);
0922: lstrcat(strResult, buf);
0923: }
0924:
0925: CEdit *Edit = (CEdit *) GetDlgItem (IDC_EDIT_RESULT);
0926: Edit->SetWindowText (strResult);
0927:
0928: SAFE_DELETE_ARRAY(strResult);
0929: }
0930: