Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

675 lines
24 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 <stdlib.h>
  20. /******************************************************************************
  21. Helpers
  22. ******************************************************************************/
  23. #define __GLS_PUT_BIN(inType, inSize) \
  24. __GLS_PUT_BIN_VAL(inType, inSize) \
  25. __GLS_PUT_BIN_VEC(inType, inSize) \
  26. __GLS_PUT_BIN_VECSTRIDE(inType, inSize)
  27. #define __GLS_PUT_BIN_ENUM(inType, inEnum) \
  28. __GLS_PUT_BIN_ENUM_VAL(inType, inEnum) \
  29. __GLS_PUT_BIN_ENUM_VEC(inType, inEnum)
  30. #define __GLS_PUT_BIN_SWAP(inType, inSize) \
  31. __GLS_PUT_BIN(inType, inSize) \
  32. __GLS_PUT_BIN_SWAP_VAL(inType, inSize) \
  33. __GLS_PUT_BIN_SWAP_VEC(inType, inSize) \
  34. __GLS_PUT_BIN_SWAP_VECSTRIDE(inType, inSize)
  35. #define __GLS_PUT_BIN_ENUM_VAL(inType, inEnum) \
  36. static void __glsWriter_put##inType##Or##inEnum##_bin( \
  37. __GLSwriter *inoutWriter, inEnum inParam, inType inVal \
  38. ) { \
  39. inoutWriter->put##inType(inoutWriter, inVal); \
  40. }
  41. #define __GLS_PUT_BIN_ENUM_VEC(inType, inEnum) \
  42. static void __glsWriter_put##inType##Or##inEnum##v_bin( \
  43. __GLSwriter *inoutWriter, \
  44. inEnum inParam, \
  45. GLuint inCount, \
  46. const inType *inVec \
  47. ) { \
  48. inoutWriter->put##inType##v(inoutWriter, inCount, inVec); \
  49. }
  50. #define __GLS_PUT_BIN_SWAP_VAL(inType, inSize) \
  51. static void __glsWriter_put##inType##_bin_swap( \
  52. __GLSwriter *inoutWriter, inType inVal \
  53. ) { \
  54. GLubyte *bufPtr = inoutWriter->bufPtr; \
  55. inoutWriter->bufPtr += inSize; \
  56. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  57. *(inType *)bufPtr = inVal; \
  58. __glsSwap##inSize(bufPtr); \
  59. }
  60. #define __GLS_PUT_BIN_SWAP_VEC(inType, inSize) \
  61. static void __glsWriter_put##inType##v_bin_swap( \
  62. __GLSwriter *inoutWriter, GLuint inCount, const inType *inVec \
  63. ) { \
  64. GLubyte *bufPtr = inoutWriter->bufPtr; \
  65. inoutWriter->bufPtr += inSize * inCount; \
  66. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  67. while (inCount-- > 0) { \
  68. *(inType *)bufPtr = *inVec++; \
  69. __glsSwap##inSize(bufPtr); \
  70. bufPtr += inSize; \
  71. } \
  72. }
  73. #define __GLS_PUT_BIN_SWAP_VECSTRIDE(inType, inSize) \
  74. static void __glsWriter_put##inType##vs_bin_swap( \
  75. __GLSwriter *inoutWriter, \
  76. GLboolean inItemSwap, \
  77. GLint inStride1DataItems, \
  78. GLint inStride1PadBytes, \
  79. GLint inStride1Count, \
  80. GLint inStride2PadBytes, \
  81. GLint inStride2Count, \
  82. const inType *inVec \
  83. ) { \
  84. GLint i, j; \
  85. GLubyte *bufPtr = inoutWriter->bufPtr; \
  86. inoutWriter->bufPtr += ( \
  87. inSize * inStride1DataItems * inStride1Count * inStride2Count \
  88. ); \
  89. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  90. if (inItemSwap) while (inStride2Count-- > 0) { \
  91. for ( \
  92. i = 0 ; \
  93. i < inStride1Count ; \
  94. ++i, \
  95. inVec = \
  96. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  97. ) { \
  98. for (j = 0 ; j < inStride1DataItems ; ++j, bufPtr += inSize) { \
  99. *(inType *)bufPtr = *inVec++; \
  100. } \
  101. } \
  102. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  103. } else while (inStride2Count-- > 0) { \
  104. for ( \
  105. i = 0 ; \
  106. i < inStride1Count ; \
  107. ++i, \
  108. inVec = \
  109. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  110. ) { \
  111. for (j = 0 ; j < inStride1DataItems ; ++j, bufPtr += inSize) { \
  112. *(inType *)bufPtr = *inVec++; \
  113. __glsSwap##inSize(bufPtr); \
  114. } \
  115. } \
  116. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  117. } \
  118. }
  119. #define __GLS_PUT_BIN_VAL(inType, inSize) \
  120. static void __glsWriter_put##inType##_bin( \
  121. __GLSwriter *inoutWriter, inType inVal \
  122. ) { \
  123. GLubyte *bufPtr = inoutWriter->bufPtr; \
  124. inoutWriter->bufPtr += inSize; \
  125. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  126. *(inType *)bufPtr = inVal; \
  127. }
  128. #define __GLS_PUT_BIN_VEC(inType, inSize) \
  129. static void __glsWriter_put##inType##v_bin( \
  130. __GLSwriter *inoutWriter, GLuint inCount, const inType *inVec \
  131. ) { \
  132. GLubyte *bufPtr = inoutWriter->bufPtr; \
  133. inoutWriter->bufPtr += inSize * inCount; \
  134. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  135. while (inCount-- > 0) { \
  136. *(inType *)bufPtr = *inVec++; \
  137. bufPtr += inSize; \
  138. } \
  139. }
  140. #define __GLS_PUT_BIN_VECSTRIDE(inType, inSize) \
  141. static void __glsWriter_put##inType##vs_bin( \
  142. __GLSwriter *inoutWriter, \
  143. GLboolean inItemSwap, \
  144. GLint inStride1DataItems, \
  145. GLint inStride1PadBytes, \
  146. GLint inStride1Count, \
  147. GLint inStride2PadBytes, \
  148. GLint inStride2Count, \
  149. const inType *inVec \
  150. ) { \
  151. GLint i, j; \
  152. GLubyte *bufPtr = inoutWriter->bufPtr; \
  153. inoutWriter->bufPtr += ( \
  154. inSize * inStride1DataItems * inStride1Count * inStride2Count \
  155. ); \
  156. if (inoutWriter->bufPtr > inoutWriter->commandTail) return; \
  157. if (inItemSwap) while (inStride2Count-- > 0) { \
  158. for ( \
  159. i = 0 ; \
  160. i < inStride1Count ; \
  161. ++i, \
  162. inVec = \
  163. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  164. ) { \
  165. for (j = 0 ; j < inStride1DataItems ; ++j, bufPtr += inSize) { \
  166. *(inType *)bufPtr = *inVec++; \
  167. __glsSwap##inSize(bufPtr); \
  168. } \
  169. } \
  170. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  171. } else while (inStride2Count-- > 0) { \
  172. for ( \
  173. i = 0 ; \
  174. i < inStride1Count ; \
  175. ++i, \
  176. inVec = \
  177. (const inType *)((const GLubyte *)inVec + inStride1PadBytes) \
  178. ) { \
  179. for (j = 0 ; j < inStride1DataItems ; ++j, bufPtr += inSize) { \
  180. *(inType *)bufPtr = *inVec++; \
  181. } \
  182. } \
  183. inVec = (const inType *)((const GLubyte *)inVec + inStride2PadBytes); \
  184. } \
  185. }
  186. /******************************************************************************
  187. Writers
  188. ******************************************************************************/
  189. static GLboolean __glsWriter_alloc_bin(
  190. __GLSwriter *inoutWriter, size_t inWordCount
  191. ) {
  192. if (!__glsWriter_flush(inoutWriter)) return GL_FALSE;
  193. if (inoutWriter->bufPtr + inWordCount * 4 <= inoutWriter->bufTail) {
  194. return GL_TRUE;
  195. }
  196. free(inoutWriter->externBuf);
  197. if (inoutWriter->wordCount & 1) ++inWordCount;
  198. if (
  199. inoutWriter->externBuf = inoutWriter->externBufHead = __glsMalloc(
  200. inWordCount * 4
  201. )
  202. ) {
  203. if (inoutWriter->wordCount & 1) inoutWriter->externBufHead += 4;
  204. inoutWriter->bufPtr = inoutWriter->externBufHead;
  205. inoutWriter->bufTail = inoutWriter->externBuf + inWordCount * 4;
  206. return GL_TRUE;
  207. } else {
  208. inoutWriter->bufPtr = GLS_NONE;
  209. inoutWriter->bufTail = GLS_NONE;
  210. inoutWriter->error = GL_TRUE;
  211. return GL_FALSE;
  212. }
  213. }
  214. static GLboolean __glsWriter_alloc_context(
  215. __GLSwriter *inoutWriter, size_t inWordCount
  216. ) {
  217. __GLScontextStream *const stream = inoutWriter->contextStream;
  218. __GLScontextStreamBlock *const block = __glsContextStream_lastBlock(
  219. stream
  220. );
  221. const size_t fillBytes = (size_t)((ULONG_PTR)(inoutWriter->bufPtr - block->buf));
  222. const GLfloat fillFrac = (
  223. (GLfloat)(fillBytes + __GLS_JUMP_ALLOC) /
  224. (GLfloat)(block->bufTail - block->buf)
  225. );
  226. const size_t reqBytes = (inWordCount + 1) * 4 + __GLS_JUMP_ALLOC;
  227. __glsWriter_flush(inoutWriter);
  228. block->writeTail = inoutWriter->bufPtr;
  229. if (fillFrac < __GLS_FULL_CONTEXT_STREAM_BLOCK) {
  230. GLubyte *const buf = __glsMalloc(fillBytes + reqBytes);
  231. if (buf) {
  232. size_t i = fillBytes;
  233. __GLS_LIST_ITER(__GLScontextStreamBlock) iter;
  234. while (i-- > 0) buf[i] = block->buf[i];
  235. free(block->buf);
  236. block->buf = buf;
  237. block->bufTail = buf + fillBytes + reqBytes;
  238. block->writeTail = buf + fillBytes;
  239. inoutWriter->bufPtr = block->writeTail;
  240. inoutWriter->bufTail = block->bufTail - __GLS_JUMP_ALLOC;
  241. iter.elem = block;
  242. __GLS_LIST_PREV(&stream->blockList, &iter);
  243. if (iter.elem) {
  244. __glsContextStreamBlock_removeJump(iter.elem);
  245. __glsContextStreamBlock_addJump(iter.elem, buf);
  246. }
  247. return GL_TRUE;
  248. } else {
  249. inoutWriter->error = GL_TRUE;
  250. return GL_FALSE;
  251. }
  252. } else {
  253. __GLScontextStreamBlock *const newBlock = (
  254. __glsContextStream_appendBlock(
  255. stream, __GLS_MAX(__GLS_CONTEXT_STREAM_BLOCK_BYTES, reqBytes)
  256. )
  257. );
  258. if (newBlock) {
  259. if (inoutWriter->wordCount & 1) {
  260. __glsContextStreamBlock_addPad(newBlock);
  261. }
  262. inoutWriter->bufPtr = newBlock->writeTail;
  263. __glsContextStreamBlock_addJump(block, inoutWriter->bufPtr);
  264. inoutWriter->bufTail = newBlock->bufTail - __GLS_JUMP_ALLOC;
  265. return GL_TRUE;
  266. } else {
  267. inoutWriter->error = GL_TRUE;
  268. return GL_FALSE;
  269. }
  270. }
  271. }
  272. static GLboolean __glsWriter_beginCommand_bin(
  273. __GLSwriter *inoutWriter, GLSopcode inOpcode, size_t inByteCount
  274. ) {
  275. size_t wordCount = (inByteCount + 3) >> 2;
  276. GLboolean longForm;
  277. GLSopcode opcode;
  278. if (inoutWriter->error) return GL_FALSE;
  279. if (inoutWriter->type == GLS_CONTEXT) {
  280. opcode = __glsMapOpcode(inOpcode);
  281. } else {
  282. opcode = inOpcode;
  283. }
  284. longForm = (GLboolean)(
  285. opcode == GLS_OP_glsBeginGLS ||
  286. opcode == GLS_OP_glsEndGLS ||
  287. opcode >= 65536 ||
  288. wordCount >= 65535
  289. );
  290. wordCount += longForm ? 3 : 1;
  291. if (wordCount > UINT_MAX) {
  292. glsError(inOpcode, GLS_ENCODE_ERROR);
  293. return GL_FALSE;
  294. }
  295. if (
  296. inoutWriter->bufPtr + wordCount * 4 > inoutWriter->bufTail &&
  297. !inoutWriter->alloc(inoutWriter, wordCount)
  298. ) {
  299. return GL_FALSE;
  300. }
  301. inoutWriter->commandOpcode = inOpcode;
  302. inoutWriter->commandHead = inoutWriter->bufPtr;
  303. inoutWriter->commandTail = inoutWriter->bufPtr + wordCount * 4;
  304. inoutWriter->prevCommand = (
  305. (__GLSbinCommandHead_large *)inoutWriter->bufPtr
  306. );
  307. if (longForm) {
  308. inoutWriter->putGLushort(inoutWriter, GLS_NONE);
  309. inoutWriter->putGLushort(inoutWriter, 0);
  310. inoutWriter->putGLuint(inoutWriter, opcode);
  311. inoutWriter->putGLuint(inoutWriter, (GLuint)wordCount);
  312. } else {
  313. inoutWriter->putGLushort(inoutWriter, (GLushort)opcode);
  314. inoutWriter->putGLushort(inoutWriter, (GLushort)wordCount);
  315. }
  316. inoutWriter->wordCount += wordCount;
  317. return GL_TRUE;
  318. }
  319. static void __glsWriter_endCommand_bin(__GLSwriter *inoutWriter) {
  320. ptrdiff_t mod4 = ((ptrdiff_t)(inoutWriter->bufPtr - (GLubyte *)0)) & 3;
  321. if (mod4) while (mod4++ < 4) *inoutWriter->bufPtr++ = 0;
  322. if (inoutWriter->bufPtr != inoutWriter->commandTail) {
  323. inoutWriter->bufPtr = inoutWriter->commandHead;
  324. fprintf(
  325. stderr,
  326. "GLS encoder error on command %s\n",
  327. __glsOpcodeString[__glsMapOpcode(inoutWriter->commandOpcode)]
  328. );
  329. exit(EXIT_FAILURE);
  330. }
  331. }
  332. static void __glsWriter_nextList_bin(__GLSwriter *inoutWriter) {
  333. }
  334. static GLboolean __glsWriter_padWordCount_bin(
  335. __GLSwriter *inoutWriter, GLboolean inCountMod2
  336. ) {
  337. if (inoutWriter->error) return GL_FALSE;
  338. if ((inoutWriter->wordCount & 1) == inCountMod2) return GL_TRUE;
  339. if (inoutWriter->bufPtr + 4 > inoutWriter->bufTail) {
  340. if (!inoutWriter->alloc(inoutWriter, 1)) return GL_FALSE;
  341. }
  342. if (
  343. inoutWriter->prevCommand &&
  344. inoutWriter->prevCommand->opSmall &&
  345. inoutWriter->prevCommand->countSmall != USHRT_MAX
  346. ) {
  347. ++inoutWriter->prevCommand->countSmall;
  348. inoutWriter->commandTail += 4;
  349. inoutWriter->putGLuint(inoutWriter, 0);
  350. ++inoutWriter->wordCount;
  351. return GL_TRUE;
  352. } else if (
  353. inoutWriter->prevCommand &&
  354. inoutWriter->prevCommand->opLarge != GLS_OP_glsBeginGLS &&
  355. inoutWriter->prevCommand->countLarge != ULONG_MAX
  356. ) {
  357. ++inoutWriter->prevCommand->countLarge;
  358. inoutWriter->commandTail += 4;
  359. inoutWriter->putGLuint(inoutWriter, 0);
  360. ++inoutWriter->wordCount;
  361. return GL_TRUE;
  362. } else {
  363. if (inoutWriter->beginCommand(inoutWriter, GLS_OP_glsPad, 0)) {
  364. inoutWriter->endCommand(inoutWriter);
  365. return GL_TRUE;
  366. } else {
  367. return GL_FALSE;
  368. }
  369. }
  370. }
  371. static GLboolean __glsWriter_padWordCount_bin_swap(
  372. __GLSwriter *inoutWriter, GLboolean inCountMod2
  373. ) {
  374. if (inoutWriter->error) return GL_FALSE;
  375. if ((inoutWriter->wordCount & 1) == inCountMod2) return GL_TRUE;
  376. if (inoutWriter->bufPtr + 4 > inoutWriter->bufTail) {
  377. if (!inoutWriter->alloc(inoutWriter, 1)) return GL_FALSE;
  378. }
  379. if (
  380. inoutWriter->prevCommand &&
  381. inoutWriter->prevCommand->opSmall &&
  382. inoutWriter->prevCommand->countSmall != USHRT_MAX
  383. ) {
  384. __glsSwap2(&inoutWriter->prevCommand->countSmall);
  385. ++inoutWriter->prevCommand->countSmall;
  386. __glsSwap2(&inoutWriter->prevCommand->countSmall);
  387. inoutWriter->commandTail += 4;
  388. inoutWriter->putGLuint(inoutWriter, 0);
  389. ++inoutWriter->wordCount;
  390. return GL_TRUE;
  391. } else if (
  392. inoutWriter->prevCommand &&
  393. (
  394. __glsSwapi((GLint)inoutWriter->prevCommand->opLarge) !=
  395. GLS_OP_glsBeginGLS
  396. ) &&
  397. inoutWriter->prevCommand->countLarge != ULONG_MAX
  398. ) {
  399. __glsSwap4(&inoutWriter->prevCommand->countLarge);
  400. ++inoutWriter->prevCommand->countLarge;
  401. __glsSwap4(&inoutWriter->prevCommand->countLarge);
  402. inoutWriter->commandTail += 4;
  403. inoutWriter->putGLuint(inoutWriter, 0);
  404. ++inoutWriter->wordCount;
  405. return GL_TRUE;
  406. } else {
  407. if (inoutWriter->beginCommand(inoutWriter, GLS_OP_glsPad, 0)) {
  408. inoutWriter->endCommand(inoutWriter);
  409. return GL_TRUE;
  410. } else {
  411. return GL_FALSE;
  412. }
  413. }
  414. }
  415. static void __glsWriter_putGLbitvs_bin(
  416. __GLSwriter *inoutWriter,
  417. GLboolean inItemSwap,
  418. GLint inItemLeftShift,
  419. GLint inStrideDataItems,
  420. GLint inStridePadItems,
  421. GLint inStrideCount,
  422. const GLubyte *inVec
  423. ) {
  424. GLubyte *bufPtr = inoutWriter->bufPtr;
  425. GLint i;
  426. const GLint highShift = inItemLeftShift;
  427. const GLint lowShift = 8 - inItemLeftShift;
  428. GLubyte lastMask = 0xffu;
  429. if (inStrideDataItems & 7) lastMask <<= 8 - (inStrideDataItems & 7);
  430. inStrideDataItems = (inStrideDataItems + 7) >> 3;
  431. inStridePadItems >>= 3;
  432. inoutWriter->bufPtr += inStrideDataItems * inStrideCount;
  433. if (inoutWriter->bufPtr > inoutWriter->commandTail) return;
  434. if (!inItemSwap && !inItemLeftShift) while (inStrideCount-- > 0) {
  435. i = inStrideDataItems;
  436. while (i-- > 1) *bufPtr++ = *inVec++;
  437. if (!i) *bufPtr++ = (GLubyte)(*inVec++ & lastMask);
  438. inVec += inStridePadItems;
  439. } else if (!inItemLeftShift) while (inStrideCount-- > 0) {
  440. i = inStrideDataItems;
  441. while (i-- > 1) *bufPtr++ = __glsBitReverse[*inVec++];
  442. if (!i) *bufPtr++ = (GLubyte)(__glsBitReverse[*inVec++] & lastMask);
  443. inVec += inStridePadItems;
  444. } else if (!inItemSwap) while (inStrideCount-- > 0) {
  445. i = inStrideDataItems;
  446. while (i-- > 1) {
  447. *bufPtr++ = (GLubyte)(*inVec++ << highShift | *inVec >> lowShift);
  448. }
  449. if (!i) *bufPtr++ = (GLubyte)((*inVec++ & lastMask) << highShift);
  450. inVec += inStridePadItems;
  451. } else while (inStrideCount-- > 0) {
  452. i = inStrideDataItems;
  453. while (i-- > 1) *bufPtr++ = (GLubyte)(
  454. __glsBitReverse[*inVec++] << highShift |
  455. __glsBitReverse[*inVec] >> lowShift
  456. );
  457. if (!i) {
  458. *bufPtr++ = (GLubyte)(
  459. (__glsBitReverse[*inVec++] & lastMask) << highShift
  460. );
  461. }
  462. inVec += inStridePadItems;
  463. }
  464. }
  465. __GLS_PUT_BIN(GLbyte, 1)
  466. __GLS_PUT_BIN(GLubyte, 1)
  467. __GLS_PUT_BIN_ENUM(GLint, GLenum)
  468. __GLS_PUT_BIN_ENUM(GLfloat, GLenum)
  469. __GLS_PUT_BIN_ENUM(GLdouble, GLenum)
  470. __GLS_PUT_BIN_ENUM_VAL(GLint, GLSenum)
  471. __GLS_PUT_BIN_SWAP(GLshort, 2)
  472. __GLS_PUT_BIN_SWAP(GLushort, 2)
  473. __GLS_PUT_BIN_SWAP(GLint, 4)
  474. __GLS_PUT_BIN_SWAP(GLuint, 4)
  475. __GLS_PUT_BIN_SWAP(GLfloat, 4)
  476. __GLS_PUT_BIN_SWAP(GLdouble, 8)
  477. __GLS_PUT_BIN_SWAP_VAL(GLlong, 8)
  478. __GLS_PUT_BIN_SWAP_VAL(GLulong, 8)
  479. __GLS_PUT_BIN_SWAP_VEC(GLlong, 8)
  480. __GLS_PUT_BIN_SWAP_VEC(GLulong, 8)
  481. __GLS_PUT_BIN_VAL(GLlong, 8)
  482. __GLS_PUT_BIN_VAL(GLulong, 8)
  483. __GLS_PUT_BIN_VEC(GLlong, 8)
  484. __GLS_PUT_BIN_VEC(GLulong, 8)
  485. static void __glsWriter_putGLdoublem_bin(
  486. __GLSwriter *inoutWriter, const GLdouble *inMat
  487. ) {
  488. __glsWriter_putGLdoublev_bin(inoutWriter, 16, inMat);
  489. }
  490. static void __glsWriter_putGLdoublem_bin_swap(
  491. __GLSwriter *inoutWriter, const GLdouble *inMat
  492. ) {
  493. __glsWriter_putGLdoublev_bin_swap(inoutWriter, 16, inMat);
  494. }
  495. static void __glsWriter_putGLfloatm_bin(
  496. __GLSwriter *inoutWriter, const GLfloat *inMat
  497. ) {
  498. __glsWriter_putGLfloatv_bin(inoutWriter, 16, inMat);
  499. }
  500. static void __glsWriter_putGLfloatm_bin_swap(
  501. __GLSwriter *inoutWriter, const GLfloat *inMat
  502. ) {
  503. __glsWriter_putGLfloatv_bin_swap(inoutWriter, 16, inMat);
  504. }
  505. static void __glsWriter_putGLoutArg_bin(
  506. __GLSwriter *inoutWriter, GLuint inIndex, const GLvoid *inVal
  507. ) {
  508. __GLScontext *const ctx = __GLS_CONTEXT;
  509. __glsWriter_putGLulong_bin(
  510. inoutWriter,
  511. (
  512. ctx->callNesting &&
  513. !ctx->commandFuncs[__glsMapOpcode(inoutWriter->commandOpcode)]
  514. ) ?
  515. ctx->outArgs.vals[inIndex] :
  516. __glsPtrToULong(inVal)
  517. );
  518. }
  519. static void __glsWriter_putGLoutArg_bin_swap(
  520. __GLSwriter *inoutWriter, GLuint inIndex, const GLvoid *inVal
  521. ) {
  522. __GLScontext *const ctx = __GLS_CONTEXT;
  523. __glsWriter_putGLulong_bin_swap(
  524. inoutWriter,
  525. (
  526. ctx->callNesting &&
  527. !ctx->commandFuncs[__glsMapOpcode(inoutWriter->commandOpcode)]
  528. ) ?
  529. ctx->outArgs.vals[inIndex] :
  530. __glsPtrToULong(inVal)
  531. );
  532. }
  533. /******************************************************************************
  534. Dispatch setup
  535. ******************************************************************************/
  536. #define __GLS_INIT_PUT_BIN(inDst, inSrc) \
  537. __GLS_INIT_PUT_BIN_VAL(inDst, inSrc); \
  538. __GLS_INIT_PUT_BIN_VEC(inDst, inSrc); \
  539. __GLS_INIT_PUT_BIN_VECSTRIDE(inDst, inSrc);
  540. #define __GLS_INIT_PUT_BIN_SWAP(inDst, inSrc) \
  541. __GLS_INIT_PUT_BIN_SWAP_VAL(inDst, inSrc); \
  542. __GLS_INIT_PUT_BIN_SWAP_VEC(inDst, inSrc); \
  543. __GLS_INIT_PUT_BIN_SWAP_VECSTRIDE(inDst, inSrc);
  544. #define __GLS_INIT_PUT_BIN_SWAP_MAT(inDst, inSrc) \
  545. inoutWriter->put##inDst##m = ( \
  546. swap ? \
  547. __glsWriter_put##inSrc##m_bin_swap : __glsWriter_put##inSrc##m_bin \
  548. );
  549. #define __GLS_INIT_PUT_BIN_SWAP_VAL(inDst, inSrc) \
  550. inoutWriter->put##inDst = ( \
  551. swap ? \
  552. __glsWriter_put##inSrc##_bin_swap : __glsWriter_put##inSrc##_bin \
  553. );
  554. #define __GLS_INIT_PUT_BIN_SWAP_VEC(inDst, inSrc) \
  555. inoutWriter->put##inDst##v = ( \
  556. swap ? \
  557. __glsWriter_put##inSrc##v_bin_swap : __glsWriter_put##inSrc##v_bin \
  558. );
  559. #define __GLS_INIT_PUT_BIN_SWAP_VECSTRIDE(inDst, inSrc) \
  560. inoutWriter->put##inDst##vs = ( \
  561. swap ? \
  562. __glsWriter_put##inSrc##vs_bin_swap : __glsWriter_put##inSrc##vs_bin \
  563. );
  564. #define __GLS_INIT_PUT_BIN_VAL(inDst, inSrc) \
  565. inoutWriter->put##inDst = __glsWriter_put##inSrc##_bin;
  566. #define __GLS_INIT_PUT_BIN_VEC(inDst, inSrc) \
  567. inoutWriter->put##inDst##v = __glsWriter_put##inSrc##v_bin;
  568. #define __GLS_INIT_PUT_BIN_VECSTRIDE(inDst, inSrc) \
  569. inoutWriter->put##inDst##vs = __glsWriter_put##inSrc##vs_bin;
  570. void __glsWriter_initDispatch_bin(
  571. __GLSwriter *inoutWriter, GLSenum inStreamType
  572. ) {
  573. const GLboolean swap = (GLboolean)(inStreamType == __GLS_BINARY_SWAP1);
  574. if (inStreamType == GLS_CONTEXT) {
  575. inoutWriter->alloc = __glsWriter_alloc_context;
  576. } else {
  577. inoutWriter->alloc = __glsWriter_alloc_bin;
  578. }
  579. inoutWriter->beginCommand = __glsWriter_beginCommand_bin;
  580. inoutWriter->endCommand = __glsWriter_endCommand_bin;
  581. inoutWriter->nextList = __glsWriter_nextList_bin;
  582. inoutWriter->padWordCount = (
  583. swap ? __glsWriter_padWordCount_bin_swap : __glsWriter_padWordCount_bin
  584. );
  585. __GLS_INIT_PUT_BIN(GLbyte, GLbyte);
  586. __GLS_INIT_PUT_BIN(GLubyte, GLubyte);
  587. __GLS_INIT_PUT_BIN_SWAP(GLdouble, GLdouble);
  588. __GLS_INIT_PUT_BIN_SWAP(GLfloat, GLfloat);
  589. __GLS_INIT_PUT_BIN_SWAP(GLint, GLint);
  590. __GLS_INIT_PUT_BIN_SWAP(GLshort, GLshort);
  591. __GLS_INIT_PUT_BIN_SWAP(GLuint, GLuint);
  592. __GLS_INIT_PUT_BIN_SWAP(GLushort, GLushort);
  593. __GLS_INIT_PUT_BIN_SWAP_MAT(GLdouble, GLdouble);
  594. __GLS_INIT_PUT_BIN_SWAP_MAT(GLfloat, GLfloat);
  595. __GLS_INIT_PUT_BIN_SWAP_VAL(GLSenum, GLuint);
  596. __GLS_INIT_PUT_BIN_SWAP_VAL(GLSimageFlags, GLuint);
  597. __GLS_INIT_PUT_BIN_SWAP_VAL(GLSopcode, GLuint);
  598. __GLS_INIT_PUT_BIN_SWAP_VAL(GLattribMask, GLuint);
  599. __GLS_INIT_PUT_BIN_SWAP_VAL(GLblendingFactor, GLuint);
  600. __GLS_INIT_PUT_BIN_SWAP_VAL(GLclearBufferMask, GLuint);
  601. __GLS_INIT_PUT_BIN_SWAP_VAL(GLdrawBufferMode, GLuint);
  602. __GLS_INIT_PUT_BIN_SWAP_VAL(GLenum, GLuint);
  603. __GLS_INIT_PUT_BIN_SWAP_VAL(GLlong, GLlong);
  604. __GLS_INIT_PUT_BIN_SWAP_VAL(GLoutArg, GLoutArg);
  605. __GLS_INIT_PUT_BIN_SWAP_VAL(GLstencilOp, GLuint);
  606. __GLS_INIT_PUT_BIN_SWAP_VAL(GLtextureComponentCount, GLint);
  607. __GLS_INIT_PUT_BIN_SWAP_VAL(GLuinthex, GLuint);
  608. __GLS_INIT_PUT_BIN_SWAP_VAL(GLulong, GLulong);
  609. __GLS_INIT_PUT_BIN_SWAP_VAL(GLulonghex, GLulong);
  610. __GLS_INIT_PUT_BIN_SWAP_VAL(GLushorthex, GLushort);
  611. __GLS_INIT_PUT_BIN_SWAP_VEC(GLlong, GLlong);
  612. __GLS_INIT_PUT_BIN_SWAP_VEC(GLulong, GLulong);
  613. __GLS_INIT_PUT_BIN_VAL(GLboolean, GLubyte);
  614. __GLS_INIT_PUT_BIN_VAL(GLdoubleOrGLenum, GLdoubleOrGLenum);
  615. __GLS_INIT_PUT_BIN_VAL(GLfloatOrGLenum, GLfloatOrGLenum);
  616. __GLS_INIT_PUT_BIN_VAL(GLintOrGLSenum, GLintOrGLSenum);
  617. __GLS_INIT_PUT_BIN_VAL(GLintOrGLenum, GLintOrGLenum);
  618. __GLS_INIT_PUT_BIN_VEC(GLboolean, GLubyte);
  619. __GLS_INIT_PUT_BIN_VEC(GLchar, GLubyte);
  620. __GLS_INIT_PUT_BIN_VEC(GLdoubleOrGLenum, GLdoubleOrGLenum);
  621. __GLS_INIT_PUT_BIN_VEC(GLfloatOrGLenum, GLfloatOrGLenum);
  622. __GLS_INIT_PUT_BIN_VEC(GLintOrGLenum, GLintOrGLenum);
  623. __GLS_INIT_PUT_BIN_VECSTRIDE(GLbit, GLbit);
  624. __GLS_INIT_PUT_BIN_VECSTRIDE(GLboolean, GLubyte);
  625. }