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.

90 lines
3.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // rastedge.cpp
  5. //
  6. // Direct3D Reference Device - Edge Function Processing
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. //-----------------------------------------------------------------------------
  12. //
  13. // Set - Computes edge function and associated information.
  14. //
  15. //-----------------------------------------------------------------------------
  16. void
  17. RDEdge::Set(
  18. BOOL bDetPositive,
  19. INT32 iX0, INT32 iY0,
  20. INT32 iX1, INT32 iY1)
  21. {
  22. // compute A,B (gradient) terms - these are n.4 fixed point
  23. m_iA = iY0 - iY1;
  24. m_iB = iX1 - iX0;
  25. // flip gradient signs if backfacing so functions are consistently
  26. // greater than zero outside of primitive
  27. if ( bDetPositive ) { m_iA = -m_iA; m_iB = -m_iB; }
  28. // compute C term
  29. //
  30. // function is by definition zero at the vertices, so:
  31. // 0 = A*Xv + B*Yv + C => C = - A*Xv - B*Yv
  32. //
  33. // A*Xv & B*Yv are n.4 * n.4 = n.8, so C is n.8 fixed point
  34. m_iC = - ( (INT64)iX0 * (INT64)m_iA ) - ( (INT64)iY0 * (INT64)m_iB );
  35. // compute edge function sign flags - must be done consistently for vertical
  36. // and horizontal cases to adhere to point sample fill rules
  37. BOOL bEdgeAEQZero = ( m_iA == 0. );
  38. BOOL bEdgeBEQZero = ( m_iB == 0. );
  39. BOOL bEdgeAGTZero = ( m_iA > 0. );
  40. BOOL bEdgeBGTZero = ( m_iB > 0. );
  41. m_bAPos = bEdgeAEQZero ? bEdgeBGTZero : bEdgeAGTZero;
  42. m_bBPos = bEdgeBEQZero ? bEdgeAGTZero : bEdgeBGTZero;
  43. }
  44. //-----------------------------------------------------------------------------
  45. //
  46. // Supports the Direct3D left-top fill rule.
  47. //
  48. // inputs are n.4 floating point
  49. //
  50. //-----------------------------------------------------------------------------
  51. BOOL
  52. RDEdge::Test( INT32 iX, INT32 iY )
  53. {
  54. // evaluate edge distance function (n.8 fixed point)
  55. INT64 iEdgeDist =
  56. ( (INT64)m_iA * (INT64)iX ) + // n.4 * n.4 = n.8
  57. ( (INT64)m_iB * (INT64)iY ) + // n.4 * n.4 = n.8
  58. (INT64)m_iC; // n.8
  59. // pixel sample position is outside edge if distance is > zero
  60. //
  61. // This implements the D3D left-top fill rule
  62. //
  63. // For exactly-on-edge case (distance == zero), the sign of the Y gradient
  64. // is used to determine if the pixel is to be considered inside or outside
  65. // of the edge. For the non-horizontal case, the m_bAPos bit is based
  66. // simply on the sign of the Y slope. This implements the 'left' part of
  67. // the 'left-top' rule.
  68. //
  69. // For the horizontal case, the sign of the B gradient (X slope) is taken
  70. // into account in the computation of the m_bAPos bit when the A gradient
  71. // is exactly zero, which forces a pixel exactly on a 'top' edge to be
  72. // considered in and a pixel exactly on a 'bottom' edge to be considered out.
  73. //
  74. if ( ( iEdgeDist > 0 ) || ( ( iEdgeDist == 0 ) && m_bAPos ) )
  75. {
  76. // pixel is out
  77. return FALSE;
  78. }
  79. // pixel is in
  80. return TRUE;
  81. }
  82. ///////////////////////////////////////////////////////////////////////////////
  83. // end