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.

1289 lines
39 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // primfns.cpp
  4. //
  5. // Primitive functions for RAMP/RGB/REF.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1998.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. extern HRESULT
  13. RefRastLockTarget(ReferenceRasterizer *pRefRast);
  14. extern void
  15. RefRastUnlockTarget(ReferenceRasterizer *pRefRast);
  16. extern HRESULT
  17. RefRastLockTexture(ReferenceRasterizer *pRefRast);
  18. extern void
  19. RefRastUnlockTexture(ReferenceRasterizer *pRefRast);
  20. HRESULT WrapDp2SetViewport( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  21. {
  22. return pRefRast->Dp2SetViewport(pCmd);
  23. }
  24. HRESULT WrapDp2SetWRange ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  25. {
  26. return pRefRast->Dp2SetWRange(pCmd);
  27. }
  28. HRESULT WrapDp2SetZRange ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  29. {
  30. return pRefRast->Dp2SetZRange(pCmd);
  31. }
  32. HRESULT WrapDp2SetRenderStates( ReferenceRasterizer *pRefRast,
  33. DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd,
  34. LPDWORD lpdwRuntimeRStates )
  35. {
  36. return pRefRast->Dp2SetRenderStates(dwFvf, pCmd, lpdwRuntimeRStates);
  37. }
  38. HRESULT WrapDp2SetTextureStageState( ReferenceRasterizer *pRefRast, DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd )
  39. {
  40. return pRefRast->Dp2SetTextureStageState(dwFvf, pCmd);
  41. }
  42. HRESULT WrapDp2SetMaterial ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  43. {
  44. return pRefRast->Dp2SetMaterial(pCmd);
  45. }
  46. HRESULT WrapDp2SetLight( ReferenceRasterizer *pRefRast,
  47. LPD3DHAL_DP2COMMAND pCmd,
  48. LPDWORD pdwStride )
  49. {
  50. return pRefRast->Dp2SetLight(pCmd, pdwStride);
  51. }
  52. HRESULT WrapDp2CreateLight ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  53. {
  54. return pRefRast->Dp2CreateLight(pCmd);
  55. }
  56. HRESULT WrapDp2SetTransform( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  57. {
  58. return pRefRast->Dp2SetTransform(pCmd);
  59. }
  60. HRESULT WrapDp2SetExtention( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  61. {
  62. return pRefRast->Dp2SetExtention(pCmd);
  63. }
  64. HRESULT WrapDp2SetClipPlane( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  65. {
  66. return pRefRast->Dp2SetClipPlane(pCmd);
  67. }
  68. HRESULT WrapDp2RecViewport( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  69. {
  70. return pRefRast->Dp2RecViewport(pCmd);
  71. }
  72. HRESULT WrapDp2RecWRange ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  73. {
  74. return pRefRast->Dp2RecWRange(pCmd);
  75. }
  76. HRESULT WrapDp2RecZRange ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  77. {
  78. return pRefRast->Dp2RecZRange(pCmd);
  79. }
  80. HRESULT WrapDp2RecRenderStates( ReferenceRasterizer *pRefRast,
  81. DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd,
  82. LPDWORD lpdwRuntimeRStates )
  83. {
  84. return pRefRast->Dp2RecRenderStates(dwFvf, pCmd, lpdwRuntimeRStates);
  85. }
  86. HRESULT WrapDp2RecTextureStageState( ReferenceRasterizer *pRefRast, DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd )
  87. {
  88. return pRefRast->Dp2RecTextureStageState(dwFvf, pCmd);
  89. }
  90. HRESULT WrapDp2RecMaterial ( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  91. {
  92. return pRefRast->Dp2RecMaterial(pCmd);
  93. }
  94. HRESULT WrapDp2RecSetLight ( ReferenceRasterizer *pRefRast,
  95. LPD3DHAL_DP2COMMAND pCmd,
  96. LPDWORD pdwStride)
  97. {
  98. return pRefRast->Dp2RecSetLight(pCmd, pdwStride);
  99. }
  100. HRESULT WrapDp2RecCreateLight( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  101. {
  102. return pRefRast->Dp2RecCreateLight(pCmd);
  103. }
  104. HRESULT WrapDp2RecTransform( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  105. {
  106. return pRefRast->Dp2RecTransform(pCmd);
  107. }
  108. HRESULT WrapDp2RecExtention( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  109. {
  110. return pRefRast->Dp2RecExtention(pCmd);
  111. }
  112. HRESULT WrapDp2RecClipPlane( ReferenceRasterizer *pRefRast, LPD3DHAL_DP2COMMAND pCmd )
  113. {
  114. return pRefRast->Dp2RecClipPlane(pCmd);
  115. }
  116. static REF_STATESETFUNCTIONTBL StateRecFunctions =
  117. {
  118. sizeof(REF_STATESETFUNCTIONTBL),
  119. WrapDp2RecRenderStates,
  120. WrapDp2RecTextureStageState,
  121. WrapDp2RecViewport,
  122. WrapDp2RecWRange,
  123. WrapDp2RecMaterial,
  124. WrapDp2RecZRange,
  125. WrapDp2RecSetLight,
  126. WrapDp2RecCreateLight,
  127. WrapDp2RecTransform,
  128. WrapDp2RecExtention,
  129. WrapDp2RecClipPlane
  130. };
  131. static REF_STATESETFUNCTIONTBL StateSetFunctions =
  132. {
  133. sizeof(REF_STATESETFUNCTIONTBL),
  134. WrapDp2SetRenderStates,
  135. WrapDp2SetTextureStageState,
  136. WrapDp2SetViewport,
  137. WrapDp2SetWRange,
  138. WrapDp2SetMaterial,
  139. WrapDp2SetZRange,
  140. WrapDp2SetLight,
  141. WrapDp2CreateLight,
  142. WrapDp2SetTransform,
  143. WrapDp2SetExtention,
  144. WrapDp2SetClipPlane
  145. };
  146. void
  147. ReferenceRasterizer::StoreLastPixelState(BOOL bStore)
  148. {
  149. if (bStore)
  150. {
  151. m_LastState = GetRenderState()[D3DRENDERSTATE_LASTPIXEL];
  152. SetRenderState(D3DRENDERSTATE_LASTPIXEL, 0);
  153. }
  154. else
  155. {
  156. SetRenderState(D3DRENDERSTATE_LASTPIXEL, m_LastState);
  157. }
  158. }
  159. void
  160. ReferenceRasterizer::SetRecStateFunctions(void)
  161. {
  162. pStateSetFuncTbl = &StateRecFunctions;
  163. }
  164. void
  165. ReferenceRasterizer::SetSetStateFunctions(void)
  166. {
  167. pStateSetFuncTbl = &StateSetFunctions;
  168. }
  169. HRESULT
  170. ReferenceRasterizer::Dp2SetRenderStates(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd,
  171. LPDWORD lpdwRuntimeRStates )
  172. {
  173. WORD wStateCount = pCmd->wStateCount;
  174. INT i;
  175. HRESULT hr = D3D_OK;
  176. D3DHAL_DP2RENDERSTATE *pRenderState =
  177. (D3DHAL_DP2RENDERSTATE *)(pCmd + 1);
  178. for (i = 0; i < (INT)wStateCount; i++, pRenderState++)
  179. {
  180. UINT32 type = (UINT32) pRenderState->RenderState;
  181. // Check for overrides
  182. if (IS_OVERRIDE(type))
  183. {
  184. UINT32 override = GET_OVERRIDE(type);
  185. if (pRenderState->dwState)
  186. STATESET_SET(m_renderstate_override, override);
  187. else
  188. STATESET_CLEAR(m_renderstate_override, override);
  189. continue;
  190. }
  191. if (STATESET_ISSET(m_renderstate_override, type))
  192. continue;
  193. // Set the runtime copy (if necessary)
  194. if (NULL != lpdwRuntimeRStates)
  195. {
  196. lpdwRuntimeRStates[pRenderState->RenderState] = pRenderState->dwState;
  197. }
  198. // Set the state
  199. this->SetRenderState(pRenderState->RenderState,
  200. pRenderState->dwState);
  201. }
  202. return hr;
  203. }
  204. HRESULT
  205. ReferenceRasterizer::Dp2SetTextureStageState(DWORD dwFvf,
  206. LPD3DHAL_DP2COMMAND pCmd )
  207. {
  208. WORD wStateCount = pCmd->wStateCount;
  209. INT i;
  210. HRESULT hr = D3D_OK;
  211. D3DHAL_DP2TEXTURESTAGESTATE *pTexStageState =
  212. (D3DHAL_DP2TEXTURESTAGESTATE *)(pCmd + 1);
  213. //
  214. // The textures are already locked, unlock them
  215. //
  216. if (TexturesAreLocked())
  217. {
  218. RefRastUnlockTexture(this);
  219. }
  220. for (i = 0; i < (INT)wStateCount; i++, pTexStageState++)
  221. {
  222. this->SetTextureStageState(pTexStageState->wStage,
  223. pTexStageState->TSState,
  224. pTexStageState->dwValue);
  225. }
  226. //
  227. // We didnt unset this bool, hence lock the textures back again
  228. //
  229. if (TexturesAreLocked())
  230. {
  231. HR_RET(RefRastLockTexture(this));
  232. }
  233. return hr;
  234. }
  235. HRESULT
  236. ReferenceRasterizer::Dp2SetViewport(LPD3DHAL_DP2COMMAND pCmd)
  237. {
  238. LPD3DHAL_DP2VIEWPORTINFO pVpt;
  239. // Keep only the last viewport notification
  240. pVpt = (D3DHAL_DP2VIEWPORTINFO *)(pCmd + 1) + (pCmd->wStateCount - 1);
  241. // Update T&L viewport state
  242. m_Viewport.dwX = pVpt->dwX;
  243. m_Viewport.dwY = pVpt->dwY;
  244. m_Viewport.dwWidth = pVpt->dwWidth;
  245. m_Viewport.dwHeight = pVpt->dwHeight;
  246. m_dwDirtyFlags |= RRPV_DIRTY_VIEWRECT;
  247. // get render target; update it; put it back
  248. RRRenderTarget *pRendTgt = this->GetRenderTarget();
  249. pRendTgt->m_Clip.left = pVpt->dwX;
  250. pRendTgt->m_Clip.top = pVpt->dwY;
  251. pRendTgt->m_Clip.right = pVpt->dwX + pVpt->dwWidth - 1;
  252. pRendTgt->m_Clip.bottom = pVpt->dwY + pVpt->dwHeight - 1;
  253. this->SetRenderTarget( pRendTgt );
  254. return D3D_OK;
  255. }
  256. HRESULT
  257. ReferenceRasterizer::Dp2SetWRange(LPD3DHAL_DP2COMMAND pCmd)
  258. {
  259. LPD3DHAL_DP2WINFO pWInfo;
  260. // Keep only the last viewport notification
  261. pWInfo = (D3DHAL_DP2WINFO *)(pCmd + 1) + (pCmd->wStateCount - 1);
  262. // get render target; update it; put it back
  263. RRRenderTarget *pRendTgt = this->GetRenderTarget();
  264. pRendTgt->m_fWRange[0] = pWInfo->dvWNear;
  265. pRendTgt->m_fWRange[1] = pWInfo->dvWFar;
  266. this->SetRenderTarget( pRendTgt );
  267. return D3D_OK;
  268. }
  269. HRESULT
  270. ReferenceRasterizer::Dp2SetZRange(LPD3DHAL_DP2COMMAND pCmd)
  271. {
  272. LPD3DHAL_DP2ZRANGE pZRange;
  273. // Keep only the last viewport notification
  274. pZRange = (D3DHAL_DP2ZRANGE *)(pCmd + 1) + (pCmd->wStateCount - 1);
  275. // Update T&L viewport state
  276. m_Viewport.dvMinZ = pZRange->dvMinZ;
  277. m_Viewport.dvMaxZ = pZRange->dvMaxZ;
  278. m_dwDirtyFlags |= RRPV_DIRTY_ZRANGE;
  279. return D3D_OK;
  280. }
  281. HRESULT
  282. ReferenceRasterizer::Dp2SetMaterial(LPD3DHAL_DP2COMMAND pCmd)
  283. {
  284. LPD3DHAL_DP2SETMATERIAL pSetMat;
  285. // Keep only the last material notification
  286. pSetMat = (D3DHAL_DP2SETMATERIAL *)(pCmd + 1) + (pCmd->wStateCount - 1);
  287. m_Material = *(D3DMATERIAL7 *)pSetMat;
  288. m_dwDirtyFlags |= RRPV_DIRTY_MATERIAL;
  289. return D3D_OK;
  290. }
  291. HRESULT
  292. ReferenceRasterizer::Dp2CreateLight(LPD3DHAL_DP2COMMAND pCmd)
  293. {
  294. WORD wNumCreateLight = pCmd->wStateCount;
  295. LPD3DHAL_DP2CREATELIGHT pCreateLight = (LPD3DHAL_DP2CREATELIGHT)(pCmd + 1);
  296. HRESULT hr = D3D_OK;
  297. for (int i = 0; i < wNumCreateLight; i++, pCreateLight++)
  298. {
  299. // If the index is not already allocated, grow the light array
  300. // by REF_LIGHTARRAY_GROWTH_SIZE
  301. if (pCreateLight->dwIndex >= m_dwLightArraySize)
  302. {
  303. HR_RET(GrowLightArray(pCreateLight->dwIndex));
  304. }
  305. }
  306. return hr;
  307. }
  308. #define ARRAYGROW_DELTA 32 // Should be a power of 2
  309. HRESULT
  310. ReferenceRasterizer::GrowLightArray(const DWORD dwIndex)
  311. {
  312. // Allocate a few extra in anticipation of more light being used in the
  313. // future
  314. DWORD dwNewArraySize = dwIndex+16;
  315. RRLight *pTmpActiveLights = NULL;
  316. RRLight *pTmpLightArray = new RRLight[dwNewArraySize];
  317. if (pTmpLightArray == NULL)
  318. return DDERR_OUTOFMEMORY;
  319. // Save all the created lights
  320. for (DWORD i=0; i<m_dwLightArraySize; i++)
  321. {
  322. // If it is a valid, i.e. a light that has been set,
  323. // then save it in the new array
  324. pTmpLightArray[i] = m_pLightArray[i];
  325. // If the light is enabled, update the ActiveList pointer
  326. if (m_pLightArray[i].IsEnabled())
  327. {
  328. pTmpLightArray[i].m_Next = pTmpActiveLights;
  329. pTmpActiveLights = &pTmpLightArray[i];
  330. }
  331. }
  332. delete m_pLightArray;
  333. m_lighting.pActiveLights = pTmpActiveLights;
  334. m_pLightArray = pTmpLightArray;
  335. m_dwLightArraySize = dwNewArraySize;
  336. return D3D_OK;
  337. }
  338. HRESULT
  339. ReferenceRasterizer::Dp2SetLight(LPD3DHAL_DP2COMMAND pCmd,
  340. LPDWORD pdwStride)
  341. {
  342. HRESULT hr = D3D_OK;
  343. WORD wNumSetLight = pCmd->wStateCount;
  344. _ASSERT( pdwStride != NULL, "pdwStride is Null" );
  345. *pdwStride = sizeof(D3DHAL_DP2COMMAND);
  346. LPD3DHAL_DP2SETLIGHT pSetLight = (LPD3DHAL_DP2SETLIGHT)(pCmd + 1);
  347. D3DLIGHT7 *pLightData = NULL;
  348. for (int i = 0; i < wNumSetLight; i++)
  349. {
  350. DWORD dwStride = sizeof(D3DHAL_DP2SETLIGHT);
  351. DWORD dwIndex = pSetLight->dwIndex;
  352. // Assert that create was not called here
  353. _ASSERTf(dwIndex < m_dwLightArraySize,
  354. ( "Create was not called prior to the SetLight for light %d",
  355. dwIndex ));
  356. switch (pSetLight->dwDataType)
  357. {
  358. case D3DHAL_SETLIGHT_ENABLE:
  359. m_pLightArray[dwIndex].Enable(&m_lighting.pActiveLights);
  360. m_dwDirtyFlags |= RRPV_DIRTY_SETLIGHT;
  361. break;
  362. case D3DHAL_SETLIGHT_DISABLE:
  363. m_pLightArray[dwIndex].Disable(&m_lighting.pActiveLights);
  364. break;
  365. case D3DHAL_SETLIGHT_DATA:
  366. pLightData = (D3DLIGHT7 *)((LPBYTE)pSetLight + dwStride);
  367. dwStride += sizeof(D3DLIGHT7);
  368. HR_RET(m_pLightArray[pSetLight->dwIndex].SetLight(pLightData));
  369. m_dwDirtyFlags |= RRPV_DIRTY_SETLIGHT;
  370. break;
  371. default:
  372. DPFM(0,TNL,("Unknown SetLight command"));
  373. hr = DDERR_INVALIDPARAMS;
  374. }
  375. *pdwStride += dwStride;
  376. // Update the command buffer pointer
  377. pSetLight = (D3DHAL_DP2SETLIGHT *)((LPBYTE)pSetLight +
  378. dwStride);
  379. }
  380. return hr;
  381. }
  382. HRESULT
  383. ReferenceRasterizer::Dp2SetTransform(LPD3DHAL_DP2COMMAND pCmd)
  384. {
  385. WORD wNumXfrms = pCmd->wStateCount;
  386. D3DHAL_DP2SETTRANSFORM *pSetXfrm = (D3DHAL_DP2SETTRANSFORM*)(pCmd + 1);
  387. for (int i = 0; i < (int) wNumXfrms; i++, pSetXfrm++)
  388. {
  389. this->SetXfrm( pSetXfrm->xfrmType, &pSetXfrm->matrix);
  390. }
  391. return D3D_OK;
  392. }
  393. static D3DMATRIX matIdent =
  394. {
  395. 1.0f, 0.0f, 0.0f, 0.0f,
  396. 0.0f, 1.0f, 0.0f, 0.0f,
  397. 0.0f, 0.0f, 1.0f, 0.0f,
  398. 0.0f, 0.0f, 0.0f, 1.0f
  399. };
  400. void
  401. ReferenceRasterizer::SetXfrm(D3DTRANSFORMSTATETYPE xfrmType, D3DMATRIX *pMat)
  402. {
  403. // ATTENTION is there a define for 0x80000000?
  404. BOOL bSetIdentity = (xfrmType & 0x80000000) != 0;
  405. DWORD dwxfrmType = (DWORD)xfrmType & (~0x80000000);
  406. switch (dwxfrmType)
  407. {
  408. case D3DTRANSFORMSTATE_WORLD:
  409. memcpy(&(m_xfmWorld[0]), pMat, sizeof(D3DMATRIX));
  410. m_dwDirtyFlags |= RRPV_DIRTY_WORLDXFM;
  411. break;
  412. case D3DTRANSFORMSTATE_VIEW:
  413. memcpy(&m_xfmView, pMat, sizeof(D3DMATRIX));
  414. m_dwDirtyFlags |= RRPV_DIRTY_VIEWXFM;
  415. break;
  416. case D3DTRANSFORMSTATE_PROJECTION:
  417. memcpy(&m_xfmProj, pMat, sizeof(D3DMATRIX));
  418. m_dwDirtyFlags |= RRPV_DIRTY_PROJXFM;
  419. break;
  420. case D3DTRANSFORMSTATE_WORLD1:
  421. memcpy(&(m_xfmWorld[1]), pMat, sizeof(D3DMATRIX));
  422. m_dwDirtyFlags |= RRPV_DIRTY_WORLD1XFM;
  423. break;
  424. case D3DTRANSFORMSTATE_WORLD2:
  425. memcpy(&(m_xfmWorld[2]), pMat, sizeof(D3DMATRIX));
  426. m_dwDirtyFlags |= RRPV_DIRTY_WORLD2XFM;
  427. break;
  428. case D3DTRANSFORMSTATE_WORLD3:
  429. memcpy(&(m_xfmWorld[3]), pMat, sizeof(D3DMATRIX));
  430. m_dwDirtyFlags |= RRPV_DIRTY_WORLD3XFM;
  431. break;
  432. case D3DTRANSFORMSTATE_TEXTURE0:
  433. case D3DTRANSFORMSTATE_TEXTURE1:
  434. case D3DTRANSFORMSTATE_TEXTURE2:
  435. case D3DTRANSFORMSTATE_TEXTURE3:
  436. case D3DTRANSFORMSTATE_TEXTURE4:
  437. case D3DTRANSFORMSTATE_TEXTURE5:
  438. case D3DTRANSFORMSTATE_TEXTURE6:
  439. case D3DTRANSFORMSTATE_TEXTURE7:
  440. {
  441. DWORD dwStage = xfrmType - D3DTRANSFORMSTATE_TEXTURE0;
  442. if (bSetIdentity)
  443. {
  444. memcpy(&m_TextureStageState[dwStage].m_dwVal[D3DTSSI_MATRIX], &matIdent, sizeof(D3DMATRIX));
  445. }
  446. else
  447. {
  448. memcpy(&m_TextureStageState[dwStage].m_dwVal[D3DTSSI_MATRIX], pMat, sizeof(D3DMATRIX));
  449. }
  450. }
  451. break;
  452. default:
  453. DPFM(0,TNL,("Ignoring unknown transform type"));
  454. }
  455. }
  456. HRESULT
  457. ReferenceRasterizer::Dp2SetClipPlane(LPD3DHAL_DP2COMMAND pCmd)
  458. {
  459. WORD wNumClipPlanes = pCmd->wStateCount;
  460. LPD3DHAL_DP2SETCLIPPLANE pSetClipPlane =
  461. (LPD3DHAL_DP2SETCLIPPLANE)(pCmd + 1);
  462. for (int i = 0; i < (int) wNumClipPlanes; i++, pSetClipPlane++)
  463. {
  464. _ASSERTf( pSetClipPlane->dwIndex < RRMAX_USER_CLIPPLANES,
  465. ("Refrast does not support %d clip planes",
  466. pSetClipPlane->dwIndex ) );
  467. memcpy( &m_userClipPlanes[pSetClipPlane->dwIndex],
  468. pSetClipPlane->plane, sizeof(RRVECTOR4) );
  469. }
  470. m_dwDirtyFlags |= RRPV_DIRTY_CLIPPLANES;
  471. return D3D_OK;
  472. }
  473. HRESULT
  474. ReferenceRasterizer::Dp2SetExtention(LPD3DHAL_DP2COMMAND pCmd)
  475. {
  476. return D3D_OK;
  477. }
  478. HRESULT
  479. ReferenceRasterizer::Dp2RecRenderStates(DWORD dwFvf, LPD3DHAL_DP2COMMAND pCmd,
  480. LPDWORD lpdwRuntimeRStates )
  481. {
  482. DWORD dwSize = sizeof(D3DHAL_DP2COMMAND) +
  483. pCmd->wStateCount * sizeof(D3DHAL_DP2RENDERSTATE);
  484. return RecordStates((PUINT8)pCmd, dwSize);
  485. }
  486. HRESULT
  487. ReferenceRasterizer::Dp2RecTextureStageState(DWORD dwFvf,
  488. LPD3DHAL_DP2COMMAND pCmd )
  489. {
  490. DWORD dwSize = sizeof(D3DHAL_DP2COMMAND) +
  491. pCmd->wStateCount * sizeof(D3DHAL_DP2TEXTURESTAGESTATE);
  492. return RecordStates((PUINT8)pCmd, dwSize);
  493. }
  494. HRESULT
  495. ReferenceRasterizer::Dp2RecViewport(LPD3DHAL_DP2COMMAND pCmd)
  496. {
  497. return RecordLastState(pCmd, sizeof(D3DHAL_DP2VIEWPORTINFO));
  498. }
  499. HRESULT
  500. ReferenceRasterizer::Dp2RecWRange(LPD3DHAL_DP2COMMAND pCmd)
  501. {
  502. return RecordLastState(pCmd, sizeof(D3DHAL_DP2WINFO));
  503. }
  504. HRESULT
  505. ReferenceRasterizer::Dp2RecZRange(LPD3DHAL_DP2COMMAND pCmd)
  506. {
  507. return RecordLastState(pCmd, sizeof(D3DHAL_DP2ZRANGE));
  508. }
  509. HRESULT
  510. ReferenceRasterizer::Dp2RecMaterial(LPD3DHAL_DP2COMMAND pCmd)
  511. {
  512. return RecordLastState(pCmd, sizeof(D3DHAL_DP2SETMATERIAL));
  513. }
  514. HRESULT
  515. ReferenceRasterizer::Dp2RecCreateLight(LPD3DHAL_DP2COMMAND pCmd)
  516. {
  517. DWORD dwSize = sizeof(D3DHAL_DP2COMMAND) +
  518. pCmd->wStateCount * sizeof(D3DHAL_DP2CREATELIGHT);
  519. return RecordStates((PUINT8)pCmd, dwSize);
  520. }
  521. HRESULT
  522. ReferenceRasterizer::Dp2RecSetLight(LPD3DHAL_DP2COMMAND pCmd,
  523. LPDWORD pdwStride)
  524. {
  525. WORD wNumSetLight = pCmd->wStateCount;
  526. _ASSERT(pdwStride != NULL, "pdwStride is NULL" );
  527. *pdwStride = sizeof(D3DHAL_DP2COMMAND);
  528. LPD3DHAL_DP2SETLIGHT pSetLight = (LPD3DHAL_DP2SETLIGHT)(pCmd + 1);
  529. for (int i = 0; i < wNumSetLight; i++)
  530. {
  531. DWORD dwStride = sizeof(D3DHAL_DP2SETLIGHT);
  532. switch (pSetLight->dwDataType)
  533. {
  534. case D3DHAL_SETLIGHT_ENABLE:
  535. break;
  536. case D3DHAL_SETLIGHT_DISABLE:
  537. break;
  538. case D3DHAL_SETLIGHT_DATA:
  539. dwStride += sizeof(D3DLIGHT7);
  540. break;
  541. }
  542. *pdwStride += dwStride;
  543. // Update the command buffer pointer
  544. pSetLight = (D3DHAL_DP2SETLIGHT *)((LPBYTE)pSetLight +
  545. dwStride);
  546. }
  547. return RecordStates((PUINT8)pCmd, *pdwStride);
  548. }
  549. HRESULT
  550. ReferenceRasterizer::Dp2RecTransform(LPD3DHAL_DP2COMMAND pCmd)
  551. {
  552. DWORD dwSize = sizeof(D3DHAL_DP2COMMAND) +
  553. pCmd->wStateCount * sizeof(D3DHAL_DP2SETTRANSFORM);
  554. return RecordStates((PUINT8)pCmd, dwSize);
  555. }
  556. HRESULT
  557. ReferenceRasterizer::Dp2RecExtention(LPD3DHAL_DP2COMMAND pCmd)
  558. {
  559. return D3D_OK;
  560. }
  561. HRESULT
  562. ReferenceRasterizer::Dp2RecClipPlane(LPD3DHAL_DP2COMMAND pCmd)
  563. {
  564. DWORD dwSize = sizeof(D3DHAL_DP2COMMAND) +
  565. pCmd->wStateCount * sizeof(D3DHAL_DP2SETCLIPPLANE);
  566. return RecordStates((PUINT8)pCmd, dwSize);
  567. }
  568. //-----------------------------------------------------------------------------
  569. //
  570. // RecordStates - This function copies the state data into the internal stateset
  571. // buffer. It assumes that the current state set has already been properly set
  572. // up in BeginStateSet().
  573. //
  574. //-----------------------------------------------------------------------------
  575. HRESULT
  576. ReferenceRasterizer::RecordStates(PUINT8 pData, DWORD dwSize)
  577. {
  578. HRESULT ret;
  579. LPStateSetData pCurStateSets = m_pStateSets.CurrentItem();
  580. DWORD dwCurIdx = pCurStateSets->CurrentIndex();
  581. // Check if the buffer has enough space
  582. if ((ret = pCurStateSets->CheckAndGrow(dwCurIdx + dwSize,
  583. REF_STATESET_GROWDELTA)) != D3D_OK)
  584. {
  585. return ret;
  586. }
  587. // Copy the data and update the ptr.
  588. PUINT8 pDest = (PUINT8)&((*pCurStateSets)[dwCurIdx]);
  589. memcpy(pDest, pData, dwSize);
  590. pCurStateSets->SetCurrentIndex(dwCurIdx + dwSize);
  591. return D3D_OK;
  592. }
  593. HRESULT ReferenceRasterizer::RecordLastState(LPD3DHAL_DP2COMMAND pCmd,
  594. DWORD dwUnitSize)
  595. {
  596. _ASSERT(pCmd->wStateCount != 0, "Number of states to record is zero" );
  597. if (pCmd->wStateCount == 1)
  598. {
  599. return RecordStates((PUINT8)pCmd, sizeof(D3DHAL_DP2COMMAND) + dwUnitSize);
  600. }
  601. else
  602. {
  603. HRESULT ret;
  604. WORD wCount = pCmd->wStateCount;
  605. pCmd->wStateCount = 1;
  606. ret = RecordStates((PUINT8)pCmd, sizeof(D3DHAL_DP2COMMAND));
  607. if (ret != D3D_OK)
  608. {
  609. return ret;
  610. }
  611. ret = RecordStates((PUINT8)(pCmd + 1) + dwUnitSize * (wCount - 1),
  612. dwUnitSize);
  613. if (ret != D3D_OK)
  614. {
  615. return ret;
  616. }
  617. pCmd->wStateCount = wCount;
  618. return D3D_OK;
  619. }
  620. }
  621. HRESULT
  622. ReferenceRasterizer::BeginStateSet(DWORD dwHandle)
  623. {
  624. HRESULT ret;
  625. // Grow the array if no more space left
  626. if ((ret = m_pStateSets.CheckAndGrow(dwHandle)) != D3D_OK)
  627. {
  628. return ret;
  629. }
  630. _ASSERT(m_pStateSets[dwHandle] == NULL, "pStateSets array is NULL" );
  631. // Create the new StateSet
  632. LPStateSetData pNewStateSet = new StateSetData;
  633. if (pNewStateSet == NULL)
  634. {
  635. return DDERR_OUTOFMEMORY;
  636. }
  637. m_pStateSets.SetCurrentIndex(dwHandle);
  638. m_pStateSets.SetCurrentItem(pNewStateSet);
  639. // Switch to record mode
  640. SetRecStateFunctions();
  641. return D3D_OK;
  642. }
  643. HRESULT
  644. ReferenceRasterizer::EndStateSet(void)
  645. {
  646. // Switch to execute mode
  647. SetSetStateFunctions();
  648. return D3D_OK;
  649. }
  650. HRESULT
  651. ReferenceRasterizer::ExecuteStateSet(DWORD dwHandle)
  652. {
  653. HRESULT ret;
  654. if ((ret = m_pStateSets.CheckRange(dwHandle)) != D3D_OK)
  655. {
  656. return ret;
  657. }
  658. LPStateSetData pStateSet = m_pStateSets[dwHandle];
  659. if (pStateSet == NULL)
  660. {
  661. return DDERR_INVALIDPARAMS;
  662. }
  663. LPD3DHAL_DP2COMMAND pCmd = (LPD3DHAL_DP2COMMAND)&((*pStateSet)[0]);
  664. UINT_PTR CmdBoundary = (UINT_PTR)pCmd + pStateSet->CurrentIndex();
  665. // Loop through the data, update render states
  666. for (;;)
  667. {
  668. ret = DoDrawPrimitives2(this,
  669. (UINT16)0,
  670. (DWORD)0,
  671. NULL,
  672. 0,
  673. &pCmd,
  674. NULL,
  675. 0);
  676. if (ret != D3D_OK)
  677. {
  678. return ret;
  679. }
  680. if ((UINT_PTR)pCmd >= CmdBoundary)
  681. break;
  682. }
  683. return D3D_OK;
  684. }
  685. HRESULT
  686. ReferenceRasterizer::DeleteStateSet(DWORD dwHandle)
  687. {
  688. HRESULT ret;
  689. if ((ret = m_pStateSets.CheckRange(dwHandle)) != D3D_OK)
  690. {
  691. return ret;
  692. }
  693. if (m_pStateSets[dwHandle] != NULL)
  694. {
  695. delete m_pStateSets[dwHandle];
  696. m_pStateSets[dwHandle] = NULL;
  697. }
  698. return D3D_OK;
  699. }
  700. HRESULT
  701. ReferenceRasterizer::CaptureStateSet(DWORD dwHandle)
  702. {
  703. HRESULT ret;
  704. if ((ret = m_pStateSets.CheckRange(dwHandle)) != D3D_OK)
  705. {
  706. return ret;
  707. }
  708. LPStateSetData pStateSet = m_pStateSets[dwHandle];
  709. if (pStateSet == NULL)
  710. {
  711. return DDERR_INVALIDPARAMS;
  712. }
  713. BYTE *p = &((*pStateSet)[0]);
  714. UINT_PTR pEnd = (UINT_PTR)(p + pStateSet->CurrentIndex());
  715. while((UINT_PTR)p < pEnd)
  716. {
  717. LPD3DHAL_DP2COMMAND pCmd = (LPD3DHAL_DP2COMMAND)p;
  718. p += sizeof(D3DHAL_DP2COMMAND);
  719. switch(pCmd->bCommand)
  720. {
  721. case D3DDP2OP_RENDERSTATE:
  722. {
  723. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  724. {
  725. LPD3DHAL_DP2RENDERSTATE pData = (LPD3DHAL_DP2RENDERSTATE)p;
  726. pData->dwState = GetRenderState()[pData->RenderState];
  727. p += sizeof(D3DHAL_DP2RENDERSTATE);
  728. }
  729. break;
  730. }
  731. case D3DDP2OP_SETLIGHT:
  732. {
  733. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  734. {
  735. LPD3DHAL_DP2SETLIGHT pData = (LPD3DHAL_DP2SETLIGHT)p;
  736. p += sizeof(D3DHAL_DP2SETLIGHT);
  737. if(pData->dwIndex >= m_dwLightArraySize)
  738. {
  739. return D3DERR_LIGHT_SET_FAILED;
  740. }
  741. switch (pData->dwDataType)
  742. {
  743. case D3DHAL_SETLIGHT_ENABLE:
  744. if(!m_pLightArray[pData->dwIndex].IsEnabled())
  745. pData->dwDataType = D3DHAL_SETLIGHT_DISABLE;
  746. break;
  747. case D3DHAL_SETLIGHT_DISABLE:
  748. if(m_pLightArray[pData->dwIndex].IsEnabled())
  749. pData->dwDataType = D3DHAL_SETLIGHT_ENABLE;
  750. break;
  751. case D3DHAL_SETLIGHT_DATA:
  752. m_pLightArray[pData->dwIndex].GetLight((LPD3DLIGHT7)p);
  753. p += sizeof(D3DLIGHT7);
  754. break;
  755. }
  756. }
  757. break;
  758. }
  759. case D3DDP2OP_SETMATERIAL:
  760. {
  761. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  762. {
  763. LPD3DHAL_DP2SETMATERIAL pData = (LPD3DHAL_DP2SETMATERIAL)p;
  764. *pData = m_Material;
  765. p += sizeof(D3DHAL_DP2SETMATERIAL);
  766. }
  767. break;
  768. }
  769. case D3DDP2OP_SETTRANSFORM:
  770. {
  771. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  772. {
  773. LPD3DHAL_DP2SETTRANSFORM pData = (LPD3DHAL_DP2SETTRANSFORM)p;
  774. switch(pData->xfrmType)
  775. {
  776. case D3DTRANSFORMSTATE_WORLD:
  777. pData->matrix = m_xfmWorld[0];
  778. break;
  779. case D3DTRANSFORMSTATE_WORLD1:
  780. pData->matrix = m_xfmWorld[1];
  781. break;
  782. case D3DTRANSFORMSTATE_WORLD2:
  783. pData->matrix = m_xfmWorld[2];
  784. break;
  785. case D3DTRANSFORMSTATE_WORLD3:
  786. pData->matrix = m_xfmWorld[3];
  787. break;
  788. case D3DTRANSFORMSTATE_VIEW:
  789. pData->matrix = m_xfmView;
  790. break;
  791. case D3DTRANSFORMSTATE_PROJECTION:
  792. pData->matrix = m_xfmProj;
  793. break;
  794. case D3DTRANSFORMSTATE_TEXTURE0:
  795. case D3DTRANSFORMSTATE_TEXTURE1:
  796. case D3DTRANSFORMSTATE_TEXTURE2:
  797. case D3DTRANSFORMSTATE_TEXTURE3:
  798. case D3DTRANSFORMSTATE_TEXTURE4:
  799. case D3DTRANSFORMSTATE_TEXTURE5:
  800. case D3DTRANSFORMSTATE_TEXTURE6:
  801. case D3DTRANSFORMSTATE_TEXTURE7:
  802. pData->matrix = *((LPD3DMATRIX)&m_TextureStageState[pData->xfrmType - D3DTRANSFORMSTATE_TEXTURE0].m_dwVal[D3DTSSI_MATRIX]);
  803. break;
  804. }
  805. p += sizeof(D3DHAL_DP2SETTRANSFORM);
  806. }
  807. break;
  808. }
  809. case D3DDP2OP_TEXTURESTAGESTATE:
  810. {
  811. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  812. {
  813. LPD3DHAL_DP2TEXTURESTAGESTATE pData = (LPD3DHAL_DP2TEXTURESTAGESTATE)p;
  814. pData->dwValue = m_TextureStageState[pData->wStage].m_dwVal[pData->TSState];
  815. p += sizeof(D3DHAL_DP2TEXTURESTAGESTATE);
  816. }
  817. break;
  818. }
  819. case D3DDP2OP_VIEWPORTINFO:
  820. {
  821. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  822. {
  823. D3DVIEWPORT7 viewport;
  824. LPD3DHAL_DP2VIEWPORTINFO lpVwpData = (LPD3DHAL_DP2VIEWPORTINFO)p;
  825. lpVwpData->dwX = m_Viewport.dwX;
  826. lpVwpData->dwY = m_Viewport.dwY;
  827. lpVwpData->dwWidth = m_Viewport.dwWidth;
  828. lpVwpData->dwHeight = m_Viewport.dwHeight;
  829. p += sizeof(D3DHAL_DP2VIEWPORTINFO);
  830. }
  831. break;
  832. }
  833. case D3DDP2OP_ZRANGE:
  834. {
  835. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  836. {
  837. LPD3DHAL_DP2ZRANGE pData = (LPD3DHAL_DP2ZRANGE)p;
  838. pData->dvMinZ = m_Viewport.dvMinZ;
  839. pData->dvMaxZ = m_Viewport.dvMaxZ;
  840. p += sizeof(D3DHAL_DP2ZRANGE);
  841. }
  842. break;
  843. }
  844. case D3DDP2OP_SETCLIPPLANE:
  845. {
  846. for(DWORD i = 0; i < (DWORD)pCmd->wStateCount; ++i)
  847. {
  848. LPD3DHAL_DP2SETCLIPPLANE pData = (LPD3DHAL_DP2SETCLIPPLANE)p;
  849. *((LPRRVECTOR4)pData->plane) = m_userClipPlanes[pData->dwIndex];
  850. p += sizeof(D3DHAL_DP2SETCLIPPLANE);
  851. }
  852. break;
  853. }
  854. default:
  855. _ASSERT(FALSE, "Ununderstood DP2 command in Capture");
  856. }
  857. }
  858. return D3D_OK;
  859. }
  860. //-----------------------------------------------------------------------------
  861. //
  862. // SetRenderState -
  863. //
  864. //-----------------------------------------------------------------------------
  865. void
  866. ReferenceRasterizer::SetRenderState( DWORD dwState, DWORD dwValue )
  867. {
  868. // check for range before continuing
  869. if ( dwState >= D3DHAL_MAX_RSTATES )
  870. {
  871. return;
  872. }
  873. // set value in internal object
  874. m_dwRenderState[dwState] = dwValue;
  875. // do special validation work for some render states
  876. switch ( dwState )
  877. {
  878. case D3DRENDERSTATE_ANTIALIAS:
  879. m_bFragmentProcessingEnabled =
  880. ( D3DANTIALIAS_SORTINDEPENDENT == dwValue );
  881. break;
  882. case D3DRENDERSTATE_LIGHTING:
  883. if (dwValue)
  884. m_dwTLState |= RRPV_DOLIGHTING;
  885. else
  886. m_dwTLState &= ~RRPV_DOLIGHTING;
  887. break;
  888. case D3DRENDERSTATE_CLIPPING:
  889. if (dwValue)
  890. m_dwTLState |= RRPV_DOCLIPPING;
  891. else
  892. m_dwTLState &= ~RRPV_DOCLIPPING;
  893. break;
  894. case D3DRENDERSTATE_NORMALIZENORMALS:
  895. {
  896. if (dwValue)
  897. m_dwTLState |= RRPV_NORMALIZENORMALS;
  898. else
  899. m_dwTLState &= ~RRPV_NORMALIZENORMALS;
  900. }
  901. break;
  902. case D3DRENDERSTATE_LOCALVIEWER:
  903. {
  904. if (dwValue)
  905. m_dwTLState |= RRPV_LOCALVIEWER;
  906. else
  907. m_dwTLState &= ~RRPV_LOCALVIEWER;
  908. }
  909. break;
  910. case D3DRENDERSTATE_SPECULARENABLE:
  911. {
  912. if (dwValue)
  913. m_dwTLState |= RRPV_DOSPECULAR;
  914. else
  915. m_dwTLState &= ~RRPV_DOSPECULAR;
  916. }
  917. break;
  918. case D3DRENDERSTATE_COLORVERTEX:
  919. case D3DRENDERSTATE_AMBIENTMATERIALSOURCE:
  920. case D3DRENDERSTATE_DIFFUSEMATERIALSOURCE:
  921. case D3DRENDERSTATE_SPECULARMATERIALSOURCE:
  922. case D3DRENDERSTATE_EMISSIVEMATERIALSOURCE:
  923. m_dwDirtyFlags |= RRPV_DIRTY_COLORVTX;
  924. break;
  925. case D3DRENDERSTATE_FOGCOLOR:
  926. {
  927. m_lighting.fog_color = (D3DCOLOR) dwValue;
  928. m_dwDirtyFlags |= RRPV_DIRTY_FOG;
  929. }
  930. break;
  931. case D3DRENDERSTATE_FOGTABLESTART:
  932. {
  933. m_lighting.fog_start = *(D3DVALUE*)&dwValue;
  934. m_dwDirtyFlags |= RRPV_DIRTY_FOG;
  935. }
  936. break;
  937. case D3DRENDERSTATE_FOGTABLEEND:
  938. {
  939. m_lighting.fog_end = *(D3DVALUE*)&dwValue;
  940. m_dwDirtyFlags |= RRPV_DIRTY_FOG;
  941. }
  942. break;
  943. case D3DRENDERSTATE_FOGTABLEDENSITY:
  944. {
  945. m_lighting.fog_density = *(D3DVALUE*)&dwValue;
  946. m_dwDirtyFlags |= RRPV_DIRTY_FOG;
  947. }
  948. break;
  949. case D3DRENDERSTATE_FOGVERTEXMODE:
  950. {
  951. m_lighting.fog_mode = (int) dwValue;
  952. m_dwDirtyFlags |= RRPV_DIRTY_FOG;
  953. }
  954. break;
  955. case D3DRENDERSTATE_AMBIENT:
  956. {
  957. m_lighting.ambient_red = D3DVAL(RGBA_GETRED(dwValue))/D3DVALUE(255);
  958. m_lighting.ambient_green = D3DVAL(RGBA_GETGREEN(dwValue))/D3DVALUE(255);
  959. m_lighting.ambient_blue = D3DVAL(RGBA_GETBLUE(dwValue))/D3DVALUE(255);
  960. m_lighting.ambient_save = dwValue;
  961. m_dwDirtyFlags |= RRPV_DIRTY_MATERIAL;
  962. }
  963. break;
  964. //
  965. // map legacy texture to multi-texture stage 0
  966. //
  967. case D3DRENDERSTATE_TEXTUREMAPBLEND:
  968. // map legacy blending state to texture stage 0
  969. MapLegacyTextureBlend();
  970. break;
  971. // map legacy modes with one-to-one mappings to texture stage 0
  972. case D3DRENDERSTATE_TEXTUREADDRESS:
  973. m_TextureStageState[0].m_dwVal[D3DTSS_ADDRESS] =
  974. m_TextureStageState[0].m_dwVal[D3DTSS_ADDRESSU] =
  975. m_TextureStageState[0].m_dwVal[D3DTSS_ADDRESSV] = dwValue;
  976. break;
  977. case D3DRENDERSTATE_TEXTUREADDRESSU:
  978. m_TextureStageState[0].m_dwVal[D3DTSS_ADDRESSU] = dwValue;
  979. break;
  980. case D3DRENDERSTATE_TEXTUREADDRESSV:
  981. m_TextureStageState[0].m_dwVal[D3DTSS_ADDRESSV] = dwValue;
  982. break;
  983. case D3DRENDERSTATE_MIPMAPLODBIAS:
  984. m_TextureStageState[0].m_dwVal[D3DTSS_MIPMAPLODBIAS] = dwValue;
  985. break;
  986. case D3DRENDERSTATE_BORDERCOLOR:
  987. m_TextureStageState[0].m_dwVal[D3DTSS_BORDERCOLOR] = dwValue;
  988. break;
  989. case D3DRENDERSTATE_ANISOTROPY:
  990. m_TextureStageState[0].m_dwVal[D3DTSS_MAXANISOTROPY] = dwValue;
  991. // fall thru to update filter state
  992. case D3DRENDERSTATE_TEXTUREMAG:
  993. case D3DRENDERSTATE_TEXTUREMIN:
  994. // map legacy filtering/sampling state to texture stage 0
  995. MapLegacyTextureFilter();
  996. break;
  997. case D3DRENDERSTATE_TEXTUREHANDLE:
  998. // map thru to set handle for first stage
  999. SetTextureStageState( 0, D3DTSS_TEXTUREMAP, dwValue );
  1000. break;
  1001. //
  1002. // map legacy WRAPU/V state through to controls for tex coord 0
  1003. //
  1004. case D3DRENDERSTATE_WRAPU:
  1005. m_dwRenderState[D3DRENDERSTATE_WRAP0] &= ~D3DWRAP_U;
  1006. m_dwRenderState[D3DRENDERSTATE_WRAP0] |= ((dwValue) ? D3DWRAP_U : 0);
  1007. break;
  1008. case D3DRENDERSTATE_WRAPV:
  1009. m_dwRenderState[D3DRENDERSTATE_WRAP0] &= ~D3DWRAP_V;
  1010. m_dwRenderState[D3DRENDERSTATE_WRAP0] |= ((dwValue) ? D3DWRAP_V : 0);
  1011. break;
  1012. //
  1013. // Scene Capture
  1014. //
  1015. case D3DRENDERSTATE_SCENECAPTURE:
  1016. if (dwValue)
  1017. SceneCapture(D3DHAL_SCENE_CAPTURE_START);
  1018. else
  1019. SceneCapture(D3DHAL_SCENE_CAPTURE_END);
  1020. break;
  1021. case D3DRENDERSTATE_CLIPPLANEENABLE:
  1022. m_dwDirtyFlags |= RRPV_DIRTY_CLIPPLANES;
  1023. break;
  1024. #ifdef __POINTSPRITES
  1025. case D3DRENDERSTATE_POINTSIZE:
  1026. m_fPointSize = m_fRenderState[dwState];
  1027. break;
  1028. case D3DRENDERSTATE_POINTATTENUATION_A:
  1029. m_fPointAttA = m_fRenderState[dwState];
  1030. break;
  1031. case D3DRENDERSTATE_POINTATTENUATION_B:
  1032. m_fPointAttB = m_fRenderState[dwState];
  1033. break;
  1034. case D3DRENDERSTATE_POINTATTENUATION_C:
  1035. m_fPointAttC = m_fRenderState[dwState];
  1036. break;
  1037. case D3DRENDERSTATE_POINTSIZEMIN:
  1038. m_fPointSizeMin = m_fRenderState[dwState];
  1039. break;
  1040. #endif //__POINTSPRITES
  1041. }
  1042. }
  1043. extern DWORD __stdcall
  1044. RefRastSetRenderTarget(LPD3DHAL_SETRENDERTARGETDATA pTgtData);
  1045. HRESULT ReferenceRasterizer::Dp2SetRenderTarget(LPD3DHAL_DP2COMMAND pCmd)
  1046. {
  1047. D3DHAL_SETRENDERTARGETDATA SRTDataOld;
  1048. LPD3DHAL_DP2SETRENDERTARGET pSRTData;
  1049. BOOL bIsNew = FALSE;
  1050. HRESULT hr;
  1051. // Get new data by ignoring all but the last structure
  1052. pSRTData = (D3DHAL_DP2SETRENDERTARGET*)(pCmd + 1) + (pCmd->wStateCount - 1);
  1053. // Fill SRTDataOld with the info from the last SRTData struct
  1054. // in the command
  1055. DWORD handle = pSRTData->hRenderTarget;
  1056. SRTDataOld.dwhContext = (ULONG_PTR)this;
  1057. SRTDataOld.lpDDSLcl = GetDDSurfaceLocal(m_pDDLcl, handle, &bIsNew);
  1058. if( SRTDataOld.lpDDSLcl->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
  1059. {
  1060. if (handle >= m_dwTexArrayLength)
  1061. {
  1062. HR_RET(GrowTexArray( handle ));
  1063. }
  1064. if (m_ppTextureArray[handle] == NULL)
  1065. {
  1066. if (TextureCreate(handle, &m_ppTextureArray[handle])
  1067. == FALSE)
  1068. {
  1069. return DDERR_OUTOFMEMORY;
  1070. }
  1071. HR_RET(m_ppTextureArray[handle]->Initialize(
  1072. SRTDataOld.lpDDSLcl ));
  1073. }
  1074. else if( bIsNew )
  1075. {
  1076. HR_RET(m_ppTextureArray[handle]->Initialize(
  1077. SRTDataOld.lpDDSLcl ));
  1078. }
  1079. }
  1080. if( pSRTData->hZBuffer )
  1081. {
  1082. bIsNew = FALSE;
  1083. handle = pSRTData->hZBuffer;
  1084. SRTDataOld.lpDDSZLcl = GetDDSurfaceLocal(m_pDDLcl, pSRTData->hZBuffer,
  1085. &bIsNew);
  1086. if( SRTDataOld.lpDDSZLcl->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
  1087. {
  1088. if (handle >= m_dwTexArrayLength)
  1089. {
  1090. HR_RET(GrowTexArray( handle ));
  1091. }
  1092. if (m_ppTextureArray[handle] == NULL)
  1093. {
  1094. if (TextureCreate(handle, &m_ppTextureArray[handle])
  1095. == FALSE)
  1096. {
  1097. return DDERR_OUTOFMEMORY;
  1098. }
  1099. HR_RET(m_ppTextureArray[handle]->Initialize(
  1100. SRTDataOld.lpDDSZLcl ));
  1101. }
  1102. else if( bIsNew )
  1103. {
  1104. HR_RET(m_ppTextureArray[handle]->Initialize(
  1105. SRTDataOld.lpDDSZLcl ));
  1106. }
  1107. }
  1108. }
  1109. else
  1110. SRTDataOld.lpDDSZLcl = NULL;
  1111. // Need to unlock the current target, first
  1112. RefRastUnlockTarget(this);
  1113. // Call the old function
  1114. if ((hr = RefRastSetRenderTarget(&SRTDataOld)) != DDHAL_DRIVER_HANDLED)
  1115. return hr;
  1116. // Lock the new render target
  1117. RefRastLockTarget(this);
  1118. return SRTDataOld.ddrval;
  1119. }