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.

959 lines
42 KiB

  1. #ifndef __glcontext_h_
  2. #define __glcontext_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. ** Graphics context structures.
  20. */
  21. #include "os.h"
  22. #include "attrib.h"
  23. #include "feedback.h"
  24. #include "select.h"
  25. #include "buffers.h"
  26. #include "pixel.h"
  27. #include "dlist.h"
  28. #include "xform.h"
  29. #include "render.h"
  30. #include "oleauto.h"
  31. #include "parray.h"
  32. #include "procs.h"
  33. #include "gldrv.h"
  34. #include "glarray.h"
  35. // Disable long to float conversion warning. see also gencx.h
  36. #pragma warning (disable:4244)
  37. /*
  38. ** Mode and limit information for a context. This information is
  39. ** kept around in the context so that values can be used during
  40. ** command execution, and for returning information about the
  41. ** context to the application.
  42. */
  43. struct __GLcontextModesRec {
  44. GLboolean rgbMode;
  45. GLboolean colorIndexMode;
  46. GLboolean doubleBufferMode;
  47. GLboolean stereoMode;
  48. GLboolean haveAccumBuffer;
  49. GLboolean haveDepthBuffer;
  50. GLboolean haveStencilBuffer;
  51. /* The number of bits present in various buffers */
  52. GLint accumBits;
  53. GLint *auxBits;
  54. GLint depthBits;
  55. GLint stencilBits;
  56. GLint indexBits;
  57. GLint indexFractionBits;
  58. GLint redBits, greenBits, blueBits, alphaBits;
  59. GLuint redMask, greenMask, blueMask, alphaMask;
  60. #ifdef NT
  61. GLuint allMask;
  62. GLuint rgbMask;
  63. #endif
  64. GLint maxAuxBuffers;
  65. /* False if running from inside the X server */
  66. GLboolean isDirect;
  67. /* frame buffer level */
  68. GLint level;
  69. };
  70. /*
  71. ** Various constants. Most of these will never change through the life
  72. ** of the context.
  73. */
  74. typedef struct __GLcontextConstantsRec {
  75. /* Specific size limits */
  76. GLint numberOfLights;
  77. GLint numberOfClipPlanes;
  78. GLint numberOfTextures;
  79. GLint numberOfTextureEnvs;
  80. GLint maxViewportWidth;
  81. GLint maxViewportHeight;
  82. #ifdef GL_WIN_multiple_textures
  83. /* Maximum number of current textures */
  84. GLuint numberOfCurrentTextures;
  85. GLenum texCombineNaturalClamp;
  86. #endif // GL_WIN_multiple_textures
  87. /*
  88. ** Viewport offsets: These numbers are added to the viewport center
  89. ** values to adjust the computed window coordinates into a
  90. ** numerically well behaved space (fixed point represented in a
  91. ** floating point number).
  92. */
  93. GLint viewportXAdjust;
  94. GLint viewportYAdjust;
  95. __GLfloat fviewportXAdjust;
  96. __GLfloat fviewportYAdjust;
  97. /*
  98. ** These values are computed from viewportXAdjust when the context
  99. ** is created. It is assumed that x and y are forced into the same
  100. ** fixed point range by viewportXAdjust and viewportYAdjust.
  101. **
  102. ** viewportEpsilon is computed as the smallest possible value that can
  103. ** be represented in that fixed point space.
  104. **
  105. ** viewportAlmostHalf is equal to 0.5 - viewportEpsilon.
  106. */
  107. __GLfloat viewportEpsilon;
  108. __GLfloat viewportAlmostHalf;
  109. /* Scales that bring colors values from 0.0 to 1.0 into internal range */
  110. __GLfloat redScale, blueScale, greenScale, alphaScale;
  111. /*
  112. ** Geometry of the current window.
  113. */
  114. GLint width, height;
  115. /*
  116. ** Size of the alpha lookup table for alpha testing, and conversion
  117. ** value to convert from scaled alpha to alpha to be used for lookup table.
  118. */
  119. GLint alphaTestSize;
  120. __GLfloat alphaTableConv;
  121. /*
  122. ** Random getable constants
  123. */
  124. GLint maxTextureSize;
  125. GLint maxMipMapLevel;
  126. GLint subpixelBits;
  127. GLint maxListNesting;
  128. __GLfloat pointSizeMinimum;
  129. __GLfloat pointSizeMaximum;
  130. __GLfloat pointSizeGranularity;
  131. __GLfloat lineWidthMinimum;
  132. __GLfloat lineWidthMaximum;
  133. __GLfloat lineWidthGranularity;
  134. GLint maxEvalOrder;
  135. GLint maxPixelMapTable;
  136. GLint maxAttribStackDepth;
  137. GLint maxClientAttribStackDepth;
  138. GLint maxNameStackDepth;
  139. /*
  140. ** GDI's Y is inverted. These two constants help out.
  141. */
  142. GLboolean yInverted;
  143. GLint ySign;
  144. } __GLcontextConstants;
  145. /************************************************************************/
  146. typedef enum __GLbeginModeEnum {
  147. __GL_NOT_IN_BEGIN = 0,
  148. __GL_IN_BEGIN = 1,
  149. __GL_NEED_VALIDATE = 2
  150. } __GLbeginMode;
  151. #ifdef NT_SERVER_SHARE_LISTS
  152. //
  153. // Information for tracking dlist locks so we know what to unlock during
  154. // cleanup
  155. //
  156. typedef struct _DlLockEntry
  157. {
  158. __GLdlist *dlist;
  159. } DlLockEntry;
  160. typedef struct _DlLockArray
  161. {
  162. GLsizei nAllocated;
  163. GLsizei nFilled;
  164. DlLockEntry *pdleEntries;
  165. } DlLockArray;
  166. #endif
  167. // Signature stamp for gc's. Must be non-zero.
  168. // Currently spells 'GLGC' in byte order.
  169. #define GC_SIGNATURE 0x43474c47
  170. struct __GLcontextRec {
  171. /************************************************************************/
  172. /*
  173. ** Initialization and signature flag. If this flag is set to the
  174. ** gc signature value then the gc is initialized.
  175. ** This could be a simple bit flag except that having the signature
  176. ** is convenient for identifying gc's in memory during debugging.
  177. */
  178. GLuint gcSig;
  179. /************************************************************************/
  180. /*
  181. ** Stackable state. All of the current user controllable state
  182. ** is resident here.
  183. */
  184. __GLattribute state;
  185. /************************************************************************/
  186. /*
  187. ** Unstackable State
  188. */
  189. /*
  190. ** Current glBegin mode. Legal values are 0 (not in begin mode), 1
  191. ** (in beginMode), or 2 (not in begin mode, some validation is
  192. ** needed). Because all state changing routines have to fetch this
  193. ** value, we have overloaded state validation into it. There is
  194. ** special code in the __glim_Begin (for software renderers) which
  195. ** deals with validation.
  196. */
  197. __GLbeginMode beginMode;
  198. /* Current rendering mode */
  199. GLenum renderMode;
  200. /*
  201. ** Most recent error code, or GL_NO_ERROR if no error has occurred
  202. ** since the last glGetError.
  203. */
  204. GLint error;
  205. /*
  206. ** Mode information that describes the kind of buffers and rendering
  207. ** modes that this context manages.
  208. */
  209. __GLcontextModes modes;
  210. /* Implementation dependent constants */
  211. __GLcontextConstants constants;
  212. /* Feedback and select state */
  213. __GLfeedbackMachine feedback;
  214. __GLselectMachine select;
  215. /* Display list state */
  216. __GLdlistMachine dlist;
  217. #ifdef NT
  218. /* Saved client side dispatch tables. Used by display list. */
  219. GLCLTPROCTABLE savedCltProcTable;
  220. GLEXTPROCTABLE savedExtProcTable;
  221. #endif
  222. /************************************************************************/
  223. /*
  224. ** The remaining state is used primarily by the software renderer.
  225. */
  226. /*
  227. ** Mask word for validation state to help guide the gc validation
  228. ** code. Only operations which are largely expensive are broken
  229. ** out here. See the #define's below for the values being used.
  230. */
  231. GLuint validateMask;
  232. /*
  233. ** Mask word of dirty bits. Most routines just set the GENERIC bit to
  234. ** dirty, others may set more specific bits. The list of bits is
  235. ** listed below.
  236. */
  237. GLuint dirtyMask;
  238. /* Current draw buffer, set by glDrawBuffer */
  239. __GLcolorBuffer *drawBuffer;
  240. /* Current read buffer, set by glReadBuffer */
  241. __GLcolorBuffer *readBuffer;
  242. /* Function pointers that are mode dependent */
  243. __GLprocs procs;
  244. /* Attribute stack state */
  245. __GLattributeMachine attributes;
  246. /* Client attribute stack state */
  247. __GLclientAttributeMachine clientAttributes;
  248. /* Machine structures defining software rendering "machine" state */
  249. __GLvertexMachine vertex;
  250. __GLlightMachine light;
  251. __GLtextureMachine texture;
  252. __GLevaluatorMachine eval;
  253. __GLtransformMachine transform;
  254. __GLlineMachine line;
  255. __GLpolygonMachine polygon;
  256. __GLpixelMachine pixel;
  257. __GLbufferMachine buffers;
  258. #ifdef NT
  259. __GLfloat redClampTable[4];
  260. __GLfloat greenClampTable[4];
  261. __GLfloat blueClampTable[4];
  262. __GLfloat alphaClampTable[4];
  263. __GLfloat oneOverRedVertexScale;
  264. __GLfloat oneOverGreenVertexScale;
  265. __GLfloat oneOverBlueVertexScale;
  266. __GLfloat oneOverAlphaVertexScale;
  267. __GLfloat redVertexScale;
  268. __GLfloat greenVertexScale;
  269. __GLfloat blueVertexScale;
  270. __GLfloat alphaVertexScale;
  271. GLboolean vertexToBufferIdentity;
  272. __GLfloat redVertexToBufferScale;
  273. __GLfloat blueVertexToBufferScale;
  274. __GLfloat greenVertexToBufferScale;
  275. __GLfloat alphaVertexToBufferScale;
  276. GLuint textureKey;
  277. GLubyte *alphaTestFuncTable;
  278. #endif
  279. /* Buffers */
  280. __GLcolorBuffer *front;
  281. __GLcolorBuffer *back;
  282. __GLcolorBuffer frontBuffer;
  283. __GLcolorBuffer backBuffer;
  284. __GLcolorBuffer *auxBuffer;
  285. __GLstencilBuffer stencilBuffer;
  286. __GLdepthBuffer depthBuffer;
  287. __GLaccumBuffer accumBuffer;
  288. #ifdef NT
  289. // Temporary buffers allocated by the gc. The abnormal process exit
  290. // code will release these buffers.
  291. void * apvTempBuf[6];
  292. #endif // NT
  293. #ifdef NT_SERVER_SHARE_LISTS
  294. DlLockArray dla;
  295. #endif
  296. #ifdef NT
  297. // TEB polyarray pointer for this thread. It allows fast access to the
  298. // polyarray structure in the TEB equivalent to the GLTEB_CLTPOLYARRAY
  299. // macro. This field is kept current in MakeCurrent.
  300. POLYARRAY *paTeb;
  301. // Vertex array client states
  302. __GLvertexArray vertexArray;
  303. // Saved vertex array state for execution of display-listed
  304. // vertex array calls
  305. __GLvertexArray savedVertexArray;
  306. __GLmatrix *mInv;
  307. #endif // NT
  308. };
  309. #ifdef NT
  310. // Associate the temporary buffer with the gc for abnormal process cleanup.
  311. #define GC_TEMP_BUFFER_ALLOC(gc, pv) \
  312. { \
  313. int _i; \
  314. for (_i = 0; _i < sizeof(gc->apvTempBuf)/sizeof(void *); _i++)\
  315. { \
  316. if (!gc->apvTempBuf[_i]) \
  317. { \
  318. gc->apvTempBuf[_i] = pv; \
  319. break; \
  320. } \
  321. } \
  322. ASSERTOPENGL(_i < sizeof(gc->apvTempBuf)/sizeof(void *), \
  323. "gc->apvTempBuf overflows\n"); \
  324. }
  325. // Unassociate the temporary buffer with the gc.
  326. #define GC_TEMP_BUFFER_FREE(gc, pv) \
  327. { \
  328. int _i; \
  329. for (_i = 0; _i < sizeof(gc->apvTempBuf)/sizeof(void *); _i++)\
  330. { \
  331. if (gc->apvTempBuf[_i] == pv) \
  332. { \
  333. gc->apvTempBuf[_i] = (void *) NULL; \
  334. break; \
  335. } \
  336. } \
  337. ASSERTOPENGL(_i < sizeof(gc->apvTempBuf)/sizeof(void *), \
  338. "gc->apvTempBuf entry not found\n"); \
  339. }
  340. // Cleanup any temporary buffer allocated in gc in abnormal process exit.
  341. #define GC_TEMP_BUFFER_EXIT_CLEANUP(gc) \
  342. { \
  343. int _i; \
  344. for (_i = 0; _i < sizeof(gc->apvTempBuf)/sizeof(void *); _i++)\
  345. { \
  346. if (gc->apvTempBuf[_i]) \
  347. { \
  348. WARNING("Abnormal process exit: free allocated buffers\n");\
  349. gcTempFree(gc, gc->apvTempBuf[_i]); \
  350. gc->apvTempBuf[_i] = (void *) NULL; \
  351. } \
  352. } \
  353. }
  354. #endif // NT
  355. /*
  356. ** Bit values for the validateMask word
  357. */
  358. #define __GL_VALIDATE_ALPHA_FUNC 0x00000001
  359. #define __GL_VALIDATE_STENCIL_FUNC 0x00000002
  360. #define __GL_VALIDATE_STENCIL_OP 0x00000004
  361. /*
  362. ** Bit values for dirtyMask word.
  363. **
  364. ** These are all for delayed validation. There are a few things that do
  365. ** not trigger delayed validation. They are:
  366. **
  367. ** Matrix operations -- matrices are validated immediately.
  368. ** Material changes -- they also validate immediately.
  369. ** Color Material change -- validated immediately.
  370. ** Color Material enable -- validated immediately.
  371. ** Pixel Map changes -- no validation.
  372. */
  373. /*
  374. ** All things not listed elsewhere.
  375. */
  376. #define __GL_DIRTY_GENERIC 0x00000001
  377. /*
  378. ** Line stipple, line stipple enable, line width, line smooth enable,
  379. ** line smooth hint.
  380. */
  381. #define __GL_DIRTY_LINE 0x00000002
  382. /*
  383. ** Polygon stipple, polygon stipple enable, polygon smooth enable, face
  384. ** culling, front face orientation, polygon mode, point smooth hint.
  385. */
  386. #define __GL_DIRTY_POLYGON 0x00000004
  387. /*
  388. ** Point smooth, point smooth hint, point width.
  389. */
  390. #define __GL_DIRTY_POINT 0x00000008
  391. /*
  392. ** Pixel store, pixel zoom, pixel transfer, (pixel maps don't cause
  393. ** validation), read buffer.
  394. */
  395. #define __GL_DIRTY_PIXEL 0x00000010
  396. /*
  397. ** Light, Light Model, lighting enable, lightx enable, (color material
  398. ** validates immediately), (NOT shade model -- it is generic), (color material
  399. ** enable validates immediately)
  400. */
  401. #define __GL_DIRTY_LIGHTING 0x00000020
  402. /*
  403. ** Polygon stipple
  404. */
  405. #define __GL_DIRTY_POLYGON_STIPPLE 0x00000040
  406. /*
  407. ** the depth mode has changed. Need to update depth function pointers.
  408. */
  409. #define __GL_DIRTY_DEPTH 0x00000080
  410. /*
  411. ** Need to update texture and function pointers.
  412. */
  413. #define __GL_DIRTY_TEXTURE 0x00000100
  414. #define __GL_DIRTY_ALL 0x000001ff
  415. /*
  416. ** Bit values for changes to material colors
  417. **
  418. ** These values are shared with MCDMATERIAL_
  419. */
  420. #define __GL_MATERIAL_AMBIENT 0x00000001
  421. #define __GL_MATERIAL_DIFFUSE 0x00000002
  422. #define __GL_MATERIAL_SPECULAR 0x00000004
  423. #define __GL_MATERIAL_EMISSIVE 0x00000008
  424. #define __GL_MATERIAL_SHININESS 0x00000010
  425. #define __GL_MATERIAL_COLORINDEXES 0x00000020
  426. #define __GL_MATERIAL_ALL 0x0000003f
  427. #define __GL_DELAY_VALIDATE(gc) \
  428. ASSERTOPENGL((gc)->beginMode != __GL_IN_BEGIN, "Dirty state in begin\n"); \
  429. (gc)->beginMode = __GL_NEED_VALIDATE; \
  430. (gc)->dirtyMask |= __GL_DIRTY_GENERIC
  431. #define __GL_DELAY_VALIDATE_MASK(gc, mask) \
  432. ASSERTOPENGL((gc)->beginMode != __GL_IN_BEGIN, "Dirty state in begin\n"); \
  433. (gc)->beginMode = __GL_NEED_VALIDATE; \
  434. (gc)->dirtyMask |= (mask)
  435. #define __GL_CLAMP_CI(target, gc, r) \
  436. { \
  437. if ((r) > (GLfloat)(gc)->frontBuffer.redMax) { \
  438. GLfloat fraction; \
  439. GLint integer; \
  440. \
  441. integer = (GLint) (r); \
  442. fraction = (r) - (GLfloat) integer; \
  443. integer = integer & (GLint)(gc)->frontBuffer.redMax; \
  444. target = (GLfloat) integer + fraction; \
  445. } else if ((r) < 0) { \
  446. GLfloat fraction; \
  447. GLint integer; \
  448. \
  449. integer = (GLint) __GL_FLOORF(r); \
  450. fraction = (r) - (GLfloat) integer; \
  451. integer = integer & (GLint)(gc)->frontBuffer.redMax; \
  452. target = (GLfloat) integer + fraction; \
  453. } else { \
  454. target = r; \
  455. }\
  456. }
  457. #define __GL_CHECK_CLAMP_CI(target, gc, flags, r) \
  458. { \
  459. if (((r) > (GLfloat)(gc)->frontBuffer.redMax) || \
  460. ((r) < 0)) \
  461. flags |= POLYARRAY_CLAMP_COLOR; \
  462. (target) = (r); \
  463. }
  464. #define __GL_COLOR_CLAMP_INDEX_R(value) \
  465. (((ULONG)((CASTINT(value) & 0x80000000)) >> 30) | \
  466. ((ULONG)(((CASTINT(gc->redVertexScale) - CASTINT(value)) & 0x80000000)) >> 31)) \
  467. #define __GL_COLOR_CLAMP_INDEX_G(value) \
  468. (((ULONG)((CASTINT(value) & 0x80000000)) >> 30) | \
  469. ((ULONG)(((CASTINT(gc->greenVertexScale) - CASTINT(value)) & 0x80000000)) >> 31)) \
  470. #define __GL_COLOR_CLAMP_INDEX_B(value) \
  471. (((ULONG)((CASTINT(value) & 0x80000000)) >> 30) | \
  472. ((ULONG)(((CASTINT(gc->blueVertexScale) - CASTINT(value)) & 0x80000000)) >> 31)) \
  473. #define __GL_COLOR_CLAMP_INDEX_A(value) \
  474. (((ULONG)((CASTINT(value) & 0x80000000)) >> 30) | \
  475. ((ULONG)(((CASTINT(gc->alphaVertexScale) - CASTINT(value)) & 0x80000000)) >> 31)) \
  476. #define __GL_SCALE_R(target, gc, r) \
  477. (target) = (r) * (gc)->redVertexScale
  478. #define __GL_SCALE_G(target, gc, g) \
  479. (target) = (g) * (gc)->greenVertexScale
  480. #define __GL_SCALE_B(target, gc, b) \
  481. (target) = (b) * (gc)->blueVertexScale
  482. #define __GL_SCALE_A(target, gc, a) \
  483. (target) = (a) * (gc)->alphaVertexScale
  484. #define __GL_COLOR_CHECK_CLAMP_R(value, flags) \
  485. (flags) |= \
  486. ((ULONG)(CASTINT(value) & 0x80000000) | \
  487. (ULONG)((CASTINT(gc->redVertexScale) - CASTINT(value)) & 0x80000000))
  488. #define __GL_COLOR_CHECK_CLAMP_G(value, flags) \
  489. (flags) |= \
  490. ((ULONG)(CASTINT(value) & 0x80000000) | \
  491. (ULONG)((CASTINT(gc->greenVertexScale) - CASTINT(value)) & 0x80000000))
  492. #define __GL_COLOR_CHECK_CLAMP_B(value, flags) \
  493. (flags) |= \
  494. ((ULONG)(CASTINT(value) & 0x80000000) | \
  495. (ULONG)((CASTINT(gc->blueVertexScale) - CASTINT(value)) & 0x80000000))
  496. #define __GL_COLOR_CHECK_CLAMP_A(value, flags) \
  497. (flags) |= \
  498. ((ULONG)(CASTINT(value) & 0x80000000) | \
  499. (ULONG)((CASTINT(gc->alphaVertexScale) - CASTINT(value)) & 0x80000000))
  500. #define __GL_COLOR_CHECK_CLAMP_RGB(gc, r, g, b) \
  501. ((CASTINT(r) | ((ULONG)(CASTINT(gc->redVertexScale) - CASTINT(r))) | \
  502. CASTINT(g) | ((ULONG)(CASTINT(gc->greenVertexScale) - CASTINT(g))) | \
  503. CASTINT(b) | ((ULONG)(CASTINT(gc->blueVertexScale) - CASTINT(b)))) & \
  504. 0x80000000)
  505. #define __GL_SCALE_AND_CHECK_CLAMP_R(target, gc, flags, r) \
  506. { \
  507. __GL_SCALE_R(target, gc, r); \
  508. __GL_COLOR_CHECK_CLAMP_R(target, flags); \
  509. }
  510. #define __GL_SCALE_AND_CHECK_CLAMP_G(target, gc, flags, g) \
  511. { \
  512. __GL_SCALE_G(target, gc, g); \
  513. __GL_COLOR_CHECK_CLAMP_G(target, flags); \
  514. }
  515. #define __GL_SCALE_AND_CHECK_CLAMP_B(target, gc, flags, b) \
  516. { \
  517. __GL_SCALE_B(target, gc, b); \
  518. __GL_COLOR_CHECK_CLAMP_B(target, flags); \
  519. }
  520. #define __GL_SCALE_AND_CHECK_CLAMP_A(target, gc, flags, a) \
  521. { \
  522. __GL_SCALE_A(target, gc, a); \
  523. __GL_COLOR_CHECK_CLAMP_A(target, flags); \
  524. }
  525. #define __GL_CLAMP_R(target, gc, r) \
  526. { \
  527. (gc)->redClampTable[0] = (r); \
  528. target = (gc)->redClampTable[__GL_COLOR_CLAMP_INDEX_R((gc)->redClampTable[0])]; \
  529. }
  530. #define __GL_CLAMP_G(target, gc, g) \
  531. { \
  532. (gc)->greenClampTable[0] = (g); \
  533. target = (gc)->greenClampTable[__GL_COLOR_CLAMP_INDEX_G((gc)->greenClampTable[0])]; \
  534. }
  535. #define __GL_CLAMP_B(target, gc, b) \
  536. { \
  537. (gc)->blueClampTable[0] = (b); \
  538. target = (gc)->blueClampTable[__GL_COLOR_CLAMP_INDEX_B((gc)->blueClampTable[0])]; \
  539. }
  540. #define __GL_CLAMP_A(target, gc, a) \
  541. { \
  542. (gc)->alphaClampTable[0] = (a); \
  543. target = (gc)->alphaClampTable[__GL_COLOR_CLAMP_INDEX_A((gc)->alphaClampTable[0])]; \
  544. }
  545. /* Aggregate clamping routines. */
  546. #ifdef _X86_
  547. #define __GL_SCALE_RGB(rOut, gOut, bOut, gc, r, g, b) \
  548. __GL_SCALE_R(rOut, gc, r); \
  549. __GL_SCALE_G(gOut, gc, g); \
  550. __GL_SCALE_B(bOut, gc, b);
  551. #define __GL_SCALE_RGBA(rOut, gOut, bOut, aOut, gc, r, g, b, a) \
  552. __GL_SCALE_R(rOut, gc, r); \
  553. __GL_SCALE_G(gOut, gc, g); \
  554. __GL_SCALE_B(bOut, gc, b); \
  555. __GL_SCALE_A(aOut, gc, a);
  556. #define __GL_CLAMP_RGB(rOut, gOut, bOut, gc, r, g, b) \
  557. __GL_CLAMP_R(rOut, gc, r); \
  558. __GL_CLAMP_G(gOut, gc, g); \
  559. __GL_CLAMP_B(bOut, gc, b);
  560. #define __GL_CLAMP_RGBA(rOut, gOut, bOut, aOut, gc, r, g, b, a) \
  561. __GL_CLAMP_R(rOut, gc, r); \
  562. __GL_CLAMP_G(gOut, gc, g); \
  563. __GL_CLAMP_B(bOut, gc, b); \
  564. __GL_CLAMP_A(aOut, gc, a);
  565. #define __GL_SCALE_AND_CHECK_CLAMP_RGB(rOut, gOut, bOut, gc, flags, r, g, b)\
  566. __GL_SCALE_AND_CHECK_CLAMP_R(rOut, gc, flags, r); \
  567. __GL_SCALE_AND_CHECK_CLAMP_G(gOut, gc, flags, g); \
  568. __GL_SCALE_AND_CHECK_CLAMP_B(bOut, gc, flags, b);
  569. #define __GL_SCALE_AND_CHECK_CLAMP_RGBA(rOut, gOut, bOut, aOut, gc, flags,\
  570. r, g, b, a) \
  571. __GL_SCALE_AND_CHECK_CLAMP_R(rOut, gc, flags, r); \
  572. __GL_SCALE_AND_CHECK_CLAMP_G(gOut, gc, flags, g); \
  573. __GL_SCALE_AND_CHECK_CLAMP_B(bOut, gc, flags, b); \
  574. __GL_SCALE_AND_CHECK_CLAMP_A(aOut, gc, flags, a);
  575. #else // NOT _X86_
  576. /* The following code is written in a "load, compute, store" style.
  577. ** It is preferable for RISC CPU's with larger numbers of registers,
  578. ** such as DEC Alpha. VC++ for Alpha does not do
  579. ** a good job expanding the __GL_CLAMP_R, __GL_CLAMP_G, __GL_CLAMP_B,
  580. ** __GL_CLAMP_A macros, due to all the pointer indirections and the
  581. ** basic blocks defined by {} brackets.
  582. */
  583. #define __GL_SCALE_RGB(rOut, gOut, bOut, gc, r, g, b) \
  584. { \
  585. __GLfloat rScale, gScale, bScale; \
  586. __GLfloat rs, gs, bs; \
  587. \
  588. rScale = (gc)->redVertexScale; \
  589. gScale = (gc)->greenVertexScale; \
  590. bScale = (gc)->blueVertexScale; \
  591. \
  592. rs = (r) * rScale; \
  593. gs = (g) * gScale; \
  594. bs = (b) * bScale; \
  595. \
  596. rOut = rs; \
  597. gOut = gs; \
  598. bOut = bs; \
  599. }
  600. #define __GL_SCALE_RGBA(rOut, gOut, bOut, aOut, gc, r, g, b, a) \
  601. { \
  602. __GLfloat rScale, gScale, bScale, aScale; \
  603. __GLfloat rs, gs, bs, as; \
  604. \
  605. rScale = (gc)->redVertexScale; \
  606. gScale = (gc)->greenVertexScale; \
  607. bScale = (gc)->blueVertexScale; \
  608. aScale = (gc)->alphaVertexScale; \
  609. \
  610. rs = (r) * rScale; \
  611. gs = (g) * gScale; \
  612. bs = (b) * bScale; \
  613. as = (a) * aScale; \
  614. \
  615. rOut = rs; \
  616. gOut = gs; \
  617. bOut = bs; \
  618. aOut = as; \
  619. }
  620. #define __GL_CLAMP_RGB(rOut, gOut, bOut, gc, r, g, b) \
  621. { \
  622. __GLfloat dst_r, dst_g, dst_b; \
  623. ULONG index_r, index_g, index_b; \
  624. LONG clamp_r, clamp_g, clamp_b; \
  625. LONG i_rScale, i_gScale, i_bScale; \
  626. ULONG sign_mask = 0x80000000; \
  627. \
  628. (gc)->redClampTable[0] = (r); \
  629. (gc)->greenClampTable[0] = (g); \
  630. (gc)->blueClampTable[0] = (b); \
  631. \
  632. i_rScale = CASTINT((gc)->redVertexScale); \
  633. i_gScale = CASTINT((gc)->greenVertexScale); \
  634. i_bScale = CASTINT((gc)->blueVertexScale); \
  635. \
  636. clamp_r = CASTINT((gc)->redClampTable[0]); \
  637. clamp_g = CASTINT((gc)->greenClampTable[0]); \
  638. clamp_b = CASTINT((gc)->blueClampTable[0]); \
  639. \
  640. index_r = \
  641. (((ULONG)((clamp_r & sign_mask)) >> 30) | \
  642. ((ULONG)(((i_rScale - clamp_r) & sign_mask)) >> 31)); \
  643. \
  644. index_g = \
  645. (((ULONG)((clamp_g & sign_mask)) >> 30) | \
  646. ((ULONG)(((i_gScale - clamp_g) & sign_mask)) >> 31)); \
  647. \
  648. index_b = \
  649. (((ULONG)((clamp_b & sign_mask)) >> 30) | \
  650. ((ULONG)(((i_bScale - clamp_b) & sign_mask)) >> 31)); \
  651. \
  652. dst_r = (gc)->redClampTable[index_r]; \
  653. dst_g = (gc)->greenClampTable[index_g]; \
  654. dst_b = (gc)->blueClampTable[index_b]; \
  655. \
  656. rOut = dst_r; \
  657. gOut = dst_g; \
  658. bOut = dst_b; \
  659. }
  660. #define __GL_CLAMP_RGBA(rOut, gOut, bOut, aOut, gc, r, g, b, a) \
  661. { \
  662. __GLfloat dst_r, dst_g, dst_b, dst_a; \
  663. ULONG index_r, index_g, index_b, index_a; \
  664. LONG clamp_r, clamp_g, clamp_b, clamp_a; \
  665. LONG i_rScale, i_gScale, i_bScale, i_aScale; \
  666. ULONG sign_mask = 0x80000000; \
  667. \
  668. (gc)->redClampTable[0] = (r); \
  669. (gc)->greenClampTable[0] = (g); \
  670. (gc)->blueClampTable[0] = (b); \
  671. (gc)->alphaClampTable[0] = (a); \
  672. \
  673. i_rScale = CASTINT((gc)->redVertexScale); \
  674. i_gScale = CASTINT((gc)->greenVertexScale); \
  675. i_bScale = CASTINT((gc)->blueVertexScale); \
  676. i_aScale = CASTINT((gc)->alphaVertexScale); \
  677. \
  678. clamp_r = CASTINT((gc)->redClampTable[0]); \
  679. clamp_g = CASTINT((gc)->greenClampTable[0]); \
  680. clamp_b = CASTINT((gc)->blueClampTable[0]); \
  681. clamp_a = CASTINT((gc)->alphaClampTable[0]); \
  682. \
  683. index_r = \
  684. (((ULONG)((clamp_r & sign_mask)) >> 30) | \
  685. ((ULONG)(((i_rScale - clamp_r) & sign_mask)) >> 31)); \
  686. \
  687. index_g = \
  688. (((ULONG)((clamp_g & sign_mask)) >> 30) | \
  689. ((ULONG)(((i_gScale - clamp_g) & sign_mask)) >> 31)); \
  690. \
  691. index_b = \
  692. (((ULONG)((clamp_b & sign_mask)) >> 30) | \
  693. ((ULONG)(((i_bScale - clamp_b) & sign_mask)) >> 31)); \
  694. \
  695. index_a = \
  696. (((ULONG)((clamp_a & sign_mask)) >> 30) | \
  697. ((ULONG)(((i_aScale - clamp_a) & sign_mask)) >> 31)); \
  698. \
  699. dst_r = (gc)->redClampTable[index_r]; \
  700. dst_g = (gc)->greenClampTable[index_g]; \
  701. dst_b = (gc)->blueClampTable[index_b]; \
  702. dst_a = (gc)->alphaClampTable[index_a]; \
  703. \
  704. rOut = dst_r; \
  705. gOut = dst_g; \
  706. bOut = dst_b; \
  707. aOut = dst_a; \
  708. }
  709. #define __GL_SCALE_AND_CHECK_CLAMP_RGB(rOut, gOut, bOut, gc, flags, r, g, b)\
  710. { \
  711. ULONG sign_mask = 0x80000000; \
  712. __GLfloat rScale, gScale, bScale; \
  713. LONG i_rScale, i_gScale, i_bScale; \
  714. LONG i_r, i_g, i_b; \
  715. __GLfloat fr, fg, fb; \
  716. ULONG the_flags_copy, r_flags, g_flags, b_flags; \
  717. \
  718. the_flags_copy = (flags); \
  719. \
  720. rScale = (gc)->redVertexScale; \
  721. gScale = (gc)->greenVertexScale; \
  722. bScale = (gc)->blueVertexScale; \
  723. \
  724. i_rScale = CASTINT((gc)->redVertexScale); \
  725. i_gScale = CASTINT((gc)->greenVertexScale); \
  726. i_bScale = CASTINT((gc)->blueVertexScale); \
  727. \
  728. fr = (r) * rScale; \
  729. fg = (g) * gScale; \
  730. fb = (b) * bScale; \
  731. \
  732. rOut = fr; \
  733. gOut = fg; \
  734. bOut = fb; \
  735. \
  736. i_r = CASTINT((rOut)); \
  737. i_g = CASTINT((gOut)); \
  738. i_b = CASTINT((bOut)); \
  739. \
  740. r_flags = \
  741. ((ULONG)(i_r & sign_mask) | \
  742. (ULONG)((i_rScale - i_r) & sign_mask)); \
  743. \
  744. g_flags = \
  745. ((ULONG)(i_g & sign_mask) | \
  746. (ULONG)((i_gScale - i_g) & sign_mask)); \
  747. \
  748. b_flags = \
  749. ((ULONG)(i_b & sign_mask) | \
  750. (ULONG)((i_bScale - i_b) & sign_mask)); \
  751. \
  752. the_flags_copy |= r_flags | g_flags | b_flags; \
  753. (flags) = the_flags_copy; \
  754. }
  755. #define __GL_SCALE_AND_CHECK_CLAMP_RGBA(rOut, gOut, bOut, aOut, gc, flags, \
  756. r, g, b, a)\
  757. { \
  758. ULONG sign_mask = 0x80000000; \
  759. __GLfloat rScale, gScale, bScale, aScale; \
  760. LONG i_rScale, i_gScale, i_bScale, i_aScale; \
  761. LONG i_r, i_g, i_b, i_a; \
  762. __GLfloat fr, fg, fb, fa; \
  763. ULONG the_flags_copy, r_flags, g_flags, b_flags, a_flags; \
  764. \
  765. the_flags_copy = (flags); \
  766. \
  767. rScale = (gc)->redVertexScale; \
  768. gScale = (gc)->greenVertexScale; \
  769. bScale = (gc)->blueVertexScale; \
  770. aScale = (gc)->alphaVertexScale; \
  771. \
  772. i_rScale = CASTINT((gc)->redVertexScale); \
  773. i_gScale = CASTINT((gc)->greenVertexScale); \
  774. i_bScale = CASTINT((gc)->blueVertexScale); \
  775. i_aScale = CASTINT((gc)->alphaVertexScale); \
  776. \
  777. fr = (r) * rScale; \
  778. fg = (g) * gScale; \
  779. fb = (b) * bScale; \
  780. fa = (a) * aScale; \
  781. \
  782. rOut = fr; \
  783. gOut = fg; \
  784. bOut = fb; \
  785. aOut = fa; \
  786. \
  787. i_r = CASTINT((rOut)); \
  788. i_g = CASTINT((gOut)); \
  789. i_b = CASTINT((bOut)); \
  790. i_a = CASTINT((aOut)); \
  791. \
  792. r_flags = \
  793. ((ULONG)(i_r & sign_mask) | \
  794. (ULONG)((i_rScale - i_r) & sign_mask)); \
  795. \
  796. g_flags = \
  797. ((ULONG)(i_g & sign_mask) | \
  798. (ULONG)((i_gScale - i_g) & sign_mask)); \
  799. \
  800. b_flags = \
  801. ((ULONG)(i_b & sign_mask) | \
  802. (ULONG)((i_bScale - i_b) & sign_mask)); \
  803. \
  804. a_flags = \
  805. ((ULONG)(i_a & sign_mask) | \
  806. (ULONG)((i_aScale - i_a) & sign_mask)); \
  807. \
  808. the_flags_copy |= r_flags | g_flags | b_flags | a_flags; \
  809. (flags) = the_flags_copy; \
  810. }
  811. #endif // NOT _X86_
  812. /************************************************************************/
  813. /* Applies to current context */
  814. extern void FASTCALL __glSetError(GLenum code);
  815. #ifdef NT
  816. /* Used when no RC is current */
  817. extern void FASTCALL __glSetErrorEarly(__GLcontext *gc, GLenum code);
  818. #endif // NT
  819. extern void FASTCALL __glFreeEvaluatorState(__GLcontext *gc);
  820. extern void FASTCALL __glFreeDlistState(__GLcontext *gc);
  821. extern void FASTCALL __glFreeMachineState(__GLcontext *gc);
  822. extern void FASTCALL __glFreePixelState(__GLcontext *gc);
  823. extern void FASTCALL __glFreeTextureState(__GLcontext *gc);
  824. extern void FASTCALL __glInitDlistState(__GLcontext *gc);
  825. extern void FASTCALL __glInitEvaluatorState(__GLcontext *gc);
  826. extern void FASTCALL __glInitPixelState(__GLcontext *gc);
  827. extern void FASTCALL __glInitTextureState(__GLcontext *gc);
  828. extern void FASTCALL __glInitTransformState(__GLcontext *gc);
  829. void FASTCALL __glEarlyInitContext(__GLcontext *gc);
  830. void FASTCALL __glContextSetColorScales(__GLcontext *gc);
  831. void FASTCALL __glContextUnsetColorScales(__GLcontext *gc);
  832. void FASTCALL __glSoftResetContext(__GLcontext *gc);
  833. void FASTCALL __glDestroyContext(__GLcontext *gc);
  834. #endif /* __glcontext_h_ */