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.

210 lines
9.6 KiB

  1. /*============================ ==============================================;
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: clipper.h
  6. * Content: Clipper definitions
  7. *
  8. ***************************************************************************/
  9. #ifndef _CLIPPER_H_
  10. #define _CLIPPER_H_
  11. #define INTERPOLATE_COLOR (1<< 0)
  12. #define INTERPOLATE_SPECULAR (1<< 1)
  13. #define INTERPOLATE_TEXTUREL (1<< 2) // legacy-related texture
  14. #define INTERPOLATE_RCOLOR (1<< 3)
  15. #define INTERPOLATE_TEXTURE3 (1<< 4) // interpolate Texture3
  16. #define CLIPPED_LEFT (D3DCLIP_GEN5 << 1)
  17. #define CLIPPED_RIGHT (D3DCLIP_GEN5 << 2)
  18. #define CLIPPED_TOP (D3DCLIP_GEN5 << 3)
  19. #define CLIPPED_BOTTOM (D3DCLIP_GEN5 << 4)
  20. #define CLIPPED_FRONT (D3DCLIP_GEN5 << 5)
  21. #define CLIPPED_BACK (D3DCLIP_GEN5 << 6)
  22. #define CLIPPED_ENABLE (D3DCLIP_GEN5 << 7) /* wireframe enable flag */
  23. #define CLIPPED_ALL (CLIPPED_LEFT|CLIPPED_RIGHT \
  24. |CLIPPED_TOP|CLIPPED_BOTTOM \
  25. |CLIPPED_FRONT|CLIPPED_BACK)
  26. //---------------------------------------------------------------------
  27. // Guard band clipping bits
  28. //
  29. // A guard bit is set when a point is out of guard band
  30. // Guard bits should be cleared before a call to clip a triangle, because
  31. // they are the same as CLIPPED_... bits
  32. //
  33. // Example of clipping bits setting for X coordinate:
  34. //
  35. // if -w < x < w no clipping bit is set
  36. // if -w*ax1 < x <= -w D3DCLIP_LEFT bit is set
  37. // if x < -w*ax1 __D3DCLIPGB_LEFT bit is set
  38. //
  39. #define __D3DCLIPGB_LEFT (D3DCLIP_GEN5 << 1)
  40. #define __D3DCLIPGB_RIGHT (D3DCLIP_GEN5 << 2)
  41. #define __D3DCLIPGB_TOP (D3DCLIP_GEN5 << 3)
  42. #define __D3DCLIPGB_BOTTOM (D3DCLIP_GEN5 << 4)
  43. #define __D3DCLIPGB_ALL (__D3DCLIPGB_LEFT | __D3DCLIPGB_RIGHT | \
  44. __D3DCLIPGB_TOP | __D3DCLIPGB_BOTTOM)
  45. // If only these bits are set, then this point is inside the guard band
  46. //
  47. #define __D3DCLIP_INGUARDBAND (D3DCLIP_LEFT | D3DCLIP_RIGHT | \
  48. D3DCLIP_TOP | D3DCLIP_BOTTOM)
  49. //---------------------------------------------------------------------
  50. // Bit numbers for each clip flag
  51. //
  52. #define D3DCLIP_LEFTBIT 1
  53. #define D3DCLIP_RIGHTBIT 2
  54. #define D3DCLIP_TOPBIT 3
  55. #define D3DCLIP_BOTTOMBIT 4
  56. #define D3DCLIP_FRONTBIT 5
  57. #define D3DCLIP_BACKBIT 6
  58. #define D3DCLIPGB_LEFTBIT 13
  59. #define D3DCLIPGB_RIGHTBIT 14
  60. #define D3DCLIPGB_TOPBIT 15
  61. #define D3DCLIPGB_BOTTOMBIT 16
  62. //---------------------------------------------------------------------
  63. // Make clip vertex from D3D vertex
  64. //
  65. // device - DIRECT3DDEVICEI *
  66. // pp1 - clipVertex
  67. // p1 - TL vertex
  68. // clipMask is set to the guard band bits or 0xFFFFFFFFF
  69. //
  70. inline void MAKE_CLIP_VERTEX(D3DFE_PROCESSVERTICES *pv, ClipVertex& pp1,
  71. D3DTLVERTEX* p1, DWORD clipFlag,
  72. BOOL transformed, DWORD clipMaskOffScreen)
  73. {
  74. D3DFE_VIEWPORTCACHE& VPORT = pv->vcache;
  75. if (transformed || !(clipFlag & clipMaskOffScreen))
  76. {
  77. pp1.sx = p1->sx;
  78. pp1.sy = p1->sy;
  79. pp1.sz = p1->sz;
  80. pp1.hw = 1.0f / p1->rhw;
  81. pp1.hx = (pp1.sx - VPORT.offsetX) * pp1.hw *
  82. VPORT.scaleXi;
  83. pp1.hy = (pp1.sy - VPORT.offsetY) * pp1.hw *
  84. VPORT.scaleYi;
  85. pp1.hz = pp1.sz * pp1.hw;
  86. }
  87. else
  88. {
  89. pp1.hx = p1->sx;
  90. pp1.hy = p1->sy;
  91. pp1.hz = p1->sz;
  92. pp1.hw = p1->rhw;
  93. }
  94. pp1.color = p1->color;
  95. pp1.specular= p1->specular;
  96. pp1.tex[0].u = p1->tu;
  97. pp1.tex[0].v = p1->tv;
  98. pp1.clip = clipFlag & D3DSTATUS_CLIPUNIONALL;
  99. }
  100. //---------------------------------------------------------------------
  101. // Make TL vertex from clip vertex
  102. //
  103. // device - DIRECT3DDEVICEI *
  104. // in - clipVertex
  105. // out - TL vertex
  106. //
  107. inline void MAKE_TL_VERTEX(D3DTLVERTEX* out, ClipVertex* in)
  108. {
  109. (out)->sx = (in)->sx;
  110. (out)->sy = (in)->sy;
  111. (out)->sz = (in)->sz;
  112. (out)->rhw = D3DVAL(1)/(in)->hw;
  113. (out)->color = (in)->color;
  114. (out)->specular= (in)->specular;
  115. (out)->tu = (in)->tex[0].u;
  116. (out)->tv = (in)->tex[0].v;
  117. }
  118. //---------------------------------------------------------------------
  119. // Make clip vertex from D3D vertex
  120. //
  121. // device - DIRECT3DDEVICEI *
  122. // pp1 - clipVertex
  123. // p1 - TL vertex
  124. //
  125. inline void MAKE_CLIP_VERTEX_FVF(D3DFE_PROCESSVERTICES *pv, ClipVertex& pp1, BYTE* p1,
  126. DWORD clipFlag, BOOL transformed, DWORD clipMaskOffScreen)
  127. {
  128. D3DFE_VIEWPORTCACHE& VPORT = pv->vcache;
  129. BYTE *v = (BYTE*)p1;
  130. if (transformed || !(clipFlag & clipMaskOffScreen))
  131. {
  132. pp1.sx = ((D3DVALUE*)v)[0];
  133. pp1.sy = ((D3DVALUE*)v)[1];
  134. pp1.sz = ((D3DVALUE*)v)[2];
  135. pp1.hw = 1.0f / ((D3DVALUE*)v)[3];
  136. pp1.hx = (pp1.sx - VPORT.offsetX) * pp1.hw *
  137. VPORT.scaleXi;
  138. pp1.hy = (pp1.sy - VPORT.offsetY) * pp1.hw *
  139. VPORT.scaleYi;
  140. pp1.hz = pp1.sz * pp1.hw;
  141. }
  142. else
  143. {
  144. pp1.hx = ((D3DVALUE*)v)[0];
  145. pp1.hy = ((D3DVALUE*)v)[1];
  146. pp1.hz = ((D3DVALUE*)v)[2];
  147. pp1.hw = ((D3DVALUE*)v)[3];
  148. }
  149. v += sizeof(D3DVALUE) * 4;
  150. if (pv->dwVIDOut & D3DFVF_DIFFUSE)
  151. {
  152. pp1.color = *(DWORD*)v;
  153. v += sizeof(D3DVALUE);
  154. }
  155. if (pv->dwVIDOut & D3DFVF_SPECULAR)
  156. {
  157. pp1.specular= *(DWORD*)v;
  158. v += sizeof(DWORD);
  159. }
  160. for (DWORD ii=0; ii < pv->nTexCoord; ii++)
  161. {
  162. pp1.tex[ii].u = *(D3DVALUE*)v;
  163. v += sizeof(D3DVALUE);
  164. pp1.tex[ii].v = *(D3DVALUE*)v;
  165. v += sizeof(D3DVALUE);
  166. }
  167. pp1.clip = clipFlag; // & D3DSTATUS_CLIPUNIONALL;
  168. }
  169. //---------------------------------------------------------------------
  170. // Make TL vertex from clip vertex
  171. //
  172. // device - DIRECT3DDEVICEI *
  173. // in - clipVertex
  174. // out - TL vertex
  175. //
  176. inline void MAKE_TL_VERTEX_FVF(D3DFE_PROCESSVERTICES *pv, BYTE* out, ClipVertex* in)
  177. {
  178. BYTE *v = out;
  179. ((D3DVALUE*)v)[0] = (in)->sx;
  180. ((D3DVALUE*)v)[1] = (in)->sy;
  181. ((D3DVALUE*)v)[2] = (in)->sz;
  182. ((D3DVALUE*)v)[3] = D3DVAL(1)/(in)->hw;
  183. v += sizeof(D3DVALUE)*4;
  184. if (pv->dwVIDOut & D3DFVF_DIFFUSE)
  185. {
  186. *(DWORD*)v = (in)->color;
  187. v += sizeof(DWORD);
  188. }
  189. if (pv->dwVIDOut & D3DFVF_SPECULAR)
  190. {
  191. *(DWORD*)v = (in)->specular;
  192. v += sizeof(DWORD);
  193. }
  194. for (DWORD ii=0; ii < pv->nTexCoord; ii++)
  195. {
  196. *(D3DVALUE*)v = (in)->tex[ii].u;
  197. v += sizeof(D3DVALUE);
  198. *(D3DVALUE*)v = (in)->tex[ii].v;
  199. v += sizeof(D3DVALUE);
  200. }
  201. }
  202. #endif // _CLIPPER_H_