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.

823 lines
32 KiB

  1. /******************************Module*Header**********************************\
  2. *
  3. * *******************
  4. * * D3D SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: dcontext.h
  8. *
  9. * Content: D3D context definition and other useful macros
  10. *
  11. * Copyright (c) 1994-1999 3Dlabs Inc. Ltd. All rights reserved.
  12. * Copyright (c) 1995-2003 Microsoft Corporation. All rights reserved.
  13. \*****************************************************************************/
  14. #ifndef __DCONTEXT_H
  15. #define __DCONTEXT_H
  16. #ifndef __SOFTCOPY
  17. #include "softcopy.h"
  18. #endif
  19. #include "d3dsurf.h"
  20. #include "d3dsset.h"
  21. //-----------------------------------------------------------------------------
  22. // Definitions for state overrides
  23. //-----------------------------------------------------------------------------
  24. #define IS_OVERRIDE(type) ((DWORD)(type) > D3DSTATE_OVERRIDE_BIAS)
  25. #define GET_OVERRIDE(type) ((DWORD)(type) - D3DSTATE_OVERRIDE_BIAS)
  26. #define MAX_STATE D3DSTATE_OVERRIDE_BIAS
  27. #define DWORD_BITS 32
  28. #define DWORD_SHIFT 5
  29. typedef struct _D3DStateSet {
  30. DWORD bits[MAX_STATE >> DWORD_SHIFT];
  31. } D3DStateSet;
  32. #define STATESET_MASK(set, state) \
  33. (set).bits[((state) - 1) >> DWORD_SHIFT]
  34. #define STATESET_BIT(state) (1 << (((state) - 1) & (DWORD_BITS - 1)))
  35. #define STATESET_ISSET(set, state) \
  36. STATESET_MASK(set, state) & STATESET_BIT(state)
  37. #define STATESET_SET(set, state) \
  38. STATESET_MASK(set, state) |= STATESET_BIT(state)
  39. #define STATESET_CLEAR(set, state) \
  40. STATESET_MASK(set, state) &= ~STATESET_BIT(state)
  41. #define STATESET_INIT(set) memset(&(set), 0, sizeof(set))
  42. //-----------------------------------------------------------------------------
  43. // Rendering flags , used to set/test the P3_D3DCONTEXT.Flags field
  44. //
  45. // SURFACE_ALPHASTIPPLE - Use alpha value to calculate a stipple pattern
  46. // SURFACE_ENDPOINTENABLE - Enable last point on lines
  47. // SURFACE_ALPHACHROMA - Is the alpha blending a chromakeying operation?
  48. // SURFACE_MIPMAPPING - Is the filter mode setup for MipMapping?
  49. // SURFACE_MODULATE - Are we emulating MODULATE (as apposed to MODULATEALPHA)?
  50. // SURFACE_ANTIALIAS - Are we antialiasing
  51. //-----------------------------------------------------------------------------
  52. #define SURFACE_GOURAUD (1 << 0)
  53. #define SURFACE_ZENABLE (1 << 1)
  54. #define SURFACE_SPECULAR (1 << 2)
  55. #define SURFACE_FOGENABLE (1 << 3)
  56. #define SURFACE_PERSPCORRECT (1 << 4)
  57. #define SURFACE_TEXTURING (1 << 5)
  58. #define SURFACE_ALPHAENABLE (1 << 6)
  59. #define SURFACE_MONO (1 << 7)
  60. #define SURFACE_ALPHASTIPPLE (1 << 10)
  61. #define SURFACE_ZWRITEENABLE (1 << 11)
  62. #define SURFACE_ENDPOINTENABLE (1 << 12)
  63. #define SURFACE_ALPHACHROMA (1 << 13)
  64. #define SURFACE_MIPMAPPING (1 << 14)
  65. #define SURFACE_MODULATE (1 << 15)
  66. #define SURFACE_ANTIALIAS (1 << 16)
  67. //-----------------------------------------------------------------------------
  68. // Field values for P3_D3DCONTEXT.MagicNo field to signal its validity
  69. #define RC_MAGIC_DISABLE 0xd3d00000
  70. #define RC_MAGIC_NO 0xd3d00100
  71. #define CHECK_D3DCONTEXT_VALIDITY(ptr) \
  72. ( ((ptr) != NULL) && ((ptr)->MagicNo == RC_MAGIC_NO) )
  73. //-----------------------------------------------------------------------------
  74. // Renderer dirty flags definitions.
  75. //
  76. // They help us keep track what state needs to be refreshed in the hw
  77. //-----------------------------------------------------------------------------
  78. #define CONTEXT_DIRTY_ALPHABLEND (1 << 1)
  79. #define CONTEXT_DIRTY_ZBUFFER (1 << 2)
  80. #define CONTEXT_DIRTY_TEXTURE (1 << 3)
  81. #define CONTEXT_DIRTY_RENDER_OFFSETS (1 << 4)
  82. #define CONTEXT_DIRTY_TEXTURESTAGEBLEND (1 << 5)
  83. #define CONTEXT_DIRTY_ALPHATEST (1 << 6)
  84. #define CONTEXT_DIRTY_FOG (1 << 7)
  85. #define CONTEXT_DIRTY_STENCIL (1 << 8)
  86. #define CONTEXT_DIRTY_WBUFFER (1 << 9)
  87. #define CONTEXT_DIRTY_VIEWPORT (1 << 10)
  88. #define CONTEXT_DIRTY_PIPELINEORDER (1 << 11)
  89. #define CONTEXT_DIRTY_OPTIMIZE_ALPHA (1 << 12)
  90. #define CONTEXT_DIRTY_GAMMA (1 << 31)
  91. #define CONTEXT_DIRTY_EVERYTHING (0xffffffff)
  92. // Gamma state flags go into the dwDirtyGammaFlags field
  93. #define CONTEXT_DIRTY_GAMMA_STATE (1 << 0)
  94. #define CONTEXT_DIRTY_GAMMA_MODELVIEW_MATRIX (1 << 1)
  95. #define CONTEXT_DIRTY_GAMMA_PROJECTION_MATRIX (1 << 2)
  96. #define CONTEXT_DIRTY_GAMMA_MATERIAL (1 << 3)
  97. // * Bits 16 + are for light dirty bits *
  98. #define CONTEXT_DIRTY_GAMMA_EVERYTHING (0xffffffff)
  99. #define DIRTY_ALPHABLEND(pContext) \
  100. pContext->dwDirtyFlags |= CONTEXT_DIRTY_ALPHABLEND
  101. #define DIRTY_ALPHATEST(pContext) \
  102. pContext->dwDirtyFlags |= CONTEXT_DIRTY_ALPHATEST
  103. #define DIRTY_OPTIMIZE_ALPHA(pContext) \
  104. do \
  105. { \
  106. pContext->dwDirtyFlags |= CONTEXT_DIRTY_OPTIMIZE_ALPHA | \
  107. CONTEXT_DIRTY_ALPHATEST; \
  108. } while(0)
  109. #define DIRTY_PIPELINEORDER(pContext) \
  110. do \
  111. { \
  112. pContext->dwDirtyFlags |= CONTEXT_DIRTY_PIPELINEORDER; \
  113. } while(0)
  114. #define DIRTY_TEXTURE(pContext) \
  115. do \
  116. { \
  117. pContext->dwDirtyFlags |= CONTEXT_DIRTY_TEXTURE; \
  118. pContext->pCurrentTexture[TEXSTAGE_0] = NULL; \
  119. pContext->pCurrentTexture[TEXSTAGE_1] = NULL; \
  120. } while (0)
  121. #define DIRTY_ZBUFFER(pContext) \
  122. pContext->dwDirtyFlags |= CONTEXT_DIRTY_ZBUFFER
  123. #define DIRTY_RENDER_OFFSETS(pContext) \
  124. do \
  125. { \
  126. pContext->dwDirtyFlags |= CONTEXT_DIRTY_RENDER_OFFSETS; \
  127. } while (0)
  128. #define DIRTY_VIEWPORT(pContext) \
  129. do \
  130. { \
  131. pContext->dwDirtyFlags |= CONTEXT_DIRTY_VIEWPORT; \
  132. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  133. } while(0)
  134. #define DIRTY_TEXTURESTAGEBLEND(pContext) \
  135. pContext->dwDirtyFlags |= CONTEXT_DIRTY_TEXTURESTAGEBLEND
  136. #define DIRTY_FOG(pContext) \
  137. pContext->dwDirtyFlags |= CONTEXT_DIRTY_FOG
  138. #define DIRTY_STENCIL(pContext) \
  139. pContext->dwDirtyFlags |= CONTEXT_DIRTY_STENCIL
  140. #define DIRTY_WBUFFER(pContext) \
  141. pContext->dwDirtyFlags |= CONTEXT_DIRTY_WBUFFER
  142. #define DIRTY_GAMMA_STATE \
  143. do \
  144. { \
  145. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  146. pContext->dwDirtyGammaFlags |= CONTEXT_DIRTY_GAMMA_STATE; \
  147. } while(0)
  148. #define DIRTY_MODELVIEW \
  149. do \
  150. { \
  151. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  152. pContext->dwDirtyGammaFlags |= CONTEXT_DIRTY_GAMMA_MODELVIEW_MATRIX; \
  153. } while(0)
  154. #define DIRTY_PROJECTION \
  155. do \
  156. { \
  157. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  158. pContext->dwDirtyGammaFlags |= CONTEXT_DIRTY_GAMMA_PROJECTION_MATRIX; \
  159. } while(0)
  160. #define DIRTY_MATERIAL \
  161. do \
  162. { \
  163. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  164. pContext->dwDirtyGammaFlags |= CONTEXT_DIRTY_GAMMA_MATERIAL; \
  165. } while(0)
  166. #define DIRTY_LIGHT(pContext, a) \
  167. do \
  168. { \
  169. pContext->dwDirtyFlags |= CONTEXT_DIRTY_GAMMA; \
  170. pContext->dwDirtyGammaFlags |= (1 << (16 + (a))); \
  171. } while(0)
  172. #define DIRTY_EVERYTHING(pContext) \
  173. do \
  174. { \
  175. pContext->dwDirtyFlags = CONTEXT_DIRTY_EVERYTHING; \
  176. } while(0)
  177. //-----------------------------------------------------------------------------
  178. //
  179. // Texture Stage helper definitions
  180. //
  181. //-----------------------------------------------------------------------------
  182. typedef struct tagTexStageState
  183. {
  184. union
  185. {
  186. DWORD m_dwVal[D3DTSS_MAX]; // state array (unsigned)
  187. FLOAT m_fVal[D3DTSS_MAX]; // state array (float)
  188. };
  189. } TexStageState;
  190. typedef enum
  191. {
  192. TEXSTAGE_0 = 0,
  193. TEXSTAGE_1 = 1,
  194. TEXSTAGE_2 = 2,
  195. TEXSTAGE_3 = 3,
  196. TEXSTAGE_4 = 4,
  197. TEXSTAGE_5 = 5,
  198. TEXSTAGE_6 = 6,
  199. TEXSTAGE_7 = 7,
  200. TEXSTAGE_8 = 8,
  201. TEXSTAGE_9 = 9
  202. };
  203. //-----------------------------------------------------------------------------
  204. #define LUT_ENTRIES 256
  205. //-----------------------------------------------------------------------------
  206. // Possible ValidateDevice-type errors. Some of these match possible VD()
  207. // returns, others don't (yet). Some of these are also non-fatal, and can
  208. // be approximated. The behaviour of these depends on the current display
  209. // mode of the driver.
  210. // This flag is set if the error is fatal, and no sensible alternative
  211. // could be done. If this flag is not set, the rendering can be done
  212. // with a fair degree of fidelity, but not exactly what was requested.
  213. //-----------------------------------------------------------------------------
  214. #define BLEND_STATUS_FATAL_FLAG 0x10000
  215. // These are ordered in rough severity order, most severe last.
  216. typedef enum
  217. {
  218. BS_OK = 0,
  219. // Non-fatal errors.
  220. BS_INVALID_FILTER, // Filter can't be done in this mode (e.g. trilinear with dual-texture).
  221. BS_PHONG_SHADING, // We can do gouraud instead.
  222. // Fatal errors.
  223. BSF_BASE = BLEND_STATUS_FATAL_FLAG, // Not actually a real error value.
  224. BSF_UNSUPPORTED_FILTER, // Filter not supported at all (e.g. cubic)
  225. BSF_TEXTURE_NOT_POW2, // Using tile or wrap mode with a non-power-of-two texture dimension.
  226. BSF_TOO_MANY_PALETTES, // More than one palette used at a time.
  227. BSF_CANT_USE_ALPHA_ARG_HERE, // Some units can do this, but not in this stage.
  228. BSF_CANT_USE_ALPHA_OP_HERE, // Some units can do this, but not in this stage.
  229. BSF_CANT_USE_COLOR_ARG_HERE, // Some units can do this, but not in this stage.
  230. BSF_CANT_USE_COLOR_OP_HERE, // Some units can do this, but not in this stage.
  231. BSF_INVALID_TEXTURE, // Invalid or NULL texture.
  232. BSF_UNSUPPORTED_ALPHA_ARG,
  233. BSF_UNSUPPORTED_ALPHA_OP,
  234. BSF_UNSUPPORTED_COLOR_ARG,
  235. BSF_UNSUPPORTED_COLOR_OP,
  236. BSF_UNSUPPORTED_ALPHA_BLEND,
  237. BSF_UNSUPPORTED_STATE, // A render state value that we know, but don't support (and not one of the specific ones above).
  238. BSF_TOO_MANY_TEXTURES,
  239. BSF_TOO_MANY_BLEND_STAGES,
  240. BSF_UNDEFINED_FILTER,
  241. BSF_UNDEFINED_ALPHA_ARG,
  242. BSF_UNDEFINED_ALPHA_OP,
  243. BSF_UNDEFINED_COLOR_ARG,
  244. BSF_UNDEFINED_COLOR_OP,
  245. BSF_UNDEFINED_ALPHA_BLEND,
  246. BSF_UNDEFINED_STATE, // A render state value that we've never heard of (can happen via extensions that we don't support).
  247. // Always last.
  248. BSF_UNINITIALISED // Haven't done any validation setup yet!
  249. } D3D_BLEND_STATUS;
  250. // Useful macro for setting errors.
  251. #if DBG
  252. #define SET_BLEND_ERROR(pContext,errnum) \
  253. do \
  254. { \
  255. if ( pContext->eChipBlendStatus < (errnum) ) \
  256. { \
  257. pContext->eChipBlendStatus = (errnum); \
  258. } \
  259. DISPDBG(( WRNLVL, "azn SET_BLEND_ERROR: Error" #errnum )); \
  260. } while (FALSE)
  261. #else
  262. #define SET_BLEND_ERROR(pContext,errnum) \
  263. if ( pContext->eChipBlendStatus < (errnum) ) \
  264. pContext->eChipBlendStatus = (errnum)
  265. #endif // DBG
  266. #define RESET_BLEND_ERROR(pContext) pContext->eChipBlendStatus = BS_OK
  267. #define GET_BLEND_ERROR(pContext) (pContext->eChipBlendStatus)
  268. //-----------------------------------------------------------------------------
  269. // FVF (Flexible Vertex Format) Support declarations
  270. //-----------------------------------------------------------------------------
  271. typedef struct _FVFOFFSETS
  272. {
  273. DWORD dwColOffset;
  274. DWORD dwSpcOffset;
  275. DWORD dwTexOffset[D3DHAL_TSS_MAXSTAGES]; //offset for current texture#i
  276. DWORD dwTexCoordOffset[D3DHAL_TSS_MAXSTAGES]; //offset into each tex coord
  277. DWORD dwNormalOffset;
  278. DWORD dwNonTexStride;
  279. DWORD dwStride;
  280. DWORD dwStrideHostInline;
  281. DWORD dwVertexValid;
  282. DWORD dwVertexValidHostInline;
  283. DWORD vFmat;
  284. DWORD vFmatHostInline;
  285. DWORD dwTexCount;
  286. #if DX8_POINTSPRITES
  287. DWORD dwPntSizeOffset;
  288. #endif // DX8_POINTSPRITES
  289. } FVFOFFSETS , *LPFVFOFFSETS;
  290. #if DX8_POINTSPRITES
  291. #define P3_MAX_POINTSPRITE_SIZE 64.0f
  292. // Macro to determine if poinsprites are in order or just normal points
  293. #define IS_POINTSPRITE_ACTIVE(pContext) \
  294. ( (pContext->PntSprite.bEnabled) || \
  295. (pContext->PntSprite.fSize != 1.0f) || \
  296. (pContext->FVFData.dwPntSizeOffset) )
  297. #endif // DX8_POINTSPRITES
  298. typedef struct _FVFTEXCOORDS{
  299. D3DVALUE tu;
  300. D3DVALUE tv;
  301. #if DX8_3DTEXTURES
  302. D3DVALUE tw;
  303. #endif // DX8_3DTEXTURES
  304. } FVFTEXCOORDS, *LPFVFTEXCOORDS;
  305. typedef struct _FVFCOLOR {
  306. D3DCOLOR color;
  307. } FVFCOLOR, *LPFVFCOLOR;
  308. typedef struct _FVFSPECULAR {
  309. D3DCOLOR specular;
  310. } FVFSPECULAR, *LPFVFSPECULAR;
  311. typedef struct _FVFXYZ {
  312. float x;
  313. float y;
  314. float z;
  315. float rhw;
  316. } FVFXYZRHW, *LPFVFXYZRHW;
  317. typedef struct _FVFNORMAL {
  318. float nx;
  319. float ny;
  320. float nz;
  321. } FVFNORMAL, *LPFVFNORMAL;
  322. typedef struct _FVFPSIZE{
  323. D3DVALUE psize;
  324. } FVFPSIZE, *LPFVFPSIZE;
  325. extern const FVFCOLOR gc_FVFColorDefault;
  326. extern const FVFSPECULAR gc_FVFSpecDefault;
  327. extern const FVFTEXCOORDS gc_FVFTexCoordDefault;
  328. #define OFFSET_OFF(type, mem) ((DWORD)((char*)&((type *)0)->mem - (char*)(type*)0))
  329. // If we are asked to pick a texture coordinate (indexed by
  330. // D3DTSS_TEXCOORDINDEX in the TSS) which the incoming vertex data doesn't
  331. // have, then we should assume 0,0 as default values for it.
  332. #define FVFTEX(lpVtx, num) \
  333. (pContext->FVFData.dwTexOffset[(num)]? \
  334. ((LPFVFTEXCOORDS)((LPBYTE)(lpVtx) + \
  335. pContext->FVFData.dwTexOffset[(num)])) \
  336. :&gc_FVFTexCoordDefault )
  337. // Make sure FVFCOLOR and FVFSPEC pick up default values if
  338. // the components are not present in the FVF vertex data
  339. #define FVFCOLOR(lpVtx) \
  340. (pContext->FVFData.dwColOffset? \
  341. ((LPFVFCOLOR)((LPBYTE)(lpVtx) + pContext->FVFData.dwColOffset)) \
  342. :&gc_FVFColorDefault)
  343. #define FVFSPEC(lpVtx) \
  344. (pContext->FVFData.dwSpcOffset? \
  345. ((LPFVFSPECULAR)((LPBYTE)(lpVtx) + pContext->FVFData.dwSpcOffset)) \
  346. :&gc_FVFSpecDefault )
  347. #define FVFXYZRHW(lpVtx) ((LPFVFXYZRHW)((LPBYTE)(lpVtx)))
  348. #define FVFNORMAL(lpVtx) ((LPFVFNORMAL)((LPBYTE)(lpVtx) + pContext->FVFData.dwNormalOffset))
  349. #if DX8_POINTSPRITES
  350. #define FVFPSIZE( lpVtx) ((LPFVFPSIZE)((LPBYTE)(lpVtx) + pContext->FVFData.dwPntSizeOffset))
  351. #endif // DX8_POINTSPRITES
  352. #if DX7_TEXMANAGEMENT
  353. // Declaration for compiling purpouses
  354. typedef struct _TextureCacheManager *PTextureCacheManager;
  355. #endif // DX7_TEXMANAGEMENT
  356. //-----------------------------------------------------------------------------
  357. //
  358. // Basic renderers defined in d3dprim.c .
  359. // We have a function pointer to them in P3_D3DCONTEXT
  360. //
  361. //-----------------------------------------------------------------------------
  362. typedef struct _p3_d3dcontext P3_D3DCONTEXT;
  363. typedef int PROC_1_VERT( P3_D3DCONTEXT *pContext,
  364. D3DTLVERTEX *pv[],
  365. int vtx );
  366. typedef int PROC_3_VERTS( P3_D3DCONTEXT *pContext,
  367. D3DTLVERTEX *pv[],
  368. int edgeflags );
  369. //-----------------------------------------------------------------------------
  370. //
  371. // Definition of the P3_D3DCONTEXT structure .
  372. //
  373. //-----------------------------------------------------------------------------
  374. typedef struct _p3_d3dcontext
  375. {
  376. //***********************
  377. // Structure "header"
  378. //***********************
  379. unsigned long MagicNo ; // Magic number to verify validity of pointer
  380. P3_D3DCONTEXT* pSelf; // Ptr to self (useful if we do some realignment)
  381. DWORD dwContextHandle; // The handle passed back to D3D
  382. ULONG_PTR dwDXInterface; // Which DX interface (DX8,DX7,DX6,DX5,DX3) is
  383. // creating this context.
  384. //******************************************************************
  385. // Global DD and driver context in which this D3D context is running
  386. //******************************************************************
  387. P3_THUNKEDDATA* pThisDisplay; // The card we are running on.
  388. LPDDRAWI_DIRECTDRAW_LCL pDDLcl; // D3D Surfaces (created through
  389. // D3DCreateSurfaceEx) will be
  390. // associated through this pDDLcl
  391. LPDDRAWI_DIRECTDRAW_GBL pDDGbl; // A pointer to the DirectDraw global
  392. // object associated with this context
  393. //***********************************************
  394. // Stored render target and z buffer surface info
  395. //***********************************************
  396. P3_SURF_INTERNAL* pSurfRenderInt; // render target
  397. P3_SURF_INTERNAL* pSurfZBufferInt; // depth buffer
  398. DWORD PixelOffset; // Offset in videomemory in pixels to start
  399. DWORD ZPixelOffset; // of buffers
  400. DWORD ModeChangeCount; // Keeps track of rendertarget flips
  401. //************************
  402. // For debugging purpouses
  403. //************************
  404. DWORD OwningProcess; // Process Id
  405. BOOL bTexDisabled; // Is texturing enabled ?
  406. DWORD BPP; // Bytes per pixel of primary
  407. #if DX7_PALETTETEXTURE
  408. //**********************************************
  409. // Palette array associated to this D3D context
  410. //**********************************************
  411. PointerArray* pPalettePointerArray; // An array of palette pointers
  412. // for use in this context
  413. #endif
  414. //**********************************************
  415. // Surfaces array associated to this D3D context
  416. //**********************************************
  417. PointerArray* pTexturePointerArray; // An array of texture pointers
  418. // for use in this context
  419. //**************************************************************
  420. // Hardware setup and transport information for this D3D context
  421. //**************************************************************
  422. P3_SOFTWARECOPY SoftCopyGlint; // Software copy of registers for Permedia3
  423. BOOL b3D_FIFOS; // This context using FIFO's?
  424. DWORD dwDirtyFlags; // Hw state which stills needs update from D3D RS
  425. DWORD dwDirtyGammaFlags; // idem for TnL
  426. DWORD RenderCommand; // Rendering command to be issued to hw
  427. float XBias; // For biasing coordinates
  428. float YBias;
  429. //************************************************
  430. // Triangle hw rendering function pointers
  431. //************************************************
  432. PROC_1_VERT *pRendTri_1V;
  433. PROC_3_VERTS *pRendTri_3V;
  434. //************************************************
  435. // Context stored D3D states (render,TSS,TnL,etc.)
  436. //************************************************
  437. union
  438. {
  439. DWORD RenderStates[D3DHAL_MAX_RSTATES];
  440. float fRenderStates[D3DHAL_MAX_RSTATES];
  441. };
  442. TexStageState TextureStageState[D3DHAL_TSS_MAXSTAGES];
  443. D3DStateSet overrides; // To overide renderstates in legacy DX3 apps
  444. D3DHAL_DP2VIEWPORTINFO ViewportInfo; // Structures to store the viewport
  445. D3DHAL_DP2ZRANGE ZRange; // settings. They come into the HAL
  446. // in two seperate OP codes.
  447. D3DHAL_DP2WINFO WBufferInfo; // Structure to store w-buffering setup
  448. D3DMATERIAL7 Material;
  449. //********************************************
  450. // Command and Vertex buffer related state
  451. // (including DX8 multistreaming data)
  452. //********************************************
  453. LPDWORD lpVertices;
  454. DWORD dwVertexType;
  455. #if DX8_DDI
  456. LPDWORD lpIndices;
  457. DWORD dwIndicesStride;
  458. DWORD dwVerticesStride;
  459. DWORD dwNumVertices;
  460. DWORD dwVBSizeInBytes;
  461. #endif // DX8_DDI
  462. FVFOFFSETS FVFData;
  463. //*****************************************************
  464. // Internal context state for primitives rendering
  465. //*****************************************************
  466. ULONG Flags;
  467. DWORD dwP3HostinTriLookup; // Store mix of states to select an
  468. // appropriate rendering function
  469. DWORD dwProvokingVertex; // Simplifies the Delta renderers
  470. // to have this be global
  471. D3DTLVERTEX *pProvokingVertex;
  472. DWORD CullAndMask;
  473. DWORD CullXorMask;
  474. //*****************************************************
  475. // Internal context state kept TSS texturing
  476. // (Chip <-> D3D texture stage management)
  477. //*****************************************************
  478. // Pointer to the current texture for MipMapping
  479. P3_SURF_INTERNAL* pCurrentTexture[D3DHAL_TSS_MAXSTAGES];
  480. D3D_BLEND_STATUS eChipBlendStatus; // Is the current D3D blend valid?
  481. BOOL bTextureValid; // Are textures valid for rendering?
  482. BOOL bTex0Valid;
  483. BOOL bTex1Valid;
  484. BOOL bCanChromaKey;
  485. int iChipStage[4]; // iChipStage[n] = x means that stage n on the chip
  486. // (0,1 = texcomp0,1, 2=texapp, 3=placeholder) is
  487. // in D3D stage x.
  488. // iTexStage[n] = x means that texture n on the chip is "defined"
  489. // in D3D stage x, i.e. filter mode, FVF coord set number, etc.
  490. // A single texture may be used in multiple D3D stages, so x may
  491. // not be the only valid value. However, all instances of the texture
  492. // must be the same of course. The assignment code checks that they are.
  493. // A value of -1 means the texture is unused.
  494. int iTexStage[D3DHAL_TSS_MAXSTAGES];
  495. // iStageTex[n] = x means that the texture used by D3D stage n is
  496. // chip texture x. It therefore follows that iStageTex[iTexStage[n]] == n.
  497. // The reverse (iTexStage[iStageTex[n]] == n) need NOT be true, because
  498. // of course each chip texture can be used by multiple D3D stages.
  499. // -1 means that the stage does not use a texture (NULL handle or
  500. // invalid texture).
  501. int iStageTex[D3DTSS_MAX];
  502. BOOL bBumpmapEnabled; // TRUE if the current alpha in chipstage1
  503. // should be the bumpmap, instead of the
  504. // diffuse (normal default).
  505. BOOL bBumpmapInverted; // TRUE if the bumpmapping is the inverse
  506. // of the normal a0-a1+0.5, i.e. a1-a0+0.5
  507. BOOL bStage0DotProduct; // TRUE if chip stage 0 is using DOTPRODUCT
  508. // (can't use DOTPROD in stage 1).
  509. BOOL bAlphaBlendMustDoubleSourceColour; // TRUE if the source colour
  510. // needs to be *2 in the
  511. // alpha-blend unit.
  512. //*****************************************************
  513. // Internal context state kept for various D3D features
  514. //*****************************************************
  515. BOOL bKeptStipple; // D3DRENDERSTATE_STIPPLEDALPHA
  516. DWORD CurrentStipple[32];
  517. float MipMapLODBias[2]; // D3DTSS_MIPMAPLODBIAS
  518. #if DX8_MULTISAMPLING || DX7_ANTIALIAS
  519. // For antialiasing
  520. DWORD dwAliasPixelOffset;
  521. DWORD dwAliasBackBuffer;
  522. DWORD dwAliasZPixelOffset;
  523. DWORD dwAliasZBuffer;
  524. #endif // DX8_MULTISAMPLING || DX7_ANTIALIAS
  525. #if DX7_D3DSTATEBLOCKS
  526. BOOL bStateRecMode; // Toggle for executing or recording states
  527. P3StateSetRec *pCurrSS; // Ptr to SS currently being recorded
  528. P3StateSetRec **pIndexTableSS; // Pointer to table of indexes
  529. DWORD dwMaxSSIndex; // size of table of indexes
  530. DWORD dwVBHandle; // Stream 0 handle
  531. DWORD dwIndexHandle; // Index handle
  532. #endif
  533. #if DX8_POINTSPRITES // Point sprite support
  534. struct
  535. {
  536. BOOL bEnabled;
  537. D3DVALUE fSize;
  538. BOOL bScaleEnabled;
  539. D3DVALUE fScale_A;
  540. D3DVALUE fScale_B;
  541. D3DVALUE fScale_C;
  542. D3DVALUE fSizeMin;
  543. D3DVALUE fSizeMax;
  544. } PntSprite;
  545. #endif // DX8_POINTSPRITES
  546. #if DX8_DDI
  547. DWORD dwColorWriteHWMask; // For the new DX8 D3DRS_COLORWRITEENABLE
  548. DWORD dwColorWriteSWMask;
  549. #endif //DX8_DDI
  550. #if DX7_TEXMANAGEMENT
  551. //*****************
  552. // Texture Management
  553. //*****************
  554. PTextureCacheManager pTextureManager;
  555. #endif // DX7_TEXMANAGEMENT
  556. //*****************
  557. // Other
  558. //*****************
  559. // Track adjustments to texture coordinates that invalidate vertex sharing
  560. // (They force us to send the next triangle as 3 vtx's even if only the
  561. // coords of 1 have changed since we adjusted the tc's in order to fit
  562. // hw limitations)
  563. union
  564. {
  565. struct
  566. {
  567. BYTE flushWrap_tu1; // The s1 texture coordinate was wrapped
  568. BYTE flushWrap_tv1; // The t1 texture coordinate was wrapped
  569. BYTE flushWrap_tu2; // The s2 texture coordinate was wrapped
  570. BYTE flushWrap_tv2; // The t2 texture coordinate was wrapped
  571. };
  572. DWORD R3flushDueToTexCoordAdjust;
  573. };
  574. } P3_D3DCONTEXT ;
  575. //-----------------------------------------------------------------------------
  576. //
  577. // Triangle culling macros and definitions
  578. //
  579. //-----------------------------------------------------------------------------
  580. #define SET_CULLING_TO_NONE(pCtxt) \
  581. pCtxt->CullAndMask = 0; \
  582. pCtxt->CullXorMask = 0;
  583. #define SET_CULLING_TO_CCW(pCtxt) \
  584. pCtxt->CullAndMask = 1UL << 31; \
  585. pCtxt->CullXorMask = 0;
  586. #define SET_CULLING_TO_CW(pCtxt) \
  587. pCtxt->CullAndMask = 1UL << 31; \
  588. pCtxt->CullXorMask = 1UL << 31;
  589. #define FLIP_CCW_CW_CULLING(pCtxt) \
  590. pCtxt->CullXorMask ^= 1UL << 31;
  591. #define SAVE_CULLING_STATE(pCtxt) \
  592. DWORD oldCullAndMask = pCtxt->CullAndMask; \
  593. DWORD oldCullXorMask = pCtxt->CullXorMask;
  594. #define RESTORE_CULLING_STATE(pCtxt) \
  595. pCtxt->CullAndMask = oldCullAndMask; \
  596. pCtxt->CullXorMask = oldCullXorMask;
  597. #define _CULL_CALC(pCtxt,PixelArea) \
  598. ((*(DWORD *)&PixelArea) ^ pCtxt->CullXorMask)
  599. #if 1
  600. #define CULLED(pCtxt,PixelArea) \
  601. ((signed long)(_CULL_CALC(pCtxt,PixelArea) & pCtxt->CullAndMask) < 0) ? 1 : \
  602. ( ((_CULL_CALC(pCtxt,PixelArea)& ~pCtxt->CullAndMask) == 0.0f) ? 1 : 0 )
  603. #else
  604. static __inline int CULLED(P3_D3DCONTEXT *pCtxt, float PixelArea)
  605. {
  606. int cull;
  607. cull = (*(DWORD *)&PixelArea) ^ pCtxt->CullXorMask;
  608. if ((signed long)(cull & pContext->CullAndMask) < 0)
  609. {
  610. return 1; // True back face rejection...
  611. }
  612. if ((cull & ~pCtxt->CullAndMask) == 0.0f)
  613. {
  614. return 1;
  615. }
  616. return 0;
  617. }
  618. #endif
  619. //-----------------------------------------------------------------------------
  620. //
  621. // GetSurfaceFromHandle
  622. // Get internal surface structure pointer from handle
  623. //
  624. //-----------------------------------------------------------------------------
  625. static __inline P3_SURF_INTERNAL*
  626. GetSurfaceFromHandle(
  627. P3_D3DCONTEXT* pContext,
  628. DWORD dwHandle)
  629. {
  630. P3_SURF_INTERNAL* pTexture;
  631. {
  632. // There may never have been any texture arrays allocated...
  633. ASSERTDD(pContext->pTexturePointerArray,
  634. "ERROR: Texture pointer array is not set!");
  635. pTexture = PA_GetEntry(pContext->pTexturePointerArray, dwHandle);
  636. }
  637. DISPDBG((DBGLVL, "Texture pointer: 0x%x", pTexture));
  638. return pTexture;
  639. }
  640. //-----------------------------------------------------------------------------
  641. //
  642. // GetPaletteFromHandle
  643. // Get internal palette structure pointer from handle
  644. //
  645. //-----------------------------------------------------------------------------
  646. #if DX7_PALETTETEXTURE
  647. static __inline D3DHAL_DP2UPDATEPALETTE*
  648. GetPaletteFromHandle(
  649. P3_D3DCONTEXT* pContext,
  650. DWORD dwHandle)
  651. {
  652. D3DHAL_DP2UPDATEPALETTE* pPalette;
  653. {
  654. // There may never have been any palette arrays allocated...
  655. ASSERTDD(pContext->pPalettePointerArray,
  656. "ERROR: Palette pointer array is not set!");
  657. pPalette = PA_GetEntry(pContext->pPalettePointerArray, dwHandle);
  658. }
  659. DISPDBG((DBGLVL, "Palette pointer: 0x%x", pPalette));
  660. return pPalette;
  661. }
  662. #endif
  663. //-----------------------------------------------------------------------------
  664. //
  665. // Determine what level API is the app using which created this context
  666. //
  667. //-----------------------------------------------------------------------------
  668. #define IS_DX7_APP(pContext) ((pContext)->dwDXInterface == 3)
  669. #define IS_DX7_OR_EARLIER_APP(pContext) ((pContext)->dwDXInterface <= 3)
  670. #endif // __DCONTEXT_H