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.

171 lines
5.8 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: procver.h
  6. * Content: Generic implementation for process vertices function
  7. *
  8. * This file is included several times with different defines:
  9. * _PV_NAME - function name
  10. * _PV_EXTENT - if updating extent is required
  11. * _PV_CLIP - if clipping is required
  12. * _PV_VIEWPORT - if the function is used by TransformVertices call
  13. * _PV_LVERTEX - if D3DLVERTEX is used as input
  14. * _PV_APPLY_LIGHT - if lighting is required
  15. * _PV_FOG - if fog is required
  16. *
  17. ***************************************************************************/
  18. //--------------------------------------------------------------------------
  19. // Viewport->TransformVertices
  20. // For clipped and unclipped cases
  21. // for unclipped case H vertices should not be written
  22. //
  23. long _PV_NAME(D3DFE_PROCESSVERTICES *pv, DWORD count, LPD3DTRANSFORMDATAI data)
  24. {
  25. // We use power of 2 because it preserves the mantissa when we multiply
  26. const D3DVALUE __HUGE_PWR2 = 1024.0f*1024.0f*2.0f;
  27. CD3DFPstate D3DFPstate; // Sets optimal FPU state for D3D.
  28. D3DLVERTEX* in = (LPD3DLVERTEX)data->lpIn;
  29. size_t in_size = data->dwInSize;
  30. D3DTLVERTEX *out =(LPD3DTLVERTEX) data->lpOut;
  31. size_t out_size = data->dwOutSize;
  32. DWORD i;
  33. DWORD flags = pv->dwFlags;
  34. #ifdef _PV_CLIP
  35. D3DHVERTEX *hout = data->lpHOut;
  36. int clip_intersection = ~0;
  37. int clip_union = 0;
  38. #endif // _PV_CLIP
  39. D3DVALUE minx, maxx, miny, maxy;
  40. minx = data->drExtent.x1;
  41. miny = data->drExtent.y1;
  42. maxx = data->drExtent.x2;
  43. maxy = data->drExtent.y2;
  44. D3DFE_VIEWPORTCACHE& VPORT = pv->vcache;
  45. for (i = count; i; i--)
  46. {
  47. #ifdef _PV_CLIP
  48. int clip;
  49. #endif // _PV_CLIP
  50. float x, y, z, w, we;
  51. x = in->x*pv->mCTM._11 + in->y*pv->mCTM._21 +
  52. in->z*pv->mCTM._31 + pv->mCTM._41;
  53. y = in->x*pv->mCTM._12 + in->y*pv->mCTM._22 +
  54. in->z*pv->mCTM._32 + pv->mCTM._42;
  55. z = in->x*pv->mCTM._13 + in->y*pv->mCTM._23 +
  56. in->z*pv->mCTM._33 + pv->mCTM._43;
  57. we= in->x*pv->mCTM._14 + in->y*pv->mCTM._24 +
  58. in->z*pv->mCTM._34 + pv->mCTM._44;
  59. #ifdef _PV_CLIP
  60. hout->hx = x * VPORT.imclip11 + we * VPORT.imclip41;
  61. hout->hy = y * VPORT.imclip22 + we * VPORT.imclip42;
  62. hout->hz = z * VPORT.imclip33 + we * VPORT.imclip43;
  63. {
  64. D3DVALUE xx = we - x;
  65. D3DVALUE yy = we - y;
  66. D3DVALUE zz = we - z;
  67. clip = ((ASINT32(x) & 0x80000000) >> (32-1)) | // D3DCLIP_LEFT
  68. ((ASINT32(y) & 0x80000000) >> (32-4)) | // D3DCLIP_BOTTOM
  69. ((ASINT32(z) & 0x80000000) >> (32-5)) | // D3DCLIP_FRONT
  70. ((ASINT32(xx) & 0x80000000) >> (32-2)) | // D3DCLIP_RIGHT
  71. ((ASINT32(yy) & 0x80000000) >> (32-3)) | // D3DCLIP_TOP
  72. ((ASINT32(zz) & 0x80000000) >> (32-6)); // D3DCLIP_BACK
  73. }
  74. if (clip == 0)
  75. #endif // _PV_CLIP
  76. {
  77. w = D3DVAL(1)/we;
  78. #ifdef _PV_CLIP
  79. clip_intersection = 0;
  80. #endif // _PV_CLIP
  81. x = x * w * VPORT.scaleX + VPORT.offsetX;
  82. y = y * w * VPORT.scaleY + VPORT.offsetY;
  83. if (x < minx) minx = x;
  84. if (x > maxx) maxx = x;
  85. if (y < miny) miny = y;
  86. if (y > maxy) maxy = y;
  87. out->sx = x;
  88. out->sy = y;
  89. out->sz = z*w;
  90. out->rhw = w;
  91. }
  92. #ifdef _PV_CLIP
  93. else
  94. {
  95. if (!FLOAT_EQZ(we))
  96. out->rhw = D3DVAL(1)/we;
  97. else
  98. out->rhw = __HUGE_PWR2;
  99. clip_intersection &= clip;
  100. clip_union |= clip;
  101. }
  102. hout->dwFlags = clip;
  103. hout++;
  104. #endif // !_PV_CLIP
  105. out->tu = in->tu;
  106. out->tv = in->tv;
  107. out->color = in->color;
  108. out->specular = in->specular;
  109. in = (D3DLVERTEX*) ((char*) in + in_size);
  110. out = (D3DTLVERTEX*) ((char*) out + out_size);
  111. }
  112. /*
  113. * extend to cover lines. XXX
  114. */
  115. maxx += pv->dvExtentsAdjust;
  116. maxy += pv->dvExtentsAdjust;
  117. minx -= pv->dvExtentsAdjust;
  118. miny -= pv->dvExtentsAdjust;
  119. #ifndef _PV_CLIP
  120. /* Clamp to viewport */
  121. /* Clamp for legacy apps */
  122. if (minx < VPORT.minX || miny < VPORT.minY ||
  123. maxx > VPORT.maxX || maxy > VPORT.maxY)
  124. #endif // _PV_CLIP
  125. {
  126. /* Clamp to viewport */
  127. if (minx < VPORT.minX)
  128. minx = VPORT.minX;
  129. if (miny < VPORT.minY)
  130. miny = VPORT.minY;
  131. if (maxx > VPORT.maxX)
  132. maxx = VPORT.maxX;
  133. if (maxy > VPORT.maxY)
  134. maxy = VPORT.maxY;
  135. #ifndef _PV_CLIP
  136. if(pv->dwDeviceFlags & D3DDEV_PREDX5DEVICE)
  137. { /* Clamp vertices */
  138. int i;
  139. D3D_WARN(4, "Old semantics: Clamping Vertices");
  140. for (i = count, out = (LPD3DTLVERTEX)data->lpOut; i; i--)
  141. {
  142. if (out->sx < VPORT.minX) out->sx = VPORT.minX;
  143. if (out->sx > VPORT.maxX) out->sx = VPORT.maxX;
  144. if (out->sy < VPORT.minY) out->sy = VPORT.minY;
  145. if (out->sy > VPORT.maxY) out->sy = VPORT.maxY;
  146. out = (D3DTLVERTEX*) ((char*) out + out_size);
  147. }
  148. }
  149. #endif // _PV_CLIP
  150. }
  151. data->drExtent.x1 = minx;
  152. data->drExtent.y1 = miny;
  153. data->drExtent.x2 = maxx;
  154. data->drExtent.y2 = maxy;
  155. #ifdef _PV_CLIP
  156. data->dwClipIntersection = clip_intersection;
  157. data->dwClipUnion = clip_union;
  158. return clip_intersection;
  159. #else
  160. return 0;
  161. #endif // _PVCLIP
  162. }