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.

2150 lines
61 KiB

  1. /*
  2. ** Copyright 1991, 1992, 1993, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "lighting.h"
  20. #ifdef unix
  21. #include <GL/glxproto.h>
  22. #endif
  23. void APIPRIVATE __glim_AlphaFunc(GLenum af, GLfloat ref)
  24. {
  25. __GL_SETUP_NOT_IN_BEGIN();
  26. if ((af < GL_NEVER) || (af > GL_ALWAYS)) {
  27. __glSetError(GL_INVALID_ENUM);
  28. return;
  29. }
  30. if (__GL_FLOAT_LTZ (ref)) ref = __glZero;
  31. if (__GL_FLOAT_COMPARE_PONE (ref, >)) ref = __glOne;
  32. if ((gc->state.raster.alphaFunction != af) ||
  33. __GL_FLOAT_NE (gc->state.raster.alphaReference, ref)) {
  34. gc->state.raster.alphaFunction = af;
  35. gc->state.raster.alphaReference = ref;
  36. __GL_DELAY_VALIDATE(gc);
  37. #ifdef _MCD_
  38. MCD_STATE_DIRTY(gc, ALPHATEST);
  39. #endif
  40. gc->validateMask |= __GL_VALIDATE_ALPHA_FUNC;
  41. }
  42. }
  43. void APIPRIVATE __glim_BlendFunc(GLenum sf, GLenum df)
  44. {
  45. __GL_SETUP_NOT_IN_BEGIN();
  46. switch (sf) {
  47. case GL_ZERO:
  48. case GL_ONE:
  49. case GL_DST_COLOR:
  50. case GL_ONE_MINUS_DST_COLOR:
  51. case GL_SRC_ALPHA:
  52. case GL_ONE_MINUS_SRC_ALPHA:
  53. case GL_DST_ALPHA:
  54. case GL_ONE_MINUS_DST_ALPHA:
  55. case GL_SRC_ALPHA_SATURATE:
  56. break;
  57. default:
  58. __glSetError(GL_INVALID_ENUM);
  59. return;
  60. }
  61. switch (df) {
  62. case GL_ZERO:
  63. case GL_ONE:
  64. case GL_SRC_COLOR:
  65. case GL_ONE_MINUS_SRC_COLOR:
  66. case GL_SRC_ALPHA:
  67. case GL_ONE_MINUS_SRC_ALPHA:
  68. case GL_DST_ALPHA:
  69. case GL_ONE_MINUS_DST_ALPHA:
  70. break;
  71. default:
  72. __glSetError(GL_INVALID_ENUM);
  73. return;
  74. }
  75. if ((gc->state.raster.blendSrc != sf) ||
  76. (gc->state.raster.blendDst != df)) {
  77. gc->state.raster.blendSrc = sf;
  78. gc->state.raster.blendDst = df;
  79. __GL_DELAY_VALIDATE(gc);
  80. #ifdef _MCD_
  81. MCD_STATE_DIRTY(gc, BLEND);
  82. #endif
  83. }
  84. }
  85. void APIPRIVATE __glim_ClearAccum(GLfloat r, GLfloat g, GLfloat b, GLfloat a)
  86. {
  87. __GLfloat minusOne;
  88. __GLfloat one;
  89. __GL_SETUP_NOT_IN_BEGIN();
  90. minusOne = __glMinusOne;
  91. one = __glOne;
  92. if (r < minusOne) r = minusOne;
  93. if (r > one) r = one;
  94. if (g < minusOne) g = minusOne;
  95. if (g > one) g = one;
  96. if (b < minusOne) b = minusOne;
  97. if (b > one) b = one;
  98. if (a < minusOne) a = minusOne;
  99. if (a > one) a = one;
  100. if (__GL_FLOAT_NE (gc->state.accum.clear.r, r) ||
  101. __GL_FLOAT_NE (gc->state.accum.clear.g, g) ||
  102. __GL_FLOAT_NE (gc->state.accum.clear.b, b) ||
  103. __GL_FLOAT_NE (gc->state.accum.clear.a, a))
  104. {
  105. gc->state.accum.clear.r = r;
  106. gc->state.accum.clear.g = g;
  107. gc->state.accum.clear.b = b;
  108. gc->state.accum.clear.a = a;
  109. __GL_DELAY_VALIDATE(gc);
  110. }
  111. }
  112. void APIPRIVATE __glim_ClearColor (GLfloat r, GLfloat g, GLfloat b, GLfloat a)
  113. {
  114. __GLfloat zero;
  115. __GLfloat one;
  116. __GL_SETUP_NOT_IN_BEGIN();
  117. zero = (__GLfloat)__glZero;
  118. one = (__GLfloat)__glOne;
  119. if (__GL_FLOAT_LTZ(r)) r = zero;
  120. if (__GL_FLOAT_COMPARE_PONE (r, >)) r = one;
  121. if (__GL_FLOAT_LTZ(g)) g = zero;
  122. if (__GL_FLOAT_COMPARE_PONE (g, >)) g = one;
  123. if (__GL_FLOAT_LTZ(b)) b = zero;
  124. if (__GL_FLOAT_COMPARE_PONE (b, >)) b = one;
  125. if (__GL_FLOAT_LTZ(a)) a = zero;
  126. if (__GL_FLOAT_COMPARE_PONE (a, >)) a = one;
  127. #if 0
  128. if (__GL_FLOAT_NE (gc->state.raster.clear.r, r) ||
  129. __GL_FLOAT_NE (gc->state.raster.clear.g, g) ||
  130. __GL_FLOAT_NE (gc->state.raster.clear.b, b) ||
  131. __GL_FLOAT_NE (gc->state.raster.clear.a, a))
  132. {
  133. #endif
  134. gc->state.raster.clear.r = r;
  135. gc->state.raster.clear.g = g;
  136. gc->state.raster.clear.b = b;
  137. gc->state.raster.clear.a = a;
  138. #ifdef _MCD_
  139. MCD_STATE_DIRTY(gc, FBUFCTRL);
  140. #endif
  141. //}
  142. }
  143. void APIPRIVATE __glim_ClearDepth(GLdouble z)
  144. {
  145. __GL_SETUP_NOT_IN_BEGIN();
  146. if (z < (GLdouble) 0) z = (GLdouble)0;
  147. if (z > (GLdouble) 1) z = (GLdouble)1;
  148. if (gc->state.depth.clear != z) {
  149. gc->state.depth.clear = z;
  150. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_DEPTH);
  151. #ifdef _MCD_
  152. MCD_STATE_DIRTY(gc, FBUFCTRL);
  153. #endif
  154. }
  155. }
  156. void APIPRIVATE __glim_ClearIndex(GLfloat val)
  157. {
  158. __GL_SETUP_NOT_IN_BEGIN();
  159. val = __GL_MASK_INDEXF(gc, val);
  160. gc->state.raster.clearIndex = val;
  161. #ifdef _MCD_
  162. MCD_STATE_DIRTY(gc, FBUFCTRL);
  163. #endif
  164. }
  165. void APIPRIVATE __glim_ClearStencil(GLint s)
  166. {
  167. __GL_SETUP_NOT_IN_BEGIN();
  168. if (gc->state.stencil.clear != (GLshort) (s & __GL_MAX_STENCIL_VALUE)) {
  169. gc->state.stencil.clear = (GLshort) (s & __GL_MAX_STENCIL_VALUE);
  170. __GL_DELAY_VALIDATE(gc);
  171. #ifdef _MCD_
  172. MCD_STATE_DIRTY(gc, FBUFCTRL);
  173. #endif
  174. }
  175. }
  176. void APIPRIVATE __glim_ColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
  177. {
  178. __GL_SETUP_NOT_IN_BEGIN();
  179. if ((gc->state.raster.rMask != r) || (gc->state.raster.gMask != g) ||
  180. (gc->state.raster.bMask != b) || (gc->state.raster.aMask != a)) {
  181. gc->state.raster.rMask = r;
  182. gc->state.raster.gMask = g;
  183. gc->state.raster.bMask = b;
  184. gc->state.raster.aMask = a;
  185. __GL_DELAY_VALIDATE(gc);
  186. #ifdef _MCD_
  187. MCD_STATE_DIRTY(gc, FBUFCTRL);
  188. #endif
  189. }
  190. }
  191. void APIPRIVATE __glim_ColorMaterial(GLenum face, GLenum p)
  192. {
  193. __GL_SETUP_NOT_IN_BEGIN();
  194. switch (face) {
  195. case GL_FRONT:
  196. case GL_BACK:
  197. case GL_FRONT_AND_BACK:
  198. break;
  199. default:
  200. __glSetError(GL_INVALID_ENUM);
  201. return;
  202. }
  203. switch (p) {
  204. case GL_EMISSION:
  205. case GL_SPECULAR:
  206. case GL_AMBIENT:
  207. case GL_DIFFUSE:
  208. case GL_AMBIENT_AND_DIFFUSE:
  209. break;
  210. default:
  211. __glSetError(GL_INVALID_ENUM);
  212. return;
  213. }
  214. gc->state.light.colorMaterialFace = face;
  215. gc->state.light.colorMaterialParam = p;
  216. if (gc->state.enables.general & __GL_COLOR_MATERIAL_ENABLE) {
  217. #ifdef NT
  218. ComputeColorMaterialChange(gc);
  219. #endif
  220. (*gc->procs.pickColorMaterialProcs)(gc);
  221. (*gc->procs.applyColor)(gc);
  222. }
  223. MCD_STATE_DIRTY(gc, COLORMATERIAL);
  224. }
  225. void APIPRIVATE __glim_CullFace(GLenum cfm)
  226. {
  227. __GL_SETUP_NOT_IN_BEGIN();
  228. switch (cfm) {
  229. case GL_FRONT:
  230. case GL_BACK:
  231. case GL_FRONT_AND_BACK:
  232. break;
  233. default:
  234. __glSetError(GL_INVALID_ENUM);
  235. return;
  236. }
  237. if (gc->state.polygon.cull != cfm) {
  238. gc->state.polygon.cull = cfm;
  239. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  240. #ifdef _MCD_
  241. MCD_STATE_DIRTY(gc, POLYDRAW);
  242. #endif
  243. }
  244. }
  245. void APIPRIVATE __glim_DepthFunc(GLenum zf)
  246. {
  247. __GL_SETUP_NOT_IN_BEGIN();
  248. if ((zf < GL_NEVER) || (zf > GL_ALWAYS)) {
  249. __glSetError(GL_INVALID_ENUM);
  250. return;
  251. }
  252. if (gc->modes.depthBits != 0)
  253. gc->state.depth.testFunc = zf;
  254. else
  255. gc->state.depth.testFunc = GL_ALWAYS;
  256. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_DEPTH);
  257. #ifdef _MCD_
  258. MCD_STATE_DIRTY(gc, DEPTHTEST);
  259. #endif
  260. }
  261. void APIPRIVATE __glim_DepthMask(GLboolean enabled)
  262. {
  263. __GL_SETUP_NOT_IN_BEGIN();
  264. if (gc->state.depth.writeEnable != enabled) {
  265. gc->state.depth.writeEnable = enabled;
  266. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_DEPTH);
  267. #ifdef _MCD_
  268. MCD_STATE_DIRTY(gc, FBUFCTRL);
  269. #endif
  270. }
  271. }
  272. void APIPRIVATE __glim_DrawBuffer(GLenum mode)
  273. {
  274. GLint i;
  275. __GL_SETUP_NOT_IN_BEGIN();
  276. switch (mode) {
  277. case GL_NONE:
  278. gc->state.raster.drawBuffer = GL_NONE;
  279. break;
  280. case GL_FRONT_RIGHT:
  281. case GL_BACK_RIGHT:
  282. case GL_RIGHT:
  283. not_supported_in_this_implementation:
  284. __glSetError(GL_INVALID_OPERATION);
  285. return;
  286. case GL_FRONT:
  287. case GL_FRONT_LEFT:
  288. gc->state.raster.drawBuffer = GL_FRONT;
  289. break;
  290. case GL_FRONT_AND_BACK:
  291. case GL_LEFT:
  292. if (!gc->modes.doubleBufferMode) {
  293. gc->state.raster.drawBuffer = GL_FRONT;
  294. } else {
  295. gc->state.raster.drawBuffer = GL_FRONT_AND_BACK;
  296. }
  297. break;
  298. case GL_BACK:
  299. case GL_BACK_LEFT:
  300. if (!gc->modes.doubleBufferMode) {
  301. goto not_supported_in_this_implementation;
  302. }
  303. gc->state.raster.drawBuffer = GL_BACK;
  304. break;
  305. case GL_AUX0:
  306. case GL_AUX1:
  307. case GL_AUX2:
  308. case GL_AUX3:
  309. i = mode - GL_AUX0;
  310. if (i >= gc->modes.maxAuxBuffers) {
  311. goto not_supported_in_this_implementation;
  312. }
  313. gc->state.raster.drawBuffer = mode;
  314. break;
  315. default:
  316. __glSetError(GL_INVALID_ENUM);
  317. return;
  318. }
  319. if (gc->state.raster.drawBufferReturn != mode) {
  320. gc->state.raster.drawBufferReturn = mode;
  321. __GL_DELAY_VALIDATE(gc);
  322. #ifdef _MCD_
  323. MCD_STATE_DIRTY(gc, FBUFCTRL);
  324. #endif
  325. }
  326. }
  327. void APIPRIVATE __glim_Fogfv(GLenum p, const GLfloat pv[])
  328. {
  329. __GL_SETUP_NOT_IN_BEGIN();
  330. switch (p) {
  331. case GL_FOG_COLOR:
  332. __glClampAndScaleColorf(gc, &gc->state.fog.color, pv);
  333. #ifdef NT
  334. if (gc->state.fog.color.r == gc->state.fog.color.g
  335. && gc->state.fog.color.r == gc->state.fog.color.b)
  336. gc->state.fog.flags |= __GL_FOG_GRAY_RGB;
  337. else
  338. gc->state.fog.flags &= ~__GL_FOG_GRAY_RGB;
  339. #endif
  340. break;
  341. case GL_FOG_DENSITY:
  342. if (pv[0] < __glZero) {
  343. __glSetError(GL_INVALID_VALUE);
  344. return;
  345. }
  346. gc->state.fog.density = pv[0];
  347. #ifdef NT
  348. gc->state.fog.density2neg = -(pv[0] * pv[0]);
  349. #endif
  350. break;
  351. case GL_FOG_END:
  352. gc->state.fog.end = pv[0];
  353. break;
  354. case GL_FOG_START:
  355. gc->state.fog.start = pv[0];
  356. break;
  357. case GL_FOG_INDEX:
  358. gc->state.fog.index = __GL_MASK_INDEXF(gc, pv[0]);
  359. break;
  360. case GL_FOG_MODE:
  361. switch ((GLenum) pv[0]) {
  362. case GL_EXP:
  363. case GL_EXP2:
  364. case GL_LINEAR:
  365. gc->state.fog.mode = (GLenum) pv[0];
  366. break;
  367. default:
  368. __glSetError(GL_INVALID_ENUM);
  369. return;
  370. }
  371. break;
  372. default:
  373. __glSetError(GL_INVALID_ENUM);
  374. return;
  375. }
  376. /*
  377. ** Recompute cached 1/(end - start) value for linear fogging.
  378. */
  379. if (gc->state.fog.mode == GL_LINEAR) {
  380. if (gc->state.fog.start != gc->state.fog.end) {
  381. gc->state.fog.oneOverEMinusS =
  382. __glOne / (gc->state.fog.end - gc->state.fog.start);
  383. } else {
  384. /*
  385. ** Use zero as the undefined value.
  386. */
  387. gc->state.fog.oneOverEMinusS = __glZero;
  388. }
  389. }
  390. __GL_DELAY_VALIDATE(gc);
  391. #ifdef _MCD_
  392. MCD_STATE_DIRTY(gc, FOG);
  393. #endif
  394. }
  395. void APIPRIVATE __glim_FrontFace(GLenum dir)
  396. {
  397. __GL_SETUP_NOT_IN_BEGIN();
  398. switch (dir) {
  399. case GL_CW:
  400. case GL_CCW:
  401. break;
  402. default:
  403. __glSetError(GL_INVALID_ENUM);
  404. return;
  405. }
  406. if (gc->state.polygon.frontFaceDirection != dir) {
  407. gc->state.polygon.frontFaceDirection = dir;
  408. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  409. #ifdef _MCD_
  410. MCD_STATE_DIRTY(gc, POLYDRAW);
  411. #endif
  412. }
  413. }
  414. void APIPRIVATE __glim_Hint(GLenum target, GLenum mode)
  415. {
  416. __GLhintState *hs;
  417. __GL_SETUP_NOT_IN_BEGIN();
  418. hs = &gc->state.hints;
  419. switch (mode) {
  420. case GL_DONT_CARE:
  421. case GL_FASTEST:
  422. case GL_NICEST:
  423. break;
  424. default:
  425. __glSetError(GL_INVALID_ENUM);
  426. return;
  427. }
  428. switch (target) {
  429. case GL_PERSPECTIVE_CORRECTION_HINT:
  430. if (hs->perspectiveCorrection == mode) return;
  431. hs->perspectiveCorrection = mode;
  432. break;
  433. case GL_POINT_SMOOTH_HINT:
  434. if (hs->pointSmooth == mode) return;
  435. hs->pointSmooth = mode;
  436. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POINT);
  437. #ifdef _MCD_
  438. MCD_STATE_DIRTY(gc, HINTS);
  439. #endif
  440. return;
  441. case GL_LINE_SMOOTH_HINT:
  442. if (hs->lineSmooth == mode) return;
  443. hs->lineSmooth = mode;
  444. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  445. #ifdef _MCD_
  446. MCD_STATE_DIRTY(gc, HINTS);
  447. #endif
  448. return;
  449. case GL_POLYGON_SMOOTH_HINT:
  450. if (hs->polygonSmooth == mode) return;
  451. hs->polygonSmooth = mode;
  452. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  453. #ifdef _MCD_
  454. MCD_STATE_DIRTY(gc, HINTS);
  455. #endif
  456. return;
  457. case GL_FOG_HINT:
  458. if (hs->fog == mode) return;
  459. hs->fog = mode;
  460. break;
  461. #ifdef GL_WIN_phong_shading
  462. case GL_PHONG_HINT_WIN:
  463. if (hs->phong == mode) return;
  464. hs->phong = mode;
  465. break;
  466. #endif //GL_WIN_phong_shading
  467. default:
  468. __glSetError(GL_INVALID_ENUM);
  469. return;
  470. }
  471. __GL_DELAY_VALIDATE(gc);
  472. #ifdef _MCD_
  473. MCD_STATE_DIRTY(gc, HINTS);
  474. #endif
  475. }
  476. void APIPRIVATE __glim_IndexMask(GLuint i)
  477. {
  478. __GL_SETUP_NOT_IN_BEGIN();
  479. i = __GL_MASK_INDEXI(gc, i);
  480. if (gc->state.raster.writeMask != (GLint) i) {
  481. gc->state.raster.writeMask = (GLint) i;
  482. __GL_DELAY_VALIDATE(gc);
  483. #ifdef _MCD_
  484. MCD_STATE_DIRTY(gc, FBUFCTRL);
  485. #endif
  486. }
  487. }
  488. void FASTCALL __glTransformLightDirection(__GLcontext *gc, __GLlightSourceState *lss)
  489. {
  490. __GLcoord dir;
  491. __GLfloat q;
  492. GLint target = (GLint)((ULONG_PTR)(lss - &gc->state.light.source[0]));
  493. __GLtransform *tr;
  494. dir.x = lss->direction.x;
  495. dir.y = lss->direction.y;
  496. dir.z = lss->direction.z;
  497. #ifdef NT
  498. ASSERTOPENGL(lss->direction.w == __glOne, "Direction with invalid w\n");
  499. q = -(dir.x * lss->position.x + dir.y * lss->position.y +
  500. dir.z * lss->position.z);
  501. #else
  502. if (lss->position.w != __glZero) {
  503. q = -(dir.x * lss->position.x + dir.y * lss->position.y +
  504. dir.z * lss->position.z) / lss->position.w;
  505. } else {
  506. q = __glZero;
  507. }
  508. #endif // NT
  509. dir.w = q;
  510. tr = gc->transform.modelView;
  511. if (tr->flags & XFORM_UPDATE_INVERSE) {
  512. __glComputeInverseTranspose(gc, tr);
  513. }
  514. (*tr->inverseTranspose.xf4)(&lss->directionEye, &dir.x,
  515. &tr->inverseTranspose);
  516. __glNormalize(&lss->directionEyeNorm.x, &lss->directionEye.x);
  517. gc->light.source[target].direction = lss->directionEyeNorm;
  518. }
  519. void APIPRIVATE __glim_Lightfv(GLenum light, GLenum p, const GLfloat pv[])
  520. {
  521. __GLlightSourceState *lss;
  522. __GLmatrix *m;
  523. __GL_SETUP_NOT_IN_BEGIN();
  524. light -= GL_LIGHT0;
  525. #ifdef NT
  526. // light is unsigned!
  527. if (light >= (GLenum) gc->constants.numberOfLights) {
  528. #else
  529. if ((light < 0) || (light >= gc->constants.numberOfLights)) {
  530. #endif // NT
  531. bad_enum:
  532. __glSetError(GL_INVALID_ENUM);
  533. return;
  534. }
  535. lss = &gc->state.light.source[light];
  536. switch (p) {
  537. case GL_AMBIENT:
  538. __glScaleColorf(gc, &lss->ambient, pv);
  539. break;
  540. case GL_DIFFUSE:
  541. __glScaleColorf(gc, &lss->diffuse, pv);
  542. break;
  543. case GL_SPECULAR:
  544. __glScaleColorf(gc, &lss->specular, pv);
  545. break;
  546. case GL_POSITION:
  547. lss->position.x = pv[0];
  548. lss->position.y = pv[1];
  549. lss->position.z = pv[2];
  550. lss->position.w = pv[3];
  551. /*
  552. ** Transform light position into eye space
  553. */
  554. m = &gc->transform.modelView->matrix;
  555. (*m->xf4)(&lss->positionEye, &lss->position.x, m);
  556. //
  557. // Grab a copy of the matrix so we can do this again later for
  558. // infinite lighting (avoiding normal transformations):
  559. //
  560. lss->lightMatrix = gc->transform.modelView->matrix;
  561. break;
  562. case GL_SPOT_DIRECTION:
  563. lss->direction.x = pv[0];
  564. lss->direction.y = pv[1];
  565. lss->direction.z = pv[2];
  566. lss->direction.w = __glOne;
  567. __glTransformLightDirection(gc, lss);
  568. break;
  569. case GL_SPOT_EXPONENT:
  570. if ((pv[0] < (__GLfloat) 0) || (pv[0] > (__GLfloat) 128)) {
  571. bad_value:
  572. __glSetError(GL_INVALID_VALUE);
  573. return;
  574. }
  575. lss->spotLightExponent = pv[0];
  576. break;
  577. case GL_SPOT_CUTOFF:
  578. if ((pv[0] != (__GLfloat) 180) && ((pv[0] < (__GLfloat) 0) || (pv[0] > (__GLfloat) 90))) {
  579. goto bad_value;
  580. }
  581. lss->spotLightCutOffAngle = pv[0];
  582. break;
  583. case GL_CONSTANT_ATTENUATION:
  584. if (pv[0] < __glZero) {
  585. goto bad_value;
  586. }
  587. lss->constantAttenuation = pv[0];
  588. break;
  589. case GL_LINEAR_ATTENUATION:
  590. if (pv[0] < __glZero) {
  591. goto bad_value;
  592. }
  593. lss->linearAttenuation = pv[0];
  594. break;
  595. case GL_QUADRATIC_ATTENUATION:
  596. if (pv[0] < __glZero) {
  597. goto bad_value;
  598. }
  599. lss->quadraticAttenuation = pv[0];
  600. break;
  601. default:
  602. goto bad_enum;
  603. }
  604. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LIGHTING);
  605. gc->state.light.dirtyLights |= 1 << light;
  606. MCD_STATE_DIRTY(gc, LIGHTS);
  607. }
  608. void APIPRIVATE __glim_LightModelfv(GLenum p, const GLfloat pv[])
  609. {
  610. __GLlightModelState *model;
  611. __GL_SETUP_NOT_IN_BEGIN();
  612. model = &gc->state.light.model;
  613. switch (p) {
  614. case GL_LIGHT_MODEL_AMBIENT:
  615. __glScaleColorf(gc, &model->ambient, pv);
  616. break;
  617. case GL_LIGHT_MODEL_LOCAL_VIEWER:
  618. model->localViewer = pv[0] != __glZero;
  619. break;
  620. case GL_LIGHT_MODEL_TWO_SIDE:
  621. model->twoSided = pv[0] != __glZero;
  622. break;
  623. default:
  624. __glSetError(GL_INVALID_ENUM);
  625. return;
  626. }
  627. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LIGHTING);
  628. MCD_STATE_DIRTY(gc, LIGHTMODEL);
  629. }
  630. void APIPRIVATE __glim_LineStipple(GLint factor, GLushort stipple)
  631. {
  632. __GL_SETUP_NOT_IN_BEGIN();
  633. if (factor < 1) {
  634. factor = 1;
  635. }
  636. if (factor > 255) {
  637. factor = 255;
  638. }
  639. if ((gc->state.line.stippleRepeat != (GLshort) factor) ||
  640. (gc->state.line.stipple != stipple)) {
  641. gc->state.line.stippleRepeat = (GLshort) factor;
  642. gc->state.line.stipple = stipple;
  643. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  644. #ifdef _MCD_
  645. MCD_STATE_DIRTY(gc, LINEDRAW);
  646. #endif
  647. }
  648. }
  649. static GLint RoundWidth(__GLfloat size)
  650. {
  651. if (size < (__GLfloat) 1.0)
  652. return 1;
  653. return size + (__GLfloat) 0.5;
  654. }
  655. static __GLfloat ClampWidth(__GLcontext *gc, __GLfloat size)
  656. {
  657. __GLfloat minSize = gc->constants.lineWidthMinimum;
  658. __GLfloat maxSize = gc->constants.lineWidthMaximum;
  659. __GLfloat gran = gc->constants.lineWidthGranularity;
  660. GLint i;
  661. if (size <= minSize) return minSize;
  662. if (size >= maxSize) return maxSize;
  663. /* choose closest fence post */
  664. i = (GLint)(((size - minSize) / gran) + __glHalf);
  665. return minSize + i * gran;
  666. }
  667. void APIPRIVATE __glim_LineWidth(GLfloat width)
  668. {
  669. __GL_SETUP_NOT_IN_BEGIN();
  670. if (width <= 0) {
  671. __glSetError(GL_INVALID_VALUE);
  672. return;
  673. }
  674. if (gc->state.line.requestedWidth == width) return;
  675. gc->state.line.requestedWidth = width;
  676. gc->state.line.aliasedWidth = RoundWidth(width);
  677. gc->state.line.smoothWidth = ClampWidth(gc, width);
  678. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  679. #ifdef _MCD_
  680. MCD_STATE_DIRTY(gc, LINEDRAW);
  681. #endif
  682. }
  683. void APIPRIVATE __glim_LogicOp(GLenum op)
  684. {
  685. __GL_SETUP_NOT_IN_BEGIN();
  686. if ((op < GL_CLEAR) || (op > GL_SET)) {
  687. __glSetError(GL_INVALID_ENUM);
  688. return;
  689. }
  690. if (gc->state.raster.logicOp != op) {
  691. gc->state.raster.logicOp = op;
  692. __GL_DELAY_VALIDATE(gc);
  693. #ifdef _MCD_
  694. MCD_STATE_DIRTY(gc, LOGICOP);
  695. #endif
  696. }
  697. }
  698. static GLint ApplyParameterF(__GLcontext *gc, __GLmaterialState *ms,
  699. GLenum p, const GLfloat pv[])
  700. {
  701. switch (p) {
  702. case GL_COLOR_INDEXES:
  703. ms->cmapa = pv[0];
  704. ms->cmapd = pv[1];
  705. ms->cmaps = pv[2];
  706. return __GL_MATERIAL_COLORINDEXES;
  707. case GL_EMISSION:
  708. __glScaleColorf(gc, &ms->emissive, pv);
  709. return __GL_MATERIAL_EMISSIVE;
  710. case GL_SPECULAR:
  711. ms->specular.r = pv[0];
  712. ms->specular.g = pv[1];
  713. ms->specular.b = pv[2];
  714. ms->specular.a = pv[3];
  715. return __GL_MATERIAL_SPECULAR;
  716. case GL_SHININESS:
  717. ms->specularExponent = pv[0];
  718. return __GL_MATERIAL_SHININESS;
  719. case GL_AMBIENT:
  720. ms->ambient.r = pv[0];
  721. ms->ambient.g = pv[1];
  722. ms->ambient.b = pv[2];
  723. ms->ambient.a = pv[3];
  724. return __GL_MATERIAL_AMBIENT;
  725. case GL_DIFFUSE:
  726. ms->diffuse.r = pv[0];
  727. ms->diffuse.g = pv[1];
  728. ms->diffuse.b = pv[2];
  729. ms->diffuse.a = pv[3];
  730. return __GL_MATERIAL_DIFFUSE;
  731. case GL_AMBIENT_AND_DIFFUSE:
  732. ms->ambient.r = pv[0];
  733. ms->ambient.g = pv[1];
  734. ms->ambient.b = pv[2];
  735. ms->ambient.a = pv[3];
  736. ms->diffuse = ms->ambient;
  737. return __GL_MATERIAL_DIFFUSE | __GL_MATERIAL_AMBIENT;
  738. }
  739. return 0;
  740. }
  741. #ifdef SGI
  742. GLenum __glErrorCheckMaterial(GLenum face, GLenum p, GLfloat pv0)
  743. {
  744. switch (face) {
  745. case GL_FRONT:
  746. case GL_BACK:
  747. case GL_FRONT_AND_BACK:
  748. break;
  749. default:
  750. return GL_INVALID_ENUM;
  751. }
  752. switch (p) {
  753. case GL_COLOR_INDEXES:
  754. case GL_EMISSION:
  755. case GL_SPECULAR:
  756. case GL_AMBIENT:
  757. case GL_DIFFUSE:
  758. case GL_AMBIENT_AND_DIFFUSE:
  759. break;
  760. case GL_SHININESS:
  761. if (pv0 < (GLfloat) 0 || pv0 > (GLfloat) 128) {
  762. return GL_INVALID_VALUE;
  763. }
  764. break;
  765. default:
  766. return GL_INVALID_ENUM;
  767. }
  768. return GL_NO_ERROR;
  769. }
  770. #endif
  771. //!!! can we 'batch' these calls up until begin is called?
  772. void APIPRIVATE __glim_Materialfv(GLenum face, GLenum p, const GLfloat pv[])
  773. {
  774. GLenum error;
  775. GLint frontChange, backChange;
  776. __GL_SETUP();
  777. switch (face) {
  778. case GL_FRONT:
  779. frontChange = ApplyParameterF(gc, &gc->state.light.front, p, pv);
  780. backChange = 0;
  781. break;
  782. case GL_BACK:
  783. backChange = ApplyParameterF(gc, &gc->state.light.back, p, pv);
  784. frontChange = 0;
  785. break;
  786. case GL_FRONT_AND_BACK:
  787. backChange = ApplyParameterF(gc, &gc->state.light.back, p, pv);
  788. frontChange = ApplyParameterF(gc, &gc->state.light.front, p, pv);
  789. break;
  790. }
  791. if (p != GL_COLOR_INDEXES) {
  792. __glValidateMaterial(gc, frontChange, backChange);
  793. }
  794. if (gc->state.enables.general & __GL_COLOR_MATERIAL_ENABLE) {
  795. (*gc->procs.applyColor)(gc);
  796. }
  797. MCD_STATE_DIRTY(gc, MATERIAL);
  798. }
  799. static GLint RoundSize(__GLfloat size)
  800. {
  801. if (size < (__GLfloat) 1.0)
  802. return 1;
  803. return size + (__GLfloat) 0.5;
  804. }
  805. static __GLfloat ClampSize(__GLcontext *gc, __GLfloat size)
  806. {
  807. __GLfloat minSize = gc->constants.pointSizeMinimum;
  808. __GLfloat maxSize = gc->constants.pointSizeMaximum;
  809. __GLfloat gran = gc->constants.pointSizeGranularity;
  810. GLint i;
  811. if (size <= minSize) return minSize;
  812. if (size >= maxSize) return maxSize;
  813. /* choose closest fence post */
  814. i = (GLint)(((size - minSize) / gran) + __glHalf);
  815. return minSize + i * gran;
  816. }
  817. void APIPRIVATE __glim_PointSize(GLfloat f)
  818. {
  819. __GL_SETUP_NOT_IN_BEGIN();
  820. if (f <= __glZero) {
  821. __glSetError(GL_INVALID_VALUE);
  822. return;
  823. }
  824. if (gc->state.point.requestedSize != f) {
  825. gc->state.point.requestedSize = f;
  826. gc->state.point.aliasedSize = RoundSize(f);
  827. gc->state.point.smoothSize = ClampSize(gc, f);
  828. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POINT);
  829. #ifdef _MCD_
  830. MCD_STATE_DIRTY(gc, POINTDRAW);
  831. #endif
  832. }
  833. }
  834. void APIPRIVATE __glim_PolygonMode(GLenum face, GLenum mode)
  835. {
  836. __GL_SETUP_NOT_IN_BEGIN();
  837. switch (mode) {
  838. case GL_FILL:
  839. break;
  840. case GL_POINT:
  841. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POINT);
  842. break;
  843. case GL_LINE:
  844. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  845. break;
  846. default:
  847. __glSetError(GL_INVALID_ENUM);
  848. return;
  849. }
  850. switch (face) {
  851. case GL_FRONT:
  852. gc->state.polygon.frontMode = mode;
  853. break;
  854. case GL_BACK:
  855. gc->state.polygon.backMode = mode;
  856. break;
  857. case GL_FRONT_AND_BACK:
  858. gc->state.polygon.frontMode = mode;
  859. gc->state.polygon.backMode = mode;
  860. break;
  861. default:
  862. __glSetError(GL_INVALID_ENUM);
  863. return;
  864. }
  865. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  866. #ifdef _MCD_
  867. MCD_STATE_DIRTY(gc, POLYDRAW);
  868. #endif
  869. }
  870. #ifdef NT
  871. void APIPRIVATE __glim_PolygonStipple(const GLubyte *mask, GLboolean _IsDlist)
  872. #else
  873. void APIPRIVATE __glim_PolygonStipple(const GLubyte *mask)
  874. #endif
  875. {
  876. GLubyte *stipple;
  877. __GL_SETUP_NOT_IN_BEGIN();
  878. #ifdef NT
  879. if (_IsDlist)
  880. {
  881. const GLubyte *bits = mask;
  882. /*
  883. ** Just copy bits into stipple, convertPolygonStipple() will do the rest
  884. */
  885. __GL_MEMCOPY(&gc->state.polygonStipple.stipple[0], bits,
  886. sizeof(gc->state.polygonStipple.stipple));
  887. }
  888. else
  889. {
  890. #endif
  891. stipple = &gc->state.polygonStipple.stipple[0];
  892. __glFillImage(gc, 32, 32, GL_COLOR_INDEX, GL_BITMAP, mask, stipple);
  893. #ifdef NT
  894. }
  895. #endif
  896. (*gc->procs.convertPolygonStipple)(gc);
  897. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  898. #ifdef _MCD_
  899. MCD_STATE_DIRTY(gc, POLYDRAW);
  900. #endif
  901. }
  902. void APIPRIVATE __glim_ShadeModel(GLenum sm)
  903. {
  904. __GL_SETUP_NOT_IN_BEGIN();
  905. #ifdef GL_WIN_phong_shading
  906. if (!((sm == GL_FLAT) || (sm == GL_SMOOTH) || (sm == GL_PHONG_WIN)))
  907. #else
  908. if ((sm < GL_FLAT) || (sm > GL_SMOOTH))
  909. #endif
  910. {
  911. __glSetError(GL_INVALID_ENUM);
  912. return;
  913. }
  914. if (gc->state.light.shadingModel != sm)
  915. {
  916. gc->state.light.shadingModel = sm;
  917. __GL_DELAY_VALIDATE(gc);
  918. #ifdef _MCD_
  919. MCD_STATE_DIRTY(gc, SHADEMODEL);
  920. #endif
  921. }
  922. }
  923. void APIPRIVATE __glim_StencilMask(GLuint sm)
  924. {
  925. __GL_SETUP_NOT_IN_BEGIN();
  926. if (gc->state.stencil.writeMask !=
  927. (GLshort)(sm & __GL_MAX_STENCIL_VALUE)) {
  928. gc->state.stencil.writeMask = (GLshort) (sm & __GL_MAX_STENCIL_VALUE);
  929. __GL_DELAY_VALIDATE(gc);
  930. gc->validateMask |= __GL_VALIDATE_STENCIL_FUNC;
  931. #ifdef _MCD_
  932. MCD_STATE_DIRTY(gc, FBUFCTRL);
  933. #endif
  934. }
  935. }
  936. void APIPRIVATE __glim_StencilFunc(GLenum func, GLint ref, GLuint mask)
  937. {
  938. __GL_SETUP_NOT_IN_BEGIN();
  939. if ((func < GL_NEVER) || (func > GL_ALWAYS)) {
  940. __glSetError(GL_INVALID_ENUM);
  941. return;
  942. }
  943. if (ref < 0) ref = 0;
  944. if (ref > __GL_MAX_STENCIL_VALUE) ref = __GL_MAX_STENCIL_VALUE;
  945. if ((gc->state.stencil.testFunc != func) ||
  946. (gc->state.stencil.reference != (GLshort) ref) ||
  947. (gc->state.stencil.mask = (GLshort)(mask & __GL_MAX_STENCIL_VALUE))) {
  948. gc->state.stencil.testFunc = func;
  949. gc->state.stencil.reference = (GLshort) ref;
  950. gc->state.stencil.mask = (GLshort) (mask & __GL_MAX_STENCIL_VALUE);
  951. __GL_DELAY_VALIDATE(gc);
  952. gc->validateMask |= __GL_VALIDATE_STENCIL_FUNC;
  953. #ifdef _MCD_
  954. MCD_STATE_DIRTY(gc, STENCILTEST);
  955. #endif
  956. }
  957. }
  958. void APIPRIVATE __glim_StencilOp(GLenum fail, GLenum depthFail, GLenum depthPass)
  959. {
  960. __GL_SETUP_NOT_IN_BEGIN();
  961. switch (fail) {
  962. case GL_KEEP: case GL_ZERO: case GL_REPLACE:
  963. case GL_INCR: case GL_DECR: case GL_INVERT:
  964. break;
  965. default:
  966. __glSetError(GL_INVALID_ENUM);
  967. return;
  968. }
  969. switch (depthFail) {
  970. case GL_KEEP: case GL_ZERO: case GL_REPLACE:
  971. case GL_INCR: case GL_DECR: case GL_INVERT:
  972. break;
  973. default:
  974. __glSetError(GL_INVALID_ENUM);
  975. return;
  976. }
  977. switch (depthPass) {
  978. case GL_KEEP: case GL_ZERO: case GL_REPLACE:
  979. case GL_INCR: case GL_DECR: case GL_INVERT:
  980. break;
  981. default:
  982. __glSetError(GL_INVALID_ENUM);
  983. return;
  984. }
  985. if ((gc->state.stencil.fail != fail) ||
  986. (gc->state.stencil.depthFail != depthFail) ||
  987. (gc->state.stencil.depthPass != depthPass) ) {
  988. gc->state.stencil.fail = fail;
  989. gc->state.stencil.depthFail = depthFail;
  990. gc->state.stencil.depthPass = depthPass;
  991. __GL_DELAY_VALIDATE(gc);
  992. gc->validateMask |= __GL_VALIDATE_STENCIL_OP;
  993. #ifdef _MCD_
  994. MCD_STATE_DIRTY(gc, STENCILTEST);
  995. #endif
  996. }
  997. }
  998. /************************************************************************/
  999. /*
  1000. ** Copy context information from src to dst. Mark dst for validation
  1001. ** when done.
  1002. */
  1003. GLboolean FASTCALL __glCopyContext(__GLcontext *dst, const __GLcontext *src, GLuint mask)
  1004. {
  1005. const __GLattribute *sp;
  1006. GLboolean rv = GL_TRUE;
  1007. sp = &src->state;
  1008. if (dst == GLTEB_SRVCONTEXT()) {
  1009. return GL_FALSE;
  1010. }
  1011. /*
  1012. ** In order for a context copy to be successful, the source
  1013. ** and destination color scales must match. We make the
  1014. ** destination context match the source context, since it isn't
  1015. ** currently the current one, and will be automatically rescaled
  1016. ** when it next made current.
  1017. **
  1018. */
  1019. /* set the new destination context scale factors */
  1020. dst->frontBuffer.redScale = src->frontBuffer.redScale;
  1021. dst->frontBuffer.greenScale = src->frontBuffer.greenScale;
  1022. dst->frontBuffer.blueScale = src->frontBuffer.blueScale;
  1023. dst->frontBuffer.alphaScale = src->frontBuffer.alphaScale;
  1024. dst->redVertexScale = src->redVertexScale;
  1025. dst->greenVertexScale = src->greenVertexScale;
  1026. dst->blueVertexScale = src->blueVertexScale;
  1027. dst->alphaVertexScale = src->alphaVertexScale;
  1028. /* rescale the destination context with the new scale factors */
  1029. __glContextSetColorScales(dst);
  1030. if (mask & GL_ACCUM_BUFFER_BIT) {
  1031. dst->state.accum = sp->accum;
  1032. }
  1033. if (mask & GL_COLOR_BUFFER_BIT) {
  1034. dst->state.raster = sp->raster;
  1035. #ifdef NT
  1036. // A copy can occur from a double-buffered context to a single
  1037. // buffered context, leaving the drawBuffer in an invalid state
  1038. // Fix it up if necessary
  1039. if (dst->state.raster.drawBuffer == GL_BACK &&
  1040. !dst->modes.doubleBufferMode)
  1041. {
  1042. dst->state.raster.drawBuffer = GL_FRONT;
  1043. }
  1044. #endif
  1045. dst->state.enables.general &= ~__GL_COLOR_BUFFER_ENABLES;
  1046. dst->state.enables.general |=
  1047. sp->enables.general & __GL_COLOR_BUFFER_ENABLES;
  1048. dst->validateMask |= __GL_VALIDATE_ALPHA_FUNC; /*XXX*/
  1049. }
  1050. if (mask & GL_CURRENT_BIT) {
  1051. dst->state.current = sp->current;
  1052. }
  1053. if (mask & GL_DEPTH_BUFFER_BIT) {
  1054. dst->state.depth = sp->depth;
  1055. dst->state.enables.general &= ~__GL_DEPTH_TEST_ENABLE;
  1056. dst->state.enables.general |=
  1057. sp->enables.general & __GL_DEPTH_TEST_ENABLE;
  1058. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_DEPTH);
  1059. }
  1060. if (mask & GL_ENABLE_BIT) {
  1061. dst->state.enables = sp->enables;
  1062. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_LINE | __GL_DIRTY_POLYGON |
  1063. __GL_DIRTY_POINT | __GL_DIRTY_LIGHTING | __GL_DIRTY_DEPTH);
  1064. #ifdef NT
  1065. ComputeColorMaterialChange(dst);
  1066. #endif
  1067. (*dst->procs.pickColorMaterialProcs)(dst);
  1068. (*dst->procs.applyColor)(dst);
  1069. }
  1070. if (mask & GL_EVAL_BIT) {
  1071. dst->state.evaluator = sp->evaluator;
  1072. dst->state.enables.general &= ~__GL_AUTO_NORMAL_ENABLE;
  1073. dst->state.enables.general |=
  1074. sp->enables.general & __GL_AUTO_NORMAL_ENABLE;
  1075. dst->state.enables.eval1 = sp->enables.eval1;
  1076. dst->state.enables.eval2 = sp->enables.eval2;
  1077. }
  1078. if (mask & GL_FOG_BIT) {
  1079. dst->state.fog = sp->fog;
  1080. dst->state.enables.general &= ~__GL_FOG_ENABLE;
  1081. dst->state.enables.general |=
  1082. sp->enables.general & __GL_FOG_ENABLE;
  1083. #ifdef GL_WIN_specular_fog
  1084. dst->state.enables.general &= ~__GL_FOG_SPEC_TEX_ENABLE;
  1085. dst->state.enables.general |=
  1086. sp->enables.general & __GL_FOG_SPEC_TEX_ENABLE;
  1087. #endif //GL_WIN_specular_fog
  1088. }
  1089. if (mask & GL_HINT_BIT) {
  1090. dst->state.hints = sp->hints;
  1091. }
  1092. if (mask & GL_LIGHTING_BIT) {
  1093. dst->state.light.colorMaterialFace = sp->light.colorMaterialFace;
  1094. dst->state.light.colorMaterialParam = sp->light.colorMaterialParam;
  1095. dst->state.light.shadingModel = sp->light.shadingModel;
  1096. dst->state.light.model = sp->light.model;
  1097. dst->state.light.front = sp->light.front;
  1098. dst->state.light.back = sp->light.back;
  1099. dst->state.light.dirtyLights = (1 << dst->constants.numberOfLights)-1;
  1100. __GL_MEMCOPY(dst->state.light.source, sp->light.source,
  1101. dst->constants.numberOfLights
  1102. * sizeof(__GLlightSourceState));
  1103. dst->state.enables.general &= ~__GL_LIGHTING_ENABLES;
  1104. dst->state.enables.general |=
  1105. sp->enables.general & __GL_LIGHTING_ENABLES;
  1106. dst->state.enables.lights = sp->enables.lights;
  1107. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_LIGHTING);
  1108. }
  1109. if (mask & GL_LINE_BIT) {
  1110. dst->state.line = sp->line;
  1111. dst->state.enables.general &= ~__GL_LINE_ENABLES;
  1112. dst->state.enables.general |=
  1113. sp->enables.general & __GL_LINE_ENABLES;
  1114. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_LINE);
  1115. }
  1116. if (mask & GL_LIST_BIT) {
  1117. dst->state.list = sp->list;
  1118. }
  1119. if (mask & GL_PIXEL_MODE_BIT) {
  1120. dst->state.pixel.readBuffer = sp->pixel.readBuffer;
  1121. dst->state.pixel.readBufferReturn = sp->pixel.readBufferReturn;
  1122. dst->state.pixel.transferMode = sp->pixel.transferMode;
  1123. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_PIXEL);
  1124. }
  1125. if (mask & GL_POINT_BIT) {
  1126. dst->state.point = sp->point;
  1127. dst->state.enables.general &= ~__GL_POINT_SMOOTH_ENABLE;
  1128. dst->state.enables.general |=
  1129. sp->enables.general & __GL_POINT_SMOOTH_ENABLE;
  1130. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_POINT);
  1131. }
  1132. if (mask & GL_POLYGON_BIT) {
  1133. dst->state.polygon = sp->polygon;
  1134. dst->state.enables.general &= ~__GL_POLYGON_ENABLES;
  1135. dst->state.enables.general |=
  1136. sp->enables.general & __GL_POLYGON_ENABLES;
  1137. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_POLYGON);
  1138. }
  1139. if (mask & GL_POLYGON_STIPPLE_BIT) {
  1140. dst->state.polygonStipple = sp->polygonStipple;
  1141. dst->state.enables.general &= ~__GL_POLYGON_STIPPLE_ENABLE;
  1142. dst->state.enables.general |=
  1143. sp->enables.general & __GL_POLYGON_STIPPLE_ENABLE;
  1144. __GL_DELAY_VALIDATE_MASK(dst, __GL_DIRTY_POLYGON |
  1145. __GL_DIRTY_POLYGON_STIPPLE);
  1146. }
  1147. if (mask & GL_SCISSOR_BIT) {
  1148. dst->state.scissor = sp->scissor;
  1149. dst->state.enables.general &= ~__GL_SCISSOR_TEST_ENABLE;
  1150. dst->state.enables.general |=
  1151. sp->enables.general & __GL_SCISSOR_TEST_ENABLE;
  1152. }
  1153. if (mask & GL_STENCIL_BUFFER_BIT) {
  1154. dst->state.stencil = sp->stencil;
  1155. dst->state.enables.general &= ~__GL_STENCIL_TEST_ENABLE;
  1156. dst->state.enables.general |=
  1157. sp->enables.general & __GL_STENCIL_TEST_ENABLE;
  1158. dst->validateMask |= __GL_VALIDATE_STENCIL_FUNC |
  1159. __GL_VALIDATE_STENCIL_OP; /*XXX*/
  1160. }
  1161. if (mask & GL_TEXTURE_BIT) {
  1162. dst->state.texture.s = sp->texture.s;
  1163. dst->state.texture.t = sp->texture.t;
  1164. dst->state.texture.r = sp->texture.r;
  1165. dst->state.texture.q = sp->texture.q;
  1166. __GL_MEMCOPY(dst->state.texture.texture, sp->texture.texture,
  1167. dst->constants.numberOfTextures
  1168. * sizeof(__GLperTextureState));
  1169. __GL_MEMCOPY(dst->state.texture.env, sp->texture.env,
  1170. dst->constants.numberOfTextureEnvs
  1171. * sizeof(__GLtextureEnvState));
  1172. dst->state.enables.general &= ~__GL_TEXTURE_ENABLES;
  1173. dst->state.enables.general |=
  1174. sp->enables.general & __GL_TEXTURE_ENABLES;
  1175. }
  1176. if (mask & GL_TRANSFORM_BIT) {
  1177. dst->state.transform.matrixMode = sp->transform.matrixMode;
  1178. #ifdef NT
  1179. if (sp->transform.eyeClipPlanes != NULL)
  1180. {
  1181. if (dst->state.transform.eyeClipPlanes != NULL)
  1182. {
  1183. __GL_MEMCOPY(dst->state.transform.eyeClipPlanes,
  1184. sp->transform.eyeClipPlanes,
  1185. dst->constants.numberOfClipPlanes *
  1186. sizeof(__GLcoord));
  1187. }
  1188. }
  1189. else
  1190. {
  1191. dst->state.transform.eyeClipPlanes = NULL;
  1192. }
  1193. #else
  1194. __GL_MEMCOPY(dst->state.transform.eyeClipPlanes,
  1195. sp->transform.eyeClipPlanes,
  1196. dst->constants.numberOfClipPlanes *
  1197. sizeof(__GLcoord));
  1198. #endif
  1199. dst->state.enables.general &= ~__GL_NORMALIZE_ENABLE;
  1200. dst->state.enables.general |=
  1201. sp->enables.general & __GL_NORMALIZE_ENABLE;
  1202. }
  1203. if (mask & GL_VIEWPORT_BIT) {
  1204. dst->state.viewport = sp->viewport;
  1205. __glUpdateViewportDependents(dst);
  1206. }
  1207. __glContextUnsetColorScales(dst);
  1208. __GL_DELAY_VALIDATE(dst);
  1209. #ifdef _MCD_
  1210. MCD_STATE_DIRTY(dst, ALL);
  1211. #endif
  1212. return rv;
  1213. }
  1214. /************************************************************************/
  1215. void APIPRIVATE __glim_PushAttrib(GLuint mask)
  1216. {
  1217. __GLattribute **spp;
  1218. __GLattribute *sp;
  1219. __GL_SETUP_NOT_IN_BEGIN();
  1220. spp = gc->attributes.stackPointer;
  1221. if (spp < &gc->attributes.stack[gc->constants.maxAttribStackDepth]) {
  1222. if (!(sp = *spp)) {
  1223. sp = (__GLattribute*)
  1224. GCALLOCZ(gc, sizeof(__GLattribute));
  1225. if (NULL == sp)
  1226. {
  1227. return;
  1228. }
  1229. *spp = sp;
  1230. }
  1231. sp->mask = mask;
  1232. sp->enables = gc->state.enables; /* Always save enables */
  1233. gc->attributes.stackPointer = spp + 1;
  1234. if (mask & GL_ACCUM_BUFFER_BIT) {
  1235. sp->accum = gc->state.accum;
  1236. }
  1237. if (mask & GL_COLOR_BUFFER_BIT) {
  1238. sp->raster = gc->state.raster;
  1239. }
  1240. if (mask & GL_CURRENT_BIT) {
  1241. sp->current = gc->state.current;
  1242. }
  1243. if (mask & GL_DEPTH_BUFFER_BIT) {
  1244. sp->depth = gc->state.depth;
  1245. }
  1246. if (mask & GL_EVAL_BIT) {
  1247. sp->evaluator = gc->state.evaluator;
  1248. }
  1249. if (mask & GL_FOG_BIT) {
  1250. sp->fog = gc->state.fog;
  1251. }
  1252. if (mask & GL_HINT_BIT) {
  1253. sp->hints = gc->state.hints;
  1254. }
  1255. if (mask & GL_LIGHTING_BIT) {
  1256. size_t bytes = (size_t)
  1257. (gc->constants.numberOfLights * sizeof(__GLlightSourceState));
  1258. sp->light.colorMaterialFace = gc->state.light.colorMaterialFace;
  1259. sp->light.colorMaterialParam = gc->state.light.colorMaterialParam;
  1260. sp->light.shadingModel = gc->state.light.shadingModel;
  1261. sp->light.model = gc->state.light.model;
  1262. sp->light.front = gc->state.light.front;
  1263. sp->light.back = gc->state.light.back;
  1264. sp->light.source = (__GLlightSourceState*)
  1265. GCALLOC(gc, bytes);
  1266. #ifdef NT
  1267. if (NULL == sp->light.source)
  1268. sp->mask &= ~GL_LIGHTING_BIT;
  1269. else
  1270. __GL_MEMCOPY(sp->light.source, gc->state.light.source, bytes);
  1271. #else
  1272. __GL_MEMCOPY(sp->light.source, gc->state.light.source, bytes);
  1273. #endif
  1274. }
  1275. if (mask & GL_LINE_BIT) {
  1276. sp->line = gc->state.line;
  1277. }
  1278. if (mask & GL_LIST_BIT) {
  1279. sp->list = gc->state.list;
  1280. }
  1281. if (mask & GL_PIXEL_MODE_BIT) {
  1282. sp->pixel.readBuffer = gc->state.pixel.readBuffer;
  1283. sp->pixel.readBufferReturn = gc->state.pixel.readBufferReturn;
  1284. sp->pixel.transferMode = gc->state.pixel.transferMode;
  1285. }
  1286. if (mask & GL_POINT_BIT) {
  1287. sp->point = gc->state.point;
  1288. }
  1289. if (mask & GL_POLYGON_BIT) {
  1290. sp->polygon = gc->state.polygon;
  1291. }
  1292. if (mask & GL_POLYGON_STIPPLE_BIT) {
  1293. sp->polygonStipple = gc->state.polygonStipple;
  1294. }
  1295. if (mask & GL_SCISSOR_BIT) {
  1296. sp->scissor = gc->state.scissor;
  1297. }
  1298. if (mask & GL_STENCIL_BUFFER_BIT) {
  1299. sp->stencil = gc->state.stencil;
  1300. }
  1301. if (mask & GL_TEXTURE_BIT) {
  1302. size_t texbytes = (size_t) (gc->constants.numberOfTextures
  1303. * sizeof(__GLperTextureState));
  1304. size_t envbytes = (size_t) (gc->constants.numberOfTextureEnvs
  1305. * sizeof(__GLtextureEnvState));
  1306. sp->texture.s = gc->state.texture.s;
  1307. sp->texture.t = gc->state.texture.t;
  1308. sp->texture.r = gc->state.texture.r;
  1309. sp->texture.q = gc->state.texture.q;
  1310. #ifdef NT
  1311. sp->texture.texture = (__GLperTextureState*)
  1312. GCALLOC(gc, texbytes);
  1313. sp->texture.env = (__GLtextureEnvState*)
  1314. GCALLOC(gc, envbytes);
  1315. if ((NULL == sp->texture.texture) || (NULL == sp->texture.env)) {
  1316. if (sp->texture.texture)
  1317. GCFREE(gc, sp->texture.texture);
  1318. sp->texture.texture = NULL;
  1319. if (sp->texture.env)
  1320. GCFREE(gc, sp->texture.env);
  1321. sp->texture.env = NULL;
  1322. sp->mask &= ~GL_TEXTURE_BIT;
  1323. } else {
  1324. __GL_MEMCOPY(sp->texture.texture, gc->state.texture.texture,
  1325. texbytes);
  1326. __GL_MEMCOPY(sp->texture.env, gc->state.texture.env, envbytes);
  1327. }
  1328. #else
  1329. sp->texture.texture = (__GLperTextureState*)
  1330. GCALLOC(gc, texbytes);
  1331. __GL_MEMCOPY(sp->texture.texture, gc->state.texture.texture,
  1332. texbytes);
  1333. sp->texture.env = (__GLtextureEnvState*)
  1334. GCALLOC(gc, envbytes);
  1335. __GL_MEMCOPY(sp->texture.env, gc->state.texture.env, envbytes);
  1336. #endif
  1337. }
  1338. if (mask & GL_TRANSFORM_BIT) {
  1339. size_t bytes = (size_t)
  1340. (gc->constants.numberOfClipPlanes * sizeof(__GLcoord));
  1341. sp->transform.matrixMode = gc->state.transform.matrixMode;
  1342. sp->transform.eyeClipPlanes = (__GLcoord*)
  1343. GCALLOC(gc, bytes);
  1344. #ifdef NT
  1345. if (NULL == sp->transform.eyeClipPlanes)
  1346. sp->mask &= ~GL_TRANSFORM_BIT;
  1347. else
  1348. __GL_MEMCOPY(sp->transform.eyeClipPlanes,
  1349. gc->state.transform.eyeClipPlanes, bytes);
  1350. #else
  1351. __GL_MEMCOPY(sp->transform.eyeClipPlanes,
  1352. gc->state.transform.eyeClipPlanes, bytes);
  1353. #endif
  1354. }
  1355. if (mask & GL_VIEWPORT_BIT) {
  1356. sp->viewport = gc->state.viewport;
  1357. }
  1358. } else {
  1359. __glSetError(GL_STACK_OVERFLOW);
  1360. return;
  1361. }
  1362. }
  1363. /************************************************************************/
  1364. GLuint FASTCALL __glInternalPopAttrib(__GLcontext *gc, GLboolean destroy)
  1365. {
  1366. __GLattribute **spp;
  1367. __GLattribute *sp;
  1368. GLuint mask;
  1369. GLuint dirtyMask = 0;
  1370. spp = gc->attributes.stackPointer;
  1371. if (spp > &gc->attributes.stack[0]) {
  1372. --spp;
  1373. sp = *spp;
  1374. ASSERTOPENGL(sp != NULL, "No attribute data to pop\n");
  1375. mask = sp->mask;
  1376. gc->attributes.stackPointer = spp;
  1377. if (mask & GL_ACCUM_BUFFER_BIT) {
  1378. gc->state.accum = sp->accum;
  1379. }
  1380. if (mask & GL_COLOR_BUFFER_BIT) {
  1381. gc->state.raster = sp->raster;
  1382. gc->state.enables.general &= ~__GL_COLOR_BUFFER_ENABLES;
  1383. gc->state.enables.general |=
  1384. sp->enables.general & __GL_COLOR_BUFFER_ENABLES;
  1385. gc->validateMask |= __GL_VALIDATE_ALPHA_FUNC; /*XXX*/
  1386. }
  1387. if (mask & GL_CURRENT_BIT) {
  1388. gc->state.current = sp->current;
  1389. }
  1390. if (mask & GL_DEPTH_BUFFER_BIT) {
  1391. gc->state.depth = sp->depth;
  1392. gc->state.enables.general &= ~__GL_DEPTH_TEST_ENABLE;
  1393. gc->state.enables.general |=
  1394. sp->enables.general & __GL_DEPTH_TEST_ENABLE;
  1395. dirtyMask |= __GL_DIRTY_DEPTH;
  1396. }
  1397. if (mask & GL_ENABLE_BIT) {
  1398. gc->state.enables = sp->enables;
  1399. dirtyMask |= (__GL_DIRTY_LINE | __GL_DIRTY_POLYGON |
  1400. __GL_DIRTY_POINT | __GL_DIRTY_LIGHTING | __GL_DIRTY_DEPTH);
  1401. #ifdef NT
  1402. ComputeColorMaterialChange(gc);
  1403. #endif
  1404. (*gc->procs.pickColorMaterialProcs)(gc);
  1405. (*gc->procs.applyColor)(gc);
  1406. #ifdef NT
  1407. if (!destroy)
  1408. {
  1409. // applyViewport does both
  1410. (*gc->procs.applyViewport)(gc);
  1411. }
  1412. #else
  1413. (*gc->procs.computeClipBox)(gc);
  1414. (*gc->procs.applyScissor)(gc);
  1415. #endif
  1416. }
  1417. if (mask & GL_EVAL_BIT) {
  1418. gc->state.evaluator = sp->evaluator;
  1419. gc->state.enables.general &= ~__GL_AUTO_NORMAL_ENABLE;
  1420. gc->state.enables.general |=
  1421. sp->enables.general & __GL_AUTO_NORMAL_ENABLE;
  1422. gc->state.enables.eval1 = sp->enables.eval1;
  1423. gc->state.enables.eval2 = sp->enables.eval2;
  1424. }
  1425. if (mask & GL_FOG_BIT) {
  1426. gc->state.fog = sp->fog;
  1427. gc->state.enables.general &= ~__GL_FOG_ENABLE;
  1428. gc->state.enables.general |=
  1429. sp->enables.general & __GL_FOG_ENABLE;
  1430. #ifdef GL_WIN_specular_fog
  1431. gc->state.enables.general &= ~__GL_FOG_SPEC_TEX_ENABLE;
  1432. gc->state.enables.general |=
  1433. sp->enables.general & __GL_FOG_SPEC_TEX_ENABLE;
  1434. #endif //GL_WIN_specular_fog
  1435. }
  1436. if (mask & GL_HINT_BIT) {
  1437. gc->state.hints = sp->hints;
  1438. }
  1439. if (mask & GL_LIGHTING_BIT) {
  1440. gc->state.light.colorMaterialFace = sp->light.colorMaterialFace;
  1441. gc->state.light.colorMaterialParam = sp->light.colorMaterialParam;
  1442. gc->state.light.shadingModel = sp->light.shadingModel;
  1443. gc->state.light.model = sp->light.model;
  1444. gc->state.light.front = sp->light.front;
  1445. gc->state.light.back = sp->light.back;
  1446. gc->state.light.dirtyLights =
  1447. (1 << gc->constants.numberOfLights)-1;
  1448. __GL_MEMCOPY(gc->state.light.source, sp->light.source,
  1449. gc->constants.numberOfLights
  1450. * sizeof(__GLlightSourceState));
  1451. GCFREE(gc, sp->light.source);
  1452. sp->light.source = 0;
  1453. gc->state.enables.general &= ~__GL_LIGHTING_ENABLES;
  1454. gc->state.enables.general |=
  1455. sp->enables.general & __GL_LIGHTING_ENABLES;
  1456. gc->state.enables.lights = sp->enables.lights;
  1457. dirtyMask |= __GL_DIRTY_LIGHTING;
  1458. }
  1459. if (mask & GL_LINE_BIT) {
  1460. gc->state.line = sp->line;
  1461. gc->state.enables.general &= ~__GL_LINE_ENABLES;
  1462. gc->state.enables.general |=
  1463. sp->enables.general & __GL_LINE_ENABLES;
  1464. dirtyMask |= __GL_DIRTY_LINE;
  1465. }
  1466. if (mask & GL_LIST_BIT) {
  1467. gc->state.list = sp->list;
  1468. }
  1469. if (mask & GL_PIXEL_MODE_BIT) {
  1470. gc->state.pixel.transferMode = sp->pixel.transferMode;
  1471. gc->state.pixel.readBufferReturn = sp->pixel.readBufferReturn;
  1472. gc->state.pixel.readBuffer = sp->pixel.readBuffer;
  1473. dirtyMask |= __GL_DIRTY_PIXEL;
  1474. }
  1475. if (mask & GL_POINT_BIT) {
  1476. gc->state.point = sp->point;
  1477. gc->state.enables.general &= ~__GL_POINT_SMOOTH_ENABLE;
  1478. gc->state.enables.general |=
  1479. sp->enables.general & __GL_POINT_SMOOTH_ENABLE;
  1480. dirtyMask |= __GL_DIRTY_POINT;
  1481. }
  1482. if (mask & GL_POLYGON_BIT) {
  1483. gc->state.polygon = sp->polygon;
  1484. gc->state.enables.general &= ~__GL_POLYGON_ENABLES;
  1485. gc->state.enables.general |=
  1486. sp->enables.general & __GL_POLYGON_ENABLES;
  1487. dirtyMask |= __GL_DIRTY_POLYGON;
  1488. }
  1489. if (mask & GL_POLYGON_STIPPLE_BIT) {
  1490. gc->state.polygonStipple = sp->polygonStipple;
  1491. gc->state.enables.general &= ~__GL_POLYGON_STIPPLE_ENABLE;
  1492. gc->state.enables.general |=
  1493. sp->enables.general & __GL_POLYGON_STIPPLE_ENABLE;
  1494. (*gc->procs.convertPolygonStipple)(gc);
  1495. dirtyMask |= __GL_DIRTY_POLYGON;
  1496. }
  1497. if (mask & GL_SCISSOR_BIT) {
  1498. gc->state.scissor = sp->scissor;
  1499. gc->state.enables.general &= ~__GL_SCISSOR_TEST_ENABLE;
  1500. gc->state.enables.general |=
  1501. sp->enables.general & __GL_SCISSOR_TEST_ENABLE;
  1502. #ifdef NT
  1503. if (!destroy)
  1504. {
  1505. // applyViewport does both
  1506. (*gc->procs.applyViewport)(gc);
  1507. }
  1508. #else
  1509. (*gc->procs.computeClipBox)(gc);
  1510. (*gc->procs.applyScissor)(gc);
  1511. #endif
  1512. }
  1513. if (mask & GL_STENCIL_BUFFER_BIT) {
  1514. gc->state.stencil = sp->stencil;
  1515. gc->state.enables.general &= ~__GL_STENCIL_TEST_ENABLE;
  1516. gc->state.enables.general |=
  1517. sp->enables.general & __GL_STENCIL_TEST_ENABLE;
  1518. gc->validateMask |= __GL_VALIDATE_STENCIL_FUNC |
  1519. __GL_VALIDATE_STENCIL_OP;/*XXX*/
  1520. }
  1521. if (mask & GL_TEXTURE_BIT) {
  1522. GLuint numTextures = gc->constants.numberOfTextures;
  1523. gc->state.texture.s = sp->texture.s;
  1524. gc->state.texture.t = sp->texture.t;
  1525. gc->state.texture.r = sp->texture.r;
  1526. gc->state.texture.q = sp->texture.q;
  1527. /*
  1528. ** If the texture name is different, a new binding is
  1529. ** called for. Deferring the binding is dangerous, because
  1530. ** the state before the pop has to be saved with the
  1531. ** texture that is being unbound. If we defer the binding,
  1532. ** we need to watch out for cases like two pops in a row
  1533. ** or a pop followed by a bind.
  1534. */
  1535. {
  1536. GLuint targetIndex;
  1537. __GLperTextureState *pts, *spPts;
  1538. pts = gc->state.texture.texture;
  1539. spPts = sp->texture.texture;
  1540. for (targetIndex = 0; targetIndex < numTextures;
  1541. targetIndex++, pts++, spPts++) {
  1542. if (pts->texobjs.name != spPts->texobjs.name) {
  1543. __glBindTexture(gc, targetIndex,
  1544. spPts->texobjs.name, GL_TRUE);
  1545. }
  1546. }
  1547. }
  1548. __GL_MEMCOPY(gc->state.texture.texture, sp->texture.texture,
  1549. numTextures * sizeof(__GLperTextureState));
  1550. __GL_MEMCOPY(gc->state.texture.env, sp->texture.env,
  1551. gc->constants.numberOfTextureEnvs
  1552. * sizeof(__GLtextureEnvState));
  1553. GCFREE(gc, sp->texture.texture);
  1554. sp->texture.texture = 0;
  1555. GCFREE(gc, sp->texture.env);
  1556. sp->texture.env = 0;
  1557. gc->state.enables.general &= ~__GL_TEXTURE_ENABLES;
  1558. gc->state.enables.general |=
  1559. sp->enables.general & __GL_TEXTURE_ENABLES;
  1560. }
  1561. if (mask & GL_TRANSFORM_BIT) {
  1562. gc->state.transform.matrixMode = sp->transform.matrixMode;
  1563. __GL_MEMCOPY(gc->state.transform.eyeClipPlanes,
  1564. sp->transform.eyeClipPlanes,
  1565. gc->constants.numberOfClipPlanes * sizeof(__GLcoord));
  1566. GCFREE(gc, sp->transform.eyeClipPlanes);
  1567. sp->transform.eyeClipPlanes = 0;
  1568. gc->state.enables.general &= ~__GL_NORMALIZE_ENABLE;
  1569. gc->state.enables.general |=
  1570. sp->enables.general & __GL_NORMALIZE_ENABLE;
  1571. }
  1572. if (mask & GL_VIEWPORT_BIT) {
  1573. gc->state.viewport = sp->viewport;
  1574. __glUpdateViewportDependents(gc);
  1575. }
  1576. /*
  1577. ** Clear out mask so that any memory frees done above won't get
  1578. ** re-done when the context is destroyed
  1579. */
  1580. sp->mask = 0;
  1581. dirtyMask |= __GL_DIRTY_GENERIC;
  1582. #ifdef _MCD_
  1583. MCD_STATE_DIRTY(gc, ALL);
  1584. #endif
  1585. } else {
  1586. __glSetError(GL_STACK_UNDERFLOW);
  1587. }
  1588. return dirtyMask;
  1589. }
  1590. void APIPRIVATE __glim_PopAttrib(void)
  1591. {
  1592. GLuint dirtyMask;
  1593. __GL_SETUP_NOT_IN_BEGIN();
  1594. dirtyMask = __glInternalPopAttrib(gc, GL_FALSE);
  1595. if (dirtyMask)
  1596. {
  1597. __GL_DELAY_VALIDATE_MASK(gc, dirtyMask);
  1598. }
  1599. }
  1600. /************************************************************************/
  1601. void APIPRIVATE __glim_Disable(GLenum cap)
  1602. {
  1603. GLuint frontChange, backChange;
  1604. __GL_SETUP_NOT_IN_BEGIN();
  1605. switch (cap) {
  1606. case GL_ALPHA_TEST:
  1607. if (!(gc->state.enables.general & __GL_ALPHA_TEST_ENABLE)) return;
  1608. gc->state.enables.general &= ~__GL_ALPHA_TEST_ENABLE;
  1609. break;
  1610. case GL_BLEND:
  1611. if (!(gc->state.enables.general & __GL_BLEND_ENABLE)) return;
  1612. gc->state.enables.general &= ~__GL_BLEND_ENABLE;
  1613. break;
  1614. case GL_COLOR_MATERIAL:
  1615. if (!(gc->state.enables.general & __GL_COLOR_MATERIAL_ENABLE)) return;
  1616. gc->state.enables.general &= ~__GL_COLOR_MATERIAL_ENABLE;
  1617. frontChange = gc->light.front.colorMaterialChange;
  1618. backChange = gc->light.back.colorMaterialChange;
  1619. ComputeColorMaterialChange(gc);
  1620. (*gc->procs.pickColorMaterialProcs)(gc);
  1621. __glValidateMaterial(gc, frontChange, backChange);
  1622. break;
  1623. case GL_CULL_FACE:
  1624. if (!(gc->state.enables.general & __GL_CULL_FACE_ENABLE)) return;
  1625. gc->state.enables.general &= ~__GL_CULL_FACE_ENABLE;
  1626. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  1627. #ifdef _MCD_
  1628. MCD_STATE_DIRTY(gc, ENABLES);
  1629. #endif
  1630. return;
  1631. case GL_DEPTH_TEST:
  1632. if (!(gc->state.enables.general & __GL_DEPTH_TEST_ENABLE)) return;
  1633. gc->state.enables.general &= ~__GL_DEPTH_TEST_ENABLE;
  1634. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_DEPTH);
  1635. break;
  1636. case GL_POLYGON_OFFSET_POINT:
  1637. if (!(gc->state.enables.general & __GL_POLYGON_OFFSET_POINT_ENABLE))
  1638. return;
  1639. gc->state.enables.general &= ~__GL_POLYGON_OFFSET_POINT_ENABLE;
  1640. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POINT);
  1641. break;
  1642. case GL_POLYGON_OFFSET_LINE:
  1643. if (!(gc->state.enables.general & __GL_POLYGON_OFFSET_LINE_ENABLE))
  1644. return;
  1645. gc->state.enables.general &= ~__GL_POLYGON_OFFSET_LINE_ENABLE;
  1646. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  1647. break;
  1648. case GL_POLYGON_OFFSET_FILL:
  1649. if (!(gc->state.enables.general & __GL_POLYGON_OFFSET_FILL_ENABLE))
  1650. return;
  1651. gc->state.enables.general &= ~__GL_POLYGON_OFFSET_FILL_ENABLE;
  1652. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  1653. break;
  1654. case GL_DITHER:
  1655. if (!(gc->state.enables.general & __GL_DITHER_ENABLE)) return;
  1656. gc->state.enables.general &= ~__GL_DITHER_ENABLE;
  1657. break;
  1658. #ifdef GL_WIN_specular_fog
  1659. case GL_FOG_SPECULAR_TEXTURE_WIN:
  1660. if (!(gc->state.enables.general & __GL_FOG_SPEC_TEX_ENABLE))
  1661. return;
  1662. gc->state.enables.general &= ~__GL_FOG_SPEC_TEX_ENABLE;
  1663. break;
  1664. #endif //GL_WIN_specular_fog
  1665. case GL_FOG:
  1666. if (!(gc->state.enables.general & __GL_FOG_ENABLE)) return;
  1667. gc->state.enables.general &= ~__GL_FOG_ENABLE;
  1668. break;
  1669. case GL_LIGHTING:
  1670. if (!(gc->state.enables.general & __GL_LIGHTING_ENABLE)) return;
  1671. gc->state.enables.general &= ~__GL_LIGHTING_ENABLE;
  1672. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LIGHTING);
  1673. #ifdef _MCD_
  1674. MCD_STATE_DIRTY(gc, ENABLES);
  1675. #endif
  1676. #ifdef NT
  1677. ComputeColorMaterialChange(gc);
  1678. #endif
  1679. (*gc->procs.pickColorMaterialProcs)(gc);
  1680. (*gc->procs.applyColor)(gc);
  1681. return;
  1682. case GL_LINE_SMOOTH:
  1683. if (!(gc->state.enables.general & __GL_LINE_SMOOTH_ENABLE)) return;
  1684. gc->state.enables.general &= ~__GL_LINE_SMOOTH_ENABLE;
  1685. break;
  1686. case GL_LINE_STIPPLE:
  1687. if (!(gc->state.enables.general & __GL_LINE_STIPPLE_ENABLE)) return;
  1688. gc->state.enables.general &= ~__GL_LINE_STIPPLE_ENABLE;
  1689. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LINE);
  1690. #ifdef _MCD_
  1691. MCD_STATE_DIRTY(gc, ENABLES);
  1692. #endif
  1693. return;
  1694. case GL_INDEX_LOGIC_OP:
  1695. if (!(gc->state.enables.general & __GL_INDEX_LOGIC_OP_ENABLE)) return;
  1696. gc->state.enables.general &= ~__GL_INDEX_LOGIC_OP_ENABLE;
  1697. break;
  1698. case GL_COLOR_LOGIC_OP:
  1699. if (!(gc->state.enables.general & __GL_COLOR_LOGIC_OP_ENABLE)) return;
  1700. gc->state.enables.general &= ~__GL_COLOR_LOGIC_OP_ENABLE;
  1701. break;
  1702. case GL_NORMALIZE:
  1703. if (!(gc->state.enables.general & __GL_NORMALIZE_ENABLE)) return;
  1704. gc->state.enables.general &= ~__GL_NORMALIZE_ENABLE;
  1705. break;
  1706. case GL_POINT_SMOOTH:
  1707. if (!(gc->state.enables.general & __GL_POINT_SMOOTH_ENABLE)) return;
  1708. gc->state.enables.general &= ~__GL_POINT_SMOOTH_ENABLE;
  1709. break;
  1710. case GL_POLYGON_SMOOTH:
  1711. if (!(gc->state.enables.general & __GL_POLYGON_SMOOTH_ENABLE)) return;
  1712. gc->state.enables.general &= ~__GL_POLYGON_SMOOTH_ENABLE;
  1713. break;
  1714. case GL_POLYGON_STIPPLE:
  1715. if (!(gc->state.enables.general & __GL_POLYGON_STIPPLE_ENABLE))
  1716. return;
  1717. gc->state.enables.general &= ~__GL_POLYGON_STIPPLE_ENABLE;
  1718. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  1719. #ifdef _MCD_
  1720. MCD_STATE_DIRTY(gc, ENABLES);
  1721. #endif
  1722. return;
  1723. case GL_SCISSOR_TEST:
  1724. if (!(gc->state.enables.general & __GL_SCISSOR_TEST_ENABLE)) return;
  1725. gc->state.enables.general &= ~__GL_SCISSOR_TEST_ENABLE;
  1726. #ifdef NT
  1727. #ifdef _MCD_
  1728. MCD_STATE_DIRTY(gc, SCISSOR);
  1729. #endif
  1730. // applyViewport does both
  1731. (*gc->procs.applyViewport)(gc);
  1732. #else
  1733. (*gc->procs.computeClipBox)(gc);
  1734. (*gc->procs.applyScissor)(gc);
  1735. #endif
  1736. break;
  1737. case GL_STENCIL_TEST:
  1738. if (!(gc->state.enables.general & __GL_STENCIL_TEST_ENABLE)) return;
  1739. gc->state.enables.general &= ~__GL_STENCIL_TEST_ENABLE;
  1740. break;
  1741. case GL_TEXTURE_1D:
  1742. if (!(gc->state.enables.general & __GL_TEXTURE_1D_ENABLE)) return;
  1743. gc->state.enables.general &= ~__GL_TEXTURE_1D_ENABLE;
  1744. break;
  1745. case GL_TEXTURE_2D:
  1746. if (!(gc->state.enables.general & __GL_TEXTURE_2D_ENABLE)) return;
  1747. gc->state.enables.general &= ~__GL_TEXTURE_2D_ENABLE;
  1748. break;
  1749. case GL_AUTO_NORMAL:
  1750. if (!(gc->state.enables.general & __GL_AUTO_NORMAL_ENABLE)) return;
  1751. gc->state.enables.general &= ~__GL_AUTO_NORMAL_ENABLE;
  1752. break;
  1753. case GL_TEXTURE_GEN_S:
  1754. if (!(gc->state.enables.general & __GL_TEXTURE_GEN_S_ENABLE)) return;
  1755. gc->state.enables.general &= ~__GL_TEXTURE_GEN_S_ENABLE;
  1756. break;
  1757. case GL_TEXTURE_GEN_T:
  1758. if (!(gc->state.enables.general & __GL_TEXTURE_GEN_T_ENABLE)) return;
  1759. gc->state.enables.general &= ~__GL_TEXTURE_GEN_T_ENABLE;
  1760. break;
  1761. case GL_TEXTURE_GEN_R:
  1762. if (!(gc->state.enables.general & __GL_TEXTURE_GEN_R_ENABLE)) return;
  1763. gc->state.enables.general &= ~__GL_TEXTURE_GEN_R_ENABLE;
  1764. break;
  1765. case GL_TEXTURE_GEN_Q:
  1766. if (!(gc->state.enables.general & __GL_TEXTURE_GEN_Q_ENABLE)) return;
  1767. gc->state.enables.general &= ~__GL_TEXTURE_GEN_Q_ENABLE;
  1768. break;
  1769. #ifdef GL_WIN_multiple_textures
  1770. case GL_TEXCOMBINE_CLAMP_WIN:
  1771. if (!(gc->state.enables.general & __GL_TEXCOMBINE_CLAMP_ENABLE))
  1772. {
  1773. return;
  1774. }
  1775. gc->state.enables.general &= ~__GL_TEXCOMBINE_CLAMP_ENABLE;
  1776. break;
  1777. #endif // GL_WIN_multiple_textures
  1778. #ifdef GL_EXT_flat_paletted_lighting
  1779. case GL_PALETTED_LIGHTING_EXT:
  1780. gc->state.enables.general &= ~__GL_PALETTED_LIGHTING_ENABLE;
  1781. break;
  1782. #endif
  1783. case GL_CLIP_PLANE0: case GL_CLIP_PLANE1:
  1784. case GL_CLIP_PLANE2: case GL_CLIP_PLANE3:
  1785. case GL_CLIP_PLANE4: case GL_CLIP_PLANE5:
  1786. cap -= GL_CLIP_PLANE0;
  1787. if (!(gc->state.enables.clipPlanes & (1 << cap))) return;
  1788. gc->state.enables.clipPlanes &= ~(1 << cap);
  1789. #ifdef _MCD_
  1790. MCD_STATE_DIRTY(gc, CLIPCTRL);
  1791. #endif
  1792. break;
  1793. case GL_LIGHT0: case GL_LIGHT1:
  1794. case GL_LIGHT2: case GL_LIGHT3:
  1795. case GL_LIGHT4: case GL_LIGHT5:
  1796. case GL_LIGHT6: case GL_LIGHT7:
  1797. cap -= GL_LIGHT0;
  1798. if (!(gc->state.enables.lights & (1 << cap))) return;
  1799. gc->state.enables.lights &= ~(1 << cap);
  1800. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_LIGHTING);
  1801. MCD_STATE_DIRTY(gc, LIGHTS);
  1802. return;
  1803. case GL_MAP1_COLOR_4:
  1804. case GL_MAP1_NORMAL:
  1805. case GL_MAP1_INDEX:
  1806. case GL_MAP1_TEXTURE_COORD_1: case GL_MAP1_TEXTURE_COORD_2:
  1807. case GL_MAP1_TEXTURE_COORD_3: case GL_MAP1_TEXTURE_COORD_4:
  1808. case GL_MAP1_VERTEX_3: case GL_MAP1_VERTEX_4:
  1809. cap = __GL_EVAL1D_INDEX(cap);
  1810. if (!(gc->state.enables.eval1 & (GLushort) ~(1 << cap))) return;
  1811. gc->state.enables.eval1 &= (GLushort) ~(1 << cap);
  1812. break;
  1813. case GL_MAP2_COLOR_4:
  1814. case GL_MAP2_NORMAL:
  1815. case GL_MAP2_INDEX:
  1816. case GL_MAP2_TEXTURE_COORD_1: case GL_MAP2_TEXTURE_COORD_2:
  1817. case GL_MAP2_TEXTURE_COORD_3: case GL_MAP2_TEXTURE_COORD_4:
  1818. case GL_MAP2_VERTEX_3: case GL_MAP2_VERTEX_4:
  1819. cap = __GL_EVAL2D_INDEX(cap);
  1820. if (!(gc->state.enables.eval2 & (GLushort) ~(1 << cap))) return;
  1821. gc->state.enables.eval2 &= (GLushort) ~(1 << cap);
  1822. break;
  1823. default:
  1824. __glSetError(GL_INVALID_ENUM);
  1825. return;
  1826. }
  1827. __GL_DELAY_VALIDATE(gc);
  1828. #ifdef _MCD_
  1829. MCD_STATE_DIRTY(gc, ENABLES);
  1830. #endif
  1831. }
  1832. GLboolean APIPRIVATE __glim_IsEnabled(GLenum cap)
  1833. {
  1834. GLuint bit;
  1835. __GL_SETUP_NOT_IN_BEGIN2();
  1836. switch (cap) {
  1837. case GL_ALPHA_TEST:
  1838. bit = gc->state.enables.general & __GL_ALPHA_TEST_ENABLE;
  1839. break;
  1840. case GL_BLEND:
  1841. bit = gc->state.enables.general & __GL_BLEND_ENABLE;
  1842. break;
  1843. case GL_COLOR_MATERIAL:
  1844. bit = gc->state.enables.general & __GL_COLOR_MATERIAL_ENABLE;
  1845. break;
  1846. case GL_CULL_FACE:
  1847. bit = gc->state.enables.general & __GL_CULL_FACE_ENABLE;
  1848. break;
  1849. case GL_DEPTH_TEST:
  1850. bit = gc->state.enables.general & __GL_DEPTH_TEST_ENABLE;
  1851. break;
  1852. case GL_POLYGON_OFFSET_POINT:
  1853. bit = gc->state.enables.general & __GL_POLYGON_OFFSET_POINT_ENABLE;
  1854. break;
  1855. case GL_POLYGON_OFFSET_LINE:
  1856. bit = gc->state.enables.general & __GL_POLYGON_OFFSET_LINE_ENABLE;
  1857. break;
  1858. case GL_POLYGON_OFFSET_FILL:
  1859. bit = gc->state.enables.general & __GL_POLYGON_OFFSET_FILL_ENABLE;
  1860. break;
  1861. case GL_DITHER:
  1862. bit = gc->state.enables.general & __GL_DITHER_ENABLE;
  1863. break;
  1864. #ifdef GL_WIN_specular_fog
  1865. case GL_FOG_SPECULAR_TEXTURE_WIN:
  1866. bit = gc->state.enables.general & __GL_FOG_SPEC_TEX_ENABLE;
  1867. break;
  1868. #endif //GL_WIN_specular_fog
  1869. case GL_FOG:
  1870. bit = gc->state.enables.general & __GL_FOG_ENABLE;
  1871. break;
  1872. case GL_LIGHTING:
  1873. bit = gc->state.enables.general & __GL_LIGHTING_ENABLE;
  1874. break;
  1875. case GL_LINE_SMOOTH:
  1876. bit = gc->state.enables.general & __GL_LINE_SMOOTH_ENABLE;
  1877. break;
  1878. case GL_LINE_STIPPLE:
  1879. bit = gc->state.enables.general & __GL_LINE_STIPPLE_ENABLE;
  1880. break;
  1881. case GL_INDEX_LOGIC_OP:
  1882. bit = gc->state.enables.general & __GL_INDEX_LOGIC_OP_ENABLE;
  1883. break;
  1884. case GL_COLOR_LOGIC_OP:
  1885. bit = gc->state.enables.general & __GL_COLOR_LOGIC_OP_ENABLE;
  1886. break;
  1887. case GL_NORMALIZE:
  1888. bit = gc->state.enables.general & __GL_NORMALIZE_ENABLE;
  1889. break;
  1890. case GL_POINT_SMOOTH:
  1891. bit = gc->state.enables.general & __GL_POINT_SMOOTH_ENABLE;
  1892. break;
  1893. case GL_POLYGON_SMOOTH:
  1894. bit = gc->state.enables.general & __GL_POLYGON_SMOOTH_ENABLE;
  1895. break;
  1896. case GL_POLYGON_STIPPLE:
  1897. bit = gc->state.enables.general & __GL_POLYGON_STIPPLE_ENABLE;
  1898. break;
  1899. case GL_SCISSOR_TEST:
  1900. bit = gc->state.enables.general & __GL_SCISSOR_TEST_ENABLE;
  1901. break;
  1902. case GL_STENCIL_TEST:
  1903. bit = gc->state.enables.general & __GL_STENCIL_TEST_ENABLE;
  1904. break;
  1905. case GL_TEXTURE_1D:
  1906. bit = gc->state.enables.general & __GL_TEXTURE_1D_ENABLE;
  1907. break;
  1908. case GL_TEXTURE_2D:
  1909. bit = gc->state.enables.general & __GL_TEXTURE_2D_ENABLE;
  1910. break;
  1911. case GL_AUTO_NORMAL:
  1912. bit = gc->state.enables.general & __GL_AUTO_NORMAL_ENABLE;
  1913. break;
  1914. case GL_TEXTURE_GEN_S:
  1915. bit = gc->state.enables.general & __GL_TEXTURE_GEN_S_ENABLE;
  1916. break;
  1917. case GL_TEXTURE_GEN_T:
  1918. bit = gc->state.enables.general & __GL_TEXTURE_GEN_T_ENABLE;
  1919. break;
  1920. case GL_TEXTURE_GEN_R:
  1921. bit = gc->state.enables.general & __GL_TEXTURE_GEN_R_ENABLE;
  1922. break;
  1923. case GL_TEXTURE_GEN_Q:
  1924. bit = gc->state.enables.general & __GL_TEXTURE_GEN_Q_ENABLE;
  1925. break;
  1926. #ifdef GL_WIN_multiple_textures
  1927. case GL_TEXCOMBINE_CLAMP_WIN:
  1928. bit = gc->state.enables.general & __GL_TEXCOMBINE_CLAMP_ENABLE;
  1929. break;
  1930. #endif // GL_WIN_multiple_textures
  1931. #ifdef GL_EXT_flat_paletted_lighting
  1932. case GL_PALETTED_LIGHTING_EXT:
  1933. bit = gc->state.enables.general & __GL_PALETTED_LIGHTING_ENABLE;
  1934. break;
  1935. #endif // GL_EXT_flat_paletted_lighting
  1936. case GL_CLIP_PLANE0: case GL_CLIP_PLANE1:
  1937. case GL_CLIP_PLANE2: case GL_CLIP_PLANE3:
  1938. case GL_CLIP_PLANE4: case GL_CLIP_PLANE5:
  1939. cap -= GL_CLIP_PLANE0;
  1940. bit = gc->state.enables.clipPlanes & (1 << cap);
  1941. break;
  1942. case GL_LIGHT0: case GL_LIGHT1:
  1943. case GL_LIGHT2: case GL_LIGHT3:
  1944. case GL_LIGHT4: case GL_LIGHT5:
  1945. case GL_LIGHT6: case GL_LIGHT7:
  1946. cap -= GL_LIGHT0;
  1947. bit = gc->state.enables.lights & (1 << cap);
  1948. break;
  1949. case GL_MAP1_COLOR_4:
  1950. case GL_MAP1_NORMAL:
  1951. case GL_MAP1_INDEX:
  1952. case GL_MAP1_TEXTURE_COORD_1: case GL_MAP1_TEXTURE_COORD_2:
  1953. case GL_MAP1_TEXTURE_COORD_3: case GL_MAP1_TEXTURE_COORD_4:
  1954. case GL_MAP1_VERTEX_3: case GL_MAP1_VERTEX_4:
  1955. cap = __GL_EVAL1D_INDEX(cap);
  1956. bit = gc->state.enables.eval1 & (1 << cap);
  1957. break;
  1958. case GL_MAP2_COLOR_4:
  1959. case GL_MAP2_NORMAL:
  1960. case GL_MAP2_INDEX:
  1961. case GL_MAP2_TEXTURE_COORD_1: case GL_MAP2_TEXTURE_COORD_2:
  1962. case GL_MAP2_TEXTURE_COORD_3: case GL_MAP2_TEXTURE_COORD_4:
  1963. case GL_MAP2_VERTEX_3: case GL_MAP2_VERTEX_4:
  1964. cap = __GL_EVAL2D_INDEX(cap);
  1965. bit = gc->state.enables.eval2 & (1 << cap);
  1966. break;
  1967. case GL_VERTEX_ARRAY:
  1968. case GL_NORMAL_ARRAY:
  1969. case GL_COLOR_ARRAY:
  1970. case GL_INDEX_ARRAY:
  1971. case GL_TEXTURE_COORD_ARRAY:
  1972. case GL_EDGE_FLAG_ARRAY:
  1973. bit = gc->vertexArray.mask & vaEnable[cap - GL_VERTEX_ARRAY];
  1974. break;
  1975. default:
  1976. __glSetError(GL_INVALID_ENUM);
  1977. return GL_FALSE;
  1978. }
  1979. return bit != 0;
  1980. }
  1981. void APIPRIVATE __glim_PolygonOffset(GLfloat factor, GLfloat units)
  1982. {
  1983. __GL_SETUP_NOT_IN_BEGIN();
  1984. if (__GL_FLOAT_NE (gc->state.polygon.factor, factor) ||
  1985. __GL_FLOAT_NE (gc->state.polygon.units, units))
  1986. {
  1987. gc->state.polygon.factor = factor;
  1988. gc->state.polygon.units = units;
  1989. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_POLYGON);
  1990. #ifdef _MCD_
  1991. MCD_STATE_DIRTY(gc, POLYDRAW);
  1992. #endif
  1993. }
  1994. }