Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

248 lines
9.3 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: stateset.hpp
  6. * Content: State sets handling interfaces
  7. *
  8. ***************************************************************************/
  9. #ifndef _STATESET_HPP_
  10. #define _STATESET_HPP_
  11. #include "hmgr.hpp"
  12. extern void InsertStateSetOp(CD3DBase *pDevI, DWORD dwOperation, DWORD dwParam, D3DSTATEBLOCKTYPE sbt);
  13. //---------------------------------------------------------------------
  14. // This class provides interface to the growing state set buffer
  15. //
  16. class CStateSetBuffer
  17. {
  18. public:
  19. CStateSetBuffer()
  20. {
  21. m_pBuffer = NULL;
  22. m_dwCurrentSize = 0;
  23. m_dwBufferSize = 0;
  24. m_pDP2CurrCommand = 0;
  25. }
  26. CStateSetBuffer(CStateSetBuffer& src)
  27. {
  28. m_dwCurrentSize = src.m_dwCurrentSize;
  29. m_dwBufferSize = src.m_dwCurrentSize;
  30. if(m_dwCurrentSize != 0)
  31. {
  32. m_pBuffer = new BYTE[m_dwCurrentSize];
  33. if(m_pBuffer == 0)
  34. {
  35. m_dwCurrentSize = 0;
  36. m_pDP2CurrCommand = 0;
  37. throw E_OUTOFMEMORY;
  38. }
  39. memcpy(m_pBuffer, src.m_pBuffer, m_dwCurrentSize);
  40. }
  41. else
  42. {
  43. m_pBuffer = 0;
  44. }
  45. m_pDP2CurrCommand = 0;
  46. }
  47. ~CStateSetBuffer()
  48. {
  49. delete [] m_pBuffer;
  50. }
  51. void operator=(CStateSetBuffer& src)
  52. {
  53. m_dwCurrentSize = src.m_dwCurrentSize;
  54. if(m_dwBufferSize != m_dwCurrentSize)
  55. {
  56. m_dwBufferSize = m_dwCurrentSize;
  57. delete [] m_pBuffer;
  58. if(m_dwCurrentSize != 0)
  59. {
  60. m_pBuffer = new BYTE[m_dwCurrentSize];
  61. if(m_pBuffer == 0)
  62. {
  63. m_dwCurrentSize = 0;
  64. m_pDP2CurrCommand = 0;
  65. throw E_OUTOFMEMORY;
  66. }
  67. }
  68. else
  69. {
  70. m_pBuffer = 0;
  71. m_pDP2CurrCommand = 0;
  72. return;
  73. }
  74. }
  75. memcpy(m_pBuffer, src.m_pBuffer, m_dwCurrentSize);
  76. m_pDP2CurrCommand = 0;
  77. }
  78. // Insert a command to the buffer. Grow buffer if necessary
  79. void InsertCommand(D3DHAL_DP2OPERATION, LPVOID pData, DWORD dwDataSize);
  80. // Reset current command
  81. void ResetCurrentCommand()
  82. {
  83. m_pDP2CurrCommand = 0;
  84. }
  85. // Set buffer to its initial state. Memory is not freed
  86. void Reset()
  87. {
  88. m_dwCurrentSize = 0;
  89. m_pDP2CurrCommand = 0;
  90. }
  91. DWORD m_dwCurrentSize;
  92. DWORD m_dwBufferSize;
  93. BYTE *m_pBuffer;
  94. //Pointer to the current position the CB1 buffer
  95. LPD3DHAL_DP2COMMAND m_pDP2CurrCommand;
  96. };
  97. //---------------------------------------------------------------------
  98. // This class provides interface to a state set
  99. //
  100. const DWORD __STATESET_INITIALIZED = 1;
  101. // Set if we have to check if we need to restore texture stage indices
  102. const DWORD __STATESET_NEEDCHECKREMAPPING = 2;
  103. // Set if the state set executed had purely pixel state
  104. const DWORD __STATESET_HASONLYVERTEXSTATE = 4;
  105. class CStateSet
  106. {
  107. public:
  108. CStateSet()
  109. {
  110. m_dwStateSetFlags = 0;
  111. m_dwDeviceHandle = __INVALIDHANDLE;
  112. }
  113. virtual void InsertCommand(D3DHAL_DP2OPERATION, LPVOID pData, DWORD dwDataSize, BOOL bDriverCanHandle);
  114. // Mark the state set as unused. The object is not destroyed and can be
  115. // reused
  116. HRESULT Release();
  117. // Execute the front-end only or device state subset
  118. virtual void Execute(CD3DBase *pDevI, BOOL bFrontEndBuffer);
  119. // Capture the current device state into the state block
  120. virtual void Capture(CD3DBase *pDevI, BOOL bFrontEndBuffer);
  121. // Create a predefined state block
  122. virtual void CreatePredefined(CD3DBase *pDevI, D3DSTATEBLOCKTYPE sbt);
  123. // Reset the current command in both buffers
  124. void ResetCurrentCommand()
  125. {
  126. m_FEOnlyBuffer.ResetCurrentCommand();
  127. m_DriverBuffer.ResetCurrentCommand();
  128. }
  129. protected:
  130. CStateSetBuffer m_FEOnlyBuffer; // Contains commands that driver can not
  131. // understand
  132. CStateSetBuffer m_DriverBuffer; // Contains commands that driver can
  133. // understand
  134. DWORD m_dwDeviceHandle; // Some sets could not have corresponding
  135. // device buffers, so device handle is not
  136. // equal to the user visible handle
  137. DWORD m_dwStateSetFlags;
  138. friend class CStateSets;
  139. };
  140. class CPureStateSet : public CStateSet
  141. {
  142. public:
  143. void InsertCommand(D3DHAL_DP2OPERATION, LPVOID pData, DWORD dwDataSize, BOOL bDriverCanHandle);
  144. void Execute(CD3DBase *pDevI, BOOL bFrontEndBuffer);
  145. void Capture(CD3DBase *pDevI, BOOL bFrontEndBuffer);
  146. void CreatePredefined(CD3DBase *pDevI, D3DSTATEBLOCKTYPE sbt);
  147. };
  148. //---------------------------------------------------------------------
  149. // This class encapsulates handling of array of state sets
  150. //
  151. class CStateSets
  152. {
  153. public:
  154. CStateSets();
  155. ~CStateSets();
  156. HRESULT Init(CD3DBase *pDev);
  157. HRESULT StartNewSet();
  158. void EndSet();
  159. // Returns current handle
  160. DWORD GetCurrentHandle() {return m_dwCurrentHandle;}
  161. // Delete state set
  162. void DeleteStateSet(CD3DBase *pDevI, DWORD dwHandle);
  163. // Returns information about state set data to be written to the device
  164. // Allocates a new handle for the device buffer
  165. void GetDeviceBufferInfo(DWORD* dwStateSetHandle, LPVOID *pBuffer, DWORD* dwBufferSize);
  166. void CreateNewDeviceHandle(DWORD* dwStateSetHandle);
  167. // Copy buffer and translate for DX7 DDI
  168. void TranslateDeviceBufferToDX7DDI( DWORD* p, DWORD dwSize );
  169. // Insert a render state to the current state set
  170. // Throws an exception in case of error
  171. void InsertRenderState(D3DRENDERSTATETYPE state, DWORD dwValue,
  172. BOOL bDriverCanHandle);
  173. void InsertLight(DWORD dwLightIndex, CONST D3DLIGHT8*);
  174. void InsertLightEnable(DWORD dwLightIndex, BOOL bEnable);
  175. void InsertMaterial(CONST D3DMATERIAL8*);
  176. void InsertViewport(CONST D3DVIEWPORT8*);
  177. void InsertTransform(D3DTRANSFORMSTATETYPE state, CONST D3DMATRIX* lpMat);
  178. void InsertTextureStageState(DWORD, D3DTEXTURESTAGESTATETYPE, DWORD);
  179. void InsertTexture(DWORD dwStage, IDirect3DBaseTexture8 *pTex);
  180. void InsertClipPlane(DWORD dwPlaneIndex, CONST D3DVALUE* pPlaneEquation);
  181. void InsertVertexShader(DWORD dwShaderHandle, BOOL bHardware);
  182. void InsertPixelShader(DWORD dwShaderHandle);
  183. void InsertStreamSource(DWORD dwStream, CVertexBuffer *pBuf, DWORD dwStride);
  184. void InsertIndices(CIndexBuffer *pBuf, DWORD dwBaseVertex);
  185. void InsertVertexShaderConstant(DWORD Register, CONST VOID* pConstantData, DWORD ConstantCount);
  186. void InsertPixelShaderConstant(DWORD Register, CONST VOID* pConstantData, DWORD ConstantCount);
  187. void InsertCurrentTexturePalette(DWORD PaletteNumber);
  188. // Execute a state set with the specified handle
  189. void Execute(CD3DBase *pDevI, DWORD dwHandle);
  190. // Capture a state set to the the specified handle
  191. void Capture(CD3DBase *pDevI, DWORD dwHandle);
  192. // Capture predefined state
  193. void CreatePredefined(CD3DBase *pDevI, D3DSTATEBLOCKTYPE sbt);
  194. void Cleanup(DWORD dwHandle);
  195. protected:
  196. const DWORD m_GrowSize;
  197. DWORD m_dwMaxSets; // Maximum number of state sets
  198. DWORD m_dwCurrentHandle;
  199. CStateSet * m_pStateSets; // Array of state sets
  200. CStateSet * m_pCurrentStateSet;
  201. CHandleFactory m_DeviceHandles; // Used to create device handles
  202. CHandleFactory m_SetHandles; // Used to create state sets
  203. CStateSet * m_pBufferSet;
  204. DWORD m_dwFlags;
  205. BOOL m_bPure, m_bTLHal, m_bEmulate, m_bDX8Dev, m_bHardwareVP;
  206. };
  207. // This is RESERVED0 in d3dhal.h
  208. #define D3DDP2OP_FRONTENDDATA 4 // Used by the front-end only
  209. #define D3DDP2OP_FESETVB 5
  210. #define D3DDP2OP_FESETIB 6
  211. #define D3DDP2OP_FESETPAL 7
  212. // This structure is used by the front-end only
  213. typedef struct _D3DHAL_DP2FRONTENDDATA
  214. {
  215. WORD wStage; // texture stage
  216. IDirect3DBaseTexture8 * pTexture; // Texture pointer
  217. } D3DHAL_DP2FRONTENDDATA;
  218. typedef D3DHAL_DP2FRONTENDDATA UNALIGNED64 * LPD3DHAL_DP2FRONTENDDATA;
  219. typedef struct _D3DHAL_DP2FESETVB
  220. {
  221. WORD wStream;
  222. CVertexBuffer * pBuf;
  223. DWORD dwStride;
  224. } D3DHAL_DP2FESETVB;
  225. typedef D3DHAL_DP2FESETVB UNALIGNED64 * LPD3DHAL_DP2FESETVB;
  226. typedef struct _D3DHAL_DP2FESETIB
  227. {
  228. CIndexBuffer * pBuf;
  229. DWORD dwBase;
  230. } D3DHAL_DP2FESETIB;
  231. typedef D3DHAL_DP2FESETIB UNALIGNED64 * LPD3DHAL_DP2FESETIB;
  232. typedef struct _D3DHAL_DP2FESETPAL
  233. {
  234. DWORD dwPaletteNumber;
  235. } D3DHAL_DP2FESETPAL;
  236. typedef D3DHAL_DP2FESETPAL UNALIGNED64 * LPD3DHAL_DP2FESETPAL;
  237. #endif //_STATESTE_HPP_