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.

137 lines
4.6 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // This file contains C span loops.
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997.
  6. //
  7. //-----------------------------------------------------------------------------
  8. include(`ctexaddr.mh')dnl
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. #include "cloop.h"
  12. //-----------------------------------------------------------------------------
  13. //
  14. // C_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 C_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. // if iFog*DX is positive, iFog*DX will always be too small, hence no overflow
  44. // but if iFog*DX is negative, add some to make sure overflow does not
  45. // occur
  46. if (pCtx->SI.iFogRDX < 0)
  47. {
  48. pCtx->SI.iFogRDX = min(pCtx->SI.iFogRDX+4, 0);
  49. }
  50. if (pCtx->SI.iFogGDX < 0)
  51. {
  52. pCtx->SI.iFogGDX = min(pCtx->SI.iFogGDX+4, 0);
  53. }
  54. if (pCtx->SI.iFogBDX < 0)
  55. {
  56. pCtx->SI.iFogBDX = min(pCtx->SI.iFogBDX+4, 0);
  57. }
  58. }
  59. // don't need to do this if not texture mapping
  60. if (pCtx->pdwRenderState[D3DRENDERSTATE_TEXTUREPERSPECTIVE])
  61. {
  62. pCtx->SI.iU1 = d_WTimesUVoW(pS->iW,pS->iUoW1);
  63. pCtx->SI.iV1 = d_WTimesUVoW(pS->iW,pS->iVoW1);
  64. pCtx->SI.iU2 = d_WTimesUVoW(pS->iW,pS->iUoW2);
  65. pCtx->SI.iV2 = d_WTimesUVoW(pS->iW,pS->iVoW2);
  66. pCtx->SI.iDW = 0x0;
  67. if (pP->iDOoWDX > 0)
  68. {
  69. // iSpecialW should be negative for the first 3 pixels of span
  70. pCtx->SI.iSpecialW = -3;
  71. }
  72. else
  73. {
  74. // iSpecialW should be negative for the last 3 pixels of span
  75. pCtx->SI.iSpecialW = 0x7fff - uPix;
  76. pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  77. }
  78. }
  79. else
  80. {
  81. pCtx->SI.iU1 = pS->iUoW1>>TEX_TO_FINAL_SHIFT; // 1.11.20 >> 4 == 1.15.16
  82. pCtx->SI.iV1 = pS->iVoW1>>TEX_TO_FINAL_SHIFT;
  83. pCtx->SI.iU2 = pS->iUoW2>>TEX_TO_FINAL_SHIFT;
  84. pCtx->SI.iV2 = pS->iVoW2>>TEX_TO_FINAL_SHIFT;
  85. pCtx->SI.iDW = 0x0;
  86. pCtx->SI.iSpecialW = 0;
  87. }
  88. INT iSurfaceStep;
  89. INT iZStep;
  90. if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  91. {
  92. iZStep = -pCtx->iZStep;
  93. iSurfaceStep = -pCtx->iSurfaceStep;
  94. pCtx->SI.iXStep = -1; // for dithering
  95. }
  96. else
  97. {
  98. iZStep = pCtx->iZStep;
  99. iSurfaceStep = pCtx->iSurfaceStep;
  100. pCtx->SI.iXStep = 1;
  101. }
  102. while (1)
  103. {
  104. #if 0
  105. // for debug, since breakpoints with conditions are really really slow
  106. if ((pS->uX == 104) && (pS->uY == 146))
  107. {
  108. DPF(0, "Look at this");
  109. }
  110. #endif
  111. pCtx->pfnLoopEnd(pCtx, pP, pS);
  112. if (--uPix <= 0)
  113. break;
  114. pS->pZ += iZStep;
  115. pS->pSurface += iSurfaceStep;
  116. // don't update this in dithered write functions because of alpha test
  117. // ATTENTION could specialize loop routines based on things like dither and Z buffer
  118. pCtx->SI.uDitherOffset = (pCtx->SI.uDitherOffset + (pCtx->SI.iXStep<<2)) & 0xf;
  119. #ifdef DBG
  120. // handy for debug to see where we are
  121. pS->uX += (INT16)pCtx->SI.iXStep;
  122. #endif
  123. }
  124. }