1 //-------------------------------------------------------------------------------------- 2 // File: DXUT.h 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 //-------------------------------------------------------------------------------------- 6 #pragma once 7 #ifndef DXUT_H 8 #define DXUT_H 9 10 #ifndef UNICODE 11 #error "DXUT requires a Unicode build. See the nearby comments for details" 12 // 13 // If you are using Microsoft Visual C++ .NET, under the General tab of the project 14 // properties change the Character Set to 'Use Unicode Character Set'. 15 // 16 // Windows XP and later are native Unicode so Unicode applications will perform better. 17 // For Windows 98 and Windows Me support, consider using the Microsoft Layer for Unicode (MSLU). 18 // 19 // To use MSLU, link against a set of libraries similar to this 20 // /nod:kernel32.lib /nod:advapi32.lib /nod:user32.lib /nod:gdi32.lib /nod:shell32.lib /nod:comdlg32.lib /nod:version.lib /nod:mpr.lib /nod:rasapi32.lib /nod:winmm.lib /nod:winspool.lib /nod:vfw32.lib /nod:secur32.lib /nod:oleacc.lib /nod:oledlg.lib /nod:sensapi.lib UnicoWS.lib kernel32.lib advapi32.lib user32.lib gdi32.lib shell32.lib comdlg32.lib version.lib mpr.lib rasapi32.lib winmm.lib winspool.lib vfw32.lib secur32.lib oleacc.lib oledlg.lib sensapi.lib dxerr.lib dxguid.lib d3dx9d.lib d3d9.lib comctl32.lib 21 // and put the unicows.dll (available for download from msdn.microsoft.com) in the exe's folder. 22 // 23 // For more details see the MSDN article titled: 24 // "MSLU: Develop Unicode Applications for Windows 9x Platforms with the Microsoft Layer for Unicode" 25 // at http://msdn.microsoft.com/msdnmag/issues/01/10/MSLU/default.aspx 26 // 27 #endif 28 29 //-------------------------------------------------------------------------------------- 30 // Structs 31 //-------------------------------------------------------------------------------------- 32 class CD3DEnumeration; 33 34 struct DXUTDeviceSettings 35 { 36 UINT AdapterOrdinal; 37 D3DDEVTYPE DeviceType; 38 D3DFORMAT AdapterFormat; 39 DWORD BehaviorFlags; 40 D3DPRESENT_PARAMETERS pp; 41 }; 42 43 44 //-------------------------------------------------------------------------------------- 45 // Error codes 46 //-------------------------------------------------------------------------------------- 47 #define DXUTERR_NODIRECT3D MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0901) 48 #define DXUTERR_NOCOMPATIBLEDEVICES MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0902) 49 #define DXUTERR_MEDIANOTFOUND MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0903) 50 #define DXUTERR_NONZEROREFCOUNT MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0904) 51 #define DXUTERR_CREATINGDEVICE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0905) 52 #define DXUTERR_RESETTINGDEVICE MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0906) 53 #define DXUTERR_CREATINGDEVICEOBJECTS MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0907) 54 #define DXUTERR_RESETTINGDEVICEOBJECTS MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0908) 55 #define DXUTERR_INCORRECTVERSION MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0909) 56 57 58 //-------------------------------------------------------------------------------------- 59 // Callback registration 60 //-------------------------------------------------------------------------------------- 61 typedef bool (CALLBACK *LPDXUTCALLBACKISDEVICEACCEPTABLE)( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat, bool bWindowed, void* pUserContext ); 62 typedef bool (CALLBACK *LPDXUTCALLBACKMODIFYDEVICESETTINGS)( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext ); 63 typedef HRESULT (CALLBACK *LPDXUTCALLBACKDEVICECREATED)( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ); 64 typedef HRESULT (CALLBACK *LPDXUTCALLBACKDEVICERESET)( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ); 65 typedef void (CALLBACK *LPDXUTCALLBACKDEVICEDESTROYED)( void* pUserContext ); 66 typedef void (CALLBACK *LPDXUTCALLBACKDEVICELOST)( void* pUserContext ); 67 typedef void (CALLBACK *LPDXUTCALLBACKFRAMEMOVE)( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ); 68 typedef void (CALLBACK *LPDXUTCALLBACKFRAMERENDER)( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ); 69 typedef void (CALLBACK *LPDXUTCALLBACKKEYBOARD)( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext ); 70 typedef void (CALLBACK *LPDXUTCALLBACKMOUSE)( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext ); 71 typedef LRESULT (CALLBACK *LPDXUTCALLBACKMSGPROC)( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext ); 72 typedef void (CALLBACK *LPDXUTCALLBACKTIMER)( UINT idEvent, void* pUserContext ); 73 74 // Device callbacks 75 void DXUTSetCallbackDeviceCreated( LPDXUTCALLBACKDEVICECREATED pCallbackDeviceCreated, void* pUserContext = NULL ); 76 void DXUTSetCallbackDeviceReset( LPDXUTCALLBACKDEVICERESET pCallbackDeviceReset, void* pUserContext = NULL ); 77 void DXUTSetCallbackDeviceLost( LPDXUTCALLBACKDEVICELOST pCallbackDeviceLost, void* pUserContext = NULL ); 78 void DXUTSetCallbackDeviceDestroyed( LPDXUTCALLBACKDEVICEDESTROYED pCallbackDeviceDestroyed, void* pUserContext = NULL ); 79 void DXUTSetCallbackDeviceChanging( LPDXUTCALLBACKMODIFYDEVICESETTINGS pCallbackModifyDeviceSettings, void* pUserContext = NULL ); 80 81 // Frame callbacks 82 void DXUTSetCallbackFrameMove( LPDXUTCALLBACKFRAMEMOVE pCallbackFrameMove, void* pUserContext = NULL ); 83 void DXUTSetCallbackFrameRender( LPDXUTCALLBACKFRAMERENDER pCallbackFrameRender, void* pUserContext = NULL ); 84 85 // Message callbacks 86 void DXUTSetCallbackKeyboard( LPDXUTCALLBACKKEYBOARD pCallbackKeyboard, void* pUserContext = NULL ); 87 void DXUTSetCallbackMouse( LPDXUTCALLBACKMOUSE pCallbackMouse, bool bIncludeMouseMove = false, void* pUserContext = NULL ); 88 void DXUTSetCallbackMsgProc( LPDXUTCALLBACKMSGPROC pCallbackMsgProc, void* pUserContext = NULL ); 89 90 91 //-------------------------------------------------------------------------------------- 92 // Initialization 93 //-------------------------------------------------------------------------------------- 94 HRESULT DXUTInit( bool bParseCommandLine = true, bool bHandleDefaultHotkeys = true, bool bShowMsgBoxOnError = true, bool bHandleAltEnter = true ); 95 96 // Choose either DXUTCreateWindow or DXUTSetWindow. If using DXUTSetWindow, consider using DXUTStaticWndProc 97 HRESULT DXUTCreateWindow( const WCHAR* strWindowTitle = L"Direct3D Window", 98 HINSTANCE hInstance = NULL, HICON hIcon = NULL, HMENU hMenu = NULL, 99 int x = CW_USEDEFAULT, int y = CW_USEDEFAULT ); 100 HRESULT DXUTSetWindow( HWND hWndFocus, HWND hWndDeviceFullScreen, HWND hWndDeviceWindowed, bool bHandleMessages = true ); 101 LRESULT CALLBACK DXUTStaticWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); 102 103 // Choose either DXUTCreateDevice or DXUTSetDevice or DXUTCreateDeviceFromSettings 104 HRESULT DXUTCreateDevice( UINT AdapterOrdinal = D3DADAPTER_DEFAULT, bool bWindowed = true, 105 int nSuggestedWidth = 0, int nSuggestedHeight = 0, 106 LPDXUTCALLBACKISDEVICEACCEPTABLE pCallbackIsDeviceAcceptable = NULL, 107 LPDXUTCALLBACKMODIFYDEVICESETTINGS pCallbackModifyDeviceSettings = NULL, 108 void* pUserContext = NULL ); 109 HRESULT DXUTCreateDeviceFromSettings( DXUTDeviceSettings* pDeviceSettings, bool bPreserveInput = false, bool bClipWindowToSingleAdapter = true ); 110 HRESULT DXUTSetDevice( IDirect3DDevice9* pd3dDevice ); 111 112 // Choose either DXUTMainLoop or implement your own main loop 113 HRESULT DXUTMainLoop( HACCEL hAccel = NULL ); 114 115 // If not using DXUTMainLoop consider using DXUTRender3DEnvironment 116 void DXUTRender3DEnvironment(); 117 118 119 //-------------------------------------------------------------------------------------- 120 // Finding valid device settings 121 //-------------------------------------------------------------------------------------- 122 enum DXUT_MATCH_TYPE 123 { 124 DXUTMT_IGNORE_INPUT = 0, // Use the closest valid value to a default 125 DXUTMT_PRESERVE_INPUT, // Use input without change, but may cause no valid device to be found 126 DXUTMT_CLOSEST_TO_INPUT // Use the closest valid value to the input 127 }; 128 129 struct DXUTMatchOptions 130 { 131 DXUT_MATCH_TYPE eAdapterOrdinal; 132 DXUT_MATCH_TYPE eDeviceType; 133 DXUT_MATCH_TYPE eWindowed; 134 DXUT_MATCH_TYPE eAdapterFormat; 135 DXUT_MATCH_TYPE eVertexProcessing; 136 DXUT_MATCH_TYPE eResolution; 137 DXUT_MATCH_TYPE eBackBufferFormat; 138 DXUT_MATCH_TYPE eBackBufferCount; 139 DXUT_MATCH_TYPE eMultiSample; 140 DXUT_MATCH_TYPE eSwapEffect; 141 DXUT_MATCH_TYPE eDepthFormat; 142 DXUT_MATCH_TYPE eStencilFormat; 143 DXUT_MATCH_TYPE ePresentFlags; 144 DXUT_MATCH_TYPE eRefreshRate; 145 DXUT_MATCH_TYPE ePresentInterval; 146 }; 147 148 HRESULT DXUTFindValidDeviceSettings( DXUTDeviceSettings* pOut, DXUTDeviceSettings* pIn = NULL, DXUTMatchOptions* pMatchOptions = NULL ); 149 150 151 //-------------------------------------------------------------------------------------- 152 // Common Tasks 153 //-------------------------------------------------------------------------------------- 154 void DXUTSetCursorSettings( bool bShowCursorWhenFullScreen, bool bClipCursorWhenFullScreen ); 155 void DXUTSetMultimonSettings( bool bAutoChangeAdapter ); 156 void DXUTSetShortcutKeySettings( bool bAllowWhenFullscreen = false, bool bAllowWhenWindowed = true ); // Controls the Windows key, and accessibility shortcut keys 157 void DXUTSetWindowSettings( bool bCallDefWindowProc = true ); 158 void DXUTSetConstantFrameTime( bool bConstantFrameTime, float fTimePerFrame = 0.0333f ); 159 HRESULT DXUTSetTimer( LPDXUTCALLBACKTIMER pCallbackTimer, float fTimeoutInSecs = 1.0f, UINT* pnIDEvent = NULL, void* pCallbackUserContext = NULL ); 160 HRESULT DXUTKillTimer( UINT nIDEvent ); 161 HRESULT DXUTToggleFullScreen(); 162 HRESULT DXUTToggleREF(); 163 void DXUTPause( bool bPauseTime, bool bPauseRendering ); 164 void DXUTResetFrameworkState(); 165 void DXUTShutdown( int nExitCode = 0 ); 166 167 168 //-------------------------------------------------------------------------------------- 169 // State Retrieval 170 //-------------------------------------------------------------------------------------- 171 IDirect3D9* DXUTGetD3DObject(); // Does not addref unlike typical Get* APIs 172 IDirect3DDevice9* DXUTGetD3DDevice(); // Does not addref unlike typical Get* APIs 173 DXUTDeviceSettings DXUTGetDeviceSettings(); 174 D3DPRESENT_PARAMETERS DXUTGetPresentParameters(); 175 const D3DSURFACE_DESC* DXUTGetBackBufferSurfaceDesc(); 176 const D3DCAPS9* DXUTGetDeviceCaps(); 177 HINSTANCE DXUTGetHINSTANCE(); 178 HWND DXUTGetHWND(); 179 HWND DXUTGetHWNDFocus(); 180 HWND DXUTGetHWNDDeviceFullScreen(); 181 HWND DXUTGetHWNDDeviceWindowed(); 182 RECT DXUTGetWindowClientRect(); 183 RECT DXUTGetWindowClientRectAtModeChange(); // Useful for returning to windowed mode with the same resolution as before toggle to full screen mode 184 RECT DXUTGetFullsceenClientRectAtModeChange(); // Useful for returning to full screen mode with the same resolution as before toggle to windowed mode 185 double DXUTGetTime(); 186 float DXUTGetElapsedTime(); 187 bool DXUTIsWindowed(); 188 float DXUTGetFPS(); 189 LPCWSTR DXUTGetWindowTitle(); 190 LPCWSTR DXUTGetFrameStats( bool bIncludeFPS = false ); 191 LPCWSTR DXUTGetDeviceStats(); 192 bool DXUTIsRenderingPaused(); 193 bool DXUTIsTimePaused(); 194 bool DXUTIsActive(); 195 int DXUTGetExitCode(); 196 bool DXUTGetShowMsgBoxOnError(); 197 bool DXUTGetHandleDefaultHotkeys(); 198 bool DXUTIsKeyDown( BYTE vKey ); // Pass a virtual-key code, ex. VK_F1, 'A', VK_RETURN, VK_LSHIFT, etc 199 bool DXUTIsMouseButtonDown( BYTE vButton ); // Pass a virtual-key code: VK_LBUTTON, VK_RBUTTON, VK_MBUTTON, VK_XBUTTON1, VK_XBUTTON2 200 bool DXUTGetAutomation(); // Returns true if -automation parameter is used to launch the app 201 202 #endif 203 204 205 206 207