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.

579 lines
19 KiB

  1. #if !defined(__glsutil_h_)
  2. #define __glsutil_h_
  3. /*
  4. ** Copyright 1995-2095, Silicon Graphics, Inc.
  5. ** All Rights Reserved.
  6. **
  7. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  8. ** the contents of this file may not be disclosed to third parties, copied or
  9. ** duplicated in any form, in whole or in part, without the prior written
  10. ** permission of Silicon Graphics, Inc.
  11. **
  12. ** RESTRICTED RIGHTS LEGEND:
  13. ** Use, duplication or disclosure by the Government is subject to restrictions
  14. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  15. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  16. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  17. ** rights reserved under the Copyright Laws of the United States.
  18. */
  19. #include <glmf.h>
  20. #include <assert.h>
  21. #if defined(__cplusplus)
  22. extern "C" {
  23. #endif
  24. /******************************************************************************
  25. Array
  26. ******************************************************************************/
  27. #define __GLS_ARRAY(inType) \
  28. struct { \
  29. inType *base; \
  30. size_t count; \
  31. size_t bufCount; \
  32. }
  33. typedef __GLS_ARRAY(GLvoid) __GLSarray;
  34. #define __GLS_ARRAY_CHECK(inArray) \
  35. assert( \
  36. sizeof((inArray)->base) && \
  37. sizeof(*(inArray)) == sizeof(__GLSarray) \
  38. )
  39. #define __GLS_ARRAY_APPEND(inoutArray, inCount, inInit) \
  40. __GLS_ARRAY_CHECK(inoutArray); \
  41. __glsArray_insert( \
  42. (__GLSarray *)inoutArray, \
  43. inoutArray->count, \
  44. inCount, \
  45. inInit, \
  46. sizeof(*(inoutArray)->base) \
  47. )
  48. #define __GLS_ARRAY_FINAL(inoutArray) \
  49. __GLS_ARRAY_CHECK(inoutArray); \
  50. __glsArray_final((__GLSarray *)inoutArray)
  51. #define __GLS_ARRAY_INIT(outArray) \
  52. __GLS_ARRAY_CHECK(outArray); \
  53. __glsArray_init((__GLSarray *)outArray)
  54. #define __GLS_ARRAY_COMPACT(inoutArray) \
  55. __GLS_ARRAY_CHECK(inoutArray); \
  56. __glsArray_compact((__GLSarray *)inoutArray, sizeof(*(inoutArray)->base))
  57. #define __GLS_ARRAY_DELETE(inoutArray, inIndex, inCount) \
  58. __GLS_ARRAY_CHECK(inoutArray); \
  59. __glsArray_delete( \
  60. (__GLSarray *)inoutArray, \
  61. inIndex, \
  62. inCount, \
  63. sizeof(*(inoutArray)->base) \
  64. )
  65. #define __GLS_ARRAY_INSERT(inoutArray, inIndex, inCount, inInit) \
  66. __GLS_ARRAY_CHECK(inoutArray); \
  67. __glsArray_insert( \
  68. (__GLSarray *)inoutArray, \
  69. inIndex, \
  70. inCount, \
  71. inInit, \
  72. sizeof(*(inoutArray)->base) \
  73. )
  74. extern void __glsArray_final(__GLSarray *inoutArray);
  75. extern void __glsArray_init(__GLSarray *outArray);
  76. extern void __glsArray_compact(__GLSarray *inoutArray, size_t inElemSize);
  77. extern void __glsArray_delete(
  78. __GLSarray *inoutArray,
  79. size_t inIndex,
  80. size_t inCount,
  81. size_t inElemSize
  82. );
  83. extern GLboolean __glsArray_insert(
  84. __GLSarray *inoutArray,
  85. size_t inIndex,
  86. size_t inCount,
  87. GLboolean inInit,
  88. size_t inElemSize
  89. );
  90. /******************************************************************************
  91. Checksum
  92. ******************************************************************************/
  93. #define __GLS_CRC32_STEP(inCRC, inByte) \
  94. inCRC = (inCRC << 8) ^ __glsCRC32table[(inCRC >> 24) ^ inByte];
  95. extern const GLuint __glsCRC32table[256];
  96. /******************************************************************************
  97. Dict
  98. ******************************************************************************/
  99. typedef struct __GLSdict __GLSdict;
  100. extern __GLSdict* __glsIntDict_create(size_t inTableCount);
  101. extern __GLSdict* __glsIntDict_destroy(__GLSdict *inDict);
  102. extern void __glsIntDict_print(__GLSdict *inoutDict, const GLubyte *inName);
  103. extern void __glsIntDict_remove(__GLSdict *inoutDict, GLint inKey);
  104. extern GLboolean __glsInt2IntDict_add(
  105. __GLSdict *inoutDict, GLint inKey, GLint inVal
  106. );
  107. extern GLboolean __glsInt2IntDict_find(
  108. const __GLSdict *inDict, GLint inKey, GLint *optoutVal
  109. );
  110. extern GLboolean __glsInt2IntDict_replace(
  111. __GLSdict *inoutDict, GLint inKey, GLint inVal
  112. );
  113. extern GLboolean __glsInt2PtrDict_add(
  114. __GLSdict *inoutDict, GLint inKey, GLvoid *inVal
  115. );
  116. extern GLvoid* __glsInt2PtrDict_find(
  117. const __GLSdict *inDict, GLint inKey
  118. );
  119. extern GLboolean __glsInt2PtrDict_replace(
  120. __GLSdict *inoutDict, GLint inKey, GLvoid *inVal
  121. );
  122. extern __GLSdict* __glsStrDict_create(
  123. size_t inTableCount, GLboolean inStaticKeys
  124. );
  125. extern __GLSdict* __glsStrDict_destroy(__GLSdict *inDict);
  126. extern void __glsStrDict_print(__GLSdict *inoutDict, const GLubyte *inName);
  127. extern void __glsStrDict_remove(__GLSdict *inoutDict, const GLubyte *inKey);
  128. extern GLboolean __glsStr2IntDict_add(
  129. __GLSdict *inoutDict, const GLubyte *inKey, GLint inVal
  130. );
  131. extern GLboolean __glsStr2IntDict_find(
  132. const __GLSdict *inDict, const GLubyte *inKey, GLint *optoutVal
  133. );
  134. extern GLboolean __glsStr2IntDict_replace(
  135. __GLSdict *inoutDict, const GLubyte *inKey, GLint inVal
  136. );
  137. extern GLboolean __glsStr2PtrDict_add(
  138. __GLSdict *inoutDict, const GLubyte *inKey, GLvoid *inVal
  139. );
  140. extern GLvoid* __glsStr2PtrDict_find(
  141. const __GLSdict *inDict, const GLubyte *inKey
  142. );
  143. extern GLboolean __glsStr2PtrDict_replace(
  144. __GLSdict *inoutDict, const GLubyte *inKey, GLvoid *inVal
  145. );
  146. /******************************************************************************
  147. List
  148. ******************************************************************************/
  149. #define __GLS_LIST(inType) \
  150. struct { \
  151. inType *head; \
  152. }
  153. #define __GLS_LIST_ITER(inType) \
  154. struct { \
  155. inType *elem; \
  156. }
  157. typedef struct __GLSlistElem __GLSlistElem;
  158. typedef void (*__GLSlistElemDestructor)(__GLSlistElem *inElem);
  159. typedef __GLS_LIST(__GLSlistElem) __GLSlist;
  160. typedef __GLS_LIST_ITER(__GLSlistElem) __GLSlistIter;
  161. struct __GLSlistElem {
  162. __GLSlistElem *next;
  163. __GLSlistElem *prev;
  164. };
  165. #define __GLS_LIST_ELEM \
  166. __GLSlistElem __glsListElem
  167. #define __GLS_LIST_CHECK(inList) \
  168. assert(sizeof((inList)->head) && sizeof(*(inList)) == sizeof(__GLSlist))
  169. #define __GLS_LIST_ELEM_CHECK(inElem) \
  170. assert(sizeof((inElem)->__glsListElem.next))
  171. #define __GLS_LIST_ITER_CHECK(inIter) \
  172. assert( \
  173. sizeof((inIter)->elem) && sizeof(*(inIter)) == sizeof(__GLSlistIter) \
  174. )
  175. #define __GLS_LIST_APPEND(inoutList, inoutElem) \
  176. __GLS_LIST_CHECK(inoutList); \
  177. __GLS_LIST_ELEM_CHECK(inoutElem); \
  178. __glsListAppend((__GLSlist *)(inoutList), (__GLSlistElem *)(inoutElem))
  179. #define __GLS_LIST_CLEAR_DESTROY(inoutList, inDestructor) \
  180. __GLS_LIST_CHECK(inoutList); \
  181. __glsListClearDestroy( \
  182. (__GLSlist *)(inoutList), (__GLSlistElemDestructor)(inDestructor) \
  183. )
  184. #define __GLS_LIST_FIRST(inList, inoutIter) \
  185. __GLS_LIST_CHECK(inList); \
  186. __GLS_LIST_ITER_CHECK(inoutIter); \
  187. __glsListFirst((__GLSlist *)(inList), (__GLSlistIter *)(inoutIter))
  188. #define __GLS_LIST_LAST(inList, inoutIter) \
  189. __GLS_LIST_CHECK(inList); \
  190. __GLS_LIST_ITER_CHECK(inoutIter); \
  191. __glsListLast((__GLSlist *)(inList), (__GLSlistIter *)(inoutIter))
  192. #define __GLS_LIST_NEXT(inList, inoutIter) \
  193. __GLS_LIST_CHECK(inList); \
  194. __GLS_LIST_ITER_CHECK(inoutIter); \
  195. __glsListNext((__GLSlist *)(inList), (__GLSlistIter *)(inoutIter))
  196. #define __GLS_LIST_PREPEND(inoutList, inoutElem) \
  197. __GLS_LIST_CHECK(inoutList); \
  198. __GLS_LIST_ELEM_CHECK(inoutElem); \
  199. __glsListPrepend((__GLSlist *)(inoutList), (__GLSlistElem *)(inoutElem))
  200. #define __GLS_LIST_PREV(inList, inoutIter) \
  201. __GLS_LIST_CHECK(inList); \
  202. __GLS_LIST_ITER_CHECK(inoutIter); \
  203. __glsListPrev((__GLSlist *)(inList), (__GLSlistIter *)(inoutIter))
  204. #define __GLS_LIST_REMOVE(inoutList, inoutElem) \
  205. __GLS_LIST_CHECK(inoutList); \
  206. __GLS_LIST_ELEM_CHECK(inoutElem); \
  207. __glsListRemove((__GLSlist *)(inoutList), (__GLSlistElem*)(inoutElem))
  208. #define __GLS_LIST_REMOVE_DESTROY(inoutList, inElem, inDestructor) \
  209. __GLS_LIST_CHECK(inoutList); \
  210. __GLS_LIST_ELEM_CHECK(inElem); \
  211. __glsListRemoveDestroy( \
  212. (__GLSlist *)(inoutList), \
  213. (__GLSlistElem *)(inElem), \
  214. (__GLSlistElemDestructor)(inDestructor) \
  215. )
  216. extern void __glsListAppend(__GLSlist *inoutList, __GLSlistElem *inoutElem);
  217. extern void __glsListClearDestroy(
  218. __GLSlist *inoutList, __GLSlistElemDestructor inDestructor
  219. );
  220. extern void __glsListFirst(__GLSlist *inList, __GLSlistIter *inoutIter);
  221. extern void __glsListLast(__GLSlist *inList, __GLSlistIter *inoutIter);
  222. extern void __glsListNext(__GLSlist *inList, __GLSlistIter *inoutIter);
  223. extern void __glsListPrepend(__GLSlist *inoutList, __GLSlistElem *inoutElem);
  224. extern void __glsListPrev(__GLSlist *inList, __GLSlistIter *inoutIter);
  225. extern void __glsListRemove(__GLSlist *inoutList, __GLSlistElem *inoutElem);
  226. extern void __glsListRemoveDestroy(
  227. __GLSlist *inoutList,
  228. __GLSlistElem *inElem,
  229. __GLSlistElemDestructor inDestructor
  230. );
  231. /******************************************************************************
  232. IterList
  233. ******************************************************************************/
  234. #define __GLS_ITERLIST(inType) \
  235. struct { \
  236. inType *head; \
  237. size_t count; \
  238. inType *iterElem; \
  239. size_t iterIndex; \
  240. }
  241. typedef __GLS_ITERLIST(__GLSlistElem) __GLSiterList;
  242. #define __GLS_ITERLIST_CHECK(inList) \
  243. assert( \
  244. sizeof((inList)->head) && sizeof(*(inList)) == sizeof(__GLSiterList) \
  245. )
  246. #define __GLS_ITERLIST_APPEND(inoutList, inoutElem) \
  247. __GLS_ITERLIST_CHECK(inoutList); \
  248. __GLS_LIST_ELEM_CHECK(inoutElem); \
  249. __glsIterListAppend( \
  250. (__GLSiterList *)(inoutList), (__GLSlistElem *)(inoutElem) \
  251. )
  252. #define __GLS_ITERLIST_CLEAR_DESTROY(inoutList, inDestructor) \
  253. __GLS_ITERLIST_CHECK(inoutList); \
  254. __glsIterListClearDestroy( \
  255. (__GLSiterList *)(inoutList), (__GLSlistElemDestructor)(inDestructor) \
  256. )
  257. #define __GLS_ITERLIST_FIRST(inoutList) \
  258. __GLS_ITERLIST_CHECK(inoutList); \
  259. __glsIterListFirst((__GLSiterList *)(inoutList))
  260. #define __GLS_ITERLIST_LAST(inoutList) \
  261. __GLS_ITERLIST_CHECK(inoutList); \
  262. __glsIterListLast((__GLSiterList *)(inoutList))
  263. #define __GLS_ITERLIST_NEXT(inoutList) \
  264. __GLS_ITERLIST_CHECK(inoutList); \
  265. __glsIterListNext((__GLSiterList *)(inoutList))
  266. #define __GLS_ITERLIST_PREPEND(inoutList, inoutElem) \
  267. __GLS_ITERLIST_CHECK(inoutList); \
  268. __GLS_LIST_ELEM_CHECK(inoutElem); \
  269. __glsIterListPrepend( \
  270. (__GLSiterList *)(inoutList), (__GLSlistElem *)(inoutElem) \
  271. )
  272. #define __GLS_ITERLIST_PREV(inoutList) \
  273. __GLS_ITERLIST_CHECK(inoutList); \
  274. __glsIterListPrev((__GLSiterList *)(inoutList))
  275. #define __GLS_ITERLIST_REMOVE(inoutList, inoutElem) \
  276. __GLS_ITERLIST_CHECK(inoutList); \
  277. __GLS_LIST_ELEM_CHECK(inoutElem); \
  278. __glsIterListRemove( \
  279. (__GLSiterList *)(inoutList), (__GLSlistElem*)(inoutElem) \
  280. )
  281. #define __GLS_ITERLIST_REMOVE_DESTROY(inoutList, inElem, inDestructor) \
  282. __GLS_ITERLIST_CHECK(inoutList); \
  283. __GLS_LIST_ELEM_CHECK(inElem); \
  284. __glsIterListRemoveDestroy( \
  285. (__GLSiterList *)(inoutList), \
  286. (__GLSlistElem *)(inElem), \
  287. (__GLSlistElemDestructor)(inDestructor) \
  288. )
  289. #define __GLS_ITERLIST_SEEK(inoutList, inIndex) \
  290. __GLS_ITERLIST_CHECK(inoutList); \
  291. __glsIterListSeek((__GLSiterList *)(inoutList), inIndex)
  292. extern void __glsIterListAppend(
  293. __GLSiterList *inoutList, __GLSlistElem *inoutElem
  294. );
  295. extern void __glsIterListClearDestroy(
  296. __GLSiterList *inoutList, __GLSlistElemDestructor inDestructor
  297. );
  298. extern void __glsIterListFirst(__GLSiterList *inoutList);
  299. extern void __glsIterListLast(__GLSiterList *inoutList);
  300. extern void __glsIterListNext(__GLSiterList *inoutList);
  301. extern void __glsIterListPrepend(
  302. __GLSiterList *inoutList, __GLSlistElem *inoutElem
  303. );
  304. extern void __glsIterListPrev(__GLSiterList *inoutList);
  305. extern void __glsIterListRemove(
  306. __GLSiterList *inoutList, __GLSlistElem *inoutElem
  307. );
  308. extern void __glsIterListRemoveDestroy(
  309. __GLSiterList *inoutList,
  310. __GLSlistElem *inElem,
  311. __GLSlistElemDestructor inDestructor
  312. );
  313. extern void __glsIterListSeek(__GLSiterList *inoutList, size_t inIndex);
  314. /******************************************************************************
  315. Memory
  316. ******************************************************************************/
  317. extern GLvoid* __glsCalloc(size_t inCount, size_t inSize);
  318. extern GLvoid* __glsMalloc(size_t inSize);
  319. /******************************************************************************
  320. Nop
  321. ******************************************************************************/
  322. #define __GLS_NULL
  323. extern void __glsNop(void);
  324. /******************************************************************************
  325. Number
  326. ******************************************************************************/
  327. #define __GLS_MAX(in1, in2) ((in1) > (in2) ? (in1) : (in2))
  328. #define __GLS_MIN(in1, in2) ((in1) < (in2) ? (in1) : (in2))
  329. #define __GLS_SWAP_DECLARE \
  330. GLubyte __swapSave
  331. #define __GLS_SWAP(inPtr, in1, in2) \
  332. __swapSave = ((GLubyte*)(inPtr))[in1]; \
  333. ((GLubyte *)(inPtr))[in1] = ((GLubyte *)(inPtr))[in2]; \
  334. ((GLubyte *)(inPtr))[in2] = __swapSave;
  335. #define __GLS_SWAP1(inPtr)
  336. #define __GLS_SWAP2(inPtr) \
  337. __GLS_SWAP(inPtr, 0, 1);
  338. #define __GLS_SWAP4(inPtr) \
  339. __GLS_SWAP(inPtr, 0, 3); \
  340. __GLS_SWAP(inPtr, 1, 2);
  341. #define __GLS_SWAP8(inPtr) \
  342. __GLS_SWAP(inPtr, 0, 7); \
  343. __GLS_SWAP(inPtr, 1, 6); \
  344. __GLS_SWAP(inPtr, 2, 5); \
  345. __GLS_SWAP(inPtr, 3, 4);
  346. extern const GLubyte __glsBitReverse[256];
  347. extern const GLubyte __glsQuietNaN[8];
  348. extern size_t __glsCeilBase2(size_t inVal);
  349. extern size_t __glsLogBase2(size_t inVal);
  350. GLulong __glsPtrToULong(const GLvoid *inPtr);
  351. GLlong __glsSizeToLong(size_t inSize);
  352. #define __glsSwap1(inoutVec)
  353. extern void __glsSwap2(GLvoid *inoutVec);
  354. extern void __glsSwap2v(size_t inCount, GLvoid *inoutVec);
  355. extern void __glsSwap4(GLvoid *inoutVec);
  356. extern void __glsSwap4v(size_t inCount, GLvoid *inoutVec);
  357. extern void __glsSwap8(GLvoid *inoutVec);
  358. extern void __glsSwap8v(size_t inCount, GLvoid *inoutVec);
  359. extern GLint __glsSwapi(GLint inVal);
  360. extern GLshort __glsSwaps(GLshort inVal);
  361. extern void __glsSwapv(GLenum inType, size_t inBytes, GLvoid *inoutVec);
  362. /******************************************************************************
  363. String
  364. ******************************************************************************/
  365. #define __GLS_STRING_BUF_BYTES 32
  366. typedef GLubyte __GLSstringBuf[__GLS_STRING_BUF_BYTES];
  367. typedef struct {
  368. GLubyte *head;
  369. GLubyte *tail;
  370. GLubyte *bufTail;
  371. __GLSstringBuf buf;
  372. } __GLSstring;
  373. extern GLboolean __glsString_append(
  374. __GLSstring *inoutString, const GLubyte* inAppend
  375. );
  376. extern GLboolean __glsString_appendChar(
  377. __GLSstring *inoutString, GLubyte inAppend
  378. );
  379. extern GLboolean __glsString_appendCounted(
  380. __GLSstring *inoutString, const GLubyte* inAppend, size_t inCount
  381. );
  382. extern GLboolean __glsString_appendInt(
  383. __GLSstring *inoutString, const GLubyte *inFormat, GLint inVal
  384. );
  385. extern GLboolean __glsString_assign(
  386. __GLSstring *inoutString, const GLubyte *inAssign
  387. );
  388. extern GLboolean __glsString_assignCounted(
  389. __GLSstring *inoutString, const GLubyte *inAssign, size_t inCount
  390. );
  391. extern void __glsString_final(__GLSstring *inoutString);
  392. extern void __glsString_init(__GLSstring *outString);
  393. extern size_t __glsString_length(const __GLSstring *inString);
  394. extern void __glsString_reset(__GLSstring *inoutString);
  395. extern const GLubyte* __glsUCS1String(const GLubyte *inUTF8String);
  396. extern GLboolean __glsValidateString(const GLubyte *inString);
  397. /******************************************************************************
  398. Vertex array
  399. ******************************************************************************/
  400. #define __GLS_PAD_EIGHT(v) (((v) + 7) & ~7)
  401. #define __GLS_EXACT_ARRAY_SIZE(count, size, type) \
  402. ((count) * (size) * __glsTypeSize(type))
  403. #define __GLS_ARRAY_SIZE(count, size, type) \
  404. __GLS_PAD_EIGHT(__GLS_EXACT_ARRAY_SIZE(count, size, type))
  405. typedef struct
  406. {
  407. GLint size;
  408. GLenum type;
  409. GLsizei stride;
  410. const GLvoid *data;
  411. } __GLSsingleArrayState;
  412. #define __GLS_VERTEX_ARRAY_ENABLE 0x00000001
  413. #define __GLS_NORMAL_ARRAY_ENABLE 0x00000002
  414. #define __GLS_COLOR_ARRAY_ENABLE 0x00000004
  415. #define __GLS_INDEX_ARRAY_ENABLE 0x00000008
  416. #define __GLS_TEXTURE_COORD_ARRAY_ENABLE 0x00000010
  417. #define __GLS_EDGE_FLAG_ARRAY_ENABLE 0x00000020
  418. #define __GLS_ARRAY_COUNT 6
  419. typedef struct
  420. {
  421. GLuint enabled;
  422. __GLSsingleArrayState vertex;
  423. __GLSsingleArrayState normal;
  424. __GLSsingleArrayState color;
  425. __GLSsingleArrayState index;
  426. __GLSsingleArrayState textureCoord;
  427. __GLSsingleArrayState edgeFlag;
  428. } __GLSarrayState;
  429. extern void __glsGetArrayState(struct __GLScontext *ctx,
  430. __GLSarrayState *arrayState);
  431. extern GLint __glsArrayDataSize(GLsizei count, __GLSarrayState *arrayState);
  432. extern void __glsWriteArrayData(struct __GLSwriter *writer, GLint size,
  433. GLint first, GLsizei count,
  434. GLenum type, const GLvoid *indices,
  435. __GLSarrayState *arrayState);
  436. extern void __glsSetArrayState(struct __GLScontext *ctx, GLubyte *data);
  437. extern GLvoid *__glsSetArrayStateText(struct __GLScontext *ctx,
  438. struct __GLSreader *reader,
  439. GLuint *enabled, GLsizei *count);
  440. extern void __glsDisableArrayState(struct __GLScontext *ctx, GLuint enabled);
  441. extern void __glsSwapArrayData(GLubyte *data);
  442. typedef struct
  443. {
  444. void *freePtr;
  445. GLuint *indices;
  446. GLuint *vertices;
  447. GLint vtxCount;
  448. } __GLSdrawElementsState;
  449. extern GLint __glsDrawElementsDataSize(GLsizei count, GLenum type,
  450. const GLvoid *indices,
  451. __GLSarrayState *arrayState,
  452. __GLSdrawElementsState *deState);
  453. extern void __glsWriteDrawElementsData(struct __GLSwriter *writer, GLint size,
  454. GLsizei count,
  455. __GLSarrayState *arrayState,
  456. __GLSdrawElementsState *deState);
  457. #if defined(__cplusplus)
  458. }
  459. #endif
  460. #endif /* __glsutil_h_ */