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.

904 lines
26 KiB

  1. /*
  2. ** Copyright 1991,1992, 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 "gencx.h"
  20. #include "imfuncs.h"
  21. /*
  22. ** Initialize pixel map with default size and value.
  23. */
  24. void FASTCALL __glInitDefaultPixelMap(__GLcontext *gc, GLenum map)
  25. {
  26. __GLpixelState *ps = &gc->state.pixel;
  27. __GLpixelMapHead *pMap = ps->pixelMap;
  28. GLint index = map - GL_PIXEL_MAP_I_TO_I;
  29. #ifdef _MCD_
  30. __GLGENcontext *gengc = (__GLGENcontext *) gc;
  31. #endif
  32. switch (map) {
  33. case GL_PIXEL_MAP_I_TO_I:
  34. case GL_PIXEL_MAP_S_TO_S:
  35. /*
  36. ** Allocate single-entry map for index type.
  37. */
  38. if (!(pMap[index].base.mapI = (GLint*)
  39. GCALLOC(gc, sizeof(GLint)))) {
  40. return;
  41. } else {
  42. pMap[index].base.mapI[0] = 0;
  43. pMap[index].size = 1;
  44. #ifdef _MCD_
  45. if (gengc->pMcdState)
  46. GenMcdPixelMap(gengc, map, 1, (VOID *) pMap[index].base.mapI);
  47. #endif
  48. }
  49. break;
  50. case GL_PIXEL_MAP_I_TO_R: case GL_PIXEL_MAP_I_TO_G:
  51. case GL_PIXEL_MAP_I_TO_B: case GL_PIXEL_MAP_I_TO_A:
  52. case GL_PIXEL_MAP_R_TO_R: case GL_PIXEL_MAP_G_TO_G:
  53. case GL_PIXEL_MAP_B_TO_B: case GL_PIXEL_MAP_A_TO_A:
  54. /*
  55. ** Allocate single-entry map for component type.
  56. */
  57. if (!(pMap[index].base.mapF = (__GLfloat*)
  58. GCALLOC(gc, sizeof(__GLfloat)))) {
  59. return;
  60. } else {
  61. pMap[index].base.mapF[0] = __glZero;
  62. pMap[index].size = 1;
  63. #ifdef _MCD_
  64. if (gengc->pMcdState)
  65. GenMcdPixelMap(gengc, map, 1, (VOID *) pMap[index].base.mapF);
  66. #endif
  67. }
  68. break;
  69. default:
  70. __glSetError(GL_INVALID_ENUM);
  71. return;
  72. }
  73. }
  74. void FASTCALL __glPixelSetColorScales(__GLcontext *gc)
  75. {
  76. __GLpixelMachine *pm = &gc->pixel;
  77. GLfloat redScale, greenScale, blueScale, alphaScale;
  78. int i;
  79. GLint mask;
  80. if (pm->redMap == NULL) {
  81. /* First time allocation of these maps */
  82. /*
  83. ** These lookup tables are for type UNSIGNED_BYTE, so they are sized
  84. ** to 256 entries. They map from UNSIGNED_BYTE to internal scaled
  85. ** floating point colors.
  86. */
  87. #ifdef NT
  88. pm->redMap =
  89. (GLfloat*) GCALLOC(gc, 5 * 256 * sizeof(GLfloat));
  90. if (!pm->redMap)
  91. return;
  92. pm->greenMap = pm->redMap + 1 * 256;
  93. pm->blueMap = pm->redMap + 2 * 256;
  94. pm->alphaMap = pm->redMap + 3 * 256;
  95. pm->iMap = pm->redMap + 4 * 256;
  96. #else
  97. pm->redMap =
  98. (GLfloat*) GCALLOC(gc, 256 * sizeof(GLfloat));
  99. pm->greenMap =
  100. (GLfloat*) GCALLOC(gc, 256 * sizeof(GLfloat));
  101. pm->blueMap =
  102. (GLfloat*) GCALLOC(gc, 256 * sizeof(GLfloat));
  103. pm->alphaMap =
  104. (GLfloat*) GCALLOC(gc, 256 * sizeof(GLfloat));
  105. pm->iMap =
  106. (GLfloat*) GCALLOC(gc, 256 * sizeof(GLfloat));
  107. #endif
  108. }
  109. redScale = gc->frontBuffer.redScale / 255;
  110. greenScale = gc->frontBuffer.greenScale / 255;
  111. blueScale = gc->frontBuffer.blueScale / 255;
  112. alphaScale = gc->frontBuffer.alphaScale / 255;
  113. mask = gc->frontBuffer.redMax;
  114. for (i=0; i<256; i++) {
  115. pm->redMap[i] = i * redScale;
  116. pm->greenMap[i] = i * greenScale;
  117. pm->blueMap[i] = i * blueScale;
  118. pm->alphaMap[i] = i * alphaScale;
  119. pm->iMap[i] = (GLfloat) (i & mask);
  120. }
  121. /*
  122. ** Invalidate the RGBA modify tables so that they will be
  123. ** recomputed using the current color buffer scales.
  124. */
  125. pm->rgbaCurrent = GL_FALSE;
  126. }
  127. /************************************************************************/
  128. void FASTCALL __glFreePixelState(__GLcontext *gc)
  129. {
  130. __GLpixelState *ps = &gc->state.pixel;
  131. __GLpixelMapHead *pMap = ps->pixelMap;
  132. __GLpixelMachine *pm = &gc->pixel;
  133. GLenum m;
  134. GLint i;
  135. /*
  136. ** Free memory allocated to pixel maps.
  137. */
  138. for (m = GL_PIXEL_MAP_I_TO_I; m <= GL_PIXEL_MAP_A_TO_A; m++) {
  139. i = m - GL_PIXEL_MAP_I_TO_I;
  140. if (pMap[i].base.mapI) {
  141. GCFREE(gc, pMap[i].base.mapI);
  142. pMap[i].base.mapI = 0;
  143. }
  144. }
  145. #ifdef NT
  146. // This includes red, green, blue, alpha and i maps.
  147. GCFREE(gc, pm->redMap);
  148. #else
  149. GCFREE(gc, pm->redMap);
  150. GCFREE(gc, pm->greenMap);
  151. GCFREE(gc, pm->blueMap);
  152. GCFREE(gc, pm->alphaMap);
  153. GCFREE(gc, pm->iMap);
  154. #endif
  155. if (pm->redModMap) {
  156. #ifdef NT
  157. // This includes red, green, blue and alpha mod maps.
  158. GCFREE(gc, pm->redModMap);
  159. #else
  160. GCFREE(gc, pm->redModMap);
  161. GCFREE(gc, pm->greenModMap);
  162. GCFREE(gc, pm->blueModMap);
  163. GCFREE(gc, pm->alphaModMap);
  164. #endif
  165. }
  166. if (pm->iToRMap) {
  167. #ifdef NT
  168. // This includes iToR, iToG, iToB and iToA maps.
  169. GCFREE(gc, pm->iToRMap);
  170. #else
  171. GCFREE(gc, pm->iToRMap);
  172. GCFREE(gc, pm->iToGMap);
  173. GCFREE(gc, pm->iToBMap);
  174. GCFREE(gc, pm->iToAMap);
  175. #endif
  176. }
  177. if (pm->iToIMap) {
  178. GCFREE(gc, pm->iToIMap);
  179. }
  180. }
  181. void FASTCALL __glInitPixelState(__GLcontext *gc)
  182. {
  183. __GLpixelState *ps = &gc->state.pixel;
  184. __GLpixelMachine *pm = &gc->pixel;
  185. GLenum m;
  186. /*
  187. ** Initialize transfer mode.
  188. */
  189. ps->transferMode.r_scale = __glOne;
  190. ps->transferMode.g_scale = __glOne;
  191. ps->transferMode.b_scale = __glOne;
  192. ps->transferMode.a_scale = __glOne;
  193. ps->transferMode.d_scale = __glOne;
  194. ps->transferMode.zoomX = __glOne;
  195. ps->transferMode.zoomY = __glOne;
  196. /*
  197. ** Initialize pixel maps with default sizes and values.
  198. */
  199. for (m = GL_PIXEL_MAP_I_TO_I; m <= GL_PIXEL_MAP_A_TO_A; m++) {
  200. __glInitDefaultPixelMap(gc, m);
  201. }
  202. /*
  203. ** Initialize store mode.
  204. */
  205. ps->packModes.alignment = 4;
  206. ps->unpackModes.alignment = 4;
  207. /* Setup to use the correct read buffer */
  208. if (gc->modes.doubleBufferMode) {
  209. ps->readBuffer = GL_BACK;
  210. } else {
  211. ps->readBuffer = GL_FRONT;
  212. }
  213. ps->readBufferReturn = ps->readBuffer;
  214. /* Lookup tables used by some pixel routines */
  215. __glPixelSetColorScales(gc);
  216. #ifdef _MCD_
  217. MCD_STATE_DIRTY(gc, PIXELSTATE);
  218. #endif
  219. }
  220. /************************************************************************/
  221. /*
  222. ** Specify modes that control the storage format of pixel arrays.
  223. */
  224. void APIPRIVATE __glim_PixelStoref(GLenum mode, GLfloat value)
  225. {
  226. switch (mode) {
  227. case GL_PACK_ROW_LENGTH:
  228. case GL_PACK_SKIP_ROWS:
  229. case GL_PACK_SKIP_PIXELS:
  230. case GL_PACK_ALIGNMENT:
  231. case GL_UNPACK_ROW_LENGTH:
  232. case GL_UNPACK_SKIP_ROWS:
  233. case GL_UNPACK_SKIP_PIXELS:
  234. case GL_UNPACK_ALIGNMENT:
  235. /* Round */
  236. if (value < 0) {
  237. __glim_PixelStorei(mode, (GLint) (value - (__GLfloat) 0.5));
  238. } else {
  239. __glim_PixelStorei(mode, (GLint) (value + (__GLfloat) 0.5));
  240. }
  241. break;
  242. case GL_PACK_SWAP_BYTES:
  243. case GL_PACK_LSB_FIRST:
  244. case GL_UNPACK_SWAP_BYTES:
  245. case GL_UNPACK_LSB_FIRST:
  246. if (value == __glZero) {
  247. __glim_PixelStorei(mode, GL_FALSE);
  248. } else {
  249. __glim_PixelStorei(mode, GL_TRUE);
  250. }
  251. default:
  252. __glim_PixelStorei(mode, (GLint) value);
  253. break;
  254. }
  255. }
  256. void APIPRIVATE __glim_PixelStorei(GLenum mode, GLint value)
  257. {
  258. __GLpixelState *ps;
  259. __GL_SETUP_NOT_IN_BEGIN();
  260. ps = &gc->state.pixel;
  261. switch (mode) {
  262. case GL_PACK_ROW_LENGTH:
  263. if (value < 0) {
  264. __glSetError(GL_INVALID_VALUE);
  265. return;
  266. }
  267. if (ps->packModes.lineLength == (GLuint) value) return;
  268. ps->packModes.lineLength = (GLuint) value;
  269. break;
  270. case GL_PACK_SKIP_ROWS:
  271. if (value < 0) {
  272. __glSetError(GL_INVALID_VALUE);
  273. return;
  274. }
  275. if (ps->packModes.skipLines == (GLuint) value) return;
  276. ps->packModes.skipLines = (GLuint) value;
  277. break;
  278. case GL_PACK_SKIP_PIXELS:
  279. if (value < 0) {
  280. __glSetError(GL_INVALID_VALUE);
  281. return;
  282. }
  283. if (ps->packModes.skipPixels == (GLuint) value) return;
  284. ps->packModes.skipPixels = (GLuint) value;
  285. break;
  286. case GL_PACK_ALIGNMENT:
  287. switch (value) {
  288. case 1: case 2: case 4: case 8:
  289. if (ps->packModes.alignment == (GLuint) value) return;
  290. ps->packModes.alignment = (GLuint) value;
  291. break;
  292. default:
  293. __glSetError(GL_INVALID_VALUE);
  294. return;
  295. }
  296. break;
  297. case GL_PACK_SWAP_BYTES:
  298. if (ps->packModes.swapEndian == (value != 0)) return;
  299. ps->packModes.swapEndian = (value != 0);
  300. break;
  301. case GL_PACK_LSB_FIRST:
  302. if (ps->packModes.lsbFirst == (value != 0)) return;
  303. ps->packModes.lsbFirst = (value != 0);
  304. break;
  305. case GL_UNPACK_ROW_LENGTH:
  306. if (value < 0) {
  307. __glSetError(GL_INVALID_VALUE);
  308. return;
  309. }
  310. if (ps->unpackModes.lineLength == (GLuint) value) return;
  311. ps->unpackModes.lineLength = (GLuint) value;
  312. break;
  313. case GL_UNPACK_SKIP_ROWS:
  314. if (value < 0) {
  315. __glSetError(GL_INVALID_VALUE);
  316. return;
  317. }
  318. if (ps->unpackModes.skipLines == (GLuint) value) return;
  319. ps->unpackModes.skipLines = (GLuint) value;
  320. break;
  321. case GL_UNPACK_SKIP_PIXELS:
  322. if (value < 0) {
  323. __glSetError(GL_INVALID_VALUE);
  324. return;
  325. }
  326. if (ps->unpackModes.skipPixels == (GLuint) value) return;
  327. ps->unpackModes.skipPixels = (GLuint) value;
  328. break;
  329. case GL_UNPACK_ALIGNMENT:
  330. switch (value) {
  331. case 1: case 2: case 4: case 8:
  332. if (ps->unpackModes.alignment == (GLuint) value) return;
  333. ps->unpackModes.alignment = (GLuint) value;
  334. break;
  335. default:
  336. __glSetError(GL_INVALID_VALUE);
  337. return;
  338. }
  339. break;
  340. case GL_UNPACK_SWAP_BYTES:
  341. if (ps->unpackModes.swapEndian == (value != 0)) return;
  342. ps->unpackModes.swapEndian = (value != 0);
  343. break;
  344. case GL_UNPACK_LSB_FIRST:
  345. if (ps->unpackModes.lsbFirst == (value != 0)) return;
  346. ps->unpackModes.lsbFirst = (value != 0);
  347. break;
  348. default:
  349. __glSetError(GL_INVALID_ENUM);
  350. return;
  351. }
  352. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_PIXEL);
  353. #ifdef _MCD_
  354. MCD_STATE_DIRTY(gc, PIXELSTATE);
  355. #endif
  356. }
  357. /*
  358. ** Specify zoom factor that affects drawing and copying of pixel arrays
  359. */
  360. void APIPRIVATE __glim_PixelZoom(GLfloat xfactor, GLfloat yfactor)
  361. {
  362. __GLpixelState *ps;
  363. GLint xtemp, ytemp;
  364. __GL_SETUP_NOT_IN_BEGIN();
  365. ps = &gc->state.pixel;
  366. /* Round xfactor and yfactor to fixed point accuracy. */
  367. if (xfactor > 0) {
  368. xtemp = (GLint) ((xfactor / gc->constants.viewportEpsilon) + __glHalf);
  369. } else {
  370. xtemp = (GLint) ((xfactor / gc->constants.viewportEpsilon) - __glHalf);
  371. }
  372. if (yfactor > 0) {
  373. ytemp = (GLint) ((yfactor / gc->constants.viewportEpsilon) + __glHalf);
  374. } else {
  375. ytemp = (GLint) ((yfactor / gc->constants.viewportEpsilon) - __glHalf);
  376. }
  377. xfactor = xtemp * gc->constants.viewportEpsilon;
  378. yfactor = ytemp * gc->constants.viewportEpsilon;
  379. if ((ps->transferMode.zoomX == xfactor) &&
  380. (ps->transferMode.zoomY == yfactor))
  381. return;
  382. ps->transferMode.zoomX = xfactor;
  383. ps->transferMode.zoomY = yfactor;
  384. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_PIXEL);
  385. #ifdef _MCD_
  386. MCD_STATE_DIRTY(gc, PIXELSTATE);
  387. #endif
  388. }
  389. /*
  390. ** Specify modes that control the transfer of pixel arrays.
  391. */
  392. void APIPRIVATE __glim_PixelTransferf(GLenum mode, GLfloat value)
  393. {
  394. __GLpixelState *ps;
  395. __GL_SETUP_NOT_IN_BEGIN();
  396. ps = &gc->state.pixel;
  397. switch (mode) {
  398. case GL_RED_SCALE:
  399. if (ps->transferMode.r_scale == value) return;
  400. ps->transferMode.r_scale = value;
  401. break;
  402. case GL_GREEN_SCALE:
  403. if (ps->transferMode.g_scale == value) return;
  404. ps->transferMode.g_scale = value;
  405. break;
  406. case GL_BLUE_SCALE:
  407. if (ps->transferMode.b_scale == value) return;
  408. ps->transferMode.b_scale = value;
  409. break;
  410. case GL_ALPHA_SCALE:
  411. if (ps->transferMode.a_scale == value) return;
  412. ps->transferMode.a_scale = value;
  413. break;
  414. case GL_DEPTH_SCALE:
  415. if (ps->transferMode.d_scale == value) return;
  416. ps->transferMode.d_scale = value;
  417. break;
  418. case GL_RED_BIAS:
  419. if (ps->transferMode.r_bias == value) return;
  420. ps->transferMode.r_bias = value;
  421. break;
  422. case GL_GREEN_BIAS:
  423. if (ps->transferMode.g_bias == value) return;
  424. ps->transferMode.g_bias = value;
  425. break;
  426. case GL_BLUE_BIAS:
  427. if (ps->transferMode.b_bias == value) return;
  428. ps->transferMode.b_bias = value;
  429. break;
  430. case GL_ALPHA_BIAS:
  431. if (ps->transferMode.a_bias == value) return;
  432. ps->transferMode.a_bias = value;
  433. break;
  434. case GL_DEPTH_BIAS:
  435. if (ps->transferMode.d_bias == value) return;
  436. ps->transferMode.d_bias = value;
  437. break;
  438. case GL_INDEX_SHIFT:
  439. {
  440. GLint tmp;
  441. /* Round */
  442. if (value > 0) {
  443. tmp = (GLint) (value + __glHalf);
  444. } else {
  445. tmp = (GLint) (value - __glHalf);
  446. }
  447. if (ps->transferMode.indexShift == tmp) return;
  448. ps->transferMode.indexShift = tmp;
  449. break;
  450. }
  451. case GL_INDEX_OFFSET:
  452. {
  453. GLint tmp;
  454. /* Round */
  455. if (value > 0) {
  456. tmp = (GLint) (value - __glHalf);
  457. } else {
  458. tmp = (GLint) (value - __glHalf);
  459. }
  460. if (ps->transferMode.indexOffset == tmp) return;
  461. ps->transferMode.indexOffset = tmp;
  462. break;
  463. }
  464. case GL_MAP_COLOR:
  465. if (ps->transferMode.mapColor == (value != __glZero)) return;
  466. ps->transferMode.mapColor = (value != __glZero);
  467. break;
  468. case GL_MAP_STENCIL:
  469. if (ps->transferMode.mapStencil == (value != __glZero)) return;
  470. ps->transferMode.mapStencil = (value != __glZero);
  471. break;
  472. default:
  473. __glSetError(GL_INVALID_ENUM);
  474. return;
  475. }
  476. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_PIXEL);
  477. #ifdef _MCD_
  478. MCD_STATE_DIRTY(gc, PIXELSTATE);
  479. #endif
  480. }
  481. void APIPRIVATE __glim_PixelTransferi( GLenum mode, GLint value)
  482. {
  483. __glim_PixelTransferf(mode, (GLfloat) value);
  484. }
  485. /************************************************************************/
  486. /*
  487. ** Functions to specify mapping of pixel colors and stencil values.
  488. */
  489. void APIPRIVATE __glim_PixelMapfv(GLenum map, GLint mapSize,
  490. const GLfloat values[])
  491. {
  492. __GLpixelState *ps;
  493. __GLpixelMapHead *pMap;
  494. GLint index = map - GL_PIXEL_MAP_I_TO_I;
  495. GLfloat value;
  496. #ifdef _MCD_
  497. __GLGENcontext *gengc;
  498. #endif
  499. __GL_SETUP_NOT_IN_BEGIN();
  500. #ifdef _MCD_
  501. gengc = (__GLGENcontext *) gc;
  502. #endif
  503. ps = &gc->state.pixel;
  504. pMap = ps->pixelMap;
  505. switch (map) {
  506. case GL_PIXEL_MAP_I_TO_I:
  507. case GL_PIXEL_MAP_S_TO_S:
  508. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  509. /*
  510. ** Maps indexed by color or stencil index must be sized
  511. ** to a power of two.
  512. */
  513. __glSetError(GL_INVALID_VALUE);
  514. return;
  515. }
  516. if (pMap[index].base.mapI) {
  517. GCFREE(gc, pMap[index].base.mapI);
  518. pMap[index].base.mapI = 0;
  519. }
  520. pMap[index].base.mapI = (GLint*)
  521. GCALLOC(gc, (size_t) (mapSize * sizeof(GLint)));
  522. if (!pMap[index].base.mapI) {
  523. pMap[index].size = 0;
  524. return;
  525. }
  526. pMap[index].size = mapSize;
  527. while (--mapSize >= 0) {
  528. value = values[mapSize];
  529. if (value > 0) { /* round! */
  530. pMap[index].base.mapI[mapSize] =
  531. (GLint)(value + __glHalf);
  532. } else {
  533. pMap[index].base.mapI[mapSize] =
  534. (GLint)(value - __glHalf);
  535. }
  536. }
  537. #ifdef _MCD_
  538. if (gengc->pMcdState) {
  539. GenMcdPixelMap(gengc, map, mapSize,
  540. (VOID *) pMap[index].base.mapI);
  541. }
  542. #endif
  543. break;
  544. case GL_PIXEL_MAP_I_TO_R:
  545. case GL_PIXEL_MAP_I_TO_G:
  546. case GL_PIXEL_MAP_I_TO_B:
  547. case GL_PIXEL_MAP_I_TO_A:
  548. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  549. /*
  550. ** Maps indexed by color or stencil index must be sized
  551. ** to a power of two.
  552. */
  553. __glSetError(GL_INVALID_VALUE);
  554. return;
  555. }
  556. case GL_PIXEL_MAP_R_TO_R:
  557. case GL_PIXEL_MAP_G_TO_G:
  558. case GL_PIXEL_MAP_B_TO_B:
  559. case GL_PIXEL_MAP_A_TO_A:
  560. if (mapSize < 0) {
  561. /*
  562. ** Maps indexed by color component must not have negative size.
  563. */
  564. __glSetError(GL_INVALID_VALUE);
  565. return;
  566. }
  567. if (pMap[index].base.mapF) {
  568. GCFREE(gc, pMap[index].base.mapF);
  569. pMap[index].base.mapF = 0;
  570. }
  571. if (mapSize == 0) {
  572. __glInitDefaultPixelMap(gc, map);
  573. } else {
  574. pMap[index].base.mapF = (__GLfloat*)
  575. GCALLOC(gc,
  576. (size_t) (mapSize * sizeof(__GLfloat)));
  577. if (!pMap[index].base.mapF) {
  578. pMap[index].size = 0;
  579. return;
  580. }
  581. pMap[index].size = mapSize;
  582. while (--mapSize >= 0) {
  583. value = values[mapSize];
  584. if (value < __glZero) value = __glZero;
  585. else if (value > __glOne) value = __glOne;
  586. pMap[index].base.mapF[mapSize] = value;
  587. }
  588. #ifdef _MCD_
  589. if (gengc->pMcdState) {
  590. GenMcdPixelMap(gengc, map, mapSize,
  591. (VOID *) pMap[index].base.mapF);
  592. }
  593. #endif
  594. }
  595. break;
  596. default:
  597. __glSetError(GL_INVALID_ENUM);
  598. return;
  599. }
  600. }
  601. void APIPRIVATE __glim_PixelMapuiv(GLenum map, GLint mapSize,
  602. const GLuint values[])
  603. {
  604. __GLpixelState *ps;
  605. __GLpixelMapHead *pMap;
  606. GLint index = map - GL_PIXEL_MAP_I_TO_I;
  607. #ifdef _MCD_
  608. __GLGENcontext *gengc;
  609. #endif
  610. __GL_SETUP_NOT_IN_BEGIN();
  611. #ifdef _MCD_
  612. gengc = (__GLGENcontext *) gc;
  613. #endif
  614. ps = &gc->state.pixel;
  615. pMap = ps->pixelMap;
  616. switch (map) {
  617. case GL_PIXEL_MAP_I_TO_I:
  618. case GL_PIXEL_MAP_S_TO_S:
  619. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  620. /*
  621. ** Maps indexed by color or stencil index must be sized
  622. ** to a power of two.
  623. */
  624. __glSetError(GL_INVALID_VALUE);
  625. return;
  626. }
  627. if (pMap[index].base.mapI) {
  628. GCFREE(gc, pMap[index].base.mapI);
  629. pMap[index].base.mapI = 0;
  630. }
  631. pMap[index].base.mapI = (GLint*)
  632. GCALLOC(gc, (size_t) (mapSize * sizeof(GLint)));
  633. if (!pMap[index].base.mapI) {
  634. pMap[index].size = 0;
  635. return;
  636. }
  637. pMap[index].size = mapSize;
  638. while (--mapSize >= 0) {
  639. pMap[index].base.mapI[mapSize] = values[mapSize];
  640. }
  641. #ifdef _MCD_
  642. if (gengc->pMcdState) {
  643. GenMcdPixelMap(gengc, map, mapSize,
  644. (VOID *) pMap[index].base.mapI);
  645. }
  646. #endif
  647. break;
  648. case GL_PIXEL_MAP_I_TO_R:
  649. case GL_PIXEL_MAP_I_TO_G:
  650. case GL_PIXEL_MAP_I_TO_B:
  651. case GL_PIXEL_MAP_I_TO_A:
  652. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  653. /*
  654. ** Maps indexed by color or stencil index must be sized
  655. ** to a power of two.
  656. */
  657. __glSetError(GL_INVALID_VALUE);
  658. return;
  659. }
  660. case GL_PIXEL_MAP_R_TO_R:
  661. case GL_PIXEL_MAP_G_TO_G:
  662. case GL_PIXEL_MAP_B_TO_B:
  663. case GL_PIXEL_MAP_A_TO_A:
  664. if (mapSize < 0) {
  665. /*
  666. ** Maps indexed by color component must not have negative size.
  667. */
  668. __glSetError(GL_INVALID_VALUE);
  669. return;
  670. }
  671. if (pMap[index].base.mapF) {
  672. GCFREE(gc, pMap[index].base.mapF);
  673. pMap[index].base.mapF = 0;
  674. }
  675. if (mapSize == 0) {
  676. __glInitDefaultPixelMap(gc, map);
  677. } else {
  678. pMap[index].base.mapF = (__GLfloat*)
  679. GCALLOC(gc, (size_t) (mapSize * sizeof(GLfloat)));
  680. if (!pMap[index].base.mapF) {
  681. pMap[index].size = 0;
  682. return;
  683. }
  684. pMap[index].size = mapSize;
  685. while (--mapSize >= 0) {
  686. pMap[index].base.mapF[mapSize] =
  687. __GL_UI_TO_FLOAT(values[mapSize]);
  688. }
  689. #ifdef _MCD_
  690. if (gengc->pMcdState) {
  691. GenMcdPixelMap(gengc, map, mapSize,
  692. (VOID *) pMap[index].base.mapF);
  693. }
  694. #endif
  695. }
  696. break;
  697. default:
  698. __glSetError(GL_INVALID_ENUM);
  699. return;
  700. }
  701. }
  702. void APIPRIVATE __glim_PixelMapusv(GLenum map, GLint mapSize,
  703. const GLushort values[])
  704. {
  705. __GLpixelState *ps;
  706. __GLpixelMapHead *pMap;
  707. GLint index = map - GL_PIXEL_MAP_I_TO_I;
  708. #ifdef _MCD_
  709. __GLGENcontext *gengc;
  710. #endif
  711. __GL_SETUP_NOT_IN_BEGIN();
  712. #ifdef _MCD_
  713. gengc = (__GLGENcontext *) gc;
  714. #endif
  715. ps = &gc->state.pixel;
  716. pMap = ps->pixelMap;
  717. switch (map) {
  718. case GL_PIXEL_MAP_I_TO_I:
  719. case GL_PIXEL_MAP_S_TO_S:
  720. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  721. /*
  722. ** Maps indexed by color or stencil index must be sized
  723. ** to a power of two.
  724. */
  725. __glSetError(GL_INVALID_VALUE);
  726. return;
  727. }
  728. if (pMap[index].base.mapI) {
  729. GCFREE(gc, pMap[index].base.mapI);
  730. pMap[index].base.mapI = 0;
  731. }
  732. pMap[index].base.mapI = (GLint*)
  733. GCALLOC(gc, (size_t) (mapSize * sizeof(GLint)));
  734. if (!pMap[index].base.mapI) {
  735. pMap[index].size = 0;
  736. return;
  737. }
  738. pMap[index].size = mapSize;
  739. while (--mapSize >= 0) {
  740. pMap[index].base.mapI[mapSize] = values[mapSize];
  741. }
  742. #ifdef _MCD_
  743. if (gengc->pMcdState) {
  744. GenMcdPixelMap(gengc, map, mapSize,
  745. (VOID *) pMap[index].base.mapI);
  746. }
  747. #endif
  748. break;
  749. case GL_PIXEL_MAP_I_TO_R:
  750. case GL_PIXEL_MAP_I_TO_G:
  751. case GL_PIXEL_MAP_I_TO_B:
  752. case GL_PIXEL_MAP_I_TO_A:
  753. if (mapSize <= 0 || (mapSize & (mapSize - 1))) {
  754. /*
  755. ** Maps indexed by color or stencil index must be sized
  756. ** to a power of two.
  757. */
  758. __glSetError(GL_INVALID_VALUE);
  759. return;
  760. }
  761. case GL_PIXEL_MAP_R_TO_R:
  762. case GL_PIXEL_MAP_G_TO_G:
  763. case GL_PIXEL_MAP_B_TO_B:
  764. case GL_PIXEL_MAP_A_TO_A:
  765. if (mapSize < 0) {
  766. /*
  767. ** Maps indexed by color component must not have negative size.
  768. */
  769. __glSetError(GL_INVALID_VALUE);
  770. return;
  771. }
  772. if (pMap[index].base.mapF) {
  773. GCFREE(gc, pMap[index].base.mapF);
  774. pMap[index].base.mapF = 0;
  775. }
  776. if (mapSize == 0) {
  777. __glInitDefaultPixelMap(gc, map);
  778. } else {
  779. pMap[index].base.mapF = (__GLfloat*)
  780. GCALLOC(gc, (size_t) (mapSize * sizeof(GLfloat)));
  781. if (!pMap[index].base.mapF) {
  782. pMap[index].size = 0;
  783. return;
  784. }
  785. pMap[index].size = mapSize;
  786. while (--mapSize >= 0) {
  787. pMap[index].base.mapF[mapSize] =
  788. __GL_US_TO_FLOAT(values[mapSize]);
  789. }
  790. #ifdef _MCD_
  791. if (gengc->pMcdState) {
  792. GenMcdPixelMap(gengc, map, mapSize,
  793. (VOID *) pMap[index].base.mapF);
  794. }
  795. #endif
  796. }
  797. break;
  798. default:
  799. __glSetError(GL_INVALID_ENUM);
  800. return;
  801. }
  802. }
  803. /*
  804. ** Specify buffer from which pixels are read (another transfer mode).
  805. */
  806. void APIPRIVATE __glim_ReadBuffer(GLenum mode)
  807. {
  808. GLint i;
  809. __GL_SETUP_NOT_IN_BEGIN();
  810. switch (mode) {
  811. case GL_FRONT:
  812. case GL_LEFT:
  813. case GL_FRONT_LEFT:
  814. gc->state.pixel.readBuffer = GL_FRONT;
  815. break;
  816. case GL_BACK:
  817. case GL_BACK_LEFT:
  818. if (!gc->modes.doubleBufferMode) {
  819. __glSetError(GL_INVALID_OPERATION);
  820. return;
  821. }
  822. gc->state.pixel.readBuffer = GL_BACK;
  823. break;
  824. case GL_AUX0:
  825. case GL_AUX1:
  826. case GL_AUX2:
  827. case GL_AUX3:
  828. i = mode - GL_AUX0;
  829. if (i >= gc->modes.maxAuxBuffers) {
  830. __glSetError(GL_INVALID_OPERATION);
  831. return;
  832. }
  833. gc->state.pixel.readBuffer = mode;
  834. break;
  835. case GL_FRONT_RIGHT:
  836. case GL_BACK_RIGHT:
  837. case GL_RIGHT:
  838. __glSetError(GL_INVALID_OPERATION);
  839. return;
  840. default:
  841. __glSetError(GL_INVALID_ENUM);
  842. return;
  843. }
  844. if (gc->state.pixel.readBufferReturn == mode) return;
  845. gc->state.pixel.readBufferReturn = mode;
  846. __GL_DELAY_VALIDATE_MASK(gc, __GL_DIRTY_PIXEL);
  847. #ifdef _MCD_
  848. MCD_STATE_DIRTY(gc, PIXELSTATE);
  849. #endif
  850. }