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.

2159 lines
70 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // refrastfn.cpp
  4. //
  5. // Reference rasterizer callback functions for D3DIM.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. // Primitive functions
  13. #include "primfns.hpp"
  14. #define MAX_CLIPPING_PLANES 12
  15. #define MAX_CLIP_VERTICES (( 2 * MAX_CLIPPING_PLANES ) + 3 )
  16. #define MAX_VERTEX_COUNT 2048
  17. #define BASE_VERTEX_COUNT (MAX_VERTEX_COUNT - MAX_CLIP_VERTICES)
  18. HRESULT
  19. RefRastLockTarget(ReferenceRasterizer *pRefRast);
  20. void
  21. RefRastUnlockTarget(ReferenceRasterizer *pRefRast);
  22. HRESULT
  23. RefRastLockTexture(ReferenceRasterizer *pRefRast);
  24. void
  25. RefRastUnlockTexture(ReferenceRasterizer *pRefRast);
  26. //----------------------------------------------------------------------------
  27. //
  28. // Stiches together device descs
  29. //
  30. //----------------------------------------------------------------------------
  31. void
  32. D3DDeviceDescConvert(LPD3DDEVICEDESC7 lpOut,
  33. LPD3DDEVICEDESC_V1 lpV1,
  34. LPD3DHAL_D3DEXTENDEDCAPS lpExt)
  35. {
  36. if(lpV1!=NULL)
  37. {
  38. lpOut->dwDevCaps = lpV1->dwDevCaps;
  39. lpOut->dpcLineCaps = lpV1->dpcLineCaps;
  40. lpOut->dpcTriCaps = lpV1->dpcTriCaps;
  41. lpOut->dwDeviceRenderBitDepth = lpV1->dwDeviceRenderBitDepth;
  42. lpOut->dwDeviceZBufferBitDepth = lpV1->dwDeviceZBufferBitDepth;
  43. }
  44. if (lpExt)
  45. {
  46. // DX5
  47. lpOut->dwMinTextureWidth = lpExt->dwMinTextureWidth;
  48. lpOut->dwMaxTextureWidth = lpExt->dwMaxTextureWidth;
  49. lpOut->dwMinTextureHeight = lpExt->dwMinTextureHeight;
  50. lpOut->dwMaxTextureHeight = lpExt->dwMaxTextureHeight;
  51. // DX6
  52. lpOut->dwMaxTextureRepeat = lpExt->dwMaxTextureRepeat;
  53. lpOut->dwMaxTextureAspectRatio = lpExt->dwMaxTextureAspectRatio;
  54. lpOut->dwMaxAnisotropy = lpExt->dwMaxAnisotropy;
  55. lpOut->dvGuardBandLeft = lpExt->dvGuardBandLeft;
  56. lpOut->dvGuardBandTop = lpExt->dvGuardBandTop;
  57. lpOut->dvGuardBandRight = lpExt->dvGuardBandRight;
  58. lpOut->dvGuardBandBottom = lpExt->dvGuardBandBottom;
  59. lpOut->dvExtentsAdjust = lpExt->dvExtentsAdjust;
  60. lpOut->dwStencilCaps = lpExt->dwStencilCaps;
  61. lpOut->dwFVFCaps = lpExt->dwFVFCaps;
  62. lpOut->dwTextureOpCaps = lpExt->dwTextureOpCaps;
  63. lpOut->wMaxTextureBlendStages = lpExt->wMaxTextureBlendStages;
  64. lpOut->wMaxSimultaneousTextures = lpExt->wMaxSimultaneousTextures;
  65. // DX7
  66. lpOut->dwMaxActiveLights = lpExt->dwMaxActiveLights;
  67. lpOut->dvMaxVertexW = lpExt->dvMaxVertexW;
  68. lpOut->wMaxUserClipPlanes = lpExt->wMaxUserClipPlanes;
  69. lpOut->wMaxVertexBlendMatrices = lpExt->wMaxVertexBlendMatrices;
  70. lpOut->dwVertexProcessingCaps = lpExt->dwVertexProcessingCaps;
  71. lpOut->dwReserved1 = lpExt->dwReserved1;
  72. lpOut->dwReserved2 = lpExt->dwReserved2;
  73. lpOut->dwReserved3 = lpExt->dwReserved3;
  74. lpOut->dwReserved4 = lpExt->dwReserved4;
  75. }
  76. }
  77. //----------------------------------------------------------------------------
  78. //
  79. // FindOutSurfFormat
  80. //
  81. // Converts a DDPIXELFORMAT to RRSurfaceType.
  82. //
  83. //----------------------------------------------------------------------------
  84. HRESULT FASTCALL
  85. FindOutSurfFormat(LPDDPIXELFORMAT pDdPixFmt, RRSurfaceType *pFmt)
  86. {
  87. if (pDdPixFmt->dwFlags & DDPF_ZBUFFER)
  88. {
  89. switch(pDdPixFmt->dwZBitMask)
  90. {
  91. default:
  92. case 0x0000FFFF: *pFmt = RR_STYPE_Z16S0; break;
  93. case 0xFFFFFF00:
  94. if (pDdPixFmt->dwStencilBitMask == 0x000000FF)
  95. {
  96. *pFmt = RR_STYPE_Z24S8;
  97. }
  98. else
  99. {
  100. *pFmt = RR_STYPE_Z24S4;
  101. }
  102. break;
  103. case 0x00FFFFFF:
  104. if (pDdPixFmt->dwStencilBitMask == 0xFF000000)
  105. {
  106. *pFmt = RR_STYPE_S8Z24;
  107. }
  108. else
  109. {
  110. *pFmt = RR_STYPE_S4Z24;
  111. }
  112. break;
  113. case 0x0000FFFE: *pFmt = RR_STYPE_Z15S1; break;
  114. case 0x00007FFF: *pFmt = RR_STYPE_S1Z15; break;
  115. case 0xFFFFFFFF: *pFmt = RR_STYPE_Z32S0; break;
  116. }
  117. }
  118. else if (pDdPixFmt->dwFlags & DDPF_BUMPDUDV)
  119. {
  120. UINT uFmt = pDdPixFmt->dwBumpDvBitMask;
  121. switch (uFmt)
  122. {
  123. case 0x0000ff00:
  124. switch (pDdPixFmt->dwRGBBitCount)
  125. {
  126. case 24:
  127. *pFmt = RR_STYPE_U8V8L8;
  128. break;
  129. case 16:
  130. *pFmt = RR_STYPE_U8V8;
  131. break;
  132. }
  133. break;
  134. case 0x000003e0:
  135. *pFmt = RR_STYPE_U5V5L6;
  136. break;
  137. }
  138. }
  139. else if (pDdPixFmt->dwFlags & DDPF_PALETTEINDEXED8)
  140. {
  141. *pFmt = RR_STYPE_PALETTE8;
  142. }
  143. else if (pDdPixFmt->dwFlags & DDPF_PALETTEINDEXED4)
  144. {
  145. *pFmt = RR_STYPE_PALETTE4;
  146. }
  147. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('U', 'Y', 'V', 'Y'))
  148. {
  149. *pFmt = RR_STYPE_UYVY;
  150. }
  151. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('Y', 'U', 'Y', '2'))
  152. {
  153. *pFmt = RR_STYPE_YUY2;
  154. }
  155. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '1'))
  156. {
  157. *pFmt = RR_STYPE_DXT1;
  158. }
  159. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '2'))
  160. {
  161. *pFmt = RR_STYPE_DXT2;
  162. }
  163. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '3'))
  164. {
  165. *pFmt = RR_STYPE_DXT3;
  166. }
  167. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '4'))
  168. {
  169. *pFmt = RR_STYPE_DXT4;
  170. }
  171. else if (pDdPixFmt->dwFourCC == MAKEFOURCC('D', 'X', 'T', '5'))
  172. {
  173. *pFmt = RR_STYPE_DXT5;
  174. }
  175. else
  176. {
  177. UINT uFmt = pDdPixFmt->dwGBitMask | pDdPixFmt->dwRBitMask;
  178. if (pDdPixFmt->dwFlags & DDPF_ALPHAPIXELS)
  179. {
  180. uFmt |= pDdPixFmt->dwRGBAlphaBitMask;
  181. }
  182. switch (uFmt)
  183. {
  184. case 0x00ffff00:
  185. switch (pDdPixFmt->dwRGBBitCount)
  186. {
  187. case 32:
  188. *pFmt = RR_STYPE_B8G8R8X8;
  189. break;
  190. case 24:
  191. *pFmt = RR_STYPE_B8G8R8;
  192. break;
  193. }
  194. break;
  195. case 0xffffff00:
  196. *pFmt = RR_STYPE_B8G8R8A8;
  197. break;
  198. case 0xffe0:
  199. if (pDdPixFmt->dwFlags & DDPF_ALPHAPIXELS)
  200. {
  201. *pFmt = RR_STYPE_B5G5R5A1;
  202. }
  203. else
  204. {
  205. *pFmt = RR_STYPE_B5G6R5;
  206. }
  207. break;
  208. case 0x07fe0:
  209. *pFmt = RR_STYPE_B5G5R5;
  210. break;
  211. case 0xff0:
  212. *pFmt = RR_STYPE_B4G4R4;
  213. break;
  214. case 0xfff0:
  215. *pFmt = RR_STYPE_B4G4R4A4;
  216. break;
  217. case 0xff:
  218. if (pDdPixFmt->dwFlags & DDPF_ALPHAPIXELS)
  219. {
  220. *pFmt = RR_STYPE_L4A4;
  221. }
  222. else
  223. {
  224. *pFmt = RR_STYPE_L8;
  225. }
  226. break;
  227. case 0xffff:
  228. *pFmt = RR_STYPE_L8A8;
  229. break;
  230. case 0xfc:
  231. *pFmt = RR_STYPE_B2G3R3;
  232. break;
  233. case 0xfffc:
  234. *pFmt = RR_STYPE_B2G3R3A8;
  235. break;
  236. default:
  237. *pFmt = RR_STYPE_NULL;
  238. break;
  239. }
  240. }
  241. return D3D_OK;
  242. }
  243. //----------------------------------------------------------------------------
  244. //
  245. // ValidTextureSize
  246. //
  247. // checks for power of two texture size
  248. //
  249. //----------------------------------------------------------------------------
  250. BOOL FASTCALL
  251. ValidTextureSize(INT16 iuSize, INT16 iuShift,
  252. INT16 ivSize, INT16 ivShift)
  253. {
  254. if (iuSize == 1)
  255. {
  256. if (ivSize == 1)
  257. {
  258. return TRUE;
  259. }
  260. else
  261. {
  262. return !(ivSize & (~(1 << ivShift)));
  263. }
  264. }
  265. else
  266. {
  267. if (ivSize == 1)
  268. {
  269. return !(iuSize & (~(1 << iuShift)));
  270. }
  271. else
  272. {
  273. return (!(iuSize & (~(1 << iuShift)))
  274. && !(iuSize & (~(1 << iuShift))));
  275. }
  276. }
  277. }
  278. //----------------------------------------------------------------------------
  279. //
  280. // ValidMipmapSize
  281. //
  282. // Computes size of next smallest mipmap level, clamping at 1
  283. //
  284. //----------------------------------------------------------------------------
  285. BOOL FASTCALL
  286. ValidMipmapSize(INT16 iPreSize, INT16 iSize)
  287. {
  288. if (iPreSize == 1)
  289. {
  290. if (iSize == 1)
  291. {
  292. return TRUE;
  293. }
  294. else
  295. {
  296. return FALSE;
  297. }
  298. }
  299. else
  300. {
  301. return ((iPreSize >> 1) == iSize);
  302. }
  303. }
  304. //----------------------------------------------------------------------------
  305. //
  306. // RefRastLockTarget
  307. //
  308. // Lock current RenderTarget.
  309. //
  310. //----------------------------------------------------------------------------
  311. HRESULT
  312. RefRastLockTarget(ReferenceRasterizer *pRefRast)
  313. {
  314. HRESULT hr;
  315. RRRenderTarget *pRrTarget;
  316. pRrTarget = pRefRast->GetRenderTarget();
  317. HR_RET(LockSurface(pRrTarget->m_pDDSLcl, (LPVOID*)&(pRrTarget->m_pColorBufBits)));
  318. if (pRrTarget->m_pDDSZLcl)
  319. {
  320. HR_RET(LockSurface(pRrTarget->m_pDDSZLcl,
  321. (LPVOID*)&(pRrTarget->m_pDepthBufBits)));
  322. }
  323. else
  324. {
  325. pRrTarget->m_pDepthBufBits = NULL;
  326. }
  327. return D3D_OK;
  328. }
  329. //----------------------------------------------------------------------------
  330. //
  331. // RefRastUnlockTexture
  332. //
  333. // Unlock current RenderTarget.
  334. //
  335. //----------------------------------------------------------------------------
  336. void
  337. RefRastUnlockTarget(ReferenceRasterizer *pRefRast)
  338. {
  339. RRRenderTarget *pRrTarget;
  340. pRrTarget = pRefRast->GetRenderTarget();
  341. UnlockSurface(pRrTarget->m_pDDSLcl);
  342. if (pRrTarget->m_pDDSZLcl)
  343. {
  344. UnlockSurface(pRrTarget->m_pDDSZLcl);
  345. }
  346. }
  347. //----------------------------------------------------------------------------
  348. //
  349. // RRTextureMapSetSizes
  350. //
  351. // Sets sizes, pitches, etc, based on the current iFirstSurf.
  352. //
  353. //----------------------------------------------------------------------------
  354. static HRESULT RRTextureMapSetSizes( RRTexture *pRRTex, INT iFirstSurf, INT cEnvMap )
  355. {
  356. LPDDRAWI_DDRAWSURFACE_LCL pDDSLcl = pRRTex->m_pDDSLcl[iFirstSurf];
  357. RRSurfaceType SurfType = pRRTex->m_SurfType;
  358. INT i, j;
  359. // Init texturemap.
  360. pRRTex->m_iWidth = DDSurf_Width( pDDSLcl );
  361. pRRTex->m_iHeight = DDSurf_Height( pDDSLcl );
  362. for ( j = 0; j < cEnvMap; j++ )
  363. {
  364. if ((SurfType == RR_STYPE_DXT1) ||
  365. (SurfType == RR_STYPE_DXT2) ||
  366. (SurfType == RR_STYPE_DXT3) ||
  367. (SurfType == RR_STYPE_DXT4) ||
  368. (SurfType == RR_STYPE_DXT5))
  369. {
  370. // Note, here is the assumption that:
  371. // 1) width and height are reported correctly by the driver that
  372. // created the surface
  373. // 2) The allocation of the memory is contiguous (as done by hel)
  374. pRRTex->m_iPitch[j] = ((pRRTex->m_iWidth+3)>>2) *
  375. g_DXTBlkSize[(int)SurfType - (int)RR_STYPE_DXT1];
  376. }
  377. else
  378. {
  379. pRRTex->m_iPitch[j] = DDSurf_Pitch( pDDSLcl );
  380. }
  381. }
  382. // Check if the texture size is power of 2
  383. if (!ValidTextureSize((INT16)pRRTex->m_iWidth, (INT16)IntLog2(pRRTex->m_iWidth),
  384. (INT16)pRRTex->m_iHeight, (INT16)IntLog2(pRRTex->m_iHeight)))
  385. {
  386. return DDERR_INVALIDPARAMS;
  387. }
  388. // Check for mipmap if any.
  389. // iPreSizeU and iPreSizeV store the size(u and v) of the previous level
  390. // mipmap. They are init'ed with the first texture size.
  391. INT16 iPreSizeU = (INT16)pRRTex->m_iWidth, iPreSizeV = (INT16)pRRTex->m_iHeight;
  392. for ( i = iFirstSurf + cEnvMap; i <= pRRTex->m_cLOD*cEnvMap; i += cEnvMap)
  393. {
  394. for ( j = 0; j < cEnvMap; j++ )
  395. {
  396. pDDSLcl = pRRTex->m_pDDSLcl[i+j];
  397. if (NULL == pDDSLcl) continue;
  398. if ((SurfType == RR_STYPE_DXT1) ||
  399. (SurfType == RR_STYPE_DXT2) ||
  400. (SurfType == RR_STYPE_DXT3) ||
  401. (SurfType == RR_STYPE_DXT4) ||
  402. (SurfType == RR_STYPE_DXT5))
  403. {
  404. // Note, here is the assumption that:
  405. // 1) width and height are reported correctly by the driver that
  406. // created the surface
  407. // 2) The allocation of the memory is contiguous (as done by hel)
  408. pRRTex->m_iPitch[i-iFirstSurf+j] =
  409. ((DDSurf_Width( pDDSLcl )+3)>>2) *
  410. g_DXTBlkSize[(int)SurfType - (int)RR_STYPE_DXT1];
  411. }
  412. else
  413. {
  414. pRRTex->m_iPitch[i-iFirstSurf+j] = DDSurf_Pitch( pDDSLcl );
  415. }
  416. if (j == 0)
  417. {
  418. // Check for invalid mipmap texture size
  419. if (!ValidMipmapSize(iPreSizeU, (INT16)DDSurf_Width( pDDSLcl )) ||
  420. !ValidMipmapSize(iPreSizeV, (INT16)DDSurf_Height( pDDSLcl )))
  421. {
  422. return DDERR_INVALIDPARAMS;
  423. }
  424. }
  425. iPreSizeU = (INT16)DDSurf_Width( pDDSLcl );
  426. iPreSizeV = (INT16)DDSurf_Height( pDDSLcl );
  427. }
  428. }
  429. return D3D_OK;
  430. }
  431. //----------------------------------------------------------------------------
  432. //
  433. // RefRastLockTexture
  434. //
  435. // Lock current texture surface before the texture bits are accessed.
  436. //
  437. //----------------------------------------------------------------------------
  438. HRESULT
  439. RefRastLockTexture(ReferenceRasterizer *pRefRast)
  440. {
  441. INT i, j, k;
  442. RRTexture* pRRTex[D3DHAL_TSS_MAXSTAGES];
  443. D3DTEXTUREHANDLE phTex[D3DHAL_TSS_MAXSTAGES];
  444. HRESULT hr;
  445. int cActTex;
  446. if ((cActTex = pRefRast->GetCurrentTextureMaps(phTex, pRRTex)) == 0)
  447. {
  448. return D3D_OK;
  449. }
  450. for (j = 0; j < cActTex; j++)
  451. {
  452. // stages may not have texture bound
  453. if ( NULL == pRRTex[j] ) continue;
  454. // Don't lock anything that is currently locked
  455. if ((pRRTex[j]->m_uFlags & RR_TEXTURE_LOCKED) == 0)
  456. {
  457. INT32 iMaxMipLevels = 0;
  458. if ( NULL != pRRTex[j]->m_pStageState )
  459. {
  460. iMaxMipLevels = pRRTex[j]->m_pStageState->m_dwVal[D3DTSS_MAXMIPLEVEL];
  461. }
  462. INT iFirstSurf = min(iMaxMipLevels, pRRTex[j]->m_cLODDDS);
  463. INT cEnvMap = (pRRTex[j]->m_uFlags & RR_TEXTURE_ENVMAP) ? (6) : (1);
  464. iFirstSurf *= cEnvMap;
  465. HR_RET(RRTextureMapSetSizes(pRRTex[j], iFirstSurf, cEnvMap));
  466. for (i = iFirstSurf; i <= pRRTex[j]->m_cLODDDS*cEnvMap; i += cEnvMap)
  467. {
  468. for ( k = 0; k < cEnvMap; k++ )
  469. {
  470. hr = LockSurface(pRRTex[j]->m_pDDSLcl[i+k],
  471. (LPVOID*)&(pRRTex[j]->m_pTextureBits[i-iFirstSurf+k]));
  472. if (hr != D3D_OK)
  473. {
  474. // Unlock any partial mipmap locks we've taken, as
  475. // RastUnlock can only handle entire textures being
  476. // locked or unlocked.
  477. while (--i + k >= 0)
  478. {
  479. UnlockSurface(pRRTex[j]->m_pDDSLcl[i+k]);
  480. }
  481. // Make sure that i is signed and that the above
  482. // loop exited properly.
  483. _ASSERT(i+k < 0,
  484. "Unlock of partial mipmap locks failed" );
  485. goto EH_Unlock;
  486. }
  487. }
  488. }
  489. // Set the transparent bit and the transparent color with pDDS[0]
  490. LPDDRAWI_DDRAWSURFACE_LCL pLcl;
  491. pLcl = pRRTex[j]->m_pDDSLcl[0];
  492. if ((pLcl->dwFlags & DDRAWISURF_HASCKEYSRCBLT) != 0)
  493. {
  494. pRRTex[j]->m_uFlags |= RR_TEXTURE_HAS_CK;
  495. pRRTex[j]->m_dwColorKey = pLcl->ddckCKSrcBlt.dwColorSpaceLowValue;
  496. }
  497. else
  498. {
  499. pRRTex[j]->m_uFlags &= ~RR_TEXTURE_HAS_CK;
  500. }
  501. // set the empty face color with pDDS[0]
  502. // note that ddckCKDestOverlay is unioned with dwEmptyFaceColor, but
  503. // not in the internal structure
  504. pRRTex[j]->m_dwEmptyFaceColor = pLcl->ddckCKDestOverlay.dwColorSpaceLowValue;
  505. // Update palette
  506. if (pRRTex[j]->m_SurfType == RR_STYPE_PALETTE8 ||
  507. pRRTex[j]->m_SurfType == RR_STYPE_PALETTE4)
  508. {
  509. if (pLcl->lpDDPalette)
  510. {
  511. LPDDRAWI_DDRAWPALETTE_GBL pPal = pLcl->lpDDPalette->lpLcl->lpGbl;
  512. pRRTex[j]->m_pPalette = (DWORD*)pPal->lpColorTable;
  513. if (pPal->dwFlags & DDRAWIPAL_ALPHA)
  514. {
  515. pRRTex[j]->m_uFlags |= RR_TEXTURE_ALPHAINPALETTE;
  516. }
  517. }
  518. }
  519. pRRTex[j]->m_uFlags |= RR_TEXTURE_LOCKED;
  520. }
  521. }
  522. // validate texture internals
  523. for (j = 0; j < cActTex; j++)
  524. {
  525. // stages may not have texture bound
  526. if ( NULL == pRRTex[j] ) continue;
  527. if ( !(pRRTex[j]->Validate()) )
  528. {
  529. hr = DDERR_INVALIDPARAMS;
  530. goto EH_Unlock;
  531. }
  532. }
  533. return D3D_OK;
  534. EH_Unlock:
  535. // Unlock complete textures we've already locked.
  536. // RastUnlock will check the flags to figure
  537. // out which ones to unlock.
  538. RefRastUnlockTexture(pRefRast);
  539. return hr;
  540. }
  541. //----------------------------------------------------------------------------
  542. //
  543. // RefRastUnlockTexture
  544. //
  545. // Unlock texture surface after the texture bits are accessed.
  546. //
  547. //----------------------------------------------------------------------------
  548. void
  549. RefRastUnlockTexture(ReferenceRasterizer *pRefRast)
  550. {
  551. INT i, j, k;
  552. RRTexture* pRRTex[D3DHAL_TSS_MAXSTAGES];
  553. D3DTEXTUREHANDLE phTex[D3DHAL_TSS_MAXSTAGES];
  554. int cActTex;
  555. if ((cActTex = pRefRast->GetCurrentTextureMaps(phTex, pRRTex)) == 0)
  556. {
  557. return ;
  558. }
  559. for (j = 0; j < cActTex; j++)
  560. {
  561. // stages may not have texture bound
  562. if ( NULL == pRRTex[j] ) continue;
  563. // RastUnlock is used for cleanup in RastLock so it needs to
  564. // be able to handle partially locked mipmap chains.
  565. if (pRRTex[j]->m_uFlags & RR_TEXTURE_LOCKED)
  566. {
  567. INT32 iMaxMipLevels = 0;
  568. if ( NULL != pRRTex[j]->m_pStageState )
  569. {
  570. iMaxMipLevels = pRRTex[j]->m_pStageState->m_dwVal[D3DTSS_MAXMIPLEVEL];
  571. }
  572. INT iFirstSurf = min(iMaxMipLevels, pRRTex[j]->m_cLODDDS);
  573. INT cEnvMap = (pRRTex[j]->m_uFlags & RR_TEXTURE_ENVMAP) ? (6) : (1);
  574. iFirstSurf *= cEnvMap;
  575. for (i = iFirstSurf; i <= pRRTex[j]->m_cLODDDS*cEnvMap; i += cEnvMap)
  576. {
  577. for ( k = 0; k < cEnvMap; k++ )
  578. {
  579. UnlockSurface(pRRTex[j]->m_pDDSLcl[i+k]);
  580. pRRTex[j]->m_pTextureBits[i-iFirstSurf+k] = NULL;
  581. }
  582. }
  583. // Reset the flags
  584. pRRTex[j]->m_uFlags &= ~RR_TEXTURE_LOCKED;
  585. pRRTex[j]->m_uFlags &= ~RR_TEXTURE_HAS_CK;
  586. pRRTex[j]->Validate();
  587. }
  588. }
  589. }
  590. //----------------------------------------------------------------------------
  591. //
  592. // FillRRRenderTarget
  593. //
  594. // Converts color and Z surface information into refrast form.
  595. //
  596. //----------------------------------------------------------------------------
  597. HRESULT
  598. FillRRRenderTarget(LPDDRAWI_DDRAWSURFACE_LCL pLclColor,
  599. LPDDRAWI_DDRAWSURFACE_LCL pLclZ,
  600. RRRenderTarget *pRrTarget)
  601. {
  602. HRESULT hr;
  603. RRSurfaceType ColorFmt;
  604. RRSurfaceType ZFmt = RR_STYPE_NULL;
  605. // Release objects we hold pointers to
  606. if (pRrTarget->m_pDDSLcl)
  607. {
  608. pRrTarget->m_pDDSLcl = NULL;
  609. }
  610. if (pRrTarget->m_pDDSZLcl)
  611. {
  612. pRrTarget->m_pDDSZLcl = NULL;
  613. }
  614. HR_RET(FindOutSurfFormat(&DDSurf_PixFmt(pLclColor), &ColorFmt));
  615. if (NULL != pLclZ)
  616. {
  617. HR_RET(FindOutSurfFormat(&(DDSurf_PixFmt(pLclZ)), &ZFmt));
  618. pRrTarget->m_pDepthBufBits = (char *)SURFACE_MEMORY(pLclZ);
  619. pRrTarget->m_iDepthBufPitch = DDSurf_Pitch(pLclZ);
  620. pRrTarget->m_pDDSZLcl = pLclZ;
  621. }
  622. else
  623. {
  624. pRrTarget->m_pDepthBufBits = NULL;
  625. pRrTarget->m_iDepthBufPitch = 0;
  626. pRrTarget->m_pDDSZLcl = NULL;
  627. }
  628. pRrTarget->m_Clip.left = 0;
  629. pRrTarget->m_Clip.top = 0;
  630. pRrTarget->m_Clip.bottom = DDSurf_Height(pLclColor) - 1;
  631. pRrTarget->m_Clip.right = DDSurf_Width(pLclColor) - 1;
  632. pRrTarget->m_iWidth = DDSurf_Width(pLclColor);
  633. pRrTarget->m_iHeight = DDSurf_Height(pLclColor);
  634. pRrTarget->m_pColorBufBits = (char *)SURFACE_MEMORY(pLclColor);
  635. pRrTarget->m_iColorBufPitch = DDSurf_Pitch(pLclColor);
  636. pRrTarget->m_ColorSType = (RRSurfaceType)ColorFmt;
  637. pRrTarget->m_DepthSType = (RRSurfaceType)ZFmt;
  638. pRrTarget->m_pDDSLcl = pLclColor;
  639. return D3D_OK;
  640. }
  641. //----------------------------------------------------------------------------
  642. //
  643. // RefRastContextCreate
  644. //
  645. // Creates a ReferenceRasterizer and initializes it with the info passed in.
  646. //
  647. //----------------------------------------------------------------------------
  648. DWORD __stdcall
  649. RefRastContextCreate(LPD3DHAL_CONTEXTCREATEDATA pCtxData)
  650. {
  651. ReferenceRasterizer *pRefRast;
  652. RRRenderTarget *pRendTgt;
  653. INT i;
  654. RRDEVICETYPE dwDriverType;
  655. // Surface7 pointers for QI
  656. LPDDRAWI_DDRAWSURFACE_LCL pZLcl = NULL;
  657. LPDDRAWI_DDRAWSURFACE_LCL pColorLcl = NULL;
  658. HRESULT ret;
  659. DPFM(0, DRV, ("In the new RefRast Dll\n"));
  660. // this only needs to be called once, but once per context won't hurt
  661. RefRastSetMemif(&malloc, &free, &realloc);
  662. if ((pRendTgt = new RRRenderTarget()) == NULL)
  663. {
  664. pCtxData->ddrval = DDERR_OUTOFMEMORY;
  665. return DDHAL_DRIVER_HANDLED;
  666. }
  667. // If it is expected to be a DX7+ driver
  668. if (pCtxData->ddrval < (DWORD)RRTYPE_DX7HAL)
  669. {
  670. if (pCtxData->lpDDS)
  671. pColorLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pCtxData->lpDDS))->lpLcl;
  672. if (pCtxData->lpDDSZ)
  673. pZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pCtxData->lpDDSZ))->lpLcl;
  674. }
  675. else
  676. {
  677. pColorLcl = pCtxData->lpDDSLcl;
  678. pZLcl = pCtxData->lpDDSZLcl;
  679. }
  680. // save the ddrval that is being sent down to communicate the driver
  681. // type that the runtime expects it to be.
  682. dwDriverType = (RRDEVICETYPE) pCtxData->ddrval;
  683. // Collect surface information where the failures are easy to handle.
  684. pCtxData->ddrval = FillRRRenderTarget(pColorLcl, pZLcl, pRendTgt);
  685. if (pCtxData->ddrval != D3D_OK)
  686. {
  687. return DDHAL_DRIVER_HANDLED;
  688. }
  689. // Note (Hacks):
  690. // dwhContext is used by the runtime to inform the driver, which
  691. // d3d interface is calling the driver.
  692. // ddrval is used by the runtime to inform the driver the DriverStyle
  693. // value it read. This is a RefRast specific hack.
  694. if ((pRefRast = new ReferenceRasterizer( pCtxData->lpDDLcl,
  695. (DWORD)(pCtxData->dwhContext),
  696. dwDriverType)) == NULL)
  697. {
  698. pCtxData->ddrval = DDERR_OUTOFMEMORY;
  699. return DDHAL_DRIVER_HANDLED;
  700. }
  701. pRefRast->SetRenderTarget(pRendTgt);
  702. // return RR object pointer as context handle
  703. pCtxData->dwhContext = (ULONG_PTR)pRefRast;
  704. pCtxData->ddrval = D3D_OK;
  705. return DDHAL_DRIVER_HANDLED;
  706. }
  707. //----------------------------------------------------------------------------
  708. //
  709. // RefRastContextDestroy
  710. //
  711. // Destroy a ReferenceRasterizer.
  712. //
  713. //----------------------------------------------------------------------------
  714. DWORD __stdcall
  715. RefRastContextDestroy(LPD3DHAL_CONTEXTDESTROYDATA pCtxDestroyData)
  716. {
  717. ReferenceRasterizer *pRefRast;
  718. // Check ReferenceRasterizer
  719. VALIDATE_REFRAST_CONTEXT("RefRastContextDestroy", pCtxDestroyData);
  720. // Clean up override bits
  721. RRRenderTarget *pRendTgt = pRefRast->GetRenderTarget();
  722. if ( NULL != pRendTgt ) { delete pRendTgt; }
  723. delete pRefRast;
  724. pCtxDestroyData->ddrval = D3D_OK;
  725. return DDHAL_DRIVER_HANDLED;
  726. }
  727. //----------------------------------------------------------------------------
  728. //
  729. // RefRastSceneCapture
  730. //
  731. // Pass scene capture callback to ref rast.
  732. //
  733. //----------------------------------------------------------------------------
  734. DWORD __stdcall
  735. RefRastSceneCapture(LPD3DHAL_SCENECAPTUREDATA pData)
  736. {
  737. ReferenceRasterizer *pRefRast;
  738. // Check ReferenceRasterizer
  739. VALIDATE_REFRAST_CONTEXT("RefRastSceneCapture", pData);
  740. pRefRast->SceneCapture( pData->dwFlag );
  741. pData->ddrval = D3D_OK; // Should this be changed to a QI ?
  742. return DDHAL_DRIVER_HANDLED;
  743. }
  744. //----------------------------------------------------------------------------
  745. //
  746. // RefRastSetRenderTarget
  747. //
  748. // Update a RefRast context with the info from a new render target.
  749. //
  750. //----------------------------------------------------------------------------
  751. DWORD __stdcall
  752. RefRastSetRenderTarget(LPD3DHAL_SETRENDERTARGETDATA pTgtData)
  753. {
  754. ReferenceRasterizer *pRefRast;
  755. LPDDRAWI_DDRAWSURFACE_LCL pZLcl = NULL;
  756. LPDDRAWI_DDRAWSURFACE_LCL pColorLcl = NULL;
  757. HRESULT ret;
  758. // Check ReferenceRasterizer
  759. VALIDATE_REFRAST_CONTEXT("RefRastSetRenderTarget", pTgtData);
  760. RRRenderTarget *pRendTgt = pRefRast->GetRenderTarget();
  761. if ( NULL == pRendTgt ) { return DDHAL_DRIVER_HANDLED; }
  762. if (pRefRast->IsInterfaceDX6AndBefore() ||
  763. pRefRast->IsDriverDX6AndBefore())
  764. {
  765. if( pTgtData->lpDDS )
  766. pColorLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pTgtData->lpDDS))->lpLcl;
  767. if( pTgtData->lpDDSZ )
  768. pZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pTgtData->lpDDSZ))->lpLcl;
  769. }
  770. else
  771. {
  772. pColorLcl = pTgtData->lpDDSLcl;
  773. pZLcl = pTgtData->lpDDSZLcl;
  774. }
  775. // Collect surface information.
  776. pTgtData->ddrval = FillRRRenderTarget(pColorLcl, pZLcl, pRendTgt);
  777. if (pTgtData->ddrval != D3D_OK)
  778. {
  779. return DDHAL_DRIVER_HANDLED;
  780. }
  781. pRefRast->SetRenderTarget(pRendTgt);
  782. return DDHAL_DRIVER_HANDLED;
  783. }
  784. //----------------------------------------------------------------------------
  785. //
  786. // RefRastValidateTextureStageState
  787. //
  788. // Validate current blend operations. RefRast does everything.
  789. //
  790. //----------------------------------------------------------------------------
  791. DWORD __stdcall
  792. RefRastValidateTextureStageState(LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA pData)
  793. {
  794. ReferenceRasterizer *pRefRast;
  795. // Check ReferenceRasterizer
  796. VALIDATE_REFRAST_CONTEXT("RefRastValidateTextureStageState", pData);
  797. pData->dwNumPasses = 1;
  798. pData->ddrval = D3D_OK;
  799. return DDHAL_DRIVER_HANDLED;
  800. }
  801. //----------------------------------------------------------------------------
  802. //
  803. // RefRastDrawOneIndexedPrimitive
  804. //
  805. // Draw one list of primitives. This is called by D3DIM for API
  806. // DrawIndexedPrimitive.
  807. //
  808. //----------------------------------------------------------------------------
  809. DWORD __stdcall
  810. RefRastDrawOneIndexedPrimitive(LPD3DHAL_DRAWONEINDEXEDPRIMITIVEDATA
  811. pOneIdxPrimData)
  812. {
  813. ReferenceRasterizer *pRefRast;
  814. HRESULT hr;
  815. DWORD dwVStride;
  816. // Check ReferenceRasterizer
  817. VALIDATE_REFRAST_CONTEXT("RefRastDrawOneIndexedPrimitive",
  818. pOneIdxPrimData);
  819. if ((pOneIdxPrimData->ddrval=RRFVFCheckAndStride(pOneIdxPrimData->dwFVFControl, &dwVStride)) != D3D_OK)
  820. {
  821. return DDHAL_DRIVER_HANDLED;
  822. }
  823. if ((pOneIdxPrimData->ddrval= RefRastLockTarget(pRefRast)) != D3D_OK)
  824. {
  825. return DDHAL_DRIVER_HANDLED;
  826. }
  827. if ((pOneIdxPrimData->ddrval=RefRastLockTexture(pRefRast)) != D3D_OK)
  828. {
  829. RefRastUnlockTarget(pRefRast);
  830. return DDHAL_DRIVER_HANDLED;
  831. }
  832. if ((pOneIdxPrimData->ddrval=
  833. pRefRast->BeginRendering((DWORD)pOneIdxPrimData->dwFVFControl)) != D3D_OK)
  834. {
  835. RefRastUnlockTexture(pRefRast);
  836. RefRastUnlockTarget(pRefRast);
  837. return DDHAL_DRIVER_HANDLED;
  838. }
  839. pOneIdxPrimData->ddrval =
  840. DoDrawOneIndexedPrimitive(pRefRast,
  841. (UINT16)dwVStride,
  842. (PUINT8)pOneIdxPrimData->lpvVertices,
  843. pOneIdxPrimData->lpwIndices,
  844. pOneIdxPrimData->PrimitiveType,
  845. pOneIdxPrimData->dwNumIndices);
  846. hr = pRefRast->EndRendering();
  847. RefRastUnlockTexture(pRefRast);
  848. RefRastUnlockTarget(pRefRast);
  849. if (pOneIdxPrimData->ddrval == D3D_OK)
  850. {
  851. pOneIdxPrimData->ddrval = hr;
  852. }
  853. return DDHAL_DRIVER_HANDLED;
  854. }
  855. //----------------------------------------------------------------------------
  856. //
  857. // RefRastDrawOnePrimitive
  858. //
  859. // Draw one list of primitives. This is called by D3DIM for API DrawPrimitive.
  860. //
  861. //----------------------------------------------------------------------------
  862. DWORD __stdcall
  863. RefRastDrawOnePrimitive(LPD3DHAL_DRAWONEPRIMITIVEDATA pOnePrimData)
  864. {
  865. ReferenceRasterizer *pRefRast;
  866. HRESULT hr;
  867. DWORD dwVStride;
  868. // Check ReferenceRasterizer
  869. VALIDATE_REFRAST_CONTEXT("RefRastDrawOnePrimitive", pOnePrimData);
  870. if ((pOnePrimData->ddrval=RRFVFCheckAndStride(pOnePrimData->dwFVFControl, &dwVStride)) != D3D_OK)
  871. {
  872. return DDHAL_DRIVER_HANDLED;
  873. }
  874. if ((pOnePrimData->ddrval=RefRastLockTarget(pRefRast)) != D3D_OK)
  875. {
  876. return DDHAL_DRIVER_HANDLED;
  877. }
  878. if ((pOnePrimData->ddrval=RefRastLockTexture(pRefRast)) != D3D_OK)
  879. {
  880. RefRastUnlockTarget(pRefRast);
  881. return DDHAL_DRIVER_HANDLED;
  882. }
  883. if ((pOnePrimData->ddrval=
  884. pRefRast->BeginRendering(pOnePrimData->dwFVFControl)) != D3D_OK)
  885. {
  886. RefRastUnlockTexture(pRefRast);
  887. RefRastUnlockTarget(pRefRast);
  888. return DDHAL_DRIVER_HANDLED;
  889. }
  890. pOnePrimData->ddrval =
  891. DoDrawOnePrimitive(pRefRast,
  892. (UINT16)dwVStride,
  893. (PUINT8)pOnePrimData->lpvVertices,
  894. pOnePrimData->PrimitiveType,
  895. pOnePrimData->dwNumVertices);
  896. hr = pRefRast->EndRendering();
  897. // Unlock texture/rendertarget
  898. RefRastUnlockTexture(pRefRast);
  899. RefRastUnlockTarget(pRefRast);
  900. if (pOnePrimData->ddrval == D3D_OK)
  901. {
  902. pOnePrimData->ddrval = hr;
  903. }
  904. return DDHAL_DRIVER_HANDLED;
  905. }
  906. //----------------------------------------------------------------------------
  907. //
  908. // RefRastDrawPrimitives
  909. //
  910. // This is called by D3DIM for a list of batched API DrawPrimitive calls.
  911. //
  912. //----------------------------------------------------------------------------
  913. DWORD __stdcall
  914. RefRastDrawPrimitives(LPD3DHAL_DRAWPRIMITIVESDATA pDrawPrimData)
  915. {
  916. ReferenceRasterizer *pRefRast;
  917. PUINT8 pData = (PUINT8)pDrawPrimData->lpvData;
  918. LPD3DHAL_DRAWPRIMCOUNTS pDrawPrimitiveCounts;
  919. HRESULT hr;
  920. DWORD dwVStride;
  921. // Check ReferenceRasterizer
  922. VALIDATE_REFRAST_CONTEXT("RefRastDrawPrimitives", pDrawPrimData);
  923. pDrawPrimitiveCounts = (LPD3DHAL_DRAWPRIMCOUNTS)pData;
  924. // Check for FVF only if there is something to be drawn
  925. if (pDrawPrimitiveCounts->wNumVertices > 0)
  926. {
  927. // Unconditionally get the vertex stride, since it can not change
  928. if ((pDrawPrimData->ddrval =
  929. RRFVFCheckAndStride(pDrawPrimData->dwFVFControl, &dwVStride)) != D3D_OK)
  930. {
  931. return DDHAL_DRIVER_HANDLED;
  932. }
  933. }
  934. if ((pDrawPrimData->ddrval=RefRastLockTarget(pRefRast)) != D3D_OK)
  935. {
  936. return DDHAL_DRIVER_HANDLED;
  937. }
  938. // Skip BeginRendering & RefRastLockTexture if first thing is state change
  939. if (pDrawPrimitiveCounts->wNumStateChanges <= 0)
  940. {
  941. if ((pDrawPrimData->ddrval=RefRastLockTexture(pRefRast)) != D3D_OK)
  942. {
  943. RefRastUnlockTarget(pRefRast);
  944. return DDHAL_DRIVER_HANDLED;
  945. }
  946. if ((pDrawPrimData->ddrval =
  947. pRefRast->BeginRendering(pDrawPrimData->dwFVFControl)) != D3D_OK)
  948. {
  949. RefRastUnlockTexture(pRefRast);
  950. RefRastUnlockTarget(pRefRast);
  951. return DDHAL_DRIVER_HANDLED;
  952. }
  953. }
  954. // Loop through the data, update render states
  955. // and then draw the primitive
  956. for (;;)
  957. {
  958. pDrawPrimitiveCounts = (LPD3DHAL_DRAWPRIMCOUNTS)pData;
  959. pData += sizeof(D3DHAL_DRAWPRIMCOUNTS);
  960. // Update render states
  961. if (pDrawPrimitiveCounts->wNumStateChanges > 0)
  962. {
  963. UINT32 StateType,StateValue;
  964. LPDWORD pStateChange = (LPDWORD)pData;
  965. INT i;
  966. for (i = 0; i < pDrawPrimitiveCounts->wNumStateChanges; i++)
  967. {
  968. StateType = *pStateChange;
  969. pStateChange ++;
  970. StateValue = *pStateChange;
  971. pStateChange ++;
  972. pRefRast->SetRenderState(StateType, StateValue);
  973. }
  974. pData += pDrawPrimitiveCounts->wNumStateChanges *
  975. sizeof(DWORD) * 2;
  976. }
  977. // Check for exit
  978. if (pDrawPrimitiveCounts->wNumVertices == 0)
  979. {
  980. break;
  981. }
  982. // Align pointer to vertex data
  983. pData = (PUINT8)
  984. ((ULONG_PTR)(pData + (DP_VTX_ALIGN - 1)) & ~(DP_VTX_ALIGN - 1));
  985. // The texture might changed
  986. if (pDrawPrimitiveCounts->wNumStateChanges > 0)
  987. {
  988. RefRastUnlockTexture(pRefRast);
  989. if ((pDrawPrimData->ddrval=pRefRast->EndRendering()) != D3D_OK)
  990. {
  991. RefRastUnlockTarget(pRefRast);
  992. return DDHAL_DRIVER_HANDLED;
  993. }
  994. if ((pDrawPrimData->ddrval=RefRastLockTexture(pRefRast)) != D3D_OK)
  995. {
  996. RefRastUnlockTarget(pRefRast);
  997. return DDHAL_DRIVER_HANDLED;
  998. }
  999. if ((pDrawPrimData->ddrval =
  1000. pRefRast->BeginRendering(pDrawPrimData->dwFVFControl)) != D3D_OK)
  1001. {
  1002. RefRastUnlockTexture(pRefRast);
  1003. RefRastUnlockTarget(pRefRast);
  1004. return DDHAL_DRIVER_HANDLED;
  1005. }
  1006. }
  1007. // Draw primitives
  1008. pDrawPrimData->ddrval =
  1009. DoDrawOnePrimitive(pRefRast,
  1010. (UINT16)dwVStride,
  1011. (PUINT8)pData,
  1012. (D3DPRIMITIVETYPE)
  1013. pDrawPrimitiveCounts->wPrimitiveType,
  1014. pDrawPrimitiveCounts->wNumVertices);
  1015. if (pDrawPrimData->ddrval != DD_OK)
  1016. {
  1017. goto EH_exit;
  1018. }
  1019. pData += pDrawPrimitiveCounts->wNumVertices * dwVStride;
  1020. }
  1021. EH_exit:
  1022. hr = pRefRast->EndRendering();
  1023. RefRastUnlockTexture(pRefRast);
  1024. RefRastUnlockTarget(pRefRast);
  1025. if (pDrawPrimData->ddrval == D3D_OK)
  1026. {
  1027. pDrawPrimData->ddrval = hr;
  1028. }
  1029. return DDHAL_DRIVER_HANDLED;
  1030. }
  1031. //----------------------------------------------------------------------------
  1032. //
  1033. // RefRastTextureCreate
  1034. //
  1035. // Creates a RefRast texture and initializes it with the info passed in.
  1036. //
  1037. //----------------------------------------------------------------------------
  1038. DWORD __stdcall
  1039. RefRastTextureCreate(LPD3DHAL_TEXTURECREATEDATA pTexData)
  1040. {
  1041. ReferenceRasterizer *pRefRast;
  1042. RRTexture* pRRTex;
  1043. HRESULT hr;
  1044. LPDDRAWI_DDRAWSURFACE_LCL pLcl;
  1045. if (pTexData->lpDDS)
  1046. {
  1047. pLcl = ((LPDDRAWI_DDRAWSURFACE_INT)pTexData->lpDDS)->lpLcl;
  1048. }
  1049. // Check ReferenceRasterizer
  1050. VALIDATE_REFRAST_CONTEXT("RefRastTextureCreate", pTexData);
  1051. // Runtime shouldnt be calling TextureCreate for DX7 and newer
  1052. // driver models
  1053. if ((pRefRast->IsInterfaceDX6AndBefore() == FALSE) &&
  1054. (pRefRast->IsDriverDX6AndBefore() == FALSE))
  1055. {
  1056. pTexData->ddrval = DDERR_GENERIC;
  1057. return DDHAL_DRIVER_HANDLED;
  1058. }
  1059. // assume OKness
  1060. pTexData->ddrval = D3D_OK;
  1061. // Allocate RRTexture
  1062. if ( !(pRefRast->TextureCreate(
  1063. (LPD3DTEXTUREHANDLE)&(pTexData->dwHandle), &pRRTex ) ) )
  1064. {
  1065. pTexData->ddrval = DDERR_GENERIC;
  1066. return DDHAL_DRIVER_HANDLED;
  1067. }
  1068. // Init texturemap.
  1069. hr = pRRTex->Initialize( pLcl );
  1070. if (hr != D3D_OK)
  1071. {
  1072. pTexData->ddrval = hr;
  1073. return DDHAL_DRIVER_HANDLED;
  1074. }
  1075. return DDHAL_DRIVER_HANDLED;
  1076. }
  1077. //----------------------------------------------------------------------------
  1078. //
  1079. // RefRastTextureDestroy
  1080. //
  1081. // Destroy a RefRast texture.
  1082. //
  1083. //----------------------------------------------------------------------------
  1084. DWORD __stdcall
  1085. RefRastTextureDestroy(LPD3DHAL_TEXTUREDESTROYDATA pTexDestroyData)
  1086. {
  1087. ReferenceRasterizer *pRefRast;
  1088. // Check ReferenceRasterizer
  1089. VALIDATE_REFRAST_CONTEXT("RefRastTextureDestroy", pTexDestroyData);
  1090. // Runtime shouldnt be Calling TextureCreate for DX7 and newer
  1091. // driver models
  1092. if ((pRefRast->IsInterfaceDX6AndBefore() == FALSE) &&
  1093. (pRefRast->IsDriverDX6AndBefore() == FALSE))
  1094. {
  1095. pTexDestroyData->ddrval = DDERR_GENERIC;
  1096. return DDHAL_DRIVER_HANDLED;
  1097. }
  1098. if (!(pRefRast->TextureDestroy(pTexDestroyData->dwHandle)))
  1099. {
  1100. pTexDestroyData->ddrval = DDERR_GENERIC;
  1101. }
  1102. else
  1103. {
  1104. pTexDestroyData->ddrval = D3D_OK;
  1105. }
  1106. return DDHAL_DRIVER_HANDLED;
  1107. }
  1108. //----------------------------------------------------------------------------
  1109. //
  1110. // RefRastTextureGetSurf
  1111. //
  1112. // Returns the surface pointer associate with a texture handle.
  1113. //
  1114. //----------------------------------------------------------------------------
  1115. DWORD __stdcall
  1116. RefRastTextureGetSurf(LPD3DHAL_TEXTUREGETSURFDATA pTexGetSurf)
  1117. {
  1118. ReferenceRasterizer *pRefRast;
  1119. // Check ReferenceRasterizer
  1120. VALIDATE_REFRAST_CONTEXT("RefRastTextureGetSurf", pTexGetSurf);
  1121. pTexGetSurf->lpDDS = pRefRast->TextureGetSurf(pTexGetSurf->dwHandle);
  1122. pTexGetSurf->ddrval = D3D_OK;
  1123. return DDHAL_DRIVER_HANDLED;
  1124. }
  1125. //----------------------------------------------------------------------------
  1126. //
  1127. // RefRastRenderPrimitive
  1128. //
  1129. // Called by Execute() for drawing primitives.
  1130. //
  1131. //----------------------------------------------------------------------------
  1132. DWORD __stdcall
  1133. RefRastRenderPrimitive(LPD3DHAL_RENDERPRIMITIVEDATA pRenderData)
  1134. {
  1135. ReferenceRasterizer *pRefRast;
  1136. LPD3DINSTRUCTION pIns;
  1137. LPD3DTLVERTEX pVtx;
  1138. PUINT8 pData, pPrim;
  1139. // Check ReferenceRasterizer
  1140. VALIDATE_REFRAST_CONTEXT("RefRastRenderPrimitive", pRenderData);
  1141. if (pRefRast->GetRenderState()[D3DRENDERSTATE_ZVISIBLE])
  1142. {
  1143. pRenderData->dwStatus &= ~D3DSTATUS_ZNOTVISIBLE;
  1144. pRenderData->ddrval = D3D_OK;
  1145. return DDHAL_DRIVER_HANDLED;
  1146. }
  1147. // Find out necessary data
  1148. pData = (PUINT8)(((LPDDRAWI_DDRAWSURFACE_INT)
  1149. (pRenderData->lpExeBuf))->lpLcl->lpGbl->fpVidMem);
  1150. pIns = &pRenderData->diInstruction;
  1151. pPrim = pData + pRenderData->dwOffset;
  1152. pVtx = (LPD3DTLVERTEX)((PUINT8)((LPDDRAWI_DDRAWSURFACE_INT)
  1153. (pRenderData->lpTLBuf))->lpLcl->lpGbl->fpVidMem +
  1154. pRenderData->dwTLOffset);
  1155. if ( (pRenderData->ddrval=RefRastLockTarget(pRefRast)) != D3D_OK )
  1156. {
  1157. return DDHAL_DRIVER_HANDLED;
  1158. }
  1159. if ( (pRenderData->ddrval=RefRastLockTexture(pRefRast)) != D3D_OK )
  1160. {
  1161. return DDHAL_DRIVER_HANDLED;
  1162. }
  1163. if ( (pRenderData->ddrval=pRefRast->BeginRendering(D3DFVF_TLVERTEX)) != D3D_OK )
  1164. {
  1165. return DDHAL_DRIVER_HANDLED;
  1166. }
  1167. // Render
  1168. switch (pIns->bOpcode) {
  1169. case D3DOP_POINT:
  1170. pRenderData->ddrval = DoRendPoints(pRefRast,
  1171. pIns, pVtx,
  1172. (LPD3DPOINT)pPrim);
  1173. break;
  1174. case D3DOP_LINE:
  1175. pRenderData->ddrval = DoRendLines(pRefRast,
  1176. pIns, pVtx,
  1177. (LPD3DLINE)pPrim);
  1178. break;
  1179. case D3DOP_TRIANGLE:
  1180. pRenderData->ddrval = DoRendTriangles(pRefRast,
  1181. pIns, pVtx,
  1182. (LPD3DTRIANGLE)pPrim);
  1183. break;
  1184. default:
  1185. DPFM(0, DRV, ("(RefRast) Wrong Opcode passed to the new rasterizer."));
  1186. pRenderData->ddrval = DDERR_INVALIDPARAMS;
  1187. break;
  1188. }
  1189. HRESULT hr = pRefRast->EndRendering();
  1190. RefRastUnlockTarget(pRefRast);
  1191. RefRastUnlockTexture(pRefRast);
  1192. if (pRenderData->ddrval == D3D_OK)
  1193. {
  1194. pRenderData->ddrval = hr;
  1195. }
  1196. return DDHAL_DRIVER_HANDLED;
  1197. }
  1198. //----------------------------------------------------------------------------
  1199. //
  1200. // RefRastRenderState
  1201. //
  1202. // Called by Execute() for setting render states.
  1203. //
  1204. //----------------------------------------------------------------------------
  1205. DWORD __stdcall
  1206. RefRastRenderState(LPD3DHAL_RENDERSTATEDATA pStateData)
  1207. {
  1208. ReferenceRasterizer *pRefRast;
  1209. // Check ReferenceRasterizer
  1210. VALIDATE_REFRAST_CONTEXT("RefRastRenderState", pStateData);
  1211. PUINT8 pData;
  1212. LPD3DSTATE pState;
  1213. INT i;
  1214. pData = (PUINT8) (((LPDDRAWI_DDRAWSURFACE_INT)
  1215. (pStateData->lpExeBuf))->lpLcl->lpGbl->fpVidMem);
  1216. // Updates states
  1217. for (i = 0, pState = (LPD3DSTATE) (pData + pStateData->dwOffset);
  1218. i < (INT)pStateData->dwCount;
  1219. i ++, pState ++)
  1220. {
  1221. UINT32 type = (UINT32) pState->drstRenderStateType;
  1222. // Set the state
  1223. pRefRast->SetRenderState(type, pState->dwArg[0]);
  1224. }
  1225. return DDHAL_DRIVER_HANDLED;
  1226. }
  1227. //----------------------------------------------------------------------------
  1228. //
  1229. // RefRastGetDriverState
  1230. //
  1231. // Called by the runtime to get any kind of driver information
  1232. //
  1233. //----------------------------------------------------------------------------
  1234. DWORD __stdcall
  1235. RefRastGetDriverState(LPDDHAL_GETDRIVERSTATEDATA pGDSData)
  1236. {
  1237. ReferenceRasterizer *pRefRast;
  1238. // Check ReferenceRasterizer
  1239. #if DBG
  1240. if ((pGDSData) == NULL)
  1241. {
  1242. DPFM(0, DRV, ("in %s, data pointer = NULL", "RefRastGetDriverState"));
  1243. return DDHAL_DRIVER_HANDLED;
  1244. }
  1245. pRefRast = (ReferenceRasterizer *)((pGDSData)->dwhContext);
  1246. if (!pRefRast)
  1247. {
  1248. DPFM(0, DRV, ("in %s, dwhContext = NULL", "RefRastGetDriverState"));
  1249. pGDSData->ddRVal = D3DHAL_CONTEXT_BAD;
  1250. return DDHAL_DRIVER_HANDLED;
  1251. }
  1252. #else // !DBG
  1253. pRefRast = (ReferenceRasterizer *)((pGDSData)->dwhContext);
  1254. #endif // !DBG
  1255. //
  1256. // No implementation yet, so nothing is understood yet
  1257. //
  1258. pGDSData->ddRVal = S_FALSE;
  1259. return DDHAL_DRIVER_HANDLED;
  1260. }
  1261. //----------------------------------------------------------------------------
  1262. //
  1263. // RefRastHalProvider::GetCaps/GetInterface
  1264. //
  1265. // Returns the reference rasterizer's HAL interface.
  1266. //
  1267. //----------------------------------------------------------------------------
  1268. extern D3DDEVICEDESC7 g_nullDevDesc;
  1269. static D3DHAL_CALLBACKS Callbacks =
  1270. {
  1271. sizeof(D3DHAL_CALLBACKS),
  1272. RefRastContextCreate,
  1273. RefRastContextDestroy,
  1274. NULL,
  1275. RefRastSceneCapture,
  1276. NULL,
  1277. NULL,
  1278. RefRastRenderState,
  1279. RefRastRenderPrimitive,
  1280. NULL,
  1281. RefRastTextureCreate,
  1282. RefRastTextureDestroy,
  1283. NULL,
  1284. RefRastTextureGetSurf,
  1285. // All others NULL.
  1286. };
  1287. static D3DHAL_CALLBACKS2 Callbacks2 =
  1288. {
  1289. sizeof(D3DHAL_CALLBACKS2),
  1290. D3DHAL2_CB32_SETRENDERTARGET |
  1291. D3DHAL2_CB32_DRAWONEPRIMITIVE |
  1292. D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE |
  1293. D3DHAL2_CB32_DRAWPRIMITIVES,
  1294. RefRastSetRenderTarget,
  1295. NULL,
  1296. RefRastDrawOnePrimitive,
  1297. RefRastDrawOneIndexedPrimitive,
  1298. RefRastDrawPrimitives
  1299. };
  1300. static D3DHAL_CALLBACKS3 Callbacks3 =
  1301. {
  1302. sizeof(D3DHAL_CALLBACKS3),
  1303. D3DHAL3_CB32_VALIDATETEXTURESTAGESTATE |
  1304. D3DHAL3_CB32_DRAWPRIMITIVES2,
  1305. NULL, // Clear2
  1306. NULL, // lpvReserved
  1307. RefRastValidateTextureStageState,
  1308. RefRastDrawPrimitives2, // DrawVB
  1309. };
  1310. static D3DDEVICEDESC7 RefDevDesc = { 0 };
  1311. static D3DHAL_D3DEXTENDEDCAPS RefExtCaps;
  1312. static void
  1313. FillOutDeviceCaps( BOOL bIsNullDevice )
  1314. {
  1315. //
  1316. // set device description
  1317. //
  1318. RefDevDesc.dwDevCaps =
  1319. D3DDEVCAPS_FLOATTLVERTEX |
  1320. D3DDEVCAPS_EXECUTESYSTEMMEMORY |
  1321. D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
  1322. D3DDEVCAPS_TEXTURESYSTEMMEMORY |
  1323. D3DDEVCAPS_DRAWPRIMTLVERTEX |
  1324. D3DDEVCAPS_DRAWPRIMITIVES2EX |
  1325. D3DDEVCAPS_HWTRANSFORMANDLIGHT ;
  1326. RefDevDesc.dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
  1327. RefDevDesc.dpcTriCaps.dwMiscCaps =
  1328. D3DPMISCCAPS_MASKZ |
  1329. D3DPMISCCAPS_CULLNONE |
  1330. D3DPMISCCAPS_CULLCW |
  1331. D3DPMISCCAPS_CULLCCW ;
  1332. RefDevDesc.dpcTriCaps.dwRasterCaps =
  1333. D3DPRASTERCAPS_DITHER |
  1334. // D3DPRASTERCAPS_ROP2 |
  1335. // D3DPRASTERCAPS_XOR |
  1336. // D3DPRASTERCAPS_PAT |
  1337. D3DPRASTERCAPS_ZTEST |
  1338. D3DPRASTERCAPS_SUBPIXEL |
  1339. D3DPRASTERCAPS_SUBPIXELX |
  1340. D3DPRASTERCAPS_FOGVERTEX |
  1341. D3DPRASTERCAPS_FOGTABLE |
  1342. // D3DPRASTERCAPS_STIPPLE |
  1343. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  1344. D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  1345. // D3DPRASTERCAPS_ANTIALIASEDGES |
  1346. D3DPRASTERCAPS_MIPMAPLODBIAS |
  1347. // D3DPRASTERCAPS_ZBIAS |
  1348. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  1349. D3DPRASTERCAPS_FOGRANGE |
  1350. D3DPRASTERCAPS_ANISOTROPY |
  1351. D3DPRASTERCAPS_WBUFFER |
  1352. D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT |
  1353. D3DPRASTERCAPS_WFOG |
  1354. D3DPRASTERCAPS_ZFOG;
  1355. RefDevDesc.dpcTriCaps.dwZCmpCaps =
  1356. D3DPCMPCAPS_NEVER |
  1357. D3DPCMPCAPS_LESS |
  1358. D3DPCMPCAPS_EQUAL |
  1359. D3DPCMPCAPS_LESSEQUAL |
  1360. D3DPCMPCAPS_GREATER |
  1361. D3DPCMPCAPS_NOTEQUAL |
  1362. D3DPCMPCAPS_GREATEREQUAL |
  1363. D3DPCMPCAPS_ALWAYS ;
  1364. RefDevDesc.dpcTriCaps.dwSrcBlendCaps =
  1365. D3DPBLENDCAPS_ZERO |
  1366. D3DPBLENDCAPS_ONE |
  1367. D3DPBLENDCAPS_SRCCOLOR |
  1368. D3DPBLENDCAPS_INVSRCCOLOR |
  1369. D3DPBLENDCAPS_SRCALPHA |
  1370. D3DPBLENDCAPS_INVSRCALPHA |
  1371. D3DPBLENDCAPS_DESTALPHA |
  1372. D3DPBLENDCAPS_INVDESTALPHA |
  1373. D3DPBLENDCAPS_DESTCOLOR |
  1374. D3DPBLENDCAPS_INVDESTCOLOR |
  1375. D3DPBLENDCAPS_SRCALPHASAT |
  1376. D3DPBLENDCAPS_BOTHSRCALPHA |
  1377. D3DPBLENDCAPS_BOTHINVSRCALPHA ;
  1378. RefDevDesc.dpcTriCaps.dwDestBlendCaps =
  1379. D3DPBLENDCAPS_ZERO |
  1380. D3DPBLENDCAPS_ONE |
  1381. D3DPBLENDCAPS_SRCCOLOR |
  1382. D3DPBLENDCAPS_INVSRCCOLOR |
  1383. D3DPBLENDCAPS_SRCALPHA |
  1384. D3DPBLENDCAPS_INVSRCALPHA |
  1385. D3DPBLENDCAPS_DESTALPHA |
  1386. D3DPBLENDCAPS_INVDESTALPHA |
  1387. D3DPBLENDCAPS_DESTCOLOR |
  1388. D3DPBLENDCAPS_INVDESTCOLOR |
  1389. D3DPBLENDCAPS_SRCALPHASAT ;
  1390. RefDevDesc.dpcTriCaps.dwAlphaCmpCaps =
  1391. RefDevDesc.dpcTriCaps.dwZCmpCaps;
  1392. RefDevDesc.dpcTriCaps.dwShadeCaps =
  1393. D3DPSHADECAPS_COLORFLATRGB |
  1394. D3DPSHADECAPS_COLORGOURAUDRGB |
  1395. D3DPSHADECAPS_SPECULARFLATRGB |
  1396. D3DPSHADECAPS_SPECULARGOURAUDRGB |
  1397. D3DPSHADECAPS_ALPHAFLATBLEND |
  1398. D3DPSHADECAPS_ALPHAGOURAUDBLEND |
  1399. D3DPSHADECAPS_FOGFLAT |
  1400. D3DPSHADECAPS_FOGGOURAUD ;
  1401. RefDevDesc.dpcTriCaps.dwTextureCaps =
  1402. D3DPTEXTURECAPS_PERSPECTIVE |
  1403. D3DPTEXTURECAPS_POW2 |
  1404. D3DPTEXTURECAPS_ALPHA |
  1405. D3DPTEXTURECAPS_TRANSPARENCY |
  1406. D3DPTEXTURECAPS_ALPHAPALETTE |
  1407. D3DPTEXTURECAPS_BORDER |
  1408. D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
  1409. D3DPTEXTURECAPS_ALPHAPALETTE |
  1410. D3DPTEXTURECAPS_PROJECTED |
  1411. D3DPTEXTURECAPS_CUBEMAP |
  1412. D3DPTEXTURECAPS_COLORKEYBLEND;
  1413. RefDevDesc.dpcTriCaps.dwTextureFilterCaps =
  1414. D3DPTFILTERCAPS_NEAREST |
  1415. D3DPTFILTERCAPS_LINEAR |
  1416. D3DPTFILTERCAPS_MIPNEAREST |
  1417. D3DPTFILTERCAPS_MIPLINEAR |
  1418. D3DPTFILTERCAPS_LINEARMIPNEAREST |
  1419. D3DPTFILTERCAPS_LINEARMIPLINEAR |
  1420. D3DPTFILTERCAPS_MINFPOINT |
  1421. D3DPTFILTERCAPS_MINFLINEAR |
  1422. D3DPTFILTERCAPS_MINFANISOTROPIC |
  1423. D3DPTFILTERCAPS_MIPFPOINT |
  1424. D3DPTFILTERCAPS_MIPFLINEAR |
  1425. D3DPTFILTERCAPS_MAGFPOINT |
  1426. D3DPTFILTERCAPS_MAGFLINEAR |
  1427. D3DPTFILTERCAPS_MAGFANISOTROPIC ;
  1428. RefDevDesc.dpcTriCaps.dwTextureBlendCaps =
  1429. D3DPTBLENDCAPS_DECAL |
  1430. D3DPTBLENDCAPS_MODULATE |
  1431. D3DPTBLENDCAPS_DECALALPHA |
  1432. D3DPTBLENDCAPS_MODULATEALPHA |
  1433. // D3DPTBLENDCAPS_DECALMASK |
  1434. // D3DPTBLENDCAPS_MODULATEMASK |
  1435. D3DPTBLENDCAPS_COPY |
  1436. D3DPTBLENDCAPS_ADD ;
  1437. RefDevDesc.dpcTriCaps.dwTextureAddressCaps =
  1438. D3DPTADDRESSCAPS_WRAP |
  1439. D3DPTADDRESSCAPS_MIRROR |
  1440. D3DPTADDRESSCAPS_CLAMP |
  1441. D3DPTADDRESSCAPS_BORDER |
  1442. D3DPTADDRESSCAPS_INDEPENDENTUV ;
  1443. RefDevDesc.dpcTriCaps.dwStippleWidth = 0;
  1444. RefDevDesc.dpcTriCaps.dwStippleHeight = 0;
  1445. // line caps - copy tricaps and modify
  1446. memcpy( &RefDevDesc.dpcLineCaps, &RefDevDesc.dpcTriCaps, sizeof(D3DPRIMCAPS) );
  1447. // disable antialias cap
  1448. RefDevDesc.dpcLineCaps.dwRasterCaps =
  1449. D3DPRASTERCAPS_DITHER |
  1450. // D3DPRASTERCAPS_ROP2 |
  1451. // D3DPRASTERCAPS_XOR |
  1452. // D3DPRASTERCAPS_PAT |
  1453. D3DPRASTERCAPS_ZTEST |
  1454. D3DPRASTERCAPS_SUBPIXEL |
  1455. D3DPRASTERCAPS_SUBPIXELX |
  1456. D3DPRASTERCAPS_FOGVERTEX |
  1457. D3DPRASTERCAPS_FOGTABLE |
  1458. // D3DPRASTERCAPS_STIPPLE |
  1459. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  1460. // D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  1461. // D3DPRASTERCAPS_ANTIALIASEDGES |
  1462. D3DPRASTERCAPS_MIPMAPLODBIAS |
  1463. // D3DPRASTERCAPS_ZBIAS |
  1464. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  1465. D3DPRASTERCAPS_FOGRANGE |
  1466. D3DPRASTERCAPS_ANISOTROPY |
  1467. D3DPRASTERCAPS_WBUFFER |
  1468. // D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT |
  1469. D3DPRASTERCAPS_WFOG;
  1470. RefDevDesc.dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
  1471. RefDevDesc.dwDeviceZBufferBitDepth = DDBD_16 | DDBD_32;
  1472. // DX5 stuff (should be in sync with the extended caps reported below)
  1473. RefDevDesc.dwMinTextureWidth = 1;
  1474. RefDevDesc.dwMaxTextureWidth = 4096;
  1475. RefDevDesc.dwMinTextureHeight = 1;
  1476. RefDevDesc.dwMaxTextureHeight = 4096;
  1477. //
  1478. // set extended caps
  1479. //
  1480. RefExtCaps.dwSize = sizeof(RefExtCaps);
  1481. RefExtCaps.dwMinTextureWidth = 1;
  1482. RefExtCaps.dwMaxTextureWidth = 4096;
  1483. RefExtCaps.dwMinTextureHeight = 1;
  1484. RefExtCaps.dwMaxTextureHeight = 4096;
  1485. RefExtCaps.dwMinStippleWidth = 0; // stipple unsupported
  1486. RefExtCaps.dwMaxStippleWidth = 0;
  1487. RefExtCaps.dwMinStippleHeight = 0;
  1488. RefExtCaps.dwMaxStippleHeight = 0;
  1489. RefExtCaps.dwMaxTextureRepeat = 32768;
  1490. RefExtCaps.dwMaxTextureAspectRatio = 0; // no limit
  1491. RefExtCaps.dwMaxAnisotropy = 16;
  1492. RefExtCaps.dvGuardBandLeft = (bIsNullDevice) ? (-2048.f) : (-32768.f);
  1493. RefExtCaps.dvGuardBandTop = (bIsNullDevice) ? (-2048.f) : (-32768.f);
  1494. RefExtCaps.dvGuardBandRight = (bIsNullDevice) ? ( 2047.f) : ( 32767.f);
  1495. RefExtCaps.dvGuardBandBottom = (bIsNullDevice) ? ( 2047.f) : ( 32767.f);
  1496. RefExtCaps.dvExtentsAdjust = 0.; // AA kernel is 1.0 x 1.0
  1497. RefExtCaps.dwStencilCaps =
  1498. D3DSTENCILCAPS_KEEP |
  1499. D3DSTENCILCAPS_ZERO |
  1500. D3DSTENCILCAPS_REPLACE|
  1501. D3DSTENCILCAPS_INCRSAT|
  1502. D3DSTENCILCAPS_DECRSAT|
  1503. D3DSTENCILCAPS_INVERT |
  1504. D3DSTENCILCAPS_INCR |
  1505. D3DSTENCILCAPS_DECR;
  1506. RefExtCaps.dwFVFCaps = 8; // max number of tex coord sets
  1507. RefExtCaps.dwTextureOpCaps =
  1508. D3DTEXOPCAPS_DISABLE |
  1509. D3DTEXOPCAPS_SELECTARG1 |
  1510. D3DTEXOPCAPS_SELECTARG2 |
  1511. D3DTEXOPCAPS_MODULATE |
  1512. D3DTEXOPCAPS_MODULATE2X |
  1513. D3DTEXOPCAPS_MODULATE4X |
  1514. D3DTEXOPCAPS_ADD |
  1515. D3DTEXOPCAPS_ADDSIGNED |
  1516. D3DTEXOPCAPS_ADDSIGNED2X |
  1517. D3DTEXOPCAPS_SUBTRACT |
  1518. D3DTEXOPCAPS_ADDSMOOTH |
  1519. D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
  1520. D3DTEXOPCAPS_BLENDTEXTUREALPHA |
  1521. D3DTEXOPCAPS_BLENDFACTORALPHA |
  1522. D3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
  1523. D3DTEXOPCAPS_BLENDCURRENTALPHA |
  1524. D3DTEXOPCAPS_PREMODULATE |
  1525. D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
  1526. D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
  1527. D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
  1528. D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
  1529. D3DTEXOPCAPS_BUMPENVMAP |
  1530. D3DTEXOPCAPS_BUMPENVMAPLUMINANCE |
  1531. D3DTEXOPCAPS_DOTPRODUCT3 ;
  1532. RefExtCaps.wMaxTextureBlendStages = 8;
  1533. RefExtCaps.wMaxSimultaneousTextures = 8;
  1534. RefExtCaps.dwMaxActiveLights = 0xffffffff;
  1535. RefExtCaps.dvMaxVertexW = 1.0e10;
  1536. RefExtCaps.wMaxUserClipPlanes = RRMAX_USER_CLIPPLANES;
  1537. RefExtCaps.wMaxVertexBlendMatrices = RRMAX_WORLD_MATRICES;
  1538. RefExtCaps.dwVertexProcessingCaps = (D3DVTXPCAPS_TEXGEN |
  1539. D3DVTXPCAPS_MATERIALSOURCE7 |
  1540. D3DVTXPCAPS_VERTEXFOG |
  1541. D3DVTXPCAPS_DIRECTIONALLIGHTS |
  1542. D3DVTXPCAPS_POSITIONALLIGHTS |
  1543. D3DVTXPCAPS_LOCALVIEWER);
  1544. RefExtCaps.dwReserved1 = 0;
  1545. RefExtCaps.dwReserved2 = 0;
  1546. RefExtCaps.dwReserved3 = 0;
  1547. RefExtCaps.dwReserved4 = 0;
  1548. }
  1549. static D3DHAL_GLOBALDRIVERDATA RefDriverData;
  1550. static void DevDesc7ToDevDescV1( D3DDEVICEDESC_V1 *pOut, D3DDEVICEDESC7 *pIn )
  1551. {
  1552. // These fields are not available in D3DDEVICEDESC7.
  1553. // Zeroing them out, the front-end should not be using them
  1554. // DWORD dwFlags
  1555. // D3DCOLORMODEL dcmColorModel
  1556. // D3DTRANSFORMCAPS dtcTransformCaps
  1557. // BOOL bClipping
  1558. // D3DLIGHTINGCAPS dlcLightingCaps
  1559. // DWORD dwMaxBufferSize
  1560. // DWORD dwMaxVertexCount
  1561. // DWORD dwMinStippleWidth, dwMaxStippleWidth
  1562. // DWORD dwMinStippleHeight, dwMaxStippleHeight;
  1563. //
  1564. ZeroMemory( pOut, sizeof( D3DDEVICEDESC_V1 ) );
  1565. pOut->dwSize = sizeof( D3DDEVICEDESC_V1 );
  1566. // These are available in D3DDEVICEDESC7 so copy field by field
  1567. // to avoid any future problems based on the assumptions of size
  1568. pOut->dwDevCaps = pIn->dwDevCaps;
  1569. pOut->dpcLineCaps = pIn->dpcLineCaps;
  1570. pOut->dpcTriCaps = pIn->dpcTriCaps;
  1571. pOut->dwDeviceRenderBitDepth = pIn->dwDeviceRenderBitDepth;
  1572. pOut->dwDeviceZBufferBitDepth = pIn->dwDeviceZBufferBitDepth;
  1573. }
  1574. static void DevDesc7ToDevDesc( D3DDEVICEDESC *pOut, D3DDEVICEDESC7 *pIn )
  1575. {
  1576. pOut->dwSize = sizeof( D3DDEVICEDESC );
  1577. // These fields are not available in D3DDEVICEDESC7.
  1578. // Setting them to some sensible values
  1579. pOut->dwFlags =
  1580. D3DDD_COLORMODEL |
  1581. D3DDD_DEVCAPS |
  1582. D3DDD_TRANSFORMCAPS |
  1583. D3DDD_LIGHTINGCAPS |
  1584. D3DDD_BCLIPPING |
  1585. D3DDD_LINECAPS |
  1586. D3DDD_TRICAPS |
  1587. D3DDD_DEVICERENDERBITDEPTH |
  1588. D3DDD_DEVICEZBUFFERBITDEPTH |
  1589. D3DDD_MAXBUFFERSIZE |
  1590. D3DDD_MAXVERTEXCOUNT ;
  1591. pOut->dcmColorModel = D3DCOLOR_RGB;
  1592. pOut->dtcTransformCaps.dwSize = sizeof(D3DTRANSFORMCAPS);
  1593. pOut->dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
  1594. pOut->bClipping = TRUE;
  1595. pOut->dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
  1596. pOut->dlcLightingCaps.dwCaps =
  1597. D3DLIGHTCAPS_POINT |
  1598. D3DLIGHTCAPS_SPOT |
  1599. D3DLIGHTCAPS_DIRECTIONAL ;
  1600. pOut->dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
  1601. pOut->dlcLightingCaps.dwNumLights = 0;
  1602. pOut->dwMaxBufferSize = 0;
  1603. pOut->dwMaxVertexCount = BASE_VERTEX_COUNT;
  1604. pOut->dwMinStippleWidth = 0;
  1605. pOut->dwMaxStippleWidth = 0;
  1606. pOut->dwMinStippleHeight = 0;
  1607. pOut->dwMaxStippleHeight = 0;
  1608. // These are available in D3DDEVICEDESC7 so copy field by field
  1609. // to avoid any future problems based on the assumptions of size
  1610. pOut->dwDevCaps = pIn->dwDevCaps;
  1611. pOut->dpcLineCaps = pIn->dpcLineCaps;
  1612. pOut->dpcTriCaps = pIn->dpcTriCaps;
  1613. pOut->dwDeviceRenderBitDepth = pIn->dwDeviceRenderBitDepth;
  1614. pOut->dwDeviceZBufferBitDepth = pIn->dwDeviceZBufferBitDepth;
  1615. pOut->dwMinTextureWidth = pIn->dwMinTextureWidth;
  1616. pOut->dwMinTextureHeight = pIn->dwMinTextureHeight;
  1617. pOut->dwMaxTextureWidth = pIn->dwMaxTextureWidth;
  1618. pOut->dwMaxTextureHeight = pIn->dwMaxTextureHeight;
  1619. pOut->dwMaxTextureRepeat = pIn->dwMaxTextureRepeat;
  1620. pOut->dwMaxTextureAspectRatio = pIn->dwMaxTextureAspectRatio;
  1621. pOut->dwMaxAnisotropy = pIn->dwMaxAnisotropy;
  1622. pOut->dvGuardBandLeft = pIn->dvGuardBandLeft;
  1623. pOut->dvGuardBandTop = pIn->dvGuardBandTop;
  1624. pOut->dvGuardBandRight = pIn->dvGuardBandRight;
  1625. pOut->dvGuardBandBottom = pIn->dvGuardBandBottom;
  1626. pOut->dvExtentsAdjust = pIn->dvExtentsAdjust;
  1627. pOut->dwStencilCaps = pIn->dwStencilCaps;
  1628. pOut->dwFVFCaps = pIn->dwFVFCaps;
  1629. pOut->dwTextureOpCaps = pIn->dwTextureOpCaps;
  1630. pOut->wMaxTextureBlendStages = pIn->wMaxTextureBlendStages;
  1631. pOut->wMaxSimultaneousTextures = pIn->wMaxSimultaneousTextures;
  1632. }
  1633. STDMETHODIMP
  1634. RefRastHalProvider::GetInterface(THIS_
  1635. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  1636. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  1637. DWORD dwVersion)
  1638. {
  1639. // fill out device description & extended caps
  1640. FillOutDeviceCaps(FALSE);
  1641. // add extended caps to RefDevDesc
  1642. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps);
  1643. // fill out GLOBALDRIVERDATA (initially zero)
  1644. RefDriverData.dwSize = sizeof(RefDriverData);
  1645. //
  1646. // Need to fix up RefDriverData.hwCaps (D3DDEVICEDESC) from
  1647. // rgbDevDesc (D3DDEVICEDESC7)
  1648. //
  1649. DevDesc7ToDevDescV1( &RefDriverData.hwCaps, &RefDevDesc );
  1650. RefDriverData.dwNumVertices = BASE_VERTEX_COUNT;
  1651. RefDriverData.dwNumClipVertices = MAX_CLIP_VERTICES;
  1652. RefDriverData.dwNumTextureFormats =
  1653. GetRefTextureFormats(IID_IDirect3DRefDevice,
  1654. &RefDriverData.lpTextureFormats, dwVersion);
  1655. // set interface data for return
  1656. pInterfaceData->pGlobalData = &RefDriverData;
  1657. pInterfaceData->pExtCaps = &RefExtCaps;
  1658. pInterfaceData->pCallbacks = &Callbacks;
  1659. pInterfaceData->pCallbacks2 = &Callbacks2;
  1660. pInterfaceData->pCallbacks3 = &Callbacks3;
  1661. //
  1662. // This dwVersion==4 corresponds to DX7+
  1663. // This HalProvider interface is a hack to enable sw-drivers to
  1664. // behave like hw-hals hence this mysteriousness!
  1665. //
  1666. if( dwVersion >= 4 )
  1667. {
  1668. pInterfaceData->pfnGetDriverState = RefRastGetDriverState;
  1669. }
  1670. return S_OK;
  1671. }
  1672. STDMETHODIMP
  1673. RefRastHalProvider::GetCaps(THIS_
  1674. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  1675. LPD3DDEVICEDESC7 pHwDesc,
  1676. LPD3DDEVICEDESC7 pHelDesc,
  1677. DWORD dwVersion)
  1678. {
  1679. // fill out device description & extended caps
  1680. FillOutDeviceCaps(FALSE);
  1681. // add extended caps to RefDevDesc
  1682. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps);
  1683. //
  1684. // This dwVersion==4 corresponds to DX7+
  1685. // This HalProvider interface is a hack to enable sw-drivers to
  1686. // behave like hw-hals hence this mysteriousness!
  1687. //
  1688. if (dwVersion < 4)
  1689. {
  1690. ZeroMemory( pHwDesc, sizeof( D3DDEVICEDESC ));
  1691. ((D3DDEVICEDESC *)pHwDesc)->dwSize = sizeof( D3DDEVICEDESC );
  1692. DevDesc7ToDevDesc( (D3DDEVICEDESC *)pHelDesc, &RefDevDesc );
  1693. }
  1694. else
  1695. {
  1696. memcpy(pHwDesc, &g_nullDevDesc, sizeof(D3DDEVICEDESC7));
  1697. memcpy(pHelDesc, &RefDevDesc, sizeof(D3DDEVICEDESC7));
  1698. }
  1699. return D3D_OK;
  1700. }
  1701. //----------------------------------------------------------------------------
  1702. //
  1703. // Null Device implementation section
  1704. //
  1705. //----------------------------------------------------------------------------
  1706. //----------------------------------------------------------------------------
  1707. // NullDeviceContextCreate
  1708. //----------------------------------------------------------------------------
  1709. DWORD __stdcall
  1710. NullDeviceContextCreate(LPD3DHAL_CONTEXTCREATEDATA pData)
  1711. {
  1712. pData->ddrval = D3D_OK;
  1713. return DDHAL_DRIVER_HANDLED;
  1714. }
  1715. //----------------------------------------------------------------------------
  1716. // NullDeviceContextDestroy
  1717. //----------------------------------------------------------------------------
  1718. DWORD __stdcall
  1719. NullDeviceContextDestroy(LPD3DHAL_CONTEXTDESTROYDATA pData)
  1720. {
  1721. pData->ddrval = D3D_OK;
  1722. return DDHAL_DRIVER_HANDLED;
  1723. }
  1724. //----------------------------------------------------------------------------
  1725. // NullDeviceSceneCapture
  1726. //----------------------------------------------------------------------------
  1727. DWORD __stdcall
  1728. NullDeviceSceneCapture(LPD3DHAL_SCENECAPTUREDATA pData)
  1729. {
  1730. pData->ddrval = D3D_OK;
  1731. return DDHAL_DRIVER_HANDLED;
  1732. }
  1733. //----------------------------------------------------------------------------
  1734. // NullDeviceSetRenderTarget
  1735. //----------------------------------------------------------------------------
  1736. DWORD __stdcall
  1737. NullDeviceSetRenderTarget(LPD3DHAL_SETRENDERTARGETDATA pData)
  1738. {
  1739. pData->ddrval = D3D_OK;
  1740. return DDHAL_DRIVER_HANDLED;
  1741. }
  1742. //----------------------------------------------------------------------------
  1743. // NullDeviceDrawOneIndexedPrimitive
  1744. //----------------------------------------------------------------------------
  1745. DWORD __stdcall
  1746. NullDeviceDrawOneIndexedPrimitive(LPD3DHAL_DRAWONEINDEXEDPRIMITIVEDATA pData)
  1747. {
  1748. pData->ddrval = D3D_OK;
  1749. return DDHAL_DRIVER_HANDLED;
  1750. }
  1751. //----------------------------------------------------------------------------
  1752. // NullDeviceDrawOnePrimitive
  1753. //----------------------------------------------------------------------------
  1754. DWORD __stdcall
  1755. NullDeviceDrawOnePrimitive(LPD3DHAL_DRAWONEPRIMITIVEDATA pData)
  1756. {
  1757. pData->ddrval = D3D_OK;
  1758. return DDHAL_DRIVER_HANDLED;
  1759. }
  1760. //----------------------------------------------------------------------------
  1761. // NullDeviceDrawPrimitives
  1762. //----------------------------------------------------------------------------
  1763. DWORD __stdcall
  1764. NullDeviceDrawPrimitives(LPD3DHAL_DRAWPRIMITIVESDATA pData)
  1765. {
  1766. pData->ddrval = D3D_OK;
  1767. return DDHAL_DRIVER_HANDLED;
  1768. }
  1769. //----------------------------------------------------------------------------
  1770. // NullDeviceDrawPrimitives2
  1771. //----------------------------------------------------------------------------
  1772. DWORD __stdcall
  1773. NullDeviceDrawPrimitives2(LPD3DHAL_DRAWPRIMITIVES2DATA pData)
  1774. {
  1775. pData->ddrval = D3D_OK;
  1776. return DDHAL_DRIVER_HANDLED;
  1777. }
  1778. //----------------------------------------------------------------------------
  1779. // NullDeviceTextureCreate
  1780. //----------------------------------------------------------------------------
  1781. DWORD __stdcall
  1782. NullDeviceTextureCreate(LPD3DHAL_TEXTURECREATEDATA pData)
  1783. {
  1784. pData->ddrval = D3D_OK;
  1785. return DDHAL_DRIVER_HANDLED;
  1786. }
  1787. //----------------------------------------------------------------------------
  1788. // NullDeviceTextureDestroy
  1789. //----------------------------------------------------------------------------
  1790. DWORD __stdcall
  1791. NullDeviceTextureDestroy(LPD3DHAL_TEXTUREDESTROYDATA pData)
  1792. {
  1793. pData->ddrval = D3D_OK;
  1794. return DDHAL_DRIVER_HANDLED;
  1795. }
  1796. //----------------------------------------------------------------------------
  1797. // NullDeviceTextureGetSurf
  1798. //----------------------------------------------------------------------------
  1799. DWORD __stdcall
  1800. NullDeviceTextureGetSurf(LPD3DHAL_TEXTUREGETSURFDATA pData)
  1801. {
  1802. pData->ddrval = D3D_OK;
  1803. return DDHAL_DRIVER_HANDLED;
  1804. }
  1805. //----------------------------------------------------------------------------
  1806. // NullDeviceRenderPrimitive
  1807. //----------------------------------------------------------------------------
  1808. DWORD __stdcall
  1809. NullDeviceRenderPrimitive(LPD3DHAL_RENDERPRIMITIVEDATA pData)
  1810. {
  1811. pData->ddrval = D3D_OK;
  1812. return DDHAL_DRIVER_HANDLED;
  1813. }
  1814. //----------------------------------------------------------------------------
  1815. // NullDeviceRenderState
  1816. //----------------------------------------------------------------------------
  1817. DWORD __stdcall
  1818. NullDeviceRenderState(LPD3DHAL_RENDERSTATEDATA pData)
  1819. {
  1820. pData->ddrval = D3D_OK;
  1821. return DDHAL_DRIVER_HANDLED;
  1822. }
  1823. //----------------------------------------------------------------------------
  1824. // NullDeviceValidateTextureStageState
  1825. //----------------------------------------------------------------------------
  1826. DWORD __stdcall
  1827. NullDeviceValidateTextureStageState(LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA pData)
  1828. {
  1829. pData->dwNumPasses = 1;
  1830. pData->ddrval = D3D_OK;
  1831. return DDHAL_DRIVER_HANDLED;
  1832. }
  1833. //----------------------------------------------------------------------------
  1834. //
  1835. // NullDeviceHalProvider::GetCaps/GetInterface
  1836. //
  1837. // Returns the null device's HAL interface.
  1838. // RefRast's caps are reflected by this device. Only the actual callbacks
  1839. // are different.
  1840. //----------------------------------------------------------------------------
  1841. static D3DHAL_CALLBACKS NullCallbacks =
  1842. {
  1843. sizeof(D3DHAL_CALLBACKS),
  1844. NullDeviceContextCreate,
  1845. NullDeviceContextDestroy,
  1846. NULL,
  1847. NullDeviceSceneCapture,
  1848. NULL,
  1849. NULL,
  1850. NullDeviceRenderState,
  1851. NullDeviceRenderPrimitive,
  1852. NULL,
  1853. NullDeviceTextureCreate,
  1854. NullDeviceTextureDestroy,
  1855. NULL,
  1856. NullDeviceTextureGetSurf,
  1857. // All others NULL.
  1858. };
  1859. static D3DHAL_CALLBACKS2 NullCallbacks2 =
  1860. {
  1861. sizeof(D3DHAL_CALLBACKS2),
  1862. D3DHAL2_CB32_SETRENDERTARGET |
  1863. D3DHAL2_CB32_DRAWONEPRIMITIVE |
  1864. D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE |
  1865. D3DHAL2_CB32_DRAWPRIMITIVES,
  1866. NullDeviceSetRenderTarget,
  1867. NULL,
  1868. NullDeviceDrawOnePrimitive,
  1869. NullDeviceDrawOneIndexedPrimitive,
  1870. NullDeviceDrawPrimitives
  1871. };
  1872. static D3DHAL_CALLBACKS3 NullCallbacks3 =
  1873. {
  1874. sizeof(D3DHAL_CALLBACKS3),
  1875. D3DHAL3_CB32_VALIDATETEXTURESTAGESTATE |
  1876. D3DHAL3_CB32_DRAWPRIMITIVES2,
  1877. NULL, // Clear2
  1878. NULL, // lpvReserved
  1879. NullDeviceValidateTextureStageState,
  1880. NullDeviceDrawPrimitives2,
  1881. };
  1882. STDMETHODIMP
  1883. NullDeviceHalProvider::GetInterface(THIS_
  1884. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  1885. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  1886. DWORD dwVersion)
  1887. {
  1888. // fill out device description & extended caps
  1889. FillOutDeviceCaps(TRUE);
  1890. // add extended caps to RefDevDesc
  1891. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps);
  1892. // fill out GLOBALDRIVERDATA (initially zero)
  1893. RefDriverData.dwSize = sizeof(RefDriverData);
  1894. DevDesc7ToDevDescV1( &RefDriverData.hwCaps, &RefDevDesc );
  1895. RefDriverData.dwNumVertices = BASE_VERTEX_COUNT;
  1896. RefDriverData.dwNumClipVertices = MAX_CLIP_VERTICES;
  1897. RefDriverData.dwNumTextureFormats =
  1898. GetRefTextureFormats(IID_IDirect3DNullDevice,
  1899. &RefDriverData.lpTextureFormats, dwVersion);
  1900. // set interface data for return
  1901. pInterfaceData->pGlobalData = &RefDriverData;
  1902. pInterfaceData->pExtCaps = &RefExtCaps;
  1903. pInterfaceData->pCallbacks = &NullCallbacks;
  1904. pInterfaceData->pCallbacks2 = &NullCallbacks2;
  1905. pInterfaceData->pCallbacks3 = &NullCallbacks3;
  1906. return S_OK;
  1907. }
  1908. STDMETHODIMP
  1909. NullDeviceHalProvider::GetCaps(THIS_
  1910. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  1911. LPD3DDEVICEDESC7 pHwDesc,
  1912. LPD3DDEVICEDESC7 pHelDesc,
  1913. DWORD dwVersion)
  1914. {
  1915. *pHwDesc = g_nullDevDesc;
  1916. // fill out device description & extended caps
  1917. FillOutDeviceCaps(TRUE);
  1918. // add extended caps to RefDevDesc
  1919. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps);
  1920. //
  1921. // This dwVersion==4 corresponds to DX7+
  1922. // This HalProvider interface is a hack to enable sw-drivers to
  1923. // behave like hw-hals hence this mysteriousness!
  1924. //
  1925. if (dwVersion < 4)
  1926. {
  1927. ZeroMemory( pHwDesc, sizeof( D3DDEVICEDESC ));
  1928. ((D3DDEVICEDESC *)pHwDesc)->dwSize = sizeof( D3DDEVICEDESC );
  1929. DevDesc7ToDevDesc( (D3DDEVICEDESC *)pHelDesc, &RefDevDesc );
  1930. }
  1931. else
  1932. {
  1933. memcpy(pHwDesc, &g_nullDevDesc, sizeof(D3DDEVICEDESC7));
  1934. memcpy(pHelDesc, &RefDevDesc, sizeof(D3DDEVICEDESC7));
  1935. }
  1936. return D3D_OK;
  1937. }