DXUT.h
上传用户:junlon
上传日期:2022-01-05
资源大小:39075k
文件大小:12k
源码类别:

DirextX编程

开发平台:

Visual C++

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