0001: //-------------------------------------------------------------
0002: // File: main.cpp
0003: //
0004: // Desc: Bitonic sort
0005: //-------------------------------------------------------------
0006: #define STRICT
0007: #include <windows.h>
0008: #include <commctrl.h>
0009: #include <commdlg.h>
0010: #include <basetsd.h>
0011: #include <math.h>
0012: #include <stdio.h>
0013: #include <d3dx9.h>
0014: #include <dxerr9.h>
0015: #include <tchar.h>
0016: #include "Common/DXUtil.h"
0017: #include "Common/D3DEnumeration.h"
0018: #include "Common/D3DSettings.h"
0019: #include "Common/D3DApp.h"
0020: #include "Common/D3DFont.h"
0021: #include "Common/D3DFile.h"
0022: #include "Common/D3DUtil.h"
0023: #include "resource.h"
0024: #include "main.h"
0025: 
0026: // 長いから短縮形を作ってみた
0027: #define RS   m_pd3dDevice->SetRenderState
0028: #define TSS  m_pd3dDevice->SetTextureStageState
0029: #define SAMP m_pd3dDevice->SetSamplerState
0030: 
0031: #define frand() ((float)rand()/RAND_MAX)
0032: 
0033: #if 0
0034: #define TEX_WIDTH  2
0035: #define TEX_HEIGHT 2
0036: #define LOG_SIZE   2 // log2(TEX_WIDTH*TEX_HEIGHT)
0037: #else
0038: #if 0
0039: #define TEX_WIDTH  4
0040: #define TEX_HEIGHT 4
0041: #define LOG_SIZE   4 // log2(TEX_WIDTH*TEX_HEIGHT)
0042: #else
0043: #if 0
0044: #define TEX_WIDTH  16
0045: #define TEX_HEIGHT 16
0046: #define LOG_SIZE   8 // log2(TEX_WIDTH*TEX_HEIGHT)
0047: #else
0048: #if 0
0049: #define TEX_WIDTH  256
0050: #define TEX_HEIGHT 256
0051: #define LOG_SIZE   16 // log2(TEX_WIDTH*TEX_HEIGHT)
0052: #else
0053: #if 1
0054: #define TEX_WIDTH  512
0055: #define TEX_HEIGHT 512
0056: #define LOG_SIZE   18 // log2(TEX_WIDTH*TEX_HEIGHT)
0057: #else
0058: #if 1
0059: #define TEX_WIDTH  1024
0060: #define TEX_HEIGHT 1024
0061: #define LOG_SIZE   20 // log2(TEX_WIDTH*TEX_HEIGHT)
0062: #else
0063: #endif
0064: #endif
0065: #endif
0066: #endif
0067: #endif
0068: #endif
0069: 
0070: //-------------------------------------------------------------
0071: // 頂点の構造体
0072: //-------------------------------------------------------------
0073: typedef struct {
0074:     FLOAT       p[4];
0075:     FLOAT       tu, tv;
0076: } TVERTEX;
0077: 
0078: //-------------------------------------------------------------
0079: // グローバル変数
0080: //-------------------------------------------------------------
0081: CMyD3DApplication* g_pApp  = NULL;
0082: HINSTANCE          g_hInst = NULL;
0083: 
0084: 
0085: //-------------------------------------------------------------
0086: // Name: WinMain()
0087: // Desc: メイン関数
0088: //-------------------------------------------------------------
0089: INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
0090: {
0091:     CMyD3DApplication d3dApp;
0092: 
0093:     g_pApp  = &d3dApp;
0094:     g_hInst = hInst;
0095: 
0096:     InitCommonControls();
0097:     if( FAILED( d3dApp.Create( hInst ) ) )
0098:         return 0;
0099: 
0100:     return d3dApp.Run();
0101: }
0102: 
0103: 
0104: 
0105: 
0106: //-------------------------------------------------------------
0107: // Name: CMyD3DApplication()
0108: // Desc: アプリケーションのコンストラクタ
0109: //-------------------------------------------------------------
0110: CMyD3DApplication::CMyD3DApplication()
0111: {
0112:     m_pSeedTex                  = NULL;
0113: 
0114:     m_pSortTex[0]               = NULL;
0115:     m_pSortTex[1]               = NULL;
0116:     m_pSortSurf[0]              = NULL;
0117:     m_pSortSurf[1]              = NULL;
0118:     m_id                        = 0;
0119:     this->SetState(STATE_INIT);
0120: 
0121:     m_pEffect                   = NULL;
0122:     m_hTechnique                = NULL;
0123:     m_htSrcMap                  = NULL;
0124:     m_hstage                    = NULL;
0125:     m_hstepno                   = NULL;
0126:     m_hoffset                   = NULL;
0127: 
0128:     m_dwCreationWidth           = 512+20;
0129:     m_dwCreationHeight          = 512+20;
0130:     m_strWindowTitle            = TEXT( "main" );
0131:     m_d3dEnumeration.AppUsesDepthBuffer   = TRUE;
0132:     m_bStartFullscreen          = false;
0133:     m_bShowCursorWhenFullscreen = false;
0134: 
0135:     m_pFont                     = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
0136:     m_bLoadingApp               = TRUE;
0137:     m_bDispText                 = FALSE;
0138: 
0139:     ZeroMemory( &m_UserInput, sizeof(m_UserInput) );
0140: }
0141: 
0142: 
0143: 
0144: 
0145: //-------------------------------------------------------------
0146: // Name: CreateSeedTex()
0147: // Desc: CreateSeedTex テクスチャの作成
0148: //-------------------------------------------------------------
0149: VOID WINAPI CreateSeedTex (D3DXVECTOR4* pOut, CONST D3DXVECTOR2* pTexCoord, 
0150: CONST D3DXVECTOR2* pTexelSize, LPVOID pData)
0151: {
0152:     UNREFERENCED_PARAMETER( pTexCoord );
0153:     UNREFERENCED_PARAMETER( pTexelSize );
0154:     UNREFERENCED_PARAMETER( pData );
0155: 
0156: #if 0
0157:     float c = pTexCoord->x/pTexelSize->x-0.5;
0158:     c = TEX_HEIGHT-c;
0159:     pOut->x = 
0160:     pOut->y = 
0161:     pOut->z = 
0162:     pOut->w = c/TEX_HEIGHT;
0163: #else
0164:     pOut->x = 
0165:     pOut->y = 
0166:     pOut->z = 
0167:     pOut->w = frand();
0168: #endif
0169: }
0170: 
0171: 
0172: 
0173: 
0174: //-------------------------------------------------------------
0175: // Name: ~CMyD3DApplication()
0176: // Desc: デストラクタ
0177: //-------------------------------------------------------------
0178: CMyD3DApplication::~CMyD3DApplication()
0179: {
0180: }
0181: 
0182: 
0183: 
0184: 
0185: //-------------------------------------------------------------
0186: // Name: OneTimeSceneInit()
0187: // Desc: 一度だけ行う初期化
0188: //      ウィンドウの初期化やIDirect3D9の初期化は終わってます。
0189: //      ただ、LPDIRECT3DDEVICE9 の初期化は終わっていません。
0190: //-------------------------------------------------------------
0191: HRESULT CMyD3DApplication::OneTimeSceneInit()
0192: {
0193:     // ローディングメッセージを表示する
0194:     SendMessage( m_hWnd, WM_PAINT, 0, 0 );
0195: 
0196:     m_bLoadingApp = FALSE;
0197: 
0198:     return S_OK;
0199: }
0200: 
0201: 
0202: 
0203: 
0204: //-------------------------------------------------------------
0205: // Name: ConfirmDevice()
0206: // Desc: 初期化の時に呼ばれます。必要な能力をチェックします。
0207: //-------------------------------------------------------------
0208: HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS9* pCaps,
0209:                      DWORD dwBehavior,    D3DFORMAT Format )
0210: {
0211:     UNREFERENCED_PARAMETER( Format );
0212:     UNREFERENCED_PARAMETER( dwBehavior );
0213:     UNREFERENCED_PARAMETER( pCaps );
0214:     
0215: 
0216:     // ピクセルシェーダバージョンチェック
0217:     if( pCaps->PixelShaderVersion < D3DPS_VERSION(2,0) )
0218:         return E_FAIL;
0219: 
0220:     return S_OK;
0221: }
0222: 
0223: 
0224: 
0225: 
0226: //-------------------------------------------------------------
0227: // Name: InitDeviceObjects()
0228: // Desc: デバイスが生成された後の初期化をします。
0229: //      フレームバッファフォーマットやデバイスの種類が変わった
0230: //      後に通過します。
0231: //      ここで確保したメモリはDeleteDeviceObjects()で開放します
0232: //-------------------------------------------------------------
0233: HRESULT CMyD3DApplication::InitDeviceObjects()
0234: {
0235:     HRESULT hr;
0236: 
0237:     // シェーダの読み込み
0238:     LPD3DXBUFFER pErr;
0239:     if( FAILED( hr = D3DXCreateEffectFromFile(
0240:                 m_pd3dDevice, "hlsl.fx", NULL, NULL, 
0241:                 D3DXSHADER_DEBUG , NULL, &m_pEffect, &pErr ))){
0242:         MessageBox( NULL, (LPCTSTR)pErr->GetBufferPointer()
0243:                     , "ERROR", MB_OK);
0244:         return DXTRACE_ERR( "CreateEffectFromFile", hr );
0245:     }
0246:     m_hTechnique = m_pEffect->GetTechniqueByName( "TShader" );
0247:     m_htSrcMap   = m_pEffect->GetParameterByName( NULL, "SrcMap" );
0248:     m_hstage     = m_pEffect->GetParameterByName( NULL, "stage" );
0249:     m_hstepno    = m_pEffect->GetParameterByName( NULL, "stepno" );
0250:     m_hoffset    = m_pEffect->GetParameterByName( NULL, "offset" );
0251:     // テクスチャサイズ
0252:     D3DXVECTOR4 BufInfo = D3DXVECTOR4(TEX_WIDTH, TEX_HEIGHT, 0,0);
0253:     m_pEffect->SetVector("BufInfo",  &BufInfo);
0254: 
0255:     // フォント
0256:     m_pFont->InitDeviceObjects( m_pd3dDevice );
0257: 
0258:     return S_OK;
0259: }
0260: 
0261: 
0262: 
0263: 
0264: //-------------------------------------------------------------
0265: // Name: RestoreDeviceObjects()
0266: // Desc: 画面のサイズが変更された時等に呼ばれます。
0267: //      確保したメモリはInvalidateDeviceObjects()で開放します。
0268: //-------------------------------------------------------------
0269: HRESULT CMyD3DApplication::RestoreDeviceObjects()
0270: {
0271:     HRESULT hr;
0272:     int i;
0273:     
0274:     // 状態リセット
0275:     this->SetState(STATE_INIT);
0276: 
0277:     // エフェクト
0278:     m_pEffect->OnResetDevice();
0279:     
0280:     // 乱数種
0281:     if( FAILED(hr = m_pd3dDevice->CreateTexture(TEX_WIDTH, TEX_HEIGHT, 1
0282:                           , D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8
0283:                           , D3DPOOL_DEFAULT, &m_pSeedTex, NULL)))
0284:         return hr;
0285: 
0286: 
0287:     // レンダリングターゲット
0288:     for(i=0;i<2;i++){
0289:         if (FAILED(m_pd3dDevice->CreateTexture(TEX_WIDTH, TEX_HEIGHT, 1
0290:                             , D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8
0291:                             , D3DPOOL_DEFAULT, &m_pSortTex[i], NULL)))
0292:             return E_FAIL;
0293:         if (FAILED(m_pSortTex[i]->GetSurfaceLevel(0, &m_pSortSurf[i])))
0294:             return E_FAIL;
0295:     }
0296: 
0297: 
0298:     // レンダリング状態の設定
0299:     RS( D3DRS_DITHERENABLE,   FALSE );
0300:     RS( D3DRS_SPECULARENABLE, FALSE );
0301:     RS( D3DRS_ZENABLE, FALSE );
0302:     RS( D3DRS_LIGHTING, FALSE );
0303: 
0304:     TSS(0,D3DTSS_COLOROP,   D3DTOP_SELECTARG1);
0305:     TSS(0,D3DTSS_COLORARG1, D3DTA_TEXTURE);
0306:     TSS(1,D3DTSS_COLOROP,    D3DTOP_DISABLE);
0307: 
0308:     SAMP( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
0309:     SAMP( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
0310:     SAMP( 0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP );
0311:     SAMP( 0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP );
0312: 
0313:     // フォント
0314:     m_pFont->RestoreDeviceObjects();
0315: 
0316:     return S_OK;
0317: }
0318: 
0319: 
0320: 
0321: 
0322: //-------------------------------------------------------------
0323: // Name: FrameMove()
0324: // Desc: 毎フレーム呼ばれます。アニメの処理などを行います。
0325: //-------------------------------------------------------------
0326: HRESULT CMyD3DApplication::FrameMove()
0327: {
0328:     // 入力データの更新
0329:     UpdateInput( &m_UserInput );
0330: 
0331:     return S_OK;
0332: }
0333: //-------------------------------------------------------------
0334: // Name: UpdateInput()
0335: // Desc: 入力データを更新する
0336: //-------------------------------------------------------------
0337: void CMyD3DApplication::UpdateInput( UserInput* pUserInput )
0338: {
0339:     pUserInput->bRotateUp    = ( m_bActive && (GetAsyncKeyState( VK_UP )    & 0x8000) == 0x8000 );
0340:     pUserInput->bRotateDown  = ( m_bActive && (GetAsyncKeyState( VK_DOWN )  & 0x8000) == 0x8000 );
0341:     pUserInput->bRotateLeft  = ( m_bActive && (GetAsyncKeyState( VK_LEFT )  & 0x8000) == 0x8000 );
0342:     pUserInput->bRotateRight = ( m_bActive && (GetAsyncKeyState( VK_RIGHT ) & 0x8000) == 0x8000 );
0343: }
0344: 
0345: 
0346: //-------------------------------------------------------------
0347: // Name: Sort()
0348: // Desc: 2次元のソートをする
0349: //-------------------------------------------------------------
0350: BOOL CMyD3DApplication::Sort()
0351: {
0352:     //-------------------------------------------------
0353:     // パラメータの計算
0354:     //-------------------------------------------------
0355:     int step = m_cnt;
0356:     int rank;
0357:     for(rank = 0; rank<step ; rank++){
0358:         step -= rank+1;
0359:     }
0360: 
0361:     float stepno = (float)(1<<(rank+1));
0362:     float offset = (float)(1<<(rank-step));
0363:     float stage  = 2*offset;
0364: 
0365:     if(LOG_SIZE<=rank) return FALSE;// すでにソート済み
0366: 
0367:     //-------------------------------------------------
0368:     // レンダリングターゲットの切り替え
0369:     //-------------------------------------------------
0370:     m_id=1-m_id;
0371:     m_pd3dDevice->SetRenderTarget(0, m_pSortSurf[m_id]);
0372:     m_pd3dDevice->SetDepthStencilSurface(NULL);
0373:     // ビューポートの変更
0374:     D3DVIEWPORT9 viewport = {0,0 // 左上の座標
0375:                     , TEX_WIDTH  // 幅
0376:                     , TEX_HEIGHT // 高さ
0377:                     , 0.0f,1.0f};// 前面、後面
0378:     m_pd3dDevice->SetViewport(&viewport);
0379: 
0380:     if( m_pEffect != NULL ) 
0381:     {
0382:         //-------------------------------------------------
0383:         // シェーダの設定
0384:         //-------------------------------------------------
0385:         m_pEffect->SetTechnique( m_hTechnique );
0386:         m_pEffect->Begin( NULL, 0 );
0387:         m_pEffect->Pass( 0 );
0388: 
0389:         //-------------------------------------------------
0390:         // 描画
0391:         //-------------------------------------------------
0392:         static CONST FLOAT w = TEX_WIDTH;
0393:         static CONST FLOAT h = TEX_HEIGHT;
0394:         static CONST TVERTEX Vertex1[4] = {
0395:             //x  y   z   rhw   tu    tv
0396:             { 0, 0, 0.1f, 1,  0, 0,},
0397:             { w, 0, 0.1f, 1,  1, 0,},
0398:             { w, h, 0.1f, 1,  1, 1,},
0399:             { 0, h, 0.1f, 1,  0, 1,},
0400:         };
0401:         m_pd3dDevice->SetFVF( D3DFVF_XYZRHW | D3DFVF_TEX1);
0402:         m_pEffect->SetTexture( m_htSrcMap,    m_pSortTex [1-m_id]);
0403: 
0404:         m_pEffect->SetFloat(m_hstage,  stage);
0405:         m_pEffect->SetFloat(m_hstepno, stepno);
0406:         m_pEffect->SetFloat(m_hoffset, offset);
0407: 
0408:         m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0409:                         , 2, Vertex1, sizeof( TVERTEX ) );
0410:         
0411:         m_pEffect->End();
0412:     }
0413: 
0414:     return TRUE;
0415: }
0416: //-------------------------------------------------------------
0417: // Name: Render()
0418: // Desc: 画面を描画する.
0419: //-------------------------------------------------------------
0420: int CMyD3DApplication::RenderStateSort()
0421: {
0422:     int ret = 0;
0423:     HRESULT hr;
0424: 
0425:     LPDIRECT3DSURFACE9 pOldBackBuffer, pOldZBuffer;
0426:     D3DVIEWPORT9 oldViewport;
0427: 
0428:     //---------------------------------------------------------
0429:     // ひと休み ひと休み
0430:     //---------------------------------------------------------
0431:     Sleep(50);
0432: 
0433:     //---------------------------------------------------------
0434:     // レンダリングターゲットの保存
0435:     //---------------------------------------------------------
0436:     m_pd3dDevice->GetRenderTarget(0, &pOldBackBuffer);
0437:     m_pd3dDevice->GetDepthStencilSurface(&pOldZBuffer);
0438:     m_pd3dDevice->GetViewport(&oldViewport);
0439: 
0440:     //---------------------------------------------------------
0441:     // 初期化
0442:     //---------------------------------------------------------
0443:     if(0==m_cnt){
0444:         // 種の作成
0445:         if( FAILED(hr = D3DXFillTexture(m_pSeedTex, CreateSeedTex, NULL))) return hr;
0446:         
0447:         // レンダリングターゲットの変更
0448:         m_pd3dDevice->SetRenderTarget(0, m_pSortSurf[m_id]);
0449:         m_pd3dDevice->SetDepthStencilSurface(NULL);
0450:         // ビューポートの変更
0451:         D3DVIEWPORT9 viewport = {0,0 // 左上の座標
0452:                         , TEX_WIDTH   // 幅
0453:                         , TEX_HEIGHT  // 高さ
0454:                         , 0.0f,1.0f};// 前面、後面
0455:         m_pd3dDevice->SetViewport(&viewport);
0456: 
0457:         // テクスチャを張る
0458:         TVERTEX VertexSeed[4] = {
0459:             //   x          y       z rhw tu tv
0460:             {         0,         0, 0, 1, 0, 0,},
0461:             { TEX_WIDTH,         0, 0, 1, 1, 0,},
0462:             { TEX_WIDTH,TEX_HEIGHT, 0, 1, 1, 1,},
0463:             {         0,TEX_HEIGHT, 0, 1, 0, 1,},
0464:         };
0465:         m_pd3dDevice->SetFVF(D3DFVF_XYZRHW| D3DFVF_TEX1);
0466:         m_pd3dDevice->SetTexture( 0, m_pSeedTex );
0467:         m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0468:                         , 2, VertexSeed, sizeof( TVERTEX ) );
0469:     }
0470:     
0471:     //---------------------------------------------------------
0472:     // ソート
0473:     //---------------------------------------------------------
0474:     BOOL bDo;// 実際にソートした?
0475:     bDo = this->Sort();
0476: 
0477:     //-----------------------------------------------------
0478:     // レンダリングターゲットを元に戻す
0479:     //-----------------------------------------------------
0480:     m_pd3dDevice->SetRenderTarget(0, pOldBackBuffer);
0481:     m_pd3dDevice->SetDepthStencilSurface(pOldZBuffer);
0482:     m_pd3dDevice->SetViewport(&oldViewport);
0483: 
0484:     pOldBackBuffer->Release();
0485:     pOldZBuffer->Release();
0486: 
0487:     //-----------------------------------------------------
0488:     // 画面の描画
0489:     //-----------------------------------------------------
0490:     if(bDo){
0491:         // ソート中
0492:         m_pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(50,100,200,0), 0, 0);
0493:     }else{
0494:         // ソート終了!!
0495:         m_pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(255,50,50,0), 0, 0);
0496:     }
0497: 
0498:     float w = (float)this->m_d3dsdBackBuffer.Width -20;
0499:     float h = (float)this->m_d3dsdBackBuffer.Height-20;
0500:     TVERTEX VertexFinal[4] = {
0501:         //  x     y   z rhw tu tv
0502:         { 10+0, 10,  0, 1, 0, 0,},
0503:         { 10+w, 10,  0, 1, 1, 0,},
0504:         { 10+w, 10+h,0, 1, 1, 1,},
0505:         { 10+0, 10+h,0, 1, 0, 1,},
0506:     };
0507:     m_pd3dDevice->SetFVF(D3DFVF_XYZRHW| D3DFVF_TEX1);
0508:     m_pd3dDevice->SetTexture( 0, m_pSortTex[m_id] );
0509:     m_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN
0510:                     , 2, VertexFinal, sizeof( TVERTEX ) );
0511: 
0512:     //-----------------------------------------------------
0513:     // 終了判定
0514:     //-----------------------------------------------------
0515:     int max = LOG_SIZE*(LOG_SIZE+1)/2;// ソートにかかる時間
0516:     if(max+100<=m_cnt+1){ret = -1;}
0517: //  if(max<=m_cnt+1){ret = -1;}// ソート直後に終了するとき
0518: 
0519:     return ret;
0520: }
0521: //-------------------------------------------------------------
0522: // Name: Render()
0523: // Desc: 画面を描画する.
0524: //-------------------------------------------------------------
0525: HRESULT CMyD3DApplication::Render()
0526: {
0527:     //---------------------------------------------------------
0528:     // 描画
0529:     //---------------------------------------------------------
0530:     if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
0531:     {
0532:         switch(m_iState){
0533:         case STATE_INIT:
0534:             m_pd3dDevice->Clear(0L, NULL, D3DCLEAR_TARGET, 0, 0, 0);
0535:             this->SetState(STATE_SORT);
0536:             break;
0537:         case STATE_SORT:
0538:             if(this->RenderStateSort()) this->SetState(STATE_INIT);
0539:             break;
0540:         }
0541: 
0542:         // ヘルプの表示
0543:         if(m_bDispText)RenderText();
0544: 
0545:         // 描画の終了
0546:         m_pd3dDevice->EndScene();
0547:     }
0548: 
0549:     m_cnt++;
0550: 
0551:     return S_OK;
0552: }
0553: 
0554: 
0555: 
0556: 
0557: //-------------------------------------------------------------
0558: // Name: RenderText()
0559: // Desc: 状態やヘルプを画面に表示する
0560: //-------------------------------------------------------------
0561: HRESULT CMyD3DApplication::RenderText()
0562: {
0563:     D3DCOLOR fontColor        = D3DCOLOR_ARGB(255,255,255,0);
0564:     TCHAR szMsg[MAX_PATH] = TEXT("");
0565: 
0566:     FLOAT fNextLine = 40.0f; // 表示する高さ
0567: 
0568:     // 操作法やパラメータを表示する
0569:     fNextLine = (FLOAT) m_d3dsdBackBuffer.Height; 
0570:     lstrcpy( szMsg, TEXT("Press 'F2' to configure display") );
0571:     fNextLine -= 20.0f;
0572:     m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0573: 
0574:     lstrcpy( szMsg, m_strDeviceStats );
0575:     fNextLine -= 20.0f;
0576:     m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0577:     lstrcpy( szMsg, m_strFrameStats );
0578:     fNextLine -= 20.0f;
0579:     m_pFont->DrawText( 2, fNextLine, fontColor, szMsg );
0580:     
0581:     return S_OK;
0582: }
0583: 
0584: 
0585: 
0586: 
0587: //-------------------------------------------------------------
0588: // Name: MsgProc()
0589: // Desc: WndProc をオーバーライドしたもの
0590: //-------------------------------------------------------------
0591: LRESULT CMyD3DApplication::MsgProc( HWND hWnd, UINT msg,
0592:                                  WPARAM wParam, LPARAM lParam )
0593: {
0594:     switch( msg )
0595:     {
0596:         case WM_PAINT:
0597:         {
0598:             if( m_bLoadingApp )
0599:             {
0600:                 // ロード中
0601:                 HDC hDC = GetDC( hWnd );
0602:                 TCHAR strMsg[MAX_PATH];
0603:                 wsprintf(strMsg, TEXT("Loading... Please wait"));
0604:                 RECT rct;
0605:                 GetClientRect( hWnd, &rct );
0606:                 DrawText( hDC, strMsg, -1, &rct
0607:                         , DT_CENTER|DT_VCENTER|DT_SINGLELINE );
0608:                 ReleaseDC( hWnd, hDC );
0609:             }
0610:             break;
0611:         }
0612:         case WM_COMMAND:
0613:             switch( LOWORD(wParam) ){
0614:             case ID_MENUITEM_INFO:
0615:                 // テキストの表示非常時
0616:                 m_bDispText ^= 1;
0617:                 MENUITEMINFO menu; 
0618:                 ZeroMemory(&menu, sizeof(MENUITEMINFO)); 
0619:                 menu.cbSize = sizeof(MENUITEMINFO); 
0620:                 menu.fMask = MIIM_STATE; 
0621:                 if(m_bDispText)menu.fState = MFS_CHECKED; 
0622:                 SetMenuItemInfo(GetMenu(this->m_hWnd), ID_MENUITEM_INFO, FALSE, &menu); 
0623:                 break;
0624:             }
0625: 
0626:     }
0627: 
0628:     return CD3DApplication::MsgProc( hWnd, msg, wParam, lParam );
0629: }
0630: 
0631: 
0632: 
0633: 
0634: //-------------------------------------------------------------
0635: // Name: InvalidateDeviceObjects()
0636: // Desc: RestoreDeviceObjects() で作成したオブジェクトの開放
0637: //-------------------------------------------------------------
0638: HRESULT CMyD3DApplication::InvalidateDeviceObjects()
0639: {
0640:     SAFE_RELEASE(m_pSortSurf[1]);
0641:     SAFE_RELEASE(m_pSortSurf[0]);
0642:     SAFE_RELEASE(m_pSortTex[1]);
0643:     SAFE_RELEASE(m_pSortTex[0]);
0644: 
0645:     SAFE_RELEASE( m_pSeedTex );
0646: 
0647:     // シェーダ
0648:     if( m_pEffect != NULL ) m_pEffect->OnLostDevice();
0649: 
0650:     m_pFont->InvalidateDeviceObjects(); // フォント
0651: 
0652:     return S_OK;
0653: }
0654: 
0655: 
0656: 
0657: 
0658: //-------------------------------------------------------------
0659: // Name: DeleteDeviceObjects()
0660: // Desc: InitDeviceObjects() で作成したオブジェクトを開放する
0661: //-------------------------------------------------------------
0662: HRESULT CMyD3DApplication::DeleteDeviceObjects()
0663: {
0664:     // シェーダ
0665:     SAFE_RELEASE( m_pEffect );
0666:     
0667:     // フォント
0668:     m_pFont->DeleteDeviceObjects();
0669: 
0670:     return S_OK;
0671: }
0672: 
0673: 
0674: 
0675: 
0676: //-------------------------------------------------------------
0677: // Name: FinalCleanup()
0678: // Desc: 終了する直線に呼ばれる
0679: //-------------------------------------------------------------
0680: HRESULT CMyD3DApplication::FinalCleanup()
0681: {
0682:     SAFE_DELETE( m_pFont ); // フォント
0683: 
0684:     return S_OK;
0685: }
0686: 
0687: 
0688: 
0689: 
0690: