Source code of Windows XP (NT5)
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.

341 lines
13 KiB

  1. #if _MSC_VER > 1000
  2. #pragma once
  3. #endif // _MSC_VER > 1000
  4. // forward declaration
  5. class CMyRasterizer;
  6. ////////////////////////////////////////////////////////////////////////////////
  7. //
  8. // CMyDriver
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. class CMyDriver:
  12. public CMinimalDriver< CMyDriver, CMyRasterizer>
  13. {
  14. private:
  15. static const CSurfaceCapWrap c_aSurfaces[];
  16. static const D3DCAPS8 c_D3DCaps;
  17. protected:
  18. public:
  19. CMyDriver();
  20. ~CMyDriver()
  21. { }
  22. static const D3DCAPS8 GetCaps( void)
  23. { return c_D3DCaps; }
  24. };
  25. ////////////////////////////////////////////////////////////////////////////////
  26. //
  27. // CMyRasterizer
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30. class CMyRasterizer
  31. {
  32. public: // Types
  33. typedef CMyDriver::TContext TContext;
  34. protected:
  35. int m_iVal;
  36. public:
  37. CMyRasterizer() { }
  38. ~CMyRasterizer() { }
  39. HRESULT DrawPrimitive( TContext& Context, const D3DHAL_DP2COMMAND& DP2Cmd,
  40. const D3DHAL_DP2DRAWPRIMITIVE* aDP2Param)
  41. {
  42. // Context can be converted to this structure.
  43. const D3DHAL_DP2VERTEXSHADER VertexShader( Context);
  44. // We need this data.
  45. UINT8* pStartVData= NULL;
  46. DWORD dwVStride( 0);
  47. // Since Sample is a non TnL device, the vertex shader handle should
  48. // always be a fixed function FVF.
  49. const DWORD dwFVF( VertexShader.dwHandle);
  50. // Since Sample only supports one stream, our data source should be
  51. // from stream 0.
  52. TContext::TVStream& VStream0( Context.GetVStream( 0));
  53. VStream0.SetFVF( dwFVF);
  54. // Find vertex information.
  55. if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::User)
  56. {
  57. pStartVData= reinterpret_cast< UINT8*>( VStream0.GetUserMemPtr());
  58. dwVStride= VStream0.GetStride();
  59. }
  60. else if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::System||
  61. VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::Video)
  62. {
  63. // Sample can pretend system mem and video mem surfaces are the same.
  64. pStartVData= reinterpret_cast< UINT8*>(
  65. VStream0.GetSurfDBRepresentation()->GetGBLfpVidMem());
  66. dwVStride= VStream0.GetStride();
  67. }
  68. if( pStartVData!= NULL)
  69. {
  70. const D3DHAL_DP2DRAWPRIMITIVE* pParam= aDP2Param;
  71. WORD wPrimitiveCount( DP2Cmd.wPrimitiveCount);
  72. if( wPrimitiveCount) do
  73. {
  74. const UINT8* pVData= pStartVData+ pParam->VStart* dwVStride;
  75. DrawOnePrimitive( Context, pParam->primType,
  76. pParam->PrimitiveCount, pVData, dwVStride, dwFVF);
  77. pParam++;
  78. } while( --wPrimitiveCount);
  79. }
  80. return DD_OK;
  81. }
  82. HRESULT DrawPrimitive2( TContext& Context, const D3DHAL_DP2COMMAND& DP2Cmd,
  83. const D3DHAL_DP2DRAWPRIMITIVE2* aDP2Param)
  84. {
  85. // Context can be converted to this structure.
  86. const D3DHAL_DP2VERTEXSHADER VertexShader( Context);
  87. // We need this data.
  88. UINT8* pStartVData= NULL;
  89. DWORD dwVStride( 0);
  90. // Since Sample is a non TnL device, the vertex shader handle should
  91. // always be a fixed function FVF.
  92. const DWORD dwFVF( VertexShader.dwHandle);
  93. // Since Sample only supports one stream, our data source should be
  94. // from stream 0.
  95. TContext::TVStream& VStream0( Context.GetVStream( 0));
  96. VStream0.SetFVF( dwFVF);
  97. // Find vertex information.
  98. if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::User)
  99. {
  100. pStartVData= reinterpret_cast< UINT8*>( VStream0.GetUserMemPtr());
  101. dwVStride= VStream0.GetStride();
  102. }
  103. else if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::System||
  104. VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::Video)
  105. {
  106. // Sample can pretend system mem and video mem surfaces are the same.
  107. pStartVData= reinterpret_cast< UINT8*>(
  108. VStream0.GetSurfDBRepresentation()->GetGBLfpVidMem());
  109. dwVStride= VStream0.GetStride();
  110. }
  111. if( pStartVData!= NULL)
  112. {
  113. const D3DHAL_DP2DRAWPRIMITIVE2* pParam= aDP2Param;
  114. WORD wPrimitiveCount( DP2Cmd.wPrimitiveCount);
  115. if( wPrimitiveCount) do
  116. {
  117. const UINT8* pVData= pStartVData+ pParam->FirstVertexOffset;
  118. DrawOnePrimitive( Context, pParam->primType,
  119. pParam->PrimitiveCount, pVData, dwVStride, dwFVF);
  120. pParam++;
  121. } while( --wPrimitiveCount);
  122. }
  123. return DD_OK;
  124. }
  125. HRESULT DrawIndexedPrimitive( TContext& Context, const D3DHAL_DP2COMMAND& DP2Cmd,
  126. const D3DHAL_DP2DRAWINDEXEDPRIMITIVE* aDP2Param)
  127. {
  128. // Context can be converted to these structures.
  129. const D3DHAL_DP2VERTEXSHADER VertexShader( Context);
  130. // We need this data.
  131. UINT8* pStartVData= NULL;
  132. UINT16* pStartIData= NULL;
  133. DWORD dwVStride( 0);
  134. DWORD dwIStride( 0);
  135. // Since Sample is a non TnL device, the vertex shader handle should
  136. // always be a fixed function FVF.
  137. const DWORD dwFVF( VertexShader.dwHandle);
  138. // Since Sample only supports one stream, our data source should be
  139. // from stream 0.
  140. TContext::TVStream& VStream0= Context.GetVStream( 0);
  141. VStream0.SetFVF( dwFVF);
  142. // Find vertex information.
  143. if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::User)
  144. {
  145. pStartVData= reinterpret_cast< UINT8*>( VStream0.GetUserMemPtr());
  146. dwVStride= VStream0.GetStride();
  147. }
  148. else if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::System||
  149. VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::Video)
  150. {
  151. // Sample can pretend system mem and video mem surfaces are the same.
  152. pStartVData= reinterpret_cast< UINT8*>(
  153. VStream0.GetSurfDBRepresentation()->GetGBLfpVidMem());
  154. dwVStride= VStream0.GetStride();
  155. }
  156. // Find Indices information.
  157. TContext::TIStream& IStream= Context.GetIStream( 0);
  158. if( IStream.GetMemLocation()== TContext::TIStream::EMemLocation::System||
  159. IStream.GetMemLocation()== TContext::TIStream::EMemLocation::Video)
  160. {
  161. // Sample can pretend system mem and video mem surfaces are the same.
  162. pStartIData= reinterpret_cast< UINT16*>(
  163. IStream.GetSurfDBRepresentation()->GetGBLfpVidMem());
  164. dwIStride= IStream.GetStride();
  165. }
  166. if( pStartVData!= NULL&& pStartIData!= NULL)
  167. {
  168. // Sample should've marked caps as only supporting 16-bit indices.
  169. assert( sizeof(UINT16)== dwIStride);
  170. const D3DHAL_DP2DRAWINDEXEDPRIMITIVE* pParam= aDP2Param;
  171. WORD wPrimitiveCount( DP2Cmd.wPrimitiveCount);
  172. if( wPrimitiveCount) do
  173. {
  174. const UINT8* pVData= pStartVData+ pParam->BaseVertexIndex* dwVStride;
  175. const UINT16* pIData= pStartIData+ pParam->StartIndex; //* dwIStride;
  176. DrawOneIPrimitive( Context, pParam->primType,
  177. pParam->PrimitiveCount, pVData, dwVStride, dwFVF, pIData);
  178. pParam++;
  179. } while( --wPrimitiveCount);
  180. }
  181. return DD_OK;
  182. }
  183. HRESULT DrawIndexedPrimitive2( TContext& Context, const D3DHAL_DP2COMMAND& DP2Cmd,
  184. const D3DHAL_DP2DRAWINDEXEDPRIMITIVE2* aDP2Param)
  185. {
  186. // Context can be converted to these structures.
  187. const D3DHAL_DP2VERTEXSHADER VertexShader( Context);
  188. // We need this data.
  189. UINT8* pStartVData= NULL;
  190. UINT16* pStartIData= NULL;
  191. DWORD dwVStride( 0);
  192. DWORD dwIStride( 0);
  193. // Since Sample is a non TnL device, the vertex shader handle should
  194. // always be a fixed function FVF.
  195. const DWORD dwFVF( VertexShader.dwHandle);
  196. // Since Sample only supports one stream, our data source should be
  197. // from stream 0.
  198. TContext::TVStream& VStream0( Context.GetVStream( 0));
  199. VStream0.SetFVF( dwFVF);
  200. // Find vertex information.
  201. if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::User)
  202. {
  203. pStartVData= reinterpret_cast< UINT8*>( VStream0.GetUserMemPtr());
  204. dwVStride= VStream0.GetStride();
  205. }
  206. else if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::System||
  207. VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::Video)
  208. {
  209. // Sample can pretend system mem and video mem surfaces are the same.
  210. pStartVData= reinterpret_cast< UINT8*>(
  211. VStream0.GetSurfDBRepresentation()->GetGBLfpVidMem());
  212. dwVStride= VStream0.GetStride();
  213. }
  214. // Find Indices information.
  215. TContext::TIStream& IStream= Context.GetIStream( 0);
  216. if( IStream.GetMemLocation()== TContext::TIStream::EMemLocation::System||
  217. IStream.GetMemLocation()== TContext::TIStream::EMemLocation::Video)
  218. {
  219. // Sample can pretend system mem and video mem surfaces are the same.
  220. pStartIData= reinterpret_cast< UINT16*>(
  221. IStream.GetSurfDBRepresentation()->GetGBLfpVidMem());
  222. dwIStride= IStream.GetStride();
  223. }
  224. if( pStartVData!= NULL&& pStartIData!= NULL)
  225. {
  226. // Sample should've marked caps as only supporting 16-bit indices.
  227. assert( sizeof(UINT16)== dwIStride);
  228. const D3DHAL_DP2DRAWINDEXEDPRIMITIVE2* pParam= aDP2Param;
  229. WORD wPrimitiveCount( DP2Cmd.wPrimitiveCount);
  230. if( wPrimitiveCount) do
  231. {
  232. const UINT8* pVData= pStartVData+ pParam->BaseVertexOffset;
  233. const UINT16* pIData= reinterpret_cast< const UINT16*>(
  234. pStartIData+ pParam->StartIndexOffset);
  235. DrawOneIPrimitive( Context, pParam->primType,
  236. pParam->PrimitiveCount, pVData, dwVStride, dwFVF, pIData);
  237. pParam++;
  238. } while( --wPrimitiveCount);
  239. }
  240. return DD_OK;
  241. }
  242. HRESULT ClippedTriangleFan( TContext& Context, const D3DHAL_DP2COMMAND& DP2Cmd,
  243. const D3DHAL_CLIPPEDTRIANGLEFAN* aDP2Param)
  244. {
  245. // Context can be converted to this structure.
  246. const D3DHAL_DP2VERTEXSHADER VertexShader( Context);
  247. // We need this data.
  248. UINT8* pStartVData= NULL;
  249. DWORD dwVStride( 0);
  250. // Since Sample is a non TnL device, the vertex shader handle should
  251. // always be a fixed function FVF.
  252. const DWORD dwFVF( VertexShader.dwHandle);
  253. // Since Sample only supports one stream, our data source should be
  254. // from stream 0.
  255. TContext::TVStream& VStream0( Context.GetVStream( 0));
  256. VStream0.SetFVF( dwFVF);
  257. // Find vertex information.
  258. if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::User)
  259. {
  260. pStartVData= reinterpret_cast< UINT8*>( VStream0.GetUserMemPtr());
  261. dwVStride= VStream0.GetStride();
  262. }
  263. else if( VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::System||
  264. VStream0.GetMemLocation()== TContext::TVStream::EMemLocation::Video)
  265. {
  266. // Sample can pretend system mem and video mem surfaces are the same.
  267. pStartVData= reinterpret_cast< UINT8*>(
  268. VStream0.GetSurfDBRepresentation()->GetGBLfpVidMem());
  269. dwVStride= VStream0.GetStride();
  270. }
  271. if( pStartVData!= NULL)
  272. {
  273. const D3DHAL_CLIPPEDTRIANGLEFAN* pParam= aDP2Param;
  274. WORD wPrimitiveCount( DP2Cmd.wPrimitiveCount);
  275. if( wPrimitiveCount) do
  276. {
  277. const UINT8* pVData= pStartVData+ pParam->FirstVertexOffset;
  278. // Must use pParam->dwEdgeFlags for correct drawing of wireframe.
  279. if( Context.GetRenderStateDW( D3DRS_FILLMODE)!= D3DFILL_WIREFRAME)
  280. DrawOnePrimitive( Context, D3DPT_TRIANGLEFAN,
  281. pParam->PrimitiveCount, pVData, dwVStride, dwFVF);
  282. else
  283. assert( false); // NYI
  284. pParam++;
  285. } while( --wPrimitiveCount);
  286. }
  287. return DD_OK;
  288. }
  289. void DrawOnePrimitive( TContext& Context, D3DPRIMITIVETYPE primType,
  290. WORD wPrims, const UINT8* pVData, DWORD dwVStride, DWORD dwFVF)
  291. { }
  292. void DrawOneIPrimitive( TContext& Context, D3DPRIMITIVETYPE primType,
  293. WORD wPrims, const UINT8* pVData, DWORD dwVStride, DWORD dwFVF,
  294. const UINT16* pIData)
  295. { }
  296. };