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.

101 lines
3.1 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 2000.
  3. //
  4. // refrasti.hpp
  5. //
  6. // Direct3D Reference Device - Main Internal Header File
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _REFRASTI_HPP
  10. #define _REFRASTI_HPP
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // //
  13. // Texture Mapping Utility Functions //
  14. // //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. //
  17. // various approximations and tricks to speed up the texture map coverage
  18. // computations
  19. //
  20. // Integer value of first exponent bit in a float. Provides a scaling factor
  21. // for exponent values extracted directly from float representation.
  22. #define FLOAT_EXPSCALE ((FLOAT)0x00800000)
  23. #define FLOAT_OOEXPSCALE ((FLOAT)(1.0 / (double)FLOAT_EXPSCALE))
  24. // Integer representation of 1.0f.
  25. #define INT32_FLOAT_ONE 0x3f800000
  26. static inline FLOAT
  27. RR_LOG2(FLOAT f)
  28. {
  29. return (FLOAT)(AS_INT32(f) - INT32_FLOAT_ONE) * FLOAT_OOEXPSCALE;
  30. }
  31. static inline FLOAT
  32. RR_ALOG2(FLOAT f)
  33. {
  34. INT32 i = (INT32)(f * FLOAT_EXPSCALE) + INT32_FLOAT_ONE;
  35. return AS_FLOAT((long int)i);
  36. }
  37. static inline FLOAT
  38. RR_ABSF(FLOAT f)
  39. {
  40. UINT32 i = AS_UINT32(f) & 0x7fffffff;
  41. return AS_FLOAT((unsigned long int)i);
  42. }
  43. static inline FLOAT
  44. RR_SQRT(FLOAT f)
  45. {
  46. INT32 i = (AS_INT32(f) >> 1) + (INT32_FLOAT_ONE >> 1);
  47. return AS_FLOAT((long int)i);
  48. }
  49. //
  50. // Steve Gabriel's version of an octagonal approximation euclidian distance -
  51. // return is approximating sqrt(fX*fX + fY*fY)
  52. //
  53. static inline FLOAT
  54. RR_LENGTH(FLOAT fX, FLOAT fY)
  55. {
  56. fX = RR_ABSF(fX);
  57. fY = RR_ABSF(fY);
  58. return ((11.0f/32.0f)*(fX + fY) + (21.0f/32.0f)*max(fX, fY));
  59. }
  60. // compute level of detail (texel->pixel coverage)
  61. void
  62. ComputeSimpleLevelOfDetail(
  63. const RDTextureCoord& TCoord, // inputs
  64. FLOAT& fLOD ); // outputs
  65. void
  66. ComputeCubeMapLevelOfDetail(
  67. const RDTextureCoord& TCoord, // inputs
  68. FLOAT& fLOD ); // outputs
  69. void
  70. ComputeAnisotropicLevelOfDetail(
  71. const RDTextureCoord& TCoord, FLOAT fMaxAniso, // inputs
  72. FLOAT& fLOD, FLOAT& fRatio, FLOAT fDelta[] ); // outputs
  73. // color interpolation utilities
  74. void LerpColor(RDColor& Color,
  75. const RDColor& Color0, const RDColor& Color1, UINT8 uT);
  76. void BiLerpColor( RDColor& OutColor,
  77. const RDColor& Color00, const RDColor& Color01,
  78. const RDColor& Color10, const RDColor& Color11,
  79. UINT8 uA, UINT8 uB);
  80. void BiLerpColor3D( RDColor& OutColor,
  81. const RDColor& Color000, const RDColor& Color010,
  82. const RDColor& Color100, const RDColor& Color110,
  83. const RDColor& Color001, const RDColor& Color011,
  84. const RDColor& Color101, const RDColor& Color111,
  85. UINT8 uA, UINT8 uB, UINT8 uC);
  86. ///////////////////////////////////////////////////////////////////////////////
  87. #endif // _REFRASTI_HPP