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.

897 lines
29 KiB

  1. /*
  2. ** Copyright 1995-2095, 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 "glslib.h"
  18. #include <limits.h>
  19. #include <locale.h>
  20. #include <math.h>
  21. #include <string.h>
  22. /******************************************************************************
  23. Helpers
  24. ******************************************************************************/
  25. #define __GLS_ALLOC(inoutWriter, inReturn) \
  26. if ( \
  27. inoutWriter->bufPtr >= inoutWriter->bufTail && \
  28. !__glsWriter_flush(inoutWriter) \
  29. ) { \
  30. return inReturn; \
  31. }
  32. #define __GLS_PARAM_SEP(inoutWriter) \
  33. if (inoutWriter->paramCount++) { \
  34. __GLS_PUT_CHAR(inoutWriter, ','); \
  35. __GLS_PUT_CHAR(inoutWriter, ' '); \
  36. }
  37. #define __GLS_PARAM_SETUP(inoutWriter) \
  38. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  39. __GLS_PARAM_SEP(inoutWriter);
  40. #define __GLS_PUT_BOOLEAN(inoutWriter, inVal) \
  41. if (!__glsWriter_putGLbooleanVal_text(inoutWriter, inVal)) { \
  42. __GLS_PUT_INT(inoutWriter, inVal); \
  43. }
  44. #define __GLS_PUT_CHAR(inoutWriter, inChar) \
  45. *inoutWriter->bufPtr++ = inChar;
  46. #define __GLS_PUT_DOUBLE(inoutWriter, inVal) \
  47. if (__GLS_FINITE(inVal)) { \
  48. __GLS_C_LOCALE_DECLARE; \
  49. __GLS_C_LOCALE_BEGIN; \
  50. __GLS_PUT_NUM(inoutWriter, "%.16g", inVal); \
  51. __GLS_C_LOCALE_END; \
  52. } else { \
  53. __GLS_PUT_HEX16(inoutWriter, *(const GLulong *)&(inVal)); \
  54. }
  55. #define __GLS_PUT_DOUBLE17(inoutWriter, inVal) \
  56. if (__GLS_FINITE(inVal)) { \
  57. __GLS_C_LOCALE_DECLARE; \
  58. __GLS_C_LOCALE_BEGIN; \
  59. __GLS_PUT_NUM(inoutWriter, "%-17.16g", inVal); \
  60. __GLS_C_LOCALE_END; \
  61. } else { \
  62. __GLS_PUT_HEX16(inoutWriter, *(const GLulong *)&(inVal)); \
  63. }
  64. #define __GLS_PUT_FLOAT(inoutWriter, inVal) \
  65. if (__GLS_FINITE((GLdouble)inVal)) { \
  66. __GLS_C_LOCALE_DECLARE; \
  67. __GLS_C_LOCALE_BEGIN; \
  68. __GLS_PUT_NUM(inoutWriter, "%.7g", inVal); \
  69. __GLS_C_LOCALE_END; \
  70. } else { \
  71. __GLS_PUT_HEX8(inoutWriter, *(const GLuint *)&(inVal)); \
  72. }
  73. #define __GLS_PUT_FLOAT11(inoutWriter, inVal) \
  74. if (__GLS_FINITE((GLdouble)inVal)) { \
  75. __GLS_C_LOCALE_DECLARE; \
  76. __GLS_C_LOCALE_BEGIN; \
  77. __GLS_PUT_NUM(inoutWriter, "%-11.7g", inVal); \
  78. __GLS_C_LOCALE_END; \
  79. } else { \
  80. __GLS_PUT_HEX8(inoutWriter, *(const GLuint *)&(inVal)); \
  81. }
  82. #define __GLS_PUT_HEX2(inoutWriter, inVal) \
  83. __GLS_PUT_NUM(inoutWriter, "0x%.2x", inVal);
  84. #define __GLS_PUT_HEX4(inoutWriter, inVal) \
  85. __GLS_PUT_NUM(inoutWriter, "0x%.4x", inVal);
  86. #define __GLS_PUT_HEX8(inoutWriter, inVal) \
  87. __GLS_PUT_NUM(inoutWriter, "0x%.8x", inVal);
  88. #if __GLS_SPRINTF_INT64
  89. #define __GLS_PUT_HEX16(inoutWriter, inVal) \
  90. __GLS_PUT_NUM(inoutWriter, __GLS_OUT_FORMAT_INT64HEX, inVal);
  91. #else /* !__GLS_SPRINTF_INT64 */
  92. #define __GLS_PUT_HEX16(inoutWriter, inVal) \
  93. __GLS_PUT_NUM( \
  94. inoutWriter, "0x%.8x", glsULongHigh(*(const GLulong *)&(inVal)) \
  95. ); \
  96. __GLS_PUT_NUM( \
  97. inoutWriter, "%.8x", glsULongLow(*(const GLulong *)&(inVal)) \
  98. );
  99. #endif /* __GLS_SPRINTF_INT64 */
  100. #define __GLS_PUT_INT(inoutWriter, inVal) \
  101. __GLS_PUT_NUM(inoutWriter, "%d", inVal);
  102. #if __GLS_SPRINTF_INT64
  103. #define __GLS_PUT_LONG(inoutWriter, inVal) \
  104. __GLS_PUT_NUM(inoutWriter, __GLS_OUT_FORMAT_INT64, inVal);
  105. #elif defined(__GLS_INT64_TO_STR)
  106. #define __GLS_PUT_LONG(inoutWriter, inVal) \
  107. inoutWriter->bufPtr += \
  108. strlen(__GLS_INT64_TO_STR(inVal, (char *)inoutWriter->bufPtr));
  109. #else /* !__GLS_SPRINTF_INT64 && !defined(__GLS_INT64_TO_STR) */
  110. #define __GLS_PUT_LONG(inoutWriter, inVal) \
  111. __GLS_PUT_HEX16(inoutWriter, inVal);
  112. #endif /* __GLS_SPRINTF_INT64 */
  113. #define __GLS_PUT_NUM(inoutWriter, inFormat, inVal) \
  114. inoutWriter->bufPtr += sprintf( \
  115. (char *)inoutWriter->bufPtr, (const char *)(inFormat), inVal \
  116. );
  117. #define __GLS_PUT_STRING(inoutWriter, inString) { \
  118. size_t __count = strlen((const char *)inString); \
  119. const GLubyte *ptr = glsCSTR(inString); \
  120. while (__count-- > 0) { \
  121. if (*ptr == '\\' || *ptr == '\"') *inoutWriter->bufPtr++ = '\\'; \
  122. *inoutWriter->bufPtr++ = *ptr++; \
  123. } \
  124. }
  125. #define __GLS_PUT_TEXT(inType, inSize, inCategory) \
  126. __GLS_PUT_TEXT_VAL(inType, inSize, inCategory) \
  127. __GLS_PUT_TEXT_VEC(inType, inSize, inCategory) \
  128. __GLS_PUT_TEXT_VECSTRIDE(inType, inSize, inCategory)
  129. #define __GLS_PUT_TEXT_ENUM(inType, inEnum, inCategory) \
  130. __GLS_PUT_TEXT_ENUM_VAL(inType, inEnum, inCategory) \
  131. __GLS_PUT_TEXT_ENUM_VEC(inType, inEnum, inCategory)
  132. #define __GLS_PUT_TEXT_ENUM_VAL(inType, inEnum, inCategory) \
  133. static void __glsWriter_put##inType##Or##inEnum##_text( \
  134. __GLSwriter *inoutWriter, \
  135. GLenum inParam, \
  136. inType inVal \
  137. ) { \
  138. __GLS_PARAM_SETUP(inoutWriter); \
  139. if ( \
  140. !__GLS_FINITE((GLdouble)inVal) || \
  141. floor((GLdouble)inVal) != (GLdouble)inVal || \
  142. (GLdouble)inVal < 0. || \
  143. (GLdouble)inVal > (GLdouble)UINT_MAX || \
  144. !__glsWriter_put##inEnum##ParamVal_text( \
  145. inoutWriter, inParam, (inEnum)inVal \
  146. ) \
  147. ) { \
  148. __GLS_PUT_##inCategory(inoutWriter, inVal); \
  149. } \
  150. }
  151. #define __GLS_PUT_TEXT_ENUM_VEC(inType, inEnum, inCategory) \
  152. static void __glsWriter_put##inType##Or##inEnum##v_text( \
  153. __GLSwriter *inoutWriter, \
  154. GLenum inParam, \
  155. GLuint inCount, \
  156. const inType *inVec \
  157. ) { \
  158. GLuint i; \
  159. const GLboolean multiLine = (GLboolean)(inCount > 4); \
  160. __GLS_PARAM_SETUP(inoutWriter); \
  161. __GLS_PUT_CHAR(inoutWriter, '{'); \
  162. for (i = 0 ; i < inCount ; ++i) { \
  163. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  164. if (i) __GLS_PUT_CHAR(inoutWriter, ','); \
  165. if (multiLine && !(i & 7)) { \
  166. __GLS_PUT_STRING(inoutWriter, "\n "); \
  167. } else if (i) { \
  168. __GLS_PUT_CHAR(inoutWriter, ' '); \
  169. } \
  170. if ( \
  171. !__GLS_FINITE((GLdouble)inVec[i]) || \
  172. floor((GLdouble)inVec[i]) != (GLdouble)inVec[i] || \
  173. (GLdouble)inVec[i] < 0. || \
  174. (GLdouble)inVec[i] > (GLdouble)UINT_MAX || \
  175. !__glsWriter_put##inEnum##ParamVal_text( \
  176. inoutWriter, inParam, (inEnum)inVec[i] \
  177. ) \
  178. ) { \
  179. __GLS_PUT_##inCategory(inoutWriter, inVec[i]); \
  180. } \
  181. } \
  182. if (multiLine) __GLS_PUT_CHAR(inoutWriter, '\n'); \
  183. __GLS_PUT_CHAR(inoutWriter, '}'); \
  184. }
  185. #define __GLS_PUT_TEXT_MAT(inType, inCategory) \
  186. static void __glsWriter_put##inType##m_text( \
  187. __GLSwriter *inoutWriter, \
  188. const inType *inMat \
  189. ) { \
  190. GLuint i, j; \
  191. __GLS_PARAM_SETUP(inoutWriter); \
  192. __GLS_PUT_CHAR(inoutWriter, '{'); \
  193. for (i = 0 ; i < 4 ; ++i) { \
  194. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  195. if (i) __GLS_PUT_CHAR(inoutWriter, ','); \
  196. __GLS_PUT_STRING(inoutWriter, "\n "); \
  197. for (j = 0 ; j < 4 ; ++j) { \
  198. if (j) __GLS_PUT_STRING(inoutWriter, ", "); \
  199. __GLS_PUT_##inCategory(inoutWriter, inMat[i * 4 + j]); \
  200. } \
  201. } \
  202. __GLS_PUT_STRING(inoutWriter, "\n}"); \
  203. }
  204. #define __GLS_PUT_TEXT_VAL(inType, inSize, inCategory) \
  205. static void __glsWriter_put##inType##_text( \
  206. __GLSwriter *inoutWriter, inType inVal \
  207. ) { \
  208. __GLS_PARAM_SETUP(inoutWriter); \
  209. __GLS_PUT_##inCategory(inoutWriter, inVal); \
  210. }
  211. #define __GLS_PUT_TEXT_VEC(inType, inSize, inCategory) \
  212. static void __glsWriter_put##inType##v_text( \
  213. __GLSwriter *inoutWriter, \
  214. GLuint inCount, \
  215. const inType *inVec \
  216. ) { \
  217. GLuint i; \
  218. const GLboolean multiLine = (GLboolean)(inCount > 4); \
  219. __GLS_PARAM_SETUP(inoutWriter); \
  220. __GLS_PUT_CHAR(inoutWriter, '{'); \
  221. for (i = 0 ; i < inCount ; ++i) { \
  222. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  223. if (i) __GLS_PUT_CHAR(inoutWriter, ','); \
  224. if (multiLine && !(i & 7)) { \
  225. __GLS_PUT_STRING(inoutWriter, "\n "); \
  226. } else if (i) { \
  227. __GLS_PUT_CHAR(inoutWriter, ' '); \
  228. } \
  229. __GLS_PUT_##inCategory(inoutWriter, inVec[i]); \
  230. } \
  231. if (multiLine) __GLS_PUT_CHAR(inoutWriter, '\n'); \
  232. __GLS_PUT_CHAR(inoutWriter, '}'); \
  233. }
  234. #define __GLS_PUT_TEXT_VECSTRIDE(inType, inSize, inCategory) \
  235. static void __glsWriter_put##inType##vs_text( \
  236. __GLSwriter *inoutWriter, \
  237. GLboolean inItemSwap, \
  238. GLint inStride1DataItems, \
  239. GLint inStride1PadBytes, \
  240. GLint inStride1Count, \
  241. GLint inStride2PadBytes, \
  242. GLint inStride2Count, \
  243. const inType *inVec \
  244. ) { \
  245. GLint i, j, param = 0; \
  246. const GLboolean multiLine = (GLboolean)( \
  247. inStride1DataItems * inStride1Count * inStride2Count > 4 \
  248. ); \
  249. __GLS_PARAM_SETUP(inoutWriter); \
  250. __GLS_PUT_CHAR(inoutWriter, '{'); \
  251. if (inItemSwap) while (inStride2Count-- > 0) { \
  252. for ( \
  253. i = 0 ; \
  254. i < inStride1Count ; \
  255. ++i, \
  256. inVec = \
  257. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  258. ) { \
  259. for (j = 0 ; j < inStride1DataItems ; ++j, ++param) { \
  260. inType val = *inVec++; \
  261. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  262. if (param) __GLS_PUT_CHAR(inoutWriter, ','); \
  263. if (multiLine && !(param & 7)) { \
  264. __GLS_PUT_STRING(inoutWriter, "\n "); \
  265. } else if (param) { \
  266. __GLS_PUT_CHAR(inoutWriter, ' '); \
  267. } \
  268. __glsSwap##inSize(&val); \
  269. __GLS_PUT_##inCategory(inoutWriter, val); \
  270. } \
  271. } \
  272. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  273. } else while (inStride2Count-- > 0) { \
  274. for ( \
  275. i = 0 ; \
  276. i < inStride1Count ; \
  277. ++i, \
  278. inVec = \
  279. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  280. ) { \
  281. for (j = 0 ; j < inStride1DataItems ; ++j, ++param) { \
  282. inType val = *inVec++; \
  283. __GLS_ALLOC(inoutWriter, __GLS_NULL); \
  284. if (param) __GLS_PUT_CHAR(inoutWriter, ','); \
  285. if (multiLine && !(param & 7)) { \
  286. __GLS_PUT_STRING(inoutWriter, "\n "); \
  287. } else if (param) { \
  288. __GLS_PUT_CHAR(inoutWriter, ' '); \
  289. } \
  290. __GLS_PUT_##inCategory(inoutWriter, val); \
  291. } \
  292. } \
  293. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  294. } \
  295. if (multiLine) __GLS_PUT_CHAR(inoutWriter, '\n'); \
  296. __GLS_PUT_CHAR(inoutWriter, '}'); \
  297. }
  298. #define __GLS_PUT_UNSIGNED_INT(inoutWriter, inVal) \
  299. __GLS_PUT_NUM(inoutWriter, "%u", inVal);
  300. #if __GLS_SPRINTF_INT64
  301. #define __GLS_PUT_UNSIGNED_LONG(inoutWriter, inVal) \
  302. __GLS_PUT_NUM(inoutWriter, __GLS_OUT_FORMAT_INT64U, inVal);
  303. #elif defined(__GLS_INT64U_TO_STR)
  304. #define __GLS_PUT_UNSIGNED_LONG(inoutWriter, inVal) \
  305. inoutWriter->bufPtr += \
  306. strlen(__GLS_INT64U_TO_STR(inVal, (char *)inoutWriter->bufPtr));
  307. #else /* !__GLS_SPRINTF_INT64 && !defined(__GLS_INT64U_TO_STR) */
  308. #define __GLS_PUT_UNSIGNED_LONG(inoutWriter, inVal) \
  309. __GLS_PUT_HEX16(inoutWriter, inVal);
  310. #endif /* __GLS_SPRINTF_INT64 */
  311. __GLS_FORWARD static GLboolean __glsWriter_putGLbooleanVal_text(
  312. __GLSwriter *inoutWriter, GLboolean inVal
  313. );
  314. __GLS_FORWARD static GLboolean __glsWriter_putGLenumVal_text(
  315. __GLSwriter *inoutWriter, GLenum inVal
  316. );
  317. __GLS_FORWARD static GLboolean __glsWriter_putGLstencilOpVal_text(
  318. __GLSwriter *inoutWriter, GLenum inVal
  319. );
  320. __GLS_FORWARD static GLboolean __glsWriter_putGLtextureComponentCountVal_text(
  321. __GLSwriter *inoutWriter, GLint inVal
  322. );
  323. static void __glsWriter_putBitfield_text(
  324. __GLSwriter *inoutWriter,
  325. GLbitfield inBits,
  326. GLint inCount,
  327. const GLubyte *const inString[],
  328. const GLbitfield inVal[]
  329. ) {
  330. GLint i, putCount;
  331. __GLS_PARAM_SETUP(inoutWriter);
  332. for (i = 0 ; i < inCount ; ++i) {
  333. if (inBits == inVal[i]) {
  334. __GLS_PUT_STRING(inoutWriter, inString[i]);
  335. return;
  336. }
  337. }
  338. for (putCount = i = 0 ; i < inCount ; ++i) {
  339. if (inBits & inVal[i]) {
  340. inBits &= ~inVal[i];
  341. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  342. if (putCount++) __GLS_PUT_STRING(inoutWriter, " | ");
  343. __GLS_PUT_STRING(inoutWriter, inString[i]);
  344. }
  345. }
  346. if (inBits) {
  347. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  348. if (putCount) __GLS_PUT_STRING(inoutWriter, " | ");
  349. __GLS_PUT_HEX8(inoutWriter, inBits);
  350. }
  351. }
  352. static GLboolean __glsWriter_putGLSenumVal_text(
  353. __GLSwriter *inoutWriter, GLSenum inVal
  354. ) {
  355. const GLint page = __GLS_ENUM_PAGE(inVal);
  356. const GLint offset = __GLS_ENUM_OFFSET(inVal);
  357. if (
  358. page < __GLS_ENUM_PAGE_COUNT &&
  359. offset < __glsEnumStringCount[page] &&
  360. __glsEnumString[page][offset]
  361. ) {
  362. __GLS_PUT_STRING(inoutWriter, __glsEnumString[page][offset]);
  363. return GL_TRUE;
  364. } else {
  365. return GL_FALSE;
  366. }
  367. }
  368. static GLboolean __glsWriter_putGLSenumParamVal_text(
  369. __GLSwriter *inoutWriter, GLSenum inParam, GLSenum inVal
  370. ) {
  371. switch (inParam) {
  372. case GLS_DISPLAY_FORMAT:
  373. return __glsWriter_putGLSenumVal_text(inoutWriter, inVal);
  374. case GLS_DOUBLEBUFFER:
  375. case GLS_INVISIBLE:
  376. case GLS_STEREO:
  377. case GLS_TILEABLE:
  378. case GLS_TRANSPARENT:
  379. return (
  380. __glsWriter_putGLbooleanVal_text(inoutWriter, (GLboolean)inVal)
  381. );
  382. default:
  383. return GL_FALSE;
  384. }
  385. }
  386. static GLboolean __glsWriter_putGLblendingFactorVal_text(
  387. __GLSwriter *inoutWriter, GLenum inVal
  388. ) {
  389. switch (inVal) {
  390. case GL_ZERO:
  391. __GLS_PUT_STRING(inoutWriter, "GL_ZERO");
  392. return GL_TRUE;
  393. case GL_ONE:
  394. __GLS_PUT_STRING(inoutWriter, "GL_ONE");
  395. return GL_TRUE;
  396. default:
  397. return __glsWriter_putGLenumVal_text(inoutWriter, inVal);
  398. }
  399. }
  400. static GLboolean __glsWriter_putGLbooleanVal_text(
  401. __GLSwriter *inoutWriter, GLboolean inVal
  402. ) {
  403. switch (inVal) {
  404. case GL_FALSE:
  405. __GLS_PUT_STRING(inoutWriter, "GL_FALSE");
  406. return GL_TRUE;
  407. case GL_TRUE:
  408. __GLS_PUT_STRING(inoutWriter, "GL_TRUE");
  409. return GL_TRUE;
  410. default:
  411. return GL_FALSE;
  412. }
  413. }
  414. static GLboolean __glsWriter_putGLdrawBufferModeVal_text(
  415. __GLSwriter *inoutWriter, GLenum inVal
  416. ) {
  417. if (inVal) {
  418. return __glsWriter_putGLenumVal_text(inoutWriter, inVal);
  419. } else {
  420. __GLS_PUT_STRING(inoutWriter, "GL_NONE");
  421. return GL_TRUE;
  422. }
  423. }
  424. static GLboolean __glsWriter_putGLenumParamVal_text(
  425. __GLSwriter *inoutWriter, GLenum inParam, GLenum inVal
  426. ) {
  427. switch (inParam) {
  428. case GL_FOG_MODE:
  429. case GL_TEXTURE_ENV_MODE:
  430. case GL_TEXTURE_GEN_MODE:
  431. case GL_TEXTURE_MAG_FILTER:
  432. case GL_TEXTURE_MIN_FILTER:
  433. case GL_TEXTURE_WRAP_S:
  434. case GL_TEXTURE_WRAP_T:
  435. #if __GL_EXT_convolution
  436. case GL_CONVOLUTION_BORDER_MODE_EXT:
  437. #endif /* __GL_EXT_convolution */
  438. #if __GL_EXT_texture3D
  439. case GL_TEXTURE_WRAP_R_EXT:
  440. #endif /* __GL_EXT_texture3D */
  441. #if __GL_SGIS_component_select
  442. case GL_TEXTURE_SS_SELECT_SGIS:
  443. case GL_TEXTURE_SSSS_SELECT_SGIS:
  444. #endif /* __GL_SGIS_component_select */
  445. #if __GL_SGIS_detail_texture
  446. case GL_DETAIL_TEXTURE_MODE_SGIS:
  447. #endif /* __GL_SGIS_detail_texture */
  448. #if __GL_SGIS_texture4D
  449. case GL_TEXTURE_WRAP_Q_SGIS:
  450. #endif /* __GL_SGIS_texture4D */
  451. #if __GL_SGIX_sprite
  452. case GL_SPRITE_MODE_SGIX:
  453. #endif /* __GL_SGIX_sprite */
  454. return __glsWriter_putGLenumVal_text(inoutWriter, inVal);
  455. case GL_LIGHT_MODEL_LOCAL_VIEWER:
  456. case GL_LIGHT_MODEL_TWO_SIDE:
  457. case GL_MAP_COLOR:
  458. case GL_MAP_STENCIL:
  459. case GL_PACK_LSB_FIRST:
  460. case GL_PACK_SWAP_BYTES:
  461. case GL_UNPACK_LSB_FIRST:
  462. case GL_UNPACK_SWAP_BYTES:
  463. return (
  464. __glsWriter_putGLbooleanVal_text(inoutWriter, (GLboolean)inVal)
  465. );
  466. default:
  467. return GL_FALSE;
  468. }
  469. }
  470. static GLboolean __glsWriter_putGLenumVal_text(
  471. __GLSwriter *inoutWriter, GLenum inVal
  472. ) {
  473. const GLint page = __GL_ENUM_PAGE(inVal);
  474. const GLint offset = __GL_ENUM_OFFSET(inVal);
  475. if (
  476. page < __GL_ENUM_PAGE_COUNT &&
  477. offset < __glEnumStringCount[page] &&
  478. __glEnumString[page][offset]
  479. ) {
  480. __GLS_PUT_STRING(inoutWriter, __glEnumString[page][offset]);
  481. return GL_TRUE;
  482. } else {
  483. return GL_FALSE;
  484. }
  485. }
  486. static GLboolean __glsWriter_putGLstencilOpVal_text(
  487. __GLSwriter *inoutWriter, GLenum inVal
  488. ) {
  489. if (inVal) {
  490. return __glsWriter_putGLenumVal_text(inoutWriter, inVal);
  491. } else {
  492. __GLS_PUT_STRING(inoutWriter, "GL_ZERO");
  493. return GL_TRUE;
  494. }
  495. }
  496. static GLboolean __glsWriter_putGLtextureComponentCountVal_text(
  497. __GLSwriter *inoutWriter, GLint inVal
  498. ) {
  499. if (inVal > 4) {
  500. return __glsWriter_putGLenumVal_text(inoutWriter, inVal);
  501. } else {
  502. return GL_FALSE;
  503. }
  504. }
  505. typedef GLuint GLuinthex;
  506. typedef GLulong GLulonghex;
  507. typedef GLushort GLushorthex;
  508. __GLS_PUT_TEXT(GLbyte, 1, INT)
  509. __GLS_PUT_TEXT(GLubyte, 1, UNSIGNED_INT)
  510. __GLS_PUT_TEXT(GLshort, 2, INT)
  511. __GLS_PUT_TEXT(GLushort, 2, UNSIGNED_INT)
  512. __GLS_PUT_TEXT(GLint, 4, INT)
  513. __GLS_PUT_TEXT(GLuint, 4, UNSIGNED_INT)
  514. __GLS_PUT_TEXT(GLfloat, 4, FLOAT)
  515. __GLS_PUT_TEXT(GLdouble, 8, DOUBLE)
  516. __GLS_PUT_TEXT_ENUM(GLfloat, GLenum, FLOAT)
  517. __GLS_PUT_TEXT_ENUM(GLdouble, GLenum, DOUBLE)
  518. __GLS_PUT_TEXT_ENUM(GLint, GLenum, INT)
  519. __GLS_PUT_TEXT_ENUM_VAL(GLint, GLSenum, INT)
  520. __GLS_PUT_TEXT_MAT(GLfloat, FLOAT11)
  521. __GLS_PUT_TEXT_MAT(GLdouble, DOUBLE17)
  522. __GLS_PUT_TEXT_VAL(GLlong, 8, LONG)
  523. __GLS_PUT_TEXT_VAL(GLuinthex, 4, HEX8)
  524. __GLS_PUT_TEXT_VAL(GLulong, 8, UNSIGNED_LONG)
  525. __GLS_PUT_TEXT_VAL(GLulonghex, 8, HEX16)
  526. __GLS_PUT_TEXT_VAL(GLushorthex, 2, HEX4)
  527. __GLS_PUT_TEXT_VEC(GLboolean, 1, BOOLEAN)
  528. __GLS_PUT_TEXT_VEC(GLlong, 8, LONG)
  529. __GLS_PUT_TEXT_VEC(GLulong, 8, UNSIGNED_LONG)
  530. __GLS_PUT_TEXT_VECSTRIDE(GLboolean, 1, BOOLEAN)
  531. /******************************************************************************
  532. Writers
  533. ******************************************************************************/
  534. static GLboolean __glsWriter_beginCommand_text(
  535. __GLSwriter *inoutWriter, GLSopcode inOpcode, size_t inByteCount
  536. ) {
  537. if (!inoutWriter || inoutWriter->error) return GL_FALSE;
  538. __GLS_ALLOC(inoutWriter, GL_FALSE);
  539. inoutWriter->commandOpcode = inOpcode;
  540. inoutWriter->paramCount = 0;
  541. __GLS_PUT_STRING(inoutWriter, __glsOpcodeString[__glsMapOpcode(inOpcode)]);
  542. __GLS_PUT_CHAR(inoutWriter, '(');
  543. return GL_TRUE;
  544. }
  545. static void __glsWriter_endCommand_text(__GLSwriter *inoutWriter) {
  546. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  547. __GLS_PUT_CHAR(inoutWriter, ')');
  548. __GLS_PUT_CHAR(inoutWriter, ';');
  549. __GLS_PUT_CHAR(inoutWriter, '\n');
  550. }
  551. static void __glsWriter_nextList_text(__GLSwriter *inoutWriter) {
  552. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  553. __GLS_PUT_STRING(inoutWriter, ")(");
  554. inoutWriter->paramCount = 0;
  555. }
  556. static GLboolean __glsWriter_padWordCount_text(
  557. __GLSwriter *inoutWriter, GLboolean inCountMod2
  558. ) {
  559. return GL_TRUE;
  560. }
  561. static void __glsWriter_putGLSenum_text(
  562. __GLSwriter *inoutWriter, GLSenum inVal
  563. ) {
  564. __GLS_PARAM_SETUP(inoutWriter);
  565. if (!__glsWriter_putGLSenumVal_text(inoutWriter, inVal)) {
  566. __GLS_PUT_INT(inoutWriter, inVal);
  567. }
  568. }
  569. static void __glsWriter_putGLSimageFlags_text(
  570. __GLSwriter *inoutWriter, GLbitfield inVal
  571. ) {
  572. __glsWriter_putBitfield_text(
  573. inoutWriter,
  574. inVal,
  575. __GLS_IMAGE_FLAGS_COUNT,
  576. __glsImageFlagsString,
  577. __glsImageFlagsVal
  578. );
  579. }
  580. static void __glsWriter_putGLSopcode_text(
  581. __GLSwriter *inoutWriter, GLSopcode inVal
  582. ) {
  583. const GLSopcode opcode = __glsMapOpcode(inVal);
  584. __GLS_PARAM_SETUP(inoutWriter);
  585. if (
  586. opcode >= __GLS_OPCODES_PER_PAGE &&
  587. opcode < __GLS_OPCODE_COUNT &&
  588. __glsOpcodeString[opcode]
  589. ) {
  590. __GLS_PUT_STRING(inoutWriter, "GLS_OP_");
  591. __GLS_PUT_STRING(inoutWriter, __glsOpcodeString[opcode]);
  592. } else {
  593. __GLS_PUT_INT(inoutWriter, inVal);
  594. }
  595. }
  596. static void __glsWriter_putGLattribMask_text(
  597. __GLSwriter *inoutWriter, GLbitfield inVal
  598. ) {
  599. __glsWriter_putBitfield_text(
  600. inoutWriter,
  601. inVal,
  602. __GL_ATTRIB_MASK_COUNT,
  603. __glAttribMaskString,
  604. __glAttribMaskVal
  605. );
  606. }
  607. static void __glsWriter_putGLbitvs_text(
  608. __GLSwriter *inoutWriter,
  609. GLboolean inItemSwap,
  610. GLint inItemLeftShift,
  611. GLint inStrideDataItems,
  612. GLint inStridePadItems,
  613. GLint inStrideCount,
  614. const GLubyte *inVec
  615. ) {
  616. GLint i, param = 0;
  617. const GLboolean multiLine = (GLboolean)(
  618. inStrideDataItems * inStrideCount / 8 > 4
  619. );
  620. const GLint highShift = inItemLeftShift;
  621. const GLint lowShift = 8 - inItemLeftShift;
  622. GLubyte lastMask = 0xffu;
  623. if (inStrideDataItems & 7) lastMask <<= 8 - (inStrideDataItems & 7);
  624. inStrideDataItems = (inStrideDataItems + 7) >> 3;
  625. inStridePadItems >>= 3;
  626. __GLS_PARAM_SETUP(inoutWriter);
  627. __GLS_PUT_CHAR(inoutWriter, '{');
  628. while (inStrideCount-- > 0) {
  629. GLubyte val;
  630. i = inStrideDataItems;
  631. while (i-- > 0) {
  632. if (inItemSwap) {
  633. val = __glsBitReverse[*inVec++];
  634. if (inItemLeftShift) {
  635. if (i) {
  636. val <<= highShift;
  637. val |= __glsBitReverse[*inVec] >> lowShift;
  638. } else {
  639. val = (GLubyte)((val & lastMask) << highShift);
  640. }
  641. } else if (!i) {
  642. val &= lastMask;
  643. }
  644. } else {
  645. val = *inVec++;
  646. if (inItemLeftShift) {
  647. if (i) {
  648. val = (GLubyte)(val << highShift | *inVec >> lowShift);
  649. } else {
  650. val = (GLubyte)((val & lastMask) << highShift);
  651. }
  652. } else if (!i) {
  653. val &= lastMask;
  654. }
  655. }
  656. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  657. if (param) __GLS_PUT_CHAR(inoutWriter, ',');
  658. if (multiLine && !(param & 7)) {
  659. __GLS_PUT_STRING(inoutWriter, "\n ");
  660. } else if (param) {
  661. __GLS_PUT_CHAR(inoutWriter, ' ');
  662. }
  663. __GLS_PUT_HEX2(inoutWriter, val);
  664. ++param;
  665. }
  666. inVec += inStridePadItems;
  667. }
  668. if (multiLine) __GLS_PUT_CHAR(inoutWriter, '\n');
  669. __GLS_PUT_CHAR(inoutWriter, '}');
  670. }
  671. static void __glsWriter_putGLblendingFactor_text(
  672. __GLSwriter *inoutWriter, GLenum inVal
  673. ) {
  674. __GLS_PARAM_SETUP(inoutWriter);
  675. if (!__glsWriter_putGLblendingFactorVal_text(inoutWriter, inVal)) {
  676. __GLS_PUT_INT(inoutWriter, inVal);
  677. }
  678. }
  679. static void __glsWriter_putGLboolean_text(
  680. __GLSwriter *inoutWriter, GLboolean inVal
  681. ) {
  682. __GLS_PARAM_SETUP(inoutWriter);
  683. if (!__glsWriter_putGLbooleanVal_text(inoutWriter, inVal)) {
  684. __GLS_PUT_INT(inoutWriter, inVal);
  685. }
  686. }
  687. static void __glsWriter_putGLcharv_text(
  688. __GLSwriter *inoutWriter, GLuint inCount, const GLubyte *inString
  689. ) {
  690. size_t count = strlen((const char *)inString);
  691. const GLubyte *ptr = inString;
  692. __GLS_PARAM_SETUP(inoutWriter);
  693. __GLS_PUT_CHAR(inoutWriter, '"');
  694. while (count-- > 0) {
  695. __GLS_ALLOC(inoutWriter, __GLS_NULL);
  696. if (__GLS_CHAR_IS_GRAPHIC(*ptr)) {
  697. if (*ptr == '\\' || *ptr == '\"') *inoutWriter->bufPtr++ = '\\';
  698. *inoutWriter->bufPtr++ = *ptr++;
  699. } else {
  700. __GLS_PUT_NUM(inoutWriter, "\\x%.2x", *ptr++);
  701. }
  702. }
  703. __GLS_PUT_CHAR(inoutWriter, '"');
  704. }
  705. static void __glsWriter_putGLclearBufferMask_text(
  706. __GLSwriter *inoutWriter, GLbitfield inVal
  707. ) {
  708. __glsWriter_putGLattribMask_text(inoutWriter, inVal);
  709. }
  710. static void __glsWriter_putGLdrawBufferMode_text(
  711. __GLSwriter *inoutWriter, GLenum inVal
  712. ) {
  713. __GLS_PARAM_SETUP(inoutWriter);
  714. if (!__glsWriter_putGLdrawBufferModeVal_text(inoutWriter, inVal)) {
  715. __GLS_PUT_INT(inoutWriter, inVal);
  716. }
  717. }
  718. static void __glsWriter_putGLenum_text(
  719. __GLSwriter *inoutWriter, GLenum inVal
  720. ) {
  721. __GLS_PARAM_SETUP(inoutWriter);
  722. if (!__glsWriter_putGLenumVal_text(inoutWriter, inVal)) {
  723. __GLS_PUT_INT(inoutWriter, inVal);
  724. }
  725. }
  726. static void __glsWriter_putGLoutArg_text(
  727. __GLSwriter *inoutWriter, GLuint inIndex, const GLvoid *inVal
  728. ) {
  729. __GLScontext *const ctx = __GLS_CONTEXT;
  730. __glsWriter_putGLulonghex_text(
  731. inoutWriter,
  732. (
  733. ctx->callNesting &&
  734. !ctx->commandFuncs[__glsMapOpcode(inoutWriter->commandOpcode)]
  735. ) ?
  736. ctx->outArgs.vals[inIndex] :
  737. __glsPtrToULong(inVal)
  738. );
  739. }
  740. static void __glsWriter_putGLstencilOp_text(
  741. __GLSwriter *inoutWriter, GLenum inVal
  742. ) {
  743. __GLS_PARAM_SETUP(inoutWriter);
  744. if (!__glsWriter_putGLstencilOpVal_text(inoutWriter, inVal)) {
  745. __GLS_PUT_INT(inoutWriter, inVal);
  746. }
  747. }
  748. static void __glsWriter_putGLtextureComponentCount_text(
  749. __GLSwriter *inoutWriter, GLint inVal
  750. ) {
  751. __GLS_PARAM_SETUP(inoutWriter);
  752. if (!__glsWriter_putGLtextureComponentCountVal_text(inoutWriter, inVal)) {
  753. __GLS_PUT_INT(inoutWriter, inVal);
  754. }
  755. }
  756. /******************************************************************************
  757. Dispatch setup
  758. ******************************************************************************/
  759. #define __GLS_INIT_PUT_TEXT(inType) \
  760. inoutWriter->put##inType = __glsWriter_put##inType##_text
  761. void __glsWriter_initDispatch_text(__GLSwriter *inoutWriter) {
  762. inoutWriter->beginCommand = __glsWriter_beginCommand_text;
  763. inoutWriter->endCommand = __glsWriter_endCommand_text;
  764. inoutWriter->nextList = __glsWriter_nextList_text;
  765. inoutWriter->padWordCount = __glsWriter_padWordCount_text;
  766. __GLS_INIT_PUT_TEXT(GLSenum);
  767. __GLS_INIT_PUT_TEXT(GLSimageFlags);
  768. __GLS_INIT_PUT_TEXT(GLSopcode);
  769. __GLS_INIT_PUT_TEXT(GLattribMask);
  770. __GLS_INIT_PUT_TEXT(GLbitvs);
  771. __GLS_INIT_PUT_TEXT(GLblendingFactor);
  772. __GLS_INIT_PUT_TEXT(GLboolean);
  773. __GLS_INIT_PUT_TEXT(GLbooleanv);
  774. __GLS_INIT_PUT_TEXT(GLbooleanvs);
  775. __GLS_INIT_PUT_TEXT(GLbyte);
  776. __GLS_INIT_PUT_TEXT(GLbytev);
  777. __GLS_INIT_PUT_TEXT(GLbytevs);
  778. __GLS_INIT_PUT_TEXT(GLcharv);
  779. __GLS_INIT_PUT_TEXT(GLclearBufferMask);
  780. __GLS_INIT_PUT_TEXT(GLdouble);
  781. __GLS_INIT_PUT_TEXT(GLdoubleOrGLenum);
  782. __GLS_INIT_PUT_TEXT(GLdoubleOrGLenumv);
  783. __GLS_INIT_PUT_TEXT(GLdoublem);
  784. __GLS_INIT_PUT_TEXT(GLdoublev);
  785. __GLS_INIT_PUT_TEXT(GLdoublevs);
  786. __GLS_INIT_PUT_TEXT(GLdrawBufferMode);
  787. __GLS_INIT_PUT_TEXT(GLenum);
  788. __GLS_INIT_PUT_TEXT(GLfloat);
  789. __GLS_INIT_PUT_TEXT(GLfloatOrGLenum);
  790. __GLS_INIT_PUT_TEXT(GLfloatOrGLenumv);
  791. __GLS_INIT_PUT_TEXT(GLfloatm);
  792. __GLS_INIT_PUT_TEXT(GLfloatv);
  793. __GLS_INIT_PUT_TEXT(GLfloatvs);
  794. __GLS_INIT_PUT_TEXT(GLint);
  795. __GLS_INIT_PUT_TEXT(GLintOrGLSenum);
  796. __GLS_INIT_PUT_TEXT(GLintOrGLenum);
  797. __GLS_INIT_PUT_TEXT(GLintOrGLenumv);
  798. __GLS_INIT_PUT_TEXT(GLintv);
  799. __GLS_INIT_PUT_TEXT(GLintvs);
  800. __GLS_INIT_PUT_TEXT(GLlong);
  801. __GLS_INIT_PUT_TEXT(GLlongv);
  802. __GLS_INIT_PUT_TEXT(GLoutArg);
  803. __GLS_INIT_PUT_TEXT(GLshort);
  804. __GLS_INIT_PUT_TEXT(GLshortv);
  805. __GLS_INIT_PUT_TEXT(GLshortvs);
  806. __GLS_INIT_PUT_TEXT(GLstencilOp);
  807. __GLS_INIT_PUT_TEXT(GLtextureComponentCount);
  808. __GLS_INIT_PUT_TEXT(GLubyte);
  809. __GLS_INIT_PUT_TEXT(GLubytev);
  810. __GLS_INIT_PUT_TEXT(GLubytevs);
  811. __GLS_INIT_PUT_TEXT(GLuint);
  812. __GLS_INIT_PUT_TEXT(GLuinthex);
  813. __GLS_INIT_PUT_TEXT(GLuintv);
  814. __GLS_INIT_PUT_TEXT(GLuintvs);
  815. __GLS_INIT_PUT_TEXT(GLulong);
  816. __GLS_INIT_PUT_TEXT(GLulonghex);
  817. __GLS_INIT_PUT_TEXT(GLulongv);
  818. __GLS_INIT_PUT_TEXT(GLushort);
  819. __GLS_INIT_PUT_TEXT(GLushorthex);
  820. __GLS_INIT_PUT_TEXT(GLushortv);
  821. __GLS_INIT_PUT_TEXT(GLushortvs);
  822. }