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.

550 lines
17 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 <stdlib.h>
  19. #include <string.h>
  20. static GLclampf __glsFloatToClampf(GLfloat inVal) {
  21. if (inVal < 0.f) inVal = 0.f;
  22. if (inVal > 1.f) inVal = 1.f;
  23. return inVal;
  24. }
  25. void __gls_exec_glsBeginGLS(
  26. GLint inVersionMajor, GLint inVersionMinor
  27. ) {
  28. __GLS_CONTEXT->streamVersion.major = inVersionMajor;
  29. __GLS_CONTEXT->streamVersion.minor = inVersionMinor;
  30. }
  31. void __gls_exec_glsBlock(GLSenum inBlockType) {
  32. __GLScontext *const ctx = __GLS_CONTEXT;
  33. switch (inBlockType) {
  34. case GLS_FRAME:
  35. case GLS_INIT:
  36. case GLS_STATIC:
  37. ctx->blockType = inBlockType;
  38. break;
  39. case GLS_HEADER:
  40. if (__glsHeader_reset(&ctx->header)) ctx->blockType = inBlockType;
  41. break;
  42. default:
  43. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  44. break;
  45. }
  46. }
  47. GLSenum __gls_exec_glsCallStream(const GLubyte *inName) {
  48. __GLScontext *const ctx = __GLS_CONTEXT;
  49. __GLScontextStream *contextStream;
  50. __GLSreadStream *readStream;
  51. GLSenum outType = GLS_NONE;
  52. __GLSversion versionSave;
  53. if (ctx->abortMode) return outType;
  54. if (ctx->callNesting >= __GLS_MAX_CALL_NESTING) {
  55. __GLS_RAISE_ERROR(GLS_CALL_OVERFLOW);
  56. glsAbortCall(GLS_ALL);
  57. return outType;
  58. }
  59. if (!__glsValidateString(inName)) return outType;
  60. ++ctx->callNesting;
  61. versionSave = ctx->streamVersion;
  62. ctx->streamVersion.major = ctx->streamVersion.minor = 0;
  63. if (
  64. contextStream = __glsStr2PtrDict_find(ctx->contextStreamDict, inName)
  65. ) {
  66. GLint i;
  67. outType = GLS_CONTEXT;
  68. for (i = 0 ; i < ctx->captureNesting ; ++i) {
  69. if (ctx->writers[i]->contextStream == contextStream) {
  70. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  71. outType = GLS_NONE;
  72. break;
  73. }
  74. }
  75. if (outType == GLS_CONTEXT) __glsContextStream_call(contextStream);
  76. } else if (readStream = __glsReadStream_create(inName)) {
  77. __GLSreader reader;
  78. if (__glsReader_init_stream(
  79. &reader, readStream, __GLS_READER_BUF_BYTES
  80. )) {
  81. outType = reader.type;
  82. __glsReader_call(&reader);
  83. __glsReader_final(&reader);
  84. } else {
  85. __GLS_RAISE_ERROR(GLS_INVALID_STREAM);
  86. }
  87. __glsReadStream_destroy(readStream);
  88. } else {
  89. __GLS_RAISE_ERROR(GLS_NOT_FOUND);
  90. }
  91. --ctx->callNesting;
  92. switch (ctx->abortMode) {
  93. case GLS_ALL:
  94. if (!ctx->callNesting) glsAbortCall(GLS_NONE);
  95. break;
  96. case GLS_LAST:
  97. glsAbortCall(GLS_NONE);
  98. break;
  99. }
  100. ctx->streamVersion = versionSave;
  101. return outType;
  102. }
  103. void __gls_exec_glsEndGLS(void) {
  104. __GLS_CONTEXT->streamVersion.major = 0;
  105. __GLS_CONTEXT->streamVersion.minor = 0;
  106. }
  107. void __gls_exec_glsError(GLSopcode inOpcode, GLSenum inError) {
  108. if (
  109. inError &&
  110. (inError < GLS_CALL_OVERFLOW || inError > GLS_UNSUPPORTED_EXTENSION)
  111. ) {
  112. inError = GLS_INVALID_ENUM;
  113. }
  114. __GLS_RAISE_ERROR( UintToPtr(inError) );
  115. }
  116. void __gls_exec_glsGLRC(GLuint inGLRC) {
  117. __GLScontext *const ctx = __GLS_CONTEXT;
  118. if (!inGLRC || inGLRC > (GLuint)ctx->header.glrcCount) {
  119. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  120. } else {
  121. ctx->currentGLRC = inGLRC;
  122. }
  123. }
  124. void __gls_exec_glsGLRCLayer(
  125. GLuint inGLRC, GLuint inLayer, GLuint inReadLayer
  126. ) {
  127. __GLScontext *const ctx = __GLS_CONTEXT;
  128. if (
  129. !inGLRC ||
  130. inGLRC > (GLuint)ctx->header.glrcCount ||
  131. !inLayer ||
  132. inLayer > (GLuint)ctx->header.layerCount ||
  133. inReadLayer > (GLuint)ctx->header.layerCount
  134. ) {
  135. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  136. } else {
  137. __GLSglrc *const glrc = ctx->header.glrcs + inGLRC - 1;
  138. glrc->layer = inLayer;
  139. glrc->readLayer = inReadLayer;
  140. }
  141. }
  142. void __gls_exec_glsHeaderGLRCi(GLuint inGLRC, GLSenum inAttrib, GLint inVal) {
  143. __GLScontext *const ctx = __GLS_CONTEXT;
  144. __GLSglrc *glrc;
  145. if (ctx->blockType != GLS_HEADER) {
  146. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  147. return;
  148. }
  149. if (!inGLRC || inGLRC > (GLuint)ctx->header.glrcCount) {
  150. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  151. return;
  152. }
  153. glrc = ctx->header.glrcs + inGLRC - 1;
  154. switch (inAttrib) {
  155. case GLS_LAYER:
  156. if (inVal < 1 || inVal > ctx->header.layerCount) {
  157. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  158. } else {
  159. glrc->layer = inVal;
  160. }
  161. break;
  162. case GLS_READ_LAYER:
  163. if (inVal < 0 || inVal > ctx->header.layerCount) {
  164. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  165. } else {
  166. glrc->readLayer = inVal;
  167. }
  168. break;
  169. case GLS_SHARE_GLRC:
  170. if (inVal < 0 || inVal > ctx->header.glrcCount) {
  171. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  172. } else {
  173. glrc->shareGLRC = inVal;
  174. }
  175. break;
  176. default:
  177. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  178. break;
  179. }
  180. }
  181. void __gls_exec_glsHeaderLayerf(
  182. GLuint inLayer, GLSenum inAttrib, GLfloat inVal
  183. ) {
  184. __GLScontext *const ctx = __GLS_CONTEXT;
  185. __GLSlayer *layer;
  186. if (ctx->blockType != GLS_HEADER) {
  187. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  188. return;
  189. }
  190. if (!inLayer || inLayer > (GLuint)ctx->header.layerCount) {
  191. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  192. return;
  193. }
  194. layer = ctx->header.layers + inLayer - 1;
  195. switch (inAttrib) {
  196. case GLS_INVISIBLE_ASPECT:
  197. layer->invisibleAspect = inVal > 0.f ? inVal : 0.f;
  198. break;
  199. default:
  200. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  201. break;
  202. }
  203. }
  204. void __gls_exec_glsHeaderLayeri(
  205. GLuint inLayer, GLSenum inAttrib, GLint inVal
  206. ) {
  207. __GLScontext *const ctx = __GLS_CONTEXT;
  208. __GLSlayer *layer;
  209. if (ctx->blockType != GLS_HEADER) {
  210. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  211. return;
  212. }
  213. if (!inLayer || inLayer > (GLuint)ctx->header.layerCount) {
  214. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  215. return;
  216. }
  217. layer = ctx->header.layers + inLayer - 1;
  218. switch (inAttrib) {
  219. case GLS_DISPLAY_FORMAT:
  220. switch (inVal) {
  221. case GLS_IIII:
  222. case GLS_RGBA:
  223. case GLS_RRRA:
  224. layer->displayFormat = inVal;
  225. break;
  226. default:
  227. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  228. break;
  229. }
  230. break;
  231. case GLS_DOUBLEBUFFER:
  232. layer->doubleBuffer = inVal ? GL_TRUE : GL_FALSE;
  233. break;
  234. case GLS_INVISIBLE:
  235. layer->invisible = inVal ? GL_TRUE : GL_FALSE;
  236. break;
  237. case GLS_INVISIBLE_HEIGHT_PIXELS:
  238. layer->invisibleHeightPixels = inVal > 0 ? inVal : 0;
  239. break;
  240. case GLS_LEVEL:
  241. layer->level = inVal;
  242. break;
  243. case GLS_STEREO:
  244. layer->stereo = inVal ? GL_TRUE : GL_FALSE;
  245. break;
  246. case GLS_TRANSPARENT:
  247. layer->transparent = inVal ? GL_TRUE : GL_FALSE;
  248. break;
  249. case GLS_INDEX_BITS:
  250. layer->indexBits = inVal > 0 ? inVal : 0;
  251. break;
  252. case GLS_RED_BITS:
  253. layer->redBits = inVal > 0 ? inVal : 0;
  254. break;
  255. case GLS_GREEN_BITS:
  256. layer->greenBits = inVal > 0 ? inVal : 0;
  257. break;
  258. case GLS_BLUE_BITS:
  259. layer->blueBits = inVal > 0 ? inVal : 0;
  260. break;
  261. case GLS_ALPHA_BITS:
  262. layer->alphaBits = inVal > 0 ? inVal : 0;
  263. break;
  264. case GLS_DEPTH_BITS:
  265. layer->depthBits = inVal > 0 ? inVal : 0;
  266. break;
  267. case GLS_STENCIL_BITS:
  268. layer->stencilBits = inVal > 0 ? inVal : 0;
  269. break;
  270. case GLS_ACCUM_RED_BITS:
  271. layer->accumRedBits = inVal > 0 ? inVal : 0;
  272. break;
  273. case GLS_ACCUM_GREEN_BITS:
  274. layer->accumGreenBits = inVal > 0 ? inVal : 0;
  275. break;
  276. case GLS_ACCUM_BLUE_BITS:
  277. layer->accumBlueBits = inVal > 0 ? inVal : 0;
  278. break;
  279. case GLS_ACCUM_ALPHA_BITS:
  280. layer->accumAlphaBits = inVal > 0 ? inVal : 0;
  281. break;
  282. case GLS_AUX_BUFFERS:
  283. layer->auxBuffers = inVal > 0 ? inVal : 0;
  284. break;
  285. #if __GL_SGIS_multisample
  286. case GLS_SAMPLE_BUFFERS_SGIS:
  287. layer->sampleBuffers = inVal > 0 ? inVal : 0;
  288. break;
  289. case GLS_SAMPLES_SGIS:
  290. layer->samples = inVal > 0 ? inVal : 0;
  291. break;
  292. #endif /* __GL_SGIS_multisample */
  293. default:
  294. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  295. break;
  296. }
  297. }
  298. void __gls_exec_glsHeaderf(GLSenum inAttrib, GLfloat inVal) {
  299. __GLScontext *const ctx = __GLS_CONTEXT;
  300. __GLSheader *header;
  301. if (ctx->blockType != GLS_HEADER) {
  302. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  303. return;
  304. }
  305. header = &ctx->header;
  306. switch (inAttrib) {
  307. case GLS_ASPECT:
  308. header->aspect = inVal > 0.f ? inVal : 0.f;
  309. break;
  310. case GLS_BORDER_WIDTH:
  311. header->borderWidth = inVal > 0.f ? inVal : 0.f;
  312. break;
  313. case GLS_CONTRAST_RATIO:
  314. header->contrastRatio = inVal > 0.f ? inVal : 0.f;
  315. break;
  316. case GLS_HEIGHT_MM:
  317. header->heightMM = inVal > 0.f ? inVal : 0.f;
  318. break;
  319. default:
  320. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  321. break;
  322. }
  323. }
  324. void __gls_exec_glsHeaderfv(GLSenum inAttrib, const GLfloat *inVec) {
  325. __GLScontext *const ctx = __GLS_CONTEXT;
  326. __GLSheader *header;
  327. GLint i;
  328. if (ctx->blockType != GLS_HEADER) {
  329. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  330. return;
  331. }
  332. header = &ctx->header;
  333. switch (inAttrib) {
  334. case GLS_BORDER_COLOR:
  335. for (i = 0 ; i < 4 ; ++i) {
  336. header->borderColor[i] = __glsFloatToClampf(inVec[i]);
  337. }
  338. break;
  339. case GLS_GAMMA:
  340. for (i = 0 ; i < 4 ; ++i) {
  341. header->gamma[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  342. }
  343. break;
  344. case GLS_ORIGIN:
  345. for (i = 0 ; i < 2 ; ++i) header->origin[i] = inVec[i];
  346. break;
  347. case GLS_PAGE_COLOR:
  348. for (i = 0 ; i < 4 ; ++i) {
  349. header->pageColor[i] = __glsFloatToClampf(inVec[i]);
  350. }
  351. break;
  352. case GLS_PAGE_SIZE:
  353. for (i = 0 ; i < 2 ; ++i) {
  354. header->pageSize[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  355. }
  356. break;
  357. case GLS_RED_POINT:
  358. for (i = 0 ; i < 2 ; ++i) {
  359. header->redPoint[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  360. }
  361. break;
  362. case GLS_GREEN_POINT:
  363. for (i = 0 ; i < 2 ; ++i) {
  364. header->greenPoint[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  365. }
  366. break;
  367. case GLS_BLUE_POINT:
  368. for (i = 0 ; i < 2 ; ++i) {
  369. header->bluePoint[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  370. }
  371. break;
  372. case GLS_WHITE_POINT:
  373. for (i = 0 ; i < 2 ; ++i) {
  374. header->whitePoint[i] = inVec[i] > 0.f ? inVec[i] : 0.f;
  375. }
  376. break;
  377. default:
  378. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  379. break;
  380. }
  381. }
  382. void __gls_exec_glsHeaderi(GLSenum inAttrib, GLint inVal) {
  383. __GLScontext *const ctx = __GLS_CONTEXT;
  384. __GLSheader *header;
  385. if (ctx->blockType != GLS_HEADER) {
  386. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  387. return;
  388. }
  389. header = &ctx->header;
  390. switch (inAttrib) {
  391. case GLS_FRAME_COUNT:
  392. header->frameCount = inVal > 0 ? inVal : 0;
  393. break;
  394. case GLS_GLRC_COUNT:
  395. if (inVal < header->glrcCount) {
  396. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  397. } else if (inVal > header->glrcCount) {
  398. GLint i;
  399. __GLSglrc *glrcs = __glsMalloc(inVal * sizeof(__GLSglrc));
  400. if (!glrcs) break;
  401. memcpy(
  402. glrcs,
  403. header->glrcs,
  404. header->glrcCount * sizeof(__GLSglrc)
  405. );
  406. for (i = header->glrcCount ; i < inVal ; ++i) {
  407. __glsGLRC_init(glrcs + i);
  408. }
  409. header->glrcCount = inVal;
  410. free(header->glrcs);
  411. header->glrcs = glrcs;
  412. }
  413. break;
  414. case GLS_HEIGHT_PIXELS:
  415. header->heightPixels = inVal > 0 ? inVal : 0;
  416. break;
  417. case GLS_LAYER_COUNT:
  418. if (inVal < header->layerCount) {
  419. __GLS_RAISE_ERROR(GLS_INVALID_VALUE);
  420. } else if (inVal > header->layerCount) {
  421. GLint i;
  422. __GLSlayer *layers = __glsMalloc(inVal * sizeof(__GLSlayer));
  423. if (!layers) break;
  424. memcpy(
  425. layers,
  426. header->layers,
  427. header->layerCount * sizeof(__GLSlayer)
  428. );
  429. for (i = header->layerCount ; i < inVal ; ++i) {
  430. __glsLayer_init(layers + i);
  431. }
  432. header->layerCount = inVal;
  433. free(header->layers);
  434. header->layers = layers;
  435. }
  436. break;
  437. case GLS_TILEABLE:
  438. header->tileable = inVal ? GL_TRUE : GL_FALSE;
  439. break;
  440. default:
  441. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  442. break;
  443. }
  444. }
  445. void __gls_exec_glsHeaderiv(GLSenum inAttrib, const GLint *inVec) {
  446. __GLScontext *const ctx = __GLS_CONTEXT;
  447. __GLSheader *header;
  448. GLint i;
  449. if (ctx->blockType != GLS_HEADER) {
  450. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  451. return;
  452. }
  453. header = &ctx->header;
  454. switch (inAttrib) {
  455. case GLS_CREATE_TIME:
  456. for (i = 0 ; i < 6 ; ++i) {
  457. header->createTime[i] = inVec[i] > 0 ? inVec[i] : 0;
  458. }
  459. break;
  460. case GLS_MODIFY_TIME:
  461. for (i = 0 ; i < 6 ; ++i) {
  462. header->modifyTime[i] = inVec[i] > 0 ? inVec[i] : 0;
  463. }
  464. break;
  465. default:
  466. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  467. break;
  468. }
  469. }
  470. void __gls_exec_glsHeaderubz(GLSenum inAttrib, const GLubyte *inString) {
  471. __GLScontext *const ctx = __GLS_CONTEXT;
  472. __GLSheader *header;
  473. if (ctx->blockType != GLS_HEADER) {
  474. __GLS_RAISE_ERROR(GLS_INVALID_OPERATION);
  475. return;
  476. }
  477. if (!__glsValidateString(inString)) return;
  478. header = &ctx->header;
  479. switch (inAttrib) {
  480. case GLS_EXTENSIONS:
  481. __glsString_assign(&header->extensions, inString);
  482. break;
  483. case GLS_AUTHOR:
  484. __glsString_assign(&header->author, inString);
  485. break;
  486. case GLS_DESCRIPTION:
  487. __glsString_assign(&header->description, inString);
  488. break;
  489. case GLS_NOTES:
  490. __glsString_assign(&header->notes, inString);
  491. break;
  492. case GLS_TITLE:
  493. __glsString_assign(&header->title, inString);
  494. break;
  495. case GLS_TOOLS:
  496. __glsString_assign(&header->tools, inString);
  497. break;
  498. case GLS_VERSION:
  499. __glsString_assign(&header->version, inString);
  500. break;
  501. default:
  502. __GLS_RAISE_ERROR(GLS_INVALID_ENUM);
  503. break;
  504. }
  505. }
  506. void __gls_exec_glsRequireExtension(const GLubyte *inExtension) {
  507. if (!__glsValidateString(inExtension)) return;
  508. if (!glsIsExtensionSupported(inExtension)) {
  509. __GLS_RAISE_ERROR(GLS_UNSUPPORTED_EXTENSION);
  510. }
  511. }
  512. void __gls_exec_glsUnsupportedCommand(void) {
  513. __GLS_RAISE_ERROR(GLS_UNSUPPORTED_COMMAND);
  514. }