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.

121 lines
4.1 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains C span loops.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. include(`mtexaddr.mh')dnl
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. #include "mloop.h"
  12. //-----------------------------------------------------------------------------
  13. //
  14. // CMMX_LoopAny
  15. //
  16. // Loops over the pixels of a span, calling processing routines at each one.
  17. // Handles any pixel-to-pixel step.
  18. //
  19. //-----------------------------------------------------------------------------
  20. void CMMX_LoopAny(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP, PD3DI_RASTSPAN pS)
  21. {
  22. // get values to iterate
  23. UINT16 uPix = pS->uPix;
  24. // Keep dither pattern up to date directly, so keeping SI.uX up
  25. // to date is not necessary, except for debug
  26. pCtx->SI.uDitherOffset = (pS->uY & 3) | ((pS->uX & 3)<<2);
  27. if (pCtx->pdwRenderState[D3DRENDERSTATE_FOGENABLE]) {
  28. D3DCOLOR FogColor = pCtx->pdwRenderState[D3DRENDERSTATE_FOGCOLOR];
  29. UINT16 uMFog = 0xff - (pS->uFog>>8);
  30. UINT16 FR = (UINT16)RGBA_GETRED(FogColor);
  31. UINT16 FG = (UINT16)RGBA_GETGREEN(FogColor);
  32. UINT16 FB = (UINT16)RGBA_GETBLUE(FogColor);
  33. pCtx->SI.uFogR = uMFog * FR; // 0.8 * 8.0 = 8.8
  34. pCtx->SI.uFogG = uMFog * FG;
  35. pCtx->SI.uFogB = uMFog * FB;
  36. INT32 iMDFog = -pS->iDFog;
  37. // 1.7.8 * 8.0 >> 8 = 1.7.8 (ATTENTION this could overflow, but it is naturally aligned for
  38. // doing the walking. Can fix by changing precision of uFogR values, or by clamping
  39. // range of iDFog.
  40. pCtx->SI.iFogRDX = (INT16)((iMDFog * FR) >> 8);
  41. pCtx->SI.iFogGDX = (INT16)((iMDFog * FG) >> 8);
  42. pCtx->SI.iFogBDX = (INT16)((iMDFog * FB) >> 8);
  43. }
  44. // don't need to do this if not texture mapping
  45. if (pCtx->pdwRenderState[D3DRENDERSTATE_TEXTUREPERSPECTIVE])
  46. {
  47. pCtx->SI.iU1 = d_WTimesUVoW(pS->iW,pS->iUoW1);
  48. pCtx->SI.iV1 = d_WTimesUVoW(pS->iW,pS->iVoW1);
  49. pCtx->SI.iU2 = d_WTimesUVoW(pS->iW,pS->iUoW2);
  50. pCtx->SI.iV2 = d_WTimesUVoW(pS->iW,pS->iVoW2);
  51. pCtx->SI.iDW = 0x0;
  52. if (pP->iDOoWDX > 0)
  53. {
  54. // iSpecialW should be negative for the first 3 pixels of span
  55. pCtx->SI.iSpecialW = -3;
  56. }
  57. else
  58. {
  59. // iSpecialW should be negative for the last 3 pixels of span
  60. pCtx->SI.iSpecialW = 0x7fff - uPix;
  61. pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  62. }
  63. }
  64. else
  65. {
  66. pCtx->SI.iU1 = pS->iUoW1>>TEX_TO_FINAL_SHIFT; // 1.11.20 >> 4 == 1.15.16
  67. pCtx->SI.iV1 = pS->iVoW1>>TEX_TO_FINAL_SHIFT;
  68. pCtx->SI.iU2 = pS->iUoW2>>TEX_TO_FINAL_SHIFT;
  69. pCtx->SI.iV2 = pS->iVoW2>>TEX_TO_FINAL_SHIFT;
  70. pCtx->SI.iDW = 0x0;
  71. pCtx->SI.iSpecialW = 0;
  72. }
  73. INT iSurfaceStep;
  74. INT iZStep;
  75. if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  76. {
  77. iZStep = -pCtx->iZStep;
  78. iSurfaceStep = -pCtx->iSurfaceStep;
  79. pCtx->SI.iXStep = -1; // for dithering
  80. }
  81. else
  82. {
  83. iZStep = pCtx->iZStep;
  84. iSurfaceStep = pCtx->iSurfaceStep;
  85. pCtx->SI.iXStep = 1;
  86. }
  87. while (1)
  88. {
  89. #if 0
  90. // for debug, since breakpoints with conditions are really really slow
  91. if ((pS->uX == 56) && ((pS->uY == 26) || (pS->uY == 26)))
  92. {
  93. DPF(0, "Look at this");
  94. }
  95. #endif
  96. pCtx->pfnLoopEnd(pCtx, pP, pS);
  97. if (--uPix <= 0)
  98. break;
  99. pS->pZ += iZStep;
  100. pS->pSurface += iSurfaceStep;
  101. // don't update this in dithered write functions because of alpha test
  102. // ATTENTION could specialize loop routines based on things like dither and Z buffer
  103. pCtx->SI.uDitherOffset = (pCtx->SI.uDitherOffset + (pCtx->SI.iXStep<<2)) & 0xf;
  104. #ifdef DBG
  105. // handy for debug to see where we are
  106. pS->uX += (INT16)pCtx->SI.iXStep;
  107. #endif
  108. }
  109. }