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.

895 lines
30 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 ((D3DHAL_MAX_RSTATES_AND_STAGES >> 3) + 1)
  87. /*
  88. * Macro to compute D3DRENDERSTATE offset for a particular per-stage state.
  89. * It's moved here after texture3 removal.
  90. */
  91. #define D3DHAL_TSS_OFFSET( _Stage, _State ) \
  92. ((D3DRENDERSTATETYPE) \
  93. (D3DHAL_TSS_RENDERSTATEBASE + \
  94. ((_Stage) * D3DHAL_TSS_STATESPERSTAGE) + (_State)))
  95. /*
  96. * Convenience texture map offsets for stages.
  97. */
  98. #define D3DHAL_TSS_TEXTUREMAP0 D3DHAL_TSS_OFFSET(0, D3DTSS_TEXTUREMAP)
  99. #define D3DHAL_TSS_TEXTUREMAP1 D3DHAL_TSS_OFFSET(1, D3DTSS_TEXTUREMAP)
  100. #define D3DHAL_TSS_TEXTUREMAP2 D3DHAL_TSS_OFFSET(2, D3DTSS_TEXTUREMAP)
  101. #define D3DHAL_TSS_TEXTUREMAP3 D3DHAL_TSS_OFFSET(3, D3DTSS_TEXTUREMAP)
  102. #define D3DHAL_TSS_TEXTUREMAP4 D3DHAL_TSS_OFFSET(4, D3DTSS_TEXTUREMAP)
  103. #define D3DHAL_TSS_TEXTUREMAP5 D3DHAL_TSS_OFFSET(5, D3DTSS_TEXTUREMAP)
  104. #define D3DHAL_TSS_TEXTUREMAP6 D3DHAL_TSS_OFFSET(6, D3DTSS_TEXTUREMAP)
  105. #define D3DHAL_TSS_TEXTUREMAP7 D3DHAL_TSS_OFFSET(7, D3DTSS_TEXTUREMAP)
  106. // General per span data. This structure is designed to be qword aligned.
  107. typedef struct tagD3DI_RASTSPAN
  108. {
  109. // Space separated things are quad words and are intended to be
  110. // quad word aligned.
  111. UINT16 uPix; // count of pixels to render
  112. INT16 iDFog; // 1.7.8 delta fog
  113. UINT16 uX; // 16.0 start X
  114. UINT16 uY; // 16.0 start Y
  115. INT16 iLOD; // 1.4.11 start LOD
  116. INT16 iDLOD; // 1.4.11 delta LOD (so piecewise linear LOD interp
  117. // is possible)
  118. union
  119. {
  120. UINT32 uZ; // 16.15 start Z
  121. FLOAT fZ;
  122. };
  123. // If texture stuff (iOoW, iUoW1, etc.) is 32 bits (even if we iterate
  124. // them at 16 bits under MMX sometimes)
  125. union
  126. {
  127. INT32 iW; // 1.15.16 first inverted W of span
  128. FLOAT fW;
  129. };
  130. union
  131. {
  132. INT32 iOoW; // 1.31 start 1/W (signed since they are target
  133. // of MMX multiply)
  134. FLOAT fOoW;
  135. };
  136. union
  137. {
  138. INT32 iUoW1; // 1.11.20 first texture coordinates
  139. FLOAT fUoW1;
  140. };
  141. union
  142. {
  143. INT32 iVoW1; // 1.11.20 first texture coordinates
  144. FLOAT fVoW1;
  145. };
  146. union
  147. {
  148. struct
  149. {
  150. UINT16 uB, uG, uR, uA; // 8.8 start colors
  151. };
  152. struct
  153. {
  154. INT32 iIdx, iIdxA; // 1.8.16 ramp start color and alpha
  155. };
  156. };
  157. UINT16 uBS, uGS, uRS; // 8.8 start specular colors
  158. // Specular alpha is fog. This prevents specular color from
  159. // being unioned with the texture 2 coordinates below.
  160. UINT16 uFog; // 1.7.8 start fog value
  161. union
  162. {
  163. INT32 iUoW2; // 1.11.20 second texture coordinates
  164. FLOAT fUoW2;
  165. };
  166. union
  167. {
  168. INT32 iVoW2; // 1.11.20 second texture coordinates
  169. FLOAT fVoW2;
  170. };
  171. // Pointers into surface and Z buffers interpolated by the edge walker.
  172. PUINT8 pSurface;
  173. PUINT8 pZ;
  174. #ifdef _IA64_
  175. UINT8 Padding[24];
  176. #endif // _IA64_
  177. } D3DI_RASTSPAN, *PD3DI_RASTSPAN; // sizeof(D3DI_RASTSPAN) == 64
  178. typedef CONST D3DI_RASTSPAN *PCD3DI_RASTSPAN;
  179. // D3DI_RASTPRIM uFlags
  180. #define D3DI_RASTPRIM_X_DEC (0x00000001L) // Else X increments.
  181. // General per primitive for edge walking and span scanning.
  182. // Can be expanded to suit the edge walker.
  183. // The information the span rasterizer needs is sensitive to qwords for
  184. // the MMX rasterizers.
  185. typedef struct tagD3DI_RASTPRIM
  186. {
  187. UINT32 uFlags;
  188. UINT16 uSpans; // count of spans
  189. UINT16 uResvd1; // perhaps we want to expand uSpans to 32 bits,
  190. // or perhaps 16 flag bits are enough
  191. // X gradients
  192. union
  193. {
  194. INT32 iDZDX; // 1.16.15
  195. FLOAT fDZDX;
  196. };
  197. union
  198. {
  199. INT32 iDOoWDX; // 1.31
  200. FLOAT fDOoWDX;
  201. };
  202. union
  203. {
  204. INT32 iDUoW1DX; // 1.11.20
  205. FLOAT fDUoW1DX;
  206. };
  207. union
  208. {
  209. INT32 iDVoW1DX; // 1.11.20
  210. FLOAT fDVoW1DX;
  211. };
  212. union
  213. {
  214. struct
  215. {
  216. INT16 iDBDX, iDGDX, iDRDX, iDADX; // 1.7.8
  217. };
  218. struct
  219. {
  220. FLOAT fDBDX, fDGDX, fDRDX, fDADX;
  221. };
  222. struct
  223. {
  224. INT32 iDIdxDX, iDIdxADX; // 1.8.16
  225. };
  226. };
  227. struct
  228. {
  229. union
  230. {
  231. struct
  232. {
  233. INT16 iDBSDX, iDGSDX, iDRSDX; // 1.7.8
  234. };
  235. struct
  236. {
  237. FLOAT fDBSDX, fDGSDX, fDRSDX;
  238. FLOAT fPad; // Padding to keep this set of attributes
  239. // an even multiple of quadwords.
  240. };
  241. };
  242. };
  243. struct
  244. {
  245. union
  246. {
  247. INT32 iDUoW2DX; // 1.11.20
  248. FLOAT fDUoW2DX;
  249. };
  250. union
  251. {
  252. INT32 iDVoW2DX; // 1.11.20
  253. FLOAT fDVoW2DX;
  254. };
  255. };
  256. // Y gradients for some attributes so that span routines
  257. // can do per-pixel mipmapping.
  258. union
  259. {
  260. INT32 iDUoW1DY; // 1.11.20
  261. FLOAT fDUoW1DY;
  262. };
  263. union
  264. {
  265. INT32 iDVoW1DY; // 1.11.20
  266. FLOAT fDVoW1DY;
  267. };
  268. union
  269. {
  270. INT32 iDUoW2DY; // 1.11.20
  271. FLOAT fDUoW2DY;
  272. };
  273. union
  274. {
  275. INT32 iDVoW2DY; // 1.11.20
  276. FLOAT fDVoW2DY;
  277. };
  278. union
  279. {
  280. INT32 iDOoWDY; // 1.31
  281. FLOAT fDOoWDY;
  282. };
  283. struct tagD3DI_RASTPRIM *pNext;
  284. // Pad to an even multiple of 32 bytes for cache alignment.
  285. DWORD uPad[2];
  286. // Anything else needed
  287. #ifdef _IA64_
  288. UINT8 Padding[28];
  289. #endif // _IA64_
  290. } D3DI_RASTPRIM, *PD3DI_RASTPRIM;
  291. typedef CONST D3DI_RASTPRIM *PCD3DI_RASTPRIM;
  292. // D3DI_SPANTEX uFlags
  293. #define D3DI_SPANTEX_HAS_TRANSPARENT (0x00000001L)
  294. #define D3DI_SPANTEX_SURFACES_LOCKED (0x00000002L)
  295. #define D3DI_SPANTEX_MAXMIPLEVELS_DIRTY (0x00000004L)
  296. // Palette with alpha
  297. #define D3DI_SPANTEX_ALPHAPALETTE (0x00000008L)
  298. #define D3DI_SPANTEX_NON_POWER_OF_2 (0x00000010L)
  299. // D3DI_SPANTEX uFormat - NOTE: these enumerations match the sequence in the
  300. // array of DDPIXELFORMAT structures defined for matching in texture creation
  301. //
  302. // NOTE: these must be kept consistent with the RRPixelFormats for the reference rasterizer
  303. typedef enum _D3DI_SPANTEX_FORMAT
  304. {
  305. D3DI_SPTFMT_NULL = 0,
  306. D3DI_SPTFMT_B8G8R8 = 1,
  307. D3DI_SPTFMT_B8G8R8A8 = 2,
  308. D3DI_SPTFMT_B8G8R8X8 = 3,
  309. D3DI_SPTFMT_B5G6R5 = 4,
  310. D3DI_SPTFMT_B5G5R5 = 5,
  311. D3DI_SPTFMT_PALETTE4 = 6,
  312. D3DI_SPTFMT_PALETTE8 = 7,
  313. D3DI_SPTFMT_B5G5R5A1 = 8,
  314. D3DI_SPTFMT_B4G4R4 = 9,
  315. D3DI_SPTFMT_B4G4R4A4 =10,
  316. D3DI_SPTFMT_L8 =11, /* 8 bit luminance-only */
  317. D3DI_SPTFMT_L8A8 =12, /* 16 bit alpha-luminance */
  318. D3DI_SPTFMT_U8V8 =13, /* 16 bit bump map format */
  319. D3DI_SPTFMT_U5V5L6 =14, /* 16 bit bump map format with luminance */
  320. D3DI_SPTFMT_U8V8L8 =15, /* 24 bit bump map format with luminance */
  321. D3DI_SPTFMT_UYVY =16, /* UYVY format for PC98 compliance */
  322. D3DI_SPTFMT_YUY2 =17, /* YUY2 format for PC98 compliance */
  323. D3DI_SPTFMT_DXT1 =18, /* S3 texture compression technique 1 */
  324. D3DI_SPTFMT_DXT2 =19, /* S3 texture compression technique 2 */
  325. D3DI_SPTFMT_DXT3 =20, /* S3 texture compression technique 3 */
  326. D3DI_SPTFMT_DXT4 =21, /* S3 texture compression technique 4 */
  327. D3DI_SPTFMT_DXT5 =22, /* S3 texture compression technique 5 */
  328. D3DI_SPTFMT_B2G3R3 =23, /* 8 bit RGB texture format */
  329. D3DI_SPTFMT_Z16S0 =32,
  330. D3DI_SPTFMT_Z24S8 =33,
  331. D3DI_SPTFMT_Z15S1 =34,
  332. D3DI_SPTFMT_Z32S0 =35,
  333. D3DI_SPTFMT_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  334. } D3DI_SPANTEX_FORMAT;
  335. // This encompasses all needed info about a chain of DD surfaces being used
  336. // as a potentially mipmapped texture.
  337. #define SPANTEX_MAXCLOD 11 // up to 2kx2k texture, all we can do with MMX INT16
  338. // U's and V's
  339. typedef struct tagD3DI_SPANTEX
  340. {
  341. UINT32 dwSize;
  342. INT32 iGeneration; // incremented when the texture changes
  343. UINT32 uFlags; // perspective, etc.
  344. D3DI_SPANTEX_FORMAT Format; // pixel format of the texture
  345. D3DTEXTUREADDRESS TexAddrU, TexAddrV; // texture address mode
  346. D3DTEXTUREMAGFILTER uMagFilter;// TEX3 style filter information
  347. D3DTEXTUREMINFILTER uMinFilter;// ATTENTION we could express this information more compactly
  348. D3DTEXTUREMIPFILTER uMipFilter;
  349. D3DCOLOR BorderColor; // border color for the texture
  350. // (for D3DTADDRESS_BORDER)
  351. D3DCOLOR TransparentColor; // color key on texture read
  352. FLOAT fLODBias; // Texture3 LOD bias value.
  353. PUINT8 pBits[SPANTEX_MAXCLOD]; // pointer for each LOD
  354. #if (SPANTEX_MAXCLOD & 1) != 0
  355. // Pad following fields to a DWORD boundary.
  356. INT16 iPitchPad;
  357. #endif
  358. PUINT32 pRampmap; // set by ramp rasterizer, if necessary
  359. PUINT32 pPalette; // pointer to palette, if necessary
  360. INT32 iPaletteSize; // size of palette
  361. INT32 cLOD; // contains count of levels - 1 (0 means 1 level)
  362. // to use
  363. INT32 cLODTex; // contains count of levels - 1 (0 means 1 level)
  364. // that are actually in the texture
  365. // cLODTex >= cLOD is always true
  366. INT32 iMaxMipLevel; // index of largest mip map to use. 0 means use largest.
  367. INT iMaxScaledLOD; // ((cLOD + 1) scaled by LOD_SCALE) - 1.
  368. INT16 iSizeU, iSizeV; // LOD 0 size (only support power of 2
  369. // textures)
  370. INT16 iShiftU, iShiftV; // LOD 0 log2 size (valid for power-of-2
  371. // size only)
  372. INT16 iShiftPitch[SPANTEX_MAXCLOD]; // log2 pitch for each LOD
  373. UINT16 uMaskU, uMaskV; // LOD 0 (1<<log2(size))-1
  374. // Variables for arithmetic address computation. Computed by DoTexAddrSetup.
  375. INT16 iFlipMaskU, iFlipMaskV;
  376. INT16 iClampMinU, iClampMinV;
  377. INT16 iClampMaxU, iClampMaxV;
  378. INT16 iClampEnU, iClampEnV;
  379. LPDIRECTDRAWSURFACE pSurf[SPANTEX_MAXCLOD]; // Added for TextureGetSurf
  380. // and Lock/Unlock Texture
  381. } D3DI_SPANTEX, *PD3DI_SPANTEX;
  382. // Color structure for blending etc. with enough room for 8.8 colors.
  383. // Even for 8 bit colors, this is convenient for lining up the colors
  384. // as we desire in MMX for 16 bit multiplies
  385. typedef struct tagD3DI_RASTCOLOR
  386. {
  387. UINT16 uB, uG, uR, uA;
  388. } D3DI_RASTCOLOR, *PD3DI_RASTCOLOR;
  389. // This structure has all the temporary storage needed for all the iterated
  390. // values to route the span information between the layers.
  391. // TBD there is lots more to add here, do texture mapping first
  392. typedef struct tagD3DI_SPANITER
  393. {
  394. // make the colors use the same order as RASTCOLOR above
  395. UINT16 uBB, uBG, uBR, uBA; // 8.8 blended color
  396. UINT16 uFogB, uFogG, uFogR, uFog; // 8.8 fog color, 0.16 fog value
  397. INT16 iFogBDX, iFogGDX, iFogRDX, iDFog; // 1.7.8 fog color deltas
  398. UINT32 uZDeferred; // storage for Z for deferred Z write
  399. union
  400. {
  401. INT32 iU1; // 1.15.16
  402. FLOAT fU1;
  403. };
  404. union
  405. {
  406. INT32 iV1; // 1.15.16
  407. FLOAT fV1;
  408. };
  409. union
  410. {
  411. INT32 iU2; // 1.15.16
  412. FLOAT fU2;
  413. };
  414. union
  415. {
  416. INT32 iV2; // 1.15.16
  417. FLOAT fV2;
  418. };
  419. D3DCOLOR TexCol[2]; // [Texture]
  420. INT32 iDW; // to remember last delta W in
  421. UINT16 uDitherOffset;
  422. INT16 iXStep; // 1 or -1
  423. INT16 iSpecialW; // negative for first or last 3 pixels of span
  424. INT16 bStencilPass; // 1 if stencil test passed, otherwise 0
  425. union
  426. {
  427. INT32 iOoW; // previous OoW to pass between texaddr stages
  428. FLOAT fOoW;
  429. };
  430. } D3DI_SPANITER, *PD3DI_SPANITER;
  431. // Z compare macro
  432. // This does depend on the result of a compare being 0 or 1 (for the final XOR, since C
  433. // doesn't have a logical XOR), but this has been true on all processors and
  434. // compilers for some time.
  435. #define ZCMP16(p, g, b) \
  436. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  437. // Assumes the most significant bit of Z is 0 (31 bit Z)
  438. #define ZCMP32(p, g, b) \
  439. ((((((INT32)(g) - (INT32)(b)) & (p)->iZAndMask) - (p)->iZNeg) >= 0) ^ (p)->iZXorMask)
  440. // Alpha Test compare macro
  441. #define ACMP(p, g, b) \
  442. ((((((INT32)(g) - (INT32)(b)) & (p)->iAAndMask) - (p)->iANeg) >= 0) ^ (p)->iAXorMask)
  443. // Stencil Test compare macro
  444. #define SCMP(p, g, b) \
  445. ((((((INT32)(g) - (INT32)(b)) & (p)->iSAndMask) - (p)->iSNeg) >= 0) ^ (p)->iSXorMask)
  446. // Helper macro that converts [0, 0xff] to [0, 5], linearly
  447. #define RGB8_CHANNEL(rgb) ((((rgb) * 5) + 0x80) >> 8)
  448. // Defines conversion from 24 bit RGB to 8 bit palette index. Each color has 6 values
  449. // resulting in 6**3 == 216 required colors in the palette.
  450. #define MAKE_RGB8(r, g, b) (RGB8_CHANNEL(r) * 36 \
  451. + RGB8_CHANNEL(g) * 6 \
  452. + RGB8_CHANNEL(b))
  453. // forward declaration of D3DI_RASTCTX
  454. struct tagD3DI_RASTCTX;
  455. typedef struct tagD3DI_RASTCTX D3DI_RASTCTX;
  456. typedef struct tagD3DI_RASTCTX *PD3DI_RASTCTX;
  457. typedef CONST struct tagD3DI_RASTCTX *PCD3DI_RASTCTX;
  458. // typedef for old ramp assembly monolithics
  459. typedef void (CDECL *PFNRAMPOLD)(PD3DI_RASTCTX drv, D3DINSTRUCTION* ins,
  460. D3DTLVERTEX* lpTLVert, D3DTRIANGLE* tri);
  461. // typedef for entry point for old ramp assembly monolithics
  462. typedef HRESULT (CDECL *PFNRAMPOLDTRI)(PD3DI_RASTCTX pCtx,
  463. LPD3DTLVERTEX pV0,
  464. LPD3DTLVERTEX pV1,
  465. LPD3DTLVERTEX pV2);
  466. // typedef for each rendering layer
  467. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  468. typedef void (CDECL *PFNSPANLAYER)(PD3DI_RASTCTX pCtx, PD3DI_RASTPRIM pP,
  469. PD3DI_RASTSPAN pS);
  470. // typedef texture read functions
  471. // this is an actual function so it can be called multiple times
  472. // note that the RASTCTX is changed because of the D3DI_SPANITER values
  473. typedef D3DCOLOR (CDECL *PFNTEXREAD)(INT32 iU, INT32 iV, INT32 iShiftU,
  474. PUINT8 pBits, PD3DI_SPANTEX pTex);
  475. // Typedef for span rendering function pointers.
  476. typedef HRESULT (CDECL *PFNRENDERSPANS)(PD3DI_RASTCTX pCtx);
  477. // typedef for alpha blending functions.
  478. typedef void (CDECL *PFNBLENDFUNC)(PUINT16 pR, PUINT16 pG, PUINT16 pB,
  479. PUINT16 pA, D3DCOLOR DestC,
  480. PD3DI_RASTCTX pCtx);
  481. // typedef for buffer read functions.
  482. typedef D3DCOLOR (CDECL *PFNBUFREAD)(PUINT8 pBits);
  483. // typedef for texture blend get functions.
  484. typedef void (CDECL *PFNTEXBLENDGET)(PD3DI_RASTCOLOR pArg1,
  485. PD3DI_RASTCOLOR pArg2,
  486. PD3DI_RASTCOLOR pInput,
  487. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  488. INT32 iTex);
  489. // typedef for texture blend get functions.
  490. typedef void (CDECL *PFNTEXBLENDOP)(PD3DI_RASTCOLOR pOut,
  491. PD3DI_RASTCOLOR pArg1,
  492. PD3DI_RASTCOLOR pArg2,
  493. PD3DI_RASTCTX pCtx, PD3DI_RASTSPAN pS,
  494. INT32 iTex);
  495. // Prototype for set of bead selections.
  496. typedef enum tagD3DI_BEADSET
  497. {
  498. D3DIBS_CMMX = 1, // C emulation of MMX beads
  499. D3DIBS_MMX = 2, // MMX beads
  500. D3DIBS_C = 3, // C beads
  501. D3DIBS_RAMP = 4, // Ramp beads
  502. D3DIBS_MMXASRGB = 5, // MMX selected for RGB rasterizer
  503. } D3DI_BEADSET;
  504. typedef struct tagD3DI_FILLPARAMS
  505. {
  506. DWORD dwWrapU;
  507. DWORD dwWrapV;
  508. DWORD dwCullCCW;
  509. DWORD dwCullCW;
  510. } D3DI_FILLPARAMS, *PD3DI_FILLPARAMS;
  511. // General span scanning context
  512. struct tagD3DI_RASTCTX
  513. {
  514. UINT32 dwSize;
  515. //////////////////////////////////////////////////////////////////////
  516. // Temporary storage for span rendering routines. Could be global.
  517. // Not set by caller, and not changed by SpanInit.
  518. //
  519. D3DI_SPANITER SI;
  520. //////////////////////////////////////////////////////////////////////
  521. // Data that must be set by caller before a SpanInit.
  522. //
  523. // we may want to put a pointer to a DDSURFACEDESC or something like it
  524. // instead of this
  525. PUINT8 pSurfaceBits;
  526. INT iSurfaceStride;
  527. INT iSurfaceStep;
  528. INT iSurfaceBitCount;
  529. INT iSurfaceType; // or however we end up expressing this
  530. PUINT32 pRampMap; // pointer to ramp map, if necessary
  531. LPDIRECTDRAWSURFACE pDDS;
  532. PUINT8 pZBits;
  533. INT iZStride;
  534. INT iZStep;
  535. INT iZBitCount;
  536. LPDIRECTDRAWSURFACE pDDSZ;
  537. // Clip area.
  538. RECT Clip;
  539. // Sign of face area that should be culled. Zero is clockwise,
  540. // one is CCW and everything else means no culling.
  541. UINT uCullFaceSign;
  542. union
  543. {
  544. DWORD pdwRenderState[D3DHAL_MAX_RSTATES_AND_STAGES];
  545. FLOAT pfRenderState[D3DHAL_MAX_RSTATES_AND_STAGES];
  546. };
  547. // Since we are adjusting the order of texIdx in the vertex to suit that
  548. // defined in state TEXCOORDINDEX, we need a copy of adjusted WRAP state.
  549. // This is declared immediately after pdwRenderState so that we can share
  550. // a register with it in the assembly code.
  551. // WARNING WARNING - THIS ABSOLUTELY NEEDS TO BE FOLLOWING pdwRenderState
  552. // IMMEDIATELY. ASM CODE DEPENDS ON THIS.
  553. DWORD pdwWrap[2];
  554. // first texture object contains information for texture for first pair
  555. // of texture coordinates, second contains texture for second pair of
  556. // texture coordinates, etc.
  557. PD3DI_SPANTEX pTexture[2];
  558. // Number of active textures. 0 - texture off; 1 - pTexture[0] is valid
  559. // 2 - both pTexture[0] and pTexture[1] are valid
  560. UINT cActTex;
  561. // Dirty bits for render states.
  562. // ATTENTION - We can reduce the size to have one bit for each group of
  563. // states when we implement the light weighted beed chooser.
  564. // Right now, it's set by SetRenderState and cleared after SpanInit is
  565. // called. The bit corresponding to D3DHAL_MAX_RSTATES_AND_STAGES is set
  566. // whenever a state is changed.
  567. UINT8 StatesDirtyBits[RAST_DIRTYBITS_SIZE];
  568. #if (RAST_DIRTYBITS_SIZE & 1) != 0
  569. // Pad following fields to a DWORD boundary.
  570. INT8 StatesDirtyBitsPad0;
  571. #endif
  572. #if (RAST_DIRTYBITS_SIZE & 2) != 0
  573. // Pad following fields to a DWORD boundary.
  574. INT16 StatesDirtyBitsPad1;
  575. #endif
  576. // Version# of the D3DDevice corresponding to this Context
  577. UINT32 uDevVer;
  578. //////////////////////////////////////////////////////////////////////
  579. // Data is set by SpanInit given the input above.
  580. //
  581. // Triangle entry points for old DX5/DX3 style ramp monolithics
  582. PFNRAMPOLDTRI pfnRampOldTri;
  583. PFNRAMPOLD pfnRampOld;
  584. // Span rendering entry point.
  585. PFNRENDERSPANS pfnRenderSpans;
  586. // function pointers for the beads
  587. PFNSPANLAYER pfnBegin;
  588. PFNSPANLAYER pfnLoopEnd;
  589. PFNSPANLAYER pfnTestPassEnd;
  590. PFNSPANLAYER pfnTestFailEnd;
  591. PFNSPANLAYER pfnTex1AddrEnd;
  592. PFNTEXREAD pfnTexRead[2];
  593. PFNSPANLAYER pfnTex2AddrEnd;
  594. PFNSPANLAYER pfnTexBlendEnd;
  595. PFNTEXBLENDGET pfnTexBlendGetColor[2];
  596. PFNTEXBLENDGET pfnTexBlendGetAlpha[2];
  597. PFNTEXBLENDOP pfnTexBlendOpColor[2];
  598. PFNTEXBLENDOP pfnTexBlendOpAlpha[2];
  599. PFNSPANLAYER pfnColorGenEnd;
  600. PFNSPANLAYER pfnAlphaTestPassEnd;
  601. PFNSPANLAYER pfnAlphaTestFailEnd;
  602. PFNBLENDFUNC pfnSrcBlend;
  603. PFNBLENDFUNC pfnDestBlend;
  604. PFNBUFREAD pfnBufRead;
  605. PFNSPANLAYER pfnColorBlendEnd;
  606. // Optional bead that can be called after every pixel for rasterizers
  607. // which loop beads rather than returning.
  608. PFNSPANLAYER pfnPixelEnd;
  609. // Optional bead that can be called after every span for rasterizers
  610. // which loop spans rather than returning.
  611. PFNSPANLAYER pfnSpanEnd;
  612. // arithmetic Z variables
  613. INT32 iZAndMask, iZNeg, iZXorMask;
  614. // arithmetic Alpha test variables. These could be 16 bits, if we ever really want
  615. // to save space
  616. INT32 iAAndMask, iANeg, iAXorMask;
  617. // 8.8 Alpha reference value
  618. INT32 iARef;
  619. // arithmetic stencil test variables. These could be 16 bits, if we ever really want
  620. // to save space
  621. INT32 iSAndMask, iSNeg, iSXorMask;
  622. // Pointer to first RASTPRIM.
  623. PD3DI_RASTPRIM pPrim;
  624. // Pointer to next context.
  625. PD3DI_RASTCTX pNext;
  626. // Current BeadTable to use
  627. D3DI_BEADSET BeadSet;
  628. // Bit 0 set disables ml1, etc.
  629. #define MMX_FP_DISABLE_MASK_NUM 1
  630. DWORD dwMMXFPDisableMask[MMX_FP_DISABLE_MASK_NUM];
  631. // RampLightingDriver, should be NULL except for RampRast and 8 bit palettized RGB
  632. // output surface cases.
  633. LPVOID pRampDrv;
  634. // RAMP_RANGE_INFO RampInfo;
  635. DWORD RampBase;
  636. DWORD RampSize;
  637. PUINT32 pTexRampMap;
  638. BOOL bRampSpecular;
  639. PD3DI_FILLPARAMS pFillParams;
  640. D3DI_FILLPARAMS FillParams;
  641. DWORD uFlags; // misc. flags
  642. #ifdef DBG
  643. #define NAME_LEN 128
  644. char szTest[NAME_LEN];
  645. char szTestFail[NAME_LEN];
  646. char szTex1Addr[NAME_LEN];
  647. char szTexRead[2][NAME_LEN];
  648. char szTex2Addr[NAME_LEN];
  649. char szTexBlend[NAME_LEN];
  650. char szColorGen[NAME_LEN];
  651. char szAlphaTest[NAME_LEN];
  652. char szColorBlend[NAME_LEN];
  653. char szSrcBlend[NAME_LEN];
  654. char szDestBlend[NAME_LEN];
  655. char szBufRead[NAME_LEN];
  656. char szBufWrite[NAME_LEN];
  657. #undef NAME_LEN
  658. #endif
  659. };
  660. #define RASTCTXFLAGS_APPHACK_MSGOLF 0x00000001
  661. // Data passed to the span rendering functions looks like this:
  662. //
  663. // RASTCTX
  664. // |-> RASTPRIM
  665. // | | RASTSPAN
  666. // | | RASTSPAN (as many as RASTPRIM.uSpans says there are)
  667. // | RASTPRIM
  668. // | | RASTSPAN
  669. // | NULL
  670. // RASTCTX
  671. // |-> RASTPRIM
  672. // | | RASTSPAN
  673. // | NULL
  674. // NULL
  675. //
  676. // The given RASTCTX is the head of a list of contexts. Each context
  677. // points to a list of RASTPRIMs. Each RASTPRIM structure is immediately
  678. // followed by RASTPRIM.uSpans RASTSPAN structures.
  679. // Prototype for state validation call.
  680. HRESULT SpanInit(PD3DI_RASTCTX pCtx);
  681. // This is used to pack a FVF vertex into one understand by OptRast so it
  682. // does not need to figure out where to get the data it needs. This struct
  683. // can be modified to accommodate more data and it can be broken into more
  684. // specilized and smalled structs.
  685. // Right now, it is an extension of D3DTLVERTEX, and the extra uv is at the
  686. // very end so that OptRast can treat it as a D3DTLVERTEX if only the first
  687. // part of the data needs to be accessed.
  688. typedef struct _RAST_GENERIC_VERTEX {
  689. union {
  690. D3DVALUE sx; /* Screen coordinates */
  691. D3DVALUE dvSX;
  692. };
  693. union {
  694. D3DVALUE sy;
  695. D3DVALUE dvSY;
  696. };
  697. union {
  698. D3DVALUE sz;
  699. D3DVALUE dvSZ;
  700. };
  701. union {
  702. D3DVALUE rhw; /* Reciprocal of homogeneous w */
  703. D3DVALUE dvRHW;
  704. };
  705. union {
  706. D3DCOLOR color; /* Vertex color */
  707. D3DCOLOR dcColor;
  708. };
  709. union {
  710. D3DCOLOR specular; /* Specular component of vertex */
  711. D3DCOLOR dcSpecular;
  712. };
  713. union {
  714. D3DVALUE tu; /* Texture coordinates */
  715. D3DVALUE dvTU;
  716. };
  717. union {
  718. D3DVALUE tv;
  719. D3DVALUE dvTV;
  720. };
  721. union {
  722. D3DVALUE tu2; /* second Texture coordinates */
  723. D3DVALUE dvTU2;
  724. };
  725. union {
  726. D3DVALUE tv2;
  727. D3DVALUE dvTV2;
  728. };
  729. }RAST_GENERIC_VERTEX, *PRAST_GENERIC_VERTEX;
  730. // Vertex types supported by OptRast
  731. typedef enum _RAST_VERTEX_TYPE
  732. {
  733. RAST_TLVERTEX = 1, /* (Legacy) TL vertex */
  734. RAST_GENVERTEX = 2, /* Generic FVF vertex */
  735. RAST_FORCE_DWORD = 0x7fffffff, /* force 32-bit size enum */
  736. }RAST_VERTEX_TYPE;
  737. #include <poppack.h>
  738. //-----------------------------------------------------------------------------
  739. //
  740. // Surface types for rendering surfaces and textures. Different subsets are
  741. // supported for render targets and for textures.
  742. //
  743. //-----------------------------------------------------------------------------
  744. typedef enum _RRSurfaceType
  745. {
  746. RR_STYPE_NULL = 0,
  747. RR_STYPE_B8G8R8 = 1,
  748. RR_STYPE_B8G8R8A8 = 2,
  749. RR_STYPE_B8G8R8X8 = 3,
  750. RR_STYPE_B5G6R5 = 4,
  751. RR_STYPE_B5G5R5 = 5,
  752. RR_STYPE_PALETTE4 = 6,
  753. RR_STYPE_PALETTE8 = 7,
  754. RR_STYPE_B5G5R5A1 = 8,
  755. RR_STYPE_B4G4R4 = 9,
  756. RR_STYPE_B4G4R4A4 =10,
  757. RR_STYPE_L8 =11, // 8 bit luminance-only
  758. RR_STYPE_L8A8 =12, // 16 bit alpha-luminance
  759. RR_STYPE_U8V8 =13, // 16 bit bump map format
  760. RR_STYPE_U5V5L6 =14, // 16 bit bump map format with luminance
  761. RR_STYPE_U8V8L8 =15, // 24 bit bump map format with luminance
  762. RR_STYPE_UYVY =16, // UYVY format (PC98 compliance)
  763. RR_STYPE_YUY2 =17, // YUY2 format (PC98 compliance)
  764. RR_STYPE_DXT1 =18, // S3 texture compression technique 1
  765. RR_STYPE_DXT2 =19, // S3 texture compression technique 2
  766. RR_STYPE_DXT3 =20, // S3 texture compression technique 3
  767. RR_STYPE_DXT4 =21, // S3 texture compression technique 4
  768. RR_STYPE_DXT5 =22, // S3 texture compression technique 5
  769. RR_STYPE_B2G3R3 =23, // 8 bit RGB texture format
  770. RR_STYPE_Z16S0 =32,
  771. RR_STYPE_Z24S8 =33,
  772. RR_STYPE_Z15S1 =34,
  773. RR_STYPE_Z32S0 =35,
  774. } RRSurfaceType;
  775. #ifdef __cplusplus
  776. }
  777. #endif
  778. #endif // _SPAN_H_