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.

427 lines
15 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // nullif.mcp
  4. //
  5. // Null Device callback functions for D3DIM.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. include(`m4hdr.mh')dnl
  11. #include "pch.cpp"
  12. #pragma hdrstop
  13. // For BASE_VERTEX_COUNT and MAX_CLIP_VERTICES
  14. #include "getcaps.h"
  15. extern D3DDEVICEDESC g_nullDevDesc;
  16. // give DX6 null device same caps as old DX6 reference device
  17. static D3DDEVICEDESC RefDevDesc = { 0 };
  18. static D3DHAL_D3DEXTENDEDCAPS RefExtCaps;
  19. static void
  20. FillOutDeviceCaps( void )
  21. {
  22. //
  23. // set device description
  24. //
  25. RefDevDesc.dwSize = sizeof(RefDevDesc);
  26. RefDevDesc.dwFlags =
  27. D3DDD_COLORMODEL |
  28. D3DDD_DEVCAPS |
  29. D3DDD_TRANSFORMCAPS |
  30. D3DDD_LIGHTINGCAPS |
  31. D3DDD_BCLIPPING |
  32. D3DDD_LINECAPS |
  33. D3DDD_TRICAPS |
  34. D3DDD_DEVICERENDERBITDEPTH |
  35. D3DDD_DEVICEZBUFFERBITDEPTH |
  36. D3DDD_MAXBUFFERSIZE |
  37. D3DDD_MAXVERTEXCOUNT ;
  38. RefDevDesc.dcmColorModel = D3DCOLOR_RGB;
  39. RefDevDesc.dwDevCaps =
  40. D3DDEVCAPS_FLOATTLVERTEX |
  41. D3DDEVCAPS_EXECUTESYSTEMMEMORY |
  42. D3DDEVCAPS_TLVERTEXSYSTEMMEMORY |
  43. D3DDEVCAPS_TEXTURESYSTEMMEMORY |
  44. D3DDEVCAPS_DRAWPRIMTLVERTEX ;
  45. RefDevDesc.dtcTransformCaps.dwSize = sizeof(D3DTRANSFORMCAPS);
  46. RefDevDesc.dtcTransformCaps.dwCaps = D3DTRANSFORMCAPS_CLIP;
  47. RefDevDesc.bClipping = TRUE;
  48. RefDevDesc.dlcLightingCaps.dwSize = sizeof(D3DLIGHTINGCAPS);
  49. RefDevDesc.dlcLightingCaps.dwCaps =
  50. D3DLIGHTCAPS_POINT |
  51. D3DLIGHTCAPS_SPOT |
  52. D3DLIGHTCAPS_DIRECTIONAL |
  53. D3DLIGHTCAPS_PARALLELPOINT ;
  54. RefDevDesc.dlcLightingCaps.dwLightingModel = D3DLIGHTINGMODEL_RGB;
  55. RefDevDesc.dlcLightingCaps.dwNumLights = 0;
  56. RefDevDesc.dpcTriCaps.dwSize = sizeof(D3DPRIMCAPS);
  57. RefDevDesc.dpcTriCaps.dwMiscCaps =
  58. D3DPMISCCAPS_CULLNONE |
  59. D3DPMISCCAPS_CULLCW |
  60. D3DPMISCCAPS_CULLCCW ;
  61. RefDevDesc.dpcTriCaps.dwRasterCaps =
  62. D3DPRASTERCAPS_DITHER |
  63. // D3DPRASTERCAPS_ROP2 |
  64. // D3DPRASTERCAPS_XOR |
  65. // D3DPRASTERCAPS_PAT |
  66. D3DPRASTERCAPS_ZTEST |
  67. D3DPRASTERCAPS_SUBPIXEL |
  68. D3DPRASTERCAPS_SUBPIXELX |
  69. D3DPRASTERCAPS_FOGVERTEX |
  70. D3DPRASTERCAPS_FOGTABLE |
  71. // D3DPRASTERCAPS_STIPPLE |
  72. // D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT |
  73. D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT |
  74. // D3DPRASTERCAPS_ANTIALIASEDGES |
  75. D3DPRASTERCAPS_MIPMAPLODBIAS |
  76. // D3DPRASTERCAPS_ZBIAS |
  77. // D3DPRASTERCAPS_ZBUFFERLESSHSR |
  78. D3DPRASTERCAPS_FOGRANGE |
  79. D3DPRASTERCAPS_ANISOTROPY |
  80. D3DPRASTERCAPS_WBUFFER |
  81. D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT |
  82. D3DPRASTERCAPS_WFOG;
  83. RefDevDesc.dpcTriCaps.dwZCmpCaps =
  84. D3DPCMPCAPS_NEVER |
  85. D3DPCMPCAPS_LESS |
  86. D3DPCMPCAPS_EQUAL |
  87. D3DPCMPCAPS_LESSEQUAL |
  88. D3DPCMPCAPS_GREATER |
  89. D3DPCMPCAPS_NOTEQUAL |
  90. D3DPCMPCAPS_GREATEREQUAL |
  91. D3DPCMPCAPS_ALWAYS ;
  92. RefDevDesc.dpcTriCaps.dwSrcBlendCaps =
  93. D3DPBLENDCAPS_ZERO |
  94. D3DPBLENDCAPS_ONE |
  95. D3DPBLENDCAPS_SRCCOLOR |
  96. D3DPBLENDCAPS_INVSRCCOLOR |
  97. D3DPBLENDCAPS_SRCALPHA |
  98. D3DPBLENDCAPS_INVSRCALPHA |
  99. D3DPBLENDCAPS_DESTALPHA |
  100. D3DPBLENDCAPS_INVDESTALPHA |
  101. D3DPBLENDCAPS_DESTCOLOR |
  102. D3DPBLENDCAPS_INVDESTCOLOR |
  103. D3DPBLENDCAPS_SRCALPHASAT |
  104. D3DPBLENDCAPS_BOTHSRCALPHA |
  105. D3DPBLENDCAPS_BOTHINVSRCALPHA ;
  106. RefDevDesc.dpcTriCaps.dwDestBlendCaps =
  107. D3DPBLENDCAPS_ZERO |
  108. D3DPBLENDCAPS_ONE |
  109. D3DPBLENDCAPS_SRCCOLOR |
  110. D3DPBLENDCAPS_INVSRCCOLOR |
  111. D3DPBLENDCAPS_SRCALPHA |
  112. D3DPBLENDCAPS_INVSRCALPHA |
  113. D3DPBLENDCAPS_DESTALPHA |
  114. D3DPBLENDCAPS_INVDESTALPHA |
  115. D3DPBLENDCAPS_DESTCOLOR |
  116. D3DPBLENDCAPS_INVDESTCOLOR |
  117. D3DPBLENDCAPS_SRCALPHASAT ;
  118. RefDevDesc.dpcTriCaps.dwAlphaCmpCaps =
  119. RefDevDesc.dpcTriCaps.dwZCmpCaps;
  120. RefDevDesc.dpcTriCaps.dwShadeCaps =
  121. D3DPSHADECAPS_COLORFLATRGB |
  122. D3DPSHADECAPS_COLORGOURAUDRGB |
  123. D3DPSHADECAPS_SPECULARFLATRGB |
  124. D3DPSHADECAPS_SPECULARGOURAUDRGB |
  125. D3DPSHADECAPS_ALPHAFLATBLEND |
  126. D3DPSHADECAPS_ALPHAGOURAUDBLEND |
  127. D3DPSHADECAPS_FOGFLAT |
  128. D3DPSHADECAPS_FOGGOURAUD ;
  129. RefDevDesc.dpcTriCaps.dwTextureCaps =
  130. D3DPTEXTURECAPS_PERSPECTIVE |
  131. D3DPTEXTURECAPS_POW2 |
  132. D3DPTEXTURECAPS_ALPHA |
  133. D3DPTEXTURECAPS_TRANSPARENCY |
  134. D3DPTEXTURECAPS_ALPHAPALETTE |
  135. D3DPTEXTURECAPS_BORDER |
  136. D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE |
  137. D3DPTEXTURECAPS_ALPHAPALETTE ;
  138. RefDevDesc.dpcTriCaps.dwTextureFilterCaps =
  139. D3DPTFILTERCAPS_NEAREST |
  140. D3DPTFILTERCAPS_LINEAR |
  141. D3DPTFILTERCAPS_MIPNEAREST |
  142. D3DPTFILTERCAPS_MIPLINEAR |
  143. D3DPTFILTERCAPS_LINEARMIPNEAREST |
  144. D3DPTFILTERCAPS_LINEARMIPLINEAR |
  145. D3DPTFILTERCAPS_MINFPOINT |
  146. D3DPTFILTERCAPS_MINFLINEAR |
  147. D3DPTFILTERCAPS_MINFANISOTROPIC |
  148. D3DPTFILTERCAPS_MIPFPOINT |
  149. D3DPTFILTERCAPS_MIPFLINEAR |
  150. D3DPTFILTERCAPS_MAGFPOINT |
  151. D3DPTFILTERCAPS_MAGFLINEAR |
  152. D3DPTFILTERCAPS_MAGFANISOTROPIC ;
  153. RefDevDesc.dpcTriCaps.dwTextureBlendCaps =
  154. D3DPTBLENDCAPS_DECAL |
  155. D3DPTBLENDCAPS_MODULATE |
  156. D3DPTBLENDCAPS_DECALALPHA |
  157. D3DPTBLENDCAPS_MODULATEALPHA |
  158. // D3DPTBLENDCAPS_DECALMASK |
  159. // D3DPTBLENDCAPS_MODULATEMASK |
  160. D3DPTBLENDCAPS_COPY |
  161. D3DPTBLENDCAPS_ADD ;
  162. RefDevDesc.dpcTriCaps.dwTextureAddressCaps =
  163. D3DPTADDRESSCAPS_WRAP |
  164. D3DPTADDRESSCAPS_MIRROR |
  165. D3DPTADDRESSCAPS_CLAMP |
  166. D3DPTADDRESSCAPS_BORDER |
  167. D3DPTADDRESSCAPS_INDEPENDENTUV ;
  168. RefDevDesc.dpcTriCaps.dwStippleWidth = 0;
  169. RefDevDesc.dpcTriCaps.dwStippleHeight = 0;
  170. // line caps - copy tricaps and modify
  171. memcpy( &RefDevDesc.dpcLineCaps, &RefDevDesc.dpcTriCaps, sizeof(D3DPRIMCAPS) );
  172. RefDevDesc.dwDeviceRenderBitDepth = DDBD_16 | DDBD_24 | DDBD_32;
  173. RefDevDesc.dwDeviceZBufferBitDepth = D3DSWRASTERIZER_ZBUFFERBITDEPTHFLAGS;
  174. RefDevDesc.dwMaxBufferSize = 0;
  175. RefDevDesc.dwMaxVertexCount = BASE_VERTEX_COUNT;
  176. // DX5 stuff (should be in sync with the extended caps reported below)
  177. RefDevDesc.dwMinTextureWidth = 1;
  178. RefDevDesc.dwMaxTextureWidth = 4096;
  179. RefDevDesc.dwMinTextureHeight = 1;
  180. RefDevDesc.dwMaxTextureHeight = 4096;
  181. RefDevDesc.dwMinStippleWidth = 0; // stipple unsupported
  182. RefDevDesc.dwMaxStippleWidth = 0;
  183. RefDevDesc.dwMinStippleHeight = 0;
  184. RefDevDesc.dwMaxStippleHeight = 0;
  185. //
  186. // set extended caps
  187. //
  188. RefExtCaps.dwSize = sizeof(RefExtCaps);
  189. RefExtCaps.dwMinTextureWidth = 1;
  190. RefExtCaps.dwMaxTextureWidth = 4096;
  191. RefExtCaps.dwMinTextureHeight = 1;
  192. RefExtCaps.dwMaxTextureHeight = 4096;
  193. RefExtCaps.dwMinStippleWidth = 0; // stipple unsupported
  194. RefExtCaps.dwMaxStippleWidth = 0;
  195. RefExtCaps.dwMinStippleHeight = 0;
  196. RefExtCaps.dwMaxStippleHeight = 0;
  197. RefExtCaps.dwMaxTextureRepeat = 32768;
  198. RefExtCaps.dwMaxTextureAspectRatio = 0; // no limit
  199. RefExtCaps.dwMaxAnisotropy = 16;
  200. RefExtCaps.dvGuardBandLeft = -32768.f;
  201. RefExtCaps.dvGuardBandTop = -32768.f;
  202. RefExtCaps.dvGuardBandRight = 32767.f;
  203. RefExtCaps.dvGuardBandBottom = 32767.f;
  204. RefExtCaps.dvExtentsAdjust = 0.; // AA kernel is 1.0 x 1.0
  205. RefExtCaps.dwStencilCaps =
  206. D3DSTENCILCAPS_KEEP |
  207. D3DSTENCILCAPS_ZERO |
  208. D3DSTENCILCAPS_REPLACE|
  209. D3DSTENCILCAPS_INCRSAT|
  210. D3DSTENCILCAPS_DECRSAT|
  211. D3DSTENCILCAPS_INVERT |
  212. D3DSTENCILCAPS_INCR |
  213. D3DSTENCILCAPS_DECR;
  214. RefExtCaps.dwFVFCaps = 8; // max number of tex coord sets
  215. RefExtCaps.dwTextureOpCaps =
  216. D3DTEXOPCAPS_DISABLE |
  217. D3DTEXOPCAPS_SELECTARG1 |
  218. D3DTEXOPCAPS_SELECTARG2 |
  219. D3DTEXOPCAPS_MODULATE |
  220. D3DTEXOPCAPS_MODULATE2X |
  221. D3DTEXOPCAPS_MODULATE4X |
  222. D3DTEXOPCAPS_ADD |
  223. D3DTEXOPCAPS_ADDSIGNED |
  224. D3DTEXOPCAPS_ADDSIGNED2X |
  225. D3DTEXOPCAPS_SUBTRACT |
  226. D3DTEXOPCAPS_ADDSMOOTH |
  227. D3DTEXOPCAPS_BLENDDIFFUSEALPHA |
  228. D3DTEXOPCAPS_BLENDTEXTUREALPHA |
  229. D3DTEXOPCAPS_BLENDFACTORALPHA |
  230. D3DTEXOPCAPS_BLENDTEXTUREALPHAPM |
  231. D3DTEXOPCAPS_BLENDCURRENTALPHA |
  232. D3DTEXOPCAPS_PREMODULATE |
  233. D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR |
  234. D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA |
  235. D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR |
  236. D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA |
  237. D3DTEXOPCAPS_BUMPENVMAP |
  238. D3DTEXOPCAPS_BUMPENVMAPLUMINANCE |
  239. D3DTEXOPCAPS_DOTPRODUCT3 ;
  240. RefExtCaps.wMaxTextureBlendStages = 8;
  241. RefExtCaps.wMaxSimultaneousTextures = 8;
  242. }
  243. static D3DHAL_GLOBALDRIVERDATA RefDriverData;
  244. //----------------------------------------------------------------------------
  245. //
  246. // Null Device implementation section
  247. //
  248. //----------------------------------------------------------------------------
  249. dnl
  250. dnl Macro: NullFunc(fn_name)
  251. dnl This macro generates a Null callback function
  252. dnl Usage:
  253. dnl NullFunc(ContextCreate) generates:
  254. dnl
  255. dnl //------------------------------------------------------------------------
  256. dnl // NullDeviceContextCreate
  257. dnl //------------------------------------------------------------------------
  258. dnl DWORD __stdcall
  259. dnl NullDeviceContextCreate(LPD3DHAL_CONTEXTCREATEDATA pCtxData)
  260. dnl {
  261. dnl pCtxData->ddrval = D3D_OK;
  262. dnl return DDHAL_DRIVER_HANDLED;
  263. dnl }
  264. dnl
  265. define(`Null_Func', `
  266. //----------------------------------------------------------------------------
  267. // NullDevice$1
  268. //----------------------------------------------------------------------------
  269. DWORD __stdcall
  270. NullDevice$1(LPD3DHAL`_'d_UpCase($1)DATA pData)
  271. {
  272. pData->ddrval = D3D_OK;
  273. return DDHAL_DRIVER_HANDLED;
  274. }
  275. ')dnl
  276. d_RepStr(`Null_Func(AA)', `AA',
  277. `ContextCreate',
  278. `ContextDestroy',
  279. `SceneCapture',
  280. `SetRenderTarget',
  281. `DrawOneIndexedPrimitive',
  282. `DrawOnePrimitive',
  283. `DrawPrimitives',
  284. `DrawPrimitives2',
  285. `TextureCreate',
  286. `TextureDestroy',
  287. `TextureSwap',
  288. `TextureGetSurf',
  289. `RenderPrimitive',
  290. `RenderState')dnl
  291. //----------------------------------------------------------------------------
  292. // NullDeviceValidateTextureStageState
  293. //----------------------------------------------------------------------------
  294. DWORD __stdcall
  295. NullDeviceValidateTextureStageState(LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA pData)
  296. {
  297. pData->dwNumPasses = 1;
  298. pData->ddrval = D3D_OK;
  299. return DDHAL_DRIVER_HANDLED;
  300. }
  301. //----------------------------------------------------------------------------
  302. //
  303. // NullDeviceHalProvider::GetCaps/GetInterface
  304. //
  305. // Returns the null device's HAL interface.
  306. // RefRast's caps are reflected by this device. Only the actual callbacks
  307. // are different.
  308. //----------------------------------------------------------------------------
  309. static D3DHAL_CALLBACKS NullCallbacks =
  310. {
  311. sizeof(D3DHAL_CALLBACKS),
  312. NullDeviceContextCreate,
  313. NullDeviceContextDestroy,
  314. NULL,
  315. NullDeviceSceneCapture,
  316. NULL,
  317. NULL,
  318. NullDeviceRenderState,
  319. NullDeviceRenderPrimitive,
  320. NULL,
  321. NullDeviceTextureCreate,
  322. NullDeviceTextureDestroy,
  323. NullDeviceTextureSwap,
  324. NullDeviceTextureGetSurf,
  325. // All others NULL.
  326. };
  327. static D3DHAL_CALLBACKS2 NullCallbacks2 =
  328. {
  329. sizeof(D3DHAL_CALLBACKS2),
  330. D3DHAL2_CB32_SETRENDERTARGET |
  331. D3DHAL2_CB32_DRAWONEPRIMITIVE |
  332. D3DHAL2_CB32_DRAWONEINDEXEDPRIMITIVE |
  333. D3DHAL2_CB32_DRAWPRIMITIVES,
  334. NullDeviceSetRenderTarget,
  335. NULL,
  336. NullDeviceDrawOnePrimitive,
  337. NullDeviceDrawOneIndexedPrimitive,
  338. NullDeviceDrawPrimitives
  339. };
  340. static D3DHAL_CALLBACKS3 NullCallbacks3 =
  341. {
  342. sizeof(D3DHAL_CALLBACKS3),
  343. D3DHAL3_CB32_VALIDATETEXTURESTAGESTATE |
  344. D3DHAL3_CB32_DRAWPRIMITIVES2,
  345. NULL, // Clear2
  346. NULL, // lpvReserved
  347. NullDeviceValidateTextureStageState,
  348. NullDeviceDrawPrimitives2,
  349. };
  350. STDMETHODIMP
  351. NullDeviceHalProvider::GetInterface(THIS_
  352. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  353. LPD3DHALPROVIDER_INTERFACEDATA pInterfaceData,
  354. DWORD dwVersion)
  355. {
  356. // fill out device description & extended caps (once)
  357. if ( RefDevDesc.dwSize == 0 )
  358. {
  359. FillOutDeviceCaps();
  360. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps); // add extended caps to RefDevDesc
  361. }
  362. // fill out GLOBALDRIVERDATA (initially zero)
  363. RefDriverData.dwSize = sizeof(RefDriverData);
  364. memcpy(&RefDriverData.hwCaps, &RefDevDesc, sizeof(RefDriverData.hwCaps));
  365. RefDriverData.dwNumVertices = BASE_VERTEX_COUNT;
  366. RefDriverData.dwNumClipVertices = MAX_CLIP_VERTICES;
  367. RefDriverData.dwNumTextureFormats =
  368. TextureFormats(&RefDriverData.lpTextureFormats, dwVersion, SW_RAST_REFNULL);
  369. // set interface data for return
  370. pInterfaceData->pGlobalData = &RefDriverData;
  371. pInterfaceData->pExtCaps = &RefExtCaps;
  372. pInterfaceData->pCallbacks = &NullCallbacks;
  373. pInterfaceData->pCallbacks2 = &NullCallbacks2;
  374. pInterfaceData->pCallbacks3 = &NullCallbacks3;
  375. pInterfaceData->pfnRampService = NULL;
  376. return S_OK;
  377. }
  378. STDMETHODIMP
  379. NullDeviceHalProvider::GetCaps(THIS_
  380. LPDDRAWI_DIRECTDRAW_GBL pDdGbl,
  381. LPD3DDEVICEDESC pHwDesc,
  382. LPD3DDEVICEDESC pHelDesc,
  383. DWORD dwVersion)
  384. {
  385. *pHwDesc = g_nullDevDesc;
  386. // fill out device description & extended caps (once)
  387. if ( RefDevDesc.dwSize == 0 )
  388. {
  389. FillOutDeviceCaps();
  390. D3DDeviceDescConvert(&RefDevDesc,NULL,&RefExtCaps); // add extended caps to RefDevDesc
  391. }
  392. *pHelDesc = RefDevDesc;
  393. return D3D_OK;
  394. }