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.

197 lines
7.2 KiB

  1. /*==========================================================================;
  2. *
  3. * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dpgen.h
  6. * Content: Generate some functions for Draw Primitive
  7. *
  8. ***************************************************************************/
  9. #ifdef __DRAWPRIMFUNC
  10. //---------------------------------------------------------------------
  11. // Draws indexed and non-indexed primitives which do not require clipping
  12. //
  13. #ifdef __DRAWPRIMINDEX
  14. HRESULT CDirect3DDeviceIDP::DrawIndexPrim()
  15. {
  16. D3DHAL_DRAWONEINDEXEDPRIMITIVEDATA dpData;
  17. DWORD &dwNumElements = this->dwNumIndices;
  18. #else
  19. HRESULT CDirect3DDeviceIDP::DrawPrim()
  20. {
  21. D3DHAL_DRAWONEPRIMITIVEDATA dpData;
  22. DWORD &dwNumElements = this->dwNumVertices;
  23. #endif
  24. const WORD vertexType = D3DVT_TLVERTEX; // XXX While we do not have DDI
  25. // Do we need to map new texture stage operations to DX5 renderstates?
  26. if(this->dwFEFlags & D3DFE_MAP_TSS_TO_RS) {
  27. MapTSSToRS();
  28. this->dwFEFlags &= ~D3DFE_MAP_TSS_TO_RS; // Reset request bit
  29. }
  30. if(this->dwFEFlags & D3DFE_NEED_TEXTURE_UPDATE)
  31. {
  32. HRESULT ret = UpdateTextures();
  33. if(ret != D3D_OK)
  34. {
  35. D3D_ERR("UpdateTextures failed. Device probably doesn't support current texture (check return code).");
  36. return ret;
  37. }
  38. this->dwFEFlags &= ~D3DFE_NEED_TEXTURE_UPDATE;
  39. }
  40. if (dwNumElements < LOWVERTICESNUMBERDP &&
  41. this->dwCurrentBatchVID == this->dwVIDOut)
  42. {
  43. LPD3DHAL_DRAWPRIMCOUNTS lpPC;
  44. lpPC = this->lpDPPrimCounts;
  45. if (lpPC->wNumVertices)
  46. {
  47. if ((lpPC->wPrimitiveType!=(WORD) this->primType) ||
  48. (lpPC->wVertexType != vertexType) ||
  49. (this->primType==D3DPT_TRIANGLESTRIP) ||
  50. (this->primType==D3DPT_TRIANGLEFAN) ||
  51. (this->primType==D3DPT_LINESTRIP))
  52. {
  53. lpPC = this->lpDPPrimCounts=(LPD3DHAL_DRAWPRIMCOUNTS)
  54. ((LPBYTE)this->lpwDPBuffer + this->dwDPOffset);
  55. memset( (char *)lpPC, 0, sizeof(D3DHAL_DRAWPRIMCOUNTS));
  56. // preserve 32 bytes alignment for vertices
  57. this->dwDPOffset += sizeof(D3DHAL_DRAWPRIMCOUNTS);
  58. ALIGN32(this->dwDPOffset);
  59. }
  60. }
  61. else
  62. {
  63. // 32-byte align offset pointer, just in case states have been
  64. // recorded.
  65. ALIGN32(this->dwDPOffset);
  66. }
  67. ULONG ByteCount;
  68. if (FVF_DRIVERSUPPORTED(this))
  69. ByteCount = dwNumElements * this->dwOutputSize;
  70. else
  71. ByteCount = dwNumElements << 5; // D3DTLVERTEX
  72. if (this->dwDPOffset + ByteCount > this->dwDPMaxOffset)
  73. {
  74. CLockD3DST lockObject(this, DPF_MODNAME, REMIND("")); // Takes D3D lock (ST only).
  75. //DPF(0,"overflowed ByteCount=%08lx",ByteCount);
  76. HRESULT ret;
  77. ret = this->FlushStates();
  78. if (ret != D3D_OK)
  79. {
  80. D3D_ERR("Error trying to render batched commands in Draw*Prim");
  81. return ret;
  82. }
  83. lpPC = this->lpDPPrimCounts;
  84. ALIGN32(this->dwDPOffset);
  85. }
  86. lpPC->wPrimitiveType = (WORD)this->primType;
  87. lpPC->wVertexType = (WORD)vertexType;
  88. lpPC->wNumVertices += (WORD)dwNumElements;
  89. BYTE *lpVertex = (BYTE*)((char *)this->lpwDPBuffer + this->dwDPOffset);
  90. #ifdef __DRAWPRIMINDEX
  91. DWORD i;
  92. BYTE *pV = (BYTE*)this->lpvOut;
  93. if (FVF_DRIVERSUPPORTED(this) || this->dwVIDOut == D3DFVF_TLVERTEX)
  94. for (i=0; i < this->dwNumIndices; i++)
  95. {
  96. memcpy(lpVertex, pV + this->lpwIndices[i] * this->dwOutputSize,
  97. this->dwOutputSize);
  98. lpVertex += this->dwOutputSize;
  99. }
  100. else
  101. for (i=0; i < this->dwNumIndices; i++)
  102. {
  103. MapFVFtoTLVertex1(this, (D3DTLVERTEX*)lpVertex,
  104. (DWORD*)(pV + this->lpwIndices[i] *
  105. this->dwOutputSize));
  106. lpVertex += sizeof(D3DTLVERTEX);
  107. }
  108. #else // !__DRAWPRIMINDEX
  109. if (FVF_DRIVERSUPPORTED(this) || this->dwVIDOut == D3DFVF_TLVERTEX)
  110. memcpy(lpVertex, this->lpvOut, ByteCount);
  111. else
  112. MapFVFtoTLVertex(lpVertex);
  113. #endif //__DRAWPRIMINDEX
  114. this->dwDPOffset += ByteCount;
  115. return D3D_OK;
  116. }
  117. else
  118. {
  119. CLockD3DST lockObject(this, DPF_MODNAME, REMIND("")); // Takes D3D lock (ST only).
  120. HRESULT ret;
  121. ret = this->FlushStates();
  122. if (ret != D3D_OK)
  123. {
  124. D3D_ERR("Error trying to render batched commands in Draw*Prim");
  125. return ret;
  126. }
  127. dpData.dwhContext = this->dwhContext;
  128. dpData.dwFlags = this->dwFlags;
  129. dpData.PrimitiveType = this->primType;
  130. if (FVF_DRIVERSUPPORTED(this))
  131. {
  132. dpData.dwFVFControl = this->dwVIDOut;
  133. dpData.lpvVertices = this->lpvOut;
  134. }
  135. else
  136. {
  137. if (this->dwVIDOut == D3DFVF_TLVERTEX)
  138. dpData.lpvVertices = this->lpvOut;
  139. else
  140. {
  141. HRESULT ret;
  142. #ifdef __DRAWPRIMINDEX
  143. if (this->dwNumIndices * INDEX_BATCH_SCALE < this->dwNumVertices)
  144. ret = this->MapFVFtoTLVertexIndexed();
  145. else
  146. #endif
  147. ret = MapFVFtoTLVertex(NULL);
  148. if (ret != D3D_OK)
  149. return ret;
  150. dpData.lpvVertices = this->TLVbuf.GetAddress();
  151. }
  152. dpData.VertexType = (D3DVERTEXTYPE)vertexType;
  153. if (this->dwDebugFlags & D3DDEBUG_DISABLEFVF)
  154. dpData.dwFVFControl = D3DFVF_TLVERTEX;
  155. }
  156. dpData.dwNumVertices = this->dwNumVertices;
  157. dpData.ddrval = D3D_OK;
  158. #ifdef __DRAWPRIMINDEX
  159. dpData.lpwIndices = this->lpwIndices;
  160. dpData.dwNumIndices = this->dwNumIndices;
  161. #endif
  162. // Spin waiting on the driver if wait requested
  163. #if _D3D_FORCEDOUBLE
  164. CD3DForceFPUDouble ForceFPUDouble(this);
  165. #endif //_D3D_FORCEDOUBLE
  166. do {
  167. DWORD dwRet;
  168. #ifndef WIN95
  169. if((dwRet = CheckContextSurface(this)) != D3D_OK)
  170. {
  171. return (dwRet);
  172. }
  173. #endif //WIN95
  174. #ifdef __DRAWPRIMINDEX
  175. CALL_HAL2ONLY(dwRet, this, DrawOneIndexedPrimitive, &dpData);
  176. #else
  177. CALL_HAL2ONLY(dwRet, this, DrawOnePrimitive, &dpData);
  178. #endif
  179. if (dwRet != DDHAL_DRIVER_HANDLED)
  180. {
  181. D3D_ERR ( "Driver not handled in DrawOnePrimitive" );
  182. // Need sensible return value in this case,
  183. // currently we return whatever the driver stuck in here.
  184. }
  185. } while ( (this->dwFlags & D3DDP_WAIT) && (dpData.ddrval == DDERR_WASSTILLDRAWING) );
  186. }
  187. return dpData.ddrval;
  188. }
  189. #endif //__DRAWPRIMFUNC
  190. #undef __DRAWPRIMFUNC
  191. #undef __DRAWPRIMINDEX