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.

304 lines
9.7 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: d3dpoint.c
  8. *
  9. * Content: Direct3D hw point 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_Point
  24. //
  25. // Hardare render a single point coming from a FVF vertex
  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_Point(PERMEDIA_D3DCONTEXT *pContext,
  34. LPD3DTLVERTEX lpV0,
  35. LPP2FVFOFFSETS lpFVFOff)
  36. {
  37. PPDev pPdev = pContext->ppdev;
  38. DWORD dwFlags = pContext->Hdr.Flags;
  39. ULONG ulRenderCmd = pContext->RenderCommand;
  40. DWORD dwColorOffs,dwSpecularOffs,dwTexOffs;
  41. D3DCOLOR dwColor, dwSpecular;
  42. D3DVALUE fKs, fS, fT, fQ;
  43. PERMEDIA_DEFS(pContext->ppdev);
  44. DBG_D3D((10,"Entering P2_Draw_FVF_Point"));
  45. // Set point rendering mode
  46. RENDER_POINT(ulRenderCmd);
  47. // Get FVF structure offsets
  48. __SetFVFOffsets(&dwColorOffs,&dwSpecularOffs,&dwTexOffs,lpFVFOff);
  49. RESERVEDMAPTR(0x80);
  50. SEND_PERMEDIA_DATA(RasterizerMode, BIAS_NEARLY_HALF);
  51. // Get vertex color value (FVF based)
  52. if (dwColorOffs)
  53. {
  54. dwColor = FVFCOLOR(lpV0, dwColorOffs)->color;
  55. if (FAKE_ALPHABLEND_MODULATE & pContext->FakeBlendNum)
  56. {
  57. dwColor |= 0xFF000000;
  58. }
  59. }
  60. else
  61. {
  62. // must set default in case no D3DFVF_DIFFUSE
  63. dwColor = 0xFFFFFFFF;
  64. }
  65. // Get vertex specular value (FVF based) if necessary
  66. if ((dwFlags & (CTXT_HAS_SPECULAR_ENABLED | CTXT_HAS_FOGGING_ENABLED))
  67. && (dwSpecularOffs != 0))
  68. {
  69. dwSpecular = FVFSPEC(lpV0, dwSpecularOffs)->specular;
  70. }
  71. if ((dwFlags & CTXT_HAS_TEXTURE_ENABLED) && (dwTexOffs != 0))
  72. {
  73. // Get s,t texture coordinates (FVF based)
  74. fS = FVFTEX(lpV0,dwTexOffs)->tu;
  75. fT = FVFTEX(lpV0,dwTexOffs)->tv;
  76. // Scale s,t coordinate values
  77. fS *= pContext->DeltaWidthScale;
  78. fT *= pContext->DeltaHeightScale;
  79. // Apply perpspective corrections if necessary
  80. if (dwFlags & CTXT_HAS_PERSPECTIVE_ENABLED)
  81. {
  82. fQ = lpV0->rhw;
  83. fS *= fQ;
  84. fT *= fQ;
  85. }
  86. else
  87. {
  88. fQ = 1.0;
  89. }
  90. // Send points s,t,q,ks (conditionaly),x,y,z values
  91. if ((dwFlags & CTXT_HAS_SPECULAR_ENABLED) && (dwSpecularOffs != 0))
  92. {
  93. fKs = RGB256_TO_LUMA(RGB_GETRED(dwSpecular),
  94. RGB_GETGREEN(dwSpecular),
  95. RGB_GETBLUE(dwSpecular));
  96. SEND_VERTEX_STQ_KS_XYZ(__Permedia2TagV0FloatS, fS, fT, fQ, fKs,
  97. lpV0->sx, lpV0->sy, lpV0->sz);
  98. }
  99. else
  100. {
  101. SEND_VERTEX_STQ_XYZ(__Permedia2TagV0FloatS, fS, fT, fQ,
  102. lpV0->sx, lpV0->sy, lpV0->sz);
  103. }
  104. }
  105. else // not textured point
  106. {
  107. // If specular is enabled, change the colours
  108. if ((dwFlags & CTXT_HAS_SPECULAR_ENABLED) && (dwSpecularOffs != 0))
  109. {
  110. CLAMP8888(dwColor, dwColor, dwSpecular);
  111. }
  112. // Send lines x,y,z values
  113. SEND_VERTEX_XYZ(__Permedia2TagV0FloatS, lpV0->sx, lpV0->sy, lpV0->sz);
  114. }
  115. // If fog is set, send the appropriate value
  116. if ((dwFlags & CTXT_HAS_FOGGING_ENABLED) && (dwSpecularOffs != 0))
  117. {
  118. SEND_VERTEX_FOG(__Permedia2TagV0FixedF, RGB_GET_GAMBIT_FOG(dwSpecular));
  119. }
  120. // Send appropriate color depending on Gouraud , Mono, & Alpha
  121. if (dwFlags & CTXT_HAS_GOURAUD_ENABLED)
  122. {
  123. // Gouraud shading
  124. if (RENDER_MONO)
  125. {
  126. SEND_VERTEX_RGB_MONO_P2(__Permedia2TagV0FixedS, dwColor);
  127. }
  128. else
  129. {
  130. if (dwFlags & CTXT_HAS_ALPHABLEND_ENABLED)
  131. {
  132. if (pContext->FakeBlendNum & FAKE_ALPHABLEND_ONE_ONE)
  133. {
  134. dwColor &= 0xFFFFFF; // supress color's alpha value
  135. }
  136. }
  137. SEND_VERTEX_RGBA_P2(__Permedia2TagV0FixedS, dwColor);
  138. }
  139. }
  140. else // Flat shading
  141. {
  142. if (RENDER_MONO)
  143. {
  144. // Get constant color from the blue channel
  145. DWORD BlueChannel = RGBA_GETBLUE(dwColor);
  146. SEND_PERMEDIA_DATA(ConstantColor,
  147. RGB_MAKE(BlueChannel, BlueChannel, BlueChannel));
  148. }
  149. else
  150. {
  151. if (pContext->FakeBlendNum & FAKE_ALPHABLEND_ONE_ONE)
  152. {
  153. dwColor &= 0xFFFFFF;
  154. }
  155. SEND_PERMEDIA_DATA(ConstantColor,
  156. RGBA_MAKE(RGBA_GETBLUE(dwColor),
  157. RGBA_GETGREEN(dwColor),
  158. RGBA_GETRED(dwColor),
  159. RGBA_GETALPHA(dwColor)));
  160. }
  161. }
  162. SEND_PERMEDIA_DATA(DrawLine01, ulRenderCmd);
  163. SEND_PERMEDIA_DATA(RasterizerMode, 0);
  164. COMMITDMAPTR();
  165. DBG_D3D((10,"Exiting P2_Draw_FVF_Point"));
  166. } // P2_Draw_FVF_Point
  167. //-----------------------------------------------------------------------------
  168. //
  169. // void P2_Draw_FVF_Point_Tri
  170. //
  171. // Render a triangle with FVF vertexes when the point fillmode is active
  172. //
  173. //-----------------------------------------------------------------------------
  174. void
  175. P2_Draw_FVF_Point_Tri(PERMEDIA_D3DCONTEXT *pContext,
  176. LPD3DTLVERTEX lpV0,
  177. LPD3DTLVERTEX lpV1,
  178. LPD3DTLVERTEX lpV2,
  179. LPP2FVFOFFSETS lpFVFOff)
  180. {
  181. D3DFVFDRAWPNTFUNCPTR pPoint;
  182. DBG_D3D((10,"Entering P2_Draw_FVF_Point_Tri"));
  183. pPoint = __HWSetPointFunc(pContext, lpFVFOff);
  184. (*pPoint)(pContext, lpV0, lpFVFOff);
  185. (*pPoint)(pContext, lpV1, lpFVFOff);
  186. (*pPoint)(pContext, lpV2, lpFVFOff);
  187. DBG_D3D((10,"Exiting P2_Draw_FVF_Point_Tri"));
  188. } // P2_Draw_FVF_Point_Tri
  189. //@@BEGIN_DDKSPLIT
  190. #if D3D_POINTSPRITES
  191. //-----------------------------------------------------------------------------
  192. //
  193. // void P2_Draw_FVF_Point_Sprite
  194. //
  195. // Render a point sprite with FVF vertexes when the point sprite enable is on
  196. //
  197. //-----------------------------------------------------------------------------
  198. #define SPRITETEXCOORDMAX (4095.75F/4096.F)
  199. void
  200. P2_Draw_FVF_Point_Sprite(PERMEDIA_D3DCONTEXT *pContext,
  201. LPD3DTLVERTEX lpV0,
  202. LPP2FVFOFFSETS lpFVFOff)
  203. {
  204. P2FVFMAXVERTEX fvfVUL, fvfVUR, fvfVLL, fvfVLR;
  205. DWORD dwColorOffs,dwSpecularOffs,dwTexOffs;
  206. D3DVALUE fPntSize, fPntSizeHalf;
  207. DBG_D3D((10,"Entering P2_Draw_FVF_Point_Sprite"));
  208. // Get FVF structure offsets
  209. __SetFVFOffsets(&dwColorOffs,&dwSpecularOffs,&dwTexOffs,lpFVFOff);
  210. // Compute point sprite size
  211. if (lpFVFOff->dwPntSizeOffset)
  212. {
  213. fPntSize = FVFPSIZE(lpV0, lpFVFOff->dwPntSizeOffset)->psize;
  214. }
  215. else
  216. {
  217. fPntSize = pContext->fPointSize;
  218. }
  219. // Initialize square values
  220. memcpy( &fvfVUL, lpV0, lpFVFOff->dwStride);
  221. memcpy( &fvfVUR, lpV0, lpFVFOff->dwStride);
  222. memcpy( &fvfVLL, lpV0, lpFVFOff->dwStride);
  223. memcpy( &fvfVLR, lpV0, lpFVFOff->dwStride);
  224. // Clamp point size to zero
  225. if (fPntSize > 0.0f)
  226. fPntSizeHalf = fPntSize * 0.5f;
  227. else
  228. fPntSizeHalf = 0.0f;
  229. // Make this a square of size fPntSize
  230. ((D3DTLVERTEX *)&fvfVUL)->sx -= fPntSizeHalf;
  231. ((D3DTLVERTEX *)&fvfVUL)->sy -= fPntSizeHalf;
  232. ((D3DTLVERTEX *)&fvfVUR)->sx += fPntSizeHalf;
  233. ((D3DTLVERTEX *)&fvfVUR)->sy -= fPntSizeHalf;
  234. ((D3DTLVERTEX *)&fvfVLL)->sx -= fPntSizeHalf;
  235. ((D3DTLVERTEX *)&fvfVLL)->sy += fPntSizeHalf;
  236. ((D3DTLVERTEX *)&fvfVLR)->sx += fPntSizeHalf;
  237. ((D3DTLVERTEX *)&fvfVLR)->sy += fPntSizeHalf;
  238. if ((pContext->bPointSpriteEnabled) && (dwTexOffs))
  239. {
  240. // Modify texture coordinates according to spec
  241. FVFTEX(&fvfVUL, dwTexOffs)->tu = 0.0f;
  242. FVFTEX(&fvfVUL, dwTexOffs)->tv = 0.0f;
  243. FVFTEX(&fvfVUR, dwTexOffs)->tu = SPRITETEXCOORDMAX;
  244. FVFTEX(&fvfVUR, dwTexOffs)->tv = 0.0f;
  245. FVFTEX(&fvfVLL, dwTexOffs)->tu = 0.0f;
  246. FVFTEX(&fvfVLL, dwTexOffs)->tv = SPRITETEXCOORDMAX;
  247. FVFTEX(&fvfVLR, dwTexOffs)->tu = SPRITETEXCOORDMAX;
  248. FVFTEX(&fvfVLR, dwTexOffs)->tv = SPRITETEXCOORDMAX;
  249. }
  250. // here we are going to send the required quad
  251. P2_Draw_FVF_Solid_Tri(pContext, (D3DTLVERTEX *)&fvfVUL,
  252. (D3DTLVERTEX *)&fvfVUR,
  253. (D3DTLVERTEX *)&fvfVLL, lpFVFOff);
  254. P2_Draw_FVF_Solid_Tri(pContext, (D3DTLVERTEX *)&fvfVLL,
  255. (D3DTLVERTEX *)&fvfVUR,
  256. (D3DTLVERTEX *)&fvfVLR, lpFVFOff);
  257. DBG_D3D((10,"Exiting P2_Draw_FVF_Point_Sprite"));
  258. }
  259. #endif // D3D_POINTSPRITES
  260. //@@END_DDKSPLIT