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.

139 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. for (INT32 i = 0; i < (INT32)pCtx->cActTex; i ++)
  63. {
  64. pCtx->SI.TexUV[i].iU = d_WTimesUVoW(pS->iW,pS->UVoW[i].iUoW);
  65. pCtx->SI.TexUV[i].iV = d_WTimesUVoW(pS->iW,pS->UVoW[i].iVoW);
  66. }
  67. pCtx->SI.iDW = 0x0;
  68. if (pP->iDOoWDX > 0)
  69. {
  70. // iSpecialW should be negative for the first 3 pixels of span
  71. pCtx->SI.iSpecialW = -3;
  72. }
  73. else
  74. {
  75. // iSpecialW should be negative for the last 3 pixels of span
  76. pCtx->SI.iSpecialW = 0x7fff - uPix;
  77. pCtx->SI.iSpecialW += 5; // this may wrap, but it should
  78. }
  79. }
  80. else
  81. {
  82. for (INT32 i = 0; i < (INT32)pCtx->cActTex; i ++)
  83. {
  84. pCtx->SI.TexUV[i].iU = pS->UVoW[i].iUoW>>TEX_TO_FINAL_SHIFT; // 1.11.20 >> 4 == 1.15.16
  85. pCtx->SI.TexUV[i].iV = pS->UVoW[i].iVoW>>TEX_TO_FINAL_SHIFT;
  86. }
  87. pCtx->SI.iDW = 0x0;
  88. pCtx->SI.iSpecialW = 0;
  89. }
  90. INT iSurfaceStep;
  91. INT iZStep;
  92. if (pP->uFlags & D3DI_RASTPRIM_X_DEC)
  93. {
  94. iZStep = -pCtx->iZStep;
  95. iSurfaceStep = -pCtx->iSurfaceStep;
  96. pCtx->SI.iXStep = -1; // for dithering
  97. }
  98. else
  99. {
  100. iZStep = pCtx->iZStep;
  101. iSurfaceStep = pCtx->iSurfaceStep;
  102. pCtx->SI.iXStep = 1;
  103. }
  104. while (1)
  105. {
  106. #if 0
  107. // for debug, since breakpoints with conditions are really really slow
  108. if ((pS->uX == 104) && (pS->uY == 146))
  109. {
  110. DPF(0, "Look at this");
  111. }
  112. #endif
  113. pCtx->pfnLoopEnd(pCtx, pP, pS);
  114. if (--uPix <= 0)
  115. break;
  116. pS->pZ += iZStep;
  117. pS->pSurface += iSurfaceStep;
  118. // don't update this in dithered write functions because of alpha test
  119. // ATTENTION could specialize loop routines based on things like dither and Z buffer
  120. pCtx->SI.uDitherOffset = (pCtx->SI.uDitherOffset + (pCtx->SI.iXStep<<2)) & 0xf;
  121. #ifdef DBG
  122. // handy for debug to see where we are
  123. pS->uX += (INT16)pCtx->SI.iXStep;
  124. #endif
  125. }
  126. }