DDDevice.h
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:6k
源码类别:

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1998-1999 DXGuide.  All Rights Reserved.
  2. // File: DDDevice.h
  3. #ifndef _DDDEVICE__H
  4. #define _DDDEVICE__H
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. #include <ddraw.h>
  9. // turn off warnings for /W4
  10. #pragma warning(disable: 4201)
  11. #include <d3d.h>
  12. #pragma warning(default: 4201)
  13. #include "DDModeInfoObject.h"
  14. #include "D3DDeviceInfoObject.h"
  15. #include "DXDriverInfoObject.h" // base class define
  16. #include <afxtempl.h>
  17. class CDDSurface;
  18. class CDDPalette;
  19. class CPackFileManager;
  20. class CDDDevice : public  CDXDriverInfoObject
  21. {
  22. friend class CDirectDraw;
  23. friend class CDDSurface;
  24. friend class CDDPalette;
  25. public:
  26. // Flags for DDInit
  27. enum DDInitFlag
  28. {
  29. DDIF_ENABLED = 0x00000001L,
  30. DDIF_WINDOWED = 0x00000002L,
  31. DDIF_NO_FLIP = 0x00000004L,
  32. DDIF_NO_BACKBUFFER = 0x00000008L, // Don't create and use a backbuffer
  33. DDIF_BACKBUFFERINSYSTEMMEMORY = 0x00000010L, // create backbuffer in system memory
  34. DDIF_TRIPLEBUFFER = 0x00000020L, // using triple buffering
  35. DDIF_3D = 0x00000100L,
  36. DDIF_MULTIMON = 0x00000200L,
  37. DDIF_SETDEVICEWND = 0x00000400L,
  38. D3DIF_NO_FPUSETUP = 0x00010000L, // Don't use default DDSCL_FPUSETUP flag
  39. D3DIF_ZBUFFER = 0x00020000L, // Create and use a zbuffer
  40. D3DIF_STENCILBUFFER = 0x00040000L, // Use a z-buffer w/stenciling
  41. };
  42. protected:
  43. CDDDevice(void);
  44. virtual ~CDDDevice();
  45. protected:
  46. virtual bool Create(HWND  hWnd, DWORD  dwFlags);
  47. public:
  48. // inline functions.
  49. DWORD GetWidth(void) const;
  50. DWORD GetHeight(void) const;
  51. DWORD GetBPP(void) const;
  52. CDDSurface* GetFront(void) const;
  53. CDDSurface* GetBack(void) const;
  54. CDDSurface* GetRenderSurface(void) const;
  55. CDDPalette* GetPalette(void) const;
  56. // Does this driver have 3D hardware capabilites?
  57. bool IsSupport3D(void) const;
  58. bool IsSupportGDI(void) const;
  59. bool IsCanRenderWindowed(void) const;
  60. bool IsCanFlipNoVsync(void) const;
  61. void SetCaps(const DDCAPS*  pDDCapsHAL, const DDCAPS*  pDDCapsHEL);
  62. DDCAPS* GetCaps(void) const;
  63. bool SelectD3DDevice(int  nPos);
  64. protected:
  65. void SetEnabled(void);
  66. protected:
  67. DDCAPS* m_pDDCapsHAL;
  68. DDCAPS* m_pDDCapsHEL;
  69. protected:
  70. // DDraw interface pointers
  71. LPDIRECTDRAW7 m_lpDD;
  72. // descriptive data structures
  73. HMONITOR m_hMonitor;
  74. MONITORINFOEX m_MonitorInfo;
  75. LPRECT m_lpMonitorRect;
  76. DWORD m_dwWidth; // Dimensions of the render target
  77. DWORD m_dwHeight;
  78. protected:
  79. DWORD m_dwDDInitFlags;
  80. HWND m_hWnd;
  81. CDDSurface* m_pDDSFront; // The primary surface
  82. CDDSurface* m_pDDSBack; // The backbuffer surface
  83. CDDSurface* m_pDDSRenderTarget; // The render target surface
  84. CDDPalette* m_pPalette;
  85. LPDIRECTDRAWCLIPPER m_lpClipper;
  86. DWORD m_dwBPP; // Bit depth of the current display mode
  87. int m_nMonitorNo;
  88. RECT m_rcScreenRect; // Screen rect for window
  89. RECT m_rcViewportRect; // Offscreen rect for VPort
  90. protected:
  91. bool CreateDirectDrawInterface(GUID FAR*  lpGuid);
  92. public:
  93. void Move(int  x, int  y);
  94. // Functions for managing viewport bounds
  95. const RECT* GetViewportRect(void) const;
  96. const RECT* GetScreenRect(void) const;
  97. public:
  98. bool LoadPalette(LPCTSTR  lpszFileName,
  99. CPackFileManager*  pPackFileManager = NULL,
  100. bool  bFromDIB = true);
  101. HRESULT Flip(void);
  102. public:
  103. HRESULT SetCooperativeLevel(HWND  hWnd, DWORD  dwFlags);
  104. HRESULT TestCooperativeLevel(void);
  105. DWORD GetMonitorFrequency(void) const;
  106. DWORD GetScanLine(void) const;
  107. bool GetVerticalBlankStatus(void) const;
  108. HRESULT WaitForVerticalBlank(DWORD  dwFlags) const;
  109. HRESULT GetAvailableVidMem(DWORD  dwCaps, DWORD&  dwTotal,
  110. DWORD&  dwFree) const;
  111. DWORD GetGDIMem(void) const;
  112. HRESULT RestoreDisplayMode(void);
  113. HRESULT SetDisplayMode(DWORD  dwWidth, DWORD  dwHeight, DWORD  dwBPP,
  114. DWORD  dwRefreshRate, DWORD  dwFlags);
  115. HRESULT GetDisplayMode(LPDDSURFACEDESC2  lpDDSurfaceDesc);
  116. HRESULT FlipToGDISurface(void);
  117. HRESULT GetDeviceIdentifier(
  118. LPDDDEVICEIDENTIFIER2  lpdddi, DWORD  dwFlags) const;
  119. protected:
  120. HRESULT CreatePalette(DWORD  dwFlags,
  121. LPPALETTEENTRY  lpDDColorArray,
  122. LPDIRECTDRAWPALETTE FAR*  lplpDDPalette);
  123. HRESULT CreateSurface(
  124. LPDDSURFACEDESC2  lpDDSurfaceDesc2,
  125. LPDIRECTDRAWSURFACE7 FAR*  lplpDDSurface);
  126. public:
  127. bool LoadD3DDeviceInfos(LPDIRECT3D7  lpD3D);
  128. CD3DDeviceInfoObject* GetSelectedD3DDeviceInfoObject(void) const;
  129. bool SelectD3DDevice(const _GUID* const  lpGuid);
  130. bool SelectDefaultD3DDevice(void);
  131. int GetD3DDeviceNumber(void) const;
  132. protected:
  133. void AddD3DDeviceInfo(
  134. LPSTR  lpDeviceDescription,
  135. LPSTR  lpDeviceName,
  136. LPD3DDEVICEDESC7  lpD3DDesc);
  137. static HRESULT CALLBACK D3DEnumDevicesCallback7(
  138. LPSTR  lpDeviceDescription,
  139. LPSTR  lpDeviceName,
  140. LPD3DDEVICEDESC7  lpD3DDeviceDesc,
  141. LPVOID  lpContext);
  142. protected:
  143. CTypedPtrArray<CObArray, CD3DDeviceInfoObject*> m_d3dDeviceInfoArray;
  144. int m_nSelectedD3DDeviceInfoPos;
  145. public:
  146. bool IsEnabled(void) const;
  147. bool LoadDisplayModeInfos(void);
  148. protected:
  149. CDDModeInfoObject* GetSelectedModeInfoObject(void) const;
  150. public:
  151. bool SelectDisplayMode(int  nPos);
  152. bool SelectDisplayMode(bool  bFullScreen,
  153. DWORD  dwWidth, DWORD  dwHeight, DWORD  dwBPP);
  154. bool SelectDisplayMode(const DDSURFACEDESC2*  pDDSD);
  155. int GetModeNumber(void) const;
  156. protected:
  157. static HRESULT WINAPI EnumModesCallback2(
  158. LPDDSURFACEDESC2  lpDDSurfaceDesc, LPVOID  lpContext);
  159. void AddModeInfo(const DDSURFACEDESC2*  pDDSD);
  160. protected:
  161. CTypedPtrArray<CObArray, CDDModeInfoObject*> m_ddDisplayModeInfoArray;
  162. int m_nSelectedDisplayModeInfoPos;
  163. };
  164. #include "DDDevice.inl"
  165. #endif // _DDDEVICE__H