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.

2713 lines
98 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. // The DDI refrast is emulating
  13. RDDDITYPE g_RefDDI;
  14. // All the supported texture formats
  15. DDSURFACEDESC g_ddsdTex[RD_MAX_NUM_TEXTURE_FORMATS];
  16. // The current caps8 for newly created devices
  17. static D3DCAPS8 g_RefCaps8;
  18. // Maps D3DMULTISAMPLE_TYPE into the bit to use for the flags.
  19. // Maps each of the multisampling values (2 to 16) to the bits[1] to bits[15]
  20. // of wBltMSTypes and wFlipMSTypes
  21. #define DDI_MULTISAMPLE_TYPE(x) (1 << ((x)-1))
  22. //----------------------------------------------------------------------------
  23. //
  24. // RefRastUpdatePalettes
  25. //
  26. //----------------------------------------------------------------------------
  27. HRESULT
  28. RefRastUpdatePalettes(RefDev *pRefDev)
  29. {
  30. INT i, j, k;
  31. RDSurface2D* pRDTex[D3DHAL_TSS_MAXSTAGES];
  32. D3DTEXTUREHANDLE phTex[D3DHAL_TSS_MAXSTAGES];
  33. HRESULT hr;
  34. int cActTex;
  35. if ((cActTex = pRefDev->GetCurrentTextureMaps(phTex, pRDTex)) == 0)
  36. {
  37. return D3D_OK;
  38. }
  39. for (j = 0; j < cActTex; j++)
  40. {
  41. // stages may not have texture bound
  42. if ( NULL == pRDTex[j] ) continue;
  43. pRDTex[j]->UpdatePalette();
  44. }
  45. return D3D_OK;
  46. }
  47. //----------------------------------------------------------------------------
  48. //
  49. // RDRenderTarget::Initialize
  50. //
  51. // Converts color and Z surface information into refrast form.
  52. //
  53. //----------------------------------------------------------------------------
  54. HRESULT
  55. RDRenderTarget::Initialize( LPDDRAWI_DDRAWSURFACE_LCL pLclColor,
  56. LPDDRAWI_DDRAWSURFACE_LCL pLclZ )
  57. {
  58. HRESULT hr;
  59. RDSurfaceFormat ColorFmt;
  60. RDSurfaceFormat ZFmt;
  61. RDSurface2D* pOldColor = m_pColor;
  62. RDSurface2D* pOldDepth = m_pDepth;
  63. if( m_pColor )
  64. {
  65. m_pColor = NULL;
  66. }
  67. if( m_pDepth )
  68. {
  69. m_pDepth = NULL;
  70. }
  71. // Find the surfaces from the global surface manager
  72. // We are assuming that CreateSurfaceEx has been called on these
  73. // surfaces before this.
  74. RDSurface2D* pColor = m_pColor = new RDSurface2D;
  75. if( pColor == NULL )
  76. {
  77. DPFERR( "Color surface could not be allocated" );
  78. m_pColor = pOldColor;
  79. m_pDepth = pOldDepth;
  80. return DDERR_OUTOFMEMORY;
  81. }
  82. if( FAILED( hr = pColor->Initialize( pLclColor ) ) )
  83. {
  84. DPFERR( "Unable to initialize the color buffer" );
  85. delete pColor;
  86. m_pColor = pOldColor;
  87. m_pDepth = pOldDepth;
  88. return hr;
  89. }
  90. if (NULL != pLclZ)
  91. {
  92. RDSurface2D* pDepth = m_pDepth = new RDSurface2D;
  93. if( pDepth == NULL )
  94. {
  95. DPFERR( "Depth surface could not be allocated" );
  96. delete pColor;
  97. m_pColor = pOldColor;
  98. m_pDepth = pOldDepth;
  99. return DDERR_OUTOFMEMORY;
  100. }
  101. if( FAILED( hr = pDepth->Initialize( pLclZ ) ) )
  102. {
  103. DPFERR("Unable to initialize the Depth buffer");
  104. delete pColor;
  105. delete pDepth;
  106. m_pColor = pOldColor;
  107. m_pDepth = pOldDepth;
  108. return hr;
  109. }
  110. }
  111. m_Clip.left = 0;
  112. m_Clip.top = 0;
  113. m_Clip.bottom = pColor->GetHeight() - 1;
  114. m_Clip.right = pColor->GetWidth() - 1;
  115. m_bPreDX7DDI = TRUE;
  116. delete pOldColor;
  117. delete pOldDepth;
  118. return D3D_OK;
  119. }
  120. //----------------------------------------------------------------------------
  121. //
  122. // RDRenderTarget::Initialize
  123. //
  124. // Converts color and Z surface information into refrast form.
  125. //
  126. //----------------------------------------------------------------------------
  127. HRESULT
  128. RDRenderTarget::Initialize( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  129. LPDDRAWI_DDRAWSURFACE_LCL pLclColor,
  130. LPDDRAWI_DDRAWSURFACE_LCL pLclZ )
  131. {
  132. HRESULT hr;
  133. RDSurfaceFormat ColorFmt;
  134. RDSurfaceFormat ZFmt;
  135. RDSurface2D* pOldColor = m_pColor;
  136. RDSurface2D* pOldDepth = m_pDepth;
  137. if( m_pColor )
  138. {
  139. m_pColor = NULL;
  140. }
  141. if( m_pDepth )
  142. {
  143. m_pDepth = NULL;
  144. }
  145. // Find the surfaces from the global surface manager
  146. // We are assuming that CreateSurfaceEx has been called on these
  147. // surfaces before this.
  148. DWORD dwColorHandle = pLclColor->lpSurfMore->dwSurfaceHandle;
  149. RDSurface2D* pColor = m_pColor =
  150. (RDSurface2D *)g_SurfMgr.GetSurfFromList( pDDLcl,
  151. dwColorHandle);
  152. if( pColor == NULL )
  153. {
  154. DPFERR("Color surface not found");
  155. m_pColor = pOldColor;
  156. m_pDepth = pOldDepth;
  157. return DDERR_INVALIDPARAMS;
  158. }
  159. if (NULL != pLclZ)
  160. {
  161. DWORD dwDepthHandle = pLclZ->lpSurfMore->dwSurfaceHandle;
  162. RDSurface2D* pDepth = m_pDepth =
  163. (RDSurface2D *)g_SurfMgr.GetSurfFromList( pDDLcl,
  164. dwDepthHandle);
  165. if( pDepth == NULL )
  166. {
  167. DPFERR("Depth surface not found");
  168. m_pColor = pOldColor;
  169. m_pDepth = pOldDepth;
  170. return DDERR_INVALIDPARAMS;
  171. }
  172. }
  173. m_Clip.left = 0;
  174. m_Clip.top = 0;
  175. m_Clip.bottom = pColor->GetHeight() - 1;
  176. m_Clip.right = pColor->GetWidth() - 1;
  177. return D3D_OK;
  178. }
  179. //----------------------------------------------------------------------------
  180. //
  181. // RDRenderTarget::Initialize
  182. //
  183. // Converts color and Z surface information into refrast form.
  184. //
  185. //----------------------------------------------------------------------------
  186. HRESULT
  187. RDRenderTarget::Initialize( LPDDRAWI_DIRECTDRAW_LCL pDDLcl,
  188. DWORD dwColorHandle,
  189. DWORD dwDepthHandle )
  190. {
  191. HRESULT hr;
  192. RDSurfaceFormat ColorFmt;
  193. RDSurfaceFormat ZFmt;
  194. RDSurface2D* pOldColor = m_pColor;
  195. RDSurface2D* pOldDepth = m_pDepth;
  196. // Release objects we hold pointers to
  197. if( m_pColor )
  198. {
  199. m_pColor = NULL;
  200. }
  201. if( m_pDepth )
  202. {
  203. m_pDepth = NULL;
  204. }
  205. // Find the surfaces from the global surface manager
  206. // We are assuming that CreateSurfaceEx has been called on these
  207. // surfaces before this.
  208. RDSurface2D* pColor = m_pColor =
  209. (RDSurface2D *)g_SurfMgr.GetSurfFromList( pDDLcl,
  210. dwColorHandle);
  211. if( pColor == NULL )
  212. {
  213. DPFERR("Color surface not found");
  214. m_pColor = pOldColor;
  215. m_pDepth = pOldDepth;
  216. return DDERR_INVALIDPARAMS;
  217. }
  218. if (0 != dwDepthHandle)
  219. {
  220. RDSurface2D* pDepth = m_pDepth =
  221. (RDSurface2D *)g_SurfMgr.GetSurfFromList( pDDLcl,
  222. dwDepthHandle);
  223. if( pDepth == NULL )
  224. {
  225. DPFERR("Depth surface not found");
  226. m_pColor = pOldColor;
  227. m_pDepth = pOldDepth;
  228. return DDERR_INVALIDPARAMS;
  229. }
  230. }
  231. m_Clip.left = 0;
  232. m_Clip.top = 0;
  233. m_Clip.bottom = pColor->GetHeight() - 1;
  234. m_Clip.right = pColor->GetWidth() - 1;
  235. return D3D_OK;
  236. }
  237. //----------------------------------------------------------------------------
  238. //
  239. // RefRastContextCreate
  240. //
  241. // Creates a RefDev and initializes it with the info passed in.
  242. //
  243. //----------------------------------------------------------------------------
  244. DWORD __stdcall
  245. RefRastContextCreate(LPD3DHAL_CONTEXTCREATEDATA pCtxData)
  246. {
  247. RefDev *pRefDev;
  248. RDRenderTarget *pRendTgt;
  249. INT i;
  250. // Surface7 pointers for QI
  251. LPDDRAWI_DDRAWSURFACE_LCL pZLcl = NULL;
  252. LPDDRAWI_DDRAWSURFACE_LCL pColorLcl = NULL;
  253. HRESULT ret;
  254. DPFM(0, DRV, ("In the new RefRast Dll\n"));
  255. // this only needs to be called once, but once per context won't hurt
  256. RefRastSetMemif(&malloc, &free, &realloc);
  257. if ((pRendTgt = new RDRenderTarget()) == NULL)
  258. {
  259. pCtxData->ddrval = DDERR_OUTOFMEMORY;
  260. return DDHAL_DRIVER_HANDLED;
  261. }
  262. // If it is expected to be a DX7+ driver
  263. if (g_RefDDI < RDDDI_DX7HAL)
  264. {
  265. if (pCtxData->lpDDS)
  266. pColorLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pCtxData->lpDDS))->lpLcl;
  267. if (pCtxData->lpDDSZ)
  268. pZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pCtxData->lpDDSZ))->lpLcl;
  269. // Collect surface information where the failures are easy to handle.
  270. pCtxData->ddrval = pRendTgt->Initialize( pColorLcl, pZLcl );
  271. }
  272. else
  273. {
  274. pColorLcl = pCtxData->lpDDSLcl;
  275. pZLcl = pCtxData->lpDDSZLcl;
  276. // Collect surface information where the failures are easy to handle.
  277. pCtxData->ddrval = pRendTgt->Initialize( pCtxData->lpDDLcl, pColorLcl,
  278. pZLcl );
  279. }
  280. if (pCtxData->ddrval != D3D_OK)
  281. {
  282. delete pRendTgt;
  283. return DDHAL_DRIVER_HANDLED;
  284. }
  285. // Note:
  286. // dwhContext is used by the runtime to inform the driver, which
  287. // d3d interface is calling the driver.
  288. if ( ( pRefDev = new RefDev( pCtxData->lpDDLcl,
  289. (DWORD)(pCtxData->dwhContext),
  290. g_RefDDI, &g_RefCaps8 ) ) == NULL )
  291. {
  292. pCtxData->ddrval = DDERR_OUTOFMEMORY;
  293. return DDHAL_DRIVER_HANDLED;
  294. }
  295. pRefDev->SetRenderTarget( pRendTgt );
  296. // return RR object pointer as context handle
  297. pCtxData->dwhContext = (ULONG_PTR)pRefDev;
  298. pCtxData->ddrval = D3D_OK;
  299. return DDHAL_DRIVER_HANDLED;
  300. }
  301. //----------------------------------------------------------------------------
  302. //
  303. // RefRastContextDestroy
  304. //
  305. // Destroy a RefDev.
  306. //
  307. //----------------------------------------------------------------------------
  308. DWORD __stdcall
  309. RefRastContextDestroy(LPD3DHAL_CONTEXTDESTROYDATA pCtxDestroyData)
  310. {
  311. RefDev *pRefDev;
  312. // Check RefDev
  313. VALIDATE_REFRAST_CONTEXT("RefRastContextDestroy", pCtxDestroyData);
  314. // Clean up override bits
  315. RDRenderTarget *pRendTgt = pRefDev->GetRenderTarget();
  316. if ( NULL != pRendTgt ) { delete pRendTgt; }
  317. delete pRefDev;
  318. pCtxDestroyData->ddrval = D3D_OK;
  319. return DDHAL_DRIVER_HANDLED;
  320. }
  321. //----------------------------------------------------------------------------
  322. //
  323. // RefRastSceneCapture
  324. //
  325. // Pass scene capture callback to ref rast.
  326. //
  327. //----------------------------------------------------------------------------
  328. DWORD __stdcall
  329. RefRastSceneCapture(LPD3DHAL_SCENECAPTUREDATA pData)
  330. {
  331. RefDev *pRefDev;
  332. // Check RefDev
  333. VALIDATE_REFRAST_CONTEXT("RefRastSceneCapture", pData);
  334. pRefDev->SceneCapture( pData->dwFlag );
  335. pData->ddrval = D3D_OK; // Should this be changed to a QI ?
  336. return DDHAL_DRIVER_HANDLED;
  337. }
  338. //----------------------------------------------------------------------------
  339. //
  340. // RefRastSetRenderTarget
  341. //
  342. // Update a RefRast context with the info from a new render target.
  343. //
  344. //----------------------------------------------------------------------------
  345. DWORD __stdcall
  346. RefRastSetRenderTarget(LPD3DHAL_SETRENDERTARGETDATA pTgtData)
  347. {
  348. RefDev *pRefDev;
  349. LPDDRAWI_DDRAWSURFACE_LCL pZLcl = NULL;
  350. LPDDRAWI_DDRAWSURFACE_LCL pColorLcl = NULL;
  351. HRESULT ret;
  352. // Check RefDev
  353. VALIDATE_REFRAST_CONTEXT("RefRastSetRenderTarget", pTgtData);
  354. _ASSERT( pRefDev->IsDriverDX6AndBefore(), "This callback should"
  355. "never be called on DDIs DX7 and beyond" )
  356. _ASSERT( pRefDev->IsInterfaceDX6AndBefore(), "An older interface should"
  357. "never call this DLL" )
  358. RDRenderTarget *pRendTgt = pRefDev->GetRenderTarget();
  359. if ( NULL == pRendTgt ) { return DDHAL_DRIVER_HANDLED; }
  360. if( pTgtData->lpDDS )
  361. pColorLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pTgtData->lpDDS))->lpLcl;
  362. if( pTgtData->lpDDSZ )
  363. pZLcl = ((LPDDRAWI_DDRAWSURFACE_INT)(pTgtData->lpDDSZ))->lpLcl;
  364. // Collect surface information.
  365. pTgtData->ddrval = pRendTgt->Initialize( pColorLcl, pZLcl);
  366. if (pTgtData->ddrval != D3D_OK)
  367. {
  368. return DDHAL_DRIVER_HANDLED;
  369. }
  370. pRefDev->SetRenderTarget(pRendTgt);
  371. return DDHAL_DRIVER_HANDLED;
  372. }
  373. //----------------------------------------------------------------------------
  374. //
  375. // RefRastValidateTextureStageState
  376. //
  377. // Validate current blend operations. RefRast does everything.
  378. //
  379. //----------------------------------------------------------------------------
  380. DWORD __stdcall
  381. RefRastValidateTextureStageState(LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA pData)
  382. {
  383. RefDev *pRefDev;
  384. // Check RefDev
  385. VALIDATE_REFRAST_CONTEXT("RefRastValidateTextureStageState", pData);
  386. pData->dwNumPasses = 1;
  387. pData->ddrval = D3D_OK;
  388. return DDHAL_DRIVER_HANDLED;
  389. }
  390. //----------------------------------------------------------------------------
  391. //
  392. // RefRastTextureCreate
  393. //
  394. // Creates a RefRast texture and initializes it with the info passed in.
  395. //
  396. //----------------------------------------------------------------------------
  397. DWORD __stdcall
  398. RefRastTextureCreate(LPD3DHAL_TEXTURECREATEDATA pTexData)
  399. {
  400. RefDev *pRefDev;
  401. RDSurface2D* pRDTex;
  402. HRESULT hr;
  403. LPDDRAWI_DDRAWSURFACE_LCL pLcl;
  404. if (pTexData->lpDDS)
  405. {
  406. pLcl = ((LPDDRAWI_DDRAWSURFACE_INT)pTexData->lpDDS)->lpLcl;
  407. }
  408. // Check RefDev
  409. VALIDATE_REFRAST_CONTEXT("RefRastTextureCreate", pTexData);
  410. // Runtime shouldnt be calling TextureCreate for DX7 and newer
  411. // driver models
  412. _ASSERT( pRefDev->IsDriverDX6AndBefore(), "This DDI should not"
  413. "be called from DDIs previous to DX7" );
  414. // assume OKness
  415. pTexData->ddrval = D3D_OK;
  416. // Allocate RDSurface2D
  417. if ( !(pRefDev->TextureCreate(
  418. (LPD3DTEXTUREHANDLE)&(pTexData->dwHandle), &pRDTex ) ) )
  419. {
  420. pTexData->ddrval = DDERR_GENERIC;
  421. return DDHAL_DRIVER_HANDLED;
  422. }
  423. // Init texturemap.
  424. hr = pRDTex->Initialize( pLcl );
  425. if (hr != D3D_OK)
  426. {
  427. pTexData->ddrval = hr;
  428. return DDHAL_DRIVER_HANDLED;
  429. }
  430. return DDHAL_DRIVER_HANDLED;
  431. }
  432. //----------------------------------------------------------------------------
  433. //
  434. // RefRastTextureDestroy
  435. //
  436. // Destroy a RefRast texture.
  437. //
  438. //----------------------------------------------------------------------------
  439. DWORD __stdcall
  440. RefRastTextureDestroy(LPD3DHAL_TEXTUREDESTROYDATA pTexDestroyData)
  441. {
  442. RefDev *pRefDev;
  443. // Check RefDev
  444. VALIDATE_REFRAST_CONTEXT("RefRastTextureDestroy", pTexDestroyData);
  445. // Runtime shouldnt be Calling TextureCreate for DX7 and newer
  446. // driver models
  447. _ASSERT( pRefDev->IsDriverDX6AndBefore(), "This DDI should not"
  448. "be called from DDIs previous to DX7" );
  449. if (!(pRefDev->TextureDestroy(pTexDestroyData->dwHandle)))
  450. {
  451. pTexDestroyData->ddrval = DDERR_GENERIC;
  452. }
  453. else
  454. {
  455. pTexDestroyData->ddrval = D3D_OK;
  456. }
  457. return DDHAL_DRIVER_HANDLED;
  458. }
  459. //----------------------------------------------------------------------------
  460. //
  461. // RefRastTextureGetSurf
  462. //
  463. // Returns the surface pointer associate with a texture handle.
  464. //
  465. //----------------------------------------------------------------------------
  466. DWORD __stdcall
  467. RefRastTextureGetSurf(LPD3DHAL_TEXTUREGETSURFDATA pTexGetSurf)
  468. {
  469. RefDev *pRefDev;
  470. // Check RefDev
  471. VALIDATE_REFRAST_CONTEXT("RefRastTextureGetSurf", pTexGetSurf);
  472. pTexGetSurf->lpDDS = pRefDev->TextureGetSurf(pTexGetSurf->dwHandle);
  473. pTexGetSurf->ddrval = D3D_OK;
  474. return DDHAL_DRIVER_HANDLED;
  475. }
  476. //----------------------------------------------------------------------------
  477. //
  478. // RefRastGetDriverState
  479. //
  480. // Called by the runtime to get any kind of driver information
  481. //
  482. //----------------------------------------------------------------------------
  483. DWORD __stdcall
  484. RefRastGetDriverState(LPDDHAL_GETDRIVERSTATEDATA pGDSData)
  485. {
  486. RefDev *pRefDev;
  487. // Check RefDev
  488. #if DBG
  489. if ((pGDSData) == NULL)
  490. {
  491. DPFERR("in %s, data pointer = NULL", "RefRastGetDriverState");
  492. return DDHAL_DRIVER_HANDLED;
  493. }
  494. pRefDev = (RefDev *)ULongToPtr((pGDSData)->dwhContext);
  495. if (!pRefDev)
  496. {
  497. DPFERR("in %s, dwhContext = NULL", "RefRastGetDriverState");
  498. pGDSData->ddRVal = D3DHAL_CONTEXT_BAD;
  499. return DDHAL_DRIVER_HANDLED;
  500. }
  501. #else // !DBG
  502. pRefDev = (RefDev *)ULongToPtr((pGDSData)->dwhContext);
  503. #endif // !DBG
  504. //
  505. // No implementation yet, so nothing is understood yet
  506. //
  507. pGDSData->ddRVal = S_FALSE;
  508. return DDHAL_DRIVER_HANDLED;
  509. }
  510. //----------------------------------------------------------------------------
  511. //
  512. // FindAttachedSurfaceCaps2
  513. //
  514. // Walks the attachment list for the surface, looking for an attachment
  515. // that has any of the dwCaps2 bits (or ignores if zero) and none of the
  516. // FindAttachedSurfaceCaps2NotPresent bits.
  517. //
  518. //----------------------------------------------------------------------------
  519. LPDDRAWI_DDRAWSURFACE_LCL
  520. FindAttachedSurfaceCaps2(
  521. LPDDRAWI_DDRAWSURFACE_LCL pLcl,
  522. DWORD dwCaps2)
  523. {
  524. LPATTACHLIST lpAttachStruct = pLcl->lpAttachList;
  525. while(lpAttachStruct)
  526. {
  527. if ((dwCaps2 == 0) || (lpAttachStruct->lpAttached->lpSurfMore->ddsCapsEx.dwCaps2 & dwCaps2))
  528. return lpAttachStruct->lpAttached;
  529. lpAttachStruct = lpAttachStruct->lpLink;
  530. }
  531. return 0;
  532. }
  533. //----------------------------------------------------------------------------
  534. //
  535. // ProcessPossibleMipMap
  536. //
  537. // Record private data structure for this surface and all attached mip
  538. // sublevels.
  539. //
  540. //----------------------------------------------------------------------------
  541. void
  542. ProcessPossibleMipMap(
  543. LPDDHAL_CREATESURFACEEXDATA p,
  544. LPDDRAWI_DDRAWSURFACE_LCL lpDDSMipLcl
  545. )
  546. {
  547. do
  548. {
  549. // This function should not deal with deletions. Assert this.
  550. _ASSERT( SURFACE_MEMORY(lpDDSMipLcl),
  551. "Delete should have already taken place" );
  552. p->ddRVal = g_SurfMgr.AddSurfToList( p->lpDDLcl, lpDDSMipLcl, NULL );
  553. if (FAILED(p->ddRVal))
  554. return;
  555. // Now search down the 2nd+ order attachment: the chain
  556. // of mip sublevels.
  557. lpDDSMipLcl = FindAttachedSurfaceCaps2(lpDDSMipLcl,
  558. DDSCAPS2_MIPMAPSUBLEVEL);
  559. }
  560. while (lpDDSMipLcl);
  561. }
  562. //----------------------------------------------------------------------------
  563. //
  564. // RefRastCreateSurfaceEx
  565. //
  566. // Refrast implementation of CreateSurfaceEx. g_SurfMgr is the object
  567. // that does the real job.
  568. //
  569. // CreateSurfaceEx is also used to inform the driver to create and destroy
  570. // surface representations for a given handle. The way the driver can tell
  571. // the difference between create and destroy is by looking at the fpVidmem
  572. // pointer of the passed local. If it is null, it is a destroy.
  573. //
  574. // Create: This call is atomic. i.e. the attachments are all done by the
  575. // runtime. The driver is expected to walk through the attachment and
  576. // form its internal picture as described below.
  577. // For complex surfaces (mipped textures, cubemaps), we need to record an
  578. // internal representation for the top-level surface that includes all
  579. // sub-surfaces. This is because the handle associated with the top-level
  580. // surface is what's passed to SetTextureStage.
  581. // However, we also need entries in our list that allow us to set any
  582. // of the sublevels as render targets. Thus this top-level routine iterates
  583. // across the entire attachment graph (to accomodate SRT on any subsurface)
  584. // and the lower-level routine (RDSurface2D::Initialize) also iterates across
  585. // the whole graph (to accomodate SetTexture on the top-level).
  586. // A flipping chain is another structure that needs SRT to work on all
  587. // contained surfaces.
  588. //
  589. // Destroy: The destruction unfortunately is not atomic. The driver gets
  590. // the call to destroy per sub-level. The attachment has no meaning
  591. // at this time, so the driver should only delete the level being
  592. // referred to.
  593. //
  594. //----------------------------------------------------------------------------
  595. DWORD __stdcall
  596. RefRastCreateSurfaceEx(LPDDHAL_CREATESURFACEEXDATA p)
  597. {
  598. #if DBG
  599. if( p == NULL )
  600. {
  601. DPFERR("CreateSurfaceExData ptr is NULL");
  602. return DDHAL_DRIVER_HANDLED;
  603. }
  604. if( p->lpDDLcl == NULL || p->lpDDSLcl == NULL )
  605. {
  606. DPFERR("DDLcl or the DDSLcl ptr is NULL");
  607. return DDHAL_DRIVER_HANDLED;
  608. }
  609. #endif
  610. LPDDRAWI_DDRAWSURFACE_LCL lpDDSLcl = p->lpDDSLcl;
  611. p->ddRVal = DD_OK;
  612. //
  613. // Is it a Delete call ? If so simply delete the surface-rep associated
  614. // with this local and dont walk the local chain.
  615. //
  616. if( 0 == SURFACE_MEMORY(lpDDSLcl) )
  617. {
  618. g_SurfMgr.RemoveSurfFromList( p->lpDDLcl, lpDDSLcl );
  619. return DDHAL_DRIVER_HANDLED;
  620. }
  621. ProcessPossibleMipMap(p, lpDDSLcl);
  622. //Now we have two possibilities: cubemap or flipping chain.
  623. // Check cube map first:
  624. //+ve X is always the first face
  625. // (Note a DX7 driver would have to handle cubes w/o the +X face (since DX7
  626. // cubes may have any set of faces missing).)
  627. if (lpDDSLcl->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_CUBEMAP_POSITIVEX)
  628. {
  629. //Go find each attached cubemap face and process it as a mipmap
  630. for (int i=1;i<6;i++)
  631. {
  632. DWORD dwCaps2=0;
  633. switch(i)
  634. {
  635. case 1: dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEX; break;
  636. case 2: dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEY; break;
  637. case 3: dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEY; break;
  638. case 4: dwCaps2 = DDSCAPS2_CUBEMAP_POSITIVEZ; break;
  639. case 5: dwCaps2 = DDSCAPS2_CUBEMAP_NEGATIVEZ; break;
  640. }
  641. //Find the top-level faces attached to the root
  642. //(there will be no mip sublevel of any of these five types
  643. //attached to the root).
  644. lpDDSLcl = FindAttachedSurfaceCaps2(p->lpDDSLcl, dwCaps2);
  645. if (lpDDSLcl) ProcessPossibleMipMap(p, lpDDSLcl);
  646. }
  647. }
  648. else if (
  649. 0==(lpDDSLcl->ddsCaps.dwCaps & DDSCAPS_MIPMAP) &&
  650. 0 != lpDDSLcl->lpAttachList)
  651. {
  652. //just assert that we're not handling some of the other types
  653. //we know are passed to CSEx.
  654. _ASSERT(0==(lpDDSLcl->ddsCaps.dwCaps & DDSCAPS_TEXTURE), "CSEx for an attached texture?");
  655. _ASSERT(0==(lpDDSLcl->ddsCaps.dwCaps & DDSCAPS_EXECUTEBUFFER), "CSEx for an attached execute buffer?");
  656. // We processed mipmaps above, so either there will be no
  657. // more attachments (aside from the mipsublevels), or it's
  658. // a flipping chain.
  659. // The first member of the chain was processed above.
  660. // Npw we look around the ring, terminating when we hit the first surface
  661. // again.
  662. //
  663. // NOTE: DX8 software drivers will only ever see a chain, not a ring.
  664. // This code terminates at the end of the chain.
  665. //
  666. // A real driver may have to check for attached Z surfaces
  667. // here, as well as stereo left surfaces.
  668. lpDDSLcl = lpDDSLcl->lpAttachList->lpAttached;
  669. _ASSERT(lpDDSLcl, "Bad attachment List");
  670. while (lpDDSLcl && lpDDSLcl != p->lpDDSLcl) //i.e. not the first surface again
  671. {
  672. //We just reuse the "ProcessPossibleMipmap" function, and
  673. //assert that it will not have to traverse a mipmap here.
  674. _ASSERT(0==(lpDDSLcl->ddsCaps.dwCaps & DDSCAPS_MIPMAP),
  675. "Flipping chains should not be mipmaps");
  676. ProcessPossibleMipMap(p, lpDDSLcl);
  677. //This is the termination condition we expect for DX8 software
  678. //drivers.
  679. if (0 == lpDDSLcl->lpAttachList)
  680. {
  681. lpDDSLcl = 0;
  682. break;
  683. }
  684. lpDDSLcl = lpDDSLcl->lpAttachList->lpAttached;
  685. _ASSERT(lpDDSLcl, "Bad attachment List");
  686. }
  687. }
  688. // else we drop through and do no further attachment list processing
  689. // (typically on mipmaps or execute buffers).
  690. return DDHAL_DRIVER_HANDLED;
  691. }
  692. extern HRESULT FASTCALL
  693. FindOutSurfFormat(LPDDPIXELFORMAT pDdPixFmt, RDSurfaceFormat* pFmt,
  694. BOOL* pbIsDepth);
  695. //----------------------------------------------------------------------------
  696. //
  697. // RefRastCreateSurface
  698. //
  699. // Create a requested surface. Fake VIDMEM allocation.
  700. //
  701. //----------------------------------------------------------------------------
  702. DWORD __stdcall
  703. RefRastCreateSurface(LPDDHAL_CREATESURFACEDATA pData)
  704. {
  705. LPDDRAWI_DDRAWSURFACE_LCL pSLcl = NULL;
  706. LPDDRAWI_DDRAWSURFACE_GBL pSGbl = NULL;
  707. LPDDRAWI_DDRAWSURFACE_MORE pSMore = NULL;
  708. DWORD dwBytesPerPixel = 0;
  709. DWORD dwBytesInVB = 0;
  710. DWORD dwNumBytes = 0;
  711. DWORD dwPitch = 0;
  712. DWORD dwSlicePitch = 0;
  713. DWORD i = 0, j = 0;
  714. BYTE* pBits = NULL;
  715. BOOL isDXT = FALSE;
  716. UINT MultiSampleCount;
  717. DWORD dwMultiSamplePitch = 0;
  718. BYTE* pMultiSampleBits = NULL;
  719. DWORD dwNumMultiSampleBytes = 0;
  720. HRESULT hr = S_OK;
  721. pData->ddRVal = DD_OK;
  722. //
  723. // Validation
  724. //
  725. // The surface count
  726. if( pData->dwSCnt < 1 )
  727. {
  728. DPFERR("At least one surface should be created");
  729. pData->ddRVal = E_FAIL;
  730. return DDHAL_DRIVER_HANDLED;
  731. }
  732. // Primary surface cannot be handled here
  733. if( pData->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE )
  734. {
  735. DPFERR("Refrast cannot allocate Primary surface");
  736. pData->ddRVal = DDERR_UNSUPPORTED;
  737. return DDHAL_DRIVER_HANDLED;
  738. }
  739. // Only Vidmem or Driver Managed allocations are handled here
  740. if(((pData->lpDDSurfaceDesc->ddsCaps.dwCaps &
  741. (DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM)) == 0)
  742. &&
  743. ((pData->lplpSList[0]->lpSurfMore->ddsCapsEx.dwCaps2 &
  744. DDSCAPS2_TEXTUREMANAGE) == 0))
  745. {
  746. DPFERR("Refrast can only allocate Vidmem or DriverManaged surfaces");
  747. pData->ddRVal = DDERR_UNSUPPORTED;
  748. return DDHAL_DRIVER_HANDLED;
  749. }
  750. // Dont allocate if the width or the height is not provided
  751. if( (pData->lpDDSurfaceDesc->dwFlags & (DDSD_WIDTH | DDSD_HEIGHT )) !=
  752. (DDSD_WIDTH | DDSD_HEIGHT ) )
  753. {
  754. DPFERR("No size provided for the surface");
  755. pData->ddRVal = DDERR_UNSUPPORTED;
  756. return DDHAL_DRIVER_HANDLED;
  757. }
  758. // Currently, allocation takes place only if a pixel format is provided
  759. if( pData->lpDDSurfaceDesc->dwFlags & DDSD_PIXELFORMAT )
  760. {
  761. dwBytesPerPixel =
  762. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwRGBBitCount >> 3);
  763. // For FourCCs, we need to explicitly indicate the bytes per pixel
  764. if ((dwBytesPerPixel == 0) &&
  765. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFlags & DDPF_FOURCC))
  766. {
  767. if( IsYUV( pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ) )
  768. {
  769. dwBytesPerPixel = 2;
  770. }
  771. else if( IsDXTn( pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ) )
  772. {
  773. dwBytesPerPixel = 1;
  774. isDXT = TRUE;
  775. }
  776. // All the new surface formats (introduced after DX7) are marked as
  777. // 4CC. Technically they are not 4CC, that field is overloaded to
  778. // mean the new DX8 style format ID.
  779. else if( (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  780. 0xFF000004) ||
  781. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  782. (DWORD) D3DFMT_Q8W8V8U8) ||
  783. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  784. (DWORD) D3DFMT_V16U16) ||
  785. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  786. (DWORD) D3DFMT_W11V11U10) ||
  787. // Formats introduced in DX8.1
  788. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  789. (DWORD)D3DFMT_A2B10G10R10) ||
  790. #if 0
  791. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  792. (DWORD)D3DFMT_A8B8G8R8) ||
  793. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  794. (DWORD)D3DFMT_X8B8G8R8) ||
  795. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  796. (DWORD)D3DFMT_W10V11U11) ||
  797. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  798. (DWORD)D3DFMT_A8X8V8U8) ||
  799. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  800. (DWORD)D3DFMT_L8X8V8U8) ||
  801. #endif
  802. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  803. (DWORD)D3DFMT_G16R16) ||
  804. (pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC ==
  805. (DWORD)D3DFMT_A2W10V10U10)
  806. )
  807. {
  808. // Private new format
  809. dwBytesPerPixel = 4;
  810. }
  811. }
  812. }
  813. else if( pData->lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_EXECUTEBUFFER )
  814. {
  815. dwBytesInVB = ((LPDDSURFACEDESC2)(pData->lpDDSurfaceDesc))->dwWidth;
  816. }
  817. else
  818. {
  819. // Note: for DX8 drivers, this case should never be encountered.
  820. // In the future, if RefDev is revamped to work with legacy interfaces
  821. // then this case needs to something real instead of failing:
  822. // If the pixel-formats are not provided, then the current primary
  823. // format should be assumed.
  824. DPFERR( "Refrast can only allocate if PixelFormat is provided" );
  825. pData->ddRVal = DDERR_UNSUPPORTED;
  826. return DDHAL_DRIVER_HANDLED;
  827. }
  828. //
  829. // Allocate the memory and compute the Pitch for every surface on the
  830. // list.
  831. //
  832. // We should be guaranteed that this is the same for all surfaces in the
  833. // list
  834. MultiSampleCount = 0xf & (pData->lplpSList[0]->lpSurfMore->ddsCapsEx.dwCaps3);
  835. //This will be the case on older than DX8 runtimes
  836. if (MultiSampleCount == 0)
  837. {
  838. MultiSampleCount = 1;
  839. }
  840. for( i = 0; i < pData->dwSCnt; i++ )
  841. {
  842. RDCREATESURFPRIVATE* pPriv = NULL;
  843. pSLcl = pData->lplpSList[i];
  844. pSGbl = pSLcl->lpGbl;
  845. pSMore = pSLcl->lpSurfMore;
  846. DWORD dwHeight = pSGbl->wHeight;
  847. // If already allocated, just return
  848. if( pSGbl->fpVidMem || pSGbl->dwReserved1 )
  849. {
  850. DPFERR("Surface has already been allocated");
  851. pData->ddRVal = E_FAIL;
  852. break;
  853. }
  854. // Figure out if it is a vertex buffer
  855. if( dwBytesInVB )
  856. {
  857. dwNumBytes = dwBytesInVB;
  858. dwPitch = dwBytesInVB;
  859. }
  860. else
  861. {
  862. // Figure out the pitch and allocate
  863. switch( pData->lpDDSurfaceDesc->ddpfPixelFormat.dwFourCC )
  864. {
  865. case MAKEFOURCC('D', 'X', 'T', '1'):
  866. dwMultiSamplePitch = (MultiSampleCount *
  867. ((pSGbl->wWidth+3)>>2) *
  868. g_DXTBlkSize[0] + 7) & ~7;
  869. dwPitch = (((pSGbl->wWidth+3)>>2) * g_DXTBlkSize[0] + 7) & ~7;
  870. dwHeight = ((pSGbl->wHeight+3)>>2);
  871. break;
  872. case MAKEFOURCC('D', 'X', 'T', '2'):
  873. dwMultiSamplePitch = (MultiSampleCount *
  874. ((pSGbl->wWidth+3)>>2) *
  875. g_DXTBlkSize[1] + 7) & ~7;
  876. dwPitch = (((pSGbl->wWidth+3)>>2) * g_DXTBlkSize[1] + 7) & ~7;
  877. dwHeight = ((pSGbl->wHeight+3)>>2);
  878. break;
  879. case MAKEFOURCC('D', 'X', 'T', '3'):
  880. dwMultiSamplePitch = (MultiSampleCount *
  881. ((pSGbl->wWidth+3)>>2) *
  882. g_DXTBlkSize[2] + 7) & ~7;
  883. dwPitch = (((pSGbl->wWidth+3)>>2) *
  884. g_DXTBlkSize[2] + 7) & ~7;
  885. dwHeight = ((pSGbl->wHeight+3)>>2);
  886. break;
  887. case MAKEFOURCC('D', 'X', 'T', '4'):
  888. dwMultiSamplePitch = (MultiSampleCount *
  889. ((pSGbl->wWidth+3)>>2) *
  890. g_DXTBlkSize[3] + 7) & ~7;
  891. dwPitch = (((pSGbl->wWidth+3)>>2) *
  892. g_DXTBlkSize[3] + 7) & ~7;
  893. dwHeight = ((pSGbl->wHeight+3)>>2);
  894. break;
  895. case MAKEFOURCC('D', 'X', 'T', '5'):
  896. dwMultiSamplePitch = (MultiSampleCount *
  897. ((pSGbl->wWidth+3)>>2) *
  898. g_DXTBlkSize[4] + 7) & ~7;
  899. dwPitch = (((pSGbl->wWidth+3)>>2) *
  900. g_DXTBlkSize[4] + 7) & ~7;
  901. dwHeight = ((pSGbl->wHeight+3)>>2);
  902. break;
  903. default:
  904. dwMultiSamplePitch = (MultiSampleCount
  905. * dwBytesPerPixel *
  906. pSGbl->wWidth + 7) & ~7;
  907. dwPitch = (dwBytesPerPixel *
  908. pSGbl->wWidth + 7) & ~7;
  909. break;
  910. }
  911. if (!(pSMore->ddsCapsEx.dwCaps2 & DDSCAPS2_VOLUME))
  912. {
  913. dwNumBytes = dwPitch * dwHeight;
  914. if( MultiSampleCount > 1 )
  915. dwNumMultiSampleBytes = dwMultiSamplePitch *
  916. pSGbl->wHeight;
  917. }
  918. else
  919. {
  920. _ASSERT( dwMultiSamplePitch == dwPitch,
  921. "Cant have multisample for volume textures\n" );
  922. dwSlicePitch = dwPitch * dwHeight;
  923. // low word of ddsCaps.ddsCapsEx.dwCaps4 has depth
  924. // (volume texture only).
  925. dwNumBytes = dwSlicePitch *
  926. LOWORD(pSMore->ddsCapsEx.dwCaps4);
  927. }
  928. }
  929. pPriv = new RDCREATESURFPRIVATE;
  930. if( pPriv == NULL )
  931. {
  932. DPFERR("Allocation failed");
  933. pData->ddRVal = DDERR_OUTOFMEMORY;
  934. break;
  935. }
  936. pPriv->pBits = new BYTE[dwNumBytes];
  937. if( pPriv->pBits == NULL)
  938. {
  939. DPFERR("Allocation failed");
  940. delete pPriv;
  941. pData->ddRVal = DDERR_OUTOFMEMORY;
  942. break;
  943. }
  944. pPriv->dwPitch = dwPitch;
  945. // Allocate the private MultiSample buffer
  946. if( dwNumMultiSampleBytes )
  947. {
  948. pPriv->pMultiSampleBits = new BYTE[dwNumMultiSampleBytes];
  949. if( pPriv->pMultiSampleBits == NULL)
  950. {
  951. DPFERR("Multisample allocation failed");
  952. delete pPriv;
  953. pData->ddRVal = DDERR_OUTOFMEMORY;
  954. break;
  955. }
  956. pPriv->dwMultiSamplePitch = dwMultiSamplePitch;
  957. pPriv->wSamples = (WORD)MultiSampleCount;
  958. HR_RET(FindOutSurfFormat(&(DDSurf_PixFmt(pSLcl)),
  959. &pPriv->SurfaceFormat, NULL));
  960. }
  961. // Save the stuff on the surface
  962. pSGbl->fpVidMem = (FLATPTR)pPriv->pBits;
  963. if ( isDXT )
  964. {
  965. pSGbl->lPitch = dwNumBytes;
  966. if (pSMore->ddsCapsEx.dwCaps2 & DDSCAPS2_VOLUME)
  967. {
  968. // set slice pitch (volume texture only).
  969. pSGbl->lSlicePitch = dwSlicePitch;
  970. }
  971. }
  972. else
  973. {
  974. pSGbl->lPitch = pPriv->dwPitch;
  975. if (pSMore->ddsCapsEx.dwCaps2 & DDSCAPS2_VOLUME)
  976. {
  977. // set slice pitch (volume texture only).
  978. pSGbl->lSlicePitch = dwSlicePitch;
  979. }
  980. }
  981. pSGbl->dwReserved1 = (ULONG_PTR)pPriv;
  982. }
  983. // The loop completed successfully
  984. if( i == pData->dwSCnt )
  985. return DDHAL_DRIVER_HANDLED;
  986. // Else the loop terminated abnormally,
  987. // Free up allocated memory and quit with the error
  988. for( j = 0; j < i; j++ )
  989. {
  990. pData->lplpSList[j]->lpGbl->lPitch = 0;
  991. if (pSMore->ddsCapsEx.dwCaps2 & DDSCAPS2_VOLUME)
  992. {
  993. pData->lplpSList[j]->lpGbl->lSlicePitch = 0;
  994. }
  995. delete (RDCREATESURFPRIVATE *)pData->lplpSList[j]->lpGbl->dwReserved1;
  996. pData->lplpSList[j]->lpGbl->dwReserved1 = 0;
  997. }
  998. return DDHAL_DRIVER_HANDLED;
  999. }
  1000. //----------------------------------------------------------------------------
  1001. //
  1002. // RefRastDestroySurface
  1003. //
  1004. // Destroy a requested surface.
  1005. //
  1006. //----------------------------------------------------------------------------
  1007. DWORD __stdcall
  1008. RefRastDestroySurface(LPDDHAL_DESTROYSURFACEDATA pData)
  1009. {
  1010. pData->ddRVal = DD_OK;
  1011. //
  1012. // Validation
  1013. //
  1014. if( pData->lpDDSurface->lpGbl->dwReserved1 == NULL )
  1015. {
  1016. DPFERR("This surface was not created by refrast");
  1017. pData->ddRVal = E_FAIL;
  1018. return DDHAL_DRIVER_HANDLED;
  1019. }
  1020. delete (RDCREATESURFPRIVATE *)pData->lpDDSurface->lpGbl->dwReserved1;
  1021. pData->lpDDSurface->lpGbl->dwReserved1 = 0;
  1022. // For vid-mem surfaces, runtime calls this DDI once per entire mip-chain
  1023. // so this needs to be removed.
  1024. // Now free the handle if it has been allocated for this surface
  1025. pData->ddRVal = g_SurfMgr.RemoveSurfFromList(
  1026. pData->lpDDSurface->lpSurfMore->lpDD_lcl,
  1027. pData->lpDDSurface );
  1028. return DDHAL_DRIVER_HANDLED;
  1029. }
  1030. //----------------------------------------------------------------------------
  1031. //
  1032. // RefRastLock
  1033. //
  1034. // Locks the given surface.
  1035. //
  1036. //----------------------------------------------------------------------------
  1037. DWORD __stdcall
  1038. RefRastLock(LPDDHAL_LOCKDATA pData)
  1039. {
  1040. DWORD dwBytesPerPixel = 0;
  1041. LPDDRAWI_DDRAWSURFACE_LCL pSLcl = pData->lpDDSurface;
  1042. LPDDRAWI_DDRAWSURFACE_GBL pSGbl = pSLcl->lpGbl;
  1043. pData->ddRVal = DD_OK;
  1044. //
  1045. // Validation
  1046. //
  1047. if( pSGbl->dwReserved1 == NULL )
  1048. {
  1049. DPFERR("This surface was not created by refrast");
  1050. pData->ddRVal = E_FAIL;
  1051. return DDHAL_DRIVER_HANDLED;
  1052. }
  1053. //
  1054. // Obtain the private data
  1055. //
  1056. RDCREATESURFPRIVATE* pPriv =
  1057. (RDCREATESURFPRIVATE *)pSGbl->dwReserved1;
  1058. if (g_RefDDI > RDDDI_DX7HAL)
  1059. {
  1060. // Figure out the device it is being used with.
  1061. // If this is a Multisampled Rendertarget, need to filter down for
  1062. // the runtime.
  1063. if( pPriv->pMultiSampleBits )
  1064. {
  1065. BYTE* pBits = pPriv->pBits;
  1066. DWORD dwPitch = pPriv->dwPitch;
  1067. BYTE* pMSBits = pPriv->pMultiSampleBits;
  1068. DWORD dwMSPitch = pPriv->dwMultiSamplePitch;
  1069. RDSurfaceFormat sf = pPriv->SurfaceFormat;
  1070. FLOAT fSampleScale = 1.F/((FLOAT)pPriv->wSamples);
  1071. int width = (int)DDSurf_Width(pSLcl);
  1072. int height = (int)DDSurf_Height(pSLcl);
  1073. for (int iY = 0; iY < height; iY++)
  1074. {
  1075. for (int iX = 0; iX < width; iX++)
  1076. {
  1077. RDColor Color((UINT32)0);
  1078. for (UINT iS=0; iS<pPriv->wSamples; iS++)
  1079. {
  1080. RDColor SampleColor;
  1081. SampleColor.ConvertFrom(
  1082. sf, PixelAddress( iX, iY, 0, iS,
  1083. pMSBits,
  1084. dwMSPitch,
  1085. 0,
  1086. pPriv->wSamples,
  1087. sf ) );
  1088. Color.R += (SampleColor.R * fSampleScale);
  1089. Color.G += (SampleColor.G * fSampleScale);
  1090. Color.B += (SampleColor.B * fSampleScale);
  1091. Color.A += (SampleColor.A * fSampleScale);
  1092. }
  1093. Color.ConvertTo( sf, 0., PixelAddress( iX, iY, 0, pBits,
  1094. dwPitch, 0, sf ) );
  1095. }
  1096. }
  1097. }
  1098. }
  1099. if( pData->bHasRect )
  1100. {
  1101. // If it is either a 1) VB, 2) IB or 3) CB then the
  1102. // rect has a special meaning. rect.top - rect.bottom
  1103. // gives the range of memory desired.
  1104. // Note: it rect.bottom is the higher address and it is exclusive.
  1105. if( pSLcl->ddsCaps.dwCaps & DDSCAPS_EXECUTEBUFFER )
  1106. {
  1107. pData->lpSurfData = (LPVOID)(pPriv->pBits + pData->rArea.top);
  1108. }
  1109. else if( pSLcl->lpSurfMore->ddsCapsEx.dwCaps2 & DDSCAPS2_VOLUME )
  1110. {
  1111. // If it is a volume texture, then the front and back are
  1112. // or'd into the high word of rect->left and rect->right
  1113. // respectively.
  1114. DWORD front = (pData->rArea.left >> 16);
  1115. DWORD left = pData->rArea.left & 0x0000ffff;
  1116. DWORD top = pData->rArea.top;
  1117. DWORD slicePitch = pSGbl->lSlicePitch;
  1118. if( IsDXTn( pSGbl->ddpfSurface.dwFourCC ) )
  1119. {
  1120. _ASSERT( FALSE, "Should not be reached without driver "
  1121. "managed support" );
  1122. }
  1123. else
  1124. {
  1125. dwBytesPerPixel = pSGbl->ddpfSurface.dwRGBBitCount >> 3;
  1126. pData->lpSurfData = (LPVOID)(pPriv->pBits +
  1127. front * slicePitch +
  1128. top * pPriv->dwPitch +
  1129. left * dwBytesPerPixel);
  1130. }
  1131. }
  1132. else
  1133. {
  1134. if( IsDXTn( pSGbl->ddpfSurface.dwFourCC ) )
  1135. {
  1136. _ASSERT( FALSE, "Should not be reached without driver "
  1137. "managed support" );
  1138. }
  1139. else
  1140. {
  1141. dwBytesPerPixel = pSGbl->ddpfSurface.dwRGBBitCount >> 3;
  1142. pData->lpSurfData = (LPVOID)(pPriv->pBits +
  1143. pData->rArea.top*pPriv->dwPitch +
  1144. pData->rArea.left*dwBytesPerPixel);
  1145. }
  1146. }
  1147. }
  1148. else
  1149. {
  1150. pData->lpSurfData = (LPVOID)pPriv->pBits;
  1151. }
  1152. pPriv->Lock();
  1153. return DDHAL_DRIVER_HANDLED;
  1154. }
  1155. //----------------------------------------------------------------------------
  1156. //
  1157. // RefRastUnlock
  1158. //
  1159. // Unlocks the given surface.
  1160. //
  1161. //----------------------------------------------------------------------------
  1162. DWORD __stdcall
  1163. RefRastUnlock(LPDDHAL_UNLOCKDATA pData)
  1164. {
  1165. pData->ddRVal = DD_OK;
  1166. //
  1167. // Validation
  1168. //
  1169. if( pData->lpDDSurface->lpGbl->dwReserved1 == NULL )
  1170. {
  1171. DPFERR("This surface was not created by refrast");
  1172. pData->ddRVal = E_FAIL;
  1173. return DDHAL_DRIVER_HANDLED;
  1174. }
  1175. //
  1176. // Obtain the private data
  1177. //
  1178. RDCREATESURFPRIVATE* pPriv =
  1179. (RDCREATESURFPRIVATE *)pData->lpDDSurface->lpGbl->dwReserved1;
  1180. pPriv->Unlock();
  1181. return DDHAL_DRIVER_HANDLED;
  1182. }
  1183. //////////////////////////////////////////////////////////////////////////////
  1184. //
  1185. // Software DDI interface implementation
  1186. //
  1187. //////////////////////////////////////////////////////////////////////////////
  1188. //
  1189. // DX8 DDI caps
  1190. //
  1191. #define RESPATH_D3DREF RESPATH_D3D "\\ReferenceDevice"
  1192. static void
  1193. ModifyDeviceCaps8( void )
  1194. {
  1195. HKEY hKey = (HKEY) NULL;
  1196. if( ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, RESPATH_D3DREF, &hKey) )
  1197. {
  1198. DWORD dwType;
  1199. DWORD dwValue;
  1200. char dwString[128];
  1201. DWORD dwSize;
  1202. dwSize = sizeof(dwValue);
  1203. if ( (ERROR_SUCCESS == RegQueryValueEx( hKey, "PixelShaderVersion", NULL,
  1204. &dwType, (LPBYTE)&dwValue, &dwSize )) &&
  1205. (dwType == REG_DWORD) )
  1206. {
  1207. g_RefCaps8.PixelShaderVersion = dwValue;
  1208. }
  1209. dwSize = sizeof(dwString);
  1210. if ( (ERROR_SUCCESS == RegQueryValueEx( hKey, "MaxPixelShaderValue", NULL,
  1211. &dwType, (LPBYTE)dwString, &dwSize )) &&
  1212. (dwType == REG_SZ) )
  1213. {
  1214. sscanf( dwString, "%f", &g_RefCaps8.MaxPixelShaderValue );
  1215. }
  1216. RegCloseKey(hKey);
  1217. }
  1218. }
  1219. static void
  1220. FillOutDeviceCaps8( RDDDITYPE ddi )
  1221. {
  1222. g_RefCaps8.DevCaps=
  1223. D3DDEVCAPS_EXECUTESYSTEMMEMORY |
  1224. D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
  1225. D3DDEVCAPS_TEXTURESYSTEMMEMORY |
  1226. D3DDEVCAPS_DRAWPRIMTLVERTEX |
  1227. D3DDEVCAPS_PUREDEVICE |
  1228. D3DDEVCAPS_DRAWPRIMITIVES2EX |
  1229. D3DDEVCAPS_HWVERTEXBUFFER |
  1230. D3DDEVCAPS_HWINDEXBUFFER |
  1231. 0;
  1232. g_RefCaps8.PrimitiveMiscCaps =
  1233. D3DPMISCCAPS_MASKZ |
  1234. D3DPMISCCAPS_LINEPATTERNREP |
  1235. D3DPMISCCAPS_CULLNONE |
  1236. D3DPMISCCAPS_CULLCW |
  1237. D3DPMISCCAPS_CULLCCW |
  1238. D3DPMISCCAPS_COLORWRITEENABLE |
  1239. D3DPMISCCAPS_CLIPTLVERTS |
  1240. D3DPMISCCAPS_TSSARGTEMP |
  1241. D3DPMISCCAPS_FOGINFVF |
  1242. D3DPMISCCAPS_BLENDOP ;
  1243. #ifdef __D3D_NULL_REF
  1244. g_RefCaps8.PrimitiveMiscCaps |= D3DPMISCCAPS_NULLREFERENCE;
  1245. #endif //__D3D_NULL_REF
  1246. g_RefCaps8.RasterCaps =
  1247. D3DPRASTERCAPS_DITHER |
  1248. D3DPRASTERCAPS_ZTEST |
  1249. D3DPRASTERCAPS_FOGVERTEX |
  1250. D3DPRASTERCAPS_FOGTABLE |
  1251. D3DPRASTERCAPS_MIPMAPLODBIAS |
  1252. D3DPRASTERCAPS_PAT |
  1253. // D3DPRASTERCAPS_ZBIAS |
  1254. D3DPRASTERCAPS_FOGRANGE |
  1255. D3DPRASTERCAPS_ANISOTROPY |
  1256. D3DPRASTERCAPS_WBUFFER |
  1257. D3DPRASTERCAPS_WFOG |
  1258. D3DPRASTERCAPS_ZFOG |
  1259. D3DPRASTERCAPS_COLORPERSPECTIVE ;
  1260. g_RefCaps8.ZCmpCaps =
  1261. D3DPCMPCAPS_NEVER |
  1262. D3DPCMPCAPS_LESS |
  1263. D3DPCMPCAPS_EQUAL |
  1264. D3DPCMPCAPS_LESSEQUAL |
  1265. D3DPCMPCAPS_GREATER |
  1266. D3DPCMPCAPS_NOTEQUAL |
  1267. D3DPCMPCAPS_GREATEREQUAL |
  1268. D3DPCMPCAPS_ALWAYS ;
  1269. g_RefCaps8.SrcBlendCaps =
  1270. D3DPBLENDCAPS_ZERO |
  1271. D3DPBLENDCAPS_ONE |
  1272. D3DPBLENDCAPS_SRCCOLOR |
  1273. D3DPBLENDCAPS_INVSRCCOLOR |
  1274. D3DPBLENDCAPS_SRCALPHA |
  1275. D3DPBLENDCAPS_INVSRCALPHA |
  1276. D3DPBLENDCAPS_DESTALPHA |
  1277. D3DPBLENDCAPS_INVDESTALPHA |
  1278. D3DPBLENDCAPS_DESTCOLOR |
  1279. D3DPBLENDCAPS_INVDESTCOLOR |
  1280. D3DPBLENDCAPS_SRCALPHASAT |
  1281. D3DPBLENDCAPS_BOTHSRCALPHA |
  1282. D3DPBLENDCAPS_BOTHINVSRCALPHA ;
  1283. g_RefCaps8.DestBlendCaps =
  1284. D3DPBLENDCAPS_ZERO |
  1285. D3DPBLENDCAPS_ONE |
  1286. D3DPBLENDCAPS_SRCCOLOR |
  1287. D3DPBLENDCAPS_INVSRCCOLOR |
  1288. D3DPBLENDCAPS_SRCALPHA |
  1289. D3DPBLENDCAPS_INVSRCALPHA |
  1290. D3DPBLENDCAPS_DESTALPHA |
  1291. D3DPBLENDCAPS_INVDESTALPHA |
  1292. D3DPBLENDCAPS_DESTCOLOR |
  1293. D3DPBLENDCAPS_INVDESTCOLOR |
  1294. D3DPBLENDCAPS_SRCALPHASAT ;
  1295. g_RefCaps8.AlphaCmpCaps =
  1296. D3DPCMPCAPS_NEVER |
  1297. D3DPCMPCAPS_LESS |
  1298. D3DPCMPCAPS_EQUAL |
  1299. D3DPCMPCAPS_LESSEQUAL |
  1300. D3DPCMPCAPS_GREATER |
  1301. D3DPCMPCAPS_NOTEQUAL |
  1302. D3DPCMPCAPS_GREATEREQUAL |
  1303. D3DPCMPCAPS_ALWAYS ;
  1304. g_RefCaps8.ShadeCaps =
  1305. D3DPSHADECAPS_COLORGOURAUDRGB |
  1306. D3DPSHADECAPS_SPECULARGOURAUDRGB |
  1307. D3DPSHADECAPS_ALPHAGOURAUDBLEND |
  1308. D3DPSHADECAPS_FOGGOURAUD ;
  1309. g_RefCaps8.TextureCaps =
  1310. D3DPTEXTURECAPS_PERSPECTIVE |
  1311. // D3DPTEXTURECAPS_POW2 |
  1312. D3DPTEXTURECAPS_ALPHA |
  1313. D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
  1314. D3DPTEXTURECAPS_ALPHAPALETTE |
  1315. D3DPTEXTURECAPS_PROJECTED |
  1316. D3DPTEXTURECAPS_CUBEMAP |
  1317. D3DPTEXTURECAPS_VOLUMEMAP |
  1318. D3DPTEXTURECAPS_MIPMAP |
  1319. D3DPTEXTURECAPS_MIPVOLUMEMAP |
  1320. D3DPTEXTURECAPS_MIPCUBEMAP |
  1321. D3DPTEXTURECAPS_CUBEMAP_POW2 |
  1322. D3DPTEXTURECAPS_VOLUMEMAP_POW2 ;
  1323. g_RefCaps8.TextureFilterCaps =
  1324. D3DPTFILTERCAPS_MINFPOINT |
  1325. D3DPTFILTERCAPS_MINFLINEAR |
  1326. D3DPTFILTERCAPS_MINFANISOTROPIC |
  1327. D3DPTFILTERCAPS_MIPFPOINT |
  1328. D3DPTFILTERCAPS_MIPFLINEAR |
  1329. D3DPTFILTERCAPS_MAGFPOINT |
  1330. D3DPTFILTERCAPS_MAGFLINEAR |
  1331. D3DPTFILTERCAPS_MAGFANISOTROPIC ;
  1332. g_RefCaps8.CubeTextureFilterCaps =
  1333. D3DPTFILTERCAPS_MINFPOINT |
  1334. D3DPTFILTERCAPS_MINFLINEAR |
  1335. D3DPTFILTERCAPS_MIPFPOINT |
  1336. D3DPTFILTERCAPS_MIPFLINEAR |
  1337. D3DPTFILTERCAPS_MAGFPOINT |
  1338. D3DPTFILTERCAPS_MAGFLINEAR ;
  1339. g_RefCaps8.VolumeTextureFilterCaps =
  1340. D3DPTFILTERCAPS_MINFPOINT |
  1341. D3DPTFILTERCAPS_MINFLINEAR |
  1342. D3DPTFILTERCAPS_MIPFPOINT |
  1343. D3DPTFILTERCAPS_MIPFLINEAR |
  1344. D3DPTFILTERCAPS_MAGFPOINT |
  1345. D3DPTFILTERCAPS_MAGFLINEAR ;
  1346. g_RefCaps8.TextureAddressCaps =
  1347. D3DPTADDRESSCAPS_WRAP |
  1348. D3DPTADDRESSCAPS_MIRROR |
  1349. D3DPTADDRESSCAPS_CLAMP |
  1350. D3DPTADDRESSCAPS_BORDER |
  1351. D3DPTADDRESSCAPS_INDEPENDENTUV |
  1352. D3DPTADDRESSCAPS_MIRRORONCE ;
  1353. g_RefCaps8.VolumeTextureAddressCaps =
  1354. D3DPTADDRESSCAPS_WRAP |
  1355. D3DPTADDRESSCAPS_MIRROR |
  1356. D3DPTADDRESSCAPS_CLAMP |
  1357. D3DPTADDRESSCAPS_BORDER |
  1358. D3DPTADDRESSCAPS_INDEPENDENTUV |
  1359. D3DPTADDRESSCAPS_MIRRORONCE ;
  1360. g_RefCaps8.LineCaps =
  1361. D3DLINECAPS_TEXTURE |
  1362. D3DLINECAPS_ZTEST |
  1363. D3DLINECAPS_BLEND |
  1364. D3DLINECAPS_ALPHACMP |
  1365. D3DLINECAPS_FOG ;
  1366. g_RefCaps8.MaxTextureWidth = 4096;
  1367. g_RefCaps8.MaxTextureHeight = 4096;
  1368. g_RefCaps8.MaxVolumeExtent = 4096;
  1369. g_RefCaps8.MaxTextureRepeat = 32768;
  1370. g_RefCaps8.MaxTextureAspectRatio = 0;
  1371. g_RefCaps8.MaxAnisotropy = 16;
  1372. g_RefCaps8.MaxVertexW = 1.0e10;
  1373. g_RefCaps8.GuardBandLeft = -32768.f;
  1374. g_RefCaps8.GuardBandTop = -32768.f;
  1375. g_RefCaps8.GuardBandRight = 32767.f;
  1376. g_RefCaps8.GuardBandBottom = 32767.f;
  1377. g_RefCaps8.ExtentsAdjust = 0.;
  1378. g_RefCaps8.StencilCaps =
  1379. D3DSTENCILCAPS_KEEP |
  1380. D3DSTENCILCAPS_ZERO |
  1381. D3DSTENCILCAPS_REPLACE|
  1382. D3DSTENCILCAPS_INCRSAT|
  1383. D3DSTENCILCAPS_DECRSAT|
  1384. D3DSTENCILCAPS_INVERT |
  1385. D3DSTENCILCAPS_INCR |
  1386. D3DSTENCILCAPS_DECR;
  1387. g_RefCaps8.FVFCaps = 8 | D3DFVFCAPS_PSIZE;
  1388. g_RefCaps8.TextureOpCaps =
  1389. D3DTEXOPCAPS_DISABLE |
  1390. D3DTEXOPCAPS_SELECTARG1 |
  1391. D3DTEXOPCAPS_SELECTARG2 |
  1392. D3DTEXOPCAPS_MODULATE |
  1393. D3DTEXOPCAPS_MODULATE2X |
  1394. D3DTEXOPCAPS_MODULATE4X |
  1395. D3DTEXOPCAPS_ADD |
  1396. D3DTEXOPCAPS_ADDSIGNED |
  1397. D3DTEXOPCAPS_ADDSIGNED2X |
  1398. D3DTEXOPCAPS_SUBTRACT |
  1399. D3DTEXOPCAPS_ADDSMOOTH |
  1400. D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
  1401. D3DTEXOPCAPS_BLENDTEXTUREALPHA |
  1402. D3DTEXOPCAPS_BLENDFACTORALPHA |
  1403. D3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
  1404. D3DTEXOPCAPS_BLENDCURRENTALPHA |
  1405. D3DTEXOPCAPS_PREMODULATE |
  1406. D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
  1407. D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
  1408. D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
  1409. D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
  1410. D3DTEXOPCAPS_BUMPENVMAP |
  1411. D3DTEXOPCAPS_BUMPENVMAPLUMINANCE |
  1412. D3DTEXOPCAPS_DOTPRODUCT3 |
  1413. D3DTEXOPCAPS_MULTIPLYADD |
  1414. D3DTEXOPCAPS_LERP ;
  1415. g_RefCaps8.MaxTextureBlendStages = 8;
  1416. g_RefCaps8.MaxSimultaneousTextures = 8;
  1417. g_RefCaps8.VertexProcessingCaps = 0;
  1418. g_RefCaps8.MaxActiveLights = 0;
  1419. g_RefCaps8.MaxUserClipPlanes = 0;
  1420. g_RefCaps8.MaxVertexBlendMatrices = 0;
  1421. g_RefCaps8.MaxVertexBlendMatrixIndex = 0;
  1422. g_RefCaps8.MaxPointSize = RD_MAX_POINT_SIZE;
  1423. g_RefCaps8.MaxPrimitiveCount = 0x001fffff;
  1424. g_RefCaps8.MaxVertexIndex = 0x00ffffff;
  1425. g_RefCaps8.MaxStreams = 1;
  1426. g_RefCaps8.MaxStreamStride = 256;
  1427. g_RefCaps8.VertexShaderVersion = D3DVS_VERSION(0,0);
  1428. g_RefCaps8.MaxVertexShaderConst = 0;
  1429. g_RefCaps8.PixelShaderVersion = D3DPS_VERSION(1,4);
  1430. g_RefCaps8.MaxPixelShaderValue = FLT_MAX;
  1431. // Non 3D Caps
  1432. g_RefCaps8.Caps = 0;
  1433. g_RefCaps8.Caps2 = DDCAPS2_CANMANAGERESOURCE | DDCAPS2_CANRENDERWINDOWED | DDCAPS2_DYNAMICTEXTURES;
  1434. switch( ddi )
  1435. {
  1436. case RDDDI_DX8TLHAL:
  1437. g_RefCaps8.DevCaps |=
  1438. D3DDEVCAPS_HWTRANSFORMANDLIGHT |
  1439. D3DDEVCAPS_RTPATCHES |
  1440. D3DDEVCAPS_RTPATCHHANDLEZERO |
  1441. D3DDEVCAPS_NPATCHES |
  1442. D3DDEVCAPS_QUINTICRTPATCHES |
  1443. 0;
  1444. g_RefCaps8.VertexProcessingCaps =
  1445. D3DVTXPCAPS_TEXGEN |
  1446. D3DVTXPCAPS_MATERIALSOURCE7 |
  1447. D3DVTXPCAPS_DIRECTIONALLIGHTS |
  1448. D3DVTXPCAPS_POSITIONALLIGHTS |
  1449. D3DVTXPCAPS_TWEENING |
  1450. D3DVTXPCAPS_LOCALVIEWER ;
  1451. g_RefCaps8.MaxActiveLights = 0xffffffff;
  1452. g_RefCaps8.MaxUserClipPlanes = RD_MAX_USER_CLIPPLANES;
  1453. g_RefCaps8.MaxVertexBlendMatrices = RD_MAX_BLEND_WEIGHTS;
  1454. g_RefCaps8.MaxVertexBlendMatrixIndex = RD_MAX_WORLD_MATRICES - 1;
  1455. g_RefCaps8.MaxStreams = RD_MAX_NUMSTREAMS;
  1456. g_RefCaps8.VertexShaderVersion = D3DVS_VERSION(1,1);
  1457. g_RefCaps8.MaxVertexShaderConst = RD_MAX_NUMCONSTREG;
  1458. break;
  1459. }
  1460. }
  1461. //
  1462. // pre-DX8 DDI caps
  1463. //
  1464. static D3DHAL_GLOBALDRIVERDATA RefGDD = { 0 };
  1465. static D3DHAL_D3DEXTENDEDCAPS RefExtCaps = { 0 };
  1466. static void
  1467. FillOutDeviceCaps( BOOL bIsNullDevice, RDDDITYPE ddi )
  1468. {
  1469. //
  1470. // set device description
  1471. //
  1472. RefGDD.dwSize = sizeof(RefGDD);
  1473. RefGDD.hwCaps.dwDevCaps =
  1474. D3DDEVCAPS_FLOATTLVERTEX |
  1475. D3DDEVCAPS_EXECUTESYSTEMMEMORY |
  1476. D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
  1477. D3DDEVCAPS_TEXTURESYSTEMMEMORY |
  1478. D3DDEVCAPS_DRAWPRIMTLVERTEX;
  1479. RefGDD.dwNumVertices = (RD_MAX_VERTEX_COUNT - RD_MAX_CLIP_VERTICES);
  1480. RefGDD.dwNumClipVertices = RD_MAX_CLIP_VERTICES;
  1481. RefGDD.hwCaps.dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
  1482. RefGDD.hwCaps.dpcTriCaps.dwMiscCaps =
  1483. D3DPMISCCAPS_MASKZ |
  1484. D3DPMISCCAPS_CULLNONE |
  1485. D3DPMISCCAPS_CULLCW |
  1486. D3DPMISCCAPS_CULLCCW ;
  1487. RefGDD.hwCaps.dpcTriCaps.dwRasterCaps =
  1488. D3DPRASTERCAPS_DITHER |
  1489. // D3DPRASTERCAPS_ROP2 |
  1490. // D3DPRASTERCAPS_XOR |
  1491. // D3DPRASTERCAPS_PAT |
  1492. D3DPRASTERCAPS_ZTEST |
  1493. D3DPRASTERCAPS_SUBPIXEL |
  1494. D3DPRASTERCAPS_SUBPIXELX |
  1495. D3DPRASTERCAPS_FOGVERTEX |
  1496. D3DPRASTERCAPS_FOGTABLE |
  1497. // D3DPRASTERCAPS_STIPPLE |
  1498. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  1499. D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  1500. // D3DPRASTERCAPS_ANTIALIASEDGES |
  1501. D3DPRASTERCAPS_MIPMAPLODBIAS |
  1502. // D3DPRASTERCAPS_ZBIAS |
  1503. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  1504. D3DPRASTERCAPS_FOGRANGE |
  1505. D3DPRASTERCAPS_ANISOTROPY |
  1506. D3DPRASTERCAPS_WBUFFER |
  1507. D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT |
  1508. D3DPRASTERCAPS_WFOG |
  1509. D3DPRASTERCAPS_ZFOG;
  1510. RefGDD.hwCaps.dpcTriCaps.dwZCmpCaps =
  1511. D3DPCMPCAPS_NEVER |
  1512. D3DPCMPCAPS_LESS |
  1513. D3DPCMPCAPS_EQUAL |
  1514. D3DPCMPCAPS_LESSEQUAL |
  1515. D3DPCMPCAPS_GREATER |
  1516. D3DPCMPCAPS_NOTEQUAL |
  1517. D3DPCMPCAPS_GREATEREQUAL |
  1518. D3DPCMPCAPS_ALWAYS ;
  1519. RefGDD.hwCaps.dpcTriCaps.dwSrcBlendCaps =
  1520. D3DPBLENDCAPS_ZERO |
  1521. D3DPBLENDCAPS_ONE |
  1522. D3DPBLENDCAPS_SRCCOLOR |
  1523. D3DPBLENDCAPS_INVSRCCOLOR |
  1524. D3DPBLENDCAPS_SRCALPHA |
  1525. D3DPBLENDCAPS_INVSRCALPHA |
  1526. D3DPBLENDCAPS_DESTALPHA |
  1527. D3DPBLENDCAPS_INVDESTALPHA |
  1528. D3DPBLENDCAPS_DESTCOLOR |
  1529. D3DPBLENDCAPS_INVDESTCOLOR |
  1530. D3DPBLENDCAPS_SRCALPHASAT |
  1531. D3DPBLENDCAPS_BOTHSRCALPHA |
  1532. D3DPBLENDCAPS_BOTHINVSRCALPHA ;
  1533. RefGDD.hwCaps.dpcTriCaps.dwDestBlendCaps =
  1534. D3DPBLENDCAPS_ZERO |
  1535. D3DPBLENDCAPS_ONE |
  1536. D3DPBLENDCAPS_SRCCOLOR |
  1537. D3DPBLENDCAPS_INVSRCCOLOR |
  1538. D3DPBLENDCAPS_SRCALPHA |
  1539. D3DPBLENDCAPS_INVSRCALPHA |
  1540. D3DPBLENDCAPS_DESTALPHA |
  1541. D3DPBLENDCAPS_INVDESTALPHA |
  1542. D3DPBLENDCAPS_DESTCOLOR |
  1543. D3DPBLENDCAPS_INVDESTCOLOR |
  1544. D3DPBLENDCAPS_SRCALPHASAT ;
  1545. RefGDD.hwCaps.dpcTriCaps.dwAlphaCmpCaps =
  1546. RefGDD.hwCaps.dpcTriCaps.dwZCmpCaps;
  1547. RefGDD.hwCaps.dpcTriCaps.dwShadeCaps =
  1548. D3DPSHADECAPS_COLORFLATRGB |
  1549. D3DPSHADECAPS_COLORGOURAUDRGB |
  1550. D3DPSHADECAPS_SPECULARFLATRGB |
  1551. D3DPSHADECAPS_SPECULARGOURAUDRGB |
  1552. D3DPSHADECAPS_ALPHAFLATBLEND |
  1553. D3DPSHADECAPS_ALPHAGOURAUDBLEND |
  1554. D3DPSHADECAPS_FOGFLAT |
  1555. D3DPSHADECAPS_FOGGOURAUD ;
  1556. RefGDD.hwCaps.dpcTriCaps.dwTextureCaps =
  1557. D3DPTEXTURECAPS_PERSPECTIVE |
  1558. D3DPTEXTURECAPS_POW2 |
  1559. D3DPTEXTURECAPS_ALPHA |
  1560. D3DPTEXTURECAPS_TRANSPARENCY |
  1561. D3DPTEXTURECAPS_ALPHAPALETTE |
  1562. D3DPTEXTURECAPS_BORDER |
  1563. D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
  1564. D3DPTEXTURECAPS_ALPHAPALETTE |
  1565. D3DPTEXTURECAPS_PROJECTED |
  1566. D3DPTEXTURECAPS_CUBEMAP |
  1567. D3DPTEXTURECAPS_COLORKEYBLEND;
  1568. RefGDD.hwCaps.dpcTriCaps.dwTextureFilterCaps =
  1569. D3DPTFILTERCAPS_NEAREST |
  1570. D3DPTFILTERCAPS_LINEAR |
  1571. D3DPTFILTERCAPS_MIPNEAREST |
  1572. D3DPTFILTERCAPS_MIPLINEAR |
  1573. D3DPTFILTERCAPS_LINEARMIPNEAREST |
  1574. D3DPTFILTERCAPS_LINEARMIPLINEAR |
  1575. D3DPTFILTERCAPS_MINFPOINT |
  1576. D3DPTFILTERCAPS_MINFLINEAR |
  1577. D3DPTFILTERCAPS_MINFANISOTROPIC |
  1578. D3DPTFILTERCAPS_MIPFPOINT |
  1579. D3DPTFILTERCAPS_MIPFLINEAR |
  1580. D3DPTFILTERCAPS_MAGFPOINT |
  1581. D3DPTFILTERCAPS_MAGFLINEAR |
  1582. D3DPTFILTERCAPS_MAGFANISOTROPIC ;
  1583. RefGDD.hwCaps.dpcTriCaps.dwTextureBlendCaps =
  1584. D3DPTBLENDCAPS_DECAL |
  1585. D3DPTBLENDCAPS_MODULATE |
  1586. D3DPTBLENDCAPS_DECALALPHA |
  1587. D3DPTBLENDCAPS_MODULATEALPHA |
  1588. // D3DPTBLENDCAPS_DECALMASK |
  1589. // D3DPTBLENDCAPS_MODULATEMASK |
  1590. D3DPTBLENDCAPS_COPY |
  1591. D3DPTBLENDCAPS_ADD ;
  1592. RefGDD.hwCaps.dpcTriCaps.dwTextureAddressCaps =
  1593. D3DPTADDRESSCAPS_WRAP |
  1594. D3DPTADDRESSCAPS_MIRROR |
  1595. D3DPTADDRESSCAPS_CLAMP |
  1596. D3DPTADDRESSCAPS_BORDER |
  1597. D3DPTADDRESSCAPS_INDEPENDENTUV ;
  1598. RefGDD.hwCaps.dpcTriCaps.dwStippleWidth = 0;
  1599. RefGDD.hwCaps.dpcTriCaps.dwStippleHeight = 0;
  1600. // line caps - copy tricaps and modify
  1601. memcpy( &RefGDD.hwCaps.dpcLineCaps, &RefGDD.hwCaps.dpcTriCaps,
  1602. sizeof(D3DPRIMCAPS) );
  1603. // disable antialias cap
  1604. RefGDD.hwCaps.dpcLineCaps.dwRasterCaps =
  1605. D3DPRASTERCAPS_DITHER |
  1606. // D3DPRASTERCAPS_ROP2 |
  1607. // D3DPRASTERCAPS_XOR |
  1608. // D3DPRASTERCAPS_PAT |
  1609. D3DPRASTERCAPS_ZTEST |
  1610. D3DPRASTERCAPS_SUBPIXEL |
  1611. D3DPRASTERCAPS_SUBPIXELX |
  1612. D3DPRASTERCAPS_FOGVERTEX |
  1613. D3DPRASTERCAPS_FOGTABLE |
  1614. // D3DPRASTERCAPS_STIPPLE |
  1615. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  1616. // D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  1617. // D3DPRASTERCAPS_ANTIALIASEDGES |
  1618. D3DPRASTERCAPS_MIPMAPLODBIAS |
  1619. // D3DPRASTERCAPS_ZBIAS |
  1620. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  1621. D3DPRASTERCAPS_FOGRANGE |
  1622. D3DPRASTERCAPS_ANISOTROPY |
  1623. D3DPRASTERCAPS_WBUFFER |
  1624. // D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT |
  1625. D3DPRASTERCAPS_WFOG;
  1626. RefGDD.hwCaps.dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
  1627. RefGDD.hwCaps.dwDeviceZBufferBitDepth = DDBD_16 | DDBD_32;
  1628. //
  1629. // set extended caps
  1630. //
  1631. RefExtCaps.dwSize = sizeof(RefExtCaps);
  1632. RefExtCaps.dwMinTextureWidth = 1;
  1633. RefExtCaps.dwMaxTextureWidth = 4096;
  1634. RefExtCaps.dwMinTextureHeight = 1;
  1635. RefExtCaps.dwMaxTextureHeight = 4096;
  1636. RefExtCaps.dwMinStippleWidth = 0; // stipple unsupported
  1637. RefExtCaps.dwMaxStippleWidth = 0;
  1638. RefExtCaps.dwMinStippleHeight = 0;
  1639. RefExtCaps.dwMaxStippleHeight = 0;
  1640. RefExtCaps.dwMaxTextureRepeat = 32768;
  1641. RefExtCaps.dwMaxTextureAspectRatio = 0; // no limit
  1642. RefExtCaps.dwMaxAnisotropy = 16;
  1643. RefExtCaps.dvGuardBandLeft = (bIsNullDevice) ? (-2048.f) : (-32768.f);
  1644. RefExtCaps.dvGuardBandTop = (bIsNullDevice) ? (-2048.f) : (-32768.f);
  1645. RefExtCaps.dvGuardBandRight = (bIsNullDevice) ? ( 2047.f) : ( 32767.f);
  1646. RefExtCaps.dvGuardBandBottom = (bIsNullDevice) ? ( 2047.f) : ( 32767.f);
  1647. RefExtCaps.dvExtentsAdjust = 0.; // AA kernel is 1.0 x 1.0
  1648. RefExtCaps.dwStencilCaps =
  1649. D3DSTENCILCAPS_KEEP |
  1650. D3DSTENCILCAPS_ZERO |
  1651. D3DSTENCILCAPS_REPLACE|
  1652. D3DSTENCILCAPS_INCRSAT|
  1653. D3DSTENCILCAPS_DECRSAT|
  1654. D3DSTENCILCAPS_INVERT |
  1655. D3DSTENCILCAPS_INCR |
  1656. D3DSTENCILCAPS_DECR;
  1657. RefExtCaps.dwFVFCaps = 8; // max number of tex coord sets
  1658. RefExtCaps.dwTextureOpCaps =
  1659. D3DTEXOPCAPS_DISABLE |
  1660. D3DTEXOPCAPS_SELECTARG1 |
  1661. D3DTEXOPCAPS_SELECTARG2 |
  1662. D3DTEXOPCAPS_MODULATE |
  1663. D3DTEXOPCAPS_MODULATE2X |
  1664. D3DTEXOPCAPS_MODULATE4X |
  1665. D3DTEXOPCAPS_ADD |
  1666. D3DTEXOPCAPS_ADDSIGNED |
  1667. D3DTEXOPCAPS_ADDSIGNED2X |
  1668. D3DTEXOPCAPS_SUBTRACT |
  1669. D3DTEXOPCAPS_ADDSMOOTH |
  1670. D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
  1671. D3DTEXOPCAPS_BLENDTEXTUREALPHA |
  1672. D3DTEXOPCAPS_BLENDFACTORALPHA |
  1673. D3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
  1674. D3DTEXOPCAPS_BLENDCURRENTALPHA |
  1675. D3DTEXOPCAPS_PREMODULATE |
  1676. D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
  1677. D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
  1678. D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
  1679. D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
  1680. D3DTEXOPCAPS_BUMPENVMAP |
  1681. D3DTEXOPCAPS_BUMPENVMAPLUMINANCE |
  1682. D3DTEXOPCAPS_DOTPRODUCT3 ;
  1683. RefExtCaps.wMaxTextureBlendStages = 8;
  1684. RefExtCaps.wMaxSimultaneousTextures = 8;
  1685. RefExtCaps.dwMaxActiveLights = 0xffffffff;
  1686. RefExtCaps.dvMaxVertexW = 1.0e10;
  1687. switch( ddi )
  1688. {
  1689. case RDDDI_DX7TLHAL:
  1690. RefGDD.hwCaps.dwDevCaps |= D3DDEVCAPS_HWTRANSFORMANDLIGHT;
  1691. RefExtCaps.dwVertexProcessingCaps = (D3DVTXPCAPS_TEXGEN |
  1692. D3DVTXPCAPS_MATERIALSOURCE7 |
  1693. D3DVTXPCAPS_VERTEXFOG |
  1694. D3DVTXPCAPS_DIRECTIONALLIGHTS |
  1695. D3DVTXPCAPS_POSITIONALLIGHTS |
  1696. D3DVTXPCAPS_LOCALVIEWER);
  1697. RefExtCaps.wMaxUserClipPlanes = RD_MAX_USER_CLIPPLANES;
  1698. RefExtCaps.wMaxVertexBlendMatrices = RD_MAX_BLEND_WEIGHTS;
  1699. // Fall throug
  1700. case RDDDI_DX7HAL:
  1701. RefGDD.hwCaps.dwDevCaps |= D3DDEVCAPS_DRAWPRIMITIVES2EX;
  1702. }
  1703. }
  1704. //----------------------------------------------------------------------------
  1705. //
  1706. // Pixel formats
  1707. //
  1708. // Returns all the pixel formats supported by our rasterizer, and what we
  1709. // can do with them.
  1710. // Called at device creation time.
  1711. //
  1712. //----------------------------------------------------------------------------
  1713. DWORD
  1714. GetRefFormatOperations( LPDDSURFACEDESC* lplpddsd )
  1715. {
  1716. int i = 0;
  1717. DDSURFACEDESC* ddsd = g_ddsdTex;
  1718. // Here we list our DX8 texture formats.
  1719. // A driver wishing to run against DX7 or earlier runtimes would duplicate
  1720. // entries, placing a list of DDSURFACEDESCs before this list that contain
  1721. // old-style DDPIXELFORMAT structures. Example of old style:
  1722. // /* 888 */
  1723. // ddsd[i].dwSize = sizeof(ddsd[0]);
  1724. // ddsd[i].dwFlags = DDSD_PIXELFORMAT | DDSD_CAPS;
  1725. // ddsd[i].ddsCaps.dwCaps = DDSCAPS_TEXTURE;
  1726. // ddsd[i].ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
  1727. // ddsd[i].ddpfPixelFormat.dwFlags = DDPF_RGB;
  1728. // ddsd[i].ddpfPixelFormat.dwRGBBitCount = 32;
  1729. // ddsd[i].ddpfPixelFormat.dwRBitMask = 0xff0000;
  1730. // ddsd[i].ddpfPixelFormat.dwGBitMask = 0x00ff00;
  1731. // ddsd[i].ddpfPixelFormat.dwBBitMask = 0x0000ff;
  1732. //-------------------------- (A)RGB Formats -----------------------------------------
  1733. /* 888 */
  1734. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1735. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_R8G8B8;
  1736. ddsd[i].ddpfPixelFormat.dwOperations =
  1737. D3DFORMAT_OP_TEXTURE |
  1738. D3DFORMAT_OP_VOLUMETEXTURE |
  1739. D3DFORMAT_OP_CUBETEXTURE |
  1740. D3DFORMAT_OP_3DACCELERATION |
  1741. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1742. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1743. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1744. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1745. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1746. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1747. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1748. i++;
  1749. /* x888 */
  1750. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1751. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X8R8G8B8;
  1752. ddsd[i].ddpfPixelFormat.dwOperations =
  1753. D3DFORMAT_OP_TEXTURE |
  1754. D3DFORMAT_OP_VOLUMETEXTURE |
  1755. D3DFORMAT_OP_CUBETEXTURE |
  1756. D3DFORMAT_OP_3DACCELERATION |
  1757. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1758. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1759. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1760. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1761. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1762. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1763. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1764. i++;
  1765. /* 8888 */
  1766. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1767. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8R8G8B8;
  1768. ddsd[i].ddpfPixelFormat.dwOperations =
  1769. D3DFORMAT_OP_TEXTURE |
  1770. D3DFORMAT_OP_VOLUMETEXTURE |
  1771. D3DFORMAT_OP_CUBETEXTURE |
  1772. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1773. D3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET |
  1774. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1775. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1776. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1777. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1778. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1779. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1780. i++;
  1781. /* 565 */
  1782. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1783. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_R5G6B5;
  1784. ddsd[i].ddpfPixelFormat.dwOperations =
  1785. D3DFORMAT_OP_TEXTURE |
  1786. D3DFORMAT_OP_VOLUMETEXTURE |
  1787. D3DFORMAT_OP_CUBETEXTURE |
  1788. D3DFORMAT_OP_3DACCELERATION |
  1789. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1790. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1791. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1792. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1793. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1794. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1795. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1796. i++;
  1797. /* x555 */
  1798. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1799. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X1R5G5B5;
  1800. ddsd[i].ddpfPixelFormat.dwOperations =
  1801. D3DFORMAT_OP_TEXTURE |
  1802. D3DFORMAT_OP_VOLUMETEXTURE |
  1803. D3DFORMAT_OP_CUBETEXTURE |
  1804. D3DFORMAT_OP_3DACCELERATION |
  1805. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1806. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1807. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1808. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1809. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1810. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1811. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1812. i++;
  1813. /* 1555 */
  1814. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1815. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A1R5G5B5;
  1816. ddsd[i].ddpfPixelFormat.dwOperations =
  1817. D3DFORMAT_OP_TEXTURE |
  1818. D3DFORMAT_OP_VOLUMETEXTURE |
  1819. D3DFORMAT_OP_CUBETEXTURE |
  1820. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1821. D3DFORMAT_OP_SAME_FORMAT_UP_TO_ALPHA_RENDERTARGET |
  1822. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1823. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1824. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1825. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1826. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1827. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1828. i++;
  1829. // A formats for PC98 consistency
  1830. // 4444 ARGB (it is already supported by S3 Virge)
  1831. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1832. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A4R4G4B4;
  1833. ddsd[i].ddpfPixelFormat.dwOperations =
  1834. D3DFORMAT_OP_TEXTURE |
  1835. D3DFORMAT_OP_VOLUMETEXTURE |
  1836. D3DFORMAT_OP_CUBETEXTURE |
  1837. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1838. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1839. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1840. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1841. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1842. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1843. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1844. i++;
  1845. // 4444 XRGB
  1846. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1847. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X4R4G4B4;
  1848. ddsd[i].ddpfPixelFormat.dwOperations =
  1849. D3DFORMAT_OP_TEXTURE |
  1850. D3DFORMAT_OP_VOLUMETEXTURE |
  1851. D3DFORMAT_OP_CUBETEXTURE |
  1852. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1853. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1854. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1855. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1856. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1857. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1858. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1859. i++;
  1860. // 332 8-bit RGB
  1861. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1862. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_R3G3B2;
  1863. ddsd[i].ddpfPixelFormat.dwOperations =
  1864. D3DFORMAT_OP_TEXTURE |
  1865. D3DFORMAT_OP_VOLUMETEXTURE |
  1866. D3DFORMAT_OP_CUBETEXTURE |
  1867. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1868. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1869. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1870. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1871. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1872. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1873. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1874. i++;
  1875. // 8332 16-bit ARGB
  1876. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1877. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8R3G3B2;
  1878. ddsd[i].ddpfPixelFormat.dwOperations =
  1879. D3DFORMAT_OP_TEXTURE |
  1880. D3DFORMAT_OP_VOLUMETEXTURE |
  1881. D3DFORMAT_OP_CUBETEXTURE |
  1882. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1883. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1884. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1885. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1886. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1887. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  1888. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  1889. i++;
  1890. //---------------------------- Palettized formats ------------------------------------
  1891. #if 0
  1892. /* pal4 */
  1893. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1894. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD)
  1895. ddsd[i].ddpfPixelFormat.dwOperations =
  1896. D3DFORMAT_OP_TEXTURE |
  1897. D3DFORMAT_OP_VOLUMETEXTURE |
  1898. D3DFORMAT_OP_CUBETEXTURE |
  1899. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  1900. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  1901. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1902. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1903. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  1904. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES);
  1905. i++;
  1906. #endif
  1907. /* A8P8 */
  1908. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1909. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8P8;
  1910. ddsd[i].ddpfPixelFormat.dwOperations =
  1911. D3DFORMAT_OP_TEXTURE |
  1912. D3DFORMAT_OP_VOLUMETEXTURE |
  1913. D3DFORMAT_OP_CUBETEXTURE;
  1914. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1915. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1916. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1917. i++;
  1918. /* pal8 */
  1919. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1920. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_P8;
  1921. ddsd[i].ddpfPixelFormat.dwOperations =
  1922. D3DFORMAT_OP_TEXTURE |
  1923. D3DFORMAT_OP_VOLUMETEXTURE |
  1924. D3DFORMAT_OP_CUBETEXTURE;
  1925. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1926. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1927. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1928. i++;
  1929. //-------------------------- alpha/luminance formats -----------------------------------
  1930. /* 8 bit luminance-only */
  1931. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1932. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_L8;
  1933. ddsd[i].ddpfPixelFormat.dwOperations =
  1934. D3DFORMAT_OP_TEXTURE |
  1935. D3DFORMAT_OP_VOLUMETEXTURE |
  1936. D3DFORMAT_OP_CUBETEXTURE;
  1937. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1938. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1939. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1940. i++;
  1941. /* 16 bit alpha-luminance */
  1942. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1943. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8L8;
  1944. ddsd[i].ddpfPixelFormat.dwOperations =
  1945. D3DFORMAT_OP_TEXTURE |
  1946. D3DFORMAT_OP_VOLUMETEXTURE |
  1947. D3DFORMAT_OP_CUBETEXTURE;
  1948. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1949. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1950. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1951. i++;
  1952. /* 8 bit alpha-luminance */
  1953. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1954. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A4L4;
  1955. ddsd[i].ddpfPixelFormat.dwOperations =
  1956. D3DFORMAT_OP_TEXTURE |
  1957. D3DFORMAT_OP_VOLUMETEXTURE |
  1958. D3DFORMAT_OP_CUBETEXTURE;
  1959. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1960. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1961. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1962. i++;
  1963. /* A8 */
  1964. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1965. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8;
  1966. ddsd[i].ddpfPixelFormat.dwOperations =
  1967. D3DFORMAT_OP_TEXTURE |
  1968. D3DFORMAT_OP_VOLUMETEXTURE |
  1969. D3DFORMAT_OP_CUBETEXTURE;
  1970. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1971. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1972. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1973. i++;
  1974. //-------------------------- YUV formats -----------------------------------
  1975. // UYVY
  1976. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1977. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_UYVY;
  1978. ddsd[i].ddpfPixelFormat.dwOperations =
  1979. D3DFORMAT_OP_TEXTURE |
  1980. D3DFORMAT_OP_VOLUMETEXTURE |
  1981. D3DFORMAT_OP_CUBETEXTURE;
  1982. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1983. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1984. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1985. i++;
  1986. // YUY2
  1987. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  1988. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_YUY2;
  1989. ddsd[i].ddpfPixelFormat.dwOperations =
  1990. D3DFORMAT_OP_TEXTURE |
  1991. D3DFORMAT_OP_VOLUMETEXTURE |
  1992. D3DFORMAT_OP_CUBETEXTURE;
  1993. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  1994. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  1995. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  1996. i++;
  1997. //-------------------------- DXT formats -----------------------------------
  1998. // DXT compressed texture format 1
  1999. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2000. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_DXT1;
  2001. ddsd[i].ddpfPixelFormat.dwOperations =
  2002. D3DFORMAT_OP_TEXTURE |
  2003. D3DFORMAT_OP_VOLUMETEXTURE |
  2004. D3DFORMAT_OP_CUBETEXTURE;
  2005. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2006. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2007. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2008. i++;
  2009. // DXT compressed texture format 2
  2010. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2011. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_DXT2;
  2012. ddsd[i].ddpfPixelFormat.dwOperations =
  2013. D3DFORMAT_OP_TEXTURE |
  2014. D3DFORMAT_OP_VOLUMETEXTURE |
  2015. D3DFORMAT_OP_CUBETEXTURE;
  2016. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2017. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2018. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2019. i++;
  2020. // DXT compressed texture format 3
  2021. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2022. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_DXT3;
  2023. ddsd[i].ddpfPixelFormat.dwOperations =
  2024. D3DFORMAT_OP_TEXTURE |
  2025. D3DFORMAT_OP_VOLUMETEXTURE |
  2026. D3DFORMAT_OP_CUBETEXTURE;
  2027. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2028. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2029. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2030. i++;
  2031. // DXT compressed texture format 4
  2032. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2033. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_DXT4;
  2034. ddsd[i].ddpfPixelFormat.dwOperations =
  2035. D3DFORMAT_OP_TEXTURE |
  2036. D3DFORMAT_OP_VOLUMETEXTURE |
  2037. D3DFORMAT_OP_CUBETEXTURE;
  2038. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2039. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2040. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2041. i++;
  2042. // DXT compressed texture format 5
  2043. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2044. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_DXT5;
  2045. ddsd[i].ddpfPixelFormat.dwOperations =
  2046. D3DFORMAT_OP_TEXTURE |
  2047. D3DFORMAT_OP_VOLUMETEXTURE |
  2048. D3DFORMAT_OP_CUBETEXTURE;
  2049. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2050. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2051. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2052. i++;
  2053. //-------------------------- Bump/luminance formats / Signed formats -----------------
  2054. // V8U8
  2055. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2056. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_V8U8;
  2057. ddsd[i].ddpfPixelFormat.dwOperations =
  2058. D3DFORMAT_OP_TEXTURE |
  2059. D3DFORMAT_OP_VOLUMETEXTURE |
  2060. D3DFORMAT_OP_CUBETEXTURE;
  2061. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2062. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2063. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2064. i++;
  2065. // L6V5U5
  2066. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2067. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_L6V5U5;
  2068. ddsd[i].ddpfPixelFormat.dwOperations =
  2069. D3DFORMAT_OP_TEXTURE |
  2070. D3DFORMAT_OP_VOLUMETEXTURE |
  2071. D3DFORMAT_OP_CUBETEXTURE;
  2072. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2073. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2074. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2075. i++;
  2076. // X8L8V8U8
  2077. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2078. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X8L8V8U8;
  2079. ddsd[i].ddpfPixelFormat.dwOperations =
  2080. D3DFORMAT_OP_TEXTURE |
  2081. D3DFORMAT_OP_VOLUMETEXTURE |
  2082. D3DFORMAT_OP_CUBETEXTURE;
  2083. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2084. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2085. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2086. i++;
  2087. // V16U16
  2088. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2089. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_V16U16;
  2090. ddsd[i].ddpfPixelFormat.dwOperations =
  2091. D3DFORMAT_OP_TEXTURE |
  2092. D3DFORMAT_OP_VOLUMETEXTURE |
  2093. D3DFORMAT_OP_CUBETEXTURE;
  2094. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2095. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2096. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2097. i++;
  2098. // Q8W8V8U8
  2099. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2100. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_Q8W8V8U8;
  2101. ddsd[i].ddpfPixelFormat.dwOperations =
  2102. D3DFORMAT_OP_TEXTURE |
  2103. D3DFORMAT_OP_VOLUMETEXTURE |
  2104. D3DFORMAT_OP_CUBETEXTURE;
  2105. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2106. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2107. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2108. i++;
  2109. // W11V11U10
  2110. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2111. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_W11V11U10;
  2112. ddsd[i].ddpfPixelFormat.dwOperations =
  2113. D3DFORMAT_OP_TEXTURE |
  2114. D3DFORMAT_OP_VOLUMETEXTURE |
  2115. D3DFORMAT_OP_CUBETEXTURE;
  2116. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2117. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2118. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2119. i++;
  2120. //-------------- Formats introduced in DX8.1 -------------------------
  2121. #if 0
  2122. // A8B8G8R8
  2123. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2124. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8B8G8R8;
  2125. ddsd[i].ddpfPixelFormat.dwOperations =
  2126. D3DFORMAT_OP_TEXTURE |
  2127. D3DFORMAT_OP_VOLUMETEXTURE |
  2128. D3DFORMAT_OP_CUBETEXTURE |
  2129. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  2130. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  2131. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2132. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2133. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2134. i++;
  2135. // W10V11U11
  2136. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2137. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_W10V11U11;
  2138. ddsd[i].ddpfPixelFormat.dwOperations =
  2139. D3DFORMAT_OP_TEXTURE |
  2140. D3DFORMAT_OP_VOLUMETEXTURE |
  2141. D3DFORMAT_OP_CUBETEXTURE;
  2142. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2143. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2144. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2145. i++;
  2146. // A8X8V8U8
  2147. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2148. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A8X8V8U8;
  2149. ddsd[i].ddpfPixelFormat.dwOperations =
  2150. D3DFORMAT_OP_TEXTURE |
  2151. D3DFORMAT_OP_VOLUMETEXTURE |
  2152. D3DFORMAT_OP_CUBETEXTURE;
  2153. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2154. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2155. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2156. i++;
  2157. // L8X8V8U8
  2158. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2159. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_L8X8V8U8;
  2160. ddsd[i].ddpfPixelFormat.dwOperations =
  2161. D3DFORMAT_OP_TEXTURE |
  2162. D3DFORMAT_OP_VOLUMETEXTURE |
  2163. D3DFORMAT_OP_CUBETEXTURE;
  2164. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2165. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2166. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2167. i++;
  2168. // X8B8G8R8
  2169. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2170. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X8B8G8R8;
  2171. ddsd[i].ddpfPixelFormat.dwOperations =
  2172. D3DFORMAT_OP_TEXTURE |
  2173. D3DFORMAT_OP_VOLUMETEXTURE |
  2174. D3DFORMAT_OP_CUBETEXTURE |
  2175. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  2176. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  2177. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2178. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2179. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2180. i++;
  2181. #endif
  2182. // A2W10V10U10
  2183. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2184. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A2W10V10U10;
  2185. ddsd[i].ddpfPixelFormat.dwOperations =
  2186. D3DFORMAT_OP_TEXTURE |
  2187. D3DFORMAT_OP_VOLUMETEXTURE |
  2188. D3DFORMAT_OP_CUBETEXTURE;
  2189. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2190. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2191. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2192. i++;
  2193. // A2B10G10R10
  2194. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2195. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_A2B10G10R10;
  2196. ddsd[i].ddpfPixelFormat.dwOperations =
  2197. D3DFORMAT_OP_TEXTURE |
  2198. D3DFORMAT_OP_VOLUMETEXTURE |
  2199. D3DFORMAT_OP_CUBETEXTURE |
  2200. D3DFORMAT_OP_SAME_FORMAT_RENDERTARGET |
  2201. D3DFORMAT_OP_OFFSCREEN_RENDERTARGET;
  2202. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2203. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2204. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2205. i++;
  2206. // G16R16
  2207. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2208. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_G16R16;
  2209. ddsd[i].ddpfPixelFormat.dwOperations =
  2210. D3DFORMAT_OP_TEXTURE |
  2211. D3DFORMAT_OP_VOLUMETEXTURE |
  2212. D3DFORMAT_OP_CUBETEXTURE;
  2213. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2214. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2215. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2216. i++;
  2217. //-------------------------- Z/Stencil buffer formats -----------------------------------
  2218. /* 8 bit stencil; 24 bit Z */
  2219. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2220. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_S8D24;
  2221. ddsd[i].ddpfPixelFormat.dwOperations =
  2222. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2223. D3DFORMAT_OP_ZSTENCIL;
  2224. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2225. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2226. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2227. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2228. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2229. i++;
  2230. /* 1 bit stencil; 15 bit Z */
  2231. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2232. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_S1D15;
  2233. ddsd[i].ddpfPixelFormat.dwOperations =
  2234. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2235. D3DFORMAT_OP_ZSTENCIL;
  2236. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2237. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2238. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2239. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2240. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2241. i++;
  2242. /* 4 bit stencil; 24 bit Z */
  2243. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2244. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_D24X4S4;
  2245. ddsd[i].ddpfPixelFormat.dwOperations =
  2246. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2247. D3DFORMAT_OP_ZSTENCIL;
  2248. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2249. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2250. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2251. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2252. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2253. i++;
  2254. //-------------------------- Z/Stencil/texture + shadow buffer formats -----------------------------------
  2255. // Z16S0
  2256. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2257. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_D16_LOCKABLE;
  2258. ddsd[i].ddpfPixelFormat.dwOperations =
  2259. #if 0
  2260. // for Shadow Buffer prototype API
  2261. D3DFORMAT_OP_TEXTURE |
  2262. #endif
  2263. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2264. D3DFORMAT_OP_ZSTENCIL;
  2265. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2266. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2267. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2268. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2269. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2270. i++;
  2271. // Z32S0
  2272. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2273. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_D32;
  2274. ddsd[i].ddpfPixelFormat.dwOperations =
  2275. #if 0
  2276. // for Shadow Buffer prototype API
  2277. D3DFORMAT_OP_TEXTURE |
  2278. #endif
  2279. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2280. D3DFORMAT_OP_ZSTENCIL;
  2281. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2282. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2283. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2284. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2285. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2286. i++;
  2287. /* 24 bit Z */
  2288. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2289. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) D3DFMT_X8D24;
  2290. ddsd[i].ddpfPixelFormat.dwOperations =
  2291. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2292. D3DFORMAT_OP_ZSTENCIL;
  2293. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 0; //not required for known formats
  2294. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2295. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes =
  2296. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_4_SAMPLES) |
  2297. DDI_MULTISAMPLE_TYPE(D3DMULTISAMPLE_9_SAMPLES);
  2298. i++;
  2299. //
  2300. // This is an example of a IHV-specific format
  2301. // The HIWORD must be the PCI-ID of the IHV
  2302. // and the third byte must be zero.
  2303. // In this case, we're using a sample PCI-ID of
  2304. // FF00, and we're denoting the 4th format
  2305. // by that PCI-ID.
  2306. //
  2307. // In this case, we're exposing a non-standard Z-buffer format
  2308. // that can be used as a texture and depth-stencil at
  2309. // in the same format.(We are also choosing to
  2310. // disallow it as valid for cubemaps and volumes.)
  2311. //
  2312. ddsd[i].ddpfPixelFormat.dwFlags = DDPF_D3DFORMAT;
  2313. ddsd[i].ddpfPixelFormat.dwFourCC = (DWORD) 0xFF000004;
  2314. ddsd[i].ddpfPixelFormat.dwOperations =
  2315. D3DFORMAT_OP_ZSTENCIL_WITH_ARBITRARY_COLOR_DEPTH |
  2316. D3DFORMAT_OP_ZSTENCIL |
  2317. D3DFORMAT_OP_TEXTURE |
  2318. D3DFORMAT_OP_PIXELSIZE;
  2319. ddsd[i].ddpfPixelFormat.dwPrivateFormatBitCount = 32; // required for IHV formats
  2320. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wFlipMSTypes = 0;
  2321. ddsd[i].ddpfPixelFormat.MultiSampleCaps.wBltMSTypes = 0;
  2322. i++;
  2323. *lplpddsd = ddsd;
  2324. _ASSERT(i<=RD_MAX_NUM_TEXTURE_FORMATS, "Not enough space in static texture list");
  2325. return i;
  2326. }
  2327. #include <d3d8sddi.h>
  2328. HRESULT WINAPI
  2329. D3D8GetSWInfo( D3DCAPS8* pCaps, PD3D8_SWCALLBACKS pCallbacks,
  2330. DWORD* pNumTextures, DDSURFACEDESC** ppTexList )
  2331. {
  2332. #define RESPATH_D3D "Software\\Microsoft\\Direct3D"
  2333. // First query the registry to check if we were asked to
  2334. // emulate any particular DDI.
  2335. g_RefDDI = RDDDI_DX8TLHAL;
  2336. HKEY hKey = (HKEY) NULL;
  2337. if( ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, RESPATH_D3D, &hKey) )
  2338. {
  2339. DWORD dwType;
  2340. DWORD dwValue;
  2341. DWORD dwSize = sizeof(dwValue);
  2342. if ( ERROR_SUCCESS == RegQueryValueEx( hKey, "DriverStyle", NULL,
  2343. &dwType, (LPBYTE) &dwValue,
  2344. &dwSize ) &&
  2345. dwType == REG_DWORD &&
  2346. dwValue > 0
  2347. )
  2348. {
  2349. g_RefDDI = (RDDDITYPE)dwValue;
  2350. // NOTE: RefDev's DDI emulation is currently restricted to
  2351. // DX8 TL and Non-TL HALs only.
  2352. if( g_RefDDI > RDDDI_DX8TLHAL )
  2353. {
  2354. DPFERR( "Bad Driver style set. Assuming DX8TLHAL" );
  2355. g_RefDDI = RDDDI_DX8TLHAL;
  2356. }
  2357. if( g_RefDDI < RDDDI_DX8HAL )
  2358. {
  2359. DPFERR( "Bad Driver style set. Assuming DX8HAL" );
  2360. g_RefDDI = RDDDI_DX8HAL;
  2361. }
  2362. }
  2363. RegCloseKey(hKey);
  2364. }
  2365. // NULL out all the callbacks first
  2366. memset( pCallbacks, 0, sizeof(PD3D8_SWCALLBACKS) );
  2367. // These callbacks are needed by everyone
  2368. pCallbacks->CreateContext = RefRastContextCreate;
  2369. pCallbacks->ContextDestroy = RefRastContextDestroy;
  2370. pCallbacks->ContextDestroyAll = NULL;
  2371. pCallbacks->SceneCapture = RefRastSceneCapture;
  2372. pCallbacks->CreateSurface = RefRastCreateSurface;
  2373. pCallbacks->Lock = RefRastLock;
  2374. pCallbacks->DestroySurface = RefRastDestroySurface;
  2375. pCallbacks->Unlock = RefRastUnlock;
  2376. switch( g_RefDDI )
  2377. {
  2378. case RDDDI_DX8TLHAL:
  2379. case RDDDI_DX8HAL:
  2380. case RDDDI_DX7TLHAL:
  2381. case RDDDI_DX7HAL:
  2382. pCallbacks->GetDriverState = RefRastGetDriverState;
  2383. pCallbacks->CreateSurfaceEx = RefRastCreateSurfaceEx;
  2384. // Fall through
  2385. case RDDDI_DP2HAL:
  2386. pCallbacks->ValidateTextureStageState =
  2387. RefRastValidateTextureStageState;
  2388. pCallbacks->DrawPrimitives2 = RefRastDrawPrimitives2;
  2389. pCallbacks->Clear2 = NULL;
  2390. // Fall through
  2391. case RDDDI_DPHAL:
  2392. pCallbacks->DrawOnePrimitive = NULL;
  2393. pCallbacks->DrawOneIndexedPrimitive = NULL;
  2394. pCallbacks->DrawPrimitives = NULL;
  2395. pCallbacks->Clear = NULL;
  2396. pCallbacks->SetRenderTarget = RefRastSetRenderTarget;
  2397. // Fall through
  2398. case RDDDI_OLDHAL:
  2399. pCallbacks->RenderState = NULL;
  2400. pCallbacks->RenderPrimitive = NULL;
  2401. pCallbacks->TextureCreate = RefRastTextureCreate;
  2402. pCallbacks->TextureDestroy = RefRastTextureDestroy;
  2403. pCallbacks->TextureSwap = NULL;
  2404. pCallbacks->TextureGetSurf = RefRastTextureGetSurf;
  2405. break;
  2406. default:
  2407. DPFERR( "Unknown DDI style set" );
  2408. return E_FAIL;
  2409. }
  2410. // Now deal with the caps
  2411. FillOutDeviceCaps(FALSE, g_RefDDI);
  2412. // Fill in the supported pixel format operations
  2413. // In DX8 these operations are expressed through the texture
  2414. // format list.
  2415. *pNumTextures = GetRefFormatOperations( ppTexList );
  2416. FillOutDeviceCaps8( g_RefDDI );
  2417. ModifyDeviceCaps8();
  2418. *pCaps = g_RefCaps8;
  2419. return DD_OK;
  2420. }