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.

699 lines
23 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // d3dif.hpp
  4. //
  5. // D3D front-end/rasterizer interface header.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #ifndef _D3DIF_HPP_
  11. #define _D3DIF_HPP_
  12. #include <setup.hpp>
  13. // For Primitive function prototypes.
  14. #include <pmfns_mh.h>
  15. // Vertex data is aligned on 32-byte boundaries.
  16. #define DP_VTX_ALIGN 32
  17. // Flags for uflags of D3DContex
  18. #define D3DCONTEXT_IN_BEGIN 0x0001
  19. #define D3DCONTEXT_TEXTURE_LOCKED 0x0002
  20. #define D3DCONTEXT_APPHACK_MSGOLF 0x0004
  21. // Flags for D3DDEVICEDESC dwDeviceZBufferBitDepth
  22. // Note: This must be replicated in ddraw\ddd3dapi.h so DDHEL can pick them up
  23. // It only affect what legacy apps see when using GetCaps or EnumDevices,
  24. // internally ZBufferFormats() is checked when on ZBuffer creation.
  25. // Note stencil formats should have no representation in this flag word
  26. // becase legacy apps will be fooled into trying to create a Z-only surface
  27. // at the DDBD bitdepth and fail. New apps should ignore dwDeviceZBufferBitDepth
  28. // and use EnumZBufferFormats
  29. #define D3DSWRASTERIZER_ZBUFFERBITDEPTHFLAGS (DDBD_16)
  30. // Macros used to access DDRAW surface info.
  31. #define DDSurf_Width(lpLcl) ( (lpLcl)->lpGbl->wWidth )
  32. #define DDSurf_Pitch(lpLcl) ( (lpLcl)->lpGbl->lPitch )
  33. #define DDSurf_Height(lpLcl) ( (lpLcl)->lpGbl->wHeight )
  34. #define DDSurf_BitDepth(lpLcl) \
  35. ( (lpLcl->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  36. (lpLcl->lpGbl->ddpfSurface.dwRGBBitCount) : \
  37. (lpLcl->lpGbl->lpDD->vmiData.ddpfDisplay.dwRGBBitCount) \
  38. )
  39. #define DDSurf_PixFmt(lpLcl) \
  40. ( ((lpLcl)->dwFlags & DDRAWISURF_HASPIXELFORMAT) ? \
  41. ((lpLcl)->lpGbl->ddpfSurface) : \
  42. ((lpLcl)->lpGbl->lpDD->vmiData.ddpfDisplay) \
  43. )
  44. #define VIDEO_MEMORY(pDDS) \
  45. (!(((LPDDRAWI_DDRAWSURFACE_INT) (pDDS))->lpLcl->lpGbl->dwGlobalFlags & \
  46. DDRAWISURFGBL_SYSMEMREQUESTED))
  47. #define SURFACE_LOCKED(pDDS) \
  48. (((LPDDRAWI_DDRAWSURFACE_INT)(pDDS))->lpLcl->lpGbl->dwUsageCount > 0)
  49. // Macro to retrieve SPANTEX pointer
  50. #define HANDLE_TO_SPANTEX(hTex) \
  51. (*(PD3DI_SPANTEX *)ULongToPtr(hTex))
  52. // Check the return value and return if something wrong.
  53. // Assume hr has been declared
  54. #define HR_RET(exp) \
  55. { \
  56. hr = (exp); \
  57. if (hr != D3D_OK) \
  58. { \
  59. return hr; \
  60. } \
  61. }
  62. // Triangle/Line/Point function
  63. #define PFN_TRIANGLE_5ARG_DEFAULT (D3DTRIFLAG_EDGEENABLE1 | \
  64. D3DTRIFLAG_EDGEENABLE2 | \
  65. D3DTRIFLAG_EDGEENABLE3)
  66. typedef HRESULT (*PFN_TRIANGLE)(LPVOID pCtx, PUINT8 pV0, PUINT8 pV1,
  67. PUINT8 pV2,
  68. WORD wFlags /*= PFN_TRIANGLE_5ARG_DEFAULT */);
  69. typedef HRESULT (*PFN_POINT)(LPVOID pCtx, PUINT8 pV0);
  70. typedef HRESULT (*PFN_LINE)(LPVOID pCtx, PUINT8 pV0, PUINT8 pV1);
  71. typedef void (*PFN_STORELASTPIXELSTATE)(LPVOID pCtx, BOOL bStore);
  72. typedef HRESULT (*PFN_DP2SETRENDERSTATES)(LPVOID pCtx,
  73. DWORD dwFvf,
  74. LPD3DHAL_DP2COMMAND pCmd,
  75. LPDWORD lpdwRuntimeRStates);
  76. typedef HRESULT (*PFN_DP2TEXTURESTAGESTATE)(LPVOID pCtx,
  77. DWORD dwFvf,
  78. LPD3DHAL_DP2COMMAND pCmd);
  79. typedef HRESULT (*PFN_DP2SETVIEWPORT)(LPVOID pCtx, LPD3DHAL_DP2COMMAND pCmd);
  80. typedef HRESULT (*PFN_DP2SETWRANGE)(LPVOID pCtx, LPD3DHAL_DP2COMMAND pCmd);
  81. typedef struct _PRIMITIVE_FUNTIONS
  82. {
  83. PFN_TRIANGLE pfnTri;
  84. PFN_POINT pfnPoint;
  85. PFN_LINE pfnLine;
  86. PFN_STORELASTPIXELSTATE pfnStoreLastPixelState;
  87. PFN_DP2SETRENDERSTATES pfnDp2SetRenderStates;
  88. PFN_DP2TEXTURESTAGESTATE pfnDp2TextureStageState;
  89. PFN_DP2SETVIEWPORT pfnDp2SetViewport;
  90. PFN_DP2SETWRANGE pfnDp2SetWRange;
  91. }PRIMITIVE_FUNTIONS;
  92. typedef enum _SW_RAST_TYPE
  93. {
  94. SW_RAST_REFNULL = 1,
  95. SW_RAST_RGB = 2,
  96. SW_RAST_MMX = 3,
  97. SW_RAST_MMXASRGB = 4,
  98. }SW_RAST_TYPE;
  99. // Records the stride and the member offsets of the current FVF vertex type
  100. // Used to pack a FVF vertex into one known by the rasterizer, such as
  101. // RAST_GENERIC_VERTEX
  102. typedef struct _FVFDATA
  103. {
  104. // 0 means no according field
  105. INT16 offsetRHW;
  106. INT16 offsetDiff;
  107. INT16 offsetSpec;
  108. INT16 offsetTex[D3DHAL_TSS_MAXSTAGES];
  109. UINT16 stride;
  110. RAST_VERTEX_TYPE vtxType;
  111. DWORD preFVF;
  112. INT TexIdx[D3DHAL_TSS_MAXSTAGES];
  113. UINT cActTex;
  114. }FVFDATA;
  115. // Class used for the context returned to D3DIM.
  116. class D3DContext
  117. {
  118. public:
  119. D3DI_RASTCTX m_RastCtx;
  120. // InBegin and TextureLockd flags
  121. // TextureLockd bit is set/cleared by texture Lock/Unlock functions.
  122. // It is used by texture Lock/Unlock and Begin functions.
  123. // InBegin bit is set by Begin and cleared by End
  124. unsigned short m_uFlags;
  125. // This is init'ed according to the fill mode.
  126. // It is init'ed after state change and before rendering
  127. PRIMITIVE_FUNTIONS m_fnPrims;
  128. // Used to store the old last pixel setting when drawing line strips.
  129. UINT uOldFlags;
  130. inline BOOL IsTextureOff(void);
  131. inline void UpdatePrimFunctionTbl(void); // Init m_pfnTri
  132. inline BOOL IsAnyStatesChanged(void);
  133. inline BOOL IsStateChanged(UINT32 uState);
  134. inline void StateChanged(UINT32 uState);
  135. inline void SetAllStatesDirtyBits(void);
  136. inline void ClearAllStatesDirtyBits(void);
  137. inline void ClearStateDirtyBit(UINT32 uState);
  138. // FVF stuff
  139. FVFDATA m_fvfData;
  140. #if DBG
  141. inline HRESULT ValidatePrimType(D3DPRIMITIVETYPE PrimitiveType);
  142. #endif
  143. PrimProcessor m_PrimProc;
  144. UINT32 dwSize;
  145. D3DContext(void){};
  146. ~D3DContext(void){};
  147. HRESULT Initialize(LPDIRECTDRAWSURFACE pDDS,
  148. LPDIRECTDRAWSURFACE pDDSZ, DWORD BeadSet, DWORD devVer);
  149. HRESULT FillContext(LPDIRECTDRAWSURFACE pDDS, LPDIRECTDRAWSURFACE pDDSZ);
  150. HRESULT SetViewport(LPD3DHAL_DP2VIEWPORTINFO pVpt);
  151. HRESULT TextureSetState(PD3DI_SPANTEX pSpanTex, DWORD dwState, DWORD dwValue);
  152. HRESULT ValidateTextureStageState(void);
  153. HRESULT UpdateActiveTexStageCount(void);
  154. inline PD3DI_RASTCTX GetRastCtx(void){return &m_RastCtx;};
  155. HRESULT Begin(void);
  156. inline HRESULT End(BOOL bNotFlush = TRUE);
  157. inline void BeginPrimSet(D3DPRIMITIVETYPE PrimType, RAST_VERTEX_TYPE VertType)
  158. {m_PrimProc.BeginPrimSet(PrimType, VertType);};
  159. inline void StoreLastPixelState(BOOL bStore);
  160. inline PRIMITIVE_FUNTIONS *GetFunsTbl(void){return &m_fnPrims;};
  161. void RastUnlockSpanTexture(void);
  162. HRESULT RastLockSpanTexture(void);
  163. void UpdateColorKeyAndPalette(void);
  164. void RemoveTexture(PD3DI_SPANTEX pSpanTex);
  165. HRESULT InitSpanTexture(PD3DI_SPANTEX pSpanTex, LPDIRECTDRAWSURFACE pDDS);
  166. HRESULT SetSizesSpanTexture(PD3DI_SPANTEX pSpanTex);
  167. HRESULT SetRenderState(UINT32 uState, UINT32 uStateVal);
  168. HRESULT UpdateRenderStates(LPDWORD puStateChange, UINT cStateChanges);
  169. HRESULT UpdateAllRenderStates(LPDWORD puStates);
  170. HRESULT SetTextureStageState(DWORD dwStage, DWORD dwState, DWORD uStateVal);
  171. HRESULT Dp2SetRenderStates(LPD3DHAL_DP2COMMAND pCmd, LPDWORD lpdwRuntimeRStates);
  172. HRESULT Dp2TextureStageState(LPD3DHAL_DP2COMMAND pCmd, DWORD dwFvf);
  173. void MapTextureStageState( DWORD dwStage );
  174. void MapLegacyTextureBlend( void );
  175. void MapLegacyTextureFilter( void );
  176. inline HRESULT CheckDrawOnePrimitive(
  177. LPD3DHAL_DRAWONEPRIMITIVEDATA pOnePrimData);
  178. inline HRESULT CheckDrawOneIndexedPrimitive(
  179. LPD3DHAL_DRAWONEINDEXEDPRIMITIVEDATA pOneIdxPrimData);
  180. inline HRESULT DrawOnePrimitive(PUINT8 pVtx,
  181. D3DPRIMITIVETYPE PrimType,
  182. UINT cVertices);
  183. inline HRESULT DrawOneIndexedPrimitive(PUINT8 pVtx,
  184. LPWORD puIndices,
  185. D3DPRIMITIVETYPE PrimType,
  186. UINT cIndices);
  187. // Check if a triangle is culled or not. It's only used for wireframe and
  188. // point mode. It's done in PrimProc.Tri for solid mode.
  189. inline BOOL NotCulled(LPD3DTLVERTEX pV0, LPD3DTLVERTEX pV1,
  190. LPD3DTLVERTEX pV2);
  191. // FVF stuff
  192. HRESULT FASTCALL CheckFVF(DWORD dwFVF);
  193. void FASTCALL PackGenVertex(PUINT8 pFvfVtx, RAST_GENERIC_VERTEX *pGenVtx);
  194. inline UINT16 GetFvfStride(void){return m_fvfData.stride;};
  195. inline RAST_VERTEX_TYPE GetFvfVertexType(void){return m_fvfData.vtxType;};
  196. inline void BeginSceneHook(void);
  197. inline void EndSceneHook(void);
  198. };
  199. inline void D3DContext::StoreLastPixelState(BOOL bStore)
  200. {
  201. if (bStore)
  202. {
  203. uOldFlags = m_PrimProc.GetFlags();
  204. m_PrimProc.ClrFlags(PPF_DRAW_LAST_LINE_PIXEL);
  205. }
  206. else
  207. {
  208. m_PrimProc.SetFlags(uOldFlags & PPF_DRAW_LAST_LINE_PIXEL);
  209. }
  210. }
  211. inline BOOL D3DContext::NotCulled(LPD3DTLVERTEX pV0,
  212. LPD3DTLVERTEX pV1, LPD3DTLVERTEX pV2)
  213. {
  214. if (m_RastCtx.pdwRenderState[D3DRENDERSTATE_CULLMODE] == D3DCULL_NONE)
  215. {
  216. return TRUE;
  217. }
  218. FLOAT x1, y1, x2x1, x3x1, y2y1, y3y1, fDet;
  219. x1 = pV0->sx;
  220. y1 = pV0->sy;
  221. x2x1 = pV1->sx - x1;
  222. y2y1 = pV1->sy - y1;
  223. x3x1 = pV2->sx - x1;
  224. y3y1 = pV2->sy - y1;
  225. fDet = x2x1 * y3y1 - x3x1 * y2y1;
  226. if (0. == fDet)
  227. {
  228. return FALSE;
  229. }
  230. switch ( m_RastCtx.pdwRenderState[D3DRENDERSTATE_CULLMODE] )
  231. {
  232. case D3DCULL_CW:
  233. if ( fDet > 0.f )
  234. {
  235. return FALSE;
  236. }
  237. break;
  238. case D3DCULL_CCW:
  239. if ( fDet < 0.f )
  240. {
  241. return FALSE;
  242. }
  243. break;
  244. }
  245. return TRUE;
  246. }
  247. // Update m_pfnPrims according to the current fill mode, device type
  248. // and vertextype. It's called when fill mode or FVF type chang.
  249. inline void D3DContext::UpdatePrimFunctionTbl(void)
  250. {
  251. if (m_fvfData.vtxType == RAST_GENVERTEX)
  252. {
  253. m_fnPrims.pfnPoint = RGB_PointPack;
  254. m_fnPrims.pfnLine = RGB_LinePack;
  255. }
  256. else
  257. {
  258. m_fnPrims.pfnPoint = RGB_PointNoPack;
  259. m_fnPrims.pfnLine = RGB_LineNoPack;
  260. }
  261. switch (m_RastCtx.pdwRenderState[D3DRENDERSTATE_FILLMODE])
  262. {
  263. case D3DFILL_POINT:
  264. if (m_fvfData.vtxType == RAST_GENVERTEX)
  265. {
  266. m_fnPrims.pfnTri = RGB_TriPackPoint;
  267. }
  268. else
  269. {
  270. m_fnPrims.pfnTri = RGB_TriNoPackPoint;
  271. }
  272. break;
  273. case D3DFILL_WIREFRAME:
  274. if (m_fvfData.vtxType == RAST_GENVERTEX)
  275. {
  276. m_fnPrims.pfnTri = RGB_TriPackWireframe;
  277. }
  278. else
  279. {
  280. m_fnPrims.pfnTri = RGB_TriNoPackWireframe;
  281. }
  282. break;
  283. break;
  284. case D3DFILL_SOLID:
  285. default:
  286. if (m_fvfData.vtxType == RAST_GENVERTEX)
  287. {
  288. m_fnPrims.pfnTri = RGB_TriPackSolid;
  289. }
  290. else
  291. {
  292. m_fnPrims.pfnTri = RGB_TriNoPackSolid;
  293. }
  294. break;
  295. }
  296. }
  297. // The following inline functions are provided to manipulate StatesDirtyBits.
  298. // StatesDirtyBits is used to store one dirty bit for each render state. It
  299. // contains (D3DHAL_MAX_RSTATES_AND_STAGES>>3+1) bytes.
  300. // For a particular state, say uState,
  301. // it is represented by i'th bit of j'th byte, where i=(uState & 7) and
  302. // j=uState>>3. So,
  303. // StatesDirtyBits[uState>>3]&(1<<(uState&7)) gives the bit info. for uState
  304. // StatesDirtyBits[uState>>3] |= (1<<(uState&7)) sets the bit to 1
  305. // StatesDirtyBits[uState>>3] &= ~(1 <<(uState&7)) clears the bit to 0
  306. // Check if any render states have changed. The info. is stored in the bit
  307. // corresponding to D3DHAL_MAX_RSTATES_AND_STAGES.
  308. inline BOOL D3DContext::IsAnyStatesChanged()
  309. {
  310. return (m_RastCtx.StatesDirtyBits[D3DHAL_MAX_RSTATES_AND_STAGES>>3] &
  311. (1<<(D3DHAL_MAX_RSTATES_AND_STAGES & 7)));
  312. }
  313. // Check if uState has changed.
  314. inline BOOL D3DContext::IsStateChanged(UINT32 uState)
  315. {
  316. return (m_RastCtx.StatesDirtyBits[uState>>3] & (1<<(uState & 7)));
  317. };
  318. // uState has changed so set the according dirty bit and the AnyStates bit.
  319. inline void D3DContext::StateChanged(UINT32 uState)
  320. {
  321. m_RastCtx.StatesDirtyBits[uState>>3] |= (1<<(uState & 7));
  322. m_RastCtx.StatesDirtyBits[D3DHAL_MAX_RSTATES_AND_STAGES>>3] |=
  323. (1<<(D3DHAL_MAX_RSTATES_AND_STAGES & 7));
  324. };
  325. // Called after bead chooser to clear all the dirty bits.
  326. inline void D3DContext::ClearAllStatesDirtyBits(void)
  327. {
  328. memset(m_RastCtx.StatesDirtyBits, 0, sizeof(UINT8) * RAST_DIRTYBITS_SIZE);
  329. };
  330. // Called at context creation time to set all the dirty bits.
  331. inline void D3DContext::SetAllStatesDirtyBits(void)
  332. {
  333. memset(m_RastCtx.StatesDirtyBits, 7, sizeof(UINT8) * RAST_DIRTYBITS_SIZE);
  334. };
  335. // Clear the dirty bit corresponding to uState.
  336. inline void D3DContext::ClearStateDirtyBit(UINT32 uState)
  337. {
  338. m_RastCtx.StatesDirtyBits[uState>>3] &= ~(1 << (uState & 7));
  339. }
  340. inline BOOL D3DContext::IsTextureOff(void)
  341. {
  342. return
  343. (m_RastCtx.cActTex == 0 ||
  344. (m_RastCtx.cActTex == 1 && m_RastCtx.pTexture[0] == NULL) ||
  345. (m_RastCtx.cActTex == 2 &&
  346. (m_RastCtx.pTexture[0] == NULL ||
  347. m_RastCtx.pTexture[1] == NULL)));
  348. }
  349. extern "C" HRESULT WINAPI
  350. DDInternalLock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl, LPVOID* lpBits );
  351. extern "C" HRESULT WINAPI
  352. DDInternalUnlock( LPDDRAWI_DDRAWSURFACE_LCL this_lcl );
  353. // Lock surfaces before rendering
  354. inline HRESULT LockSurface(LPDIRECTDRAWSURFACE pDDS, LPVOID *ppData)
  355. {
  356. if (pDDS)
  357. {
  358. if (!VIDEO_MEMORY(pDDS))
  359. {
  360. if (SURFACE_LOCKED(pDDS))
  361. return DDERR_SURFACEBUSY;
  362. *ppData = (LPVOID)SURFACE_MEMORY(pDDS);
  363. return DD_OK;
  364. }
  365. else
  366. {
  367. HRESULT ddrval;
  368. do
  369. {
  370. LPDDRAWI_DDRAWSURFACE_INT lpInt;
  371. lpInt = (LPDDRAWI_DDRAWSURFACE_INT) pDDS;
  372. ddrval = DDInternalLock(lpInt->lpLcl, ppData);
  373. } while (ddrval == DDERR_WASSTILLDRAWING);
  374. return ddrval;
  375. }
  376. }
  377. return DD_OK;
  378. }
  379. // Unlock surfaces after rendering
  380. inline void UnlockSurface(LPDIRECTDRAWSURFACE pDDS)
  381. {
  382. if (pDDS && VIDEO_MEMORY(pDDS))
  383. {
  384. LPDDRAWI_DDRAWSURFACE_INT lpInt;
  385. lpInt = (LPDDRAWI_DDRAWSURFACE_INT) pDDS;
  386. DDInternalUnlock(lpInt->lpLcl);
  387. }
  388. }
  389. // After rendering cleanup: flush primitive processor, unlock textures
  390. inline HRESULT
  391. D3DContext::End(BOOL bNotFlush)
  392. {
  393. if (m_uFlags & D3DCONTEXT_IN_BEGIN)
  394. {
  395. HRESULT hr = m_PrimProc.End();
  396. // Unlock texture if this is not called in the middle of drawPrims to
  397. // flush for possible state changes. In the 2nd case, let
  398. // SetRenderState to handle it.
  399. if (bNotFlush)
  400. {
  401. RastUnlockSpanTexture();
  402. }
  403. // Unlock surfaces
  404. UnlockSurface(m_RastCtx.pDDS);
  405. if (m_RastCtx.pDDSZ != NULL)
  406. {
  407. UnlockSurface(m_RastCtx.pDDSZ);
  408. }
  409. m_uFlags &= ~D3DCONTEXT_IN_BEGIN;
  410. return (hr);
  411. }
  412. else
  413. {
  414. // In the case of DrawPrims being called just to set render states,
  415. // Begin is actually not called.
  416. return D3D_OK;
  417. }
  418. }
  419. // Following primitive functions are shared by RGB/REF rasterizers
  420. HRESULT FASTCALL
  421. DoDrawOneIndexedPrimitive(LPVOID pCtx,
  422. PRIMITIVE_FUNTIONS *pfnPrims,
  423. UINT16 FvfStride,
  424. PUINT8 pVtx,
  425. LPWORD puIndices,
  426. D3DPRIMITIVETYPE PrimType,
  427. UINT cIndices);
  428. HRESULT FASTCALL
  429. DoDrawOnePrimitive(LPVOID pCtx,
  430. PRIMITIVE_FUNTIONS *pfnPrims,
  431. UINT16 FvfStride,
  432. PUINT8 pVtx,
  433. D3DPRIMITIVETYPE PrimType,
  434. UINT cVertices);
  435. HRESULT FASTCALL
  436. DoDrawOneEdgeFlagTriangleFan(LPVOID pCtx,
  437. PRIMITIVE_FUNTIONS *pfnPrims,
  438. UINT16 FvfStride,
  439. PUINT8 pVtx,
  440. UINT cVertices,
  441. UINT32 dwEdgeFlags);
  442. HRESULT FASTCALL
  443. DoRendPoints(LPVOID pCtx,
  444. PRIMITIVE_FUNTIONS *pfnPrims,
  445. LPD3DINSTRUCTION pIns,
  446. LPD3DTLVERTEX pVtx,
  447. LPD3DPOINT pPt);
  448. HRESULT FASTCALL
  449. DoRendLines(LPVOID pCtx,
  450. PRIMITIVE_FUNTIONS *pfnPrims,
  451. LPD3DINSTRUCTION pIns,
  452. LPD3DTLVERTEX pVtx,
  453. LPD3DLINE pLine);
  454. HRESULT FASTCALL
  455. DoRendTriangles(LPVOID pCtx,
  456. PRIMITIVE_FUNTIONS *pfnPrims,
  457. LPD3DINSTRUCTION pIns,
  458. LPD3DTLVERTEX pVtx,
  459. LPD3DTRIANGLE pTri);
  460. HRESULT FASTCALL
  461. DoDrawPrimitives2(LPVOID pCtx,
  462. PRIMITIVE_FUNTIONS *pfnPrims,
  463. UINT16 dwStride,
  464. DWORD dwFvf,
  465. PUINT8 pVtx,
  466. LPD3DHAL_DP2COMMAND *ppCmd,
  467. LPDWORD lpdwRStates,
  468. BOOL bWireframe = FALSE
  469. );
  470. inline HRESULT
  471. D3DContext::DrawOnePrimitive(PUINT8 pVtx,
  472. D3DPRIMITIVETYPE PrimType,
  473. UINT cVertices)
  474. {
  475. m_PrimProc.BeginPrimSet(PrimType, m_fvfData.vtxType);
  476. return DoDrawOnePrimitive((LPVOID)this,
  477. &m_fnPrims,
  478. m_fvfData.stride,
  479. (PUINT8)pVtx,
  480. PrimType,
  481. cVertices);
  482. }
  483. inline HRESULT
  484. D3DContext::DrawOneIndexedPrimitive(PUINT8 pVtx,
  485. LPWORD puIndices,
  486. D3DPRIMITIVETYPE PrimType,
  487. UINT cIndices)
  488. {
  489. m_PrimProc.BeginPrimSet(PrimType, m_fvfData.vtxType);
  490. return DoDrawOneIndexedPrimitive((LPVOID)this,
  491. &m_fnPrims,
  492. m_fvfData.stride,
  493. (PUINT8)pVtx,
  494. puIndices,
  495. PrimType,
  496. cIndices);
  497. }
  498. // Macros to check if a pointer is valid
  499. #if DBG
  500. #define VALID_D3DCONTEX_PTR(pDCtx) ((pDCtx)->dwSize == sizeof(D3DContext))
  501. #define VALID_D3DI_RASTCTX_PTR(pRastCtx) \
  502. ((pRastCtx)->dwSize == sizeof(D3DI_RASTCTX))
  503. #define VALID_D3DI_SPANTEX_PTR(pSpanTex) \
  504. ((pSpanTex)->dwSize == sizeof(D3DI_SPANTEX))
  505. #define VALID_D3DI_SPANTEX_PTR_PTR(ppSpanTex) \
  506. ((ppSpanTex) && VALID_D3DI_SPANTEX_PTR(*(ppSpanTex)))
  507. // Validate context. pCtx should be declared before this macro
  508. // Type can be D3DContext or RefRast
  509. #define VALIDATE_CONTEXT(caller_name, data_ptr, pCtx, type) \
  510. { \
  511. if ((data_ptr) == NULL) \
  512. { \
  513. D3D_INFO(0, "in %s, data pointer = NULL", (caller_name)); \
  514. return DDHAL_DRIVER_HANDLED; \
  515. } \
  516. pCtx = (type)((data_ptr)->dwhContext); \
  517. if (!pCtx) \
  518. { \
  519. D3D_INFO(0, "in %s, dwhContext = NULL", (caller_name)); \
  520. (data_ptr)->ddrval = D3DHAL_CONTEXT_BAD; \
  521. return DDHAL_DRIVER_HANDLED; \
  522. } \
  523. }
  524. #else // !DBG
  525. #define VALID_D3DCONTEX_PTR(pDCtx) 1
  526. #define VALID_D3DI_RASTCTX_PTR(pRastCtx) 1
  527. #define VALID_D3DI_SPANTEX_PTR(pSpanTex) 1
  528. #define VALID_D3DI_SPANTEX_PTR_PTR(ppSpanTex) 1
  529. // Validate context. pCtx should be declared before this macro
  530. // Type can be D3DContext or RefRast
  531. #define VALIDATE_CONTEXT(caller_name, data_ptr, pCtx, type) \
  532. { \
  533. pCtx = (type)((data_ptr)->dwhContext); \
  534. }
  535. #endif // !DBG
  536. // Validate D3DCxt. pDCtx should be declared before this macro
  537. #define VALIDATE_D3DCONTEXT(caller_name, data_ptr) \
  538. { \
  539. VALIDATE_CONTEXT(caller_name, data_ptr, pDCtx, D3DContext*); \
  540. if (!VALID_D3DCONTEX_PTR(pDCtx) || \
  541. !VALID_D3DI_RASTCTX_PTR((pDCtx)->GetRastCtx())) \
  542. { \
  543. D3D_INFO(0, "in %s, invalid dwhContext", (caller_name)); \
  544. (data_ptr)->ddrval = D3DHAL_CONTEXT_BAD; \
  545. return DDHAL_DRIVER_HANDLED; \
  546. } \
  547. }
  548. // Validate ReferenceRasterizer. pRefRast should be declared before this macro
  549. #define VALIDATE_REFRAST_CONTEXT(caller_name, data_ptr) \
  550. { \
  551. VALIDATE_CONTEXT(caller_name, data_ptr, pRefRast, ReferenceRasterizer*);\
  552. }
  553. #define CHECK_FVF(ret, pDCtx, dwFlags) \
  554. { \
  555. if ((ret = pDCtx->CheckFVF(dwFlags)) != DD_OK) \
  556. { \
  557. return DDHAL_DRIVER_HANDLED; \
  558. } \
  559. }
  560. HRESULT FASTCALL
  561. FindOutSurfFormat(LPDDPIXELFORMAT pDdPixFmt,
  562. D3DI_SPANTEX_FORMAT *pFmt);
  563. extern int
  564. TextureFormats(LPDDSURFACEDESC* lplpddsd, DWORD dwVersion, SW_RAST_TYPE RastType);
  565. extern int
  566. ZBufferFormats(DDPIXELFORMAT** ppDDPF);
  567. BOOL FASTCALL
  568. ValidTextureSize(INT16 iuSize, INT16 iuShift,
  569. INT16 ivSize, INT16 ivShift);
  570. BOOL FASTCALL
  571. ValidMipmapSize(INT16 iPreSize, INT16 iSize);
  572. DWORD __stdcall
  573. RastContextCreate(LPD3DHAL_CONTEXTCREATEDATA pCtxData, DWORD BeadSet);
  574. DWORD __stdcall
  575. RastContextCreate(LPD3DHAL_CONTEXTCREATEDATA pCtxData, DWORD BeadSet);
  576. DWORD __stdcall
  577. RastContextCreateC(LPD3DHAL_CONTEXTCREATEDATA pCtxData);
  578. DWORD __stdcall
  579. RastContextCreateMMX(LPD3DHAL_CONTEXTCREATEDATA pCtxData);
  580. DWORD __stdcall
  581. RastContextCreateMMXAsRGB(LPD3DHAL_CONTEXTCREATEDATA pCtxData);
  582. DWORD __stdcall
  583. RastContextDestroy(LPD3DHAL_CONTEXTDESTROYDATA pCtxDestroyData);
  584. DWORD __stdcall
  585. RastSetRenderTarget(LPD3DHAL_SETRENDERTARGETDATA pTgtData);
  586. DWORD __stdcall
  587. RastTextureCreate(LPD3DHAL_TEXTURECREATEDATA pTexData);
  588. DWORD __stdcall
  589. RastTextureDestroy(LPD3DHAL_TEXTUREDESTROYDATA pTexDestroyData);
  590. DWORD __stdcall
  591. RastTextureGetSurf(LPD3DHAL_TEXTUREGETSURFDATA pTexGetSurf);
  592. DWORD __stdcall
  593. RastRenderState(LPD3DHAL_RENDERSTATEDATA pStateData);
  594. DWORD __stdcall
  595. RastRenderPrimitive(LPD3DHAL_RENDERPRIMITIVEDATA pRenderData);
  596. DWORD __stdcall
  597. RastDrawOnePrimitive(LPD3DHAL_DRAWONEPRIMITIVEDATA pOnePrimData);
  598. DWORD __stdcall
  599. RastDrawOneIndexedPrimitive(LPD3DHAL_DRAWONEINDEXEDPRIMITIVEDATA
  600. pOneIdxPrimData);
  601. DWORD __stdcall
  602. RastDrawPrimitives(LPD3DHAL_DRAWPRIMITIVESDATA pDrawPrimData);
  603. DWORD __stdcall
  604. RastValidateTextureStageState(LPD3DHAL_VALIDATETEXTURESTAGESTATEDATA pData);
  605. DWORD __stdcall
  606. RastDrawPrimitives2(LPD3DHAL_DRAWPRIMITIVES2DATA pDPrim2Data);
  607. DWORD __stdcall
  608. RefRastDrawPrimitives2(LPD3DHAL_DRAWPRIMITIVES2DATA pDPrim2Data);
  609. #endif // #ifndef _D3DIF_HPP_