Source code of Windows XP (NT5)
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.

359 lines
12 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: mcdhw.h
  3. *
  4. * Driver-specific structures and defines for the Millenium MCD driver.
  5. *
  6. * Copyright (c) 1996 Microsoft Corporation
  7. \**************************************************************************/
  8. #if DBG
  9. #define FASTCALL
  10. #else
  11. #ifdef _X86_
  12. #define FASTCALL __fastcall
  13. #else
  14. #define FASTCALL
  15. #endif
  16. #endif
  17. #define ASM_ACCEL 1 // Enable/disable asm code
  18. #define __MCD_USER_CLIP_MASK ((1 << MCD_MAX_USER_CLIP_PLANES) - 1)
  19. #define __MCD_CW 0
  20. #define __MCD_CCW 1
  21. #define __MCD_FRONTFACE MCDVERTEX_FRONTFACE
  22. #define __MCD_BACKFACE MCDVERTEX_BACKFACE
  23. #define __MCD_NOFACE -1
  24. #define __MCDENABLE_TWOSIDED 0x0001
  25. #define __MCDENABLE_Z 0x0002
  26. #define __MCDENABLE_SMOOTH 0x0004
  27. #define __MCDENABLE_GRAY_FOG 0x0008
  28. typedef LONG MCDFIXED;
  29. typedef struct _RGBACOLOR {
  30. MCDFIXED r, g, b, a;
  31. } RGBACOLOR;
  32. #define SWAP_COLOR(p)\
  33. {\
  34. MCDFLOAT tempR, tempG, tempB;\
  35. \
  36. tempR = (p)->colors[0].r;\
  37. (p)->colors[0].r = (p)->colors[1].r;\
  38. (p)->colors[1].r = tempR;\
  39. \
  40. tempG = (p)->colors[0].g;\
  41. (p)->colors[0].g = (p)->colors[1].g;\
  42. (p)->colors[1].g = tempG;\
  43. \
  44. tempB = (p)->colors[0].b;\
  45. (p)->colors[0].b = (p)->colors[1].b;\
  46. (p)->colors[1].b = tempB;\
  47. }
  48. #define SAVE_COLOR(temp, p)\
  49. {\
  50. temp.r = (p)->colors[0].r;\
  51. temp.g = (p)->colors[0].g;\
  52. temp.b = (p)->colors[0].b;\
  53. }
  54. #define RESTORE_COLOR(temp, p)\
  55. {\
  56. (p)->colors[0].r = temp.r;\
  57. (p)->colors[0].g = temp.g;\
  58. (p)->colors[0].b = temp.b;\
  59. }
  60. #define COPY_COLOR(pDst, pSrc)\
  61. {\
  62. pDst.r = pSrc.r;\
  63. pDst.g = pSrc.g;\
  64. pDst.b = pSrc.b;\
  65. }
  66. #define MCDCLAMPCOUNT(value) ((ULONG)(value) & 0x00007fff)
  67. #define MCDFIXEDRGB(fixColor, fltColor)\
  68. fixColor.r = (MCDFIXED)(fltColor.r * pRc->rScale);\
  69. fixColor.g = (MCDFIXED)(fltColor.g * pRc->gScale);\
  70. fixColor.b = (MCDFIXED)(fltColor.b * pRc->bScale);
  71. typedef struct _DRVPIXELFORMAT {
  72. UCHAR cColorBits;
  73. UCHAR rBits;
  74. UCHAR gBits;
  75. UCHAR bBits;
  76. UCHAR aBits;
  77. UCHAR rShift;
  78. UCHAR gShift;
  79. UCHAR bShift;
  80. UCHAR aShift;
  81. } DRVPIXELFORMAT;
  82. typedef struct _DEVWND {
  83. ULONG createFlags; // (RC) creation flags
  84. LONG iPixelFormat; // pixel format ID for this window
  85. ULONG dispUnique; // display resolution uniqueness
  86. ULONG frontBufferPitch; // pitch in bytes
  87. ULONG allocatedBufferHeight; // Same for back and z on Millenium
  88. BOOL bValidBackBuffer; // back buffer validity
  89. ULONG backBufferBase; // byte offset to start of back buffer pool
  90. ULONG backBufferBaseY; // y value for start of back buffer pool
  91. ULONG backBufferOffset; // byte offset to start of back buffer
  92. ULONG backBufferY; // y value for start of active back buffer
  93. ULONG backBufferPitch; // back buffer pitch in bytes
  94. BOOL bValidZBuffer; // z buffer validity
  95. ULONG zBufferBase; // byte offset to start of z buffer pool
  96. ULONG zBufferBaseY; // y value for start of z buffer pool
  97. ULONG zBufferOffset; // byte offset to start of z buffer
  98. ULONG zPitch; // z buffer pitch in bytes
  99. ULONG numPadScans; // number of pad scan lines in buffers
  100. OH* pohBackBuffer; // ofscreen pools
  101. OH* pohZBuffer;
  102. } DEVWND;
  103. typedef struct _DEVRC DEVRC;
  104. typedef struct _DEVRC
  105. {
  106. MCDRENDERSTATE MCDState;
  107. MCDVIEWPORT MCDViewport;
  108. MCDSURFACE *pMCDSurface; // Valid for primitives only
  109. MCDRC *pMCDRc; // Valid for primitives only
  110. PDEV* ppdev; // Valid for primitives only
  111. ENUMRECTS *pEnumClip; // Valid for primitives only
  112. MCDVERTEX *pvProvoking; // provoking vertex
  113. UCHAR *pMemMax; // command-buffer memory bounds
  114. UCHAR *pMemMin;
  115. LONG iPixelFormat; // valid pixel format ID for this RC
  116. // storage and pointers for clip processing:
  117. MCDVERTEX clipTemp[6 + MCD_MAX_USER_CLIP_PLANES];
  118. MCDVERTEX *pNextClipTemp;
  119. VOID (FASTCALL *lineClipParam)(MCDVERTEX*, const MCDVERTEX*, const MCDVERTEX*, MCDFLOAT);
  120. VOID (FASTCALL *polyClipParam)(MCDVERTEX*, const MCDVERTEX*, const MCDVERTEX*, MCDFLOAT);
  121. // Rendering functions:
  122. VOID (FASTCALL *renderPoint)(DEVRC *pRc, MCDVERTEX *pv);
  123. VOID (FASTCALL *renderLine)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  124. VOID (FASTCALL *renderTri)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  125. VOID (FASTCALL *clipLine)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL bResetLine);
  126. VOID (FASTCALL *clipTri)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3, ULONG clipFlags);
  127. VOID (FASTCALL *clipPoly)(DEVRC *pRc, MCDVERTEX *pv, ULONG numVert);
  128. VOID (FASTCALL *doClippedPoly)(DEVRC *pRc, MCDVERTEX **pv, ULONG numVert, ULONG clipFlags);
  129. VOID (FASTCALL *renderPointX)(DEVRC *pRc, MCDVERTEX *pv);
  130. VOID (FASTCALL *renderLineX)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  131. VOID (FASTCALL *renderTriX)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  132. // Primitive-rendering function table:
  133. MCDCOMMAND * (FASTCALL *primFunc[10])(DEVRC *pRc, MCDCOMMAND *pCommand);
  134. // Internal table of rendering functions:
  135. VOID (FASTCALL *drawPoint)(DEVRC *pRc, MCDVERTEX *pv);
  136. VOID (FASTCALL *drawLine)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  137. VOID (FASTCALL *drawTri)(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3, BOOL bCCW);
  138. // Rendering helper functions:
  139. VOID (FASTCALL *HWSetupClipRect)(DEVRC *pRc, RECTL *pRect);
  140. VOID (FASTCALL *HWDrawTrap)(DEVRC *pRc, MCDFLOAT dxLeft, MCDFLOAT dxRight,
  141. LONG y, LONG dy);
  142. VOID (FASTCALL *HWSetupDeltas)(DEVRC *pRc);
  143. VOID (FASTCALL *beginLineDrawing)(DEVRC *pRc);
  144. VOID (FASTCALL *endLineDrawing)(DEVRC *pRc);
  145. VOID (FASTCALL *beginPointDrawing)(DEVRC *pRc);
  146. VOID (FASTCALL *calcDeltas)(DEVRC *pRc, MCDVERTEX *a, MCDVERTEX *b,
  147. MCDVERTEX *c);
  148. VOID (FASTCALL *adjustLeftEdge)(DEVRC *pRc, MCDVERTEX *p, MCDFLOAT dxLeft,
  149. MCDFLOAT dyLeft, MCDFLOAT xFrac, MCDFLOAT yFrac, MCDFLOAT xErr);
  150. VOID (FASTCALL *adjustRightEdge)(DEVRC *pRc, MCDVERTEX *p, MCDFLOAT dxRight,
  151. MCDFLOAT dyRight, MCDFLOAT xErr);
  152. BOOL bCheapFog;
  153. BOOL allPrimFail; // TRUE is the driver can't draw *any*
  154. // primitives for current state
  155. BOOL pickNeeded;
  156. BOOL resetLineStipple;
  157. RGBACOLOR fillColor;
  158. ULONG polygonFace[2]; // front/back face tables
  159. ULONG polygonMode[2];
  160. // Polygon-filling parameters and state:
  161. MCDFLOAT halfArea;
  162. MCDFLOAT invHalfArea;
  163. MCDFLOAT dxAC;
  164. MCDFLOAT dxAB;
  165. MCDFLOAT dxBC;
  166. MCDFLOAT dyAC;
  167. MCDFLOAT dyAB;
  168. MCDFLOAT dyBC;
  169. LONG cullFlag;
  170. MCDFLOAT drdx, drdy; // delta values
  171. MCDFLOAT dgdx, dgdy;
  172. MCDFLOAT dbdx, dbdy;
  173. MCDFLOAT dzdx, dzdy;
  174. MCDFIXED fxdrdx, fxdrdy; // fixed-point delta values
  175. MCDFIXED fxdgdx, fxdgdy;
  176. MCDFIXED fxdbdx, fxdbdy;
  177. MCDFIXED fxdzdx, fxdzdy;
  178. MCDFIXED rStart;
  179. MCDFIXED gStart;
  180. MCDFIXED bStart;
  181. ULONG ixLeft;
  182. ULONG ixRight;
  183. ULONG xOffset, yOffset;
  184. LONG viewportXAdjust;
  185. LONG viewportYAdjust;
  186. // Hardware-specific state and other information. Modifications will
  187. // not affect high-level code:
  188. LONG cFifo;
  189. BOOL bRGBMode;
  190. BOOL zBufEnabled;
  191. BOOL backBufEnabled;
  192. ULONG hwPlaneMask;
  193. ULONG hwZFunc;
  194. ULONG hwRop;
  195. ULONG ulAccess;
  196. ULONG hwStipple;
  197. ULONG hwLineFunc;
  198. ULONG hwIntLineFunc;
  199. ULONG hwTrapFunc;
  200. ULONG hwSpanFunc;
  201. ULONG hwSolidColor;
  202. ULONG hwPatternLength;
  203. ULONG hwPatternStart;
  204. ULONG hwPatternPos;
  205. ULONG hwBpp;
  206. LONG hwBufferYBias; // bias to convert window to buffer coord
  207. ULONG hwYOrgBias; // bias to convert window to 0-relative coord
  208. ULONG privateEnables;
  209. MCDFLOAT rScale;
  210. MCDFLOAT gScale;
  211. MCDFLOAT bScale;
  212. MCDFLOAT aScale;
  213. MCDFLOAT zScale;
  214. // shifts for converting to native bit depth
  215. ULONG rShift;
  216. ULONG gShift;
  217. ULONG bShift;
  218. ULONG aShift;
  219. // shifts for converting to hardware format
  220. ULONG hwRShift;
  221. ULONG hwGShift;
  222. ULONG hwBShift;
  223. ULONG hwAShift;
  224. // Not used in this driver, but good information to have around:
  225. ULONG hwZPitch;
  226. ULONG hwZBytesPerPixel;
  227. ULONG hwCPitch;
  228. ULONG hwCBytesPerPixel;
  229. MCDFLOAT zero;
  230. DRVPIXELFORMAT pixelFormat;
  231. } DEVRC;
  232. // External declarations
  233. MCDCOMMAND * FASTCALL __MCDPrimDrawPoints(DEVRC *pRc, MCDCOMMAND *pCmd);
  234. MCDCOMMAND * FASTCALL __MCDPrimDrawLines(DEVRC *pRc, MCDCOMMAND *pCmd);
  235. MCDCOMMAND * FASTCALL __MCDPrimDrawLineLoop(DEVRC *pRc, MCDCOMMAND *pCmd);
  236. MCDCOMMAND * FASTCALL __MCDPrimDrawLineStrip(DEVRC *pRc, MCDCOMMAND *pCmd);
  237. MCDCOMMAND * FASTCALL __MCDPrimDrawTriangles(DEVRC *pRc, MCDCOMMAND *pCmd);
  238. MCDCOMMAND * FASTCALL __MCDPrimDrawTriangleStrip(DEVRC *pRc, MCDCOMMAND *pCmd);
  239. MCDCOMMAND * FASTCALL __MCDPrimDrawTriangleFan(DEVRC *pRc, MCDCOMMAND *pCmd);
  240. MCDCOMMAND * FASTCALL __MCDPrimDrawQuads(DEVRC *pRc, MCDCOMMAND *pCmd);
  241. MCDCOMMAND * FASTCALL __MCDPrimDrawQuadStrip(DEVRC *pRc, MCDCOMMAND *pCmd);
  242. MCDCOMMAND * FASTCALL __MCDPrimDrawPolygon(DEVRC *pRc, MCDCOMMAND *_pCmd);
  243. // High-level rendering functions:
  244. VOID __MCDPickRenderingFuncs(DEVRC *pRc, DEVWND *pDevWnd);
  245. VOID FASTCALL __MCDRenderPoint(DEVRC *pRc, MCDVERTEX *pv);
  246. VOID FASTCALL __MCDRenderFogPoint(DEVRC *pRc, MCDVERTEX *pv);
  247. VOID FASTCALL __MCDRenderGenPoint(DEVRC *pRc, MCDVERTEX *pv);
  248. VOID FASTCALL __MCDRenderFlatLine(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  249. VOID FASTCALL __MCDRenderFlatFogLine(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  250. VOID FASTCALL __MCDRenderSmoothLine(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  251. VOID FASTCALL __MCDRenderGenLine(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, BOOL resetLine);
  252. VOID FASTCALL __MCDRenderFlatTriangle(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  253. VOID FASTCALL __MCDRenderFlatFogTriangle(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  254. VOID FASTCALL __MCDRenderSmoothTriangle(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  255. VOID FASTCALL __MCDRenderGenTriangle(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2, MCDVERTEX *pv3);
  256. // Low-level drawing functions:
  257. VOID FASTCALL __MCDPointBegin(DEVRC *pRc);
  258. VOID FASTCALL __MCDLineBegin(DEVRC *pRc);
  259. VOID FASTCALL __MCDLineEnd(DEVRC *pRc);
  260. VOID FASTCALL __MCDFillTriangle(DEVRC *pRc, MCDVERTEX *pv1, MCDVERTEX *pv2,
  261. MCDVERTEX *pv3, BOOL bCCW);
  262. // Clipping functions:
  263. VOID FASTCALL __MCDPickClipFuncs(DEVRC *pRc);
  264. VOID FASTCALL __MCDClipLine(DEVRC *pRc, MCDVERTEX *a, MCDVERTEX *b,
  265. BOOL bResetLine);
  266. VOID FASTCALL __MCDClipTriangle(DEVRC *pRc, MCDVERTEX *a, MCDVERTEX *b,
  267. MCDVERTEX *c, ULONG orClipCode);
  268. VOID FASTCALL __MCDClipPolygon(DEVRC *pRc, MCDVERTEX *v0, ULONG nv);
  269. VOID FASTCALL __MCDDoClippedPolygon(DEVRC *pRc, MCDVERTEX **iv, ULONG nout,
  270. ULONG allClipCodes);
  271. VOID FASTCALL __HWAdjustLeftEdgeRGBZ(DEVRC *pRc, MCDVERTEX *p,
  272. MCDFLOAT fdxLeft, MCDFLOAT fdyLeft,
  273. MCDFLOAT xFrac, MCDFLOAT yFrac,
  274. MCDFLOAT xErr);
  275. VOID FASTCALL __HWAdjustRightEdge(DEVRC *pRc, MCDVERTEX *p,
  276. MCDFLOAT fdxRight, MCDFLOAT fdyRight,
  277. MCDFLOAT xErr);
  278. VOID FASTCALL __MCDCalcDeltaRGBZ(DEVRC *pRc, MCDVERTEX *a, MCDVERTEX *b,
  279. MCDVERTEX *c);
  280. MCDFLOAT FASTCALL __MCDGetZOffsetDelta(DEVRC *pRc);
  281. // Fog function
  282. VOID __MCDCalcFogColor(DEVRC *pRc, MCDVERTEX *a, MCDCOLOR *pResult, MCDCOLOR *pColor);