home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / directx / dxf / samples / multimedia / common / include / d3dapp.h next >
Encoding:
C/C++ Source or Header  |  2000-11-04  |  8.6 KB  |  207 lines

  1. //-----------------------------------------------------------------------------
  2. // File: D3DApp.h
  3. //
  4. // Desc: Application class for the Direct3D samples framework library.
  5. //
  6. // Copyright (c) 1998-2000 Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #ifndef D3DAPP_H
  9. #define D3DAPP_H
  10.  
  11. // basetsd.h defines INT_PTR (used below).  It is not included by default
  12. // under VC 5.0.  If you are using VC6 or later, it is included via Windows.h.
  13. #include <basetsd.h> 
  14.  
  15.  
  16. //-----------------------------------------------------------------------------
  17. // Error codes
  18. //-----------------------------------------------------------------------------
  19. enum APPMSGTYPE { MSG_NONE, MSGERR_APPMUSTEXIT, MSGWARN_SWITCHEDTOREF };
  20.  
  21. #define D3DAPPERR_NODIRECT3D          0x82000001
  22. #define D3DAPPERR_NOWINDOW            0x82000002
  23. #define D3DAPPERR_NOCOMPATIBLEDEVICES 0x82000003
  24. #define D3DAPPERR_NOWINDOWABLEDEVICES 0x82000004
  25. #define D3DAPPERR_NOHARDWAREDEVICE    0x82000005
  26. #define D3DAPPERR_HALNOTCOMPATIBLE    0x82000006
  27. #define D3DAPPERR_NOWINDOWEDHAL       0x82000007
  28. #define D3DAPPERR_NODESKTOPHAL        0x82000008
  29. #define D3DAPPERR_NOHALTHISMODE       0x82000009
  30. #define D3DAPPERR_NONZEROREFCOUNT     0x8200000a
  31. #define D3DAPPERR_MEDIANOTFOUND       0x8200000b
  32. #define D3DAPPERR_RESIZEFAILED        0x8200000c
  33.  
  34.  
  35.  
  36.  
  37. //-----------------------------------------------------------------------------
  38. // Name: struct D3DModeInfo
  39. // Desc: Structure for holding information about a display mode
  40. //-----------------------------------------------------------------------------
  41. struct D3DModeInfo
  42. {
  43.     DWORD      Width;      // Screen width in this mode
  44.     DWORD      Height;     // Screen height in this mode
  45.     D3DFORMAT  Format;     // Pixel format in this mode
  46.     DWORD      dwBehavior; // Hardware / Software / Mixed vertex processing
  47.     D3DFORMAT  DepthStencilFormat; // Which depth/stencil format to use with this mode
  48. };
  49.  
  50.  
  51.  
  52.  
  53. //-----------------------------------------------------------------------------
  54. // Name: struct D3DDeviceInfo
  55. // Desc: Structure for holding information about a Direct3D device, including
  56. //       a list of modes compatible with this device
  57. //-----------------------------------------------------------------------------
  58. struct D3DDeviceInfo
  59. {
  60.     // Device data
  61.     D3DDEVTYPE   DeviceType;      // Reference, HAL, etc.
  62.     D3DCAPS8     d3dCaps;         // Capabilities of this device
  63.     const TCHAR* strDesc;         // Name of this device
  64.     BOOL         bCanDoWindowed;  // Whether this device can work in windowed mode
  65.  
  66.     // Modes for this device
  67.     DWORD        dwNumModes;
  68.     D3DModeInfo  modes[150];
  69.  
  70.     // Current state
  71.     DWORD        dwCurrentMode;
  72.     BOOL         bWindowed;
  73.     D3DMULTISAMPLE_TYPE MultiSampleType;
  74. };
  75.  
  76.  
  77.  
  78.  
  79. //-----------------------------------------------------------------------------
  80. // Name: struct D3DAdapterInfo
  81. // Desc: Structure for holding information about an adapter, including a list
  82. //       of devices available on this adapter
  83. //-----------------------------------------------------------------------------
  84. struct D3DAdapterInfo
  85. {
  86.     // Adapter data
  87.     D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier;
  88.     D3DDISPLAYMODE d3ddmDesktop;      // Desktop display mode for this adapter
  89.  
  90.     // Devices for this adapter
  91.     DWORD          dwNumDevices;
  92.     D3DDeviceInfo  devices[5];
  93.  
  94.     // Current state
  95.     DWORD          dwCurrentDevice;
  96. };
  97.  
  98.  
  99.  
  100.  
  101. //-----------------------------------------------------------------------------
  102. // Name: class CD3DApplication
  103. // Desc: A base class for creating sample D3D8 applications. To create a simple
  104. //       Direct3D application, simply derive this class into a class (such as
  105. //       class CMyD3DApplication) and override the following functions, as 
  106. //       needed:
  107. //          OneTimeSceneInit()    - To initialize app data (alloc mem, etc.)
  108. //          InitDeviceObjects()   - To initialize the 3D scene objects
  109. //          FrameMove()           - To animate the scene
  110. //          Render()              - To render the scene
  111. //          DeleteDeviceObjects() - To cleanup the 3D scene objects
  112. //          FinalCleanup()        - To cleanup app data (for exitting the app)
  113. //          MsgProc()             - To handle Windows messages
  114. //-----------------------------------------------------------------------------
  115. class CD3DApplication
  116. {
  117. protected:
  118.     // Internal variables for the state of the app
  119.     D3DAdapterInfo    m_Adapters[10];
  120.     DWORD             m_dwNumAdapters;
  121.     DWORD             m_dwAdapter;
  122.     BOOL              m_bWindowed;
  123.     BOOL              m_bActive;
  124.     BOOL              m_bReady;
  125.  
  126.     // Internal variables used for timing
  127.     BOOL              m_bFrameMoving;
  128.     BOOL              m_bSingleStep;
  129.  
  130.     // Internal error handling function
  131.     HRESULT DisplayErrorMsg( HRESULT hr, DWORD dwType );
  132.  
  133.     // Internal functions to manage and render the 3D scene
  134.     HRESULT BuildDeviceList();
  135.     BOOL    FindDepthStencilFormat( UINT iAdapter, D3DDEVTYPE DeviceType,
  136.                 D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat );
  137.     HRESULT Initialize3DEnvironment();
  138.     HRESULT Resize3DEnvironment();
  139.     HRESULT ToggleFullscreen();
  140.     HRESULT ForceWindowed();
  141.     HRESULT UserSelectNewDevice();
  142.     VOID    Cleanup3DEnvironment();
  143.     HRESULT Render3DEnvironment();
  144.     virtual HRESULT AdjustWindowForChange();
  145.     static INT_PTR CALLBACK SelectDeviceProc( HWND hDlg, UINT msg, 
  146.                 WPARAM wParam, LPARAM lParam );
  147.  
  148. protected:
  149.     // Main objects used for creating and rendering the 3D scene
  150.     D3DPRESENT_PARAMETERS m_d3dpp;         // Parameters for CreateDevice/Reset
  151.     HWND              m_hWnd;              // The main app window
  152.     HWND              m_hWndFocus;         // The D3D focus window (usually same as m_hWnd)
  153.     LPDIRECT3D8       m_pD3D;              // The main D3D object
  154.     LPDIRECT3DDEVICE8 m_pd3dDevice;        // The D3D rendering device
  155.     D3DCAPS8          m_d3dCaps;           // Caps for the device
  156.     D3DSURFACE_DESC   m_d3dsdBackBuffer;   // Surface desc of the backbuffer
  157.     DWORD             m_dwCreateFlags;     // Indicate sw or hw vertex processing
  158.     DWORD             m_dwWindowStyle;     // Saved window style for mode switches
  159.     RECT              m_rcWindowBounds;    // Saved window bounds for mode switches
  160.     RECT              m_rcWindowClient;    // Saved client area size for mode switches
  161.  
  162.     // Variables for timing
  163.     FLOAT             m_fTime;             // Current time in seconds
  164.     FLOAT             m_fElapsedTime;      // Time elapsed since last frame
  165.     FLOAT             m_fFPS;              // Instanteous frame rate
  166.     TCHAR             m_strDeviceStats[90];// String to hold D3D device stats
  167.     TCHAR             m_strFrameStats[40]; // String to hold frame stats
  168.  
  169.     // Overridable variables for the app
  170.     TCHAR*            m_strWindowTitle;    // Title for the app's window
  171.     BOOL              m_bUseDepthBuffer;   // Whether to autocreate depthbuffer
  172.     DWORD             m_dwMinDepthBits;    // Minimum number of bits needed in depth buffer
  173.     DWORD             m_dwMinStencilBits;  // Minimum number of bits needed in stencil buffer
  174.     DWORD             m_dwCreationWidth;   // Width used to create window
  175.     DWORD             m_dwCreationHeight;  // Height used to create window
  176.     BOOL              m_bShowCursorWhenFullscreen; // Whether to show cursor when fullscreen
  177.  
  178.     // Overridable functions for the 3D scene created by the app
  179.     virtual HRESULT ConfirmDevice(D3DCAPS8*,DWORD,D3DFORMAT)   { return S_OK; }
  180.     virtual HRESULT OneTimeSceneInit()                         { return S_OK; }
  181.     virtual HRESULT InitDeviceObjects()                        { return S_OK; }
  182.     virtual HRESULT RestoreDeviceObjects()                     { return S_OK; }
  183.     virtual HRESULT FrameMove()                                { return S_OK; }
  184.     virtual HRESULT Render()                                   { return S_OK; }
  185.     virtual HRESULT InvalidateDeviceObjects()                  { return S_OK; }
  186.     virtual HRESULT DeleteDeviceObjects()                      { return S_OK; }
  187.     virtual HRESULT FinalCleanup()                             { return S_OK; }
  188.  
  189. public:
  190.     // Functions to create, run, pause, and clean up the application
  191.     virtual HRESULT Create( HINSTANCE hInstance );
  192.     virtual INT     Run();
  193.     virtual LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  194.     virtual VOID    Pause( BOOL bPause );
  195.  
  196.     // Internal constructor
  197.     CD3DApplication();
  198. };
  199.  
  200.  
  201.  
  202.  
  203. #endif
  204.  
  205.  
  206.  
  207.