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.

225 lines
6.6 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // rendprim.cpp
  4. //
  5. // RastRenderState and RastRenderPrimitive.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. #define DDS_LCL(x) ((LPDDRAWI_DDRAWSURFACE_INT)(x))->lpLcl
  13. //----------------------------------------------------------------------------
  14. //
  15. // RendPoint
  16. //
  17. // Draw lists of points. Called by RastRenderPrimitive() for drawing points.
  18. //
  19. //----------------------------------------------------------------------------
  20. HRESULT FASTCALL
  21. DoRendPoints(LPVOID pCtx,
  22. PRIMITIVE_FUNTIONS *pfnPrims,
  23. LPD3DINSTRUCTION pIns,
  24. LPD3DTLVERTEX pVtx,
  25. LPD3DPOINT pPt)
  26. {
  27. INT i;
  28. LPD3DTLVERTEX pV;
  29. for (i = pIns->wCount; i > 0; i--)
  30. {
  31. INT iPts;
  32. for (iPts = pPt->wCount, pV = pVtx + pPt->wFirst;
  33. iPts > 0;
  34. iPts --, pV ++)
  35. {
  36. HRESULT hr;
  37. HR_RET(pfnPrims->pfnPoint(pCtx, (PUINT8)pV));
  38. }
  39. }
  40. return D3D_OK;
  41. }
  42. //----------------------------------------------------------------------------
  43. //
  44. // RendLine
  45. //
  46. // Draw a list of lines. Called by RastRenderPrimitive() for drawing lines.
  47. //
  48. //----------------------------------------------------------------------------
  49. HRESULT FASTCALL
  50. DoRendLines(LPVOID pCtx,
  51. PRIMITIVE_FUNTIONS *pfnPrims,
  52. LPD3DINSTRUCTION pIns,
  53. LPD3DTLVERTEX pVtx,
  54. LPD3DLINE pLine)
  55. {
  56. INT i;
  57. LPD3DTLVERTEX pV0, pV1;
  58. for (i = pIns->wCount; i > 0; i --)
  59. {
  60. HRESULT hr;
  61. pV0 = pVtx + pLine->v1;
  62. pV1 = pVtx + pLine->v2;
  63. pLine = (LPD3DLINE)((PINT8)pLine + pIns->bSize);
  64. HR_RET(pfnPrims->pfnLine(pCtx, (PUINT8)pV0, (PUINT8)pV1));
  65. }
  66. return D3D_OK;
  67. }
  68. //----------------------------------------------------------------------------
  69. //
  70. // RendTriangle
  71. //
  72. // Draw a list of triangles. Called by RastRenderPrimitive() for drawing
  73. // triangles.
  74. //
  75. //----------------------------------------------------------------------------
  76. HRESULT FASTCALL
  77. DoRendTriangles(LPVOID pCtx,
  78. PRIMITIVE_FUNTIONS *pfnPrims,
  79. LPD3DINSTRUCTION pIns,
  80. LPD3DTLVERTEX pVtx,
  81. LPD3DTRIANGLE pTri)
  82. {
  83. LPD3DTLVERTEX pV0, pV1, pV2;
  84. INT i;
  85. for (i = pIns->wCount; i > 0; i --)
  86. {
  87. HRESULT hr;
  88. pV0 = pVtx + pTri->v1;
  89. pV1 = pVtx + pTri->v2;
  90. pV2 = pVtx + pTri->v3;
  91. HR_RET(pfnPrims->pfnTri(pCtx, (PUINT8)pV0, (PUINT8)pV1,
  92. (PUINT8)pV2, pTri->wFlags));
  93. pTri = (LPD3DTRIANGLE)((PINT8)pTri + pIns->bSize);
  94. }
  95. return D3D_OK;
  96. }
  97. //----------------------------------------------------------------------------
  98. //
  99. // RastRenderPrimitive
  100. //
  101. // Called by Execute() for drawing primitives.
  102. //
  103. //----------------------------------------------------------------------------
  104. DWORD __stdcall
  105. RastRenderPrimitive(LPD3DHAL_RENDERPRIMITIVEDATA pRenderData)
  106. {
  107. LPD3DINSTRUCTION pIns;
  108. LPD3DTLVERTEX pVtx;
  109. PUINT8 pData, pPrim;
  110. D3DContext *pDCtx;
  111. VALIDATE_D3DCONTEXT("RastRenderPrimitive", pRenderData);
  112. if (pDCtx->GetRastCtx()->pdwRenderState[D3DRENDERSTATE_ZVISIBLE])
  113. {
  114. pRenderData->dwStatus &= ~D3DSTATUS_ZNOTVISIBLE;
  115. pRenderData->ddrval = D3D_OK;
  116. return DDHAL_DRIVER_HANDLED;
  117. }
  118. // Find out necessary data
  119. pData = (PUINT8)(DDS_LCL(pRenderData->lpExeBuf)->lpGbl->fpVidMem);
  120. pIns = &pRenderData->diInstruction;
  121. pPrim = pData + pRenderData->dwOffset;
  122. pVtx = (LPD3DTLVERTEX)
  123. ((PUINT8)DDS_LCL(pRenderData->lpTLBuf)->lpGbl->fpVidMem
  124. + pRenderData->dwTLOffset);
  125. pRenderData->ddrval = pDCtx->Begin();
  126. if (pRenderData->ddrval != D3D_OK)
  127. {
  128. return DDHAL_DRIVER_HANDLED;
  129. }
  130. // Render
  131. switch (pIns->bOpcode) {
  132. case D3DOP_POINT:
  133. pDCtx->BeginPrimSet(D3DPT_POINTLIST, RAST_TLVERTEX);
  134. pRenderData->ddrval = DoRendPoints((LPVOID)pDCtx, pDCtx->GetFunsTbl(),
  135. pIns, pVtx, (LPD3DPOINT)pPrim);
  136. break;
  137. case D3DOP_LINE:
  138. pDCtx->BeginPrimSet(D3DPT_LINELIST, RAST_TLVERTEX);
  139. pRenderData->ddrval = DoRendLines((LPVOID)pDCtx, pDCtx->GetFunsTbl(),
  140. pIns, pVtx, (LPD3DLINE)pPrim);
  141. break;
  142. case D3DOP_TRIANGLE:
  143. pDCtx->BeginPrimSet(D3DPT_TRIANGLELIST, RAST_TLVERTEX);
  144. pRenderData->ddrval = DoRendTriangles((LPVOID)pDCtx, pDCtx->GetFunsTbl(),
  145. pIns, pVtx, (LPD3DTRIANGLE)pPrim);
  146. break;
  147. default:
  148. D3D_ERR("(Rast) Wrong Opcode passed to the new rasterizer.");
  149. pRenderData->ddrval = DDERR_INVALIDPARAMS;
  150. break;
  151. }
  152. HRESULT hr;
  153. hr = pDCtx->End();
  154. if (pRenderData->ddrval == D3D_OK)
  155. {
  156. pRenderData->ddrval = hr;
  157. }
  158. return DDHAL_DRIVER_HANDLED;
  159. }
  160. //----------------------------------------------------------------------------
  161. //
  162. // RastRenderPrimitive
  163. //
  164. // Called by Execute() for setting render states.
  165. //
  166. //----------------------------------------------------------------------------
  167. DWORD __stdcall
  168. RastRenderState(LPD3DHAL_RENDERSTATEDATA pStateData)
  169. {
  170. PUINT8 pData;
  171. LPD3DSTATE pState;
  172. INT i;
  173. D3DContext *pDCtx;
  174. VALIDATE_D3DCONTEXT("RastRenderState", pStateData);
  175. // Updates D3DCTX
  176. pData = (PUINT8) (((LPDDRAWI_DDRAWSURFACE_INT)
  177. (pStateData->lpExeBuf))->lpLcl->lpGbl->fpVidMem);
  178. for (i = 0, pState = (LPD3DSTATE) (pData + pStateData->dwOffset);
  179. i < (INT)pStateData->dwCount;
  180. i ++, pState ++)
  181. {
  182. UINT32 type = (UINT32) pState->drstRenderStateType;
  183. // Check for overrides
  184. if (IS_OVERRIDE(type)) {
  185. UINT32 override = GET_OVERRIDE(type);
  186. if (pState->dwArg[0])
  187. STATESET_SET(pDCtx->m_renderstate_override, override);
  188. else
  189. STATESET_CLEAR(pDCtx->m_renderstate_override, override);
  190. continue;
  191. }
  192. if (STATESET_ISSET(pDCtx->m_renderstate_override, type))
  193. continue;
  194. // Set the state
  195. pStateData->ddrval = pDCtx->SetRenderState(type, pState->dwArg[0]);
  196. if (pStateData->ddrval != D3D_OK)
  197. {
  198. return DDHAL_DRIVER_HANDLED;
  199. }
  200. }
  201. return DDHAL_DRIVER_HANDLED;
  202. }