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.

113 lines
4.5 KiB

  1. #ifndef __glfixed_h_
  2. #define __glfixed_h_
  3. /*
  4. ** Copyright 1991, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. */
  19. #include "types.h"
  20. #include "cpu.h"
  21. /*
  22. ** These constants in this file must be valid for all adapters using
  23. ** these macros and code which uses these macros.
  24. **
  25. ** These should be equal
  26. */
  27. #define __GL_MAX_WINDOW_SIZE_LOG2 14
  28. #define __GL_MAX_WINDOW_WIDTH (1 << __GL_MAX_WINDOW_SIZE_LOG2)
  29. #define __GL_MAX_WINDOW_HEIGHT __GL_MAX_WINDOW_WIDTH
  30. /*
  31. ** Bias numbers for moving window coordinates into a positive space.
  32. ** These values are used during viewport computations.
  33. **
  34. ** In our existing code this is only used to provide some buffer room
  35. ** in the vertex coordinate space to avoid any errors caused by
  36. ** small under- or overflows around the edge of the viewport caused
  37. ** by clip inaccuracy.
  38. **
  39. ** It must be less than the max window size so that the case of
  40. ** a point exactly at the max window value doesn't overflow
  41. ** the fixing range
  42. */
  43. #define __GL_VERTEX_X_BIAS (1 << (__GL_MAX_WINDOW_SIZE_LOG2-1))
  44. #define __GL_VERTEX_Y_BIAS __GL_VERTEX_X_BIAS
  45. /*
  46. ** Fixing numbers. These are used to move the biased window coordinates
  47. ** into a range where the number of fraction bits are constant from the
  48. ** minimal value in the range to the largest value in the range.
  49. **
  50. ** This value should be twice as large as the highest possible window
  51. ** coordinate value. Both values should be the same.
  52. **
  53. ** Having the bias in addition to this is important because in
  54. ** extreme cases the clipper can generate values slightly outside
  55. ** the clip range, due to FP inaccuracy. A slop bias in addition
  56. ** to the real fixing bias makes it impossible to underflow.
  57. */
  58. #define __GL_VERTEX_FIX_POINT (__GL_MAX_WINDOW_SIZE_LOG2+1)
  59. #define __GL_VERTEX_X_FIX (1 << __GL_VERTEX_FIX_POINT)
  60. #define __GL_VERTEX_Y_FIX __GL_VERTEX_X_FIX
  61. // The addition of the FIX bias to raw window coordinates forces the
  62. // MSB of the window coordinate to always be the same since the FIX
  63. // value is chosen to be the largest power of two greater than any
  64. // possibly window coordinate value. With the MSB pinned down, the
  65. // floating-point representation of a window coordinates degenerates to
  66. // a fixed-point number since the MSB doesn't change.
  67. //
  68. // We take advantage of this in conversions.
  69. #define __GL_VERTEX_FRAC_BITS \
  70. (__GL_FLOAT_MANTISSA_BITS-__GL_VERTEX_FIX_POINT)
  71. #define __GL_VERTEX_FRAC_HALF \
  72. (1 << (__GL_VERTEX_FRAC_BITS-1))
  73. #define __GL_VERTEX_FRAC_ONE \
  74. (1 << __GL_VERTEX_FRAC_BITS)
  75. // Converts a floating-point window coordinate to integer
  76. #define __GL_VERTEX_FLOAT_TO_INT(windowCoord) \
  77. __GL_FIXED_FLOAT_TO_INT(windowCoord, __GL_VERTEX_FRAC_BITS)
  78. // To fixed point
  79. #define __GL_VERTEX_FLOAT_TO_FIXED(windowCoord) \
  80. __GL_FIXED_FLOAT_TO_FIXED(windowCoord)
  81. // And back
  82. #define __GL_VERTEX_FIXED_TO_FLOAT(fxWindowCoord) \
  83. __GL_FIXED_TO_FIXED_FLOAT(fxWindowCoord, __GL_VERTEX_FRAC_BITS)
  84. // Fixed-point to integer
  85. #define __GL_VERTEX_FIXED_TO_INT(fxWindowCoord) \
  86. ((fxWindowCoord) >> __GL_VERTEX_FRAC_BITS)
  87. // Returns the fraction from a FP window coordinate as an N
  88. // bit integer, where N depends on the FP mantissa size and the
  89. // FIX size
  90. #define __GL_VERTEX_FLOAT_FRACTION(windowCoord) \
  91. __GL_FIXED_FLOAT_FRACTION(windowCoord, __GL_VERTEX_FRAC_BITS)
  92. // Scale the fraction to 2^31 for step values
  93. #define __GL_VERTEX_PROMOTE_FRACTION(frac) \
  94. ((frac) << (31-__GL_VERTEX_FRAC_BITS))
  95. #define __GL_VERTEX_PROMOTED_FRACTION(windowCoord) \
  96. __GL_VERTEX_PROMOTE_FRACTION(__GL_VERTEX_FLOAT_FRACTION(windowCoord))
  97. // Compare two window coordinates. Since window coordinates
  98. // are fixed-point numbers, they can be compared directly as
  99. // integers
  100. #define __GL_VERTEX_COMPARE(a, op, b) \
  101. ((*(LONG *)&(a)) op (*(LONG *)&(b)))
  102. #endif /* __glfixed_h_ */