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.

263 lines
9.0 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dline.c
  8. *
  9. * Content: Direct3D hw line rasterization code.
  10. *
  11. * Copyright (c) 1994-1998 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #include "precomp.h"
  15. #include "d3ddelta.h"
  16. #include "d3dhw.h"
  17. #include "d3dcntxt.h"
  18. #if defined(_ALPHA_)
  19. #include <math.h>
  20. #endif
  21. //-----------------------------------------------------------------------------
  22. //
  23. // VOID P2_Draw_FVF_Line
  24. //
  25. // Hardare render a single line coming from two FVF vertices
  26. //
  27. // Primitive rendering at this stage is dependent upon the current value/setting
  28. // of texturing, perspective correction, fogging, gouraud/flat shading, and
  29. // specular highlights.
  30. //
  31. //-----------------------------------------------------------------------------
  32. VOID
  33. P2_Draw_FVF_Line(PERMEDIA_D3DCONTEXT *pContext,
  34. LPD3DTLVERTEX lpV0,
  35. LPD3DTLVERTEX lpV1,
  36. LPD3DTLVERTEX lpVFlat,
  37. LPP2FVFOFFSETS lpFVFOff)
  38. {
  39. DWORD dwFlags = pContext->Hdr.Flags;
  40. ULONG ulRenderCmd = pContext->RenderCommand;
  41. DWORD dwColorOffs,dwSpecularOffs,dwTexOffs;
  42. D3DCOLOR dwColor0, dwColor1;
  43. D3DCOLOR dwSpec0, dwSpec1;
  44. D3DVALUE fS0, fS1, fT0, fT1, fQ0, fQ1;
  45. D3DVALUE fKs0, fKs1;
  46. PERMEDIA_DEFS(pContext->ppdev);
  47. DBG_D3D((10,"Entering P2_Draw_FVF_Line"));
  48. // Set line rendering mode
  49. RENDER_LINE(ulRenderCmd);
  50. // Fix up the biasing in delta because delta doesn't do it for us for lines.
  51. RESERVEDMAPTR(0x80);
  52. SEND_PERMEDIA_DATA(RasterizerMode, BIAS_NONE);
  53. // Get FVF structure offsets
  54. __SetFVFOffsets(&dwColorOffs,&dwSpecularOffs,&dwTexOffs,lpFVFOff);
  55. // Get vertex color value (FVF based)
  56. if (dwColorOffs)
  57. {
  58. dwColor0 = FVFCOLOR(lpV0, dwColorOffs)->color;
  59. dwColor1 = FVFCOLOR(lpV1, dwColorOffs)->color;
  60. if (FAKE_ALPHABLEND_MODULATE & pContext->FakeBlendNum)
  61. {
  62. dwColor0 |= 0xFF000000;
  63. dwColor1 |= 0xFF000000;
  64. }
  65. }
  66. else
  67. {
  68. // must set default in case no D3DFVF_DIFFUSE
  69. dwColor0 = 0xFFFFFFFF;
  70. dwColor1 = 0xFFFFFFFF;
  71. }
  72. // Get vertex specular value (FVF based) if necessary
  73. if ((dwFlags & (CTXT_HAS_SPECULAR_ENABLED | CTXT_HAS_FOGGING_ENABLED))
  74. && (dwSpecularOffs!=0))
  75. {
  76. dwSpec0 = FVFSPEC(lpV0, dwSpecularOffs)->specular;
  77. dwSpec1 = FVFSPEC(lpV1, dwSpecularOffs)->specular;
  78. }
  79. if ((dwFlags & CTXT_HAS_TEXTURE_ENABLED) && (dwTexOffs != 0))
  80. {
  81. // Get s,t texture coordinates (FVF based)
  82. fS0 = FVFTEX(lpV0,dwTexOffs)->tu;
  83. fT0 = FVFTEX(lpV0,dwTexOffs)->tv;
  84. fS1 = FVFTEX(lpV1,dwTexOffs)->tu;
  85. fT1 = FVFTEX(lpV1,dwTexOffs)->tv;
  86. // Wrap texture coordinates if necessary
  87. WRAP_LINE(fS, dwFlags & CTXT_HAS_WRAPU_ENABLED);
  88. WRAP_LINE(fT, dwFlags & CTXT_HAS_WRAPV_ENABLED);
  89. // Scale s,t coordinate values
  90. fS0 *= pContext->DeltaWidthScale;
  91. fS1 *= pContext->DeltaWidthScale;
  92. fT0 *= pContext->DeltaHeightScale;
  93. fT1 *= pContext->DeltaHeightScale;
  94. // Apply perpspective corrections if necessary
  95. if (dwFlags & CTXT_HAS_PERSPECTIVE_ENABLED)
  96. {
  97. fQ0 = lpV0->rhw;
  98. fQ1 = lpV1->rhw;
  99. fS0 *= fQ0;
  100. fT0 *= fQ0;
  101. fS1 *= fQ1;
  102. fT1 *= fQ1;
  103. }
  104. else
  105. {
  106. fQ0 = fQ1 = 1.0;
  107. }
  108. // Send lines s,t,q,ks (conditionaly),x,y,z values
  109. if ((dwFlags & CTXT_HAS_SPECULAR_ENABLED) && (dwSpecularOffs!=0))
  110. {
  111. fKs0 = RGB256_TO_LUMA(RGB_GETRED(dwSpec0),
  112. RGB_GETGREEN(dwSpec0),
  113. RGB_GETBLUE(dwSpec0));
  114. if (dwFlags & CTXT_HAS_GOURAUD_ENABLED)
  115. {
  116. fKs1 = RGB256_TO_LUMA(RGB_GETRED(dwSpec1),
  117. RGB_GETGREEN(dwSpec1),
  118. RGB_GETBLUE(dwSpec1));
  119. }
  120. else
  121. {
  122. fKs1 = fKs0;
  123. }
  124. SEND_VERTEX_STQ_KS_XYZ(__Permedia2TagV0FloatS, fS0, fT0, fQ0, fKs0,
  125. lpV0->sx, lpV0->sy, lpV0->sz);
  126. SEND_VERTEX_STQ_KS_XYZ(__Permedia2TagV1FloatS, fS1, fT1, fQ1, fKs1,
  127. lpV1->sx, lpV1->sy, lpV1->sz);
  128. }
  129. else
  130. {
  131. SEND_VERTEX_STQ_XYZ(__Permedia2TagV0FloatS, fS0, fT0, fQ0,
  132. lpV0->sx, lpV0->sy, lpV0->sz);
  133. SEND_VERTEX_STQ_XYZ(__Permedia2TagV1FloatS, fS1, fT1, fQ1,
  134. lpV1->sx, lpV1->sy, lpV1->sz);
  135. }
  136. }
  137. else // not textured line
  138. {
  139. // If specular is enabled, change the colours
  140. if ((dwFlags & CTXT_HAS_SPECULAR_ENABLED) && (dwSpecularOffs!=0))
  141. {
  142. CLAMP8888(dwColor0, dwColor0, dwSpec0 );
  143. CLAMP8888(dwColor1, dwColor1, dwSpec1 );
  144. }
  145. // Send lines x,y,z values
  146. SEND_VERTEX_XYZ(__Permedia2TagV0FloatS, lpV0->sx, lpV0->sy, lpV0->sz);
  147. SEND_VERTEX_XYZ(__Permedia2TagV1FloatS, lpV1->sx, lpV1->sy, lpV1->sz);
  148. }
  149. // If fog is set, send the appropriate values
  150. if ((dwFlags & CTXT_HAS_FOGGING_ENABLED) && (dwSpecularOffs!=0))
  151. {
  152. SEND_VERTEX_FOG(__Permedia2TagV0FixedF, RGB_GET_GAMBIT_FOG(dwSpec0));
  153. SEND_VERTEX_FOG(__Permedia2TagV1FixedF, RGB_GET_GAMBIT_FOG(dwSpec1));
  154. }
  155. // Send appropriate color depending on Gouraud , Mono, & Alpha
  156. if (dwFlags & CTXT_HAS_GOURAUD_ENABLED)
  157. {
  158. // Gouraud shading
  159. if (RENDER_MONO)
  160. {
  161. SEND_VERTEX_RGB_MONO_P2(__Permedia2TagV0FixedS, dwColor0);
  162. SEND_VERTEX_RGB_MONO_P2(__Permedia2TagV1FixedS, dwColor1);
  163. }
  164. else
  165. {
  166. if (dwFlags & CTXT_HAS_ALPHABLEND_ENABLED)
  167. {
  168. if (pContext->FakeBlendNum & FAKE_ALPHABLEND_ONE_ONE)
  169. {
  170. dwColor0 &= 0xFFFFFF; // supress color's alpha value
  171. dwColor1 &= 0xFFFFFF;
  172. }
  173. }
  174. SEND_VERTEX_RGBA_P2(__Permedia2TagV0FixedS, dwColor0);
  175. SEND_VERTEX_RGBA_P2(__Permedia2TagV1FixedS, dwColor1);
  176. }
  177. }
  178. else // Flat shading
  179. {
  180. // Get vertex color value (FVF based) from the right vertex!
  181. if (dwColorOffs)
  182. {
  183. dwColor0 = FVFCOLOR(lpVFlat, dwColorOffs)->color;
  184. if (FAKE_ALPHABLEND_MODULATE & pContext->FakeBlendNum)
  185. {
  186. dwColor0 |= 0xFF000000;
  187. }
  188. }
  189. else
  190. {
  191. // must set default in case no D3DFVF_DIFFUSE
  192. dwColor0 = 0xFFFFFFFF;
  193. }
  194. if (RENDER_MONO)
  195. {
  196. // Get constant color from the blue channel
  197. DWORD BlueChannel;
  198. BlueChannel = RGBA_GETBLUE(dwColor0);
  199. SEND_PERMEDIA_DATA(ConstantColor,
  200. RGB_MAKE(BlueChannel, BlueChannel, BlueChannel));
  201. }
  202. else
  203. {
  204. if (pContext->FakeBlendNum & FAKE_ALPHABLEND_ONE_ONE)
  205. {
  206. dwColor0 &= 0xFFFFFF;
  207. }
  208. SEND_PERMEDIA_DATA(ConstantColor,
  209. RGBA_MAKE(RGBA_GETBLUE(dwColor0),
  210. RGBA_GETGREEN(dwColor0),
  211. RGBA_GETRED(dwColor0),
  212. RGBA_GETALPHA(dwColor0)));
  213. }
  214. }
  215. SEND_PERMEDIA_DATA(DrawLine01, ulRenderCmd);
  216. SEND_PERMEDIA_DATA(RasterizerMode, 0);
  217. COMMITDMAPTR();
  218. DBG_D3D((10,"Exiting P2_Draw_FVF_Line"));
  219. } // P2_Draw_FVF_Line
  220. //-----------------------------------------------------------------------------
  221. //
  222. // void P2_Draw_FVF_Wire_Tri
  223. //
  224. //-----------------------------------------------------------------------------
  225. void
  226. P2_Draw_FVF_Wire_Tri(PERMEDIA_D3DCONTEXT *pContext,
  227. LPD3DTLVERTEX lpV0,
  228. LPD3DTLVERTEX lpV1,
  229. LPD3DTLVERTEX lpV2,
  230. LPP2FVFOFFSETS lpFVFOff)
  231. {
  232. DBG_D3D((10,"Entering P2_Draw_FVF_Wire_Tri"));
  233. P2_Draw_FVF_Line(pContext, lpV0, lpV1, lpV0, lpFVFOff);
  234. P2_Draw_FVF_Line(pContext, lpV1, lpV2, lpV0, lpFVFOff);
  235. P2_Draw_FVF_Line(pContext, lpV2, lpV0, lpV0, lpFVFOff);
  236. DBG_D3D((10,"Exiting P2_Draw_FVF_Wire_Tri"));
  237. }