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

DirextX编程

开发平台:

Visual C++

  1. // Copyright (C) 1998-1999 DXGuide.  All Rights Reserved.
  2. // File: D3DDevice.h
  3. #ifndef _D3DDEVICE__H
  4. #define _D3DDEVICE__H
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. #include "DDDevice.h"
  9. enum D3D_ML_COLORFLAGS
  10. {
  11. D3D_ML_AMBIENT = 0x00000001L,
  12. D3D_ML_DIFFUSE = 0x00000002L,
  13. D3D_ML_SPECULAR = 0x00000004L,
  14. D3D_M_EMISSIVE = 0x00000008L,
  15. };
  16. // Maintains the D3D surfaces, device, and viewport used for 3D rendering.
  17. class CD3DDevice : public CDDDevice
  18. {
  19. friend class CD3DLight; // for m_dwLightsNumber
  20. friend class CD3DMaterial;
  21. friend class CD3DVertexBuffer;
  22. friend class CDirectDraw;
  23. protected:
  24. CD3DDevice(void);
  25. virtual ~CD3DDevice();
  26. public:
  27. virtual bool Create(HWND  hWnd, DWORD  dwFlags);
  28. protected:
  29. bool CreateDirect3DInterface(DWORD  dwFlags);
  30. bool CreateZBuffer(void);
  31. bool CreateD3DDevice(const GUID* const  pDeviceGUID,
  32. CDDSurface*  pDDSRenderTarget);
  33. public: // Information
  34. LPDIRECT3D7 GetDirect3D(void) const;
  35. CD3DMaterial* GetD3DMaterial(void) const;
  36. HRESULT GetCaps(LPD3DDEVICEDESC7  lpD3DDevDesc);
  37. HRESULT GetInfo(DWORD  dwDevInfoID,
  38. LPVOID  pDevInfoStruct, DWORD  dwSize);
  39. D3DDEVICEDESC7 const* GetD3DDeviceDesc(void) const;
  40. D3DPRIMCAPS const* GetTriCaps(void) const;
  41. D3DPRIMCAPS const* GetLineCaps(void) const;
  42. D3DDEVICETYPE GetDeviceType(void) const;
  43. bool IsSupportMipmaps(void) const;
  44. bool IsSupportWBuffer(void) const;
  45. bool IsSupportDirectionalLights(void) const;
  46. bool IsSupportPositionalLights(void) const;
  47. public: // Device states
  48. HRESULT ApplyStateBlock(DWORD  dwBlockHandle);
  49. HRESULT BeginStateBlock(void);
  50. HRESULT EndStateBlock(LPDWORD  lpdwBlockHandle);
  51. HRESULT CaptureStateBlock(DWORD  dwBlockHandle);
  52. HRESULT CreateStateBlock(D3DSTATEBLOCKTYPE  d3dsbType,
  53. LPDWORD  lpdwBlockHandle);
  54. HRESULT DeleteStateBlock(DWORD  dwBlockHandle);
  55. HRESULT GetClipStatus(LPD3DCLIPSTATUS  lpD3DClipStatus);
  56. HRESULT SetClipStatus(LPD3DCLIPSTATUS  lpD3DClipStatus);
  57. HRESULT GetRenderState(D3DRENDERSTATETYPE  dwRenderStateType,
  58. LPDWORD  lpdwRenderState);
  59. HRESULT SetRenderState(D3DRENDERSTATETYPE  dwRenderStateType,
  60. DWORD  dwRenderState);
  61. HRESULT GetRenderTarget(LPDIRECTDRAWSURFACE7*  lplpRenderTarget);
  62. HRESULT SetRenderTarget(CDDSurface*  pDDSNewRenderTarget);
  63. HRESULT GetTransform(
  64. D3DTRANSFORMSTATETYPE  dtstTransformStateType,
  65. LPD3DMATRIX  lpD3DMatrix);
  66. HRESULT SetTransform(
  67. D3DTRANSFORMSTATETYPE  dtstTransformStateType,
  68. LPD3DMATRIX  lpD3DMatrix);
  69. public:
  70. // Functions to support sprite-based rendering
  71. HRESULT ChangeRenderTarget(CDDSurface*  pDDSNewTarget);
  72. public: // Creation
  73. HRESULT CreateVertexBuffer(
  74. LPD3DVERTEXBUFFERDESC  lpVBDesc,
  75. LPDIRECT3DVERTEXBUFFER7*  lpD3DVertexBuffer,
  76. DWORD  dwFlags);
  77. public: // Miscellaneous
  78. HRESULT EvictManagedTextures(void);
  79. public: // Scenes
  80. HRESULT BeginScene(void);
  81. HRESULT EndScene(void);
  82. public: // Rendering
  83. HRESULT DrawPrimitive(
  84. D3DPRIMITIVETYPE  dptPrimitiveType,
  85. DWORD  dwVertexTypeDesc, LPVOID  lpvVertices,
  86. DWORD  dwVertexCount, DWORD  dwFlags);
  87. HRESULT DrawIndexedPrimitive(
  88. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  89. DWORD  dwVertexTypeDesc, LPVOID  lpvVertices,
  90. DWORD  dwVertexCount, LPWORD  lpwIndices,
  91. DWORD  dwIndexCount, DWORD  dwFlags);
  92. HRESULT DrawPrimitiveStrided(
  93. D3DPRIMITIVETYPE  dptPrimitiveType,
  94. DWORD  dwVertexTypeDesc,
  95. LPD3DDRAWPRIMITIVESTRIDEDDATA  lpVertexArray,
  96. DWORD  dwVertexCount,
  97. DWORD  dwFlags);
  98. HRESULT DrawIndexedPrimitiveStrided(
  99. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  100. DWORD  dwVertexTypeDesc,
  101. LPD3DDRAWPRIMITIVESTRIDEDDATA  lpVertexArray,
  102. DWORD  dwVertexCount,
  103. LPWORD  lpwIndices,
  104. DWORD  dwIndexCount,
  105. DWORD  dwFlags);
  106. HRESULT DrawPrimitiveVB(
  107. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  108. CD3DVertexBuffer*  pD3DVertexBuffer,
  109. DWORD  dwStartVertex,
  110. DWORD  dwNumVertices,
  111. DWORD  dwFlags);
  112. HRESULT DrawIndexedPrimitiveVB(
  113. D3DPRIMITIVETYPE  d3dptPrimitiveType,
  114. CD3DVertexBuffer*  pD3DVertexBuffer,
  115. DWORD  dwStartVertex,
  116. DWORD  dwNumVertices,
  117. LPWORD  lpwIndices,
  118. DWORD  dwIndexCount,
  119. DWORD  dwFlags);
  120. public: // Miscellaneous
  121. HRESULT ComputeSphereVisibility(LPD3DVECTOR  lpCenters,
  122. LPD3DVALUE  lpRadii, DWORD  dwNumSpheres,
  123. DWORD  dwFlags, LPDWORD  lpdwReturnValues);
  124. HRESULT MultiplyTransform(
  125. D3DTRANSFORMSTATETYPE  dtstTransformStateType,
  126. LPD3DMATRIX  lpD3DMatrix);
  127. public: // Textures
  128. HRESULT SetTexture(DWORD  dwStage,
  129. LPDIRECTDRAWSURFACE7  lpTexture);
  130. HRESULT GetTexture(DWORD  dwStage,
  131. LPDIRECTDRAWSURFACE7*  lplpTexture);
  132. HRESULT ValidateDevice(LPDWORD  lpdwPasses);
  133. HRESULT SetTextureStageState(DWORD  dwStage,
  134. D3DTEXTURESTAGESTATETYPE  dwState, DWORD  dwValue);
  135. HRESULT GetTextureStageState(DWORD  dwStage,
  136. D3DTEXTURESTAGESTATETYPE  dwState, LPDWORD  lpdwValue);
  137. HRESULT Load(LPDIRECTDRAWSURFACE7  lpDestTex,
  138. LPPOINT  lpDestPoint, LPDIRECTDRAWSURFACE7  lpSrcTex,
  139. LPRECT  lprcSrcRect, DWORD  dwFlags);
  140. HRESULT PreLoad(LPDIRECTDRAWSURFACE7  lpddsTexture);
  141. public:
  142. void SetTextureColorStage(DWORD  dwStage, D3DTEXTUREOP  op, DWORD  dwArg1, DWORD  dwArg2);
  143. void SetTextureAlphaStage(DWORD  dwStage, D3DTEXTUREOP  op, DWORD  dwArg1, DWORD  dwArg2);
  144. public: // Lighting and Materials
  145. HRESULT SetMaterial(LPD3DMATERIAL7  lpMaterial);
  146. HRESULT GetMaterial(LPD3DMATERIAL7  lpMaterial);
  147. HRESULT SetLight(DWORD  dwLightIndex, LPD3DLIGHT7  lpLight);
  148. HRESULT GetLight(DWORD  dwLightIndex, LPD3DLIGHT7  lpLight);
  149. HRESULT LightEnable(DWORD  dwLightIndex, BOOL  bEnable);
  150. HRESULT GetLightEnable(DWORD  dwLightIndex, BOOL*  pbEnable) const;
  151. DWORD GetActiveLightsNumber(void) const;
  152. DWORD GetMaxActiveLights(void) const;
  153. public: // User-defined clip planes
  154. HRESULT GetClipPlane(DWORD  dwIndex, D3DVALUE*  pPlaneEquation);
  155. HRESULT SetClipPlane(DWORD  dwIndex, D3DVALUE*  pPlaneEquation);
  156. public: // Viewports
  157. HRESULT Clear(DWORD  dwColor = CLR_INVALID);
  158. HRESULT GetViewport(LPD3DVIEWPORT7  lpViewport);
  159. HRESULT SetViewport(LPD3DVIEWPORT7  lpViewport);
  160. protected:
  161. DWORD m_dwLightsNumber;
  162. protected:
  163. const D3DDEVICEDESC7* m_pD3DDeviceDesc;
  164. CD3DMaterial* m_pD3DMaterial;
  165. LPDIRECT3DDEVICE7 m_lpD3DDevice;
  166. CDDSurface* m_pZBuffer;
  167. LPDIRECT3D7 m_lpD3D;
  168. };
  169. #include "D3DDevice.inl"
  170. #endif  // _D3DDEVICE__H