Source code of Windows XP (NT5)
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.

152 lines
5.4 KiB

  1. #ifndef __CLIPPER_HPP_
  2. #define __CLIPPER_HPP_
  3. //----------------------------------------------------------------------------
  4. // Clipping macros
  5. //----------------------------------------------------------------------------
  6. // Interpolation flags
  7. #define RDCLIP_INTERPOLATE_COLOR (1<< 0)
  8. #define RDCLIP_INTERPOLATE_SPECULAR (1<< 1)
  9. #define RDCLIP_INTERPOLATE_TEXTURE (1<< 2)
  10. #define RDCLIP_INTERPOLATE_S (1<< 3)
  11. #define RDCLIP_INTERPOLATE_FOG (1<< 4)
  12. // Non guardband clipping bits
  13. #define RDCLIP_LEFT D3DCS_LEFT
  14. #define RDCLIP_RIGHT D3DCS_RIGHT
  15. #define RDCLIP_TOP D3DCS_TOP
  16. #define RDCLIP_BOTTOM D3DCS_BOTTOM
  17. #define RDCLIP_FRONT D3DCS_FRONT
  18. #define RDCLIP_BACK D3DCS_BACK
  19. //----------------------------------------------------------------------------
  20. // User define clip plane bits.
  21. // Each of these bits is set if the vertex is clipped by the associated
  22. // clip plane.
  23. //----------------------------------------------------------------------------
  24. #define RDCLIP_USERCLIPPLANE0 D3DCS_PLANE0
  25. #define RDCLIP_USERCLIPPLANE1 D3DCS_PLANE1
  26. #define RDCLIP_USERCLIPPLANE2 D3DCS_PLANE2
  27. #define RDCLIP_USERCLIPPLANE3 D3DCS_PLANE3
  28. #define RDCLIP_USERCLIPPLANE4 D3DCS_PLANE4
  29. #define RDCLIP_USERCLIPPLANE5 D3DCS_PLANE5
  30. const DWORD RDCLIP_USERPLANES_ALL = (RDCLIP_USERCLIPPLANE0 |
  31. RDCLIP_USERCLIPPLANE1 |
  32. RDCLIP_USERCLIPPLANE2 |
  33. RDCLIP_USERCLIPPLANE3 |
  34. RDCLIP_USERCLIPPLANE4 |
  35. RDCLIP_USERCLIPPLANE5 );
  36. //---------------------------------------------------------------------
  37. // Guard band clipping bits
  38. //
  39. // A guard bit is set when a point is out of guard band
  40. // Guard bits should be cleared before a call to clip a triangle, because
  41. // they are the same as CLIPPED_... bits
  42. //
  43. // Example of clipping bits setting for X coordinate:
  44. //
  45. // if -w < x < w no clipping bit is set
  46. // if -w*ax1 < x <= -w RDCLIP_LEFT bit is set
  47. // if x < -w*ax1 RDCLIPGB_LEFT bit is set
  48. //---------------------------------------------------------------------
  49. #define RDCLIPGB_LEFT (RDCLIP_USERCLIPPLANE5 << 1)
  50. #define RDCLIPGB_RIGHT (RDCLIP_USERCLIPPLANE5 << 2)
  51. #define RDCLIPGB_TOP (RDCLIP_USERCLIPPLANE5 << 3)
  52. #define RDCLIPGB_BOTTOM (RDCLIP_USERCLIPPLANE5 << 4)
  53. #define RDCLIP_ALL (RDCLIP_LEFT | RDCLIP_RIGHT | \
  54. RDCLIP_TOP | RDCLIP_BOTTOM | \
  55. RDCLIP_FRONT | RDCLIP_BACK | \
  56. RDCLIP_USERPLANES_ALL)
  57. #define RDCLIPGB_ALL (RDCLIPGB_LEFT | RDCLIPGB_RIGHT | \
  58. RDCLIPGB_TOP | RDCLIPGB_BOTTOM | \
  59. RDCLIP_FRONT | RDCLIP_BACK | \
  60. RDCLIP_USERPLANES_ALL)
  61. // If only these bits are set, then this point is inside the guard band
  62. #define RDCLIP_INGUARDBAND (RDCLIP_LEFT | RDCLIP_RIGHT | \
  63. RDCLIP_TOP | RDCLIP_BOTTOM)
  64. //---------------------------------------------------------------------
  65. // Bit numbers for each clip flag
  66. //
  67. #define RDCLIP_LEFTBIT 1
  68. #define RDCLIP_RIGHTBIT 2
  69. #define RDCLIP_TOPBIT 3
  70. #define RDCLIP_BOTTOMBIT 4
  71. #define RDCLIP_FRONTBIT 5
  72. #define RDCLIP_BACKBIT 6
  73. #define RDCLIP_USERCLIPLANE0BIT 7
  74. #define RDCLIP_USERCLIPLANE1BIT 8
  75. #define RDCLIP_USERCLIPLANE2BIT 9
  76. #define RDCLIP_USERCLIPLANE3BIT 10
  77. #define RDCLIP_USERCLIPLANE4BIT 11
  78. #define RDCLIP_USERCLIPLANE5BIT 12
  79. #define RDCLIPGB_LEFTBIT 13
  80. #define RDCLIPGB_RIGHTBIT 14
  81. #define RDCLIPGB_TOPBIT 15
  82. #define RDCLIPGB_BOTTOMBIT 16
  83. #define CLIPPED_LEFT (RDCLIP_USERCLIPPLANE5 << 1)
  84. #define CLIPPED_RIGHT (RDCLIP_USERCLIPPLANE5 << 2)
  85. #define CLIPPED_TOP (RDCLIP_USERCLIPPLANE5 << 3)
  86. #define CLIPPED_BOTTOM (RDCLIP_USERCLIPPLANE5 << 4)
  87. #define CLIPPED_FRONT (RDCLIP_USERCLIPPLANE5 << 5)
  88. #define CLIPPED_BACK (RDCLIP_USERCLIPPLANE5 << 6)
  89. #define CLIPPED_ENABLE (RDCLIP_USERCLIPPLANE5 << 7) // wireframe enable flag
  90. #define CLIPPED_ALL (CLIPPED_LEFT|CLIPPED_RIGHT \
  91. |CLIPPED_TOP|CLIPPED_BOTTOM \
  92. |CLIPPED_FRONT|CLIPPED_BACK)
  93. const DWORD CLIPPED_USERCLIPPLANE0 = RDCLIP_USERCLIPPLANE5 << 8;
  94. const DWORD CLIPPED_USERCLIPPLANE1 = RDCLIP_USERCLIPPLANE5 << 9;
  95. const DWORD CLIPPED_USERCLIPPLANE2 = RDCLIP_USERCLIPPLANE5 << 10;
  96. const DWORD CLIPPED_USERCLIPPLANE3 = RDCLIP_USERCLIPPLANE5 << 11;
  97. const DWORD CLIPPED_USERCLIPPLANE4 = RDCLIP_USERCLIPPLANE5 << 12;
  98. const DWORD CLIPPED_USERCLIPPLANE5 = RDCLIP_USERCLIPPLANE5 << 13;
  99. //---------------------------------------------------------------------
  100. // Make RDVertex from clip vertex
  101. //
  102. // in - clipVertex
  103. // out - RD vertex
  104. //---------------------------------------------------------------------
  105. inline void
  106. MakeVertexFromClipVertex( RDVertex& v, RDClipVertex& cv )
  107. {
  108. memcpy( &v, &cv, sizeof( RDVertex ) );
  109. #if 0
  110. v.m_rhw = D3DVAL(1)/cv.m_clip_w;
  111. #endif
  112. }
  113. //---------------------------------------------------------------------
  114. // Returns TRUE if clipping is needed
  115. //---------------------------------------------------------------------
  116. inline BOOL
  117. NeedClipping(BOOL bUseGB, RDCLIPCODE clipUnion)
  118. {
  119. if( bUseGB && (clipUnion & ~RDCLIP_INGUARDBAND) )
  120. {
  121. return TRUE;
  122. }
  123. else if( clipUnion )
  124. {
  125. return TRUE;
  126. }
  127. return FALSE;
  128. }
  129. #endif //__CLIPPER_HPP_