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.

755 lines
26 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // span.h
  4. //
  5. // Structures which define the interface between the edge walker to the
  6. // span interpolator.
  7. //
  8. // Copyright (C) Microsoft Corporation, 1997.
  9. //
  10. //----------------------------------------------------------------------------
  11. #ifndef _SPAN_H_
  12. #define _SPAN_H_
  13. #include <d3ditype.h>
  14. #include <d3dhalp.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. // TBD make this machine independent
  19. // don't leave any space between the elements of these structures
  20. // currently smallest element is a UINT16, may have to change this to pack(1)
  21. // if UINT8's are used.
  22. #include <pshpack2.h>
  23. // Limits, shifts and scaling factors for RASTSPAN and RASTPRIM data.
  24. // C_*_LIMIT is the constant integer form of the limit for cases where
  25. // direct integer comparisons can be done.
  26. #define Z_LIMIT g_fTwoPow31
  27. #define C_Z_LIMIT 0x4f000000
  28. #define Z16_FRAC_SHIFT 15
  29. #define Z16_FRAC_SCALE g_fTwoPow15
  30. #define OO_Z16_FRAC_SCALE g_fOoTwoPow15
  31. #define Z16_SHIFT 31
  32. #define Z16_SCALE g_fNearTwoPow31
  33. #define OO_Z16_SCALE g_fOoNearTwoPow31
  34. #define Z32_FRAC_SHIFT 0
  35. #define Z32_FRAC_SCALE g_fOne
  36. #define OO_Z32_FRAC_SCALE g_fOoNearTwoPow31
  37. #define Z32_SHIFT 31
  38. #define Z32_SCALE g_fNearTwoPow31
  39. #define OO_Z32_SCALE g_fOoNearTwoPow31
  40. #define TEX_LIMIT g_fTwoPow31
  41. #define C_TEX_LIMIT 0x4f000000
  42. #define TEX_SHIFT 20
  43. #define TEX_SCALE g_fTwoPow20
  44. #define OO_TEX_SCALE g_fOoTwoPow20
  45. #define COLOR_LIMIT g_fTwoPow15
  46. #define C_COLOR_LIMIT 0x47000000
  47. #define COLOR_SHIFT 8
  48. #define COLOR_SCALE g_fTwoPow8
  49. #define INDEX_COLOR_LIMIT g_fTwoPow30
  50. #define C_INDEX_COLOR_LIMIT 0x4e800000
  51. #define INDEX_COLOR_SHIFT 16
  52. #define INDEX_COLOR_SCALE g_fTwoPow16
  53. #define INDEX_COLOR_VERTEX_SHIFT 8
  54. // Shift to go from fixed-point value in vertex color to proper shift.
  55. #define INDEX_COLOR_FIXED_SHIFT (INDEX_COLOR_SHIFT - INDEX_COLOR_VERTEX_SHIFT)
  56. #define LOD_LIMIT g_fTwoPow15
  57. #define C_LOD_LIMIT 0x47000000
  58. #define LOD_SHIFT 11
  59. #define LOD_SCALE g_fTwoPow11
  60. #define LOD_MIN (-15)
  61. #define OOW_LIMIT g_fTwoPow31
  62. #define C_OOW_LIMIT 0x4f000000
  63. #define OOW_SHIFT 31
  64. #define OOW_SCALE g_fNearTwoPow31
  65. #define OO_OOW_SCALE g_fOoNearTwoPow31
  66. #define W_SHIFT 16
  67. #define W_SCALE g_fTwoPow16
  68. #define OO_W_SCALE g_fOoTwoPow16
  69. #define OOW_W_SHIFT (OOW_SHIFT + W_SHIFT)
  70. #define OOW_W_SCALE g_fTwoPow47
  71. #define FOG_LIMIT g_fTwoPow15
  72. #define C_FOG_LIMIT 0x47000000
  73. #define FOG_SHIFT 8
  74. #define FOG_SCALE g_fTwoPow8
  75. #define FOG_ONE_SCALE g_fTwoPow16
  76. #define FOG_255_SCALE g_fTwoPow8
  77. #define TEX_FINAL_SHIFT 16
  78. #define TEX_FINAL_FRAC_MASK (0xffff)
  79. #define TEX_TO_FINAL_SHIFT (TEX_SHIFT - TEX_FINAL_SHIFT)
  80. // Multiply with span W so that [U|V]oW times resulting W is in the
  81. // final shift position. 1 / (W_SHIFT + TEX_TO_FINAL_SHIFT).
  82. #define TEX_UVW_TO_FINAL_SCALE g_fOoTwoPow20
  83. // Divide by span OoW so that [U|V]oW times resulting W is in the
  84. // final shift position. OOW_SHIFT - TEX_TO_FINAL_SHIFT.
  85. #define TEX_OOW_TO_FINAL_SCALE g_fTwoPow27
  86. #define RAST_DIRTYBITS_SIZE (((D3D_MAXRENDERSTATES + (D3DHAL_TSS_MAXSTAGES * D3DHAL_TSS_STATESPERSTAGE)) >> 3) + 2)
  87. #define RAST_TSS_DIRTYBIT( _Stage, _State ) \
  88. ((UINT32)(D3D_MAXRENDERSTATES + \
  89. ((_Stage) * D3DHAL_TSS_STATESPERSTAGE) + (_State)))
  90. typedef struct _UV_UNION {
  91. union {
  92. D3DVALUE tu;
  93. D3DVALUE dvTU;
  94. INT32 iU;
  95. FLOAT fU;
  96. INT32 iUoW; // 1.11.20 texture coordinates
  97. FLOAT fUoW;
  98. INT32 iDUoWDX; // 1.11.20
  99. FLOAT fDUoWDX;
  100. INT32 iDUoWDY; // 1.11.20
  101. FLOAT fDUoWDY;
  102. };
  103. union {
  104. D3DVALUE tv;
  105. D3DVALUE dvTV;
  106. INT32 iV;
  107. FLOAT fV;
  108. INT32 iVoW; // 1.11.20 texture coordinates
  109. FLOAT fVoW;
  110. INT32 iDVoWDX; // 1.11.20
  111. FLOAT fDVoWDX;
  112. INT32 iDVoWDY; // 1.11.20
  113. FLOAT fDVoWDY;
  114. };
  115. }UV_UNION;
  116. // General per span data. This structure is designed to be qword aligned.
  117. typedef struct tagD3DI_RASTSPAN
  118. {
  119. // Space separated things are quad words and are intended to be
  120. // quad word aligned.
  121. UINT16 uPix; // count of pixels to render
  122. INT16 iDFog; // 1.7.8 delta fog
  123. UINT16 uX; // 16.0 start X
  124. UINT16 uY; // 16.0 start Y
  125. INT16 iLOD; // 1.4.11 start LOD
  126. INT16 iDLOD; // 1.4.11 delta LOD (so piecewise linear LOD interp
  127. // is possible)
  128. union
  129. {
  130. UINT32 uZ; // 16.15 start Z
  131. FLOAT fZ;
  132. };
  133. // If texture stuff (iOoW, iUoW1, etc.) is 32 bits (even if we iterate
  134. // them at 16 bits under MMX sometimes)
  135. union
  136. {
  137. INT32 iW; // 1.15.16 first inverted W of span
  138. FLOAT fW;
  139. };
  140. union
  141. {
  142. INT32 iOoW; // 1.31 start 1/W (signed since they are target
  143. // of MMX multiply)
  144. FLOAT fOoW;
  145. };
  146. UV_UNION UVoW[D3DHAL_TSS_MAXSTAGES];
  147. union
  148. {
  149. struct
  150. {
  151. UINT16 uB, uG, uR, uA; // 8.8 start colors
  152. };
  153. struct
  154. {
  155. INT32 iIdx, iIdxA; // 1.8.16 ramp start color and alpha
  156. };
  157. };
  158. UINT16 uBS, uGS, uRS; // 8.8 start specular colors
  159. // Specular alpha is fog. This prevents specular color from
  160. // being unioned with the texture 2 coordinates below.
  161. UINT16 uFog; // 1.7.8 start fog value
  162. // Pointers into surface and Z buffers interpolated by the edge walker.
  163. PUINT8 pSurface;
  164. PUINT8 pZ;
  165. UINT8 pPad[16];
  166. } D3DI_RASTSPAN, *PD3DI_RASTSPAN; // sizeof(D3DI_RASTSPAN) == 64
  167. typedef CONST D3DI_RASTSPAN *PCD3DI_RASTSPAN;
  168. // D3DI_RASTPRIM uFlags
  169. #define D3DI_RASTPRIM_X_DEC (0x00000001L) // Else X increments.
  170. // General per primitive for edge walking and span scanning.
  171. // Can be expanded to suit the edge walker.
  172. // The information the span rasterizer needs is sensitive to qwords for
  173. // the MMX rasterizers.
  174. typedef struct tagD3DI_RASTPRIM
  175. {
  176. UINT32 uFlags;
  177. UINT16 uSpans; // count of spans
  178. UINT16 uResvd1; // perhaps we want to expand uSpans to 32 bits,
  179. // or perhaps 16 flag bits are enough
  180. // X gradients
  181. union
  182. {
  183. INT32 iDZDX; // 1.16.15
  184. FLOAT fDZDX;
  185. };
  186. union
  187. {
  188. INT32 iDOoWDX; // 1.31
  189. FLOAT fDOoWDX;
  190. };
  191. UV_UNION DUVoWDX[D3DHAL_TSS_MAXSTAGES];
  192. union
  193. {
  194. struct
  195. {
  196. INT16 iDBDX, iDGDX, iDRDX, iDADX; // 1.7.8
  197. };
  198. struct
  199. {
  200. FLOAT fDBDX, fDGDX, fDRDX, fDADX;
  201. };
  202. struct
  203. {
  204. INT32 iDIdxDX, iDIdxADX; // 1.8.16
  205. };
  206. };
  207. struct
  208. {
  209. union
  210. {
  211. struct
  212. {
  213. INT16 iDBSDX, iDGSDX, iDRSDX; // 1.7.8
  214. };
  215. struct
  216. {
  217. FLOAT fDBSDX, fDGSDX, fDRSDX;
  218. FLOAT fPad; // Padding to keep this set of attributes
  219. // an even multiple of quadwords.
  220. };
  221. };
  222. };
  223. // Y gradients for some attributes so that span routines
  224. // can do per-pixel mipmapping.
  225. UV_UNION DUVoWDY[D3DHAL_TSS_MAXSTAGES];
  226. union
  227. {
  228. INT32 iDOoWDY; // 1.31
  229. FLOAT fDOoWDY;
  230. };
  231. struct tagD3DI_RASTPRIM *pNext;
  232. // Pad to an even multiple of 32 bytes for cache alignment.
  233. UINT8 uPad[72];
  234. // Anything else needed
  235. } D3DI_RASTPRIM, *PD3DI_RASTPRIM;
  236. typedef CONST D3DI_RASTPRIM *PCD3DI_RASTPRIM;
  237. // D3DI_SPANTEX uFlags
  238. #define D3DI_SPANTEX_HAS_TRANSPARENT (0x00000001L)
  239. #define D3DI_SPANTEX_SURFACES_LOCKED (0x00000002L)
  240. #define D3DI_SPANTEX_MAXMIPLEVELS_DIRTY (0x00000004L)
  241. // Palette with alpha
  242. #define D3DI_SPANTEX_ALPHAPALETTE (0x00000008L)
  243. // D3DI_SPANTEX uFormat - NOTE: these enumerations match the sequence in the
  244. // array of DDPIXELFORMAT structures defined for matching in texture creation
  245. //
  246. // NOTE: these must be kept consistent with the RRPixelFormats for the reference rasterizer
  247. typedef enum _D3DI_SPANTEX_FORMAT
  248. {
  249. D3DI_SPTFMT_NULL = 0,
  250. D3DI_SPTFMT_B8G8R8 = 1,
  251. D3DI_SPTFMT_B8G8R8A8 = 2,
  252. D3DI_SPTFMT_B8G8R8X8 = 3,
  253. D3DI_SPTFMT_B5G6R5 = 4,
  254. D3DI_SPTFMT_B5G5R5 = 5,
  255. D3DI_SPTFMT_PALETTE4 = 6,
  256. D3DI_SPTFMT_PALETTE8 = 7,
  257. D3DI_SPTFMT_B5G5R5A1 = 8,
  258. D3DI_SPTFMT_B4G4R4 = 9,
  259. D3DI_SPTFMT_B4G4R4A4 =10,
  260. D3DI_SPTFMT_L8 =11, /* 8 bit luminance-only */
  261. D3DI_SPTFMT_L8A8 =12, /* 16 bit alpha-luminance */
  262. D3DI_SPTFMT_U8V8 =13, /* 16 bit bump map format */
  263. D3DI_SPTFMT_U5V5L6 =14, /* 16 bit bump map format with luminance */
  264. D3DI_SPTFMT_U8V8L8 =15, /* 24 bit bump map format with luminance */
  265. D3DI_SPTFMT_UYVY =16, /* UYVY format for PC98 compliance */
  266. D3DI_SPTFMT_YUY2 =17, /* YUY2 format for PC98 compliance */
  267. D3DI_SPTFMT_DXT1 =18, /* S3 texture compression technique 1 */
  268. D3DI_SPTFMT_DXT2 =19, /* S3 texture compression technique 2 */
  269. D3DI_SPTFMT_DXT3 =20, /* S3 texture compression technique 3 */
  270. D3DI_SPTFMT_DXT4 =21, /* S3 texture compression technique 4 */
  271. D3DI_SPTFMT_DXT5 =22, /* S3 texture compression technique 5 */
  272. D3DI_SPTFMT_B2G3R3 =23, /* 8 bit RGB texture format */
  273. D3DI_SPTFMT_Z16S0 =32,
  274. D3DI_SPTFMT_Z24S8 =33,
  275. D3DI_SPTFMT_Z15S1 =34,
  276. D3DI_SPTFMT_Z32S0 =35,
  277. D3DI_SPTFMT_S1Z15 =36,
  278. D3DI_SPTFMT_S8Z24 =37,
  279. // NOTE: this must be changed in conjunction with RR_STYPE in ref\inc\refrast.hpp
  280. D3DI_SPTFMT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  281. } D3DI_SPANTEX_FORMAT;
  282. // This encompasses all needed info about a chain of DD surfaces being used
  283. // as a potentially mipmapped texture.
  284. #define SPANTEX_MAXCLOD 11 // up to 2kx2k texture, all we can do with MMX INT16
  285. // U's and V's
  286. typedef struct tagD3DI_SPANTEX
  287. {
  288. UINT32 dwSize;
  289. INT32 iGeneration; // incremented when the texture changes
  290. UINT32 uFlags; // perspective, etc.
  291. D3DI_SPANTEX_FORMAT Format; // pixel format of the texture
  292. D3DTEXTUREADDRESS TexAddrU, TexAddrV; // texture address mode
  293. D3DTEXTUREMAGFILTER uMagFilter;// TEX3 style filter information
  294. D3DTEXTUREMINFILTER uMinFilter;// ATTENTION we could express this information more compactly
  295. D3DTEXTUREMIPFILTER uMipFilter;
  296. D3DCOLOR BorderColor; // border color for the texture
  297. // (for D3DTADDRESS_BORDER)
  298. D3DCOLOR TransparentColor; // color key on texture read
  299. FLOAT fLODBias; // Texture3 LOD bias value.
  300. PUINT8 pBits[SPANTEX_MAXCLOD]; // pointer for each LOD
  301. PUINT32 pRampmap; // set by ramp rasterizer, if necessary
  302. PUINT32 pPalette; // pointer to palette, if necessary
  303. INT32 iPaletteSize; // size of palette
  304. INT32 cLOD; // contains count of levels - 1 (0 means 1 level)
  305. // to use
  306. INT32 cLODTex; // contains count of levels - 1 (0 means 1 level)
  307. // that are actually in the texture
  308. // cLODTex >= cLOD is always true
  309. INT32 iMaxMipLevel; // index of largest mip map to use. 0 means use largest.
  310. INT iMaxScaledLOD; // ((cLOD + 1) scaled by LOD_SCALE) - 1.
  311. INT16 iSizeU, iSizeV; // LOD 0 size (only support power of 2
  312. // textures)
  313. INT16 iShiftU, iShiftV; // LOD 0 log2 size (valid for power-of-2
  314. // size only)
  315. INT16 iShiftPitch[SPANTEX_MAXCLOD]; // log2 pitch for each LOD
  316. #if (SPANTEX_MAXCLOD & 1) != 0
  317. // Pad following fields to a DWORD boundary.
  318. INT16 iPitchPad;
  319. #endif
  320. UINT16 uMaskU, uMaskV; // LOD 0 (1<<log2(size))-1
  321. // Variables for arithmetic address computation. Computed by DoTexAddrSetup.
  322. INT16 iFlipMaskU, iFlipMaskV;
  323. INT16 iClampMinU, iClampMinV;
  324. INT16 iClampMaxU, iClampMaxV;
  325. INT16 iClampEnU, iClampEnV;
  326. LPDIRECTDRAWSURFACE pSurf[SPANTEX_MAXCLOD]; // Added for TextureGetSurf
  327. // and Lock/Unlock Texture
  328. } D3DI_SPANTEX, *PD3DI_SPANTEX;
  329. // Color structure for blending etc. with enough room for 8.8 colors.
  330. // Even for 8 bit colors, this is convenient for lining up the colors
  331. // as we desire in MMX for 16 bit multiplies
  332. typedef struct tagD3DI_RASTCOLOR
  333. {
  334. UINT16 uB, uG, uR, uA;
  335. } D3DI_RASTCOLOR, *PD3DI_RASTCOLOR;
  336. // This structure has all the temporary storage needed for all the iterated
  337. // values to route the span information between the layers.
  338. // TBD there is lots more to add here, do texture mapping first
  339. typedef struct tagD3DI_SPANITER
  340. {
  341. // make the colors use the same order as RASTCOLOR above
  342. UINT16 uBB, uBG, uBR, uBA; // 8.8 blended color
  343. UINT16 uFogB, uFogG, uFogR, uFog; // 8.8 fog color, 0.16 fog value
  344. INT16 iFogBDX, iFogGDX, iFogRDX, iDFog; // 1.7.8 fog color deltas
  345. UINT32 uZDeferred; // storage for Z for deferred Z write
  346. UV_UNION TexUV[D3DHAL_TSS_MAXSTAGES];
  347. D3DCOLOR TexCol[D3DHAL_TSS_MAXSTAGES]; // [Texture]
  348. INT32 iDW; // to remember last delta W in
  349. UINT16 uDitherOffset;
  350. INT16 iXStep; // 1 or -1
  351. INT16 iSpecialW; // negative for first or last 3 pixels of span
  352. INT16 bStencilPass; // 1 if stencil test passed, otherwise 0
  353. union
  354. {
  355. INT32 iOoW; // previous OoW to pass between texaddr stages
  356. FLOAT fOoW;
  357. };
  358. } D3DI_SPANITER, *PD3DI_SPANITER;
  359. // Z compare macro
  360. // This does depend on the result of a compare being 0 or 1 (for the final XOR, since C
  361. // doesn't have a logical XOR), but this has been true on all processors and
  362. // compilers for some time.
  363. #define ZCMP16(p, g, b) \
  364. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  365. // Assumes the most significant bit of Z is 0 (31 bit Z)
  366. #define ZCMP32(p, g, b) \
  367. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  368. // Alpha Test compare macro
  369. #define ACMP(p, g, b) \
  370. ((((((INT32)(g) - (INT32)(b)) & (p)->iAAndMask) - (p)->iANeg) >= 0) ^ (p)->iAXorMask)
  371. // Stencil Test compare macro
  372. #define SCMP(p, g, b) \
  373. ((((((INT32)(g) - (INT32)(b)) & (p)->iSAndMask) - (p)->iSNeg) >= 0) ^ (p)->iSXorMask)
  374. // Helper macro that converts [0, 0xff] to [0, 5], linearly
  375. #define RGB8_CHANNEL(rgb) ((((rgb) * 5) + 0x80) >> 8)
  376. // Defines conversion from 24 bit RGB to 8 bit palette index. Each color has 6 values
  377. // resulting in 6**3 == 216 required colors in the palette.
  378. #define MAKE_RGB8(r, g, b) (RGB8_CHANNEL(r) * 36 \
  379. + RGB8_CHANNEL(g) * 6 \
  380. + RGB8_CHANNEL(b))
  381. // forward declaration of D3DI_RASTCTX
  382. struct tagD3DI_RASTCTX;
  383. typedef struct tagD3DI_RASTCTX D3DI_RASTCTX;
  384. typedef struct tagD3DI_RASTCTX *PD3DI_RASTCTX;
  385. typedef CONST struct tagD3DI_RASTCTX *PCD3DI_RASTCTX;
  386. // typedef for each rendering layer
  387. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  388. typedef void (CDECL *PFNSPANLAYER)(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  389. PD3DI_RASTSPAN pS);
  390. typedef void (CDECL *PFNTEXADDRESS)(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  391. PD3DI_RASTSPAN pS, INT32 iTex);
  392. // typedef texture read functions
  393. // this is an actual function so it can be called multiple times
  394. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  395. typedef D3DCOLOR (CDECL *PFNTEXREAD)(INT32 iU, INT32 iV, INT32 iShiftU,
  396. PUINT8 pBits, PD3DI_SPANTEX pTex);
  397. // Typedef for span rendering function pointers.
  398. typedef HRESULT (CDECL *PFNRENDERSPANS)(PD3DI_RASTCTX pCtx);
  399. // typedef for alpha blending functions.
  400. typedef void (CDECL *PFNBLENDFUNC)(PUINT16 pR, PUINT16 pG, PUINT16 pB,
  401. PUINT16 pA, D3DCOLOR DestC,
  402. PD3DI_RASTCTX pCtx);
  403. // typedef for buffer read functions.
  404. typedef D3DCOLOR (CDECL *PFNBUFREAD)(PUINT8 pBits);
  405. // typedef for texture blend get functions.
  406. typedef void (CDECL *PFNTEXBLENDGET)(PD3DI_RASTCOLOR pArg1,
  407. PD3DI_RASTCOLOR pArg2,
  408. PD3DI_RASTCOLOR pInput,
  409. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  410. INT32 iTex);
  411. // typedef for texture blend get functions.
  412. typedef void (CDECL *PFNTEXBLENDOP)(PD3DI_RASTCOLOR pOut,
  413. PD3DI_RASTCOLOR pArg1,
  414. PD3DI_RASTCOLOR pArg2,
  415. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  416. INT32 iTex);
  417. // Prototype for set of bead selections.
  418. typedef enum tagD3DI_BEADSET
  419. {
  420. D3DIBS_CMMX = 1, // C emulation of MMX beads
  421. D3DIBS_MMX = 2, // MMX beads
  422. D3DIBS_C = 3, // C beads
  423. D3DIBS_RAMP = 4, // Ramp beads
  424. D3DIBS_MMXASRGB = 5, // MMX selected for RGB rasterizer
  425. } D3DI_BEADSET;
  426. // General span scanning context
  427. struct tagD3DI_RASTCTX
  428. {
  429. UINT32 dwSize;
  430. //////////////////////////////////////////////////////////////////////
  431. // Temporary storage for span rendering routines. Could be global.
  432. // Not set by caller, and not changed by SpanInit.
  433. //
  434. D3DI_SPANITER SI;
  435. //////////////////////////////////////////////////////////////////////
  436. // Data that must be set by caller before a SpanInit.
  437. //
  438. // we may want to put a pointer to a DDSURFACEDESC or something like it
  439. // instead of this
  440. PUINT8 pSurfaceBits;
  441. INT iSurfaceStride;
  442. INT iSurfaceStep;
  443. INT iSurfaceBitCount;
  444. INT iSurfaceType; // or however we end up expressing this
  445. PUINT32 pRampMap; // pointer to ramp map, if necessary
  446. LPDIRECTDRAWSURFACE pDDS;
  447. PUINT8 pZBits;
  448. INT iZStride;
  449. INT iZStep;
  450. INT iZBitCount;
  451. LPDIRECTDRAWSURFACE pDDSZ;
  452. // Clip area.
  453. RECT Clip;
  454. // Sign of face area that should be culled. Zero is clockwise,
  455. // one is CCW and everything else means no culling.
  456. UINT uCullFaceSign;
  457. union
  458. {
  459. DWORD pdwRenderState[D3D_MAXRENDERSTATES];
  460. FLOAT pfRenderState[D3D_MAXRENDERSTATES];
  461. };
  462. // Since we are adjusting the order of texIdx in the vertex to suit that
  463. // defined in state TEXCOORDINDEX, we need a copy of adjusted WRAP state.
  464. // This is declared immediately after pdwRenderState so that we can share
  465. // a register with it in the assembly code.
  466. // WARNING WARNING - THIS ABSOLUTELY NEEDS TO BE FOLLOWING pdwRenderState
  467. // IMMEDIATELY. ASM CODE DEPENDS ON THIS.
  468. union
  469. {
  470. DWORD pdwTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  471. FLOAT pfTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  472. };
  473. // first texture object contains information for texture for first pair
  474. // of texture coordinates, second contains texture for second pair of
  475. // texture coordinates, etc.
  476. PD3DI_SPANTEX pTexture[D3DHAL_TSS_MAXSTAGES];
  477. // Number of active textures. 0 - texture off; 1 - pTexture[0] is valid
  478. // 2 - both pTexture[0] and pTexture[1] are valid
  479. UINT cActTex;
  480. // Number of active texture stages for blending. It's set in spaninit()
  481. // and used in TexBlend_TexM_Gen.
  482. UINT cActBldStage;
  483. // Dirty bits for render states.
  484. // ATTENTION - We can reduce the size to have one bit for each group of
  485. // states when we implement the light weighted beed chooser.
  486. // Right now, it's set by SetRenderState and cleared after SpanInit is
  487. // called. The bit corresponding to D3DHAL_MAX_RSTATES_AND_STAGES is set
  488. // whenever a state is changed.
  489. UINT8 StatesDirtyBits[RAST_DIRTYBITS_SIZE];
  490. #if (RAST_DIRTYBITS_SIZE & 1) != 0
  491. // Pad following fields to a DWORD boundary.
  492. INT8 StatesDirtyBitsPad0;
  493. #endif
  494. #if (RAST_DIRTYBITS_SIZE & 2) != 0
  495. // Pad following fields to a DWORD boundary.
  496. INT16 StatesDirtyBitsPad1;
  497. #endif
  498. // Version# of the D3DDevice corresponding to this Context
  499. UINT32 uDevVer;
  500. //////////////////////////////////////////////////////////////////////
  501. // Data is set by SpanInit given the input above.
  502. //
  503. // Span rendering entry point.
  504. PFNRENDERSPANS pfnRenderSpans;
  505. // function pointers for the beads
  506. PFNSPANLAYER pfnBegin;
  507. PFNSPANLAYER pfnLoopEnd;
  508. PFNSPANLAYER pfnTestPassEnd;
  509. PFNSPANLAYER pfnTestFailEnd;
  510. PFNTEXADDRESS pfnTexAddr[D3DHAL_TSS_MAXSTAGES];
  511. PFNSPANLAYER pfnTexAddrEnd;
  512. PFNTEXREAD pfnTexRead[D3DHAL_TSS_MAXSTAGES];
  513. PFNSPANLAYER pfnTexBlendEnd;
  514. PFNTEXBLENDGET pfnTexBlendGetColor[D3DHAL_TSS_MAXSTAGES];
  515. PFNTEXBLENDGET pfnTexBlendGetAlpha[D3DHAL_TSS_MAXSTAGES];
  516. PFNTEXBLENDOP pfnTexBlendOpColor[D3DHAL_TSS_MAXSTAGES];
  517. PFNTEXBLENDOP pfnTexBlendOpAlpha[D3DHAL_TSS_MAXSTAGES];
  518. PFNSPANLAYER pfnColorGenEnd;
  519. PFNSPANLAYER pfnAlphaTestPassEnd;
  520. PFNSPANLAYER pfnAlphaTestFailEnd;
  521. PFNBLENDFUNC pfnSrcBlend;
  522. PFNBLENDFUNC pfnDestBlend;
  523. PFNBUFREAD pfnBufRead;
  524. PFNSPANLAYER pfnColorBlendEnd;
  525. // Optional bead that can be called after every pixel for rasterizers
  526. // which loop beads rather than returning.
  527. PFNSPANLAYER pfnPixelEnd;
  528. // Optional bead that can be called after every span for rasterizers
  529. // which loop spans rather than returning.
  530. PFNSPANLAYER pfnSpanEnd;
  531. // arithmetic Z variables
  532. INT32 iZAndMask, iZNeg, iZXorMask;
  533. // arithmetic Alpha test variables. These could be 16 bits, if we ever really want
  534. // to save space
  535. INT32 iAAndMask, iANeg, iAXorMask;
  536. // 8.8 Alpha reference value
  537. INT32 iARef;
  538. // arithmetic stencil test variables. These could be 16 bits, if we ever really want
  539. // to save space
  540. INT32 iSAndMask, iSNeg, iSXorMask;
  541. // Pointer to first RASTPRIM.
  542. PD3DI_RASTPRIM pPrim;
  543. // Pointer to next context.
  544. PD3DI_RASTCTX pNext;
  545. // Current BeadTable to use
  546. D3DI_BEADSET BeadSet;
  547. // Bit 0 set disables ml1, etc.
  548. #define MMX_FP_DISABLE_MASK_NUM 1
  549. DWORD dwMMXFPDisableMask[MMX_FP_DISABLE_MASK_NUM];
  550. // RampLightingDriver, should be NULL except for RampRast and 8 bit palettized RGB
  551. // output surface cases.
  552. LPVOID pRampDrv;
  553. // RAMP_RANGE_INFO RampInfo;
  554. DWORD RampBase;
  555. DWORD RampSize;
  556. PUINT32 pTexRampMap;
  557. BOOL bRampSpecular;
  558. #ifdef DBG
  559. #define NAME_LEN 128
  560. char szTest[NAME_LEN];
  561. char szTestFail[NAME_LEN];
  562. char szTexAddr[D3DHAL_TSS_MAXSTAGES][NAME_LEN];
  563. char szTexRead[D3DHAL_TSS_MAXSTAGES][NAME_LEN];
  564. char szTexBlend[NAME_LEN];
  565. char szColorGen[NAME_LEN];
  566. char szAlphaTest[NAME_LEN];
  567. char szColorBlend[NAME_LEN];
  568. char szSrcBlend[NAME_LEN];
  569. char szDestBlend[NAME_LEN];
  570. char szBufRead[NAME_LEN];
  571. char szBufWrite[NAME_LEN];
  572. #undef NAME_LEN
  573. #endif
  574. };
  575. // Data passed to the span rendering functions looks like this:
  576. //
  577. // RASTCTX
  578. // |-> RASTPRIM
  579. // | | RASTSPAN
  580. // | | RASTSPAN (as many as RASTPRIM.uSpans says there are)
  581. // | RASTPRIM
  582. // | | RASTSPAN
  583. // | NULL
  584. // RASTCTX
  585. // |-> RASTPRIM
  586. // | | RASTSPAN
  587. // | NULL
  588. // NULL
  589. //
  590. // The given RASTCTX is the head of a list of contexts. Each context
  591. // points to a list of RASTPRIMs. Each RASTPRIM structure is immediately
  592. // followed by RASTPRIM.uSpans RASTSPAN structures.
  593. // Prototype for state validation call.
  594. HRESULT SpanInit(PD3DI_RASTCTX pCtx);
  595. // This is used to pack a FVF vertex into one understand by OptRast so it
  596. // does not need to figure out where to get the data it needs. This struct
  597. // can be modified to accommodate more data and it can be broken into more
  598. // specilized and smalled structs.
  599. // Right now, it is an extension of D3DTLVERTEX, and the extra uv is at the
  600. // very end so that OptRast can treat it as a D3DTLVERTEX if only the first
  601. // part of the data needs to be accessed.
  602. typedef struct _RAST_GENERIC_VERTEX {
  603. union {
  604. D3DVALUE sx; /* Screen coordinates */
  605. D3DVALUE dvSX;
  606. };
  607. union {
  608. D3DVALUE sy;
  609. D3DVALUE dvSY;
  610. };
  611. union {
  612. D3DVALUE sz;
  613. D3DVALUE dvSZ;
  614. };
  615. union {
  616. D3DVALUE rhw; /* Reciprocal of homogeneous w */
  617. D3DVALUE dvRHW;
  618. };
  619. union {
  620. D3DCOLOR color; /* Vertex color */
  621. D3DCOLOR dcColor;
  622. };
  623. union {
  624. D3DCOLOR specular; /* Specular component of vertex */
  625. D3DCOLOR dcSpecular;
  626. };
  627. UV_UNION texCoord[D3DHAL_TSS_MAXSTAGES]; /* Texture coordinates */
  628. }RAST_GENERIC_VERTEX, *PRAST_GENERIC_VERTEX;
  629. // Vertex types supported by OptRast
  630. typedef enum _RAST_VERTEX_TYPE
  631. {
  632. RAST_TLVERTEX = 1, /* (Legacy) TL vertex */
  633. RAST_GENVERTEX = 2, /* Generic FVF vertex */
  634. RAST_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  635. }RAST_VERTEX_TYPE;
  636. #include <poppack.h>
  637. #ifdef __cplusplus
  638. }
  639. #endif
  640. #endif // _SPAN_H_