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.

211 lines
7.5 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // d3dutil.h
  4. //
  5. // Miscellaneous utility declarations.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #ifndef _D3DUTIL_H_
  11. #define _D3DUTIL_H_
  12. #include <d3dflt.h>
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. // Stub function that should never be called. Prints a warning and
  17. // DebugBreaks. Can be inserted in any function table, although it
  18. // will destroy the stack frame with callconv or argument mismatch.
  19. // That's OK since if it's called something has gone wrong.
  20. void FASTCALL
  21. DebugBreakFn(void);
  22. // Texture coordinate difference.
  23. FLOAT FASTCALL
  24. TextureDiff(FLOAT fTb, FLOAT fTa, INT iMode);
  25. // Inline texture coordinate difference.
  26. __inline FLOAT
  27. InlTextureDiff(FLOAT fTb, FLOAT fTa, INT iMode)
  28. #include <texdiff.h>
  29. // Returns a good approximation to sqrt(fX*fX + fY*fY)
  30. FLOAT FASTCALL
  31. OctagonNorm(FLOAT fX, FLOAT fY);
  32. // LOD computation.
  33. INT FASTCALL
  34. ComputeLOD(CONST struct tagD3DI_RASTCTX *pCtx,
  35. FLOAT fU, FLOAT fV, FLOAT fW,
  36. FLOAT fDUoWDX, FLOAT fDVoWDX, FLOAT fDOoWDX,
  37. FLOAT fDUoWDY, FLOAT fDVoWDY, FLOAT fDOoWDY);
  38. // Table fog value computation.
  39. UINT FASTCALL
  40. ComputeTableFog(PDWORD pdwRenderState, FLOAT fZ);
  41. // Compute integer log2 for exact powers of 2.
  42. UINT32 FASTCALL
  43. IntLog2(UINT32 x);
  44. //
  45. // D3DVECTOR operations.
  46. //
  47. #define pVecLenSq(pVec) \
  48. pVecDot(pVec, pVec)
  49. #define pVecLen(pVec) \
  50. SQRTF(pVecLenSq(pVec))
  51. void FASTCALL
  52. pVecNormalize2(LPD3DVECTOR pVec, LPD3DVECTOR pRes);
  53. #define pVecNormalize(pVec) pVecNormalize2(pVec, pVec)
  54. #define VecNormalize(Vec) pVecNormalize(&(Vec))
  55. #define VecNormalize2(Vec, Res) pVecNormalize2(&(Vec), &(Res))
  56. #define pVecDot(pVec1, pVec2) \
  57. ((pVec1)->x * (pVec2)->x + (pVec1)->y * (pVec2)->y + \
  58. (pVec1)->z * (pVec2)->z)
  59. #define pVecAdd(pVec1, pVec2, pRes) \
  60. ((pRes)->x = (pVec1)->x + (pVec2)->x, \
  61. (pRes)->y = (pVec1)->y + (pVec2)->y, \
  62. (pRes)->z = (pVec1)->z + (pVec2)->z)
  63. #define pVecSub(pVec1, pVec2, pRes) \
  64. ((pRes)->x = (pVec1)->x - (pVec2)->x, \
  65. (pRes)->y = (pVec1)->y - (pVec2)->y, \
  66. (pRes)->z = (pVec1)->z - (pVec2)->z)
  67. #define pVecScale(pVec, fScale, pRes) \
  68. ((pRes)->x = (pVec)->x * (fScale), \
  69. (pRes)->y = (pVec)->y * (fScale), \
  70. (pRes)->z = (pVec)->z * (fScale))
  71. #define pVecNeg(pVec, pRes) \
  72. ((pRes)->x = NEGF((pVec)->x), \
  73. (pRes)->y = NEGF((pVec)->y), \
  74. (pRes)->z = NEGF((pVec)->z))
  75. #define pVecSet(pVec, fX, fY, fZ) \
  76. ((pVec)->x = (fX), (pVec)->y = (fY), (pVec)->z = (fZ))
  77. #define VecLenSq(Vec) pVecLenSq(&(Vec))
  78. #define VecLen(Vec) pVecLen(&(Vec))
  79. #ifdef _X86_
  80. // Vector normalize through a table
  81. void FASTCALL TableVecNormalize(float *result, float *normal);
  82. // Vector normalize using Jim Blinn's floating point trick
  83. void FASTCALL JBVecNormalize(float *result, float *normal);
  84. #define VecNormalizeFast(Vec) TableVecNormalize((float*)&(Vec), (float*)&(Vec))
  85. #define VecNormalizeFast2(Vec, Res) TableVecNormalize((float*)&(Res), (float*)&(Vec))
  86. #define pVecNormalizeFast(Vec) TableVecNormalize((float*)pVec, (float*)pVec)
  87. #define pVecNormalizeFast2(pVec, pRes) TableVecNormalize((float*)pRes, (float*)pVec)
  88. #else
  89. #define VecNormalizeFast(Vec) pVecNormalize(&(Vec))
  90. #define VecNormalizeFast2(Vec, Res) pVecNormalize2(&(Vec), &(Res))
  91. #define pVecNormalizeFast(pVec) pVecNormalize(pVec)
  92. #define pVecNormalizeFast2(pVec, pRes) pVecNormalize2(pVec, pRes)
  93. #endif // _X86_
  94. #define VecDot(Vec1, Vec2) pVecDot(&(Vec1), &(Vec2))
  95. #define VecAdd(Vec1, Vec2, Res) pVecAdd(&(Vec1), &(Vec2), &(Res))
  96. #define VecSub(Vec1, Vec2, Res) pVecSub(&(Vec1), &(Vec2), &(Res))
  97. #define VecScale(Vec1, fScale, Res) pVecScale(&(Vec1), fScale, &(Res))
  98. #define VecNeg(Vec, Res) pVecNeg(&(Vec), &(Res))
  99. #define VecSet(Vec, fX, fY, fZ) pVecSet(&(Vec), fX, fY, fZ)
  100. //---------------------------------------------------------------------
  101. // Convert homogeneous vector to 3D vector
  102. //
  103. // Returns:
  104. // 0 - if success
  105. // -1 - v.w == 0
  106. //
  107. __inline int Vector4to3D(D3DVECTORH *v)
  108. {
  109. if (v->w == 0)
  110. return -1;
  111. D3DVALUE k = 1.0f/v->w;
  112. v->x *= k;
  113. v->y *= k;
  114. v->z *= k;
  115. v->w = (D3DVALUE) 1;
  116. return 0;
  117. }
  118. //---------------------------------------------------------------------
  119. // Multiplies vector (x,y,z,1) by 4x4 matrix, producing a homogeneous vector
  120. //
  121. // res and v should not be the same
  122. //
  123. __inline void VecMatMul4(D3DVECTOR *v, D3DMATRIX *m, D3DVECTORH *res)
  124. {
  125. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  126. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  127. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  128. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + m->_44;
  129. }
  130. //---------------------------------------------------------------------
  131. // Multiplies vector (x,y,z,1) by 4x3 matrix
  132. //
  133. // res and v should not be the same
  134. //
  135. __inline void VecMatMul(D3DVECTOR *v, D3DMATRIX *m, D3DVECTOR *res)
  136. {
  137. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  138. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  139. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  140. }
  141. //---------------------------------------------------------------------
  142. // Builds normalized plane equations going through 3 points
  143. //
  144. // Returns:
  145. // 0 - if success
  146. // -1 - if can not build plane
  147. //
  148. int MakePlane(D3DVECTOR *v1, D3DVECTOR *v2, D3DVECTOR *v3,
  149. D3DVECTORH *plane);
  150. //---------------------------------------------------------------------
  151. // This function uses Cramer's Rule to calculate the matrix inverse.
  152. // See nt\private\windows\opengl\serever\soft\so_math.c
  153. //
  154. // Returns:
  155. // 0 - if success
  156. // -1 - if input matrix is singular
  157. //
  158. int Inverse4x4(D3DMATRIX *src, D3DMATRIX *inverse);
  159. //---------------------------------------------------------------------
  160. // Checks the FVF flags for errors and returns the stride in bytes between
  161. // vertices.
  162. //
  163. // Returns:
  164. // HRESULT and stride in bytes between vertices
  165. //
  166. //---------------------------------------------------------------------
  167. HRESULT FASTCALL
  168. FVFCheckAndStride(DWORD dwFVF, DWORD* pdwStride);
  169. //---------------------------------------------------------------------
  170. // Gets the value from DIRECT3D registry key
  171. // Returns TRUE if success
  172. // If fails value is not changed
  173. //
  174. BOOL GetD3DRegValue(DWORD type, char *valueName, LPVOID value, DWORD dwSize);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif // #ifndef _D3DUTIL_H_