@aics/vole-app 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENSE +33 -0
  2. package/LICENSE.txt +26 -0
  3. package/README.md +45 -0
  4. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.eot +0 -0
  5. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.js +2337 -0
  6. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.svg +604 -0
  7. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.ttf +0 -0
  8. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.woff +0 -0
  9. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-500.woff2 +0 -0
  10. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.eot +0 -0
  11. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.js +2336 -0
  12. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.svg +604 -0
  13. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.ttf +0 -0
  14. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.woff +0 -0
  15. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-700.woff2 +0 -0
  16. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.eot +0 -0
  17. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.js +2337 -0
  18. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.svg +604 -0
  19. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.ttf +0 -0
  20. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.woff +0 -0
  21. package/es/aics-image-viewer/assets/fonts/open-sans/open-sans-regular.woff2 +0 -0
  22. package/es/aics-image-viewer/assets/icons/axes.js +20 -0
  23. package/es/aics-image-viewer/assets/icons/boundingBox.js +18 -0
  24. package/es/aics-image-viewer/assets/icons/camera.js +15 -0
  25. package/es/aics-image-viewer/assets/icons/channels.js +15 -0
  26. package/es/aics-image-viewer/assets/icons/closePanel.js +18 -0
  27. package/es/aics-image-viewer/assets/icons/download.js +17 -0
  28. package/es/aics-image-viewer/assets/icons/dropdownArrow.js +15 -0
  29. package/es/aics-image-viewer/assets/icons/index.js +24 -0
  30. package/es/aics-image-viewer/assets/icons/metadata.js +15 -0
  31. package/es/aics-image-viewer/assets/icons/preferences.js +15 -0
  32. package/es/aics-image-viewer/assets/icons/resetView.js +16 -0
  33. package/es/aics-image-viewer/assets/icons/svg.d.js +0 -0
  34. package/es/aics-image-viewer/assets/icons/turnTable.js +18 -0
  35. package/es/aics-image-viewer/assets/styles/animatedEllipsis.css +21 -0
  36. package/es/aics-image-viewer/assets/styles/globals.css +35 -0
  37. package/es/aics-image-viewer/assets/styles/noui-slider-override.css +1 -0
  38. package/es/aics-image-viewer/assets/styles/variables.css +1 -0
  39. package/es/aics-image-viewer/components/App/ChannelUpdater.js +96 -0
  40. package/es/aics-image-viewer/components/App/index.js +849 -0
  41. package/es/aics-image-viewer/components/App/styles.css +60 -0
  42. package/es/aics-image-viewer/components/App/types.js +1 -0
  43. package/es/aics-image-viewer/components/AxisClipSliders/index.js +285 -0
  44. package/es/aics-image-viewer/components/AxisClipSliders/styles.css +257 -0
  45. package/es/aics-image-viewer/components/BottomPanel/index.js +70 -0
  46. package/es/aics-image-viewer/components/BottomPanel/styles.css +85 -0
  47. package/es/aics-image-viewer/components/CellViewerCanvasWrapper/index.js +113 -0
  48. package/es/aics-image-viewer/components/CellViewerCanvasWrapper/styles.css +12 -0
  49. package/es/aics-image-viewer/components/ChannelsWidget.js +100 -0
  50. package/es/aics-image-viewer/components/ChannelsWidgetRow/index.js +158 -0
  51. package/es/aics-image-viewer/components/ChannelsWidgetRow/styles.css +38 -0
  52. package/es/aics-image-viewer/components/ColorPicker.js +120 -0
  53. package/es/aics-image-viewer/components/ControlPanel/index.js +180 -0
  54. package/es/aics-image-viewer/components/ControlPanel/styles.css +169 -0
  55. package/es/aics-image-viewer/components/CustomizeWidget.js +46 -0
  56. package/es/aics-image-viewer/components/ErrorAlert/index.js +144 -0
  57. package/es/aics-image-viewer/components/ErrorAlert/styles.css +22 -0
  58. package/es/aics-image-viewer/components/GlobalVolumeControls.js +38 -0
  59. package/es/aics-image-viewer/components/MetadataViewer/index.js +99 -0
  60. package/es/aics-image-viewer/components/MetadataViewer/styles.css +81 -0
  61. package/es/aics-image-viewer/components/StyleProvider/index.js +210 -0
  62. package/es/aics-image-viewer/components/TfEditor/index.js +584 -0
  63. package/es/aics-image-viewer/components/TfEditor/styles.css +88 -0
  64. package/es/aics-image-viewer/components/Toolbar/DownloadButton.js +55 -0
  65. package/es/aics-image-viewer/components/Toolbar/ViewModeRadioButtons.js +22 -0
  66. package/es/aics-image-viewer/components/Toolbar/index.js +274 -0
  67. package/es/aics-image-viewer/components/Toolbar/styles.css +241 -0
  68. package/es/aics-image-viewer/components/ViewerStateProvider/ResetStateProvider.js +160 -0
  69. package/es/aics-image-viewer/components/ViewerStateProvider/index.js +261 -0
  70. package/es/aics-image-viewer/components/ViewerStateProvider/types.js +1 -0
  71. package/es/aics-image-viewer/components/shared/NumericInput/index.js +147 -0
  72. package/es/aics-image-viewer/components/shared/NumericInput/styles.css +64 -0
  73. package/es/aics-image-viewer/components/shared/SharedCheckBox.js +17 -0
  74. package/es/aics-image-viewer/components/shared/SliderRow/index.js +31 -0
  75. package/es/aics-image-viewer/components/shared/SliderRow/styles.css +19 -0
  76. package/es/aics-image-viewer/components/shared/SmarterSlider.js +40 -0
  77. package/es/aics-image-viewer/components/shared/ViewerIcon.js +22 -0
  78. package/es/aics-image-viewer/shared/colorPalette.js +19 -0
  79. package/es/aics-image-viewer/shared/constants.js +164 -0
  80. package/es/aics-image-viewer/shared/enums.js +18 -0
  81. package/es/aics-image-viewer/shared/types.js +6 -0
  82. package/es/aics-image-viewer/shared/utils/colorRepresentations.js +16 -0
  83. package/es/aics-image-viewer/shared/utils/controlPointsToLut.js +182 -0
  84. package/es/aics-image-viewer/shared/utils/hooks.js +51 -0
  85. package/es/aics-image-viewer/shared/utils/httpClient.js +57 -0
  86. package/es/aics-image-viewer/shared/utils/playControls.js +97 -0
  87. package/es/aics-image-viewer/shared/utils/sceneStore.js +140 -0
  88. package/es/aics-image-viewer/shared/utils/sliderValuesToImageValues.js +36 -0
  89. package/es/aics-image-viewer/shared/utils/test/viewerChannelSettings.test.js +132 -0
  90. package/es/aics-image-viewer/shared/utils/utilsService.js +54 -0
  91. package/es/aics-image-viewer/shared/utils/viewerChannelSettings.js +152 -0
  92. package/es/aics-image-viewer/shared/utils/viewerState.js +69 -0
  93. package/es/aics-image-viewer/shared/utils/webgl-debug.js +1103 -0
  94. package/es/index.js +4 -0
  95. package/package.json +130 -0
  96. package/type-declarations/aics-image-viewer/assets/icons/index.d.ts +14 -0
  97. package/type-declarations/aics-image-viewer/components/App/ChannelUpdater.d.ts +16 -0
  98. package/type-declarations/aics-image-viewer/components/App/index.d.ts +6 -0
  99. package/type-declarations/aics-image-viewer/components/App/types.d.ts +45 -0
  100. package/type-declarations/aics-image-viewer/components/AxisClipSliders/index.d.ts +24 -0
  101. package/type-declarations/aics-image-viewer/components/BottomPanel/index.d.ts +11 -0
  102. package/type-declarations/aics-image-viewer/components/CellViewerCanvasWrapper/index.d.ts +33 -0
  103. package/type-declarations/aics-image-viewer/components/ChannelsWidget.d.ts +19 -0
  104. package/type-declarations/aics-image-viewer/components/ChannelsWidgetRow/index.d.ts +17 -0
  105. package/type-declarations/aics-image-viewer/components/ColorPicker.d.ts +13 -0
  106. package/type-declarations/aics-image-viewer/components/ControlPanel/index.d.ts +20 -0
  107. package/type-declarations/aics-image-viewer/components/CustomizeWidget.d.ts +15 -0
  108. package/type-declarations/aics-image-viewer/components/ErrorAlert/index.d.ts +12 -0
  109. package/type-declarations/aics-image-viewer/components/GlobalVolumeControls.d.ts +21 -0
  110. package/type-declarations/aics-image-viewer/components/MetadataViewer/index.d.ts +7 -0
  111. package/type-declarations/aics-image-viewer/components/StyleProvider/index.d.ts +5 -0
  112. package/type-declarations/aics-image-viewer/components/TfEditor/index.d.ts +19 -0
  113. package/type-declarations/aics-image-viewer/components/Toolbar/DownloadButton.d.ts +8 -0
  114. package/type-declarations/aics-image-viewer/components/Toolbar/ViewModeRadioButtons.d.ts +8 -0
  115. package/type-declarations/aics-image-viewer/components/Toolbar/index.d.ts +31 -0
  116. package/type-declarations/aics-image-viewer/components/ViewerStateProvider/ResetStateProvider.d.ts +34 -0
  117. package/type-declarations/aics-image-viewer/components/ViewerStateProvider/index.d.ts +33 -0
  118. package/type-declarations/aics-image-viewer/components/ViewerStateProvider/types.d.ts +105 -0
  119. package/type-declarations/aics-image-viewer/components/shared/NumericInput/index.d.ts +19 -0
  120. package/type-declarations/aics-image-viewer/components/shared/SharedCheckBox.d.ts +9 -0
  121. package/type-declarations/aics-image-viewer/components/shared/SliderRow/index.d.ts +17 -0
  122. package/type-declarations/aics-image-viewer/components/shared/SmarterSlider.d.ts +5 -0
  123. package/type-declarations/aics-image-viewer/components/shared/ViewerIcon.d.ts +9 -0
  124. package/type-declarations/aics-image-viewer/shared/constants.d.ts +40 -0
  125. package/type-declarations/aics-image-viewer/shared/enums.d.ts +15 -0
  126. package/type-declarations/aics-image-viewer/shared/types.d.ts +15 -0
  127. package/type-declarations/aics-image-viewer/shared/utils/colorRepresentations.d.ts +10 -0
  128. package/type-declarations/aics-image-viewer/shared/utils/controlPointsToLut.d.ts +53 -0
  129. package/type-declarations/aics-image-viewer/shared/utils/hooks.d.ts +14 -0
  130. package/type-declarations/aics-image-viewer/shared/utils/playControls.d.ts +27 -0
  131. package/type-declarations/aics-image-viewer/shared/utils/sceneStore.d.ts +17 -0
  132. package/type-declarations/aics-image-viewer/shared/utils/sliderValuesToImageValues.d.ts +10 -0
  133. package/type-declarations/aics-image-viewer/shared/utils/viewerChannelSettings.d.ts +46 -0
  134. package/type-declarations/aics-image-viewer/shared/utils/viewerState.d.ts +10 -0
  135. package/type-declarations/index.d.ts +7 -0
@@ -0,0 +1,1103 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ /*
3
+ ** Copyright (c) 2012 The Khronos Group Inc.
4
+ **
5
+ ** Permission is hereby granted, free of charge, to any person obtaining a
6
+ ** copy of this software and/or associated documentation files (the
7
+ ** "Materials"), to deal in the Materials without restriction, including
8
+ ** without limitation the rights to use, copy, modify, merge, publish,
9
+ ** distribute, sublicense, and/or sell copies of the Materials, and to
10
+ ** permit persons to whom the Materials are furnished to do so, subject to
11
+ ** the following conditions:
12
+ **
13
+ ** The above copyright notice and this permission notice shall be included
14
+ ** in all copies or substantial portions of the Materials.
15
+ **
16
+ ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
23
+ */
24
+
25
+ // Various functions for helping debug WebGL apps.
26
+
27
+ WebGLDebugUtils = function () {
28
+ /**
29
+ * Wrapped logging function.
30
+ * @param {string} msg Message to log.
31
+ */
32
+ var log = function log(msg) {
33
+ if (window.console && window.console.log) {
34
+ window.console.log(msg);
35
+ }
36
+ };
37
+
38
+ /**
39
+ * Wrapped error logging function.
40
+ * @param {string} msg Message to log.
41
+ */
42
+ var error = function error(msg) {
43
+ if (window.console && window.console.error) {
44
+ window.console.error(msg);
45
+ } else {
46
+ log(msg);
47
+ }
48
+ };
49
+
50
+ /**
51
+ * Which arguments are enums based on the number of arguments to the function.
52
+ * So
53
+ * 'texImage2D': {
54
+ * 9: { 0:true, 2:true, 6:true, 7:true },
55
+ * 6: { 0:true, 2:true, 3:true, 4:true },
56
+ * },
57
+ *
58
+ * means if there are 9 arguments then 6 and 7 are enums, if there are 6
59
+ * arguments 3 and 4 are enums
60
+ *
61
+ * @type {!Object.<number, !Object.<number, string>}
62
+ */
63
+ var glValidEnumContexts = {
64
+ // Generic setters and getters
65
+
66
+ enable: {
67
+ 1: {
68
+ 0: true
69
+ }
70
+ },
71
+ disable: {
72
+ 1: {
73
+ 0: true
74
+ }
75
+ },
76
+ getParameter: {
77
+ 1: {
78
+ 0: true
79
+ }
80
+ },
81
+ // Rendering
82
+
83
+ drawArrays: {
84
+ 3: {
85
+ 0: true
86
+ }
87
+ },
88
+ drawElements: {
89
+ 4: {
90
+ 0: true,
91
+ 2: true
92
+ }
93
+ },
94
+ // Shaders
95
+
96
+ createShader: {
97
+ 1: {
98
+ 0: true
99
+ }
100
+ },
101
+ getShaderParameter: {
102
+ 2: {
103
+ 1: true
104
+ }
105
+ },
106
+ getProgramParameter: {
107
+ 2: {
108
+ 1: true
109
+ }
110
+ },
111
+ getShaderPrecisionFormat: {
112
+ 2: {
113
+ 0: true,
114
+ 1: true
115
+ }
116
+ },
117
+ // Vertex attributes
118
+
119
+ getVertexAttrib: {
120
+ 2: {
121
+ 1: true
122
+ }
123
+ },
124
+ vertexAttribPointer: {
125
+ 6: {
126
+ 2: true
127
+ }
128
+ },
129
+ // Textures
130
+
131
+ bindTexture: {
132
+ 2: {
133
+ 0: true
134
+ }
135
+ },
136
+ activeTexture: {
137
+ 1: {
138
+ 0: true
139
+ }
140
+ },
141
+ getTexParameter: {
142
+ 2: {
143
+ 0: true,
144
+ 1: true
145
+ }
146
+ },
147
+ texParameterf: {
148
+ 3: {
149
+ 0: true,
150
+ 1: true
151
+ }
152
+ },
153
+ texParameteri: {
154
+ 3: {
155
+ 0: true,
156
+ 1: true,
157
+ 2: true
158
+ }
159
+ },
160
+ texImage2D: {
161
+ 9: {
162
+ 0: true,
163
+ 2: true,
164
+ 6: true,
165
+ 7: true
166
+ },
167
+ 6: {
168
+ 0: true,
169
+ 2: true,
170
+ 3: true,
171
+ 4: true
172
+ }
173
+ },
174
+ texSubImage2D: {
175
+ 9: {
176
+ 0: true,
177
+ 6: true,
178
+ 7: true
179
+ },
180
+ 7: {
181
+ 0: true,
182
+ 4: true,
183
+ 5: true
184
+ }
185
+ },
186
+ copyTexImage2D: {
187
+ 8: {
188
+ 0: true,
189
+ 2: true
190
+ }
191
+ },
192
+ copyTexSubImage2D: {
193
+ 8: {
194
+ 0: true
195
+ }
196
+ },
197
+ generateMipmap: {
198
+ 1: {
199
+ 0: true
200
+ }
201
+ },
202
+ compressedTexImage2D: {
203
+ 7: {
204
+ 0: true,
205
+ 2: true
206
+ }
207
+ },
208
+ compressedTexSubImage2D: {
209
+ 8: {
210
+ 0: true,
211
+ 6: true
212
+ }
213
+ },
214
+ // Buffer objects
215
+
216
+ bindBuffer: {
217
+ 2: {
218
+ 0: true
219
+ }
220
+ },
221
+ bufferData: {
222
+ 3: {
223
+ 0: true,
224
+ 2: true
225
+ }
226
+ },
227
+ bufferSubData: {
228
+ 3: {
229
+ 0: true
230
+ }
231
+ },
232
+ getBufferParameter: {
233
+ 2: {
234
+ 0: true,
235
+ 1: true
236
+ }
237
+ },
238
+ // Renderbuffers and framebuffers
239
+
240
+ pixelStorei: {
241
+ 2: {
242
+ 0: true,
243
+ 1: true
244
+ }
245
+ },
246
+ readPixels: {
247
+ 7: {
248
+ 4: true,
249
+ 5: true
250
+ }
251
+ },
252
+ bindRenderbuffer: {
253
+ 2: {
254
+ 0: true
255
+ }
256
+ },
257
+ bindFramebuffer: {
258
+ 2: {
259
+ 0: true
260
+ }
261
+ },
262
+ checkFramebufferStatus: {
263
+ 1: {
264
+ 0: true
265
+ }
266
+ },
267
+ framebufferRenderbuffer: {
268
+ 4: {
269
+ 0: true,
270
+ 1: true,
271
+ 2: true
272
+ }
273
+ },
274
+ framebufferTexture2D: {
275
+ 5: {
276
+ 0: true,
277
+ 1: true,
278
+ 2: true
279
+ }
280
+ },
281
+ getFramebufferAttachmentParameter: {
282
+ 3: {
283
+ 0: true,
284
+ 1: true,
285
+ 2: true
286
+ }
287
+ },
288
+ getRenderbufferParameter: {
289
+ 2: {
290
+ 0: true,
291
+ 1: true
292
+ }
293
+ },
294
+ renderbufferStorage: {
295
+ 4: {
296
+ 0: true,
297
+ 1: true
298
+ }
299
+ },
300
+ // Frame buffer operations (clear, blend, depth test, stencil)
301
+
302
+ clear: {
303
+ 1: {
304
+ 0: {
305
+ enumBitwiseOr: ["COLOR_BUFFER_BIT", "DEPTH_BUFFER_BIT", "STENCIL_BUFFER_BIT"]
306
+ }
307
+ }
308
+ },
309
+ depthFunc: {
310
+ 1: {
311
+ 0: true
312
+ }
313
+ },
314
+ blendFunc: {
315
+ 2: {
316
+ 0: true,
317
+ 1: true
318
+ }
319
+ },
320
+ blendFuncSeparate: {
321
+ 4: {
322
+ 0: true,
323
+ 1: true,
324
+ 2: true,
325
+ 3: true
326
+ }
327
+ },
328
+ blendEquation: {
329
+ 1: {
330
+ 0: true
331
+ }
332
+ },
333
+ blendEquationSeparate: {
334
+ 2: {
335
+ 0: true,
336
+ 1: true
337
+ }
338
+ },
339
+ stencilFunc: {
340
+ 3: {
341
+ 0: true
342
+ }
343
+ },
344
+ stencilFuncSeparate: {
345
+ 4: {
346
+ 0: true,
347
+ 1: true
348
+ }
349
+ },
350
+ stencilMaskSeparate: {
351
+ 2: {
352
+ 0: true
353
+ }
354
+ },
355
+ stencilOp: {
356
+ 3: {
357
+ 0: true,
358
+ 1: true,
359
+ 2: true
360
+ }
361
+ },
362
+ stencilOpSeparate: {
363
+ 4: {
364
+ 0: true,
365
+ 1: true,
366
+ 2: true,
367
+ 3: true
368
+ }
369
+ },
370
+ // Culling
371
+
372
+ cullFace: {
373
+ 1: {
374
+ 0: true
375
+ }
376
+ },
377
+ frontFace: {
378
+ 1: {
379
+ 0: true
380
+ }
381
+ },
382
+ // ANGLE_instanced_arrays extension
383
+
384
+ drawArraysInstancedANGLE: {
385
+ 4: {
386
+ 0: true
387
+ }
388
+ },
389
+ drawElementsInstancedANGLE: {
390
+ 5: {
391
+ 0: true,
392
+ 2: true
393
+ }
394
+ },
395
+ // EXT_blend_minmax extension
396
+
397
+ blendEquationEXT: {
398
+ 1: {
399
+ 0: true
400
+ }
401
+ }
402
+ };
403
+
404
+ /**
405
+ * Map of numbers to names.
406
+ * @type {Object}
407
+ */
408
+ var glEnums = null;
409
+
410
+ /**
411
+ * Map of names to numbers.
412
+ * @type {Object}
413
+ */
414
+ var enumStringToValue = null;
415
+
416
+ /**
417
+ * Initializes this module. Safe to call more than once.
418
+ * @param {!WebGLRenderingContext} ctx A WebGL context. If
419
+ * you have more than one context it doesn't matter which one
420
+ * you pass in, it is only used to pull out constants.
421
+ */
422
+ function init(ctx) {
423
+ if (glEnums == null) {
424
+ glEnums = {};
425
+ enumStringToValue = {};
426
+ for (var propertyName in ctx) {
427
+ if (typeof ctx[propertyName] == "number") {
428
+ glEnums[ctx[propertyName]] = propertyName;
429
+ enumStringToValue[propertyName] = ctx[propertyName];
430
+ }
431
+ }
432
+ }
433
+ }
434
+
435
+ /**
436
+ * Checks the utils have been initialized.
437
+ */
438
+ function checkInit() {
439
+ if (glEnums == null) {
440
+ throw "WebGLDebugUtils.init(ctx) not called";
441
+ }
442
+ }
443
+
444
+ /**
445
+ * Returns true or false if value matches any WebGL enum
446
+ * @param {*} value Value to check if it might be an enum.
447
+ * @return {boolean} True if value matches one of the WebGL defined enums
448
+ */
449
+ function mightBeEnum(value) {
450
+ checkInit();
451
+ return glEnums[value] !== undefined;
452
+ }
453
+
454
+ /**
455
+ * Gets an string version of an WebGL enum.
456
+ *
457
+ * Example:
458
+ * var str = WebGLDebugUtil.glEnumToString(ctx.getError());
459
+ *
460
+ * @param {number} value Value to return an enum for
461
+ * @return {string} The string version of the enum.
462
+ */
463
+ function glEnumToString(value) {
464
+ checkInit();
465
+ var name = glEnums[value];
466
+ return name !== undefined ? "gl." + name : "/*UNKNOWN WebGL ENUM*/ 0x" + value.toString(16) + "";
467
+ }
468
+
469
+ /**
470
+ * Returns the string version of a WebGL argument.
471
+ * Attempts to convert enum arguments to strings.
472
+ * @param {string} functionName the name of the WebGL function.
473
+ * @param {number} numArgs the number of arguments passed to the function.
474
+ * @param {number} argumentIndx the index of the argument.
475
+ * @param {*} value The value of the argument.
476
+ * @return {string} The value as a string.
477
+ */
478
+ function glFunctionArgToString(functionName, numArgs, argumentIndex, value) {
479
+ var funcInfo = glValidEnumContexts[functionName];
480
+ if (funcInfo !== undefined) {
481
+ var funcInfo = funcInfo[numArgs];
482
+ if (funcInfo !== undefined) {
483
+ if (funcInfo[argumentIndex]) {
484
+ if (_typeof(funcInfo[argumentIndex]) === "object" && funcInfo[argumentIndex]["enumBitwiseOr"] !== undefined) {
485
+ var enums = funcInfo[argumentIndex]["enumBitwiseOr"];
486
+ var orResult = 0;
487
+ var orEnums = [];
488
+ for (var i = 0; i < enums.length; ++i) {
489
+ var enumValue = enumStringToValue[enums[i]];
490
+ if ((value & enumValue) !== 0) {
491
+ orResult |= enumValue;
492
+ orEnums.push(glEnumToString(enumValue));
493
+ }
494
+ }
495
+ if (orResult === value) {
496
+ return orEnums.join(" | ");
497
+ } else {
498
+ return glEnumToString(value);
499
+ }
500
+ } else {
501
+ return glEnumToString(value);
502
+ }
503
+ }
504
+ }
505
+ }
506
+ if (value === null) {
507
+ return "null";
508
+ } else if (value === undefined) {
509
+ return "undefined";
510
+ } else {
511
+ return value.toString();
512
+ }
513
+ }
514
+
515
+ /**
516
+ * Converts the arguments of a WebGL function to a string.
517
+ * Attempts to convert enum arguments to strings.
518
+ *
519
+ * @param {string} functionName the name of the WebGL function.
520
+ * @param {number} args The arguments.
521
+ * @return {string} The arguments as a string.
522
+ */
523
+ function glFunctionArgsToString(functionName, args) {
524
+ // apparently we can't do args.join(",");
525
+ var argStr = "";
526
+ var numArgs = args.length;
527
+ for (var ii = 0; ii < numArgs; ++ii) {
528
+ argStr += (ii == 0 ? "" : ", ") + glFunctionArgToString(functionName, numArgs, ii, args[ii]);
529
+ }
530
+ return argStr;
531
+ }
532
+ function makePropertyWrapper(wrapper, original, propertyName) {
533
+ //log("wrap prop: " + propertyName);
534
+ wrapper.__defineGetter__(propertyName, function () {
535
+ return original[propertyName];
536
+ });
537
+ // TODO(gmane): this needs to handle properties that take more than
538
+ // one value?
539
+ wrapper.__defineSetter__(propertyName, function (value) {
540
+ //log("set: " + propertyName);
541
+ original[propertyName] = value;
542
+ });
543
+ }
544
+
545
+ // Makes a function that calls a function on another object.
546
+ function makeFunctionWrapper(original, functionName) {
547
+ //log("wrap fn: " + functionName);
548
+ var f = original[functionName];
549
+ return function () {
550
+ //log("call: " + functionName);
551
+ var result = f.apply(original, arguments);
552
+ return result;
553
+ };
554
+ }
555
+
556
+ /**
557
+ * Given a WebGL context returns a wrapped context that calls
558
+ * gl.getError after every command and calls a function if the
559
+ * result is not gl.NO_ERROR.
560
+ *
561
+ * @param {!WebGLRenderingContext} ctx The webgl context to
562
+ * wrap.
563
+ * @param {!function(err, funcName, args): void} opt_onErrorFunc
564
+ * The function to call when gl.getError returns an
565
+ * error. If not specified the default function calls
566
+ * console.log with a message.
567
+ * @param {!function(funcName, args): void} opt_onFunc The
568
+ * function to call when each webgl function is called.
569
+ * You can use this to log all calls for example.
570
+ * @param {!WebGLRenderingContext} opt_err_ctx The webgl context
571
+ * to call getError on if different than ctx.
572
+ */
573
+ function makeDebugContext(ctx, opt_onErrorFunc, opt_onFunc, opt_err_ctx) {
574
+ opt_err_ctx = opt_err_ctx || ctx;
575
+ init(ctx);
576
+ opt_onErrorFunc = opt_onErrorFunc || function (err, functionName, args) {
577
+ // apparently we can't do args.join(",");
578
+ var argStr = "";
579
+ var numArgs = args.length;
580
+ for (var ii = 0; ii < numArgs; ++ii) {
581
+ argStr += (ii == 0 ? "" : ", ") + glFunctionArgToString(functionName, numArgs, ii, args[ii]);
582
+ }
583
+ error("WebGL error " + glEnumToString(err) + " in " + functionName + "(" + argStr + ")");
584
+ };
585
+
586
+ // Holds booleans for each GL error so after we get the error ourselves
587
+ // we can still return it to the client app.
588
+ var glErrorShadow = {};
589
+
590
+ // Makes a function that calls a WebGL function and then calls getError.
591
+ function makeErrorWrapper(ctx, functionName) {
592
+ return function () {
593
+ if (opt_onFunc) {
594
+ opt_onFunc(functionName, arguments);
595
+ }
596
+ var result = ctx[functionName].apply(ctx, arguments);
597
+ var err = opt_err_ctx.getError();
598
+ if (err != 0) {
599
+ glErrorShadow[err] = true;
600
+ opt_onErrorFunc(err, functionName, arguments);
601
+ }
602
+ return result;
603
+ };
604
+ }
605
+
606
+ // Make a an object that has a copy of every property of the WebGL context
607
+ // but wraps all functions.
608
+ var wrapper = {};
609
+ for (var propertyName in ctx) {
610
+ if (typeof ctx[propertyName] == "function") {
611
+ if (propertyName != "getExtension") {
612
+ wrapper[propertyName] = makeErrorWrapper(ctx, propertyName);
613
+ } else {
614
+ var wrapped = makeErrorWrapper(ctx, propertyName);
615
+ wrapper[propertyName] = function () {
616
+ var result = wrapped.apply(ctx, arguments);
617
+ return makeDebugContext(result, opt_onErrorFunc, opt_onFunc, opt_err_ctx);
618
+ };
619
+ }
620
+ } else {
621
+ makePropertyWrapper(wrapper, ctx, propertyName);
622
+ }
623
+ }
624
+
625
+ // Override the getError function with one that returns our saved results.
626
+ wrapper.getError = function () {
627
+ for (var err in glErrorShadow) {
628
+ if (glErrorShadow.hasOwnProperty(err)) {
629
+ if (glErrorShadow[err]) {
630
+ glErrorShadow[err] = false;
631
+ return err;
632
+ }
633
+ }
634
+ }
635
+ return ctx.NO_ERROR;
636
+ };
637
+ return wrapper;
638
+ }
639
+ function resetToInitialState(ctx) {
640
+ var numAttribs = ctx.getParameter(ctx.MAX_VERTEX_ATTRIBS);
641
+ var tmp = ctx.createBuffer();
642
+ ctx.bindBuffer(ctx.ARRAY_BUFFER, tmp);
643
+ for (var ii = 0; ii < numAttribs; ++ii) {
644
+ ctx.disableVertexAttribArray(ii);
645
+ ctx.vertexAttribPointer(ii, 4, ctx.FLOAT, false, 0, 0);
646
+ ctx.vertexAttrib1f(ii, 0);
647
+ }
648
+ ctx.deleteBuffer(tmp);
649
+ var numTextureUnits = ctx.getParameter(ctx.MAX_TEXTURE_IMAGE_UNITS);
650
+ for (var ii = 0; ii < numTextureUnits; ++ii) {
651
+ ctx.activeTexture(ctx.TEXTURE0 + ii);
652
+ ctx.bindTexture(ctx.TEXTURE_CUBE_MAP, null);
653
+ ctx.bindTexture(ctx.TEXTURE_2D, null);
654
+ }
655
+ ctx.activeTexture(ctx.TEXTURE0);
656
+ ctx.useProgram(null);
657
+ ctx.bindBuffer(ctx.ARRAY_BUFFER, null);
658
+ ctx.bindBuffer(ctx.ELEMENT_ARRAY_BUFFER, null);
659
+ ctx.bindFramebuffer(ctx.FRAMEBUFFER, null);
660
+ ctx.bindRenderbuffer(ctx.RENDERBUFFER, null);
661
+ ctx.disable(ctx.BLEND);
662
+ ctx.disable(ctx.CULL_FACE);
663
+ ctx.disable(ctx.DEPTH_TEST);
664
+ ctx.disable(ctx.DITHER);
665
+ ctx.disable(ctx.SCISSOR_TEST);
666
+ ctx.blendColor(0, 0, 0, 0);
667
+ ctx.blendEquation(ctx.FUNC_ADD);
668
+ ctx.blendFunc(ctx.ONE, ctx.ZERO);
669
+ ctx.clearColor(0, 0, 0, 0);
670
+ ctx.clearDepth(1);
671
+ ctx.clearStencil(-1);
672
+ ctx.colorMask(true, true, true, true);
673
+ ctx.cullFace(ctx.BACK);
674
+ ctx.depthFunc(ctx.LESS);
675
+ ctx.depthMask(true);
676
+ ctx.depthRange(0, 1);
677
+ ctx.frontFace(ctx.CCW);
678
+ ctx.hint(ctx.GENERATE_MIPMAP_HINT, ctx.DONT_CARE);
679
+ ctx.lineWidth(1);
680
+ ctx.pixelStorei(ctx.PACK_ALIGNMENT, 4);
681
+ ctx.pixelStorei(ctx.UNPACK_ALIGNMENT, 4);
682
+ ctx.pixelStorei(ctx.UNPACK_FLIP_Y_WEBGL, false);
683
+ ctx.pixelStorei(ctx.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
684
+ // TODO: Delete this IF.
685
+ if (ctx.UNPACK_COLORSPACE_CONVERSION_WEBGL) {
686
+ ctx.pixelStorei(ctx.UNPACK_COLORSPACE_CONVERSION_WEBGL, ctx.BROWSER_DEFAULT_WEBGL);
687
+ }
688
+ ctx.polygonOffset(0, 0);
689
+ ctx.sampleCoverage(1, false);
690
+ ctx.scissor(0, 0, ctx.canvas.width, ctx.canvas.height);
691
+ ctx.stencilFunc(ctx.ALWAYS, 0, 0xffffffff);
692
+ ctx.stencilMask(0xffffffff);
693
+ ctx.stencilOp(ctx.KEEP, ctx.KEEP, ctx.KEEP);
694
+ ctx.viewport(0, 0, ctx.canvas.width, ctx.canvas.height);
695
+ ctx.clear(ctx.COLOR_BUFFER_BIT | ctx.DEPTH_BUFFER_BIT | ctx.STENCIL_BUFFER_BIT);
696
+
697
+ // TODO: This should NOT be needed but Firefox fails with 'hint'
698
+ while (ctx.getError());
699
+ }
700
+ function makeLostContextSimulatingCanvas(canvas) {
701
+ var unwrappedContext_;
702
+ var wrappedContext_;
703
+ var onLost_ = [];
704
+ var onRestored_ = [];
705
+ var wrappedContext_ = {};
706
+ var contextId_ = 1;
707
+ var contextLost_ = false;
708
+ var resourceId_ = 0;
709
+ var resourceDb_ = [];
710
+ var numCallsToLoseContext_ = 0;
711
+ var numCalls_ = 0;
712
+ var canRestore_ = false;
713
+ var restoreTimeout_ = 0;
714
+
715
+ // Holds booleans for each GL error so can simulate errors.
716
+ var glErrorShadow_ = {};
717
+ canvas.getContext = function (f) {
718
+ return function () {
719
+ var ctx = f.apply(canvas, arguments);
720
+ // Did we get a context and is it a WebGL context?
721
+ if (ctx instanceof WebGLRenderingContext) {
722
+ if (ctx != unwrappedContext_) {
723
+ if (unwrappedContext_) {
724
+ throw "got different context";
725
+ }
726
+ unwrappedContext_ = ctx;
727
+ wrappedContext_ = makeLostContextSimulatingContext(unwrappedContext_);
728
+ }
729
+ return wrappedContext_;
730
+ }
731
+ return ctx;
732
+ };
733
+ }(canvas.getContext);
734
+ function wrapEvent(listener) {
735
+ if (typeof listener == "function") {
736
+ return listener;
737
+ } else {
738
+ return function (info) {
739
+ listener.handleEvent(info);
740
+ };
741
+ }
742
+ }
743
+ var addOnContextLostListener = function addOnContextLostListener(listener) {
744
+ onLost_.push(wrapEvent(listener));
745
+ };
746
+ var addOnContextRestoredListener = function addOnContextRestoredListener(listener) {
747
+ onRestored_.push(wrapEvent(listener));
748
+ };
749
+ function wrapAddEventListener(canvas) {
750
+ var f = canvas.addEventListener;
751
+ canvas.addEventListener = function (type, listener, bubble) {
752
+ switch (type) {
753
+ case "webglcontextlost":
754
+ addOnContextLostListener(listener);
755
+ break;
756
+ case "webglcontextrestored":
757
+ addOnContextRestoredListener(listener);
758
+ break;
759
+ default:
760
+ f.apply(canvas, arguments);
761
+ }
762
+ };
763
+ }
764
+ wrapAddEventListener(canvas);
765
+ canvas.loseContext = function () {
766
+ if (!contextLost_) {
767
+ contextLost_ = true;
768
+ numCallsToLoseContext_ = 0;
769
+ ++contextId_;
770
+ while (unwrappedContext_.getError());
771
+ clearErrors();
772
+ glErrorShadow_[unwrappedContext_.CONTEXT_LOST_WEBGL] = true;
773
+ var event = makeWebGLContextEvent("context lost");
774
+ var callbacks = onLost_.slice();
775
+ setTimeout(function () {
776
+ //log("numCallbacks:" + callbacks.length);
777
+ for (var ii = 0; ii < callbacks.length; ++ii) {
778
+ //log("calling callback:" + ii);
779
+ callbacks[ii](event);
780
+ }
781
+ if (restoreTimeout_ >= 0) {
782
+ setTimeout(function () {
783
+ canvas.restoreContext();
784
+ }, restoreTimeout_);
785
+ }
786
+ }, 0);
787
+ }
788
+ };
789
+ canvas.restoreContext = function () {
790
+ if (contextLost_) {
791
+ if (onRestored_.length) {
792
+ setTimeout(function () {
793
+ if (!canRestore_) {
794
+ throw "can not restore. webglcontestlost listener did not call event.preventDefault";
795
+ }
796
+ freeResources();
797
+ resetToInitialState(unwrappedContext_);
798
+ contextLost_ = false;
799
+ numCalls_ = 0;
800
+ canRestore_ = false;
801
+ var callbacks = onRestored_.slice();
802
+ var event = makeWebGLContextEvent("context restored");
803
+ for (var ii = 0; ii < callbacks.length; ++ii) {
804
+ callbacks[ii](event);
805
+ }
806
+ }, 0);
807
+ }
808
+ }
809
+ };
810
+ canvas.loseContextInNCalls = function (numCalls) {
811
+ if (contextLost_) {
812
+ throw "You can not ask a lost contet to be lost";
813
+ }
814
+ numCallsToLoseContext_ = numCalls_ + numCalls;
815
+ };
816
+ canvas.getNumCalls = function () {
817
+ return numCalls_;
818
+ };
819
+ canvas.setRestoreTimeout = function (timeout) {
820
+ restoreTimeout_ = timeout;
821
+ };
822
+ function isWebGLObject(obj) {
823
+ //return false;
824
+ return obj instanceof WebGLBuffer || obj instanceof WebGLFramebuffer || obj instanceof WebGLProgram || obj instanceof WebGLRenderbuffer || obj instanceof WebGLShader || obj instanceof WebGLTexture;
825
+ }
826
+ function checkResources(args) {
827
+ for (var ii = 0; ii < args.length; ++ii) {
828
+ var arg = args[ii];
829
+ if (isWebGLObject(arg)) {
830
+ return arg.__webglDebugContextLostId__ == contextId_;
831
+ }
832
+ }
833
+ return true;
834
+ }
835
+ function clearErrors() {
836
+ var k = Object.keys(glErrorShadow_);
837
+ for (var ii = 0; ii < k.length; ++ii) {
838
+ delete glErrorShadow_[k];
839
+ }
840
+ }
841
+ function loseContextIfTime() {
842
+ ++numCalls_;
843
+ if (!contextLost_) {
844
+ if (numCallsToLoseContext_ == numCalls_) {
845
+ canvas.loseContext();
846
+ }
847
+ }
848
+ }
849
+
850
+ // Makes a function that simulates WebGL when out of context.
851
+ function makeLostContextFunctionWrapper(ctx, functionName) {
852
+ var f = ctx[functionName];
853
+ return function () {
854
+ // log("calling:" + functionName);
855
+ // Only call the functions if the context is not lost.
856
+ loseContextIfTime();
857
+ if (!contextLost_) {
858
+ //if (!checkResources(arguments)) {
859
+ // glErrorShadow_[wrappedContext_.INVALID_OPERATION] = true;
860
+ // return;
861
+ //}
862
+ var result = f.apply(ctx, arguments);
863
+ return result;
864
+ }
865
+ };
866
+ }
867
+ function freeResources() {
868
+ for (var ii = 0; ii < resourceDb_.length; ++ii) {
869
+ var resource = resourceDb_[ii];
870
+ if (resource instanceof WebGLBuffer) {
871
+ unwrappedContext_.deleteBuffer(resource);
872
+ } else if (resource instanceof WebGLFramebuffer) {
873
+ unwrappedContext_.deleteFramebuffer(resource);
874
+ } else if (resource instanceof WebGLProgram) {
875
+ unwrappedContext_.deleteProgram(resource);
876
+ } else if (resource instanceof WebGLRenderbuffer) {
877
+ unwrappedContext_.deleteRenderbuffer(resource);
878
+ } else if (resource instanceof WebGLShader) {
879
+ unwrappedContext_.deleteShader(resource);
880
+ } else if (resource instanceof WebGLTexture) {
881
+ unwrappedContext_.deleteTexture(resource);
882
+ }
883
+ }
884
+ }
885
+ function makeWebGLContextEvent(statusMessage) {
886
+ return {
887
+ statusMessage: statusMessage,
888
+ preventDefault: function preventDefault() {
889
+ canRestore_ = true;
890
+ }
891
+ };
892
+ }
893
+ return canvas;
894
+ function makeLostContextSimulatingContext(ctx) {
895
+ // copy all functions and properties to wrapper
896
+ for (var propertyName in ctx) {
897
+ if (typeof ctx[propertyName] == "function") {
898
+ wrappedContext_[propertyName] = makeLostContextFunctionWrapper(ctx, propertyName);
899
+ } else {
900
+ makePropertyWrapper(wrappedContext_, ctx, propertyName);
901
+ }
902
+ }
903
+
904
+ // Wrap a few functions specially.
905
+ wrappedContext_.getError = function () {
906
+ loseContextIfTime();
907
+ if (!contextLost_) {
908
+ var err;
909
+ while (err = unwrappedContext_.getError()) {
910
+ glErrorShadow_[err] = true;
911
+ }
912
+ }
913
+ for (var err in glErrorShadow_) {
914
+ if (glErrorShadow_[err]) {
915
+ delete glErrorShadow_[err];
916
+ return err;
917
+ }
918
+ }
919
+ return wrappedContext_.NO_ERROR;
920
+ };
921
+ var creationFunctions = ["createBuffer", "createFramebuffer", "createProgram", "createRenderbuffer", "createShader", "createTexture"];
922
+ for (var ii = 0; ii < creationFunctions.length; ++ii) {
923
+ var functionName = creationFunctions[ii];
924
+ wrappedContext_[functionName] = function (f) {
925
+ return function () {
926
+ loseContextIfTime();
927
+ if (contextLost_) {
928
+ return null;
929
+ }
930
+ var obj = f.apply(ctx, arguments);
931
+ obj.__webglDebugContextLostId__ = contextId_;
932
+ resourceDb_.push(obj);
933
+ return obj;
934
+ };
935
+ }(ctx[functionName]);
936
+ }
937
+ var functionsThatShouldReturnNull = ["getActiveAttrib", "getActiveUniform", "getBufferParameter", "getContextAttributes", "getAttachedShaders", "getFramebufferAttachmentParameter", "getParameter", "getProgramParameter", "getProgramInfoLog", "getRenderbufferParameter", "getShaderParameter", "getShaderInfoLog", "getShaderSource", "getTexParameter", "getUniform", "getUniformLocation", "getVertexAttrib"];
938
+ for (var ii = 0; ii < functionsThatShouldReturnNull.length; ++ii) {
939
+ var functionName = functionsThatShouldReturnNull[ii];
940
+ wrappedContext_[functionName] = function (f) {
941
+ return function () {
942
+ loseContextIfTime();
943
+ if (contextLost_) {
944
+ return null;
945
+ }
946
+ return f.apply(ctx, arguments);
947
+ };
948
+ }(wrappedContext_[functionName]);
949
+ }
950
+ var isFunctions = ["isBuffer", "isEnabled", "isFramebuffer", "isProgram", "isRenderbuffer", "isShader", "isTexture"];
951
+ for (var ii = 0; ii < isFunctions.length; ++ii) {
952
+ var functionName = isFunctions[ii];
953
+ wrappedContext_[functionName] = function (f) {
954
+ return function () {
955
+ loseContextIfTime();
956
+ if (contextLost_) {
957
+ return false;
958
+ }
959
+ return f.apply(ctx, arguments);
960
+ };
961
+ }(wrappedContext_[functionName]);
962
+ }
963
+ wrappedContext_.checkFramebufferStatus = function (f) {
964
+ return function () {
965
+ loseContextIfTime();
966
+ if (contextLost_) {
967
+ return wrappedContext_.FRAMEBUFFER_UNSUPPORTED;
968
+ }
969
+ return f.apply(ctx, arguments);
970
+ };
971
+ }(wrappedContext_.checkFramebufferStatus);
972
+ wrappedContext_.getAttribLocation = function (f) {
973
+ return function () {
974
+ loseContextIfTime();
975
+ if (contextLost_) {
976
+ return -1;
977
+ }
978
+ return f.apply(ctx, arguments);
979
+ };
980
+ }(wrappedContext_.getAttribLocation);
981
+ wrappedContext_.getVertexAttribOffset = function (f) {
982
+ return function () {
983
+ loseContextIfTime();
984
+ if (contextLost_) {
985
+ return 0;
986
+ }
987
+ return f.apply(ctx, arguments);
988
+ };
989
+ }(wrappedContext_.getVertexAttribOffset);
990
+ wrappedContext_.isContextLost = function () {
991
+ return contextLost_;
992
+ };
993
+ return wrappedContext_;
994
+ }
995
+ }
996
+ return {
997
+ /**
998
+ * Initializes this module. Safe to call more than once.
999
+ * @param {!WebGLRenderingContext} ctx A WebGL context. If
1000
+ * you have more than one context it doesn't matter which one
1001
+ * you pass in, it is only used to pull out constants.
1002
+ */
1003
+ init: init,
1004
+ /**
1005
+ * Returns true or false if value matches any WebGL enum
1006
+ * @param {*} value Value to check if it might be an enum.
1007
+ * @return {boolean} True if value matches one of the WebGL defined enums
1008
+ */
1009
+ mightBeEnum: mightBeEnum,
1010
+ /**
1011
+ * Gets an string version of an WebGL enum.
1012
+ *
1013
+ * Example:
1014
+ * WebGLDebugUtil.init(ctx);
1015
+ * var str = WebGLDebugUtil.glEnumToString(ctx.getError());
1016
+ *
1017
+ * @param {number} value Value to return an enum for
1018
+ * @return {string} The string version of the enum.
1019
+ */
1020
+ glEnumToString: glEnumToString,
1021
+ /**
1022
+ * Converts the argument of a WebGL function to a string.
1023
+ * Attempts to convert enum arguments to strings.
1024
+ *
1025
+ * Example:
1026
+ * WebGLDebugUtil.init(ctx);
1027
+ * var str = WebGLDebugUtil.glFunctionArgToString('bindTexture', 2, 0, gl.TEXTURE_2D);
1028
+ *
1029
+ * would return 'TEXTURE_2D'
1030
+ *
1031
+ * @param {string} functionName the name of the WebGL function.
1032
+ * @param {number} numArgs The number of arguments
1033
+ * @param {number} argumentIndx the index of the argument.
1034
+ * @param {*} value The value of the argument.
1035
+ * @return {string} The value as a string.
1036
+ */
1037
+ glFunctionArgToString: glFunctionArgToString,
1038
+ /**
1039
+ * Converts the arguments of a WebGL function to a string.
1040
+ * Attempts to convert enum arguments to strings.
1041
+ *
1042
+ * @param {string} functionName the name of the WebGL function.
1043
+ * @param {number} args The arguments.
1044
+ * @return {string} The arguments as a string.
1045
+ */
1046
+ glFunctionArgsToString: glFunctionArgsToString,
1047
+ /**
1048
+ * Given a WebGL context returns a wrapped context that calls
1049
+ * gl.getError after every command and calls a function if the
1050
+ * result is not NO_ERROR.
1051
+ *
1052
+ * You can supply your own function if you want. For example, if you'd like
1053
+ * an exception thrown on any GL error you could do this
1054
+ *
1055
+ * function throwOnGLError(err, funcName, args) {
1056
+ * throw WebGLDebugUtils.glEnumToString(err) +
1057
+ * " was caused by call to " + funcName;
1058
+ * };
1059
+ *
1060
+ * ctx = WebGLDebugUtils.makeDebugContext(
1061
+ * canvas.getContext("webgl"), throwOnGLError);
1062
+ *
1063
+ * @param {!WebGLRenderingContext} ctx The webgl context to wrap.
1064
+ * @param {!function(err, funcName, args): void} opt_onErrorFunc The function
1065
+ * to call when gl.getError returns an error. If not specified the default
1066
+ * function calls console.log with a message.
1067
+ * @param {!function(funcName, args): void} opt_onFunc The
1068
+ * function to call when each webgl function is called. You
1069
+ * can use this to log all calls for example.
1070
+ */
1071
+ makeDebugContext: makeDebugContext,
1072
+ /**
1073
+ * Given a canvas element returns a wrapped canvas element that will
1074
+ * simulate lost context. The canvas returned adds the following functions.
1075
+ *
1076
+ * loseContext:
1077
+ * simulates a lost context event.
1078
+ *
1079
+ * restoreContext:
1080
+ * simulates the context being restored.
1081
+ *
1082
+ * lostContextInNCalls:
1083
+ * loses the context after N gl calls.
1084
+ *
1085
+ * getNumCalls:
1086
+ * tells you how many gl calls there have been so far.
1087
+ *
1088
+ * setRestoreTimeout:
1089
+ * sets the number of milliseconds until the context is restored
1090
+ * after it has been lost. Defaults to 0. Pass -1 to prevent
1091
+ * automatic restoring.
1092
+ *
1093
+ * @param {!Canvas} canvas The canvas element to wrap.
1094
+ */
1095
+ makeLostContextSimulatingCanvas: makeLostContextSimulatingCanvas,
1096
+ /**
1097
+ * Resets a context to the initial state.
1098
+ * @param {!WebGLRenderingContext} ctx The webgl context to
1099
+ * reset.
1100
+ */
1101
+ resetToInitialState: resetToInitialState
1102
+ };
1103
+ }();