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.

471 lines
15 KiB

  1. #ifndef __glbuffers_h_
  2. #define __glbuffers_h_
  3. /*
  4. ** Copyright 1991, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. */
  19. #include "render.h"
  20. #include "parray.h"
  21. #include "procs.h"
  22. typedef struct __GLbufferMachineRec {
  23. /*
  24. ** GL_TRUE if store procs need to call gc->front->store and
  25. ** gc->back->store in order to store one fragment (only TRUE if
  26. ** drawBuffer is GL_FRONT_AND_BACK). This is needed because many
  27. ** frame buffers can draw to both front and back under some conditions
  28. ** (like when not blending), but not under other conditions.
  29. */
  30. GLboolean doubleStore;
  31. } __GLbufferMachine;
  32. /************************************************************************/
  33. /*
  34. ** Generic buffer description. This description is used for software
  35. ** and hardware buffers of all kinds.
  36. */
  37. struct __GLbufferRec {
  38. /*
  39. ** Which context is using this buffer.
  40. */
  41. __GLcontext *gc;
  42. /*
  43. ** Dimensions of the buffer.
  44. */
  45. GLint width, height, depth;
  46. /*
  47. ** Base of framebuffer.
  48. */
  49. void* base;
  50. /*
  51. ** Number of bytes consumed by the framebuffer.
  52. */
  53. GLuint size;
  54. /*
  55. ** Size of each element in the framebuffer.
  56. */
  57. GLuint elementSize;
  58. /*
  59. ** If this buffer is part of a larger (say full screen) buffer
  60. ** then this is the size of that larger buffer. Otherwise it is
  61. ** just a copy of width.
  62. */
  63. GLint outerWidth;
  64. /*
  65. ** If this buffer is part of a larger (say full screen) buffer
  66. ** then these are the location of this buffer in the larger
  67. ** buffer.
  68. */
  69. GLint xOrigin, yOrigin;
  70. /*
  71. ** Flags.
  72. */
  73. GLuint flags;
  74. };
  75. /*
  76. ** Generic address macro for a buffer. Coded to assume that
  77. ** the buffer is not part of a larger buffer.
  78. ** The input coordinates x,y are biased by the x & y viewport
  79. ** adjusts in gc->transform, and thus they need to be de-adjusted
  80. ** here.
  81. */
  82. #define __GL_FB_ADDRESS(fb,cast,x,y) \
  83. ((cast (fb)->buf.base) \
  84. + ((y) - (fb)->buf.gc->constants.viewportYAdjust) \
  85. * (fb)->buf.outerWidth \
  86. + (x) - (fb)->buf.gc->constants.viewportXAdjust)
  87. extern void __glResizeBuffer(__GLGENbuffers *buffers, __GLbuffer *buf,
  88. GLint w, GLint h);
  89. extern void FASTCALL __glInitGenericCB(__GLcontext *gc, __GLcolorBuffer *cfb);
  90. /************************************************************************/
  91. struct __GLalphaBufferRec {
  92. __GLbuffer buf;
  93. __GLfloat alphaScale;
  94. void (FASTCALL *store)
  95. (__GLalphaBuffer *afb, GLint x, GLint y, const __GLcolor *color);
  96. void (FASTCALL *storeSpan) (__GLalphaBuffer *afb);
  97. void (FASTCALL *storeSpan2)
  98. (__GLalphaBuffer *afb, GLint x, GLint y, GLint w, __GLcolor *colors );
  99. void (FASTCALL *fetch)
  100. (__GLalphaBuffer *afb, GLint x, GLint y, __GLcolor *result);
  101. void (FASTCALL *readSpan)
  102. (__GLalphaBuffer *afb, GLint x, GLint y, GLint w, __GLcolor *results);
  103. void (FASTCALL *clear)(__GLalphaBuffer *afb);
  104. };
  105. /************************************************************************/
  106. struct __GLcolorBufferRec {
  107. __GLbuffer buf;
  108. __GLalphaBuffer alphaBuf;
  109. GLint redMax;
  110. GLint greenMax;
  111. GLint blueMax;
  112. GLint alphaMax; // XXX not used, just here for consistency with rgb
  113. /*
  114. ** Color component scale factors. Given a component value between
  115. ** zero and one, this scales the component into a zero-N value
  116. ** which is suitable for usage in the color buffer. Note that these
  117. ** values are not necessarily the same as the max values above,
  118. ** which define precise bit ranges for the buffer. These values
  119. ** are never zero, for instance.
  120. **/
  121. __GLfloat redScale;
  122. __GLfloat greenScale;
  123. __GLfloat blueScale;
  124. /* Integer versions of above */
  125. GLint iRedScale;
  126. GLint iGreenScale;
  127. GLint iBlueScale;
  128. /* Used primarily by pixmap code */
  129. GLint redShift;
  130. GLint greenShift;
  131. GLint blueShift;
  132. GLint alphaShift;
  133. #ifdef NT
  134. GLuint allShifts;
  135. #endif
  136. /*
  137. ** Alpha is treated a little bit differently. alphaScale and
  138. ** iAlphaScale are used to define a range of alpha values that are
  139. ** generated during various rendering steps. These values will then
  140. ** be used as indices into a lookup table to see if the alpha test
  141. ** passes or not. Because of this, the number should be fairly large
  142. ** (e.g., one is not good enough).
  143. */
  144. __GLfloat alphaScale;
  145. GLint iAlphaScale;
  146. __GLfloat oneOverRedScale;
  147. __GLfloat oneOverGreenScale;
  148. __GLfloat oneOverBlueScale;
  149. __GLfloat oneOverAlphaScale;
  150. /*
  151. ** Color mask state for the buffer. When writemasking is enabled
  152. ** the source and dest mask will contain depth depedent masking.
  153. */
  154. GLuint sourceMask, destMask;
  155. /*
  156. ** This function updates the internal procedure pointers based
  157. ** on a state change in the context.
  158. */
  159. void (FASTCALL *pick)(__GLcontext *gc, __GLcolorBuffer *cfb);
  160. /*
  161. ** When the buffer needs resizing this procedure should be called.
  162. */
  163. void (*resize)(__GLGENbuffers *buffers, __GLcolorBuffer *cfb,
  164. GLint w, GLint h);
  165. /*
  166. ** Store a fragment into the buffer. For color buffers, the
  167. ** procedure will optionally dither, writemask, blend and logic op
  168. ** the fragment before final storage.
  169. */
  170. void (FASTCALL *store)(__GLcolorBuffer *cfb, const __GLfragment *frag);
  171. /*
  172. ** Fetch a color from the buffer. This returns the r, g, b and a
  173. ** values for an RGB buffer. For an index buffer the "r" value
  174. ** returned is the index.
  175. */
  176. void (*fetch)(__GLcolorBuffer *cfb, GLint x, GLint y,
  177. __GLcolor *result);
  178. /*
  179. ** Similar to fetch, except that the data is always read from
  180. ** the current read buffer, not from the current draw buffer.
  181. */
  182. void (*readColor)(__GLcolorBuffer *cfb, GLint x, GLint y,
  183. __GLcolor *result);
  184. void (*readSpan)(__GLcolorBuffer *cfb, GLint x, GLint y,
  185. __GLcolor *results, GLint w);
  186. /*
  187. ** Return a span of data from the accumulation buffer into the
  188. ** color buffer(s), multiplying by "scale" before storage.
  189. */
  190. void (*returnSpan)(__GLcolorBuffer *cfb, GLint x, GLint y,
  191. const __GLaccumCell *acbuf, __GLfloat scale, GLint w);
  192. /*
  193. ** Store a span (line) of colors into the color buffer. A minimal
  194. ** implementation need only copy the values directly into
  195. ** the framebuffer, assuming that the PickSpanProcs is providing
  196. ** software implementations of all of the modes.
  197. */
  198. __GLspanFunc storeSpan;
  199. __GLstippledSpanFunc storeStippledSpan;
  200. __GLspanFunc storeLine;
  201. __GLstippledSpanFunc storeStippledLine;
  202. /*
  203. ** Read a span (line) of colors from the color buffer. The returned
  204. ** format is in the same format used for storage.
  205. */
  206. __GLspanFunc fetchSpan;
  207. __GLstippledSpanFunc fetchStippledSpan;
  208. __GLspanFunc fetchLine;
  209. __GLstippledSpanFunc fetchStippledLine;
  210. /*
  211. ** Clear the scissor area of the color buffer, clipped to
  212. ** the window size. Apply dithering if enabled.
  213. */
  214. void (FASTCALL *clear)(__GLcolorBuffer *cfb);
  215. /*
  216. ** Pointer to bitmap information.
  217. */
  218. struct __GLGENbitmapRec *bitmap;
  219. };
  220. /* generic span read routine */
  221. extern GLboolean __glReadSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  222. __GLcolor *results, GLint w);
  223. /* generic accum return span routine */
  224. extern void __glReturnSpan(__GLcolorBuffer *cfb, GLint x, GLint y,
  225. const __GLaccumCell *ac, __GLfloat scale,
  226. GLint w);
  227. /* generic span fetch routine */
  228. extern GLboolean FASTCALL __glFetchSpan(__GLcontext *gc);
  229. /************************************************************************/
  230. struct __GLdepthBufferRec {
  231. __GLbuffer buf;
  232. GLuint writeMask;
  233. /*
  234. ** Scale factor used to convert users ZValues (0.0 to 1.0, inclusive)
  235. ** into this depth buffers range.
  236. */
  237. GLuint scale;
  238. /*
  239. ** This function updates the internal procedure pointers based
  240. ** on a state change in the context.
  241. */
  242. void (FASTCALL *pick)(__GLcontext *gc, __GLdepthBuffer *dfb, GLint depthIndex );
  243. /*
  244. ** Attempt to update the depth buffer using z. If the depth function
  245. ** passes then the depth buffer is updated and True is returned,
  246. ** otherwise False is returned. The caller is responsible for
  247. ** updating the stencil buffer.
  248. */
  249. GLboolean (*store)(__GLdepthBuffer *dfb, GLint x, GLint y, __GLzValue z);
  250. /*
  251. ** Clear the scissor area of the buffer clipped to the window
  252. ** area. No other modes apply.
  253. */
  254. void (FASTCALL *clear)(__GLdepthBuffer *dfb);
  255. /*
  256. ** Direct access routines used by ReadPixels(), WritePixels(),
  257. ** CopyPixels().
  258. */
  259. GLboolean (*store2)(__GLdepthBuffer *dfb, GLint x, GLint y, __GLzValue z);
  260. __GLzValue (FASTCALL *fetch)(__GLdepthBuffer *dfb, GLint x, GLint y);
  261. /*
  262. ** When using MCD, depth values are passed to the MCD driver via a
  263. ** 32-bit depth scanline buffer. The normal store proc, for 16-bit
  264. ** MCD depth buffers, will translate an incoming 16-bit depth value
  265. ** into a 32-bit value before copying it into the scanline buffer.
  266. **
  267. ** However, some code paths (such as the generic MCD line code)
  268. ** already do all computations in 32-bit no matter what the MCD
  269. ** depth buffer size. These code paths need a proc to write their
  270. ** values untranslated.
  271. **
  272. ** The storeRaw proc will store the incoming z value without any
  273. ** translation.
  274. */
  275. GLboolean (*storeRaw)(__GLdepthBuffer *dfb, GLint x, GLint y, __GLzValue z);
  276. };
  277. #define __GL_DEPTH_ADDR(a,b,c,d) __GL_FB_ADDRESS(a,b,c,d)
  278. /************************************************************************/
  279. struct __GLstencilBufferRec {
  280. __GLbuffer buf;
  281. /*
  282. ** Stencil test lookup table. The stencil buffer value is masked
  283. ** against the stencil mask and then used as an index into this
  284. ** table which contains either GL_TRUE or GL_FALSE for the
  285. ** index.
  286. */
  287. GLboolean *testFuncTable;
  288. /*
  289. ** Stencil op tables. These tables contain the new stencil buffer
  290. ** value given the old stencil buffer value as an index.
  291. */
  292. __GLstencilCell *failOpTable;
  293. __GLstencilCell *depthFailOpTable;
  294. __GLstencilCell *depthPassOpTable;
  295. /*
  296. ** This function updates the internal procedure pointers based
  297. ** on a state change in the context.
  298. */
  299. void (FASTCALL *pick)(__GLcontext *gc, __GLstencilBuffer *sfb);
  300. /*
  301. ** Store a fragment into the buffer.
  302. */
  303. void (*store)(__GLstencilBuffer *sfb, GLint x, GLint y,
  304. GLint value);
  305. /*
  306. ** Fetch a value.
  307. */
  308. GLint (FASTCALL *fetch)(__GLstencilBuffer *sfb, GLint x, GLint y);
  309. /*
  310. ** Return GL_TRUE if the stencil test passes.
  311. */
  312. GLboolean (FASTCALL *testFunc)(__GLstencilBuffer *sfb, GLint x, GLint y);
  313. /*
  314. ** Apply the stencil ops to this position.
  315. */
  316. void (FASTCALL *failOp)(__GLstencilBuffer *sfb, GLint x, GLint y);
  317. void (FASTCALL *passDepthFailOp)(__GLstencilBuffer *sfb, GLint x, GLint y);
  318. void (FASTCALL *depthPassOp)(__GLstencilBuffer *sfb, GLint x, GLint y);
  319. /*
  320. ** Clear the scissor area of the buffer clipped to the window
  321. ** area. No other modes apply.
  322. */
  323. void (FASTCALL *clear)(__GLstencilBuffer *sfb);
  324. };
  325. #define __GL_STENCIL_ADDR(a,b,c,d) __GL_FB_ADDRESS(a,b,c,d)
  326. /************************************************************************/
  327. struct __GLaccumBufferRec {
  328. __GLbuffer buf;
  329. /*
  330. ** Scaling factors to convert from color buffer values to accum
  331. ** buffer values.
  332. */
  333. __GLfloat redScale;
  334. __GLfloat greenScale;
  335. __GLfloat blueScale;
  336. __GLfloat alphaScale;
  337. __GLfloat oneOverRedScale;
  338. __GLfloat oneOverGreenScale;
  339. __GLfloat oneOverBlueScale;
  340. __GLfloat oneOverAlphaScale;
  341. __GLuicolor shift, mask, sign; // Cache of commonly used values
  342. __GLcolor *colors; // Temporary scanline buffer ptr
  343. /*
  344. ** This function updates the internal procedure pointers based
  345. ** on a state change in the context.
  346. */
  347. void (FASTCALL *pick)(__GLcontext *gc, __GLaccumBuffer *afb);
  348. /*
  349. ** Clear a rectangular region in the buffer. The scissor area is
  350. ** cleared.
  351. */
  352. void (FASTCALL *clear)(__GLaccumBuffer *afb);
  353. /*
  354. ** Accumulate data into the accum buffer.
  355. */
  356. void (*accumulate)(__GLaccumBuffer *afb, __GLfloat value);
  357. /*
  358. ** Load data into the accum buffer.
  359. */
  360. void (*load)(__GLaccumBuffer *afb, __GLfloat value);
  361. /*
  362. ** Return data from the accum buffer to the current framebuffer.
  363. */
  364. void (*ret)(__GLaccumBuffer *afb, __GLfloat value);
  365. /*
  366. ** Multiply the accum buffer by the value.
  367. */
  368. void (*mult)(__GLaccumBuffer *afb, __GLfloat value);
  369. /*
  370. ** Add the value to the accum buffer.
  371. */
  372. void (*add)(__GLaccumBuffer *afb, __GLfloat value);
  373. };
  374. #define __GL_ACCUM_ADDRESS(a,b,c,d) __GL_FB_ADDRESS(a,b,c,d)
  375. /************************************************************************/
  376. extern void FASTCALL __glInitAccum64(__GLcontext *gc, __GLaccumBuffer *afb);
  377. extern void FASTCALL __glFreeAccum64(__GLcontext *gc, __GLaccumBuffer *afb);
  378. extern void FASTCALL __glInitAccum32(__GLcontext *gc, __GLaccumBuffer *afb);
  379. extern void FASTCALL __glInitCI4(__GLcontext *gc, __GLcolorBuffer *cfb);
  380. extern void FASTCALL __glInitCI8(__GLcontext *gc, __GLcolorBuffer *cfb);
  381. extern void FASTCALL __glInitCI16(__GLcontext *gc, __GLcolorBuffer *cfb);
  382. extern void FASTCALL __glInitStencil8(__GLcontext *gc, __GLstencilBuffer *sfb);
  383. extern void FASTCALL __glInitAlpha(__GLcontext *gc, __GLcolorBuffer *cfb);
  384. extern void FASTCALL __glFreeStencil8(__GLcontext *gc, __GLstencilBuffer *sfb);
  385. #ifdef NT
  386. extern void FASTCALL __glInitDepth16(__GLcontext *gc, __GLdepthBuffer *dfb);
  387. #endif
  388. extern void FASTCALL __glInitDepth32(__GLcontext *gc, __GLdepthBuffer *dfb);
  389. extern void FASTCALL __glFreeDepth32(__GLcontext *gc, __GLdepthBuffer *dfb);
  390. extern void FASTCALL __glClearBuffers(__GLcontext *gc, GLuint mask);
  391. #endif /* __glbuffers_h_ */