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.

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