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.

186 lines
6.8 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. UpdateTextures();
  33. this->dwFEFlags &= ~D3DFE_NEED_TEXTURE_UPDATE;
  34. }
  35. if (dwNumElements < LOWVERTICESNUMBER &&
  36. this->dwCurrentBatchVID == this->dwVIDOut)
  37. {
  38. LPD3DHAL_DRAWPRIMCOUNTS lpPC;
  39. lpPC = this->lpDPPrimCounts;
  40. if (lpPC->wNumVertices)
  41. {
  42. if ((lpPC->wPrimitiveType!=(WORD) this->primType) ||
  43. (lpPC->wVertexType != vertexType) ||
  44. (this->primType==D3DPT_TRIANGLESTRIP) ||
  45. (this->primType==D3DPT_TRIANGLEFAN) ||
  46. (this->primType==D3DPT_LINESTRIP))
  47. {
  48. lpPC = this->lpDPPrimCounts=(LPD3DHAL_DRAWPRIMCOUNTS)
  49. ((LPBYTE)this->lpwDPBuffer + this->dwDPOffset);
  50. memset( (char *)lpPC, 0, sizeof(D3DHAL_DRAWPRIMCOUNTS));
  51. // preserve 32 bytes alignment for vertices
  52. this->dwDPOffset += sizeof(D3DHAL_DRAWPRIMCOUNTS);
  53. ALIGN32(this->dwDPOffset);
  54. }
  55. }
  56. else
  57. {
  58. // 32-byte align offset pointer, just in case states have been
  59. // recorded.
  60. ALIGN32(this->dwDPOffset);
  61. }
  62. ULONG ByteCount;
  63. if (FVF_DRIVERSUPPORTED(this))
  64. ByteCount = dwNumElements * this->dwOutputSize;
  65. else
  66. ByteCount = dwNumElements << 5; // D3DTLVERTEX
  67. if (this->dwDPOffset + ByteCount > this->dwDPMaxOffset)
  68. {
  69. CLockD3DST lockObject(this, DPF_MODNAME, REMIND("")); // Takes D3D lock (ST only).
  70. //DPF(0,"overflowed ByteCount=%08lx",ByteCount);
  71. HRESULT ret;
  72. ret = this->FlushStates();
  73. if (ret != D3D_OK)
  74. {
  75. D3D_ERR("Error trying to render batched commands in Draw*Prim");
  76. return ret;
  77. }
  78. lpPC = this->lpDPPrimCounts;
  79. ALIGN32(this->dwDPOffset);
  80. }
  81. lpPC->wPrimitiveType = (WORD)this->primType;
  82. lpPC->wVertexType = (WORD)vertexType;
  83. lpPC->wNumVertices += (WORD)dwNumElements;
  84. BYTE *lpVertex = (BYTE*)((char *)this->lpwDPBuffer + this->dwDPOffset);
  85. #ifdef __DRAWPRIMINDEX
  86. DWORD i;
  87. BYTE *pV = (BYTE*)this->lpvOut;
  88. if (FVF_DRIVERSUPPORTED(this) || this->dwVIDOut == D3DFVF_TLVERTEX)
  89. for (i=0; i < this->dwNumIndices; i++)
  90. {
  91. memcpy(lpVertex, pV + this->lpwIndices[i] * this->dwOutputSize,
  92. this->dwOutputSize);
  93. lpVertex += this->dwOutputSize;
  94. }
  95. else
  96. for (i=0; i < this->dwNumIndices; i++)
  97. {
  98. MapFVFtoTLVertex1(this, (D3DTLVERTEX*)lpVertex,
  99. (DWORD*)(pV + this->lpwIndices[i] *
  100. this->dwOutputSize));
  101. lpVertex += sizeof(D3DTLVERTEX);
  102. }
  103. #else // !__DRAWPRIMINDEX
  104. if (FVF_DRIVERSUPPORTED(this) || this->dwVIDOut == D3DFVF_TLVERTEX)
  105. memcpy(lpVertex, this->lpvOut, ByteCount);
  106. else
  107. MapFVFtoTLVertex(this, lpVertex);
  108. #endif //__DRAWPRIMINDEX
  109. this->dwDPOffset += ByteCount;
  110. return D3D_OK;
  111. }
  112. else
  113. {
  114. CLockD3DST lockObject(this, DPF_MODNAME, REMIND("")); // Takes D3D lock (ST only).
  115. HRESULT ret;
  116. ret = this->FlushStates();
  117. if (ret != D3D_OK)
  118. {
  119. D3D_ERR("Error trying to render batched commands in Draw*Prim");
  120. return ret;
  121. }
  122. dpData.dwhContext = this->dwhContext;
  123. dpData.dwFlags = this->dwFlags;
  124. dpData.PrimitiveType = this->primType;
  125. if (FVF_DRIVERSUPPORTED(this))
  126. {
  127. dpData.dwFVFControl = this->dwVIDOut;
  128. dpData.lpvVertices = this->lpvOut;
  129. }
  130. else
  131. {
  132. if (this->dwVIDOut == D3DFVF_TLVERTEX)
  133. dpData.lpvVertices = this->lpvOut;
  134. else
  135. {
  136. HRESULT ret;
  137. if ((ret = MapFVFtoTLVertex(this, NULL)) != D3D_OK)
  138. return ret;
  139. dpData.lpvVertices = this->TLVbuf.GetAddress();
  140. }
  141. dpData.VertexType = (D3DVERTEXTYPE)vertexType;
  142. if (this->dwDebugFlags & D3DDEBUG_DISABLEFVF)
  143. dpData.dwFVFControl = D3DFVF_TLVERTEX;
  144. }
  145. dpData.dwNumVertices = this->dwNumVertices;
  146. dpData.ddrval = D3D_OK;
  147. #ifdef __DRAWPRIMINDEX
  148. dpData.lpwIndices = this->lpwIndices;
  149. dpData.dwNumIndices = this->dwNumIndices;
  150. #endif
  151. // Spin waiting on the driver if wait requested
  152. #if _D3D_FORCEDOUBLE
  153. CD3DForceFPUDouble ForceFPUDouble(this);
  154. #endif //_D3D_FORCEDOUBLE
  155. do {
  156. DWORD dwRet;
  157. #ifndef WIN95
  158. if((dwRet = CheckContextSurface(this)) != D3D_OK)
  159. {
  160. return (dwRet);
  161. }
  162. #endif //WIN95
  163. #ifdef __DRAWPRIMINDEX
  164. CALL_HAL2ONLY(dwRet, this, DrawOneIndexedPrimitive, &dpData);
  165. #else
  166. CALL_HAL2ONLY(dwRet, this, DrawOnePrimitive, &dpData);
  167. #endif
  168. if (dwRet != DDHAL_DRIVER_HANDLED)
  169. {
  170. D3D_ERR ( "Driver not handled in DrawOnePrimitive" );
  171. // Need sensible return value in this case,
  172. // currently we return whatever the driver stuck in here.
  173. }
  174. } while ( (this->dwFlags & D3DDP_WAIT) && (dpData.ddrval == DDERR_WASSTILLDRAWING) );
  175. }
  176. return dpData.ddrval;
  177. }
  178. #endif //__DRAWPRIMFUNC
  179. #undef __DRAWPRIMFUNC
  180. #undef __DRAWPRIMINDEX