0001:
0002:
0003:
0004:
0005:
0006: #ifndef D3DAPP_H
0007: #define D3DAPP_H
0008:
0009:
0010:
0011: #include <basetsd.h>
0012:
0013:
0014:
0015:
0016:
0017: enum APPMSGTYPE { MSG_NONE, MSGERR_APPMUSTEXIT, MSGWARN_SWITCHEDTOREF };
0018:
0019: #define D3DAPPERR_NODIRECT3D 0x82000001
0020: #define D3DAPPERR_NOWINDOW 0x82000002
0021: #define D3DAPPERR_NOCOMPATIBLEDEVICES 0x82000003
0022: #define D3DAPPERR_NOWINDOWABLEDEVICES 0x82000004
0023: #define D3DAPPERR_NOHARDWAREDEVICE 0x82000005
0024: #define D3DAPPERR_HALNOTCOMPATIBLE 0x82000006
0025: #define D3DAPPERR_NOWINDOWEDHAL 0x82000007
0026: #define D3DAPPERR_NODESKTOPHAL 0x82000008
0027: #define D3DAPPERR_NOHALTHISMODE 0x82000009
0028: #define D3DAPPERR_NONZEROREFCOUNT 0x8200000a
0029: #define D3DAPPERR_MEDIANOTFOUND 0x8200000b
0030: #define D3DAPPERR_RESIZEFAILED 0x8200000c
0031: #define D3DAPPERR_NULLREFDEVICE 0x8200000d
0032:
0033:
0034:
0035:
0036:
0037:
0038:
0039:
0040: struct D3DModeInfo
0041: {
0042: DWORD Width;
0043: DWORD Height;
0044: D3DFORMAT Format;
0045: DWORD dwBehavior;
0046: D3DFORMAT DepthStencilFormat;
0047: };
0048:
0049:
0050:
0051:
0052:
0053:
0054:
0055:
0056:
0057: struct D3DDeviceInfo
0058: {
0059:
0060: D3DDEVTYPE DeviceType;
0061: D3DCAPS8 d3dCaps;
0062: const TCHAR* strDesc;
0063: BOOL bCanDoWindowed;
0064:
0065:
0066: DWORD dwNumModes;
0067: D3DModeInfo modes[150];
0068:
0069:
0070: DWORD dwCurrentMode;
0071: BOOL bWindowed;
0072: D3DMULTISAMPLE_TYPE MultiSampleTypeWindowed;
0073: D3DMULTISAMPLE_TYPE MultiSampleTypeFullscreen;
0074: };
0075:
0076:
0077:
0078:
0079:
0080:
0081:
0082:
0083:
0084: struct D3DAdapterInfo
0085: {
0086:
0087: D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier;
0088: D3DDISPLAYMODE d3ddmDesktop;
0089:
0090:
0091: DWORD dwNumDevices;
0092: D3DDeviceInfo devices[5];
0093:
0094:
0095: DWORD dwCurrentDevice;
0096: };
0097:
0098:
0099:
0100:
0101:
0102:
0103:
0104:
0105:
0106:
0107:
0108:
0109:
0110:
0111:
0112:
0113:
0114:
0115: class CD3DApplication
0116: {
0117: protected:
0118:
0119: D3DAdapterInfo m_Adapters[10];
0120: DWORD m_dwNumAdapters;
0121: DWORD m_dwAdapter;
0122: BOOL m_bWindowed;
0123: BOOL m_bActive;
0124: BOOL m_bReady;
0125: BOOL m_bHasFocus;
0126:
0127:
0128: BOOL m_bFrameMoving;
0129: BOOL m_bSingleStep;
0130:
0131:
0132: HRESULT DisplayErrorMsg( HRESULT hr, DWORD dwType );
0133:
0134:
0135: HRESULT BuildDeviceList();
0136: BOOL FindDepthStencilFormat( UINT iAdapter, D3DDEVTYPE DeviceType,
0137: D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat );
0138: HRESULT Initialize3DEnvironment();
0139: HRESULT Resize3DEnvironment();
0140: HRESULT ToggleFullscreen();
0141: HRESULT ForceWindowed();
0142: HRESULT UserSelectNewDevice();
0143: VOID Cleanup3DEnvironment();
0144: HRESULT Render3DEnvironment();
0145: virtual HRESULT AdjustWindowForChange();
0146: static INT_PTR CALLBACK SelectDeviceProc( HWND hDlg, UINT msg,
0147: WPARAM wParam, LPARAM lParam );
0148:
0149: protected:
0150:
0151: D3DPRESENT_PARAMETERS m_d3dpp;
0152: HWND m_hWnd;
0153: HWND m_hWndFocus;
0154: LPDIRECT3D8 m_pD3D;
0155: LPDIRECT3DDEVICE8 m_pd3dDevice;
0156: D3DCAPS8 m_d3dCaps;
0157: D3DSURFACE_DESC m_d3dsdBackBuffer;
0158: DWORD m_dwCreateFlags;
0159: DWORD m_dwWindowStyle;
0160: RECT m_rcWindowBounds;
0161: RECT m_rcWindowClient;
0162:
0163:
0164: FLOAT m_fTime;
0165: FLOAT m_fElapsedTime;
0166: FLOAT m_fFPS;
0167: TCHAR m_strDeviceStats[90];
0168: TCHAR m_strFrameStats[90];
0169:
0170:
0171: TCHAR* m_strWindowTitle;
0172: BOOL m_bUseDepthBuffer;
0173: DWORD m_dwMinDepthBits;
0174: DWORD m_dwMinStencilBits;
0175: DWORD m_dwCreationWidth;
0176: DWORD m_dwCreationHeight;
0177: BOOL m_bShowCursorWhenFullscreen;
0178: BOOL m_bClipCursorWhenFullscreen;
0179:
0180:
0181: virtual HRESULT ConfirmDevice(D3DCAPS8*,DWORD,D3DFORMAT) { return S_OK; }
0182: virtual HRESULT OneTimeSceneInit() { return S_OK; }
0183: virtual HRESULT InitDeviceObjects() { return S_OK; }
0184: virtual HRESULT RestoreDeviceObjects() { return S_OK; }
0185: virtual HRESULT FrameMove() { return S_OK; }
0186: virtual HRESULT Render() { return S_OK; }
0187: virtual HRESULT InvalidateDeviceObjects() { return S_OK; }
0188: virtual HRESULT DeleteDeviceObjects() { return S_OK; }
0189: virtual HRESULT FinalCleanup() { return S_OK; }
0190:
0191: public:
0192:
0193: virtual HRESULT Create( HINSTANCE hInstance );
0194: virtual INT Run();
0195: virtual LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
0196: virtual VOID Pause( BOOL bPause );
0197:
0198:
0199: CD3DApplication();
0200: };
0201:
0202:
0203:
0204:
0205: #endif
0206:
0207:
0208:
0209: