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.

765 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 <d3dhal.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. #ifdef _IA64_
  167. UINT8 Padding[24];
  168. #endif // _IA64_
  169. } D3DI_RASTSPAN, *PD3DI_RASTSPAN; // sizeof(D3DI_RASTSPAN) == 64
  170. typedef CONST D3DI_RASTSPAN *PCD3DI_RASTSPAN;
  171. // D3DI_RASTPRIM uFlags
  172. #define D3DI_RASTPRIM_X_DEC (0x00000001L) // Else X increments.
  173. // General per primitive for edge walking and span scanning.
  174. // Can be expanded to suit the edge walker.
  175. // The information the span rasterizer needs is sensitive to qwords for
  176. // the MMX rasterizers.
  177. typedef struct tagD3DI_RASTPRIM
  178. {
  179. UINT32 uFlags;
  180. UINT16 uSpans; // count of spans
  181. UINT16 uResvd1; // perhaps we want to expand uSpans to 32 bits,
  182. // or perhaps 16 flag bits are enough
  183. // X gradients
  184. union
  185. {
  186. INT32 iDZDX; // 1.16.15
  187. FLOAT fDZDX;
  188. };
  189. union
  190. {
  191. INT32 iDOoWDX; // 1.31
  192. FLOAT fDOoWDX;
  193. };
  194. UV_UNION DUVoWDX[D3DHAL_TSS_MAXSTAGES];
  195. union
  196. {
  197. struct
  198. {
  199. INT16 iDBDX, iDGDX, iDRDX, iDADX; // 1.7.8
  200. };
  201. struct
  202. {
  203. FLOAT fDBDX, fDGDX, fDRDX, fDADX;
  204. };
  205. struct
  206. {
  207. INT32 iDIdxDX, iDIdxADX; // 1.8.16
  208. };
  209. };
  210. struct
  211. {
  212. union
  213. {
  214. struct
  215. {
  216. INT16 iDBSDX, iDGSDX, iDRSDX; // 1.7.8
  217. };
  218. struct
  219. {
  220. FLOAT fDBSDX, fDGSDX, fDRSDX;
  221. FLOAT fPad; // Padding to keep this set of attributes
  222. // an even multiple of quadwords.
  223. };
  224. };
  225. };
  226. // Y gradients for some attributes so that span routines
  227. // can do per-pixel mipmapping.
  228. UV_UNION DUVoWDY[D3DHAL_TSS_MAXSTAGES];
  229. union
  230. {
  231. INT32 iDOoWDY; // 1.31
  232. FLOAT fDOoWDY;
  233. };
  234. struct tagD3DI_RASTPRIM *pNext;
  235. // Pad to an even multiple of 32 bytes for cache alignment.
  236. UINT8 uPad[72];
  237. #ifdef _IA64_
  238. UINT8 Padding[24];
  239. #endif // _IA64_
  240. // Anything else needed
  241. } D3DI_RASTPRIM, *PD3DI_RASTPRIM;
  242. typedef CONST D3DI_RASTPRIM *PCD3DI_RASTPRIM;
  243. // D3DI_SPANTEX uFlags
  244. #define D3DI_SPANTEX_HAS_TRANSPARENT (0x00000001L)
  245. #define D3DI_SPANTEX_SURFACES_LOCKED (0x00000002L)
  246. #define D3DI_SPANTEX_MAXMIPLEVELS_DIRTY (0x00000004L)
  247. // Palette with alpha
  248. #define D3DI_SPANTEX_ALPHAPALETTE (0x00000008L)
  249. // D3DI_SPANTEX uFormat - NOTE: these enumerations match the sequence in the
  250. // array of DDPIXELFORMAT structures defined for matching in texture creation
  251. //
  252. // NOTE: these must be kept consistent with the RRPixelFormats for the reference rasterizer
  253. typedef enum _D3DI_SPANTEX_FORMAT
  254. {
  255. D3DI_SPTFMT_NULL = 0,
  256. D3DI_SPTFMT_B8G8R8 = 1,
  257. D3DI_SPTFMT_B8G8R8A8 = 2,
  258. D3DI_SPTFMT_B8G8R8X8 = 3,
  259. D3DI_SPTFMT_B5G6R5 = 4,
  260. D3DI_SPTFMT_B5G5R5 = 5,
  261. D3DI_SPTFMT_PALETTE4 = 6,
  262. D3DI_SPTFMT_PALETTE8 = 7,
  263. D3DI_SPTFMT_B5G5R5A1 = 8,
  264. D3DI_SPTFMT_B4G4R4 = 9,
  265. D3DI_SPTFMT_B4G4R4A4 =10,
  266. D3DI_SPTFMT_L8 =11, /* 8 bit luminance-only */
  267. D3DI_SPTFMT_L8A8 =12, /* 16 bit alpha-luminance */
  268. D3DI_SPTFMT_U8V8 =13, /* 16 bit bump map format */
  269. D3DI_SPTFMT_U5V5L6 =14, /* 16 bit bump map format with luminance */
  270. D3DI_SPTFMT_U8V8L8 =15, /* 24 bit bump map format with luminance */
  271. D3DI_SPTFMT_UYVY =16, /* UYVY format for PC98 compliance */
  272. D3DI_SPTFMT_YUY2 =17, /* YUY2 format for PC98 compliance */
  273. D3DI_SPTFMT_DXT1 =18, /* S3 texture compression technique 1 */
  274. D3DI_SPTFMT_DXT2 =19, /* S3 texture compression technique 2 */
  275. D3DI_SPTFMT_DXT3 =20, /* S3 texture compression technique 3 */
  276. D3DI_SPTFMT_DXT4 =21, /* S3 texture compression technique 4 */
  277. D3DI_SPTFMT_DXT5 =22, /* S3 texture compression technique 5 */
  278. D3DI_SPTFMT_B2G3R3 =23, /* 8 bit RGB texture format */
  279. D3DI_SPTFMT_Z16S0 =32,
  280. D3DI_SPTFMT_Z24S8 =33,
  281. D3DI_SPTFMT_Z15S1 =34,
  282. D3DI_SPTFMT_Z32S0 =35,
  283. D3DI_SPTFMT_S1Z15 =36,
  284. D3DI_SPTFMT_S8Z24 =37,
  285. // NOTE: this must be changed in conjunction with RR_STYPE in ref\inc\refrast.hpp
  286. D3DI_SPTFMT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  287. } D3DI_SPANTEX_FORMAT;
  288. // This encompasses all needed info about a chain of DD surfaces being used
  289. // as a potentially mipmapped texture.
  290. #define SPANTEX_MAXCLOD 11 // up to 2kx2k texture, all we can do with MMX INT16
  291. // U's and V's
  292. typedef struct tagD3DI_SPANTEX
  293. {
  294. UINT32 dwSize;
  295. INT32 iGeneration; // incremented when the texture changes
  296. UINT32 uFlags; // perspective, etc.
  297. D3DI_SPANTEX_FORMAT Format; // pixel format of the texture
  298. D3DTEXTUREADDRESS TexAddrU, TexAddrV; // texture address mode
  299. D3DTEXTUREMAGFILTER uMagFilter;// TEX3 style filter information
  300. D3DTEXTUREMINFILTER uMinFilter;// ATTENTION we could express this information more compactly
  301. D3DTEXTUREMIPFILTER uMipFilter;
  302. D3DCOLOR BorderColor; // border color for the texture
  303. // (for D3DTADDRESS_BORDER)
  304. D3DCOLOR TransparentColor; // color key on texture read
  305. FLOAT fLODBias; // Texture3 LOD bias value.
  306. PUINT8 pBits[SPANTEX_MAXCLOD]; // pointer for each LOD
  307. PUINT32 pRampmap; // set by ramp rasterizer, if necessary
  308. PUINT32 pPalette; // pointer to palette, if necessary
  309. INT32 iPaletteSize; // size of palette
  310. INT32 cLOD; // contains count of levels - 1 (0 means 1 level)
  311. // to use
  312. INT32 cLODTex; // contains count of levels - 1 (0 means 1 level)
  313. // that are actually in the texture
  314. // cLODTex >= cLOD is always true
  315. INT32 iMaxMipLevel; // index of largest mip map to use. 0 means use largest.
  316. INT iMaxScaledLOD; // ((cLOD + 1) scaled by LOD_SCALE) - 1.
  317. INT16 iSizeU, iSizeV; // LOD 0 size (only support power of 2
  318. // textures)
  319. INT16 iShiftU, iShiftV; // LOD 0 log2 size (valid for power-of-2
  320. // size only)
  321. INT16 iShiftPitch[SPANTEX_MAXCLOD]; // log2 pitch for each LOD
  322. #if (SPANTEX_MAXCLOD & 1) != 0
  323. // Pad following fields to a DWORD boundary.
  324. INT16 iPitchPad;
  325. #endif
  326. UINT16 uMaskU, uMaskV; // LOD 0 (1<<log2(size))-1
  327. // Variables for arithmetic address computation. Computed by DoTexAddrSetup.
  328. INT16 iFlipMaskU, iFlipMaskV;
  329. INT16 iClampMinU, iClampMinV;
  330. INT16 iClampMaxU, iClampMaxV;
  331. INT16 iClampEnU, iClampEnV;
  332. LPDIRECTDRAWSURFACE pSurf[SPANTEX_MAXCLOD]; // Added for TextureGetSurf
  333. // and Lock/Unlock Texture
  334. } D3DI_SPANTEX, *PD3DI_SPANTEX;
  335. // Color structure for blending etc. with enough room for 8.8 colors.
  336. // Even for 8 bit colors, this is convenient for lining up the colors
  337. // as we desire in MMX for 16 bit multiplies
  338. typedef struct tagD3DI_RASTCOLOR
  339. {
  340. UINT16 uB, uG, uR, uA;
  341. } D3DI_RASTCOLOR, *PD3DI_RASTCOLOR;
  342. // This structure has all the temporary storage needed for all the iterated
  343. // values to route the span information between the layers.
  344. // TBD there is lots more to add here, do texture mapping first
  345. typedef struct tagD3DI_SPANITER
  346. {
  347. // make the colors use the same order as RASTCOLOR above
  348. UINT16 uBB, uBG, uBR, uBA; // 8.8 blended color
  349. UINT16 uFogB, uFogG, uFogR, uFog; // 8.8 fog color, 0.16 fog value
  350. INT16 iFogBDX, iFogGDX, iFogRDX, iDFog; // 1.7.8 fog color deltas
  351. UINT32 uZDeferred; // storage for Z for deferred Z write
  352. UV_UNION TexUV[D3DHAL_TSS_MAXSTAGES];
  353. D3DCOLOR TexCol[D3DHAL_TSS_MAXSTAGES]; // [Texture]
  354. INT32 iDW; // to remember last delta W in
  355. UINT16 uDitherOffset;
  356. INT16 iXStep; // 1 or -1
  357. INT16 iSpecialW; // negative for first or last 3 pixels of span
  358. INT16 bStencilPass; // 1 if stencil test passed, otherwise 0
  359. union
  360. {
  361. INT32 iOoW; // previous OoW to pass between texaddr stages
  362. FLOAT fOoW;
  363. };
  364. } D3DI_SPANITER, *PD3DI_SPANITER;
  365. // Z compare macro
  366. // This does depend on the result of a compare being 0 or 1 (for the final XOR, since C
  367. // doesn't have a logical XOR), but this has been true on all processors and
  368. // compilers for some time.
  369. #define ZCMP16(p, g, b) \
  370. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  371. // Assumes the most significant bit of Z is 0 (31 bit Z)
  372. #define ZCMP32(p, g, b) \
  373. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  374. // Alpha Test compare macro
  375. #define ACMP(p, g, b) \
  376. ((((((INT32)(g) - (INT32)(b)) & (p)->iAAndMask) - (p)->iANeg) >= 0) ^ (p)->iAXorMask)
  377. // Stencil Test compare macro
  378. #define SCMP(p, g, b) \
  379. ((((((INT32)(g) - (INT32)(b)) & (p)->iSAndMask) - (p)->iSNeg) >= 0) ^ (p)->iSXorMask)
  380. // Helper macro that converts [0, 0xff] to [0, 5], linearly
  381. #define RGB8_CHANNEL(rgb) ((((rgb) * 5) + 0x80) >> 8)
  382. // Defines conversion from 24 bit RGB to 8 bit palette index. Each color has 6 values
  383. // resulting in 6**3 == 216 required colors in the palette.
  384. #define MAKE_RGB8(r, g, b) (RGB8_CHANNEL(r) * 36 \
  385. + RGB8_CHANNEL(g) * 6 \
  386. + RGB8_CHANNEL(b))
  387. // forward declaration of D3DI_RASTCTX
  388. struct tagD3DI_RASTCTX;
  389. typedef struct tagD3DI_RASTCTX D3DI_RASTCTX;
  390. typedef struct tagD3DI_RASTCTX *PD3DI_RASTCTX;
  391. typedef CONST struct tagD3DI_RASTCTX *PCD3DI_RASTCTX;
  392. // typedef for each rendering layer
  393. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  394. typedef void (CDECL *PFNSPANLAYER)(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  395. PD3DI_RASTSPAN pS);
  396. typedef void (CDECL *PFNTEXADDRESS)(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  397. PD3DI_RASTSPAN pS, INT32 iTex);
  398. // typedef texture read functions
  399. // this is an actual function so it can be called multiple times
  400. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  401. typedef D3DCOLOR (CDECL *PFNTEXREAD)(INT32 iU, INT32 iV, INT32 iShiftU,
  402. PUINT8 pBits, PD3DI_SPANTEX pTex);
  403. // Typedef for span rendering function pointers.
  404. typedef HRESULT (CDECL *PFNRENDERSPANS)(PD3DI_RASTCTX pCtx);
  405. // typedef for alpha blending functions.
  406. typedef void (CDECL *PFNBLENDFUNC)(PUINT16 pR, PUINT16 pG, PUINT16 pB,
  407. PUINT16 pA, D3DCOLOR DestC,
  408. PD3DI_RASTCTX pCtx);
  409. // typedef for buffer read functions.
  410. typedef D3DCOLOR (CDECL *PFNBUFREAD)(PUINT8 pBits);
  411. // typedef for texture blend get functions.
  412. typedef void (CDECL *PFNTEXBLENDGET)(PD3DI_RASTCOLOR pArg1,
  413. PD3DI_RASTCOLOR pArg2,
  414. PD3DI_RASTCOLOR pInput,
  415. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  416. INT32 iTex);
  417. // typedef for texture blend get functions.
  418. typedef void (CDECL *PFNTEXBLENDOP)(PD3DI_RASTCOLOR pOut,
  419. PD3DI_RASTCOLOR pArg1,
  420. PD3DI_RASTCOLOR pArg2,
  421. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  422. INT32 iTex);
  423. // Prototype for set of bead selections.
  424. typedef enum tagD3DI_BEADSET
  425. {
  426. D3DIBS_CMMX = 1, // C emulation of MMX beads
  427. D3DIBS_MMX = 2, // MMX beads
  428. D3DIBS_C = 3, // C beads
  429. D3DIBS_RAMP = 4, // Ramp beads
  430. D3DIBS_MMXASRGB = 5, // MMX selected for RGB rasterizer
  431. } D3DI_BEADSET;
  432. // General span scanning context
  433. struct tagD3DI_RASTCTX
  434. {
  435. UINT32 dwSize;
  436. //////////////////////////////////////////////////////////////////////
  437. // Temporary storage for span rendering routines. Could be global.
  438. // Not set by caller, and not changed by SpanInit.
  439. //
  440. D3DI_SPANITER SI;
  441. //////////////////////////////////////////////////////////////////////
  442. // Data that must be set by caller before a SpanInit.
  443. //
  444. // we may want to put a pointer to a DDSURFACEDESC or something like it
  445. // instead of this
  446. PUINT8 pSurfaceBits;
  447. INT iSurfaceStride;
  448. INT iSurfaceStep;
  449. INT iSurfaceBitCount;
  450. INT iSurfaceType; // or however we end up expressing this
  451. PUINT32 pRampMap; // pointer to ramp map, if necessary
  452. LPDIRECTDRAWSURFACE pDDS;
  453. PUINT8 pZBits;
  454. INT iZStride;
  455. INT iZStep;
  456. INT iZBitCount;
  457. LPDIRECTDRAWSURFACE pDDSZ;
  458. // Clip area.
  459. RECT Clip;
  460. // Sign of face area that should be culled. Zero is clockwise,
  461. // one is CCW and everything else means no culling.
  462. UINT uCullFaceSign;
  463. union
  464. {
  465. DWORD pdwRenderState[D3D_MAXRENDERSTATES];
  466. FLOAT pfRenderState[D3D_MAXRENDERSTATES];
  467. };
  468. // Since we are adjusting the order of texIdx in the vertex to suit that
  469. // defined in state TEXCOORDINDEX, we need a copy of adjusted WRAP state.
  470. // This is declared immediately after pdwRenderState so that we can share
  471. // a register with it in the assembly code.
  472. // WARNING WARNING - THIS ABSOLUTELY NEEDS TO BE FOLLOWING pdwRenderState
  473. // IMMEDIATELY. ASM CODE DEPENDS ON THIS.
  474. DWORD pdwWrap[D3DHAL_TSS_MAXSTAGES];
  475. union
  476. {
  477. DWORD pdwTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  478. FLOAT pfTextureStageState[D3DHAL_TSS_MAXSTAGES][D3DHAL_TSS_STATESPERSTAGE];
  479. };
  480. // first texture object contains information for texture for first pair
  481. // of texture coordinates, second contains texture for second pair of
  482. // texture coordinates, etc.
  483. PD3DI_SPANTEX pTexture[D3DHAL_TSS_MAXSTAGES];
  484. // Number of active textures. 0 - texture off; 1 - pTexture[0] is valid
  485. // 2 - both pTexture[0] and pTexture[1] are valid
  486. UINT cActTex;
  487. // Number of active texture stages for blending. It's set in spaninit()
  488. // and used in TexBlend_TexM_Gen.
  489. UINT cActBldStage;
  490. // Dirty bits for render states.
  491. // ATTENTION - We can reduce the size to have one bit for each group of
  492. // states when we implement the light weighted beed chooser.
  493. // Right now, it's set by SetRenderState and cleared after SpanInit is
  494. // called. The bit corresponding to D3DHAL_MAX_RSTATES_AND_STAGES is set
  495. // whenever a state is changed.
  496. UINT8 StatesDirtyBits[RAST_DIRTYBITS_SIZE];
  497. #if (RAST_DIRTYBITS_SIZE & 1) != 0
  498. // Pad following fields to a DWORD boundary.
  499. INT8 StatesDirtyBitsPad0;
  500. #endif
  501. #if (RAST_DIRTYBITS_SIZE & 2) != 0
  502. // Pad following fields to a DWORD boundary.
  503. INT16 StatesDirtyBitsPad1;
  504. #endif
  505. // Version# of the D3DDevice corresponding to this Context
  506. UINT32 uDevVer;
  507. //////////////////////////////////////////////////////////////////////
  508. // Data is set by SpanInit given the input above.
  509. //
  510. // Span rendering entry point.
  511. PFNRENDERSPANS pfnRenderSpans;
  512. // function pointers for the beads
  513. PFNSPANLAYER pfnBegin;
  514. PFNSPANLAYER pfnLoopEnd;
  515. PFNSPANLAYER pfnTestPassEnd;
  516. PFNSPANLAYER pfnTestFailEnd;
  517. PFNTEXADDRESS pfnTexAddr[D3DHAL_TSS_MAXSTAGES];
  518. PFNSPANLAYER pfnTexAddrEnd;
  519. PFNTEXREAD pfnTexRead[D3DHAL_TSS_MAXSTAGES];
  520. PFNSPANLAYER pfnTexBlendEnd;
  521. PFNTEXBLENDGET pfnTexBlendGetColor[D3DHAL_TSS_MAXSTAGES];
  522. PFNTEXBLENDGET pfnTexBlendGetAlpha[D3DHAL_TSS_MAXSTAGES];
  523. PFNTEXBLENDOP pfnTexBlendOpColor[D3DHAL_TSS_MAXSTAGES];
  524. PFNTEXBLENDOP pfnTexBlendOpAlpha[D3DHAL_TSS_MAXSTAGES];
  525. PFNSPANLAYER pfnColorGenEnd;
  526. PFNSPANLAYER pfnAlphaTestPassEnd;
  527. PFNSPANLAYER pfnAlphaTestFailEnd;
  528. PFNBLENDFUNC pfnSrcBlend;
  529. PFNBLENDFUNC pfnDestBlend;
  530. PFNBUFREAD pfnBufRead;
  531. PFNSPANLAYER pfnColorBlendEnd;
  532. // Optional bead that can be called after every pixel for rasterizers
  533. // which loop beads rather than returning.
  534. PFNSPANLAYER pfnPixelEnd;
  535. // Optional bead that can be called after every span for rasterizers
  536. // which loop spans rather than returning.
  537. PFNSPANLAYER pfnSpanEnd;
  538. // arithmetic Z variables
  539. INT32 iZAndMask, iZNeg, iZXorMask;
  540. // arithmetic Alpha test variables. These could be 16 bits, if we ever really want
  541. // to save space
  542. INT32 iAAndMask, iANeg, iAXorMask;
  543. // 8.8 Alpha reference value
  544. INT32 iARef;
  545. // arithmetic stencil test variables. These could be 16 bits, if we ever really want
  546. // to save space
  547. INT32 iSAndMask, iSNeg, iSXorMask;
  548. // Pointer to first RASTPRIM.
  549. PD3DI_RASTPRIM pPrim;
  550. // Pointer to next context.
  551. PD3DI_RASTCTX pNext;
  552. // Current BeadTable to use
  553. D3DI_BEADSET BeadSet;
  554. // Bit 0 set disables ml1, etc.
  555. #define MMX_FP_DISABLE_MASK_NUM 1
  556. DWORD dwMMXFPDisableMask[MMX_FP_DISABLE_MASK_NUM];
  557. // RampLightingDriver, should be NULL except for RampRast and 8 bit palettized RGB
  558. // output surface cases.
  559. LPVOID pRampDrv;
  560. // RAMP_RANGE_INFO RampInfo;
  561. DWORD RampBase;
  562. DWORD RampSize;
  563. PUINT32 pTexRampMap;
  564. BOOL bRampSpecular;
  565. #ifdef DBG
  566. #define NAME_LEN 128
  567. char szTest[NAME_LEN];
  568. char szTestFail[NAME_LEN];
  569. char szTexAddr[D3DHAL_TSS_MAXSTAGES][NAME_LEN];
  570. char szTexRead[D3DHAL_TSS_MAXSTAGES][NAME_LEN];
  571. char szTexBlend[NAME_LEN];
  572. char szColorGen[NAME_LEN];
  573. char szAlphaTest[NAME_LEN];
  574. char szColorBlend[NAME_LEN];
  575. char szSrcBlend[NAME_LEN];
  576. char szDestBlend[NAME_LEN];
  577. char szBufRead[NAME_LEN];
  578. char szBufWrite[NAME_LEN];
  579. #undef NAME_LEN
  580. #endif
  581. };
  582. // Data passed to the span rendering functions looks like this:
  583. //
  584. // RASTCTX
  585. // |-> RASTPRIM
  586. // | | RASTSPAN
  587. // | | RASTSPAN (as many as RASTPRIM.uSpans says there are)
  588. // | RASTPRIM
  589. // | | RASTSPAN
  590. // | NULL
  591. // RASTCTX
  592. // |-> RASTPRIM
  593. // | | RASTSPAN
  594. // | NULL
  595. // NULL
  596. //
  597. // The given RASTCTX is the head of a list of contexts. Each context
  598. // points to a list of RASTPRIMs. Each RASTPRIM structure is immediately
  599. // followed by RASTPRIM.uSpans RASTSPAN structures.
  600. // Prototype for state validation call.
  601. HRESULT SpanInit(PD3DI_RASTCTX pCtx);
  602. // This is used to pack a FVF vertex into one understand by OptRast so it
  603. // does not need to figure out where to get the data it needs. This struct
  604. // can be modified to accommodate more data and it can be broken into more
  605. // specilized and smalled structs.
  606. // Right now, it is an extension of D3DTLVERTEX, and the extra uv is at the
  607. // very end so that OptRast can treat it as a D3DTLVERTEX if only the first
  608. // part of the data needs to be accessed.
  609. typedef struct _RAST_GENERIC_VERTEX {
  610. union {
  611. D3DVALUE sx; /* Screen coordinates */
  612. D3DVALUE dvSX;
  613. };
  614. union {
  615. D3DVALUE sy;
  616. D3DVALUE dvSY;
  617. };
  618. union {
  619. D3DVALUE sz;
  620. D3DVALUE dvSZ;
  621. };
  622. union {
  623. D3DVALUE rhw; /* Reciprocal of homogeneous w */
  624. D3DVALUE dvRHW;
  625. };
  626. union {
  627. D3DCOLOR color; /* Vertex color */
  628. D3DCOLOR dcColor;
  629. };
  630. union {
  631. D3DCOLOR specular; /* Specular component of vertex */
  632. D3DCOLOR dcSpecular;
  633. };
  634. UV_UNION texCoord[D3DHAL_TSS_MAXSTAGES]; /* Texture coordinates */
  635. }RAST_GENERIC_VERTEX, *PRAST_GENERIC_VERTEX;
  636. // Vertex types supported by OptRast
  637. typedef enum _RAST_VERTEX_TYPE
  638. {
  639. RAST_TLVERTEX = 1, /* (Legacy) TL vertex */
  640. RAST_GENVERTEX = 2, /* Generic FVF vertex */
  641. RAST_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  642. }RAST_VERTEX_TYPE;
  643. #include <poppack.h>
  644. #ifdef __cplusplus
  645. }
  646. #endif
  647. #endif // _SPAN_H_