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.

451 lines
17 KiB

  1. #ifndef __PARRAY_H__
  2. #define __PARRAY_H__
  3. #include "phong.h"
  4. // Number of polydata entries in the context. Must be at least 32.
  5. // It includes room for the polyarray entry and others.
  6. // It's currently based on POLYDATA_BUFFER_SIZE+1 vertices of size 128
  7. // fitting in 64K, which yields 511
  8. #define POLYDATA_BUFFER_SIZE 511
  9. // DrawElements expects at least this many vertices in the vertex buffer.
  10. // It is the sum of the following (currently sum is 278):
  11. // Number of vertex entries in a batch
  12. // Number of entries used for index map
  13. // An extra vertex entry to prevent calling PolyArrayFlushPartialPrimitive
  14. // in the Vertex routines.
  15. // An entry for POLYARRAY
  16. // 4 spare entries to be safe
  17. // It is given by
  18. // VA_DRAWELEM_MAP_SIZE +
  19. // (VA_DRAWELEM_INDEX_SIZE + sizeof(POLYDATA) - 1) / sizeof(POLYDATA) +
  20. // 1 + 1 + 4
  21. #define MINIMUM_POLYDATA_BUFFER_SIZE 300
  22. // Minimun number of polydata entries required before processing a primitive.
  23. // Must be at least 16.
  24. #define MIN_POLYDATA_BATCH_SIZE 68
  25. #if !((MIN_POLYDATA_BATCH_SIZE <= MINIMUM_POLYDATA_BUFFER_SIZE) && \
  26. (MINIMUM_POLYDATA_BUFFER_SIZE <= POLYDATA_BUFFER_SIZE) \
  27. )
  28. #error "bad sizes\n"
  29. #endif
  30. // Maximun number of vertices handled by the polygon decomposer.
  31. // It allocates stack space based on this constant. It must be at least 6.
  32. #define __GL_MAX_POLYGON_CLIP_SIZE 256
  33. // The POLYMATERIAL structure contains an index to the next available
  34. // __GLmatChange structure, an array of pointers to __GLmatChange arrays,
  35. // and a pointer to an array of PDMATERIAL structures each containing
  36. // pointers to the front and back material changes for each POLYDATA
  37. // elements in vertex buffer.
  38. //
  39. // The __GLmatChange structures are used to record material changes to
  40. // vertices in the vertex buffer. Since there can be up to two material
  41. // changes per vertex, we need up to (POLYDATA_BUFFER_SIZE * 2) material
  42. // changes per rendering thread.
  43. //
  44. // The PDMATERIAL array is part of the POLYMATERIAL structure and follows
  45. // the aMat field immediately. Its elements correspond to the POLYDATA
  46. // elements in the vertex buffer.
  47. //
  48. // To reduce memory requirement, the POLYMATERIAL structure keeps an array
  49. // of pointers to __GLmatChange arrays. Each __GLmatChange array of up to
  50. // 4K size is allocated as needed.
  51. //
  52. // An iMat index is used to keep track of the next free __GLmatChange
  53. // entry. When the poly array buffer is flushed in glsbAttention, iMat
  54. // is reset to 0.
  55. //
  56. // The POLYMATERIAL structure and its __GLmatChange arrays are part of
  57. // a thread local storage and are freed when the thread exits.
  58. #define POLYMATERIAL_ARRAY_SIZE (4096 / sizeof(__GLmatChange))
  59. // This structure is shared with MCD as MCDMATERIALCHANGE.
  60. typedef struct __GLmatChangeRec {
  61. GLuint dirtyBits;
  62. __GLcolor ambient;
  63. __GLcolor diffuse;
  64. __GLcolor specular;
  65. __GLcolor emissive;
  66. __GLfloat shininess;
  67. __GLfloat cmapa, cmapd, cmaps;
  68. } __GLmatChange;
  69. // Pointers to front and back material change structures. They are
  70. // valid only when the POLYDATA_MATERIAL_FRONT or POLYDATA_MATERIAL_BACK
  71. // flag of the corresponding POLYDATA in the vertex buffer is set.
  72. //
  73. // This structure is shared with MCD as MCDMATERIALCHANGES.
  74. typedef struct {
  75. __GLmatChange *front; // pointer to the front material changes
  76. __GLmatChange *back; // pointer to the back material changes
  77. } PDMATERIAL;
  78. typedef struct _POLYMATERIAL {
  79. GLuint iMat; // next available material structure for this command batch
  80. PDMATERIAL *pdMaterial0; // pointer to the PDMATERIAL array
  81. GLuint aMatSize; // number of aMat entries
  82. __GLmatChange *aMat[1]; // array of array of __GLmatChange structures
  83. } POLYMATERIAL;
  84. #ifdef GL_WIN_phong_shading
  85. #define __GL_PHONG_FRONT_FIRST_VALID 0x00000001
  86. #define __GL_PHONG_BACK_FIRST_VALID 0x00000002
  87. #define __GL_PHONG_FRONT_TRAIL_VALID 0x00000004
  88. #define __GL_PHONG_BACK_TRAIL_VALID 0x00000008
  89. #define __GL_PHONG_FRONT_FIRST 0
  90. #define __GL_PHONG_BACK_FIRST 1
  91. #define __GL_PHONG_FRONT_TRAIL 2
  92. #define __GL_PHONG_BACK_TRAIL 3
  93. typedef struct __GLphongMaterialDataRec
  94. {
  95. GLuint flags;
  96. __GLmatChange matChange[4];
  97. } __GLphongMaterialData;
  98. #endif //GL_WIN_phong_shading
  99. /*
  100. ** Vertex structure. Each vertex contains enough state to properly
  101. ** render the active primitive. It is used by the front-end geometry
  102. ** and back-end rasterization pipelines.
  103. **
  104. ** NOTE: Same as __GLvertex structure!
  105. ** NOTE: This structure is used by RasterPos and evaluator too!
  106. **
  107. ** To minimize storage requirement, some front-end storage (e.g. obj and normal)
  108. ** is shared with back-end storage.
  109. */
  110. typedef struct _POLYDATA {
  111. /*
  112. ** Keep this data structure aligned: have all vectors start on
  113. ** 4-word boundary, and sizeof this struct should be kept at
  114. ** a multiple of 4 words. Also helps to bunch together most
  115. ** frequently used items, helps cache.
  116. */
  117. /*
  118. ** Bits are set in this indicating which fields of the vertex are
  119. ** valid. This field is shared with the back-end has field!
  120. */
  121. GLuint flags;
  122. /*
  123. ** Moved up here to keep GLcoords aligned.
  124. */
  125. __GLcolor *color;
  126. /*
  127. ** Clipping code mask. One bit is set for each clipping plane that
  128. ** the vertex is out on.
  129. */
  130. GLuint clipCode;
  131. /*
  132. ** Fog value for the vertex. This is only filled when doing cheap
  133. ** fogging.
  134. */
  135. __GLfloat fog;
  136. /*
  137. ** Coordinates straight from client. These fields may not be
  138. ** set depending on the active modes. The normal and texture
  139. ** coordinate are used by lighting and texturing. These cells
  140. ** may be overwritten by the eyeNormal and the generated texture
  141. ** coordinate, depending on the active modes.
  142. */
  143. /*
  144. ** Projected eye coodinate. This field is filled in when the users
  145. ** eye coordinate has been multiplied by the projection matrix.
  146. */
  147. union
  148. {
  149. __GLcoord obj;
  150. __GLcoord clip;
  151. };
  152. /*
  153. ** Window coordinate. This field is filled in when the eye coordinate
  154. ** is converted to a drawing surface relative "window" coordinate.
  155. ** NOTE: the window.w coordinate contains 1/clip.w.
  156. */
  157. __GLcoord window;
  158. __GLcoord texture;
  159. __GLcoord normal;
  160. /*
  161. ** Colors. colors[0] is the "front" color, colors[1] is the "back" color.
  162. ** The color pointer points to which color is current for this
  163. ** vertex. Verticies can have more than one color when two sided
  164. ** lighting is enabled. (note color pointer moved up top).
  165. */
  166. __GLcolor colors[2];
  167. /*
  168. ** Eye coordinate. This field is filled in when the object coordinate
  169. ** has been multiplied by the model-view matrix. If no eye coordinate
  170. ** was needed then this field contains undefined values.
  171. */
  172. union {
  173. __GLcoord eye;
  174. struct {
  175. __GLfloat eyeX;
  176. __GLfloat eyeZ;
  177. __GLfloat eyeY;
  178. union {
  179. __GLfloat eyeW;
  180. __GLcolor *lastColor;
  181. };
  182. };
  183. };
  184. /*
  185. ** On Win64 the POLYARRAY structure is larger than the POLYDATA
  186. ** structure since the later contains several pointers which are
  187. ** 8 bytes on the 64-bit system. Therefore, this structure must
  188. ** be padded to be the same size as the POLYARRAY structure.
  189. **
  190. ** N.B. Since the structure must be the same size as the __GLvertex
  191. ** structure, then that structure must also be padded.
  192. **
  193. */
  194. #if defined(_WIN64)
  195. PVOID Filler[7];
  196. #endif
  197. } POLYDATA;
  198. // This structure is used by RasterPos and evaluator too!
  199. // This structure is also in the TEB!
  200. typedef struct _POLYARRAY {
  201. // Flags for this batch. Keep it first!
  202. GLuint flags;
  203. // Pointer to the next vertex in this batch.
  204. POLYDATA *pdNextVertex;
  205. // Pointer to the last vertex modifying the current color, RGBA or CI
  206. // depending on color mode, in this batch.
  207. POLYDATA *pdCurColor;
  208. // Pointer to the last vertex modifying normal coordinates in this batch.
  209. POLYDATA *pdCurNormal;
  210. // Pointer to the last vertex modifying texture coordinates in this batch.
  211. POLYDATA *pdCurTexture;
  212. // Pointer to the last vertex modifying edge flag in this batch.
  213. POLYDATA *pdCurEdgeFlag;
  214. // Pointer to the first vertex of this batch.
  215. // (pd0-1) points to this batch's POLYARRAY structure.
  216. POLYDATA *pd0;
  217. // Pointer to the flush vertex of this batch.
  218. POLYDATA *pdFlush;
  219. // Pointer to the vertex buffer entry in the gc for the next batch.
  220. POLYDATA *pdBufferNext;
  221. // Pointer to the first vertex buffer entry in the gc.
  222. POLYDATA *pdBuffer0;
  223. // Pointer to the last vertex buffer entry in the gc.
  224. POLYDATA *pdBufferMax;
  225. // In RGBA mode, otherColor.r is the last modified color index value in
  226. // this batch. In CI mode, otherColor is the last modified RGBA color in
  227. // this batch. Keep this field aligned!
  228. __GLcolor otherColor;
  229. // Primitive type.
  230. GLenum primType;
  231. // Or result of all vertex clipCode's in this batch.
  232. GLuint orClipCodes;
  233. // Pointer to the next message offset in the batching command buffer.
  234. // We use this offset to determine if 2 POLYARRAY's can be linked in
  235. // a DrawPolyArray command.
  236. ULONG nextMsgOffset;
  237. // Linear pointer to this thread's TEB POLYARRAY, kept here
  238. // so the current POLYARRAY pointer can be retrieved from the
  239. // TEB with a single instruction
  240. struct _POLYARRAY *paTeb;
  241. // This is used to form a linked list of POLYARRAY data to be
  242. // processed in the DrawPolyArray command.
  243. struct _POLYARRAY *paNext;
  244. // Number of vertices in this primitive.
  245. GLint nIndices;
  246. // Index map array defining vertex drawing order. If NULL, the
  247. // vertex order starts from pd0 through (pdNextVertex-1).
  248. GLubyte *aIndices;
  249. // Fast pointer access to the shared command message buffer.
  250. PVOID pMsgBatchInfo;
  251. // MCD Driver-private texture handle, or key
  252. DWORD textureKey;
  253. // And result of all vertex clipCode's in this batch.
  254. GLuint andClipCodes;
  255. // Currently unused but space is reserved in the TEB for it
  256. #ifdef GL_WIN_phong_shading
  257. // anankan: Using it to store a ptr to the Phong data store.
  258. __GLphongMaterialData *phong;
  259. #else
  260. ULONG ulUnused[1];
  261. #endif //GL_WIN_phong_shading
  262. POLYDATA *pdLastEvalColor;
  263. POLYDATA *pdLastEvalNormal;
  264. POLYDATA *pdLastEvalTexture;
  265. } POLYARRAY;
  266. // Special values for POLYARRAY members
  267. // Initial value for aIndices
  268. #define PA_aIndices_INITIAL_VALUE ((GLubyte *) -1)
  269. // Reset value for nextMsgOffset
  270. #define PA_nextMsgOffset_RESET_VALUE ((ULONG) -1)
  271. /*
  272. ** Edge tag. When POLYDATA_EDGEFLAG_BOUNDARY is set, this vertex and the next
  273. ** form a boundary edge on the primitive (polygon, tstrip, tfan, qstrip).
  274. */
  275. #define POLYDATA_EDGEFLAG_BOUNDARY 0x00000001 // must be 1, same as
  276. // __GL_HAS_EDGEFLAG_BOUNDARY
  277. #define POLYDATA_EDGEFLAG_VALID 0x00000002
  278. #define POLYDATA_COLOR_VALID 0x00000004
  279. #define POLYDATA_NORMAL_VALID 0x00000008
  280. #define POLYDATA_TEXTURE_VALID 0x00000010
  281. #define POLYDATA_VERTEX2 0x00000020 // same as POLYARRAY_
  282. #define POLYDATA_VERTEX3 0x00000040 // same as POLYARRAY_
  283. #define POLYDATA_VERTEX4 0x00000080 // same as POLYARRAY_
  284. /* flags for evaluators */
  285. #define POLYDATA_EVALCOORD 0x00000100 // same as POLYARRAY_
  286. #define POLYDATA_EVAL_TEXCOORD 0x00000200 // same as POLYARRAY_
  287. #define POLYDATA_EVAL_NORMAL 0x00000400 // same as POLYARRAY_
  288. #define POLYDATA_EVAL_COLOR 0x00000800 // same as POLYARRAY_
  289. #define POLYDATA_DLIST_COLOR_4 0x00002000 // client side dlist flag
  290. #define POLYDATA_FOG_VALID 0x00004000 // same as __GL_HAS_FOG
  291. // 0x00008000 // reserved
  292. #define POLYDATA_DLIST_TEXTURE1 0x00100000 // client side dlist flag
  293. #define POLYDATA_DLIST_TEXTURE2 0x00200000 // client side dlist flag
  294. #define POLYDATA_DLIST_TEXTURE3 0x00400000 // client side dlist flag
  295. #define POLYDATA_DLIST_TEXTURE4 0x00800000 // client side dlist flag
  296. #define POLYDATA_MATERIAL_FRONT 0x10000000 // same as POLYARRAY_
  297. #define POLYDATA_MATERIAL_BACK 0x20000000 // same as POLYARRAY_
  298. //
  299. // This flag is valid when POLYARRAY_HAS_CULLED_VERTEX is set only.
  300. // We have to process vertex when this flag set
  301. //
  302. #ifdef GL_EXT_cull_vertex
  303. #define POLYDATA_VERTEX_USED 0x01000000
  304. #endif //GL_EXT_cull_vertex
  305. #define POLYARRAY_IN_BEGIN 0x00000001
  306. #define POLYARRAY_EYE_PROCESSED 0x00000002
  307. #define POLYARRAY_OTHER_COLOR 0x00000004
  308. #define POLYARRAY_PARTIAL_BEGIN 0x00000008
  309. #define POLYARRAY_PARTIAL_END 0x00000010
  310. #define POLYARRAY_VERTEX2 0x00000020 // same as POLYDATA_
  311. #define POLYARRAY_VERTEX3 0x00000040 // same as POLYDATA_
  312. #define POLYARRAY_VERTEX4 0x00000080 // same as POLYDATA_
  313. /* Recycling these flags for evaluators */
  314. #define POLYARRAY_EVALCOORD 0x00000100 // same as POLYDATA_
  315. #define POLYARRAY_EVAL_TEXCOORD 0x00000200 // same as POLYDATA_
  316. #define POLYARRAY_EVAL_NORMAL 0x00000400 // same as POLYDATA_
  317. #define POLYARRAY_EVAL_COLOR 0x00000800 // same as POLYDATA_
  318. #define POLYARRAY_REMOVE_PRIMITIVE 0x00001000
  319. //
  320. // This flag is set when one of vertices has been culled by dot product
  321. // between normal at the vertex and eye direction
  322. //
  323. #ifdef GL_EXT_cull_vertex
  324. #define POLYARRAY_HAS_CULLED_VERTEX 0x02000000
  325. #endif //GL_EXT_cull_vertex
  326. #ifdef GL_WIN_phong_shading
  327. #define POLYARRAY_PHONG_DATA_VALID 0x00002000
  328. #endif //GL_WIN_phong_shading
  329. #define POLYARRAY_RESET_STIPPLE 0x00004000
  330. #define POLYARRAY_RENDER_PRIMITIVE 0x00008000
  331. #define POLYARRAY_SAME_POLYDATA_TYPE 0x00010000
  332. #define POLYARRAY_RASTERPOS 0x00020000
  333. #define POLYARRAY_SAME_COLOR_DATA 0x00040000
  334. #define POLYARRAY_TEXTURE1 0x00100000 // same as POLYDATA_DLIST_
  335. #define POLYARRAY_TEXTURE2 0x00200000 // same as POLYDATA_DLIST_
  336. #define POLYARRAY_TEXTURE3 0x00400000 // same as POLYDATA_DLIST_
  337. #define POLYARRAY_TEXTURE4 0x00800000 // same as POLYDATA_DLIST_
  338. #define POLYARRAY_MATERIAL_FRONT 0x10000000 // same as POLYDATA_
  339. #define POLYARRAY_MATERIAL_BACK 0x20000000 // same as POLYDATA_
  340. #define POLYARRAY_CLAMP_COLOR 0x80000000 // must be 0x80000000
  341. /************************************************************************/
  342. GLuint FASTCALL PAClipCheckFrustum(__GLcontext *gc, POLYARRAY *pa,
  343. POLYDATA *pdLast);
  344. GLuint FASTCALL PAClipCheckFrustum2D(__GLcontext *gc, POLYARRAY *pa,
  345. POLYDATA *pdLast);
  346. GLuint FASTCALL PAClipCheckAll(__GLcontext *gc, POLYARRAY *pa,
  347. POLYDATA *pdLast);
  348. typedef void (FASTCALL *PFN_POLYARRAYCALCCOLORSKIP)
  349. (__GLcontext *, POLYARRAY *, GLint);
  350. typedef void (FASTCALL *PFN_POLYARRAYCALCCOLOR)
  351. (__GLcontext *, GLint, POLYARRAY *, POLYDATA *, POLYDATA *);
  352. typedef void (FASTCALL *PFN_POLYARRAYAPPLYCHEAPFOG)
  353. (__GLcontext *gc, POLYARRAY *pa);
  354. void FASTCALL PolyArrayFillIndex0(__GLcontext *gc, POLYARRAY *pa, GLint face);
  355. void FASTCALL PolyArrayFillColor0(__GLcontext *gc, POLYARRAY *pa, GLint face);
  356. #ifdef GL_WIN_phong_shading
  357. void FASTCALL PolyArrayPhongPropagateColorNormal(__GLcontext *gc,
  358. POLYARRAY *pa);
  359. #endif //GL_WIN_phong_shading
  360. void FASTCALL PolyArrayCalcRGBColor(__GLcontext *gc, GLint face,
  361. POLYARRAY *pa, POLYDATA *pd1, POLYDATA *pd2);
  362. void FASTCALL PolyArrayFastCalcRGBColor(__GLcontext *gc, GLint face,
  363. POLYARRAY *pa, POLYDATA *pd1, POLYDATA *pd2);
  364. void FASTCALL PolyArrayZippyCalcRGBColor(__GLcontext *gc, GLint face,
  365. POLYARRAY *pa, POLYDATA *pd1, POLYDATA *pd2);
  366. void FASTCALL PolyArrayCalcCIColor(__GLcontext *gc, GLint face,
  367. POLYARRAY *pa, POLYDATA *pd1, POLYDATA *pd2);
  368. void FASTCALL PolyArrayFastCalcCIColor(__GLcontext *gc, GLint face,
  369. POLYARRAY *pa, POLYDATA *pd1, POLYDATA *pd2);
  370. void FASTCALL PolyArrayCheapFogRGBColor(__GLcontext *gc, POLYARRAY *pa);
  371. void FASTCALL PolyArrayCheapFogCIColor(__GLcontext *gc, POLYARRAY *pa);
  372. void FASTCALL PolyArrayFlushPartialPrimitive(void);
  373. __GLmatChange * FASTCALL PAMatAlloc(void);
  374. void FASTCALL FreePolyMaterial(void);
  375. GLboolean FASTCALL PolyArrayAllocBuffer(__GLcontext *gc, GLuint nVertices);
  376. GLvoid FASTCALL PolyArrayFreeBuffer(__GLcontext *gc);
  377. GLvoid FASTCALL PolyArrayResetBuffer(__GLcontext *gc);
  378. GLvoid FASTCALL PolyArrayRestoreColorPointer(POLYARRAY *pa);
  379. #endif /* __PARRAY_H__ */