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.

2266 lines
93 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * **************************
  4. * * DirectDraw SAMPLE CODE *
  5. * **************************
  6. *
  7. * Module Name: ddbltfx.c
  8. *
  9. * Content: DirectDraw Blt implementation for stretching blts
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #include "glint.h"
  15. #include "glintdef.h"
  16. #include "dma.h"
  17. #include "tag.h"
  18. #include "chroma.h"
  19. // A magic number to make it all work.
  20. // This must be 11 or less, according to the P3 spec.
  21. #define MAGIC_NUMBER_2D 11
  22. //-----------------------------------------------------------------------------
  23. //
  24. // _DD_P3BltSourceChroma
  25. //
  26. // Do a blt with no stretching, but with source chroma keying
  27. //
  28. //-----------------------------------------------------------------------------
  29. void
  30. _DD_P3BltSourceChroma(
  31. P3_THUNKEDDATA* pThisDisplay,
  32. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  33. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  34. P3_SURF_FORMAT* pFormatSource,
  35. P3_SURF_FORMAT* pFormatDest,
  36. LPDDHAL_BLTDATA lpBlt,
  37. RECTL *rSrc,
  38. RECTL *rDest)
  39. {
  40. LONG rSrctop, rSrcleft, rDesttop, rDestleft;
  41. BOOL b8to8blit;
  42. BOOL bBlocking;
  43. DWORD dwRenderDirection;
  44. DWORD dwSourceOffset;
  45. DWORD dwLowerSrcBound, dwUpperSrcBound;
  46. P3_DMA_DEFS();
  47. // Beacuse of a bug in RL we sometimes
  48. // have to fiddle with these values
  49. rSrctop = rSrc->top;
  50. rSrcleft = rSrc->left;
  51. rDesttop = rDest->top;
  52. rDestleft = rDest->left;
  53. // Fix coords origin
  54. if(!_DD_BLT_FixRectlOrigin("_DD_P3BltSourceChroma", rSrc, rDest))
  55. {
  56. // Nothing to be blitted
  57. return;
  58. }
  59. if ( ( pFormatDest->DeviceFormat == SURF_CI8 ) &&
  60. ( pFormatSource->DeviceFormat == SURF_CI8 ) )
  61. {
  62. // An 8bit->8bit blit. This is treated specially, since no LUT translation is involved.
  63. b8to8blit = TRUE;
  64. }
  65. else
  66. {
  67. b8to8blit = FALSE;
  68. }
  69. DISPDBG((DBGLVL, "P3 Chroma (before): Upper = 0x%08x, Lower = 0x%08x",
  70. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue,
  71. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue));
  72. // Prepare data to be used as color keying limits
  73. if ( b8to8blit )
  74. {
  75. // No conversion, just use the index value in the R channel.
  76. dwLowerSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue & 0x000000ff;
  77. dwUpperSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue | 0xffffff00;
  78. }
  79. else
  80. {
  81. dwLowerSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue;
  82. dwUpperSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue;
  83. if ( pFormatSource->DeviceFormat == SURF_8888 )
  84. {
  85. //
  86. // Mask off alpha channel when a single source color key is used
  87. //@@BEGIN_DDKSPLIT
  88. // IZ : This can be a problem when a color key range is used.
  89. //@@END_DDKSPLIT
  90. //
  91. dwUpperSrcBound |= 0xFF000000;
  92. dwLowerSrcBound &= 0x00FFFFFF;
  93. }
  94. }
  95. DISPDBG((DBGLVL, "P3 Chroma (after): Upper = 0x%08x, Lower = 0x%08x",
  96. dwUpperSrcBound, dwLowerSrcBound));
  97. // Determine the direction of the blt
  98. dwRenderDirection = _DD_BLT_GetBltDirection(pSource->lpGbl->fpVidMem,
  99. pDest->lpGbl->fpVidMem,
  100. rSrc,
  101. rDest,
  102. &bBlocking);
  103. P3_DMA_GET_BUFFER_ENTRIES(32);
  104. // Even though the AlphaBlend is disabled, the chromakeying uses
  105. // the ColorFormat, ColorOrder and ColorConversion fields.
  106. SEND_P3_DATA(PixelSize, (2 - DDSurf_GetChipPixelSize(pDest)));
  107. SEND_P3_DATA(AlphaBlendColorMode,
  108. P3RX_ALPHABLENDCOLORMODE_ENABLE ( __PERMEDIA_DISABLE )
  109. | P3RX_ALPHABLENDCOLORMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  110. | P3RX_ALPHABLENDCOLORMODE_COLORORDER ( COLOR_MODE )
  111. | P3RX_ALPHABLENDCOLORMODE_COLORCONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  112. );
  113. SEND_P3_DATA(AlphaBlendAlphaMode,
  114. P3RX_ALPHABLENDALPHAMODE_ENABLE ( __PERMEDIA_DISABLE )
  115. | P3RX_ALPHABLENDALPHAMODE_NOALPHABUFFER( __PERMEDIA_DISABLE )
  116. | P3RX_ALPHABLENDALPHAMODE_ALPHATYPE ( P3RX_ALPHABLENDMODE_ALPHATYPE_OGL )
  117. | P3RX_ALPHABLENDALPHAMODE_ALPHACONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  118. );
  119. // Setup the hw chromakeying registers
  120. SEND_P3_DATA(ChromaTestMode,
  121. P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_ENABLE)
  122. | P3RX_CHROMATESTMODE_SOURCE(P3RX_CHROMATESTMODE_SOURCE_FBDATA)
  123. | P3RX_CHROMATESTMODE_PASSACTION(P3RX_CHROMATESTMODE_ACTION_REJECT)
  124. | P3RX_CHROMATESTMODE_FAILACTION(P3RX_CHROMATESTMODE_ACTION_PASS)
  125. );
  126. SEND_P3_DATA(ChromaLower, dwLowerSrcBound);
  127. SEND_P3_DATA(ChromaUpper, dwUpperSrcBound);
  128. SEND_P3_DATA(LogicalOpMode, GLINT_ENABLED_LOGICALOP( __GLINT_LOGICOP_NOOP ));
  129. SEND_P3_DATA(FBWriteBufferAddr0,
  130. DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pDest));
  131. SEND_P3_DATA(FBWriteBufferWidth0, DDSurf_GetPixelPitch(pDest));
  132. SEND_P3_DATA(FBWriteBufferOffset0, 0);
  133. SEND_P3_DATA(FBSourceReadBufferAddr,
  134. DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pSource));
  135. SEND_P3_DATA(FBSourceReadBufferWidth, DDSurf_GetPixelPitch(pSource));
  136. dwSourceOffset = (( rSrc->top - rDest->top ) << 16 ) |
  137. (( rSrc->left - rDest->left ) & 0xffff );
  138. SEND_P3_DATA(FBSourceReadBufferOffset, dwSourceOffset);
  139. SEND_P3_DATA(FBDestReadMode,
  140. P3RX_FBDESTREAD_READENABLE(__PERMEDIA_DISABLE)
  141. | P3RX_FBDESTREAD_LAYOUT0(P3RX_LAYOUT_LINEAR));
  142. SEND_P3_DATA(FBWriteMode,
  143. P3RX_FBWRITEMODE_WRITEENABLE(__PERMEDIA_ENABLE)
  144. | P3RX_FBWRITEMODE_LAYOUT0(P3RX_LAYOUT_LINEAR));
  145. SEND_P3_DATA(FBSourceReadMode,
  146. P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE)
  147. | P3RX_FBSOURCEREAD_LAYOUT(P3RX_LAYOUT_LINEAR)
  148. | P3RX_FBSOURCEREAD_BLOCKING(bBlocking));
  149. P3_DMA_COMMIT_BUFFER();
  150. P3_DMA_GET_BUFFER_ENTRIES(30);
  151. // Can't use 2D setup because we aren't rendering with spans.
  152. if (dwRenderDirection == 0)
  153. {
  154. // right to left, bottom to top
  155. SEND_P3_DATA(StartXDom, (rDest->right << 16));
  156. SEND_P3_DATA(StartXSub, (rDest->left << 16));
  157. SEND_P3_DATA(StartY, ((rDest->bottom - 1) << 16));
  158. SEND_P3_DATA(dY, (DWORD)((-1) << 16));
  159. }
  160. else
  161. {
  162. // left to right, top to bottom
  163. SEND_P3_DATA(StartXDom, (rDest->left << 16));
  164. SEND_P3_DATA(StartXSub, (rDest->right << 16));
  165. SEND_P3_DATA(StartY, (rDest->top << 16));
  166. SEND_P3_DATA(dY, (1 << 16));
  167. }
  168. SEND_P3_DATA(Count, rDest->bottom - rDest->top );
  169. // Do the blt
  170. SEND_P3_DATA(Render,
  171. P3RX_RENDER_PRIMITIVETYPE(P3RX_RENDER_PRIMITIVETYPE_TRAPEZOID)
  172. | P3RX_RENDER_FBSOURCEREADENABLE(__PERMEDIA_ENABLE));
  173. // Disable all the units that were switched on.
  174. SEND_P3_DATA(ChromaTestMode, __PERMEDIA_DISABLE );
  175. SEND_P3_DATA(AlphaBlendColorMode, __PERMEDIA_DISABLE );
  176. SEND_P3_DATA(AlphaBlendAlphaMode, __PERMEDIA_DISABLE );
  177. SEND_P3_DATA(LogicalOpMode, __PERMEDIA_DISABLE );
  178. // Put back the values if we changed them.
  179. rSrc->top = rSrctop;
  180. rSrc->left = rSrcleft;
  181. rDest->top = rDesttop;
  182. rDest->left = rDestleft;
  183. P3_DMA_COMMIT_BUFFER();
  184. } // _DD_P3BltSourceChroma
  185. //-----------------------------------------------------------------------------
  186. //
  187. // _DD_P3BltStretchSrcChDstCh
  188. //
  189. //
  190. // Does a blit through the texture unit to allow stretching. Also
  191. // handle mirroring if the stretched image requires it and doth dest and
  192. // source chromakeying. Can also YUV->RGB convert
  193. //
  194. // This is the generic rout - others will be optimisations of this
  195. // (if necessary).
  196. //
  197. //
  198. //-----------------------------------------------------------------------------
  199. VOID
  200. _DD_P3BltStretchSrcChDstCh(
  201. P3_THUNKEDDATA* pThisDisplay,
  202. FLATPTR fpSrcVidMem,
  203. P3_SURF_FORMAT* pFormatSource,
  204. DWORD dwSrcPixelSize,
  205. DWORD dwSrcWidth,
  206. DWORD dwSrcHeight,
  207. DWORD dwSrcPixelPitch,
  208. DWORD dwSrcPatchMode,
  209. ULONG ulSrcOffsetFromMemBase,
  210. DWORD dwSrcFlags,
  211. DDPIXELFORMAT* pSrcDDPF,
  212. BOOL bIsSourceAGP,
  213. FLATPTR fpDestVidMem,
  214. P3_SURF_FORMAT* pFormatDest,
  215. DWORD dwDestPixelSize,
  216. DWORD dwDestWidth,
  217. DWORD dwDestHeight,
  218. DWORD dwDestPixelPitch,
  219. DWORD dwDestPatchMode,
  220. ULONG ulDestOffsetFromMemBase,
  221. DWORD dwBltFlags,
  222. DWORD dwBltDDFX,
  223. DDCOLORKEY BltSrcColorKey,
  224. DDCOLORKEY BltDestColorKey,
  225. RECTL *rSrc,
  226. RECTL *rDest)
  227. {
  228. ULONG renderData;
  229. RECTL rMySrc, rMyDest;
  230. int iXScale, iYScale;
  231. int iSrcWidth, iSrcHeight;
  232. int iDstWidth, iDstHeight;
  233. DWORD texSStart, texTStart;
  234. DWORD dwRenderDirection;
  235. BOOL bXMirror, bYMirror;
  236. BOOL bFiltering;
  237. BOOL bSrcKey, bDstKey;
  238. BOOL bDisableLUT;
  239. int iTemp;
  240. BOOL b8to8blit;
  241. BOOL bYUVMode;
  242. BOOL bBlocking;
  243. DWORD TR0;
  244. int iTextureType;
  245. int iPixelSize;
  246. int iTextureFilterModeColorOrder;
  247. SurfFilterDeviceFormat sfdfTextureFilterModeFormat;
  248. P3_DMA_DEFS();
  249. // Make local copies that we can mangle.
  250. rMySrc = *rSrc;
  251. rMyDest = *rDest;
  252. // Fix coords origin
  253. if(!_DD_BLT_FixRectlOrigin("_DD_P3BltStretchSrcChDstCh",
  254. &rMySrc, &rMyDest))
  255. {
  256. // Nothing to be blitted
  257. return;
  258. }
  259. iSrcWidth = rMySrc.right - rMySrc.left;
  260. iSrcHeight = rMySrc.bottom - rMySrc.top;
  261. iDstWidth = rMyDest.right - rMyDest.left;
  262. iDstHeight = rMyDest.bottom - rMyDest.top;
  263. bDisableLUT = FALSE;
  264. if (pFormatSource->DeviceFormat == SURF_YUV422)
  265. {
  266. bYUVMode = TRUE;
  267. // Always use ABGR for YUV;
  268. iTextureFilterModeColorOrder = 0;
  269. }
  270. else
  271. {
  272. bYUVMode = FALSE;
  273. iTextureFilterModeColorOrder = COLOR_MODE;
  274. }
  275. sfdfTextureFilterModeFormat = pFormatSource->FilterFormat;
  276. if ( ( pFormatDest->DeviceFormat == SURF_CI8 ) &&
  277. ( pFormatSource->DeviceFormat == SURF_CI8 ) )
  278. {
  279. // An 8bit->8bit blit. This is treated specially,
  280. // since no LUT translation is involved.
  281. // Fake this up in a wacky way to stop the LUT
  282. // getting it's hands on it.
  283. sfdfTextureFilterModeFormat = SURF_FILTER_L8;
  284. bDisableLUT = TRUE;
  285. b8to8blit = TRUE;
  286. }
  287. else
  288. {
  289. b8to8blit = FALSE;
  290. }
  291. // Let's see if anyone uses this flag - might be good to get it working
  292. // now that we know what it means (use bilinear filtering instead of point).
  293. ASSERTDD ( ( dwBltFlags & DDBLTFX_ARITHSTRETCHY ) == 0,
  294. "** _DD_P3BltStretchSrcChDstCh: DDBLTFX_ARITHSTRETCHY used");
  295. // Is this a stretch blit?
  296. if (((iSrcWidth != iDstWidth) ||
  297. (iSrcHeight != iDstHeight)) &&
  298. ((pFormatSource->DeviceFormat == SURF_YUV422)) )
  299. {
  300. bFiltering = TRUE;
  301. }
  302. else
  303. {
  304. bFiltering = FALSE;
  305. }
  306. if ( ( dwBltFlags & DDBLT_KEYSRCOVERRIDE ) != 0 )
  307. {
  308. bSrcKey = TRUE;
  309. }
  310. else
  311. {
  312. bSrcKey = FALSE;
  313. }
  314. if ( ( dwBltFlags & DDBLT_KEYDESTOVERRIDE ) != 0 )
  315. {
  316. bDstKey = TRUE;
  317. }
  318. else
  319. {
  320. bDstKey = FALSE;
  321. }
  322. // Determine the direction of the blt
  323. dwRenderDirection = _DD_BLT_GetBltDirection(fpSrcVidMem,
  324. fpDestVidMem,
  325. &rMySrc,
  326. &rMyDest,
  327. &bBlocking);
  328. // If we are doing special effects, and we are mirroring,
  329. // we need to fix up the rectangles and change the sense of
  330. // the render operation - we need to be carefull with overlapping
  331. // rectangles
  332. if (dwRenderDirection)
  333. {
  334. if(dwBltFlags & DDBLT_DDFX)
  335. {
  336. if(dwBltDDFX & DDBLTFX_MIRRORUPDOWN)
  337. {
  338. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  339. {
  340. // Need to fix up the rectangles
  341. iTemp = rMySrc.bottom;
  342. rMySrc.bottom = dwSrcHeight - rMySrc.top;
  343. rMySrc.top = dwSrcHeight - iTemp;
  344. }
  345. bYMirror = TRUE;
  346. }
  347. else
  348. {
  349. bYMirror = FALSE;
  350. }
  351. if(dwBltDDFX & DDBLTFX_MIRRORLEFTRIGHT)
  352. {
  353. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  354. {
  355. // Need to fix up the rectangles
  356. iTemp = rMySrc.right;
  357. rMySrc.right = dwSrcWidth - rMySrc.left;
  358. rMySrc.left = dwSrcWidth - iTemp;
  359. }
  360. bXMirror = TRUE;
  361. }
  362. else
  363. {
  364. bXMirror = FALSE;
  365. }
  366. }
  367. else
  368. {
  369. bXMirror = FALSE;
  370. bYMirror = FALSE;
  371. }
  372. }
  373. else
  374. {
  375. if(dwBltFlags & DDBLT_DDFX)
  376. {
  377. if(dwBltDDFX & DDBLTFX_MIRRORUPDOWN)
  378. {
  379. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  380. {
  381. // Fix up the rectangles
  382. iTemp = rMySrc.bottom;
  383. rMySrc.bottom = dwSrcHeight - rMySrc.top;
  384. rMySrc.top = dwSrcHeight - iTemp;
  385. }
  386. bYMirror = FALSE;
  387. }
  388. else
  389. {
  390. bYMirror = TRUE;
  391. }
  392. if(dwBltDDFX & DDBLTFX_MIRRORLEFTRIGHT)
  393. {
  394. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  395. {
  396. // Need to fix up the rectangles
  397. iTemp = rMySrc.right;
  398. rMySrc.right = dwSrcWidth - rMySrc.left;
  399. rMySrc.left = dwSrcWidth - iTemp;
  400. }
  401. bXMirror = FALSE;
  402. }
  403. else
  404. {
  405. bXMirror = TRUE;
  406. }
  407. }
  408. else
  409. {
  410. // Not mirroring, but need to render from the other side.
  411. bXMirror = TRUE;
  412. bYMirror = TRUE;
  413. }
  414. }
  415. // MAGIC_NUMBER_2D can be anything, but it needs to be at least as
  416. // big as the widest texture, but not too big or you'll lose fractional
  417. // precision. Valid range for a P3 is 0->11
  418. ASSERTDD ( iSrcWidth <= ( 1 << MAGIC_NUMBER_2D ),
  419. "_DD_P3BltStretchSrcChDstCh: MAGIC_NUMBER_2D is too small" );
  420. ASSERTDD ( iSrcHeight <= ( 1 << MAGIC_NUMBER_2D ),
  421. "_DD_P3BltStretchSrcChDstCh: MAGIC_NUMBER_2D is too small" );
  422. ASSERTDD ( ( iSrcWidth > 0 ) && ( iSrcHeight > 0 ) &&
  423. ( iDstWidth > 0 ) && ( iDstHeight > 0 ),
  424. "_DD_P3BltStretchSrcChDstCh: width or height negative" );
  425. if ( bFiltering )
  426. {
  427. // This must be an unsigned divide, because we need the top bit.
  428. iXScale = ( ( ( (unsigned)iSrcWidth ) << (32-MAGIC_NUMBER_2D) ) /
  429. (unsigned)( iDstWidth ) );
  430. iYScale = ( ( ( (unsigned)iSrcHeight ) << (32-MAGIC_NUMBER_2D) ) /
  431. (unsigned)( iDstHeight ) );
  432. }
  433. else
  434. {
  435. // This must be an unsigned divide, because we need the top bit.
  436. iXScale = ( ( (unsigned)iSrcWidth << (32-MAGIC_NUMBER_2D)) /
  437. (unsigned)( iDstWidth ) );
  438. iYScale = ( ( (unsigned)iSrcHeight << (32-MAGIC_NUMBER_2D)) /
  439. (unsigned)( iDstHeight) );
  440. }
  441. if (bXMirror)
  442. {
  443. texSStart = ( rMySrc.right - 1 ) << (32-MAGIC_NUMBER_2D);
  444. iXScale = -iXScale;
  445. }
  446. else
  447. {
  448. texSStart = rMySrc.left << (32-MAGIC_NUMBER_2D);
  449. }
  450. if (bYMirror)
  451. {
  452. texTStart = ( rMySrc.bottom - 1 ) << (32-MAGIC_NUMBER_2D);
  453. iYScale = -iYScale;
  454. }
  455. else
  456. {
  457. texTStart = rMySrc.top << (32-MAGIC_NUMBER_2D);
  458. }
  459. // Move pixel centres to 0.5, 0.5.
  460. if ( bFiltering )
  461. {
  462. texSStart -= 1 << (31-MAGIC_NUMBER_2D);
  463. texTStart -= 1 << (31-MAGIC_NUMBER_2D);
  464. }
  465. DISPDBG((DBGLVL, "Blt from (%d, %d) to (%d,%d) (%d, %d)",
  466. rMySrc.left, rMySrc.top,
  467. rMyDest.left, rMyDest.top,
  468. rMyDest.right, rMyDest.bottom));
  469. P3_DMA_GET_BUFFER_ENTRIES(24);
  470. SEND_P3_DATA(PixelSize, (2 - dwDestPixelSize ));
  471. // Vape the cache.
  472. P3RX_INVALIDATECACHE(__PERMEDIA_ENABLE, __PERMEDIA_ENABLE);
  473. // The write buffer is the destination for the pixels
  474. SEND_P3_DATA(FBWriteBufferAddr0, ulDestOffsetFromMemBase);
  475. SEND_P3_DATA(FBWriteBufferWidth0, dwDestPixelPitch);
  476. SEND_P3_DATA(FBWriteBufferOffset0, 0);
  477. SEND_P3_DATA(PixelSize, (2 - dwDestPixelSize));
  478. SEND_P3_DATA(RectanglePosition, P3RX_RECTANGLEPOSITION_X( rMyDest.left )
  479. | P3RX_RECTANGLEPOSITION_Y( rMyDest.top ));
  480. renderData = P3RX_RENDER2D_WIDTH(( rMyDest.right - rMyDest.left ) & 0xfff )
  481. | P3RX_RENDER2D_FBREADSOURCEENABLE( __PERMEDIA_ENABLE )
  482. | P3RX_RENDER2D_HEIGHT ( 0 )
  483. | P3RX_RENDER2D_INCREASINGX( __PERMEDIA_ENABLE )
  484. | P3RX_RENDER2D_INCREASINGY( __PERMEDIA_ENABLE )
  485. | P3RX_RENDER2D_TEXTUREENABLE( __PERMEDIA_ENABLE );
  486. SEND_P3_DATA(Render2D, renderData);
  487. // This is the alpha blending unit.
  488. // AlphaBlendxxxMode are set up by the context code.
  489. ASSERTDD ( pFormatDest->DitherFormat >= 0,
  490. "_DD_P3BltStretchSrcChDstCh: Destination format illegal" );
  491. // The colour format, order and conversion fields are used by the
  492. // chroma keying, even though this register is disabled.
  493. SEND_P3_DATA(AlphaBlendColorMode,
  494. P3RX_ALPHABLENDCOLORMODE_ENABLE ( __PERMEDIA_DISABLE )
  495. | P3RX_ALPHABLENDCOLORMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  496. | P3RX_ALPHABLENDCOLORMODE_COLORORDER ( COLOR_MODE )
  497. | P3RX_ALPHABLENDCOLORMODE_COLORCONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  498. );
  499. SEND_P3_DATA(AlphaBlendAlphaMode,
  500. P3RX_ALPHABLENDALPHAMODE_ENABLE ( __PERMEDIA_DISABLE )
  501. | P3RX_ALPHABLENDALPHAMODE_NOALPHABUFFER( __PERMEDIA_DISABLE )
  502. | P3RX_ALPHABLENDALPHAMODE_ALPHATYPE ( P3RX_ALPHABLENDMODE_ALPHATYPE_OGL )
  503. | P3RX_ALPHABLENDALPHAMODE_ALPHACONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  504. );
  505. P3_DMA_COMMIT_BUFFER();
  506. P3_DMA_GET_BUFFER_ENTRIES(26);
  507. // If there is only one chromakey needed, use the proper chromakey
  508. // This is mainly because the alphamap version doesn't work yet.
  509. if ( bDstKey )
  510. {
  511. // Dest keying.
  512. // The conventional chroma test is set up to key off the dest - the framebuffer.
  513. SEND_P3_DATA(ChromaTestMode,
  514. P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_ENABLE) |
  515. P3RX_CHROMATESTMODE_SOURCE(P3RX_CHROMATESTMODE_SOURCE_FBDATA) |
  516. P3RX_CHROMATESTMODE_PASSACTION(P3RX_CHROMATESTMODE_ACTION_PASS) |
  517. P3RX_CHROMATESTMODE_FAILACTION(P3RX_CHROMATESTMODE_ACTION_REJECT)
  518. );
  519. SEND_P3_DATA(ChromaLower, BltDestColorKey.dwColorSpaceLowValue);
  520. SEND_P3_DATA(ChromaUpper, BltDestColorKey.dwColorSpaceHighValue);
  521. // The source buffer is the source for the destination color key
  522. SEND_P3_DATA(FBSourceReadBufferAddr, ulDestOffsetFromMemBase);
  523. SEND_P3_DATA(FBSourceReadBufferWidth, dwDestPixelPitch);
  524. SEND_P3_DATA(FBSourceReadBufferOffset, 0);
  525. // Enable source reads to get the colorkey color
  526. SEND_P3_DATA(FBSourceReadMode,
  527. P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE) |
  528. P3RX_FBSOURCEREAD_LAYOUT(dwDestPatchMode)
  529. );
  530. }
  531. else
  532. {
  533. // Don't need source reads - the source data comes from the texturemap
  534. SEND_P3_DATA(FBSourceReadMode,
  535. P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_DISABLE));
  536. if ( bSrcKey )
  537. {
  538. DWORD dwLowerSrcBound;
  539. DWORD dwUpperSrcBound;
  540. // Source keying, no dest keying.
  541. // The conventional chroma test is set up to key off the source.
  542. // Note we are keying off the input from the texture here, so we use the INPUTCOLOR as the chroma test
  543. // source
  544. SEND_P3_DATA(ChromaTestMode,
  545. P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_ENABLE) |
  546. P3RX_CHROMATESTMODE_SOURCE(P3RX_CHROMATESTMODE_SOURCE_INPUTCOLOR) |
  547. P3RX_CHROMATESTMODE_PASSACTION(P3RX_CHROMATESTMODE_ACTION_REJECT) |
  548. P3RX_CHROMATESTMODE_FAILACTION(P3RX_CHROMATESTMODE_ACTION_PASS)
  549. );
  550. if ( b8to8blit )
  551. {
  552. // No conversion, just use the index value in the R channel.
  553. dwLowerSrcBound = BltSrcColorKey.dwColorSpaceLowValue & 0x000000ff;
  554. dwUpperSrcBound = BltSrcColorKey.dwColorSpaceHighValue | 0xffffff00;
  555. }
  556. else
  557. {
  558. // Don't scale, do a shift instead.
  559. Get8888ScaledChroma(pThisDisplay,
  560. dwSrcFlags,
  561. pSrcDDPF,
  562. BltSrcColorKey.dwColorSpaceLowValue,
  563. BltSrcColorKey.dwColorSpaceHighValue,
  564. &dwLowerSrcBound,
  565. &dwUpperSrcBound,
  566. NULL, // NULL palette
  567. FALSE,
  568. TRUE);
  569. }
  570. DISPDBG((DBGLVL,"P3 Src Chroma: Upper = 0x%08x, Lower = 0x%08x",
  571. BltSrcColorKey.dwColorSpaceLowValue,
  572. BltSrcColorKey.dwColorSpaceHighValue));
  573. DISPDBG((DBGLVL,"P3 Src Chroma(after): "
  574. "Upper = 0x%08x, Lower = 0x%08x",
  575. dwUpperSrcBound,
  576. dwLowerSrcBound));
  577. SEND_P3_DATA(ChromaLower, dwLowerSrcBound);
  578. SEND_P3_DATA(ChromaUpper, dwUpperSrcBound);
  579. }
  580. else if ( !bSrcKey && !bDstKey )
  581. {
  582. // No chroma keying at all.
  583. SEND_P3_DATA(ChromaTestMode,
  584. P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_DISABLE ) );
  585. }
  586. }
  587. if ( bDstKey && bSrcKey )
  588. {
  589. DWORD dwLowerSrcBound;
  590. DWORD dwUpperSrcBound;
  591. if ( b8to8blit )
  592. {
  593. DISPDBG((ERRLVL,"Er... don't know what to do in this situation."));
  594. }
  595. // Enable source reads to get the colorkey color during dest colorkeys
  596. SEND_P3_DATA(FBSourceReadMode,
  597. P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE) |
  598. P3RX_FBSOURCEREAD_LAYOUT(dwDestPatchMode)
  599. );
  600. // Don't scale, do a shift instead.
  601. Get8888ZeroExtendedChroma(pThisDisplay,
  602. dwSrcFlags,
  603. pSrcDDPF,
  604. BltSrcColorKey.dwColorSpaceLowValue,
  605. BltSrcColorKey.dwColorSpaceHighValue,
  606. &dwLowerSrcBound,
  607. &dwUpperSrcBound);
  608. // If both colourkeys are needed, the source keying is done by counting
  609. // chroma test fails in the texture filter unit.
  610. SEND_P3_DATA(TextureChromaLower0, dwLowerSrcBound);
  611. SEND_P3_DATA(TextureChromaUpper0, dwUpperSrcBound);
  612. SEND_P3_DATA(TextureChromaLower1, dwLowerSrcBound);
  613. SEND_P3_DATA(TextureChromaUpper1, dwUpperSrcBound);
  614. SEND_P3_DATA(TextureFilterMode,
  615. P3RX_TEXFILTERMODE_ENABLE ( __PERMEDIA_ENABLE )
  616. | P3RX_TEXFILTERMODE_FORMATBOTH ( sfdfTextureFilterModeFormat )
  617. | P3RX_TEXFILTERMODE_COLORORDERBOTH ( COLOR_MODE )
  618. | P3RX_TEXFILTERMODE_ALPHAMAPENABLEBOTH ( __PERMEDIA_ENABLE )
  619. | P3RX_TEXFILTERMODE_ALPHAMAPSENSEBOTH ( P3RX_ALPHAMAPSENSE_INRANGE )
  620. | P3RX_TEXFILTERMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  621. | P3RX_TEXFILTERMODE_SHIFTBOTH ( __PERMEDIA_ENABLE )
  622. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERING ( __PERMEDIA_ENABLE )
  623. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT0 ( bFiltering ? 3 : 0 )
  624. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT1 ( 4 )
  625. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT01 ( 8 )
  626. );
  627. }
  628. else
  629. {
  630. SEND_P3_DATA(TextureFilterMode,
  631. P3RX_TEXFILTERMODE_ENABLE ( __PERMEDIA_ENABLE )
  632. | P3RX_TEXFILTERMODE_FORMATBOTH ( sfdfTextureFilterModeFormat )
  633. | P3RX_TEXFILTERMODE_COLORORDERBOTH ( iTextureFilterModeColorOrder )
  634. | P3RX_TEXFILTERMODE_ALPHAMAPENABLEBOTH ( __PERMEDIA_DISABLE )
  635. | P3RX_TEXFILTERMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  636. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERING ( __PERMEDIA_DISABLE )
  637. | P3RX_TEXFILTERMODE_FORCEALPHATOONEBOTH ( __PERMEDIA_DISABLE )
  638. | P3RX_TEXFILTERMODE_SHIFTBOTH ( __PERMEDIA_ENABLE )
  639. );
  640. // And now the alpha test (alpha test unit)
  641. SEND_P3_DATA ( AlphaTestMode, P3RX_ALPHATESTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  642. }
  643. P3_DMA_COMMIT_BUFFER();
  644. P3_DMA_GET_BUFFER_ENTRIES(18);
  645. SEND_P3_DATA ( AntialiasMode, P3RX_ANTIALIASMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  646. // Texture coordinate unit.
  647. SEND_P3_DATA(TextureCoordMode,
  648. P3RX_TEXCOORDMODE_ENABLE ( __PERMEDIA_ENABLE )
  649. | P3RX_TEXCOORDMODE_WRAPS ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  650. | P3RX_TEXCOORDMODE_WRAPT ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  651. | P3RX_TEXCOORDMODE_OPERATION ( P3RX_TEXCOORDMODE_OPERATION_2D )
  652. | P3RX_TEXCOORDMODE_INHIBITDDAINIT ( __PERMEDIA_DISABLE )
  653. | P3RX_TEXCOORDMODE_ENABLELOD ( __PERMEDIA_DISABLE )
  654. | P3RX_TEXCOORDMODE_ENABLEDY ( __PERMEDIA_DISABLE )
  655. | P3RX_TEXCOORDMODE_WIDTH ( log2 ( dwDestWidth ) )
  656. | P3RX_TEXCOORDMODE_HEIGHT ( log2 ( dwDestHeight ) )
  657. | P3RX_TEXCOORDMODE_TEXTUREMAPTYPE ( P3RX_TEXCOORDMODE_TEXTUREMAPTYPE_2D )
  658. | P3RX_TEXCOORDMODE_WRAPS1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  659. | P3RX_TEXCOORDMODE_WRAPT1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  660. );
  661. SEND_P3_DATA(SStart, texSStart);
  662. SEND_P3_DATA(TStart, texTStart);
  663. SEND_P3_DATA(dSdx, iXScale);
  664. SEND_P3_DATA(dSdyDom, 0);
  665. SEND_P3_DATA(dTdx, 0);
  666. SEND_P3_DATA(dTdyDom, iYScale);
  667. SEND_P3_DATA(TextureBaseAddr0, ulSrcOffsetFromMemBase);
  668. P3_DMA_COMMIT_BUFFER();
  669. P3_DMA_GET_BUFFER_ENTRIES(32);
  670. if ( bYUVMode )
  671. {
  672. // Set up the YUV unit.
  673. SEND_P3_DATA ( YUVMode, P3RX_YUVMODE_ENABLE ( __PERMEDIA_ENABLE ) );
  674. iTextureType = P3RX_TEXREADMODE_TEXTURETYPE_VYUY422;
  675. iPixelSize = P3RX_TEXREADMODE_TEXELSIZE_16;
  676. // The idea here is to do ((colorcomp - 16) * 1.14), but in YUV space
  677. // because the YUV unit comes after the texture composite unit.
  678. SEND_P3_DATA(TextureCompositeMode,
  679. P3RX_TEXCOMPMODE_ENABLE ( __PERMEDIA_ENABLE ));
  680. SEND_P3_DATA(TextureCompositeColorMode0,
  681. P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  682. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_T0C)
  683. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  684. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FC)
  685. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  686. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  687. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  688. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_SUBTRACT_AB)
  689. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_ONE));
  690. SEND_P3_DATA(TextureCompositeAlphaMode0,
  691. P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  692. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_T0A)
  693. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  694. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FA)
  695. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  696. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  697. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  698. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_SUBTRACT_AB)
  699. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_ONE));
  700. // This subtracts 16 from Y
  701. SEND_P3_DATA(TextureCompositeFactor0, ((0 << 24) |
  702. (0x0 << 16)|
  703. (0x0 << 8) |
  704. (0x10) ));
  705. // This multiplies the channels by 0.57.
  706. SEND_P3_DATA(TextureCompositeFactor1, ((0x80 << 24) |
  707. (0x80 << 16) |
  708. (0x80 << 8) |
  709. (0x91) ));
  710. SEND_P3_DATA(TextureCompositeColorMode1,
  711. P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  712. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_OC)
  713. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  714. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FC)
  715. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  716. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  717. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  718. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_MODULATE_AB)
  719. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_TWO));
  720. SEND_P3_DATA(TextureCompositeAlphaMode1,
  721. P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  722. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_OC)
  723. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  724. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FA)
  725. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  726. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  727. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  728. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_MODULATE_AB)
  729. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_TWO));
  730. }
  731. else
  732. {
  733. iTextureType = P3RX_TEXREADMODE_TEXTURETYPE_NORMAL;
  734. iPixelSize = dwSrcPixelSize;
  735. // Disable the composite units.
  736. SEND_P3_DATA(TextureCompositeMode,
  737. P3RX_TEXCOMPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  738. }
  739. // Pass through the texel.
  740. SEND_P3_DATA(TextureApplicationMode,
  741. P3RX_TEXAPPMODE_ENABLE ( __PERMEDIA_ENABLE )
  742. | P3RX_TEXAPPMODE_BOTHA ( P3RX_TEXAPP_A_CC )
  743. | P3RX_TEXAPPMODE_BOTHB ( P3RX_TEXAPP_B_TC )
  744. | P3RX_TEXAPPMODE_BOTHI ( P3RX_TEXAPP_I_CA )
  745. | P3RX_TEXAPPMODE_BOTHINVI ( __PERMEDIA_DISABLE )
  746. | P3RX_TEXAPPMODE_BOTHOP ( P3RX_TEXAPP_OPERATION_PASS_B )
  747. | P3RX_TEXAPPMODE_KDENABLE ( __PERMEDIA_DISABLE )
  748. | P3RX_TEXAPPMODE_KSENABLE ( __PERMEDIA_DISABLE )
  749. | P3RX_TEXAPPMODE_MOTIONCOMPENABLE ( __PERMEDIA_DISABLE )
  750. );
  751. TR0 = P3RX_TEXREADMODE_ENABLE ( __PERMEDIA_ENABLE )
  752. | P3RX_TEXREADMODE_WIDTH ( 0 )
  753. | P3RX_TEXREADMODE_HEIGHT ( 0 )
  754. | P3RX_TEXREADMODE_TEXELSIZE ( iPixelSize )
  755. | P3RX_TEXREADMODE_TEXTURE3D ( __PERMEDIA_DISABLE )
  756. | P3RX_TEXREADMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  757. | P3RX_TEXREADMODE_MAPBASELEVEL ( 0 )
  758. | P3RX_TEXREADMODE_MAPMAXLEVEL ( 0 )
  759. | P3RX_TEXREADMODE_LOGICALTEXTURE ( 0 )
  760. | P3RX_TEXREADMODE_ORIGIN ( P3RX_TEXREADMODE_ORIGIN_TOPLEFT )
  761. | P3RX_TEXREADMODE_TEXTURETYPE ( iTextureType )
  762. | P3RX_TEXREADMODE_BYTESWAP ( P3RX_TEXREADMODE_BYTESWAP_NONE )
  763. | P3RX_TEXREADMODE_MIRROR ( __PERMEDIA_DISABLE )
  764. | P3RX_TEXREADMODE_INVERT ( __PERMEDIA_DISABLE )
  765. | P3RX_TEXREADMODE_OPAQUESPAN ( __PERMEDIA_DISABLE )
  766. ;
  767. SEND_P3_DATA(TextureReadMode0, TR0);
  768. SEND_P3_DATA(TextureReadMode1, TR0);
  769. SEND_P3_DATA(TextureMapWidth0,
  770. P3RX_TEXMAPWIDTH_WIDTH(dwSrcPixelPitch) |
  771. P3RX_TEXMAPWIDTH_LAYOUT(dwSrcPatchMode) |
  772. P3RX_TEXMAPWIDTH_HOSTTEXTURE(bIsSourceAGP));
  773. SEND_P3_DATA(TextureCacheReplacementMode,
  774. P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST0 ( __PERMEDIA_DISABLE )
  775. | P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST1 ( __PERMEDIA_DISABLE )
  776. | P3RX_TEXCACHEREPLACEMODE_SHOWCACHEINFO ( __PERMEDIA_DISABLE )
  777. );
  778. SEND_P3_DATA(TextureMapSize, 0 );
  779. if ( bDisableLUT )
  780. {
  781. SEND_P3_DATA(LUTMode, P3RX_LUTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  782. }
  783. if ( bFiltering )
  784. {
  785. // Texture index unit
  786. SEND_P3_DATA(TextureIndexMode0,
  787. P3RX_TEXINDEXMODE_ENABLE ( __PERMEDIA_ENABLE )
  788. | P3RX_TEXINDEXMODE_WIDTH ( MAGIC_NUMBER_2D )
  789. | P3RX_TEXINDEXMODE_HEIGHT ( MAGIC_NUMBER_2D )
  790. | P3RX_TEXINDEXMODE_BORDER ( __PERMEDIA_DISABLE )
  791. | P3RX_TEXINDEXMODE_WRAPU ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  792. | P3RX_TEXINDEXMODE_WRAPV ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  793. | P3RX_TEXINDEXMODE_MAPTYPE ( P3RX_TEXINDEXMODE_MAPTYPE_2D )
  794. | P3RX_TEXINDEXMODE_MAGFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  795. | P3RX_TEXINDEXMODE_MINFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  796. | P3RX_TEXINDEXMODE_TEX3DENABLE ( __PERMEDIA_DISABLE )
  797. | P3RX_TEXINDEXMODE_MIPMAPENABLE ( __PERMEDIA_DISABLE )
  798. | P3RX_TEXINDEXMODE_NEARESTBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  799. | P3RX_TEXINDEXMODE_LINEARBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  800. | P3RX_TEXINDEXMODE_SOURCETEXELENABLE ( __PERMEDIA_DISABLE )
  801. );
  802. }
  803. else
  804. {
  805. // Texture index unit
  806. SEND_P3_DATA(TextureIndexMode0,
  807. P3RX_TEXINDEXMODE_ENABLE ( __PERMEDIA_ENABLE )
  808. | P3RX_TEXINDEXMODE_WIDTH ( MAGIC_NUMBER_2D )
  809. | P3RX_TEXINDEXMODE_HEIGHT ( MAGIC_NUMBER_2D )
  810. | P3RX_TEXINDEXMODE_BORDER ( __PERMEDIA_DISABLE )
  811. | P3RX_TEXINDEXMODE_WRAPU ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  812. | P3RX_TEXINDEXMODE_WRAPV ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  813. | P3RX_TEXINDEXMODE_MAPTYPE ( P3RX_TEXINDEXMODE_MAPTYPE_2D )
  814. | P3RX_TEXINDEXMODE_MAGFILTER ( P3RX_TEXINDEXMODE_FILTER_NEAREST )
  815. | P3RX_TEXINDEXMODE_MINFILTER ( P3RX_TEXINDEXMODE_FILTER_NEAREST )
  816. | P3RX_TEXINDEXMODE_TEX3DENABLE ( __PERMEDIA_DISABLE )
  817. | P3RX_TEXINDEXMODE_MIPMAPENABLE ( __PERMEDIA_DISABLE )
  818. | P3RX_TEXINDEXMODE_NEARESTBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  819. | P3RX_TEXINDEXMODE_LINEARBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  820. | P3RX_TEXINDEXMODE_SOURCETEXELENABLE ( __PERMEDIA_DISABLE )
  821. );
  822. }
  823. ASSERTDD ( pFormatDest->DitherFormat >= 0,
  824. "_DD_P3BltStretchSrcChDstCh: Destination format illegal" );
  825. P3_DMA_COMMIT_BUFFER();
  826. P3_DMA_GET_BUFFER_ENTRIES(10);
  827. if ( bFiltering )
  828. {
  829. // Filtering, so dither.
  830. SEND_P3_DATA(DitherMode,
  831. P3RX_DITHERMODE_ENABLE ( __PERMEDIA_ENABLE )
  832. | P3RX_DITHERMODE_DITHERENABLE ( __PERMEDIA_ENABLE )
  833. | P3RX_DITHERMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  834. | P3RX_DITHERMODE_XOFFSET ( 0 )
  835. | P3RX_DITHERMODE_YOFFSET ( 0 )
  836. | P3RX_DITHERMODE_COLORORDER ( COLOR_MODE )
  837. | P3RX_DITHERMODE_ALPHADITHER ( P3RX_DITHERMODE_ALPHADITHER_DITHER )
  838. | P3RX_DITHERMODE_ROUNDINGMODE ( P3RX_DITHERMODE_ROUNDINGMODE_TRUNCATE )
  839. );
  840. }
  841. else
  842. {
  843. // No filter, no dither (though it doesn't actually matter).
  844. SEND_P3_DATA(DitherMode,
  845. P3RX_DITHERMODE_ENABLE ( __PERMEDIA_ENABLE )
  846. | P3RX_DITHERMODE_DITHERENABLE ( __PERMEDIA_DISABLE )
  847. | P3RX_DITHERMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  848. | P3RX_DITHERMODE_XOFFSET ( 0 )
  849. | P3RX_DITHERMODE_YOFFSET ( 0 )
  850. | P3RX_DITHERMODE_COLORORDER ( COLOR_MODE )
  851. | P3RX_DITHERMODE_ALPHADITHER ( P3RX_DITHERMODE_ALPHADITHER_DITHER )
  852. | P3RX_DITHERMODE_ROUNDINGMODE ( P3RX_DITHERMODE_ROUNDINGMODE_TRUNCATE )
  853. );
  854. }
  855. SEND_P3_DATA(LogicalOpMode,
  856. P3RX_LOGICALOPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  857. SEND_P3_DATA(PixelSize, (2 - dwDestPixelSize));
  858. SEND_P3_DATA(FBWriteMode,
  859. P3RX_FBWRITEMODE_WRITEENABLE(__PERMEDIA_ENABLE) |
  860. P3RX_FBWRITEMODE_LAYOUT0(dwDestPatchMode)
  861. );
  862. WAIT_FIFO(22);
  863. P3_ENSURE_DX_SPACE(22);
  864. SEND_P3_DATA(Count, rMyDest.bottom - rMyDest.top );
  865. SEND_P3_DATA(Render,
  866. P3RX_RENDER_PRIMITIVETYPE ( P3RX_RENDER_PRIMITIVETYPE_TRAPEZOID )
  867. | P3RX_RENDER_TEXTUREENABLE ( __PERMEDIA_ENABLE )
  868. | P3RX_RENDER_FOGENABLE ( __PERMEDIA_DISABLE )
  869. | P3RX_RENDER_FBSOURCEREADENABLE( (bDstKey ? __PERMEDIA_ENABLE : __PERMEDIA_DISABLE))
  870. );
  871. // Disable all the things I switched on.
  872. SEND_P3_DATA(ChromaTestMode, __PERMEDIA_DISABLE );
  873. SEND_P3_DATA(AlphaBlendColorMode, __PERMEDIA_DISABLE );
  874. SEND_P3_DATA(AlphaBlendAlphaMode, __PERMEDIA_DISABLE );
  875. SEND_P3_DATA(TextureFilterMode, __PERMEDIA_DISABLE );
  876. SEND_P3_DATA(AlphaTestMode, __PERMEDIA_DISABLE );
  877. SEND_P3_DATA(AntialiasMode, __PERMEDIA_DISABLE );
  878. SEND_P3_DATA(TextureCoordMode, __PERMEDIA_DISABLE );
  879. SEND_P3_DATA(TextureReadMode0, __PERMEDIA_DISABLE );
  880. SEND_P3_DATA(TextureIndexMode0, __PERMEDIA_DISABLE );
  881. P3_ENSURE_DX_SPACE(20);
  882. WAIT_FIFO(20);
  883. SEND_P3_DATA(TextureCompositeMode, __PERMEDIA_DISABLE );
  884. SEND_P3_DATA(TextureCompositeColorMode0, __PERMEDIA_DISABLE);
  885. SEND_P3_DATA(TextureCompositeAlphaMode0, __PERMEDIA_DISABLE);
  886. SEND_P3_DATA(TextureCompositeColorMode1, __PERMEDIA_DISABLE);
  887. SEND_P3_DATA(TextureCompositeAlphaMode1, __PERMEDIA_DISABLE);
  888. SEND_P3_DATA(TextureApplicationMode, __PERMEDIA_DISABLE );
  889. SEND_P3_DATA(DitherMode, __PERMEDIA_DISABLE );
  890. SEND_P3_DATA(FBSourceReadMode, __PERMEDIA_DISABLE);
  891. SEND_P3_DATA(LogicalOpMode, __PERMEDIA_DISABLE );
  892. SEND_P3_DATA(YUVMode, __PERMEDIA_DISABLE );
  893. P3_DMA_COMMIT_BUFFER();
  894. } // _DD_P3BltStretchSrcChDstCh
  895. //-----------------------------------------------------------------------------
  896. //
  897. // _DD_P3BltStretchSrcChDstCh_DD
  898. //
  899. // Stretch blit with source and destination chroma keying
  900. // This version takes as parameters DDraw objects
  901. //
  902. //-----------------------------------------------------------------------------
  903. VOID
  904. _DD_P3BltStretchSrcChDstCh_DD(
  905. P3_THUNKEDDATA* pThisDisplay,
  906. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  907. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  908. P3_SURF_FORMAT* pFormatSource,
  909. P3_SURF_FORMAT* pFormatDest,
  910. LPDDHAL_BLTDATA lpBlt,
  911. RECTL *rSrc,
  912. RECTL *rDest)
  913. {
  914. _DD_P3BltStretchSrcChDstCh(pThisDisplay,
  915. // pSource data elements
  916. pSource->lpGbl->fpVidMem,
  917. pFormatSource,
  918. DDSurf_GetChipPixelSize(pSource),
  919. (int)pSource->lpGbl->wWidth,
  920. (int)pSource->lpGbl->wHeight,
  921. DDSurf_GetPixelPitch(pSource),
  922. P3RX_LAYOUT_LINEAR,
  923. DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pSource),
  924. pSource->dwFlags,
  925. &pSource->lpGbl->ddpfSurface,
  926. DDSurf_IsAGP(pSource),
  927. // pDest data elements
  928. pDest->lpGbl->fpVidMem,
  929. pFormatDest,
  930. DDSurf_GetChipPixelSize(pDest),
  931. (int)pDest->lpGbl->wWidth,
  932. (int)pDest->lpGbl->wHeight,
  933. DDSurf_GetPixelPitch(pDest),
  934. P3RX_LAYOUT_LINEAR,
  935. DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pDest),
  936. // Others
  937. lpBlt->dwFlags,
  938. lpBlt->bltFX.dwDDFX,
  939. lpBlt->bltFX.ddckSrcColorkey,
  940. lpBlt->bltFX.ddckDestColorkey,
  941. rSrc,
  942. rDest);
  943. } // _DD_P3BltStretchSrcChDstCh_DD
  944. //-----------------------------------------------------------------------------
  945. //
  946. // __P3BltDestOveride
  947. //
  948. //-----------------------------------------------------------------------------
  949. VOID
  950. __P3BltDestOveride(
  951. P3_THUNKEDDATA* pThisDisplay,
  952. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  953. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  954. P3_SURF_FORMAT* pFormatSource,
  955. P3_SURF_FORMAT* pFormatDest,
  956. RECTL *rSrc,
  957. RECTL *rDest,
  958. DWORD logicop,
  959. DWORD dwDestPointer)
  960. {
  961. DWORD renderData;
  962. LONG rSrctop, rSrcleft, rDesttop, rDestleft;
  963. DWORD dwSourceOffset;
  964. BOOL bBlocking;
  965. DWORD dwRenderDirection;
  966. DWORD dwDestPatchMode, dwSourcePatchMode;
  967. P3_DMA_DEFS();
  968. // Beacuse of a bug in RL we sometimes have to fiddle with these values
  969. rSrctop = rSrc->top;
  970. rSrcleft = rSrc->left;
  971. rDesttop = rDest->top;
  972. rDestleft = rDest->left;
  973. // Fix coords origin
  974. if(!_DD_BLT_FixRectlOrigin("__P3BltDestOveride", rSrc, rDest))
  975. {
  976. // Nothing to be blitted
  977. return;
  978. }
  979. // Determine the direction of the blt
  980. dwRenderDirection = _DD_BLT_GetBltDirection(pSource->lpGbl->fpVidMem,
  981. pDest->lpGbl->fpVidMem,
  982. rSrc,
  983. rDest,
  984. &bBlocking);
  985. P3_DMA_GET_BUFFER();
  986. P3_ENSURE_DX_SPACE(30);
  987. WAIT_FIFO(30);
  988. SEND_P3_DATA(PixelSize, (2 - DDSurf_GetChipPixelSize(pDest)));
  989. SEND_P3_DATA(FBWriteBufferAddr0, dwDestPointer);
  990. SEND_P3_DATA(FBWriteBufferWidth0, DDSurf_GetPixelPitch(pDest));
  991. SEND_P3_DATA(FBWriteBufferOffset0, 0);
  992. SEND_P3_DATA(FBSourceReadBufferAddr,
  993. DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pSource));
  994. SEND_P3_DATA(FBSourceReadBufferWidth, DDSurf_GetPixelPitch(pSource));
  995. dwSourceOffset = (( rSrc->top - rDest->top ) << 16 ) |
  996. (( rSrc->left - rDest->left ) & 0xffff );
  997. SEND_P3_DATA(FBSourceReadBufferOffset, dwSourceOffset);
  998. dwDestPatchMode = P3RX_LAYOUT_LINEAR;
  999. dwSourcePatchMode = P3RX_LAYOUT_LINEAR;
  1000. SEND_P3_DATA(FBDestReadMode,
  1001. P3RX_FBDESTREAD_READENABLE(__PERMEDIA_DISABLE));
  1002. SEND_P3_DATA(FBSourceReadMode,
  1003. P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE) |
  1004. P3RX_FBSOURCEREAD_LAYOUT(dwSourcePatchMode) |
  1005. P3RX_FBSOURCEREAD_BLOCKING( bBlocking ));
  1006. SEND_P3_DATA(FBWriteMode,
  1007. P3RX_FBWRITEMODE_WRITEENABLE(__PERMEDIA_ENABLE) |
  1008. P3RX_FBWRITEMODE_LAYOUT0(dwDestPatchMode));
  1009. P3_ENSURE_DX_SPACE(16);
  1010. WAIT_FIFO(16);
  1011. SEND_P3_DATA(RectanglePosition,
  1012. P3RX_RECTANGLEPOSITION_Y(rDest->top) |
  1013. P3RX_RECTANGLEPOSITION_X(rDest->left));
  1014. renderData =
  1015. P3RX_RENDER2D_WIDTH(( rDest->right - rDest->left ) & 0xfff ) |
  1016. P3RX_RENDER2D_HEIGHT(( rDest->bottom - rDest->top ) & 0xfff ) |
  1017. P3RX_RENDER2D_FBREADSOURCEENABLE(__PERMEDIA_ENABLE) |
  1018. P3RX_RENDER2D_SPANOPERATION( P3RX_RENDER2D_SPAN_VARIABLE ) |
  1019. P3RX_RENDER2D_INCREASINGX( dwRenderDirection ) |
  1020. P3RX_RENDER2D_INCREASINGY( dwRenderDirection );
  1021. SEND_P3_DATA(Render2D, renderData);
  1022. // Put back the values if we changed them.
  1023. rSrc->top = rSrctop;
  1024. rSrc->left = rSrcleft;
  1025. rDest->top = rDesttop;
  1026. rDest->left = rDestleft;
  1027. P3_DMA_COMMIT_BUFFER();
  1028. } // __P3BltDestOveride
  1029. //-----------------------------------------------------------------------------
  1030. //
  1031. // __P3BltStretchSrcChDstChSourceOveride
  1032. //
  1033. //-----------------------------------------------------------------------------
  1034. VOID
  1035. __P3BltStretchSrcChDstChSourceOveride(
  1036. P3_THUNKEDDATA* pThisDisplay,
  1037. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  1038. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  1039. P3_SURF_FORMAT* pFormatSource,
  1040. P3_SURF_FORMAT* pFormatDest,
  1041. LPDDHAL_BLTDATA lpBlt,
  1042. RECTL *rSrc,
  1043. RECTL *rDest,
  1044. DWORD dwNewSource
  1045. )
  1046. {
  1047. ULONG renderData;
  1048. RECTL rMySrc, rMyDest;
  1049. int iXScale, iYScale;
  1050. int iSrcWidth, iSrcHeight;
  1051. int iDstWidth, iDstHeight;
  1052. DWORD texSStart, texTStart;
  1053. DWORD dwRenderDirection;
  1054. BOOL bXMirror, bYMirror;
  1055. BOOL bFiltering;
  1056. BOOL bSrcKey, bDstKey;
  1057. BOOL bDisableLUT;
  1058. BOOL bBlocking;
  1059. int iTemp;
  1060. BOOL b8to8blit;
  1061. BOOL bYUVMode;
  1062. DWORD TR0;
  1063. int iTextureType;
  1064. int iPixelSize;
  1065. int iTextureFilterModeColorOrder;
  1066. SurfFilterDeviceFormat sfdfTextureFilterModeFormat;
  1067. P3_DMA_DEFS();
  1068. bDisableLUT = FALSE;
  1069. // Make local copies that we can mangle.
  1070. rMySrc = *rSrc;
  1071. rMyDest = *rDest;
  1072. // Fix coords origin
  1073. if(!_DD_BLT_FixRectlOrigin("__P3BltStretchSrcChDstChSourceOveride",
  1074. &rMySrc, &rMyDest))
  1075. {
  1076. // Nothing to be blitted
  1077. return;
  1078. }
  1079. iSrcWidth = rMySrc.right - rMySrc.left;
  1080. iSrcHeight = rMySrc.bottom - rMySrc.top;
  1081. iDstWidth = rMyDest.right - rMyDest.left;
  1082. iDstHeight = rMyDest.bottom - rMyDest.top;
  1083. if (pFormatSource->DeviceFormat == SURF_YUV422)
  1084. {
  1085. bYUVMode = TRUE;
  1086. // Always use ABGR for YUV;
  1087. iTextureFilterModeColorOrder = 0;
  1088. }
  1089. else
  1090. {
  1091. bYUVMode = FALSE;
  1092. iTextureFilterModeColorOrder = COLOR_MODE;
  1093. }
  1094. sfdfTextureFilterModeFormat = pFormatSource->FilterFormat;
  1095. if ( ( pFormatDest->DeviceFormat == SURF_CI8 ) && ( pFormatSource->DeviceFormat == SURF_CI8 ) )
  1096. {
  1097. // An 8bit->8bit blit. This is treated specially, since no LUT translation is involved.
  1098. // Fake this up in a wacky way to stop the LUT
  1099. // getting it's hands on it.
  1100. sfdfTextureFilterModeFormat = SURF_FILTER_L8;
  1101. bDisableLUT = TRUE;
  1102. b8to8blit = TRUE;
  1103. }
  1104. else
  1105. {
  1106. b8to8blit = FALSE;
  1107. }
  1108. // Let's see if anyone uses this flag - might be good to get it working
  1109. // now that we know what it means (use bilinear filtering instead of point).
  1110. ASSERTDD ( ( lpBlt->dwFlags & DDBLTFX_ARITHSTRETCHY ) == 0, "** _DD_P3BltStretchSrcChDstCh: DDBLTFX_ARITHSTRETCHY used - please tell TomF" );
  1111. // Is this a stretch blit?
  1112. if (((iSrcWidth != iDstWidth) ||
  1113. (iSrcHeight != iDstHeight)) &&
  1114. ((pFormatSource->DeviceFormat == SURF_YUV422)))
  1115. {
  1116. bFiltering = TRUE;
  1117. }
  1118. else
  1119. {
  1120. bFiltering = FALSE;
  1121. }
  1122. if ( ( lpBlt->dwFlags & DDBLT_KEYSRCOVERRIDE ) != 0 )
  1123. {
  1124. bSrcKey = TRUE;
  1125. }
  1126. else
  1127. {
  1128. bSrcKey = FALSE;
  1129. }
  1130. if ( ( lpBlt->dwFlags & DDBLT_KEYDESTOVERRIDE ) != 0 )
  1131. {
  1132. bDstKey = TRUE;
  1133. }
  1134. else
  1135. {
  1136. bDstKey = FALSE;
  1137. }
  1138. // Determine the direction of the blt
  1139. dwRenderDirection = _DD_BLT_GetBltDirection(pSource->lpGbl->fpVidMem,
  1140. pDest->lpGbl->fpVidMem,
  1141. &rMySrc,
  1142. &rMyDest,
  1143. &bBlocking);
  1144. // If we are doing special effects, and we are mirroring,
  1145. // we need to fix up the rectangles and change the sense of
  1146. // the render operation - we need to be carefull with overlapping
  1147. // rectangles
  1148. if (dwRenderDirection)
  1149. {
  1150. if(lpBlt->dwFlags & DDBLT_DDFX)
  1151. {
  1152. if(lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORUPDOWN)
  1153. {
  1154. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  1155. {
  1156. // Need to fix up the rectangles
  1157. iTemp = rMySrc.bottom;
  1158. rMySrc.bottom = pSource->lpGbl->wHeight - rMySrc.top;
  1159. rMySrc.top = pSource->lpGbl->wHeight - iTemp;
  1160. }
  1161. bYMirror = TRUE;
  1162. }
  1163. else
  1164. {
  1165. bYMirror = FALSE;
  1166. }
  1167. if(lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
  1168. {
  1169. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  1170. {
  1171. // Need to fix up the rectangles
  1172. iTemp = rMySrc.right;
  1173. rMySrc.right = pSource->lpGbl->wWidth - rMySrc.left;
  1174. rMySrc.left = pSource->lpGbl->wWidth - iTemp;
  1175. }
  1176. bXMirror = TRUE;
  1177. }
  1178. else
  1179. {
  1180. bXMirror = FALSE;
  1181. }
  1182. }
  1183. else
  1184. {
  1185. bXMirror = FALSE;
  1186. bYMirror = FALSE;
  1187. }
  1188. }
  1189. else
  1190. {
  1191. if(lpBlt->dwFlags & DDBLT_DDFX)
  1192. {
  1193. if(lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORUPDOWN)
  1194. {
  1195. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  1196. {
  1197. // Fix up the rectangles
  1198. iTemp = rMySrc.bottom;
  1199. rMySrc.bottom = pSource->lpGbl->wHeight - rMySrc.top;
  1200. rMySrc.top = pSource->lpGbl->wHeight - iTemp;
  1201. }
  1202. bYMirror = FALSE;
  1203. }
  1204. else
  1205. {
  1206. bYMirror = TRUE;
  1207. }
  1208. if(lpBlt->bltFX.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
  1209. {
  1210. if (pThisDisplay->dwDXVersion < DX6_RUNTIME)
  1211. {
  1212. // Need to fix up the rectangles
  1213. iTemp = rMySrc.right;
  1214. rMySrc.right = pSource->lpGbl->wWidth - rMySrc.left;
  1215. rMySrc.left = pSource->lpGbl->wWidth - iTemp;
  1216. }
  1217. bXMirror = FALSE;
  1218. }
  1219. else
  1220. {
  1221. bXMirror = TRUE;
  1222. }
  1223. }
  1224. else
  1225. {
  1226. // Not mirroring, but need to render from the other side.
  1227. bXMirror = TRUE;
  1228. bYMirror = TRUE;
  1229. }
  1230. }
  1231. // MAGIC_NUMBER_2D can be anything, but it needs to be at least as
  1232. // big as the widest texture, but not too big or you'll lose fractional
  1233. // precision. Valid range for a P3 is 0->11
  1234. ASSERTDD ( iSrcWidth <= ( 1 << MAGIC_NUMBER_2D ), "** _DD_P3BltStretchSrcChDstCh: MAGIC_NUMBER_2D is too small" );
  1235. ASSERTDD ( iSrcHeight <= ( 1 << MAGIC_NUMBER_2D ), "** _DD_P3BltStretchSrcChDstCh: MAGIC_NUMBER_2D is too small" );
  1236. ASSERTDD ( ( iSrcWidth > 0 ) && ( iSrcHeight > 0 ) && ( iDstWidth > 0 ) && ( iDstHeight > 0 ), "** _DD_P3BltStretchSrcChDstCh: width or height negative" );
  1237. if ( bFiltering )
  1238. {
  1239. // This must be an unsigned divide, because we need the top bit.
  1240. iXScale = ( ( ( (unsigned)iSrcWidth ) << (32-MAGIC_NUMBER_2D) ) / (unsigned)( iDstWidth ) );
  1241. iYScale = ( ( ( (unsigned)iSrcHeight ) << (32-MAGIC_NUMBER_2D) ) / (unsigned)( iDstHeight ) );
  1242. }
  1243. else
  1244. {
  1245. // This must be an unsigned divide, because we need the top bit.
  1246. iXScale = ( ( (unsigned)iSrcWidth << (32-MAGIC_NUMBER_2D)) / (unsigned)( iDstWidth ) );
  1247. iYScale = ( ( (unsigned)iSrcHeight << (32-MAGIC_NUMBER_2D)) / (unsigned)( iDstHeight) );
  1248. }
  1249. if (bXMirror)
  1250. {
  1251. texSStart = ( rMySrc.right - 1 ) << (32-MAGIC_NUMBER_2D);
  1252. iXScale = -iXScale;
  1253. }
  1254. else
  1255. {
  1256. texSStart = rMySrc.left << (32-MAGIC_NUMBER_2D);
  1257. }
  1258. if (bYMirror)
  1259. {
  1260. texTStart = ( rMySrc.bottom - 1 ) << (32-MAGIC_NUMBER_2D);
  1261. iYScale = -iYScale;
  1262. }
  1263. else
  1264. {
  1265. texTStart = rMySrc.top << (32-MAGIC_NUMBER_2D);
  1266. }
  1267. // Move pixel centres to 0.5, 0.5.
  1268. if ( bFiltering )
  1269. {
  1270. texSStart -= 1 << (31-MAGIC_NUMBER_2D);
  1271. texTStart -= 1 << (31-MAGIC_NUMBER_2D);
  1272. }
  1273. DISPDBG((DBGLVL, "Blt from (%d, %d) to (%d,%d) (%d, %d)",
  1274. rMySrc.left, rMySrc.top,
  1275. rMyDest.left, rMyDest.top,
  1276. rMyDest.right, rMyDest.bottom));
  1277. P3_DMA_GET_BUFFER_ENTRIES(24);
  1278. SEND_P3_DATA(PixelSize, (2 - DDSurf_GetChipPixelSize(pDest)));
  1279. // Vape the cache.
  1280. P3RX_INVALIDATECACHE(__PERMEDIA_ENABLE, __PERMEDIA_ENABLE);
  1281. // The write buffer is the destination for the pixels
  1282. SEND_P3_DATA(FBWriteBufferAddr0, DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pDest));
  1283. SEND_P3_DATA(FBWriteBufferWidth0, DDSurf_GetPixelPitch(pDest));
  1284. SEND_P3_DATA(FBWriteBufferOffset0, 0);
  1285. SEND_P3_DATA(PixelSize, (2 - DDSurf_GetChipPixelSize(pDest)));
  1286. SEND_P3_DATA(RectanglePosition, P3RX_RECTANGLEPOSITION_X( rMyDest.left )
  1287. | P3RX_RECTANGLEPOSITION_Y( rMyDest.top ));
  1288. renderData = P3RX_RENDER2D_WIDTH(( rMyDest.right - rMyDest.left ) & 0xfff )
  1289. | P3RX_RENDER2D_FBREADSOURCEENABLE( __PERMEDIA_ENABLE )
  1290. | P3RX_RENDER2D_HEIGHT ( 0 )
  1291. | P3RX_RENDER2D_INCREASINGX( __PERMEDIA_ENABLE )
  1292. | P3RX_RENDER2D_INCREASINGY( __PERMEDIA_ENABLE )
  1293. | P3RX_RENDER2D_TEXTUREENABLE( __PERMEDIA_ENABLE );
  1294. SEND_P3_DATA(Render2D, renderData);
  1295. // This is the alpha blending unit.
  1296. // AlphaBlendxxxMode are set up by the context code.
  1297. ASSERTDD ( pFormatDest->DitherFormat >= 0, "** _DD_P3BltStretchSrcChDstCh: Destination format illegal" );
  1298. // The colour format, order and conversion fields are used by the chroma keying,
  1299. // even though this register is disabled.
  1300. SEND_P3_DATA(AlphaBlendColorMode, P3RX_ALPHABLENDCOLORMODE_ENABLE ( __PERMEDIA_DISABLE )
  1301. | P3RX_ALPHABLENDCOLORMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  1302. | P3RX_ALPHABLENDCOLORMODE_COLORORDER ( COLOR_MODE )
  1303. | P3RX_ALPHABLENDCOLORMODE_COLORCONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  1304. );
  1305. SEND_P3_DATA(AlphaBlendAlphaMode, P3RX_ALPHABLENDALPHAMODE_ENABLE ( __PERMEDIA_DISABLE )
  1306. | P3RX_ALPHABLENDALPHAMODE_NOALPHABUFFER( __PERMEDIA_DISABLE )
  1307. | P3RX_ALPHABLENDALPHAMODE_ALPHATYPE ( P3RX_ALPHABLENDMODE_ALPHATYPE_OGL )
  1308. | P3RX_ALPHABLENDALPHAMODE_ALPHACONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  1309. );
  1310. P3_DMA_COMMIT_BUFFER();
  1311. P3_DMA_GET_BUFFER_ENTRIES(30);
  1312. // If there is only one chromakey needed, use the proper chromakey
  1313. // This is mainly because the alphamap version doesn't work yet.
  1314. if ( bDstKey )
  1315. {
  1316. // Dest keying.
  1317. // The conventional chroma test is set up to key off the dest - the framebuffer.
  1318. SEND_P3_DATA(ChromaTestMode, P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_ENABLE) |
  1319. P3RX_CHROMATESTMODE_SOURCE(P3RX_CHROMATESTMODE_SOURCE_FBDATA) |
  1320. P3RX_CHROMATESTMODE_PASSACTION(P3RX_CHROMATESTMODE_ACTION_PASS) |
  1321. P3RX_CHROMATESTMODE_FAILACTION(P3RX_CHROMATESTMODE_ACTION_REJECT)
  1322. );
  1323. SEND_P3_DATA(ChromaLower, lpBlt->bltFX.ddckDestColorkey.dwColorSpaceLowValue);
  1324. SEND_P3_DATA(ChromaUpper, lpBlt->bltFX.ddckDestColorkey.dwColorSpaceHighValue);
  1325. // The source buffer is the source for the destination color key
  1326. SEND_P3_DATA(FBSourceReadBufferAddr, DDSurf_SurfaceOffsetFromMemoryBase(pThisDisplay, pDest));
  1327. SEND_P3_DATA(FBSourceReadBufferWidth, DDSurf_GetPixelPitch(pDest));
  1328. SEND_P3_DATA(FBSourceReadBufferOffset, 0);
  1329. // Enable source reads to get the colorkey color
  1330. SEND_P3_DATA(FBSourceReadMode, P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE) |
  1331. P3RX_FBSOURCEREAD_LAYOUT(P3RX_LAYOUT_LINEAR));
  1332. }
  1333. else
  1334. {
  1335. // Don't need source reads - the source data comes from the texturemap
  1336. SEND_P3_DATA(FBSourceReadMode, P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_DISABLE));
  1337. if ( bSrcKey )
  1338. {
  1339. DWORD dwLowerSrcBound = 0;
  1340. DWORD dwUpperSrcBound = 0;
  1341. // Source keying, no dest keying.
  1342. // The conventional chroma test is set up to key off the source.
  1343. // Note we are keying off the input from the texture here, so we use the INPUTCOLOR as the chroma test
  1344. // source
  1345. SEND_P3_DATA(ChromaTestMode, P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_ENABLE) |
  1346. P3RX_CHROMATESTMODE_SOURCE(P3RX_CHROMATESTMODE_SOURCE_INPUTCOLOR) |
  1347. P3RX_CHROMATESTMODE_PASSACTION(P3RX_CHROMATESTMODE_ACTION_REJECT) |
  1348. P3RX_CHROMATESTMODE_FAILACTION(P3RX_CHROMATESTMODE_ACTION_PASS)
  1349. );
  1350. if ( b8to8blit )
  1351. {
  1352. // No conversion, just use the index value in the R channel.
  1353. dwLowerSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue & 0x000000ff;
  1354. dwUpperSrcBound = lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue | 0xffffff00;
  1355. }
  1356. else
  1357. {
  1358. // Don't scale, do a shift instead.
  1359. Get8888ScaledChroma(pThisDisplay,
  1360. pSource->dwFlags,
  1361. &pSource->lpGbl->ddpfSurface,
  1362. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue,
  1363. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue,
  1364. &dwLowerSrcBound,
  1365. &dwUpperSrcBound,
  1366. NULL, // NULL palette
  1367. FALSE,
  1368. TRUE);
  1369. }
  1370. DISPDBG((DBGLVL,"P3 Src Chroma: Upper = 0x%08x, Lower = 0x%08x",
  1371. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue,
  1372. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue));
  1373. DISPDBG((DBGLVL,"P3 Src Chroma(after): "
  1374. "Upper = 0x%08x, Lower = 0x%08x",
  1375. dwUpperSrcBound,
  1376. dwLowerSrcBound));
  1377. SEND_P3_DATA(ChromaLower, dwLowerSrcBound);
  1378. SEND_P3_DATA(ChromaUpper, dwUpperSrcBound);
  1379. }
  1380. else if ( !bSrcKey && !bDstKey )
  1381. {
  1382. // No chroma keying at all.
  1383. SEND_P3_DATA(ChromaTestMode, P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_DISABLE ) );
  1384. }
  1385. }
  1386. if ( bDstKey && bSrcKey )
  1387. {
  1388. DWORD dwLowerSrcBound;
  1389. DWORD dwUpperSrcBound;
  1390. if ( b8to8blit )
  1391. {
  1392. DISPDBG((ERRLVL,"Er... don't know what to do in this situation."));
  1393. }
  1394. // Enable source reads to get the colorkey color during dest colorkeys
  1395. SEND_P3_DATA(FBSourceReadMode, P3RX_FBSOURCEREAD_READENABLE(__PERMEDIA_ENABLE) |
  1396. P3RX_FBSOURCEREAD_LAYOUT(P3RX_LAYOUT_LINEAR));
  1397. // Don't scale, do a shift instead.
  1398. Get8888ZeroExtendedChroma(pThisDisplay,
  1399. pSource->dwFlags,
  1400. &pSource->lpGbl->ddpfSurface,
  1401. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceLowValue,
  1402. lpBlt->bltFX.ddckSrcColorkey.dwColorSpaceHighValue,
  1403. &dwLowerSrcBound,
  1404. &dwUpperSrcBound);
  1405. // If both colourkeys are needed, the source keying is done by counting
  1406. // chroma test fails in the texture filter unit.
  1407. SEND_P3_DATA(TextureChromaLower0, dwLowerSrcBound);
  1408. SEND_P3_DATA(TextureChromaUpper0, dwUpperSrcBound);
  1409. SEND_P3_DATA(TextureChromaLower1, dwLowerSrcBound);
  1410. SEND_P3_DATA(TextureChromaUpper1, dwUpperSrcBound);
  1411. SEND_P3_DATA(TextureFilterMode, P3RX_TEXFILTERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1412. | P3RX_TEXFILTERMODE_FORMATBOTH ( sfdfTextureFilterModeFormat )
  1413. | P3RX_TEXFILTERMODE_COLORORDERBOTH ( COLOR_MODE )
  1414. | P3RX_TEXFILTERMODE_ALPHAMAPENABLEBOTH ( __PERMEDIA_ENABLE )
  1415. | P3RX_TEXFILTERMODE_ALPHAMAPSENSEBOTH ( P3RX_ALPHAMAPSENSE_INRANGE )
  1416. | P3RX_TEXFILTERMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  1417. | P3RX_TEXFILTERMODE_SHIFTBOTH ( __PERMEDIA_ENABLE )
  1418. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERING ( __PERMEDIA_ENABLE )
  1419. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT0 ( bFiltering ? 3 : 0 )
  1420. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT1 ( 4 )
  1421. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERLIMIT01 ( 8 )
  1422. );
  1423. }
  1424. else
  1425. {
  1426. SEND_P3_DATA(TextureFilterMode, P3RX_TEXFILTERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1427. | P3RX_TEXFILTERMODE_FORMATBOTH ( sfdfTextureFilterModeFormat )
  1428. | P3RX_TEXFILTERMODE_COLORORDERBOTH ( iTextureFilterModeColorOrder )
  1429. | P3RX_TEXFILTERMODE_ALPHAMAPENABLEBOTH ( __PERMEDIA_DISABLE )
  1430. | P3RX_TEXFILTERMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  1431. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERING ( __PERMEDIA_DISABLE )
  1432. | P3RX_TEXFILTERMODE_FORCEALPHATOONEBOTH ( __PERMEDIA_DISABLE )
  1433. | P3RX_TEXFILTERMODE_SHIFTBOTH ( __PERMEDIA_ENABLE )
  1434. );
  1435. // And now the alpha test (alpha test unit)
  1436. SEND_P3_DATA ( AlphaTestMode, P3RX_ALPHATESTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1437. }
  1438. SEND_P3_DATA ( AntialiasMode, P3RX_ANTIALIASMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1439. // Texture coordinate unit.
  1440. SEND_P3_DATA(TextureCoordMode, P3RX_TEXCOORDMODE_ENABLE ( __PERMEDIA_ENABLE )
  1441. | P3RX_TEXCOORDMODE_WRAPS ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  1442. | P3RX_TEXCOORDMODE_WRAPT ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  1443. | P3RX_TEXCOORDMODE_OPERATION ( P3RX_TEXCOORDMODE_OPERATION_2D )
  1444. | P3RX_TEXCOORDMODE_INHIBITDDAINIT ( __PERMEDIA_DISABLE )
  1445. | P3RX_TEXCOORDMODE_ENABLELOD ( __PERMEDIA_DISABLE )
  1446. | P3RX_TEXCOORDMODE_ENABLEDY ( __PERMEDIA_DISABLE )
  1447. | P3RX_TEXCOORDMODE_WIDTH ( log2 ( (int)pDest->lpGbl->wWidth ) )
  1448. | P3RX_TEXCOORDMODE_HEIGHT ( log2 ( (int)pDest->lpGbl->wHeight ) )
  1449. | P3RX_TEXCOORDMODE_TEXTUREMAPTYPE ( P3RX_TEXCOORDMODE_TEXTUREMAPTYPE_2D )
  1450. | P3RX_TEXCOORDMODE_WRAPS1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  1451. | P3RX_TEXCOORDMODE_WRAPT1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  1452. );
  1453. P3_DMA_COMMIT_BUFFER();
  1454. P3_DMA_GET_BUFFER_ENTRIES(30);
  1455. SEND_P3_DATA(SStart, texSStart);
  1456. SEND_P3_DATA(TStart, texTStart);
  1457. SEND_P3_DATA(dSdx, iXScale);
  1458. SEND_P3_DATA(dSdyDom, 0);
  1459. SEND_P3_DATA(dTdx, 0);
  1460. SEND_P3_DATA(dTdyDom, iYScale);
  1461. SEND_P3_DATA(TextureBaseAddr0, dwNewSource);
  1462. if ( bYUVMode )
  1463. {
  1464. // Set up the YUV unit.
  1465. SEND_P3_DATA ( YUVMode, P3RX_YUVMODE_ENABLE ( __PERMEDIA_ENABLE ) );
  1466. iTextureType = P3RX_TEXREADMODE_TEXTURETYPE_VYUY422;
  1467. iPixelSize = P3RX_TEXREADMODE_TEXELSIZE_16;
  1468. // The idea here is to do ((colorcomp - 16) * 1.14), but in YUV space because the
  1469. // YUV unit comes after the texture composite unit. The reason for this change is
  1470. // to make our YUV conversion more like the ATI conversion. It isn't more correct this way,
  1471. // just different, but the WHQL tests were probably written on the ATI card and our colors
  1472. // aren't close enough to match what they do so we fail the test
  1473. SEND_P3_DATA(TextureCompositeMode, P3RX_TEXCOMPMODE_ENABLE ( __PERMEDIA_ENABLE ));
  1474. SEND_P3_DATA(TextureCompositeColorMode0, P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  1475. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_T0C)
  1476. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  1477. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FC)
  1478. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  1479. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  1480. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  1481. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_SUBTRACT_AB)
  1482. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_ONE));
  1483. SEND_P3_DATA(TextureCompositeAlphaMode0, P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  1484. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_T0A)
  1485. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  1486. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FA)
  1487. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  1488. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  1489. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  1490. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_SUBTRACT_AB)
  1491. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_ONE));
  1492. // This subtracts 16 from Y
  1493. SEND_P3_DATA(TextureCompositeFactor0, ((0 << 24) | (0x0 << 16) | (0x0 << 8) | 0x10));
  1494. // This multiplies the channels by 0.57.
  1495. SEND_P3_DATA(TextureCompositeFactor1, ((0x80 << 24) | (0x80 << 16) | (0x80 << 8) | 0x91));
  1496. SEND_P3_DATA(TextureCompositeColorMode1, P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  1497. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_OC)
  1498. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  1499. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FC)
  1500. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  1501. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  1502. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  1503. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_MODULATE_AB)
  1504. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_TWO));
  1505. SEND_P3_DATA(TextureCompositeAlphaMode1, P3RX_TEXCOMPCAMODE01_ENABLE(__PERMEDIA_ENABLE)
  1506. | P3RX_TEXCOMPCAMODE01_ARG1(P3RX_TEXCOMP_OC)
  1507. | P3RX_TEXCOMPCAMODE01_INVARG1(__PERMEDIA_DISABLE)
  1508. | P3RX_TEXCOMPCAMODE01_ARG2(P3RX_TEXCOMP_FA)
  1509. | P3RX_TEXCOMPCAMODE01_INVARG2(__PERMEDIA_DISABLE)
  1510. | P3RX_TEXCOMPCAMODE01_A(P3RX_TEXCOMP_ARG1)
  1511. | P3RX_TEXCOMPCAMODE01_B(P3RX_TEXCOMP_ARG2)
  1512. | P3RX_TEXCOMPCAMODE01_OPERATION(P3RX_TEXCOMP_OPERATION_MODULATE_AB)
  1513. | P3RX_TEXCOMPCAMODE01_SCALE(P3RX_TEXCOMP_OPERATION_SCALE_TWO));
  1514. }
  1515. else
  1516. {
  1517. iTextureType = P3RX_TEXREADMODE_TEXTURETYPE_NORMAL;
  1518. iPixelSize = DDSurf_GetChipPixelSize(pSource);
  1519. // Disable the composite units.
  1520. SEND_P3_DATA(TextureCompositeMode, P3RX_TEXCOMPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1521. }
  1522. P3_DMA_COMMIT_BUFFER();
  1523. P3_DMA_GET_BUFFER_ENTRIES(24);
  1524. // Pass through the texel.
  1525. SEND_P3_DATA(TextureApplicationMode, P3RX_TEXAPPMODE_ENABLE ( __PERMEDIA_ENABLE )
  1526. | P3RX_TEXAPPMODE_BOTHA ( P3RX_TEXAPP_A_CC )
  1527. | P3RX_TEXAPPMODE_BOTHB ( P3RX_TEXAPP_B_TC )
  1528. | P3RX_TEXAPPMODE_BOTHI ( P3RX_TEXAPP_I_CA )
  1529. | P3RX_TEXAPPMODE_BOTHINVI ( __PERMEDIA_DISABLE )
  1530. | P3RX_TEXAPPMODE_BOTHOP ( P3RX_TEXAPP_OPERATION_PASS_B )
  1531. | P3RX_TEXAPPMODE_KDENABLE ( __PERMEDIA_DISABLE )
  1532. | P3RX_TEXAPPMODE_KSENABLE ( __PERMEDIA_DISABLE )
  1533. | P3RX_TEXAPPMODE_MOTIONCOMPENABLE ( __PERMEDIA_DISABLE )
  1534. );
  1535. TR0 = P3RX_TEXREADMODE_ENABLE ( __PERMEDIA_ENABLE )
  1536. | P3RX_TEXREADMODE_WIDTH ( 0 )
  1537. | P3RX_TEXREADMODE_HEIGHT ( 0 )
  1538. | P3RX_TEXREADMODE_TEXELSIZE ( iPixelSize )
  1539. | P3RX_TEXREADMODE_TEXTURE3D ( __PERMEDIA_DISABLE )
  1540. | P3RX_TEXREADMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  1541. | P3RX_TEXREADMODE_MAPBASELEVEL ( 0 )
  1542. | P3RX_TEXREADMODE_MAPMAXLEVEL ( 0 )
  1543. | P3RX_TEXREADMODE_LOGICALTEXTURE ( __PERMEDIA_DISABLE )
  1544. | P3RX_TEXREADMODE_ORIGIN ( P3RX_TEXREADMODE_ORIGIN_TOPLEFT )
  1545. | P3RX_TEXREADMODE_TEXTURETYPE ( iTextureType )
  1546. | P3RX_TEXREADMODE_BYTESWAP ( P3RX_TEXREADMODE_BYTESWAP_NONE )
  1547. | P3RX_TEXREADMODE_MIRROR ( __PERMEDIA_DISABLE )
  1548. | P3RX_TEXREADMODE_INVERT ( __PERMEDIA_DISABLE )
  1549. | P3RX_TEXREADMODE_OPAQUESPAN ( __PERMEDIA_DISABLE )
  1550. ;
  1551. SEND_P3_DATA(TextureReadMode0, TR0);
  1552. SEND_P3_DATA(TextureReadMode1, TR0);
  1553. SEND_P3_DATA(TextureMapWidth0, P3RX_TEXMAPWIDTH_WIDTH(DDSurf_GetPixelPitch(pSource)) |
  1554. P3RX_TEXMAPWIDTH_LAYOUT(P3RX_LAYOUT_LINEAR) |
  1555. P3RX_TEXMAPWIDTH_HOSTTEXTURE(DDSurf_IsAGP(pSource)));
  1556. SEND_P3_DATA(TextureCacheReplacementMode,
  1557. P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST0 ( __PERMEDIA_DISABLE )
  1558. | P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST1 ( __PERMEDIA_DISABLE )
  1559. | P3RX_TEXCACHEREPLACEMODE_SHOWCACHEINFO ( __PERMEDIA_DISABLE )
  1560. );
  1561. SEND_P3_DATA(TextureMapSize, 0 );
  1562. if ( bDisableLUT )
  1563. {
  1564. SEND_P3_DATA(LUTMode, P3RX_LUTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1565. }
  1566. if ( bFiltering )
  1567. {
  1568. // Texture index unit
  1569. SEND_P3_DATA(TextureIndexMode0,
  1570. P3RX_TEXINDEXMODE_ENABLE ( __PERMEDIA_ENABLE )
  1571. | P3RX_TEXINDEXMODE_WIDTH ( MAGIC_NUMBER_2D )
  1572. | P3RX_TEXINDEXMODE_HEIGHT ( MAGIC_NUMBER_2D )
  1573. | P3RX_TEXINDEXMODE_BORDER ( __PERMEDIA_DISABLE )
  1574. | P3RX_TEXINDEXMODE_WRAPU ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1575. | P3RX_TEXINDEXMODE_WRAPV ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1576. | P3RX_TEXINDEXMODE_MAPTYPE ( P3RX_TEXINDEXMODE_MAPTYPE_2D )
  1577. | P3RX_TEXINDEXMODE_MAGFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  1578. | P3RX_TEXINDEXMODE_MINFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  1579. | P3RX_TEXINDEXMODE_TEX3DENABLE ( __PERMEDIA_DISABLE )
  1580. | P3RX_TEXINDEXMODE_MIPMAPENABLE ( __PERMEDIA_DISABLE )
  1581. | P3RX_TEXINDEXMODE_NEARESTBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1582. | P3RX_TEXINDEXMODE_LINEARBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1583. | P3RX_TEXINDEXMODE_SOURCETEXELENABLE ( __PERMEDIA_DISABLE )
  1584. );
  1585. }
  1586. else
  1587. {
  1588. // Texture index unit
  1589. SEND_P3_DATA(TextureIndexMode0,
  1590. P3RX_TEXINDEXMODE_ENABLE ( __PERMEDIA_ENABLE )
  1591. | P3RX_TEXINDEXMODE_WIDTH ( MAGIC_NUMBER_2D )
  1592. | P3RX_TEXINDEXMODE_HEIGHT ( MAGIC_NUMBER_2D )
  1593. | P3RX_TEXINDEXMODE_BORDER ( __PERMEDIA_DISABLE )
  1594. | P3RX_TEXINDEXMODE_WRAPU ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1595. | P3RX_TEXINDEXMODE_WRAPV ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1596. | P3RX_TEXINDEXMODE_MAPTYPE ( P3RX_TEXINDEXMODE_MAPTYPE_2D )
  1597. | P3RX_TEXINDEXMODE_MAGFILTER ( P3RX_TEXINDEXMODE_FILTER_NEAREST )
  1598. | P3RX_TEXINDEXMODE_MINFILTER ( P3RX_TEXINDEXMODE_FILTER_NEAREST )
  1599. | P3RX_TEXINDEXMODE_TEX3DENABLE ( __PERMEDIA_DISABLE )
  1600. | P3RX_TEXINDEXMODE_MIPMAPENABLE ( __PERMEDIA_DISABLE )
  1601. | P3RX_TEXINDEXMODE_NEARESTBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1602. | P3RX_TEXINDEXMODE_LINEARBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1603. | P3RX_TEXINDEXMODE_SOURCETEXELENABLE ( __PERMEDIA_DISABLE )
  1604. );
  1605. }
  1606. ASSERTDD ( pFormatDest->DitherFormat >= 0, "** _DD_P3BltStretchSrcChDstCh: Destination format illegal" );
  1607. if ( bFiltering )
  1608. {
  1609. // Filtering, so dither.
  1610. SEND_P3_DATA(DitherMode,
  1611. P3RX_DITHERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1612. | P3RX_DITHERMODE_DITHERENABLE ( __PERMEDIA_ENABLE )
  1613. | P3RX_DITHERMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  1614. | P3RX_DITHERMODE_XOFFSET ( 0 )
  1615. | P3RX_DITHERMODE_YOFFSET ( 0 )
  1616. | P3RX_DITHERMODE_COLORORDER ( COLOR_MODE )
  1617. | P3RX_DITHERMODE_ALPHADITHER ( P3RX_DITHERMODE_ALPHADITHER_DITHER )
  1618. | P3RX_DITHERMODE_ROUNDINGMODE ( P3RX_DITHERMODE_ROUNDINGMODE_TRUNCATE )
  1619. );
  1620. }
  1621. else
  1622. {
  1623. // No filter, no dither (though it doesn't actually matter).
  1624. SEND_P3_DATA(DitherMode,
  1625. P3RX_DITHERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1626. | P3RX_DITHERMODE_DITHERENABLE ( __PERMEDIA_DISABLE )
  1627. | P3RX_DITHERMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  1628. | P3RX_DITHERMODE_XOFFSET ( 0 )
  1629. | P3RX_DITHERMODE_YOFFSET ( 0 )
  1630. | P3RX_DITHERMODE_COLORORDER ( COLOR_MODE )
  1631. | P3RX_DITHERMODE_ALPHADITHER ( P3RX_DITHERMODE_ALPHADITHER_DITHER )
  1632. | P3RX_DITHERMODE_ROUNDINGMODE ( P3RX_DITHERMODE_ROUNDINGMODE_TRUNCATE )
  1633. );
  1634. }
  1635. SEND_P3_DATA(LogicalOpMode,
  1636. P3RX_LOGICALOPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1637. SEND_P3_DATA(PixelSize, (2 - DDSurf_GetChipPixelSize(pDest)));
  1638. SEND_P3_DATA(FBWriteMode,
  1639. P3RX_FBWRITEMODE_WRITEENABLE(__PERMEDIA_ENABLE) |
  1640. P3RX_FBWRITEMODE_LAYOUT0(P3RX_LAYOUT_LINEAR));
  1641. WAIT_FIFO(32);
  1642. P3_ENSURE_DX_SPACE(32);
  1643. SEND_P3_DATA(Count, rMyDest.bottom - rMyDest.top );
  1644. SEND_P3_DATA(Render,
  1645. P3RX_RENDER_PRIMITIVETYPE ( P3RX_RENDER_PRIMITIVETYPE_TRAPEZOID )
  1646. | P3RX_RENDER_TEXTUREENABLE ( __PERMEDIA_ENABLE )
  1647. | P3RX_RENDER_FOGENABLE ( __PERMEDIA_DISABLE )
  1648. | P3RX_RENDER_FBSOURCEREADENABLE( (bDstKey ? __PERMEDIA_ENABLE : __PERMEDIA_DISABLE))
  1649. );
  1650. // Disable all the things I switched on.
  1651. SEND_P3_DATA(ChromaTestMode, __PERMEDIA_DISABLE );
  1652. SEND_P3_DATA(AlphaBlendColorMode, __PERMEDIA_DISABLE );
  1653. SEND_P3_DATA(AlphaBlendAlphaMode, __PERMEDIA_DISABLE );
  1654. SEND_P3_DATA(TextureFilterMode, __PERMEDIA_DISABLE );
  1655. SEND_P3_DATA(AlphaTestMode, __PERMEDIA_DISABLE );
  1656. SEND_P3_DATA(AntialiasMode, __PERMEDIA_DISABLE );
  1657. SEND_P3_DATA(TextureCoordMode, __PERMEDIA_DISABLE );
  1658. SEND_P3_DATA(TextureReadMode0, __PERMEDIA_DISABLE );
  1659. SEND_P3_DATA(TextureIndexMode0, __PERMEDIA_DISABLE );
  1660. WAIT_FIFO(20);
  1661. P3_ENSURE_DX_SPACE(20);
  1662. SEND_P3_DATA(TextureCompositeMode, __PERMEDIA_DISABLE );
  1663. SEND_P3_DATA(TextureCompositeColorMode0, __PERMEDIA_DISABLE);
  1664. SEND_P3_DATA(TextureCompositeAlphaMode0, __PERMEDIA_DISABLE);
  1665. SEND_P3_DATA(TextureCompositeColorMode1, __PERMEDIA_DISABLE);
  1666. SEND_P3_DATA(TextureCompositeAlphaMode1, __PERMEDIA_DISABLE);
  1667. SEND_P3_DATA(TextureApplicationMode, __PERMEDIA_DISABLE );
  1668. SEND_P3_DATA(DitherMode, __PERMEDIA_DISABLE );
  1669. SEND_P3_DATA(FBSourceReadMode, __PERMEDIA_DISABLE);
  1670. SEND_P3_DATA(LogicalOpMode, __PERMEDIA_DISABLE );
  1671. SEND_P3_DATA(YUVMode, __PERMEDIA_DISABLE );
  1672. P3_DMA_COMMIT_BUFFER();
  1673. } // __P3BltStretchSrcChDstChSourceOveride
  1674. //-----------------------------------------------------------------------------
  1675. //
  1676. // _DD_P3BltStretchSrcChDstChOverlap
  1677. //
  1678. //-----------------------------------------------------------------------------
  1679. void
  1680. _DD_P3BltStretchSrcChDstChOverlap(
  1681. P3_THUNKEDDATA* pThisDisplay,
  1682. LPDDRAWI_DDRAWSURFACE_LCL pSource,
  1683. LPDDRAWI_DDRAWSURFACE_LCL pDest,
  1684. P3_SURF_FORMAT* pFormatSource,
  1685. P3_SURF_FORMAT* pFormatDest,
  1686. LPDDHAL_BLTDATA lpBlt,
  1687. RECTL *rSrc,
  1688. RECTL *rDest)
  1689. {
  1690. P3_MEMREQUEST mmrq;
  1691. DWORD dwResult;
  1692. ZeroMemory(&mmrq, sizeof(P3_MEMREQUEST));
  1693. mmrq.dwSize = sizeof(P3_MEMREQUEST);
  1694. mmrq.dwBytes = DDSurf_Pitch(pSource) * DDSurf_Height(pSource);
  1695. mmrq.dwAlign = 16;
  1696. mmrq.dwFlags = MEM3DL_FIRST_FIT | MEM3DL_FRONT;
  1697. dwResult = _DX_LIN_AllocateLinearMemory(&pThisDisplay->LocalVideoHeap0Info,
  1698. &mmrq);
  1699. if (dwResult != GLDD_SUCCESS)
  1700. {
  1701. // Couldn't get the memory, so try anyway. It probably won't look
  1702. // right but it is our best shot...
  1703. DISPDBG((WRNLVL,"Overlapped stretch blit unlikely to look correct!"));
  1704. _DD_P3BltStretchSrcChDstCh_DD(pThisDisplay,
  1705. pSource,
  1706. pDest,
  1707. pFormatSource,
  1708. pFormatDest,
  1709. lpBlt,
  1710. rSrc,
  1711. rDest);
  1712. return;
  1713. }
  1714. // Copy the source buffer to a temporary place.
  1715. __P3BltDestOveride(pThisDisplay,
  1716. pSource,
  1717. pSource,
  1718. pFormatSource,
  1719. pFormatSource,
  1720. rSrc,
  1721. rSrc,
  1722. __GLINT_LOGICOP_COPY,
  1723. (long)mmrq.pMem - (long)pThisDisplay->dwScreenFlatAddr);
  1724. // Do the blit, stretching to our temporary buffer
  1725. __P3BltStretchSrcChDstChSourceOveride(pThisDisplay,
  1726. pSource,
  1727. pDest,
  1728. pFormatSource,
  1729. pFormatDest,
  1730. lpBlt,
  1731. rSrc,
  1732. rDest,
  1733. (long)mmrq.pMem -
  1734. (long)pThisDisplay->dwScreenFlatAddr);
  1735. // Free the allocated source buffer.
  1736. _DX_LIN_FreeLinearMemory(&pThisDisplay->LocalVideoHeap0Info,
  1737. mmrq.pMem);
  1738. } // _DD_P3BltStretchSrcChDstChOverlap
  1739. #if DX8_MULTISAMPLING || DX7_ANTIALIAS
  1740. //-----------------------------------------------------------------------------
  1741. //
  1742. // Function: P3RX_AA_Shrink
  1743. //
  1744. // Does a 2x2 to 1x1 blit through the texture unit to shrink an AA buffer
  1745. //
  1746. //-----------------------------------------------------------------------------
  1747. VOID P3RX_AA_Shrink(P3_D3DCONTEXT* pContext)
  1748. {
  1749. ULONG renderData;
  1750. RECTL rMySrc, rMyDest;
  1751. int iSrcWidth, iSrcHeight;
  1752. int iDstWidth, iDstHeight;
  1753. DWORD TR0;
  1754. int iSourcePixelSize;
  1755. P3_THUNKEDDATA* pThisDisplay = pContext->pThisDisplay;
  1756. P3_SURF_INTERNAL* pSurf = pContext->pSurfRenderInt;
  1757. P3_SURF_FORMAT* pFormatSource;
  1758. P3_SURF_FORMAT* pFormatDest = pSurf->pFormatSurface;
  1759. P3_DMA_DEFS();
  1760. rMySrc.top = 0;
  1761. rMySrc.bottom = pSurf->wHeight * 2;
  1762. rMySrc.left = 0;
  1763. rMySrc.right = pSurf->wWidth * 2;
  1764. rMyDest.top = 0;
  1765. rMyDest.left = 0;
  1766. rMyDest.right = pSurf->wWidth;
  1767. rMyDest.bottom = pSurf->wHeight;
  1768. iSrcWidth = rMySrc.right - rMySrc.left;
  1769. iSrcHeight = rMySrc.bottom - rMySrc.top;
  1770. iDstWidth = rMyDest.right - rMyDest.left;
  1771. iDstHeight = rMyDest.bottom - rMyDest.top;
  1772. // MAGIC_NUMBER_2D can be anything, but it needs to be at least as
  1773. // big as the widest texture, but not too big or you'll lose fractional
  1774. // precision. Valid range for a P3 is 0->11
  1775. ASSERTDD ( iSrcWidth <= ( 1 << MAGIC_NUMBER_2D ),
  1776. "P3RX_AA_Shrink: MAGIC_NUMBER_2D is too small" );
  1777. ASSERTDD ( iSrcHeight <= ( 1 << MAGIC_NUMBER_2D ),
  1778. "P3RX_AA_Shrink: MAGIC_NUMBER_2D is too small" );
  1779. DISPDBG((DBGLVL, "Glint Blt from (%d, %d) to (%d,%d) (%d, %d)",
  1780. rMySrc.left, rMySrc.top,
  1781. rMyDest.left, rMyDest.top,
  1782. rMyDest.right, rMyDest.bottom));
  1783. iSourcePixelSize = pSurf->dwPixelSize;
  1784. pFormatSource = pFormatDest;
  1785. P3_DMA_GET_BUFFER();
  1786. P3_ENSURE_DX_SPACE(32);
  1787. WAIT_FIFO(32);
  1788. // Vape the cache.
  1789. P3RX_INVALIDATECACHE(__PERMEDIA_ENABLE, __PERMEDIA_ENABLE);
  1790. // Source read is same as write.
  1791. SEND_P3_DATA(FBSourceReadBufferAddr, pSurf->lOffsetFromMemoryBase );
  1792. SEND_P3_DATA(FBSourceReadBufferWidth, pSurf->dwPixelPitch);
  1793. SEND_P3_DATA(FBWriteMode,
  1794. P3RX_FBWRITEMODE_WRITEENABLE(__PERMEDIA_ENABLE) |
  1795. P3RX_FBWRITEMODE_LAYOUT0(pSurf->dwPatchMode));
  1796. // No offset - we read the dest pixels so that we can chroma-key off them.
  1797. SEND_P3_DATA(FBSourceReadBufferOffset, 0);
  1798. SEND_P3_DATA(FBWriteBufferOffset0, 0);
  1799. SEND_P3_DATA(PixelSize, pSurf->dwPixelSize);
  1800. SEND_P3_DATA(RectanglePosition,
  1801. P3RX_RECTANGLEPOSITION_X( rMyDest.left ) |
  1802. P3RX_RECTANGLEPOSITION_Y( rMyDest.top ));
  1803. renderData = P3RX_RENDER2D_WIDTH(( rMyDest.right - rMyDest.left ) & 0xfff )
  1804. | P3RX_RENDER2D_OPERATION( P3RX_RENDER2D_OPERATION_NORMAL )
  1805. | P3RX_RENDER2D_FBREADSOURCEENABLE( __PERMEDIA_DISABLE )
  1806. | P3RX_RENDER2D_HEIGHT ( 0 )
  1807. | P3RX_RENDER2D_INCREASINGX( __PERMEDIA_ENABLE )
  1808. | P3RX_RENDER2D_INCREASINGY( __PERMEDIA_ENABLE )
  1809. | P3RX_RENDER2D_AREASTIPPLEENABLE( __PERMEDIA_DISABLE )
  1810. | P3RX_RENDER2D_TEXTUREENABLE( __PERMEDIA_ENABLE );
  1811. SEND_P3_DATA(Render2D, renderData);
  1812. // This is the alpha blending unit.
  1813. // AlphaBlendxxxMode are set up by the context code.
  1814. // The colour format, order and conversion fields are used by the
  1815. // chroma keying, even though this register is disabled.
  1816. SEND_P3_DATA(AlphaBlendColorMode,
  1817. P3RX_ALPHABLENDCOLORMODE_ENABLE ( __PERMEDIA_DISABLE )
  1818. | P3RX_ALPHABLENDCOLORMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  1819. | P3RX_ALPHABLENDCOLORMODE_COLORORDER ( COLOR_MODE )
  1820. | P3RX_ALPHABLENDCOLORMODE_COLORCONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  1821. );
  1822. SEND_P3_DATA(AlphaBlendAlphaMode,
  1823. P3RX_ALPHABLENDALPHAMODE_ENABLE ( __PERMEDIA_DISABLE )
  1824. | P3RX_ALPHABLENDALPHAMODE_NOALPHABUFFER( __PERMEDIA_DISABLE )
  1825. | P3RX_ALPHABLENDALPHAMODE_ALPHATYPE ( P3RX_ALPHABLENDMODE_ALPHATYPE_OGL )
  1826. | P3RX_ALPHABLENDALPHAMODE_ALPHACONVERSION ( P3RX_ALPHABLENDMODE_CONVERT_SHIFT )
  1827. );
  1828. P3_ENSURE_DX_SPACE(32);
  1829. WAIT_FIFO(32);
  1830. // No chroma keying at all.
  1831. SEND_P3_DATA(ChromaTestMode, P3RX_CHROMATESTMODE_ENABLE(__PERMEDIA_DISABLE ) );
  1832. SEND_P3_DATA(TextureFilterMode, P3RX_TEXFILTERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1833. | P3RX_TEXFILTERMODE_FORMATBOTH ( pFormatSource->FilterFormat )
  1834. | P3RX_TEXFILTERMODE_COLORORDERBOTH ( COLOR_MODE )
  1835. | P3RX_TEXFILTERMODE_ALPHAMAPENABLEBOTH ( __PERMEDIA_DISABLE )
  1836. | P3RX_TEXFILTERMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  1837. | P3RX_TEXFILTERMODE_ALPHAMAPFILTERING ( __PERMEDIA_DISABLE )
  1838. | P3RX_TEXFILTERMODE_FORCEALPHATOONEBOTH ( __PERMEDIA_DISABLE )
  1839. | P3RX_TEXFILTERMODE_SHIFTBOTH ( __PERMEDIA_DISABLE )
  1840. );
  1841. // And now the alpha test (alpha test unit)
  1842. SEND_P3_DATA ( AlphaTestMode, P3RX_ALPHATESTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1843. SEND_P3_DATA ( AntialiasMode, P3RX_ANTIALIASMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1844. // Texture coordinate unit.
  1845. SEND_P3_DATA(TextureCoordMode,
  1846. P3RX_TEXCOORDMODE_ENABLE ( __PERMEDIA_ENABLE )
  1847. | P3RX_TEXCOORDMODE_WRAPS ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  1848. | P3RX_TEXCOORDMODE_WRAPT ( P3RX_TEXCOORDMODE_WRAP_REPEAT )
  1849. | P3RX_TEXCOORDMODE_OPERATION ( P3RX_TEXCOORDMODE_OPERATION_2D )
  1850. | P3RX_TEXCOORDMODE_INHIBITDDAINIT ( __PERMEDIA_DISABLE )
  1851. | P3RX_TEXCOORDMODE_ENABLELOD ( __PERMEDIA_DISABLE )
  1852. | P3RX_TEXCOORDMODE_ENABLEDY ( __PERMEDIA_DISABLE )
  1853. | P3RX_TEXCOORDMODE_WIDTH (0) // Only used for mipmapping
  1854. | P3RX_TEXCOORDMODE_HEIGHT (0)
  1855. | P3RX_TEXCOORDMODE_TEXTUREMAPTYPE ( P3RX_TEXCOORDMODE_TEXTUREMAPTYPE_2D )
  1856. | P3RX_TEXCOORDMODE_WRAPS1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  1857. | P3RX_TEXCOORDMODE_WRAPT1 ( P3RX_TEXCOORDMODE_WRAP_CLAMP )
  1858. );
  1859. SEND_P3_DATA(SStart, (1 << (31-MAGIC_NUMBER_2D)));
  1860. SEND_P3_DATA(TStart, (1 << (31-MAGIC_NUMBER_2D)));
  1861. SEND_P3_DATA(dSdx, (2 << (32-MAGIC_NUMBER_2D)));
  1862. SEND_P3_DATA(dSdyDom, 0);
  1863. SEND_P3_DATA(dTdx, 0);
  1864. SEND_P3_DATA(dTdyDom, (2 << (32-MAGIC_NUMBER_2D)));
  1865. SEND_P3_DATA(LBWriteMode, 0);
  1866. P3_ENSURE_DX_SPACE(32);
  1867. WAIT_FIFO(32);
  1868. SEND_P3_DATA(TextureBaseAddr0,
  1869. pContext->dwAliasBackBuffer -
  1870. pThisDisplay->dwScreenFlatAddr );
  1871. TR0 = P3RX_TEXREADMODE_ENABLE ( __PERMEDIA_ENABLE )
  1872. | P3RX_TEXREADMODE_WIDTH ( 0 )
  1873. | P3RX_TEXREADMODE_HEIGHT ( 0 )
  1874. | P3RX_TEXREADMODE_TEXELSIZE (iSourcePixelSize)
  1875. | P3RX_TEXREADMODE_TEXTURE3D ( __PERMEDIA_DISABLE )
  1876. | P3RX_TEXREADMODE_COMBINECACHES ( __PERMEDIA_ENABLE )
  1877. | P3RX_TEXREADMODE_MAPBASELEVEL ( 0 )
  1878. | P3RX_TEXREADMODE_MAPMAXLEVEL ( 0 )
  1879. | P3RX_TEXREADMODE_LOGICALTEXTURE ( __PERMEDIA_DISABLE )
  1880. | P3RX_TEXREADMODE_ORIGIN ( P3RX_TEXREADMODE_ORIGIN_TOPLEFT )
  1881. | P3RX_TEXREADMODE_TEXTURETYPE ( P3RX_TEXREADMODE_TEXTURETYPE_NORMAL)
  1882. | P3RX_TEXREADMODE_BYTESWAP ( P3RX_TEXREADMODE_BYTESWAP_NONE )
  1883. | P3RX_TEXREADMODE_MIRROR ( __PERMEDIA_DISABLE )
  1884. | P3RX_TEXREADMODE_INVERT ( __PERMEDIA_DISABLE )
  1885. | P3RX_TEXREADMODE_OPAQUESPAN ( __PERMEDIA_DISABLE )
  1886. ;
  1887. SEND_P3_DATA(TextureReadMode0, TR0);
  1888. SEND_P3_DATA(TextureReadMode1, TR0);
  1889. SEND_P3_DATA(TextureMapWidth0,
  1890. P3RX_TEXMAPWIDTH_WIDTH(pSurf->dwPixelPitch * 2) |
  1891. P3RX_TEXMAPWIDTH_LAYOUT(pSurf->dwPatchMode));
  1892. SEND_P3_DATA(TextureCacheReplacementMode,
  1893. P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST0 ( __PERMEDIA_DISABLE )
  1894. | P3RX_TEXCACHEREPLACEMODE_KEEPOLDEST1 ( __PERMEDIA_DISABLE )
  1895. | P3RX_TEXCACHEREPLACEMODE_SHOWCACHEINFO ( __PERMEDIA_DISABLE )
  1896. );
  1897. SEND_P3_DATA(TextureMapSize, 0 );
  1898. SEND_P3_DATA(LUTMode, P3RX_LUTMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1899. // Texture index unit
  1900. SEND_P3_DATA(TextureIndexMode0,
  1901. P3RX_TEXINDEXMODE_ENABLE ( __PERMEDIA_ENABLE )
  1902. | P3RX_TEXINDEXMODE_WIDTH ( MAGIC_NUMBER_2D )
  1903. | P3RX_TEXINDEXMODE_HEIGHT ( MAGIC_NUMBER_2D )
  1904. | P3RX_TEXINDEXMODE_BORDER ( __PERMEDIA_DISABLE )
  1905. | P3RX_TEXINDEXMODE_WRAPU ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1906. | P3RX_TEXINDEXMODE_WRAPV ( P3RX_TEXINDEXMODE_WRAP_REPEAT )
  1907. | P3RX_TEXINDEXMODE_MAPTYPE ( P3RX_TEXINDEXMODE_MAPTYPE_2D )
  1908. | P3RX_TEXINDEXMODE_MAGFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  1909. | P3RX_TEXINDEXMODE_MINFILTER ( P3RX_TEXINDEXMODE_FILTER_LINEAR )
  1910. | P3RX_TEXINDEXMODE_TEX3DENABLE ( __PERMEDIA_DISABLE )
  1911. | P3RX_TEXINDEXMODE_MIPMAPENABLE ( __PERMEDIA_DISABLE )
  1912. | P3RX_TEXINDEXMODE_NEARESTBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1913. | P3RX_TEXINDEXMODE_LINEARBIAS ( P3RX_TEXINDEXMODE_BIAS_ZERO )
  1914. | P3RX_TEXINDEXMODE_SOURCETEXELENABLE ( __PERMEDIA_DISABLE )
  1915. );
  1916. // Disable the composite units.
  1917. SEND_P3_DATA(TextureCompositeMode,
  1918. P3RX_TEXCOMPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1919. // Pass through the texel.
  1920. SEND_P3_DATA(TextureApplicationMode,
  1921. P3RX_TEXAPPMODE_ENABLE ( __PERMEDIA_ENABLE )
  1922. | P3RX_TEXAPPMODE_BOTHA ( P3RX_TEXAPP_A_CC )
  1923. | P3RX_TEXAPPMODE_BOTHB ( P3RX_TEXAPP_B_TC )
  1924. | P3RX_TEXAPPMODE_BOTHI ( P3RX_TEXAPP_I_CA )
  1925. | P3RX_TEXAPPMODE_BOTHINVI ( __PERMEDIA_DISABLE )
  1926. | P3RX_TEXAPPMODE_BOTHOP ( P3RX_TEXAPP_OPERATION_PASS_B )
  1927. | P3RX_TEXAPPMODE_KDENABLE ( __PERMEDIA_DISABLE )
  1928. | P3RX_TEXAPPMODE_KSENABLE ( __PERMEDIA_DISABLE )
  1929. | P3RX_TEXAPPMODE_MOTIONCOMPENABLE ( __PERMEDIA_DISABLE )
  1930. );
  1931. // Filtering, so dither.
  1932. SEND_P3_DATA(DitherMode,
  1933. P3RX_DITHERMODE_ENABLE ( __PERMEDIA_ENABLE )
  1934. | P3RX_DITHERMODE_DITHERENABLE ( __PERMEDIA_DISABLE )
  1935. | P3RX_DITHERMODE_COLORFORMAT ( pFormatDest->DitherFormat )
  1936. | P3RX_DITHERMODE_XOFFSET ( 0 )
  1937. | P3RX_DITHERMODE_YOFFSET ( 0 )
  1938. | P3RX_DITHERMODE_COLORORDER ( COLOR_MODE )
  1939. | P3RX_DITHERMODE_ALPHADITHER ( P3RX_DITHERMODE_ALPHADITHER_DITHER )
  1940. | P3RX_DITHERMODE_ROUNDINGMODE ( P3RX_DITHERMODE_ROUNDINGMODE_TRUNCATE )
  1941. );
  1942. P3_ENSURE_DX_SPACE(32);
  1943. WAIT_FIFO(32);
  1944. SEND_P3_DATA(LogicalOpMode,
  1945. P3RX_LOGICALOPMODE_ENABLE ( __PERMEDIA_DISABLE ) );
  1946. SEND_P3_DATA(FBWriteBufferAddr0, pSurf->lOffsetFromMemoryBase );
  1947. SEND_P3_DATA(FBWriteBufferWidth0, pSurf->dwPixelPitch);
  1948. SEND_P3_DATA(Count, rMyDest.bottom - rMyDest.top );
  1949. SEND_P3_DATA(Render,
  1950. P3RX_RENDER_PRIMITIVETYPE ( P3RX_RENDER_PRIMITIVETYPE_TRAPEZOID )
  1951. | P3RX_RENDER_TEXTUREENABLE ( __PERMEDIA_ENABLE )
  1952. | P3RX_RENDER_FOGENABLE ( __PERMEDIA_DISABLE )
  1953. | P3RX_RENDER_FBSOURCEREADENABLE( __PERMEDIA_DISABLE)
  1954. );
  1955. P3_ENSURE_DX_SPACE(32);
  1956. WAIT_FIFO(32);
  1957. // Disable all the units that were switched on.
  1958. SEND_P3_DATA(ChromaTestMode, __PERMEDIA_DISABLE );
  1959. SEND_P3_DATA(AlphaBlendColorMode, __PERMEDIA_DISABLE );
  1960. SEND_P3_DATA(AlphaBlendAlphaMode, __PERMEDIA_DISABLE );
  1961. SEND_P3_DATA(TextureFilterMode, __PERMEDIA_DISABLE );
  1962. SEND_P3_DATA(AlphaTestMode, __PERMEDIA_DISABLE );
  1963. SEND_P3_DATA(AntialiasMode, __PERMEDIA_DISABLE );
  1964. SEND_P3_DATA(TextureCoordMode, __PERMEDIA_DISABLE );
  1965. SEND_P3_DATA(TextureReadMode0, __PERMEDIA_DISABLE );
  1966. SEND_P3_DATA(TextureIndexMode0, __PERMEDIA_DISABLE );
  1967. SEND_P3_DATA(TextureCompositeMode, __PERMEDIA_DISABLE );
  1968. SEND_P3_DATA(TextureApplicationMode, __PERMEDIA_DISABLE );
  1969. SEND_P3_DATA(DitherMode, __PERMEDIA_DISABLE );
  1970. SEND_P3_DATA(LogicalOpMode, __PERMEDIA_DISABLE );
  1971. SEND_P3_DATA(YUVMode, __PERMEDIA_DISABLE );
  1972. P3_DMA_COMMIT_BUFFER();
  1973. } // P3RX_AA_Shrink
  1974. #endif // DX8_MULTISAMPLING || DX7_ANTIALIAS