0001:
0002:
0003:
0004:
0005:
0006: #ifndef D3DAPP_H
0007: #define D3DAPP_H
0008:
0009:
0010:
0011:
0012: enum APPMSGTYPE { MSG_NONE, MSGERR_APPMUSTEXIT, MSGWARN_SWITCHEDTOREF };
0013:
0014: #define D3DAPPERR_NODIRECT3D 0x82000001
0015: #define D3DAPPERR_NOWINDOW 0x82000002
0016: #define D3DAPPERR_NOCOMPATIBLEDEVICES 0x82000003
0017: #define D3DAPPERR_NOWINDOWABLEDEVICES 0x82000004
0018: #define D3DAPPERR_NOHARDWAREDEVICE 0x82000005
0019: #define D3DAPPERR_HALNOTCOMPATIBLE 0x82000006
0020: #define D3DAPPERR_NOWINDOWEDHAL 0x82000007
0021: #define D3DAPPERR_NODESKTOPHAL 0x82000008
0022: #define D3DAPPERR_NOHALTHISMODE 0x82000009
0023: #define D3DAPPERR_NONZEROREFCOUNT 0x8200000a
0024: #define D3DAPPERR_MEDIANOTFOUND 0x8200000b
0025: #define D3DAPPERR_RESETFAILED 0x8200000c
0026: #define D3DAPPERR_NULLREFDEVICE 0x8200000d
0027:
0028:
0029:
0030:
0031:
0032:
0033:
0034:
0035:
0036:
0037:
0038:
0039:
0040:
0041:
0042:
0043:
0044:
0045: class CD3DApplication
0046: {
0047: protected:
0048: CD3DEnumeration m_d3dEnumeration;
0049: CD3DSettings m_d3dSettings;
0050:
0051:
0052: bool m_bWindowed;
0053: bool m_bActive;
0054: bool m_bDeviceLost;
0055: bool m_bMinimized;
0056: bool m_bMaximized;
0057: bool m_bIgnoreSizeChange;
0058: bool m_bDeviceObjectsInited;
0059: bool m_bDeviceObjectsRestored;
0060:
0061:
0062: bool m_bFrameMoving;
0063: bool m_bSingleStep;
0064:
0065:
0066: HRESULT DisplayErrorMsg( HRESULT hr, DWORD dwType );
0067:
0068:
0069: static bool ConfirmDeviceHelper( D3DCAPS9* pCaps,
0070: VertexProcessingType vertexProcessingType, D3DFORMAT backBufferFormat );
0071: void BuildPresentParamsFromSettings();
0072: bool FindBestWindowedMode( bool bRequireHAL, bool bRequireREF );
0073: bool FindBestFullscreenMode( bool bRequireHAL, bool bRequireREF );
0074: HRESULT ChooseInitialD3DSettings();
0075: HRESULT Initialize3DEnvironment();
0076: HRESULT HandlePossibleSizeChange();
0077: HRESULT Reset3DEnvironment();
0078: HRESULT ToggleFullscreen();
0079: HRESULT ForceWindowed();
0080: HRESULT UserSelectNewDevice();
0081: void Cleanup3DEnvironment();
0082: HRESULT Render3DEnvironment();
0083: virtual HRESULT AdjustWindowForChange();
0084: virtual void UpdateStats();
0085:
0086: protected:
0087:
0088: D3DPRESENT_PARAMETERS m_d3dpp;
0089: HWND m_hWnd;
0090: HWND m_hWndFocus;
0091: HMENU m_hMenu;
0092: LPDIRECT3D9 m_pD3D;
0093: LPDIRECT3DDEVICE9 m_pd3dDevice;
0094: D3DCAPS9 m_d3dCaps;
0095: D3DSURFACE_DESC m_d3dsdBackBuffer;
0096: DWORD m_dwCreateFlags;
0097: DWORD m_dwWindowStyle;
0098: RECT m_rcWindowBounds;
0099: RECT m_rcWindowClient;
0100:
0101:
0102: FLOAT m_fTime;
0103: FLOAT m_fElapsedTime;
0104: FLOAT m_fFPS;
0105: TCHAR m_strDeviceStats[90];
0106: TCHAR m_strFrameStats[90];
0107:
0108:
0109: TCHAR* m_strWindowTitle;
0110: DWORD m_dwCreationWidth;
0111: DWORD m_dwCreationHeight;
0112: bool m_bShowCursorWhenFullscreen;
0113: bool m_bClipCursorWhenFullscreen;
0114: bool m_bStartFullscreen;
0115:
0116:
0117: virtual HRESULT ConfirmDevice(D3DCAPS9*,DWORD,D3DFORMAT) { return S_OK; }
0118: virtual HRESULT OneTimeSceneInit() { return S_OK; }
0119: virtual HRESULT InitDeviceObjects() { return S_OK; }
0120: virtual HRESULT RestoreDeviceObjects() { return S_OK; }
0121: virtual HRESULT FrameMove() { return S_OK; }
0122: virtual HRESULT Render() { return S_OK; }
0123: virtual HRESULT InvalidateDeviceObjects() { return S_OK; }
0124: virtual HRESULT DeleteDeviceObjects() { return S_OK; }
0125: virtual HRESULT FinalCleanup() { return S_OK; }
0126:
0127: public:
0128:
0129: virtual HRESULT Create( HINSTANCE hInstance );
0130: virtual INT Run();
0131: virtual LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
0132: virtual void Pause( bool bPause );
0133: virtual ~CD3DApplication() { }
0134:
0135:
0136: CD3DApplication();
0137: };
0138:
0139:
0140:
0141:
0142: #endif
0143:
0144:
0145:
0146: