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.

145 lines
5.3 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1997 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: d3dfei.hpp
  6. * Content: Direct3D frontend internal include file
  7. *
  8. ***************************************************************************/
  9. #ifndef _D3DFEI_H_
  10. #define _D3DFEI_H_
  11. #include "clipper.h"
  12. #define HANDLE_TO_MAT(lpDevI, h) ((LPD3DMATRIXI) ULongToPtr(h))
  13. void setIdentity(D3DMATRIXI * m);
  14. extern void UpdateXfrmLight(LPDIRECT3DDEVICEI lpDevI);
  15. extern void MatrixProduct(D3DMATRIXI *d, D3DMATRIXI *a, D3DMATRIXI *b);
  16. extern void D3DFE_updateExtents(LPDIRECT3DDEVICEI lpDevI);
  17. extern void D3DFE_ConvertExtent(LPDIRECT3DDEVICEI lpDevI, LPD3DRECTV from, LPD3DRECT to);
  18. extern HRESULT D3DFE_InitTransform(LPDIRECT3DDEVICEI lpDevI);
  19. extern void D3DFE_DestroyTransform(LPDIRECT3DDEVICEI lpDevI);
  20. // Goes through all vertices and computes ramp color and texture.
  21. // If pIn == pOut coordinates are not copied
  22. //
  23. extern void ConvertColorsToRamp(LPDIRECT3DDEVICEI lpDevI, D3DTLVERTEX *pIn,
  24. D3DTLVERTEX *pOut, DWORD count);
  25. //---------------------------------------------------------------------
  26. // Maps legacy vertex formats (D3DVERTEX, D3DTLVERTEX, D3DLVERTEX) to
  27. // FVF vertex ID.
  28. //
  29. extern DWORD d3dVertexToFVF[4];
  30. //---------------------------------------------------------------------
  31. // Computes the Current Transformation Matrix (lpDevI->mCTM) by combining
  32. // all matrices together
  33. //
  34. extern void updateTransform(LPDIRECT3DDEVICEI lpDevI);
  35. //---------------------------------------------------------------------
  36. // Clamp extents to viewport window.
  37. // For guard band it is possible that extents are outside viewport window
  38. // after clipping
  39. //
  40. inline void ClampExtents(LPD3DFE_PROCESSVERTICES pv)
  41. {
  42. if (pv->dwDeviceFlags & D3DDEV_GUARDBAND &&
  43. !(pv->dwFlags & D3DDP_DONOTUPDATEEXTENTS))
  44. {
  45. if (pv->rExtents.x1 < pv->vcache.minX)
  46. pv->rExtents.x1 = pv->vcache.minX;
  47. if (pv->rExtents.x2 > pv->vcache.maxX)
  48. pv->rExtents.x2 = pv->vcache.maxX;
  49. if (pv->rExtents.y1 < pv->vcache.minY)
  50. pv->rExtents.y1 = pv->vcache.minY;
  51. if (pv->rExtents.y2 > pv->vcache.maxY)
  52. pv->rExtents.y2 = pv->vcache.maxY;
  53. }
  54. }
  55. //---------------------------------------------------------------------
  56. // Returns TRUE if cipping is needed
  57. //
  58. inline BOOL CheckIfNeedClipping(LPD3DFE_PROCESSVERTICES pv)
  59. {
  60. if (pv->dwDeviceFlags & D3DDEV_GUARDBAND)
  61. {
  62. if (pv->dwClipUnion & ~__D3DCLIP_INGUARDBAND)
  63. return TRUE;
  64. }
  65. else
  66. if (pv->dwClipUnion)
  67. return TRUE;
  68. return FALSE;
  69. }
  70. //---------------------------------------------------------------------
  71. // Updates lighting and computes process vertices flags
  72. //
  73. inline HRESULT DoUpdateState(LPDIRECT3DDEVICEI lpDevI)
  74. {
  75. if (lpDevI->dwFlags & D3DPV_LIGHTING)
  76. {
  77. if (!(lpDevI->dwFlags & D3DDP_DONOTLIGHT ||
  78. lpDevI->lighting.hMat == NULL))
  79. {
  80. HRESULT ret;
  81. extern HRESULT setLights(LPDIRECT3DVIEWPORTI);
  82. LPDIRECT3DVIEWPORTI lpViewI = (LPDIRECT3DVIEWPORTI)
  83. (lpDevI->lpCurrentViewport);
  84. // only set up lights if something has changed
  85. if (lpViewI->bLightsChanged)
  86. {
  87. if ((ret = setLights(lpViewI)) != D3D_OK)
  88. {
  89. D3D_ERR("failed to setup lights");
  90. return ret;
  91. }
  92. lpViewI->bLightsChanged = FALSE;
  93. }
  94. lpDevI->dwFlags |= D3DPV_LIGHTING;
  95. if (lpDevI->dwFEFlags & D3DFE_COMPUTESPECULAR &&
  96. lpDevI->dwVIDOut & D3DFVF_SPECULAR)
  97. lpDevI->dwFlags |= D3DPV_COMPUTESPECULAR;
  98. }
  99. else
  100. lpDevI->dwFlags &= ~D3DPV_LIGHTING;
  101. }
  102. if (lpDevI->dwFEFlags & D3DFE_COLORVERTEX)
  103. {
  104. if (lpDevI->dwVIDIn & D3DFVF_DIFFUSE)
  105. lpDevI->dwFlags |= D3DPV_COLORVERTEX;
  106. if (lpDevI->dwVIDIn & D3DFVF_SPECULAR)
  107. lpDevI->dwFlags |= D3DPV_COLORVERTEXS;
  108. }
  109. UpdateXfrmLight(lpDevI);
  110. // In case if COLORVERTEX is TRUE, the vertexAlpha could be overriden
  111. // by vertex alpha
  112. lpDevI->lighting.alpha = lpDevI->lighting.materialAlpha;
  113. return D3D_OK;
  114. }
  115. //---------------------------------------------------------------------
  116. // The following bits should be set in dwFlags before calling this function:
  117. //
  118. // D3DPV_STRIDE - if strides are used
  119. // D3DPV_SOA - if SOA is used
  120. //
  121. inline long D3DFE_ProcessVertices(LPDIRECT3DDEVICEI lpDevI)
  122. {
  123. // Update Lighting and related flags
  124. DoUpdateState(lpDevI);
  125. return lpDevI->pGeometryFuncs->ProcessVertices(lpDevI);
  126. }
  127. //---------------------------------------------------------------------
  128. // Updates clip status in the device
  129. //
  130. // We have to mask all guard band bits
  131. //
  132. inline void D3DFE_UpdateClipStatus(LPDIRECT3DDEVICEI lpDevI)
  133. {
  134. lpDevI->iClipStatus |= lpDevI->dwClipUnion & D3DSTATUS_CLIPUNIONALL;
  135. lpDevI->iClipStatus &= (~D3DSTATUS_CLIPINTERSECTIONALL |
  136. ((lpDevI->dwClipIntersection & D3DSTATUS_CLIPUNIONALL) << 12));
  137. }
  138. #endif // _D3DFEI_H_