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.

220 lines
8.1 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. struct CHandle;
  12. const DWORD __INVALIDHANDLE = 0xFFFFFFFF;
  13. extern void InsertStateSetOp(LPDIRECT3DDEVICEI pDevI, DWORD dwOperation, DWORD dwParam, D3DSTATEBLOCKTYPE sbt);
  14. //---------------------------------------------------------------------
  15. // This class is used to generate sequential integer numbers (handles).
  16. // When a handle is released it will be reused.
  17. // Number of handles is unlimited
  18. //
  19. class CHandleFactory
  20. {
  21. public:
  22. CHandleFactory() {m_dwArraySize = 0; m_Handles = NULL;}
  23. ~CHandleFactory();
  24. HRESULT Init(DWORD dwInitialSize, DWORD dwGrowSize);
  25. DWORD CreateNewHandle();
  26. void ReleaseHandle(DWORD handle);
  27. protected:
  28. CHandle* CreateHandleArray(DWORD dwSize);
  29. CHandle *m_Handles; // Array of objects
  30. DWORD m_dwGrowSize;
  31. DWORD m_dwArraySize; // Number of objects in the array
  32. DWORD m_Free; // Header for free elements in the array
  33. };
  34. //---------------------------------------------------------------------
  35. // This class provides interface to the growing state set buffer
  36. //
  37. class CStateSetBuffer
  38. {
  39. public:
  40. CStateSetBuffer()
  41. {
  42. m_pBuffer = NULL;
  43. m_dwCurrentSize = 0;
  44. m_dwBufferSize = 0;
  45. m_pDP2CurrCommand = 0;
  46. }
  47. CStateSetBuffer(CStateSetBuffer& src)
  48. {
  49. m_dwCurrentSize = src.m_dwCurrentSize;
  50. m_dwBufferSize = src.m_dwCurrentSize;
  51. if(m_dwCurrentSize != 0)
  52. {
  53. m_pBuffer = new BYTE[m_dwCurrentSize];
  54. if(m_pBuffer == 0)
  55. {
  56. m_dwCurrentSize = 0;
  57. m_pDP2CurrCommand = 0;
  58. throw DDERR_OUTOFMEMORY;
  59. }
  60. memcpy(m_pBuffer, src.m_pBuffer, m_dwCurrentSize);
  61. }
  62. else
  63. {
  64. m_pBuffer = 0;
  65. }
  66. m_pDP2CurrCommand = 0;
  67. }
  68. ~CStateSetBuffer()
  69. {
  70. delete [] m_pBuffer;
  71. }
  72. void operator=(CStateSetBuffer& src)
  73. {
  74. m_dwCurrentSize = src.m_dwCurrentSize;
  75. if(m_dwBufferSize != m_dwCurrentSize)
  76. {
  77. m_dwBufferSize = m_dwCurrentSize;
  78. delete [] m_pBuffer;
  79. if(m_dwCurrentSize != 0)
  80. {
  81. m_pBuffer = new BYTE[m_dwCurrentSize];
  82. if(m_pBuffer == 0)
  83. {
  84. m_dwCurrentSize = 0;
  85. m_pDP2CurrCommand = 0;
  86. throw DDERR_OUTOFMEMORY;
  87. }
  88. }
  89. else
  90. {
  91. m_pBuffer = 0;
  92. m_pDP2CurrCommand = 0;
  93. return;
  94. }
  95. }
  96. memcpy(m_pBuffer, src.m_pBuffer, m_dwCurrentSize);
  97. m_pDP2CurrCommand = 0;
  98. }
  99. // Insert a command to the buffer. Grow buffer if necessary
  100. void InsertCommand(D3DHAL_DP2OPERATION, LPVOID pData, DWORD dwDataSize);
  101. // Reset current command
  102. void ResetCurrentCommand()
  103. {
  104. m_pDP2CurrCommand = 0;
  105. }
  106. // Set buffer to its initial state. Memory is not freed
  107. void Reset()
  108. {
  109. m_dwCurrentSize = 0;
  110. m_pDP2CurrCommand = 0;
  111. }
  112. DWORD m_dwCurrentSize;
  113. DWORD m_dwBufferSize;
  114. BYTE *m_pBuffer;
  115. //Pointer to the current position the CB1 buffer
  116. LPD3DHAL_DP2COMMAND m_pDP2CurrCommand;
  117. };
  118. //---------------------------------------------------------------------
  119. // This class provides interface to a state set
  120. //
  121. const DWORD __STATESET_INITIALIZED = 1;
  122. // Set if we have to check if we need to restore texture stage indices
  123. const DWORD __STATESET_NEEDCHECKREMAPPING = 2;
  124. class CStateSet
  125. {
  126. public:
  127. CStateSet()
  128. {
  129. m_dwStateSetFlags = 0;
  130. m_dwDeviceHandle = __INVALIDHANDLE;
  131. }
  132. void InsertCommand(D3DHAL_DP2OPERATION, LPVOID pData, DWORD dwDataSize, BOOL bDriverCanHandle);
  133. // Mark the state set as unused. The object is not destroyed and can be
  134. // reused
  135. HRESULT Release();
  136. // Execute the front-end only or device state subset
  137. void Execute(LPDIRECT3DDEVICEI pDevI, BOOL bFrontEndBuffer);
  138. // Capture the current device state into the state block
  139. void Capture(LPDIRECT3DDEVICEI pDevI, BOOL bFrontEndBuffer);
  140. // Reset the current command in both buffers
  141. void ResetCurrentCommand()
  142. {
  143. m_FEOnlyBuffer.ResetCurrentCommand();
  144. m_DriverBuffer.ResetCurrentCommand();
  145. }
  146. protected:
  147. CStateSetBuffer m_FEOnlyBuffer; // Contains commands that driver can not
  148. // understand
  149. CStateSetBuffer m_DriverBuffer; // Contains commands that driver can
  150. // understand
  151. DWORD m_dwDeviceHandle; // Some sets could not have corresponding
  152. // device buffers, so device handle is not
  153. // equal to the user visible handle
  154. DWORD m_dwStateSetFlags;
  155. friend class CStateSets;
  156. };
  157. //---------------------------------------------------------------------
  158. // This class encapsulates handling of array of state sets
  159. //
  160. class CStateSets
  161. {
  162. public:
  163. CStateSets();
  164. ~CStateSets();
  165. HRESULT Init(DWORD dwFlags);
  166. HRESULT StartNewSet();
  167. void EndSet();
  168. // Returns current handle
  169. DWORD GetCurrentHandle() {return m_dwCurrentHandle;}
  170. // Delete state set
  171. void DeleteStateSet(LPDIRECT3DDEVICEI pDevI, DWORD dwHandle);
  172. // Returns information about state set data to be written to the device
  173. // Allocates a new handle for the device buffer
  174. void GetDeviceBufferInfo(DWORD* dwStateSetHandle, LPVOID *pBuffer, DWORD* dwBufferSize);
  175. // Insert a render state to the current state set
  176. // Throws an exception in case of error
  177. void InsertRenderState(D3DRENDERSTATETYPE state, DWORD dwValue,
  178. BOOL bDriverCanHandle);
  179. void InsertLight(DWORD dwLightIndex, LPD3DLIGHT7);
  180. void InsertLightEnable(DWORD dwLightIndex, BOOL bEnable);
  181. void InsertMaterial(LPD3DMATERIAL7);
  182. void InsertViewport(LPD3DVIEWPORT7);
  183. void InsertTransform(D3DTRANSFORMSTATETYPE state, LPD3DMATRIX lpMat);
  184. void InsertTextureStageState(DWORD, D3DTEXTURESTAGESTATETYPE, DWORD);
  185. void InsertTexture(DWORD dwStage, LPDIRECTDRAWSURFACE7 pTex);
  186. void InsertClipPlane(DWORD dwPlaneIndex, D3DVALUE* pPlaneEquation);
  187. // Execute a state set with the specified handle
  188. void Execute(LPDIRECT3DDEVICEI pDevI, DWORD dwHandle);
  189. // Capture a state set to the the specified handle
  190. void Capture(LPDIRECT3DDEVICEI pDevI, DWORD dwHandle);
  191. // Capture predefined state
  192. void CreatePredefined(LPDIRECT3DDEVICEI pDevI, D3DSTATEBLOCKTYPE sbt);
  193. void Cleanup(DWORD dwHandle);
  194. protected:
  195. const DWORD m_GrowSize;
  196. DWORD m_dwMaxSets; // Maximum number of state sets
  197. DWORD m_dwCurrentHandle;
  198. CStateSet * m_pStateSets; // Array of state sets
  199. CStateSet * m_pCurrentStateSet;
  200. CHandleFactory m_DeviceHandles; // Used to create device handles
  201. CHandleFactory m_SetHandles; // Used to create state sets
  202. CStateSet m_BufferSet;
  203. DWORD m_dwFlags;
  204. };
  205. // This is RESERVED0 in d3dhal.h
  206. #define D3DDP2OP_FRONTENDDATA 4 // Used by the front-end only
  207. // This structure is used by the front-end only
  208. typedef struct _D3DHAL_DP2FRONTENDDATA
  209. {
  210. WORD wStage; // texture stage
  211. LPVOID pTexture; // Texture pointer
  212. } D3DHAL_DP2FRONTENDDATA, *LPD3DHAL_DP2FRONTENDDATA;
  213. #endif //_STATESTE_HPP_