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.

153 lines
7.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) Microsoft Corporation, 1998.
  3. //
  4. // MapLegcy.cpp
  5. //
  6. // Direct3D Reference Rasterizer - Mapping Legacy Modes to Current Functionality
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #include "pch.cpp"
  10. #pragma hdrstop
  11. //-----------------------------------------------------------------------------
  12. //
  13. // MapLegacyTextureFilter - Map filter state from renderstate to per-stage state.
  14. // This is invoked when a texture is bound via the TEXTUREHANDLE renderstate,
  15. // indicating that we are in 'legacy' texture mode. The rasterizer always
  16. // refers to per-stage filtering control state, so in legacy mode the filtering
  17. // controls in the renderstate are mapped into the filtering controls associated
  18. // with the texture object bound to D3DRS_TEXTUREHANDLE.
  19. //
  20. //-----------------------------------------------------------------------------
  21. void
  22. RefDev::MapLegacyTextureFilter( void )
  23. {
  24. // first check if anisotropic filtering is enabled (indicated by the
  25. // limit value being set to > 1) - if so then aniso filter will be used
  26. // for linear mag filter or 'linear within map' min filter
  27. BOOL bAnisoEnabled = ( m_dwRenderState[D3DRENDERSTATE_ANISOTROPY] > 1 );
  28. // D3D legacy filter specifications are (XXXMIP)YYY where XXX is the
  29. // mip filter and YYY is the filter used within an LOD
  30. // map MAG filter - legacy support is point or linear (and maybe aniso)
  31. switch ( m_dwRenderState[D3DRENDERSTATE_TEXTUREMAG] )
  32. {
  33. default:
  34. case D3DFILTER_NEAREST:
  35. m_TextureStageState[0].m_dwVal[D3DTSS_MAGFILTER] = D3DTEXF_POINT;
  36. break;
  37. case D3DFILTER_LINEAR:
  38. // select based on aniso enable
  39. m_TextureStageState[0].m_dwVal[D3DTSS_MAGFILTER] =
  40. bAnisoEnabled ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  41. break;
  42. }
  43. // map MIN and MIP filter at the same time - legacy support
  44. // has them intermingled...
  45. switch ( m_dwRenderState[D3DRENDERSTATE_TEXTUREMIN] )
  46. {
  47. case D3DFILTER_NEAREST:
  48. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] = D3DTEXF_POINT;
  49. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_NONE;
  50. break;
  51. case D3DFILTER_MIPNEAREST:
  52. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] = D3DTEXF_POINT;
  53. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_POINT;
  54. break;
  55. case D3DFILTER_LINEARMIPNEAREST:
  56. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] = D3DTEXF_POINT;
  57. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_LINEAR;
  58. break;
  59. case D3DFILTER_LINEAR:
  60. // select min filter based on aniso enable
  61. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] =
  62. bAnisoEnabled ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  63. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_NONE;
  64. break;
  65. case D3DFILTER_MIPLINEAR:
  66. // select min filter based on aniso enable
  67. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] =
  68. bAnisoEnabled ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  69. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_POINT;
  70. break;
  71. case D3DFILTER_LINEARMIPLINEAR:
  72. // select based on aniso enable
  73. m_TextureStageState[0].m_dwVal[D3DTSS_MINFILTER] =
  74. bAnisoEnabled ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR;
  75. m_TextureStageState[0].m_dwVal[D3DTSS_MIPFILTER] = D3DTEXF_LINEAR;
  76. break;
  77. }
  78. }
  79. //-----------------------------------------------------------------------------
  80. //
  81. // MapLegacyTextureBlend - Maps legacy (pre-DX6) texture blend modes to DX6
  82. // texture blending controls. Uses per-stage program mode (first stage only).
  83. // This mapping is done whenever the legacy TBLEND renderstate is set, and
  84. // does overwrite any previously set DX6 texture blending controls.
  85. //
  86. //-----------------------------------------------------------------------------
  87. void
  88. RefDev::MapLegacyTextureBlend( void )
  89. {
  90. // disable texture blend processing stage 1 (this also disables subsequent stages)
  91. m_TextureStageState[1].m_dwVal[D3DTSS_COLOROP] = D3DTOP_DISABLE;
  92. // set texture blend processing stage 0 to match legacy mode
  93. switch ( m_dwRenderState[D3DRENDERSTATE_TEXTUREMAPBLEND] )
  94. {
  95. default:
  96. case D3DTBLEND_DECALMASK: // unsupported - do decal
  97. case D3DTBLEND_DECAL:
  98. case D3DTBLEND_COPY:
  99. m_TextureStageState[0].m_dwVal[D3DTSS_COLOROP] = D3DTOP_SELECTARG1;
  100. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG1] = D3DTA_TEXTURE;
  101. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAOP] = D3DTOP_SELECTARG1;
  102. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG1] = D3DTA_TEXTURE;
  103. break;
  104. case D3DTBLEND_MODULATEMASK: // unsupported - do modulate
  105. case D3DTBLEND_MODULATE:
  106. m_TextureStageState[0].m_dwVal[D3DTSS_COLOROP] = D3DTOP_MODULATE;
  107. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG1] = D3DTA_TEXTURE;
  108. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG2] = D3DTA_DIFFUSE;
  109. // a special legacy alpha operation is called for that depends
  110. // on the format of the texture
  111. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAOP] = D3DTOP_LEGACY_ALPHAOVR;
  112. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG1] = D3DTA_TEXTURE;
  113. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG2] = D3DTA_DIFFUSE;
  114. break;
  115. case D3DTBLEND_MODULATEALPHA:
  116. m_TextureStageState[0].m_dwVal[D3DTSS_COLOROP] = D3DTOP_MODULATE;
  117. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG1] = D3DTA_TEXTURE;
  118. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG2] = D3DTA_DIFFUSE;
  119. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAOP] = D3DTOP_MODULATE;
  120. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG1] = D3DTA_TEXTURE;
  121. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG2] = D3DTA_DIFFUSE;
  122. break;
  123. case D3DTBLEND_DECALALPHA:
  124. m_TextureStageState[0].m_dwVal[D3DTSS_COLOROP] = D3DTOP_BLENDTEXTUREALPHA;
  125. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG1] = D3DTA_TEXTURE;
  126. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG2] = D3DTA_DIFFUSE;
  127. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAOP] = D3DTOP_SELECTARG2;
  128. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG1] = D3DTA_TEXTURE;
  129. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG2] = D3DTA_DIFFUSE;
  130. break;
  131. case D3DTBLEND_ADD:
  132. m_TextureStageState[0].m_dwVal[D3DTSS_COLOROP] = D3DTOP_ADD;
  133. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG1] = D3DTA_TEXTURE;
  134. m_TextureStageState[0].m_dwVal[D3DTSS_COLORARG2] = D3DTA_DIFFUSE;
  135. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAOP] = D3DTOP_SELECTARG2;
  136. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG1] = D3DTA_TEXTURE;
  137. m_TextureStageState[0].m_dwVal[D3DTSS_ALPHAARG2] = D3DTA_DIFFUSE;
  138. break;
  139. }
  140. }
  141. ///////////////////////////////////////////////////////////////////////////////
  142. // end