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.

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