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.

186 lines
5.3 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. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef D3DVECTOR* LPD3DVECTOR;
  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. {
  29. FLOAT fDiff1 = fTb - fTa;
  30. if (iMode == 0)
  31. {
  32. // Wrap not set, return plain difference.
  33. return fDiff1;
  34. }
  35. else
  36. {
  37. FLOAT fDiff2;
  38. // Wrap set, compute shortest distance of plain difference
  39. // and wrap difference.
  40. fDiff2 = fDiff1;
  41. if (FLOAT_LTZ(fDiff1))
  42. {
  43. fDiff2 += g_fOne;
  44. }
  45. else if (FLOAT_GTZ(fDiff1))
  46. {
  47. fDiff2 -= g_fOne;
  48. }
  49. if (ABSF(fDiff1) < ABSF(fDiff2))
  50. {
  51. return fDiff1;
  52. }
  53. else
  54. {
  55. return fDiff2;
  56. }
  57. }
  58. }
  59. // Returns a good approximation to sqrt(fX*fX + fY*fY)
  60. FLOAT FASTCALL
  61. OctagonNorm(FLOAT fX, FLOAT fY);
  62. // LOD computation.
  63. INT FASTCALL
  64. ComputeLOD(CONST struct tagD3DI_RASTCTX *pCtx,
  65. FLOAT fU, FLOAT fV, FLOAT fW,
  66. FLOAT fDUoWDX, FLOAT fDVoWDX, FLOAT fDOoWDX,
  67. FLOAT fDUoWDY, FLOAT fDVoWDY, FLOAT fDOoWDY);
  68. // Table fog value computation.
  69. UINT FASTCALL
  70. ComputeTableFog(PDWORD pdwRenderState, FLOAT fZ);
  71. // Compute integer log2 for exact powers of 2.
  72. UINT32 FASTCALL
  73. IntLog2(UINT32 x);
  74. //---------------------------------------------------------------------
  75. // Convert homogeneous vector to 3D vector
  76. //
  77. // Returns:
  78. // 0 - if success
  79. // -1 - v.w == 0
  80. //
  81. __inline int Vector4to3D(D3DVECTORH *v)
  82. {
  83. if (v->w == 0)
  84. return -1;
  85. D3DVALUE k = 1.0f/v->w;
  86. v->x *= k;
  87. v->y *= k;
  88. v->z *= k;
  89. v->w = 1;
  90. return 0;
  91. }
  92. //---------------------------------------------------------------------
  93. // Multiplies vector (x,y,z,1) by 4x4 matrix, producing a homogeneous vector
  94. //
  95. // res and v should not be the same
  96. //
  97. __inline void VecMatMul4(D3DVECTOR *v, D3DMATRIX *m, D3DVECTORH *res)
  98. {
  99. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  100. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  101. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  102. res->w = v->x*m->_14 + v->y*m->_24 + v->z*m->_34 + m->_44;
  103. }
  104. //---------------------------------------------------------------------
  105. // Multiplies vector (x,y,z,w) by transposed 4x4 matrix, producing a
  106. // homogeneous vector
  107. //
  108. // res and v should not be the same
  109. //
  110. __inline void VecMatMul4HT(D3DVECTORH *v, D3DMATRIX *m, D3DVECTORH *res)
  111. {
  112. res->x = v->x*m->_11 + v->y*m->_12 + v->z*m->_13 + v->w*m->_14;
  113. res->y = v->x*m->_21 + v->y*m->_22 + v->z*m->_23 + v->w*m->_24;
  114. res->z = v->x*m->_31 + v->y*m->_32 + v->z*m->_33 + v->w*m->_34;
  115. res->w = v->x*m->_41 + v->y*m->_42 + v->z*m->_43 + v->w*m->_44;
  116. }
  117. //---------------------------------------------------------------------
  118. // Multiplies vector (x,y,z,1) by 4x3 matrix
  119. //
  120. // res and v should not be the same
  121. //
  122. __inline void VecMatMul(D3DVECTOR *v, D3DMATRIX *m, D3DVECTOR *res)
  123. {
  124. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31 + m->_41;
  125. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32 + m->_42;
  126. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33 + m->_43;
  127. }
  128. //---------------------------------------------------------------------
  129. // Multiplies vector (x,y,z) by 3x3 matrix
  130. //
  131. // res and v should not be the same
  132. //
  133. __inline void VecMatMul3(D3DVECTOR *v, D3DMATRIX *m, D3DVECTOR *res)
  134. {
  135. res->x = v->x*m->_11 + v->y*m->_21 + v->z*m->_31;
  136. res->y = v->x*m->_12 + v->y*m->_22 + v->z*m->_32;
  137. res->z = v->x*m->_13 + v->y*m->_23 + v->z*m->_33;
  138. }
  139. //---------------------------------------------------------------------
  140. // This function uses Cramer's Rule to calculate the matrix inverse.
  141. // See nt\private\windows\opengl\serever\soft\so_math.c
  142. //
  143. // Returns:
  144. // 0 - if success
  145. // -1 - if input matrix is singular
  146. //
  147. int Inverse4x4(D3DMATRIX *src, D3DMATRIX *inverse);
  148. //---------------------------------------------------------------------
  149. // 4 by 4 matrix product
  150. //
  151. // result = a*b.
  152. // "result" pointer could be equal to "a" or "b"
  153. //
  154. void MatrixProduct(D3DMATRIX *result, D3DMATRIX *a, D3DMATRIX *b);
  155. //---------------------------------------------------------------------
  156. // Checks the FVF flags for errors and returns the stride in bytes between
  157. // vertices.
  158. //
  159. // Returns:
  160. // HRESULT and stride in bytes between vertices
  161. //
  162. //---------------------------------------------------------------------
  163. HRESULT FASTCALL
  164. FVFCheckAndStride(DWORD dwFVF, DWORD* pdwStride);
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif // #ifndef _D3DUTIL_H_