@luma.gl/webgl 9.0.0-beta.1 → 9.0.0-beta.10

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 (285) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  2. package/dist/adapter/converters/device-parameters.js +295 -156
  3. package/dist/adapter/converters/sampler-parameters.d.ts +0 -4
  4. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.js +73 -67
  6. package/dist/adapter/converters/shader-formats.d.ts.map +1 -1
  7. package/dist/adapter/converters/shader-formats.js +53 -46
  8. package/dist/adapter/converters/texture-formats.d.ts +17 -21
  9. package/dist/adapter/converters/texture-formats.d.ts.map +1 -1
  10. package/dist/adapter/converters/texture-formats.js +481 -879
  11. package/dist/adapter/converters/vertex-formats.d.ts.map +1 -1
  12. package/dist/adapter/converters/vertex-formats.js +53 -61
  13. package/dist/adapter/device-helpers/webgl-device-features.d.ts +20 -0
  14. package/dist/adapter/device-helpers/webgl-device-features.d.ts.map +1 -0
  15. package/dist/adapter/device-helpers/webgl-device-features.js +98 -0
  16. package/dist/adapter/device-helpers/webgl-device-info.d.ts +5 -0
  17. package/dist/adapter/device-helpers/webgl-device-info.d.ts.map +1 -0
  18. package/dist/adapter/device-helpers/webgl-device-info.js +90 -0
  19. package/dist/adapter/device-helpers/webgl-device-limits.d.ts +35 -0
  20. package/dist/adapter/device-helpers/webgl-device-limits.d.ts.map +1 -0
  21. package/dist/adapter/device-helpers/webgl-device-limits.js +47 -0
  22. package/dist/adapter/helpers/decode-webgl-types.d.ts.map +1 -1
  23. package/dist/adapter/helpers/decode-webgl-types.js +88 -76
  24. package/dist/adapter/helpers/get-shader-layout.d.ts +1 -1
  25. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  26. package/dist/adapter/helpers/get-shader-layout.js +261 -225
  27. package/dist/adapter/helpers/parse-shader-compiler-log.d.ts.map +1 -1
  28. package/dist/adapter/helpers/parse-shader-compiler-log.js +47 -37
  29. package/dist/adapter/helpers/set-uniform.d.ts +1 -1
  30. package/dist/adapter/helpers/set-uniform.d.ts.map +1 -1
  31. package/dist/adapter/helpers/set-uniform.js +68 -82
  32. package/dist/adapter/helpers/webgl-topology-utils.d.ts.map +1 -1
  33. package/dist/adapter/helpers/webgl-topology-utils.js +78 -93
  34. package/dist/adapter/objects/constants-to-keys.d.ts +1 -1
  35. package/dist/adapter/objects/constants-to-keys.d.ts.map +1 -1
  36. package/dist/adapter/objects/constants-to-keys.js +19 -12
  37. package/dist/adapter/objects/webgl-renderbuffer.d.ts +2 -2
  38. package/dist/adapter/objects/webgl-renderbuffer.d.ts.map +1 -1
  39. package/dist/adapter/objects/webgl-renderbuffer.js +86 -77
  40. package/dist/adapter/objects/webgl-resource.d.ts +3 -25
  41. package/dist/adapter/objects/webgl-resource.d.ts.map +1 -1
  42. package/dist/adapter/objects/webgl-resource.js +102 -147
  43. package/dist/adapter/resources/webgl-buffer.d.ts +3 -4
  44. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  45. package/dist/adapter/resources/webgl-buffer.js +159 -117
  46. package/dist/adapter/resources/webgl-command-buffer.d.ts +1 -1
  47. package/dist/adapter/resources/webgl-command-buffer.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-command-buffer.js +266 -168
  49. package/dist/adapter/resources/webgl-command-encoder.d.ts +8 -3
  50. package/dist/adapter/resources/webgl-command-encoder.d.ts.map +1 -1
  51. package/dist/adapter/resources/webgl-command-encoder.js +33 -39
  52. package/dist/adapter/resources/webgl-external-texture.js +93 -1
  53. package/dist/adapter/resources/webgl-framebuffer.d.ts +8 -12
  54. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  55. package/dist/adapter/resources/webgl-framebuffer.js +174 -139
  56. package/dist/adapter/resources/webgl-query-set.d.ts +44 -0
  57. package/dist/adapter/resources/webgl-query-set.d.ts.map +1 -0
  58. package/dist/adapter/resources/webgl-query-set.js +136 -0
  59. package/dist/adapter/resources/webgl-render-pass.d.ts +3 -1
  60. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  61. package/dist/adapter/resources/webgl-render-pass.js +124 -90
  62. package/dist/adapter/resources/webgl-render-pipeline.d.ts +15 -6
  63. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  64. package/dist/adapter/resources/webgl-render-pipeline.js +362 -221
  65. package/dist/adapter/resources/webgl-sampler.d.ts +1 -3
  66. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  67. package/dist/adapter/resources/webgl-sampler.js +43 -33
  68. package/dist/adapter/resources/webgl-shader.d.ts +12 -2
  69. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  70. package/dist/adapter/resources/webgl-shader.js +114 -47
  71. package/dist/adapter/resources/webgl-texture-view.d.ts +14 -0
  72. package/dist/adapter/resources/webgl-texture-view.d.ts.map +1 -0
  73. package/dist/adapter/resources/webgl-texture-view.js +18 -0
  74. package/dist/adapter/resources/webgl-texture.d.ts +8 -10
  75. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  76. package/dist/adapter/resources/webgl-texture.js +616 -694
  77. package/dist/adapter/resources/webgl-transform-feedback.d.ts +2 -2
  78. package/dist/adapter/resources/webgl-transform-feedback.d.ts.map +1 -1
  79. package/dist/adapter/resources/webgl-transform-feedback.js +141 -143
  80. package/dist/adapter/resources/webgl-vertex-array.d.ts +3 -3
  81. package/dist/adapter/resources/webgl-vertex-array.d.ts.map +1 -1
  82. package/dist/adapter/resources/webgl-vertex-array.js +229 -157
  83. package/dist/adapter/webgl-canvas-context.d.ts +2 -2
  84. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  85. package/dist/adapter/webgl-canvas-context.js +58 -36
  86. package/dist/adapter/webgl-device.d.ts +50 -44
  87. package/dist/adapter/webgl-device.d.ts.map +1 -1
  88. package/dist/adapter/webgl-device.js +427 -352
  89. package/dist/classic/accessor.d.ts.map +1 -1
  90. package/dist/classic/accessor.js +132 -101
  91. package/dist/classic/clear.d.ts +2 -2
  92. package/dist/classic/clear.d.ts.map +1 -1
  93. package/dist/classic/clear.js +73 -72
  94. package/dist/classic/copy-and-blit.d.ts +1 -1
  95. package/dist/classic/copy-and-blit.d.ts.map +1 -1
  96. package/dist/classic/copy-and-blit.js +174 -175
  97. package/dist/classic/format-utils.d.ts +2 -2
  98. package/dist/classic/format-utils.d.ts.map +1 -1
  99. package/dist/classic/format-utils.js +39 -32
  100. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  101. package/dist/classic/typed-array-utils.js +96 -81
  102. package/dist/context/debug/spector.d.ts.map +1 -1
  103. package/dist/context/debug/spector.js +55 -50
  104. package/dist/context/debug/webgl-developer-tools.d.ts +1 -2
  105. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  106. package/dist/context/debug/webgl-developer-tools.js +104 -77
  107. package/dist/context/{context → helpers}/create-browser-context.d.ts +1 -6
  108. package/dist/context/helpers/create-browser-context.d.ts.map +1 -0
  109. package/dist/context/helpers/create-browser-context.js +67 -0
  110. package/dist/context/{polyfill/context-data.d.ts → helpers/webgl-context-data.d.ts} +2 -2
  111. package/dist/context/helpers/webgl-context-data.d.ts.map +1 -0
  112. package/dist/context/helpers/webgl-context-data.js +21 -0
  113. package/dist/context/helpers/webgl-extensions.d.ts +4 -0
  114. package/dist/context/helpers/webgl-extensions.d.ts.map +1 -0
  115. package/dist/context/helpers/webgl-extensions.js +10 -0
  116. package/dist/context/parameters/unified-parameter-api.d.ts +3 -4
  117. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  118. package/dist/context/parameters/unified-parameter-api.js +92 -47
  119. package/dist/context/parameters/webgl-parameter-tables.d.ts +109 -99
  120. package/dist/context/parameters/webgl-parameter-tables.d.ts.map +1 -1
  121. package/dist/context/parameters/webgl-parameter-tables.js +463 -404
  122. package/dist/context/state-tracker/deep-array-equal.d.ts.map +1 -1
  123. package/dist/context/state-tracker/deep-array-equal.js +19 -14
  124. package/dist/context/state-tracker/track-context-state.d.ts +4 -4
  125. package/dist/context/state-tracker/track-context-state.d.ts.map +1 -1
  126. package/dist/context/state-tracker/track-context-state.js +188 -123
  127. package/dist/context/state-tracker/with-parameters.d.ts +2 -3
  128. package/dist/context/state-tracker/with-parameters.d.ts.map +1 -1
  129. package/dist/context/state-tracker/with-parameters.js +42 -28
  130. package/dist/dist.dev.js +4465 -7235
  131. package/dist/dist.min.js +10 -0
  132. package/dist/index.cjs +2146 -3116
  133. package/dist/index.cjs.map +7 -0
  134. package/dist/index.d.ts +25 -31
  135. package/dist/index.d.ts.map +1 -1
  136. package/dist/index.js +19 -10
  137. package/dist/types.d.ts.map +1 -1
  138. package/dist/types.js +3 -1
  139. package/dist.min.js +9 -42
  140. package/package.json +10 -15
  141. package/src/adapter/converters/device-parameters.ts +114 -28
  142. package/src/adapter/converters/sampler-parameters.ts +12 -20
  143. package/src/adapter/converters/shader-formats.ts +47 -22
  144. package/src/adapter/converters/texture-formats.ts +183 -227
  145. package/src/adapter/converters/vertex-formats.ts +3 -3
  146. package/src/adapter/device-helpers/webgl-device-features.ts +121 -0
  147. package/src/adapter/device-helpers/{get-device-info.ts → webgl-device-info.ts} +30 -22
  148. package/src/adapter/device-helpers/webgl-device-limits.ts +53 -0
  149. package/src/adapter/helpers/decode-webgl-types.ts +13 -7
  150. package/src/adapter/helpers/get-shader-layout.ts +21 -31
  151. package/src/adapter/helpers/parse-shader-compiler-log.ts +10 -6
  152. package/src/adapter/helpers/set-uniform.ts +3 -4
  153. package/src/adapter/helpers/webgl-topology-utils.ts +10 -3
  154. package/src/adapter/objects/constants-to-keys.ts +3 -2
  155. package/src/adapter/objects/webgl-renderbuffer.ts +38 -16
  156. package/src/adapter/objects/webgl-resource.ts +8 -141
  157. package/src/adapter/resources/webgl-buffer.ts +10 -14
  158. package/src/adapter/resources/webgl-command-buffer.ts +24 -34
  159. package/src/adapter/resources/webgl-command-encoder.ts +14 -11
  160. package/src/adapter/resources/webgl-external-texture.ts +7 -7
  161. package/src/adapter/resources/webgl-framebuffer.ts +65 -58
  162. package/src/adapter/resources/webgl-query-set.ts +171 -0
  163. package/src/adapter/resources/webgl-render-pass.ts +27 -18
  164. package/src/adapter/resources/webgl-render-pipeline.ts +148 -73
  165. package/src/adapter/resources/webgl-sampler.ts +7 -10
  166. package/src/adapter/resources/webgl-shader.ts +65 -11
  167. package/src/adapter/resources/webgl-texture-view.ts +28 -0
  168. package/src/adapter/resources/webgl-texture.ts +43 -106
  169. package/src/adapter/resources/webgl-transform-feedback.ts +16 -22
  170. package/src/adapter/resources/webgl-vertex-array.ts +20 -21
  171. package/src/adapter/webgl-canvas-context.ts +7 -11
  172. package/src/adapter/webgl-device.ts +142 -162
  173. package/src/classic/accessor.ts +5 -4
  174. package/src/classic/clear.ts +25 -20
  175. package/src/classic/copy-and-blit.ts +12 -6
  176. package/src/classic/format-utils.ts +2 -1
  177. package/src/classic/typed-array-utils.ts +3 -7
  178. package/src/context/debug/spector.ts +9 -6
  179. package/src/context/debug/webgl-developer-tools.ts +31 -20
  180. package/src/context/{context → helpers}/create-browser-context.ts +9 -33
  181. package/src/context/{polyfill/context-data.ts → helpers/webgl-context-data.ts} +3 -2
  182. package/src/context/helpers/webgl-extensions.ts +17 -0
  183. package/src/context/parameters/unified-parameter-api.ts +6 -17
  184. package/src/context/parameters/webgl-parameter-tables.ts +118 -90
  185. package/src/context/state-tracker/deep-array-equal.ts +2 -1
  186. package/src/context/state-tracker/track-context-state.ts +29 -23
  187. package/src/context/state-tracker/with-parameters.ts +8 -8
  188. package/src/index.ts +16 -56
  189. package/src/types.ts +2 -1
  190. package/dist/adapter/converters/device-parameters.js.map +0 -1
  191. package/dist/adapter/converters/sampler-parameters.js.map +0 -1
  192. package/dist/adapter/converters/shader-formats.js.map +0 -1
  193. package/dist/adapter/converters/texture-formats.js.map +0 -1
  194. package/dist/adapter/converters/vertex-formats.js.map +0 -1
  195. package/dist/adapter/device-helpers/device-features.d.ts +0 -9
  196. package/dist/adapter/device-helpers/device-features.d.ts.map +0 -1
  197. package/dist/adapter/device-helpers/device-features.js +0 -96
  198. package/dist/adapter/device-helpers/device-features.js.map +0 -1
  199. package/dist/adapter/device-helpers/device-limits.d.ts +0 -52
  200. package/dist/adapter/device-helpers/device-limits.d.ts.map +0 -1
  201. package/dist/adapter/device-helpers/device-limits.js +0 -87
  202. package/dist/adapter/device-helpers/device-limits.js.map +0 -1
  203. package/dist/adapter/device-helpers/get-device-info.d.ts +0 -4
  204. package/dist/adapter/device-helpers/get-device-info.d.ts.map +0 -1
  205. package/dist/adapter/device-helpers/get-device-info.js +0 -71
  206. package/dist/adapter/device-helpers/get-device-info.js.map +0 -1
  207. package/dist/adapter/device-helpers/is-old-ie.d.ts +0 -2
  208. package/dist/adapter/device-helpers/is-old-ie.d.ts.map +0 -1
  209. package/dist/adapter/device-helpers/is-old-ie.js +0 -9
  210. package/dist/adapter/device-helpers/is-old-ie.js.map +0 -1
  211. package/dist/adapter/helpers/decode-webgl-types.js.map +0 -1
  212. package/dist/adapter/helpers/get-shader-layout.js.map +0 -1
  213. package/dist/adapter/helpers/parse-shader-compiler-log.js.map +0 -1
  214. package/dist/adapter/helpers/set-uniform.js.map +0 -1
  215. package/dist/adapter/helpers/webgl-topology-utils.js.map +0 -1
  216. package/dist/adapter/objects/constants-to-keys.js.map +0 -1
  217. package/dist/adapter/objects/webgl-renderbuffer.js.map +0 -1
  218. package/dist/adapter/objects/webgl-resource.js.map +0 -1
  219. package/dist/adapter/resources/webgl-buffer.js.map +0 -1
  220. package/dist/adapter/resources/webgl-command-buffer.js.map +0 -1
  221. package/dist/adapter/resources/webgl-command-encoder.js.map +0 -1
  222. package/dist/adapter/resources/webgl-external-texture.js.map +0 -1
  223. package/dist/adapter/resources/webgl-framebuffer.js.map +0 -1
  224. package/dist/adapter/resources/webgl-render-pass.js.map +0 -1
  225. package/dist/adapter/resources/webgl-render-pipeline.js.map +0 -1
  226. package/dist/adapter/resources/webgl-sampler.js.map +0 -1
  227. package/dist/adapter/resources/webgl-shader.js.map +0 -1
  228. package/dist/adapter/resources/webgl-texture.js.map +0 -1
  229. package/dist/adapter/resources/webgl-transform-feedback.js.map +0 -1
  230. package/dist/adapter/resources/webgl-vertex-array.js.map +0 -1
  231. package/dist/adapter/webgl-canvas-context.js.map +0 -1
  232. package/dist/adapter/webgl-device.js.map +0 -1
  233. package/dist/classic/accessor.js.map +0 -1
  234. package/dist/classic/clear.js.map +0 -1
  235. package/dist/classic/copy-and-blit.js.map +0 -1
  236. package/dist/classic/format-utils.js.map +0 -1
  237. package/dist/classic/typed-array-utils.js.map +0 -1
  238. package/dist/context/context/create-browser-context.d.ts.map +0 -1
  239. package/dist/context/context/create-browser-context.js +0 -53
  240. package/dist/context/context/create-browser-context.js.map +0 -1
  241. package/dist/context/context/create-headless-context.d.ts +0 -9
  242. package/dist/context/context/create-headless-context.d.ts.map +0 -1
  243. package/dist/context/context/create-headless-context.js +0 -42
  244. package/dist/context/context/create-headless-context.js.map +0 -1
  245. package/dist/context/context/webgl-checks.d.ts +0 -13
  246. package/dist/context/context/webgl-checks.d.ts.map +0 -1
  247. package/dist/context/context/webgl-checks.js +0 -31
  248. package/dist/context/context/webgl-checks.js.map +0 -1
  249. package/dist/context/debug/spector.js.map +0 -1
  250. package/dist/context/debug/webgl-developer-tools.js.map +0 -1
  251. package/dist/context/parameters/unified-parameter-api.js.map +0 -1
  252. package/dist/context/parameters/webgl-parameter-tables.js.map +0 -1
  253. package/dist/context/polyfill/context-data.d.ts.map +0 -1
  254. package/dist/context/polyfill/context-data.js +0 -12
  255. package/dist/context/polyfill/context-data.js.map +0 -1
  256. package/dist/context/polyfill/get-parameter-polyfill.d.ts +0 -2
  257. package/dist/context/polyfill/get-parameter-polyfill.d.ts.map +0 -1
  258. package/dist/context/polyfill/get-parameter-polyfill.js +0 -85
  259. package/dist/context/polyfill/get-parameter-polyfill.js.map +0 -1
  260. package/dist/context/polyfill/polyfill-context.d.ts +0 -5
  261. package/dist/context/polyfill/polyfill-context.d.ts.map +0 -1
  262. package/dist/context/polyfill/polyfill-context.js +0 -87
  263. package/dist/context/polyfill/polyfill-context.js.map +0 -1
  264. package/dist/context/polyfill/polyfill-table.d.ts +0 -48
  265. package/dist/context/polyfill/polyfill-table.d.ts.map +0 -1
  266. package/dist/context/polyfill/polyfill-table.js +0 -137
  267. package/dist/context/polyfill/polyfill-table.js.map +0 -1
  268. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts +0 -2
  269. package/dist/context/polyfill/polyfill-vertex-array-object.d.ts.map +0 -1
  270. package/dist/context/polyfill/polyfill-vertex-array-object.js +0 -265
  271. package/dist/context/polyfill/polyfill-vertex-array-object.js.map +0 -1
  272. package/dist/context/state-tracker/deep-array-equal.js.map +0 -1
  273. package/dist/context/state-tracker/track-context-state.js.map +0 -1
  274. package/dist/context/state-tracker/with-parameters.js.map +0 -1
  275. package/dist/index.js.map +0 -1
  276. package/dist/types.js.map +0 -1
  277. package/src/adapter/device-helpers/device-features.ts +0 -161
  278. package/src/adapter/device-helpers/device-limits.ts +0 -155
  279. package/src/adapter/device-helpers/is-old-ie.ts +0 -14
  280. package/src/context/context/create-headless-context.ts +0 -51
  281. package/src/context/context/webgl-checks.ts +0 -51
  282. package/src/context/polyfill/get-parameter-polyfill.ts +0 -122
  283. package/src/context/polyfill/polyfill-context.ts +0 -104
  284. package/src/context/polyfill/polyfill-table.ts +0 -167
  285. package/src/context/polyfill/polyfill-vertex-array-object.ts +0 -365
@@ -1,161 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- // Feature detection for WebGL
5
- // Provides a function that enables simple checking of which WebGL features are
6
- // available in an WebGL1 or WebGL2 environment.
7
-
8
- import {DeviceFeature} from '@luma.gl/core';
9
- import {isWebGL2} from '../../context/context/webgl-checks';
10
- import {isOldIE} from './is-old-ie';
11
- import {getTextureFeatures, _checkFloat32ColorAttachment} from '../converters/texture-formats';
12
-
13
- /** Get WebGPU style feature strings */
14
- export function getDeviceFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {
15
- const features = getWebGLFeatures(gl);
16
-
17
- // texture features
18
- // features.add('texture-compression-bc');
19
- for (const textureFeature of getTextureFeatures(gl)) {
20
- features.add(textureFeature);
21
- }
22
-
23
- // TODO
24
- // features.add('depth-clip-control'); // GPUPrimitiveState.clampDepth
25
- // features.add('depth24unorm-stencil8'); // GPUTextureFormat 'depth24unorm-stencil8'.
26
- // features.add('depth32float-stencil8'); // GPUTextureFormat 'depth32float-stencil8'.
27
- // features.add('timestamp-query'); // GPUQueryType "timestamp-query"
28
- // "indirect-first-instance"
29
-
30
- return features;
31
- }
32
-
33
- /** Extract all WebGL features */
34
- export function getWebGLFeatures(gl: WebGLRenderingContext): Set<DeviceFeature> {
35
- // Enables EXT_float_blend first: https://developer.mozilla.org/en-US/docs/Web/API/EXT_float_blend
36
- gl.getExtension('EXT_color_buffer_float');
37
- gl.getExtension('WEBGL_color_buffer_float');
38
- gl.getExtension('EXT_float_blend');
39
-
40
- const features = new Set<DeviceFeature>();
41
- for (const feature of Object.keys(WEBGL_FEATURES)) {
42
- // @ts-expect-error
43
- if (isFeatureSupported(gl, feature)) {
44
- // @ts-expect-error
45
- features.add(feature);
46
- }
47
- }
48
- return features;
49
- }
50
-
51
- function isFeatureSupported(gl: WebGLRenderingContext, feature: DeviceFeature): boolean {
52
- const featureInfo = WEBGL_FEATURES[feature];
53
- if (!featureInfo) {
54
- return false;
55
- }
56
-
57
- const [webgl1Feature, webgl2Feature] = featureInfo || [];
58
-
59
- // Get extension name from table
60
- const featureDefinition = isWebGL2(gl) ? webgl2Feature : webgl1Feature;
61
-
62
- // Check if the value is dependent on checking one or more extensions
63
- if (typeof featureDefinition === 'boolean') {
64
- return featureDefinition;
65
- }
66
-
67
- switch (feature) {
68
- case 'texture-renderable-rgba32float-webgl':
69
- return isWebGL2(gl) ? Boolean(gl.getExtension(featureDefinition)) :
70
- _checkFloat32ColorAttachment(gl);
71
- case 'glsl-derivatives':
72
- return canCompileGLSLExtension(gl, featureDefinition); // TODO options
73
- case 'glsl-frag-data':
74
- return canCompileGLSLExtension(gl, featureDefinition, {behavior: 'require'}); // TODO options
75
- case 'glsl-frag-depth':
76
- return canCompileGLSLExtension(gl, featureDefinition); // TODO options
77
- default:
78
- return Boolean(gl.getExtension(featureDefinition));
79
- }
80
- }
81
-
82
- const compiledGLSLExtensions: Record<string, boolean> = {};
83
-
84
- /*
85
- * Enables feature detection in IE11 due to a bug where gl.getExtension may return true
86
- * but fail to compile when the extension is enabled in the shader. Specifically,
87
- * the OES_standard_derivatives and WEBGL_draw_buffers extensions fails to compile in IE11 even though its included
88
- * in the list of supported extensions.
89
- * opts allows user agent to be overridden for testing
90
- * Inputs :
91
- * gl : WebGL context
92
- * cap : Key of WEBGL_FEATURES object identifying the extension
93
- * opts :
94
- * behavior : behavior of extension to be tested, by defualt `enable` is used
95
- * Returns : true, if shader is compiled successfully, false otherwise
96
- */
97
- export function canCompileGLSLExtension(gl: WebGLRenderingContext, extensionName, opts: {behavior?} = {}) {
98
- if (!isOldIE(opts)) {
99
- return true;
100
- }
101
-
102
- if (extensionName in compiledGLSLExtensions) {
103
- return compiledGLSLExtensions[extensionName];
104
- }
105
-
106
- const behavior = opts.behavior || 'enable';
107
- const source = `#extension GL_${extensionName} : ${behavior}\nvoid main(void) {}`;
108
-
109
- const shader = gl.createShader(gl.VERTEX_SHADER);
110
- if (!shader) {
111
- throw new Error('shader');
112
- }
113
- gl.shaderSource(shader, source);
114
- gl.compileShader(shader);
115
- const canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
116
- gl.deleteShader(shader);
117
- compiledGLSLExtensions[extensionName] = canCompile;
118
- return canCompile;
119
- }
120
-
121
- /** Defines luma.gl "feature" names and semantics
122
- * Format: 'feature-name: [WebGL1 support, WebGL2 support] / [WebGL1 and WebGL2 support]', when support is 'string' it is the name of the extension
123
- */
124
- const WEBGL_FEATURES: Partial<Record<DeviceFeature, [boolean | string, boolean | string]>> = {
125
- 'webgl': [true, true],
126
- 'webgl2': [false, true],
127
-
128
- 'timer-query-webgl': ['EXT_disjoint_timer_query', 'EXT_disjoint_timer_query_webgl2'],
129
- 'transform-feedback-webgl2': [false, true],
130
-
131
- // WEBGL1 SUPPORT
132
- 'vertex-array-object-webgl1': ['OES_vertex_array_object', true],
133
- 'instanced-rendering-webgl1': ['ANGLE_instanced_arrays', true],
134
- 'multiple-render-targets-webgl1': ['WEBGL_draw_buffers', true],
135
- 'index-uint32-webgl1': ['OES_element_index_uint', true],
136
- 'blend-minmax-webgl1': ['EXT_blend_minmax', true],
137
- 'texture-blend-float-webgl1': ['EXT_float_blend', 'EXT_float_blend'],
138
-
139
- // TEXTURES, RENDERBUFFERS
140
- 'texture-formats-srgb-webgl1': ['EXT_sRGB', true],
141
-
142
- // TEXTURES
143
- 'texture-formats-depth-webgl1': ['WEBGL_depth_texture', true],
144
- 'texture-formats-float32-webgl1': ['OES_texture_float', true],
145
- 'texture-formats-float16-webgl1': ['OES_texture_half_float', true],
146
-
147
- 'texture-filter-linear-float32-webgl': ['OES_texture_float_linear', 'OES_texture_float_linear'],
148
- 'texture-filter-linear-float16-webgl': ['OES_texture_half_float_linear', 'OES_texture_half_float_linear'],
149
- 'texture-filter-anisotropic-webgl': ['EXT_texture_filter_anisotropic', 'EXT_texture_filter_anisotropic'],
150
-
151
- // FRAMEBUFFERS, TEXTURES AND RENDERBUFFERS
152
- 'texture-renderable-rgba32float-webgl': ['WEBGL_color_buffer_float', 'EXT_color_buffer_float'], // Note override check
153
- 'texture-renderable-float32-webgl': [false, 'EXT_color_buffer_float'],
154
- 'texture-renderable-float16-webgl': ['EXT_color_buffer_half_float', 'EXT_color_buffer_half_float'],
155
-
156
- // GLSL extensions
157
- 'glsl-frag-data': ['WEBGL_draw_buffers', true],
158
- 'glsl-frag-depth': ['EXT_frag_depth', true],
159
- 'glsl-derivatives': ['OES_standard_derivatives', true],
160
- 'glsl-texture-lod': ['EXT_shader_texture_lod', true]
161
- };
@@ -1,155 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- import type {DeviceLimits} from '@luma.gl/core';
5
- import {GL} from '@luma.gl/constants';
6
- import {getWebGL2Context} from '../../context/context/webgl-checks';
7
-
8
- /** Populate a WebGPU style device limits */
9
- export function getDeviceLimits(gl: WebGLRenderingContext): DeviceLimits {
10
- const gl2: WebGL2RenderingContext | null = getWebGL2Context(gl);
11
- return {
12
- maxTextureDimension1D: 0, // WebGL does not support 1D textures
13
- maxTextureDimension2D: gl.getParameter(GL.MAX_TEXTURE_SIZE),
14
- maxTextureDimension3D: gl2 ? gl2.getParameter(GL.MAX_3D_TEXTURE_SIZE) : 0,
15
- maxTextureArrayLayers: gl2 ? gl2.getParameter(GL.MAX_ARRAY_TEXTURE_LAYERS) : 0,
16
- maxBindGroups: 1, // TBD
17
- maxDynamicUniformBuffersPerPipelineLayout: 0, // TBD
18
- maxDynamicStorageBuffersPerPipelineLayout: 0, // TBD
19
- maxSampledTexturesPerShaderStage: gl.getParameter(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS), // TBD
20
- maxSamplersPerShaderStage: gl.getParameter(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS),
21
- maxStorageBuffersPerShaderStage: 0, // TBD
22
- maxStorageTexturesPerShaderStage: 0, // TBD
23
- maxUniformBuffersPerShaderStage: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BUFFER_BINDINGS) : 0,
24
- maxUniformBufferBindingSize: gl2 ? gl2.getParameter(GL.MAX_UNIFORM_BLOCK_SIZE) : 0,
25
- maxStorageBufferBindingSize: 0,
26
- minUniformBufferOffsetAlignment: gl2 ? gl2.getParameter(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) : 0,
27
- minStorageBufferOffsetAlignment: 0, // TBD
28
- maxVertexBuffers: 0,
29
- maxVertexAttributes: gl.getParameter(GL.MAX_VERTEX_ATTRIBS),
30
- maxVertexBufferArrayStride: 2048, // TBD, this is just the default value from WebGPU
31
- maxInterStageShaderComponents: gl2 ? gl2.getParameter(GL.MAX_VARYING_COMPONENTS) : 0,
32
- maxComputeWorkgroupStorageSize: 0, // WebGL does not support compute shaders
33
- maxComputeInvocationsPerWorkgroup: 0, // WebGL does not support compute shaders
34
- maxComputeWorkgroupSizeX: 0, // WebGL does not support compute shaders
35
- maxComputeWorkgroupSizeY: 0, // WebGL does not support compute shaders
36
- maxComputeWorkgroupSizeZ: 0, // WebGL does not support compute shaders
37
- maxComputeWorkgroupsPerDimension: 0, // WebGL does not support compute shaders
38
- }
39
- }
40
-
41
- /** WebGL context limits */
42
- export type WebGLLimits = {
43
- [GL.ALIASED_LINE_WIDTH_RANGE]: [number, number];
44
- [GL.ALIASED_POINT_SIZE_RANGE]: [number, number];
45
- [GL.MAX_TEXTURE_SIZE]: number;
46
- [GL.MAX_CUBE_MAP_TEXTURE_SIZE]: number;
47
- [GL.MAX_TEXTURE_IMAGE_UNITS]: number;
48
- [GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS]: number;
49
- [GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS]: number;
50
- [GL.MAX_RENDERBUFFER_SIZE]: number;
51
- [GL.MAX_VARYING_VECTORS]: number;
52
- [GL.MAX_VERTEX_ATTRIBS]: number;
53
- [GL.MAX_VERTEX_UNIFORM_VECTORS]: number;
54
- [GL.MAX_FRAGMENT_UNIFORM_VECTORS]: number;
55
- [GL.MAX_VIEWPORT_DIMS]: [number, number];
56
-
57
- // Extensions
58
- [GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT]: number;
59
-
60
- // WebGL2 Limits
61
- [GL.MAX_3D_TEXTURE_SIZE]: number;
62
- [GL.MAX_ARRAY_TEXTURE_LAYERS]: number;
63
- [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: number;
64
- [GL.MAX_COLOR_ATTACHMENTS]: number;
65
- [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: number;
66
- [GL.MAX_COMBINED_UNIFORM_BLOCKS]: number;
67
- [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: number;
68
- [GL.MAX_DRAW_BUFFERS]: number;
69
- [GL.MAX_ELEMENT_INDEX]: number;
70
- [GL.MAX_ELEMENTS_INDICES]: number;
71
- [GL.MAX_ELEMENTS_VERTICES]: number;
72
- [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: number;
73
- [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: number;
74
- [GL.MAX_FRAGMENT_UNIFORM_COMPONENTS]: number;
75
- [GL.MAX_SAMPLES]: number;
76
- [GL.MAX_SERVER_WAIT_TIMEOUT]: number;
77
- [GL.MAX_TEXTURE_LOD_BIAS]: number;
78
- [GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]: number;
79
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS]: number;
80
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS]: number;
81
- [GL.MAX_UNIFORM_BLOCK_SIZE]: number;
82
- [GL.MAX_UNIFORM_BUFFER_BINDINGS]: number;
83
- [GL.MAX_VARYING_COMPONENTS]: number;
84
- [GL.MAX_VERTEX_OUTPUT_COMPONENTS]: number;
85
- [GL.MAX_VERTEX_UNIFORM_BLOCKS]: number;
86
- [GL.MAX_VERTEX_UNIFORM_COMPONENTS]: number;
87
- [GL.MIN_PROGRAM_TEXEL_OFFSET]: number;
88
- [GL.MAX_PROGRAM_TEXEL_OFFSET]: number;
89
- [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: number;
90
- };
91
-
92
-
93
- export function getWebGLLimits(gl: WebGLRenderingContext): WebGLLimits {
94
- const gl2 = getWebGL2Context(gl);
95
- function get<T = number>(pname: number): T {
96
- return gl.getParameter(pname) as T;
97
- }
98
- function get2(pname: number, defaultValue?: number): number;
99
- function get2<T>(pname: number, defaultValue: T): T;
100
- function get2<T>(pname: number, defaultValue: T): T {
101
- return gl2 ? gl2.getParameter(pname) as T : (defaultValue || 0) as T;
102
- }
103
- // function getMaxAnistropy() {
104
- // const extension = gl.getExtension('EXT_texture_filter_anisotropic');
105
- // }
106
- return {
107
- [GL.ALIASED_LINE_WIDTH_RANGE]: get(GL.ALIASED_LINE_WIDTH_RANGE),
108
- [GL.ALIASED_POINT_SIZE_RANGE]: get(GL.ALIASED_POINT_SIZE_RANGE),
109
- [GL.MAX_TEXTURE_SIZE]: get(GL.MAX_TEXTURE_SIZE),
110
- [GL.MAX_CUBE_MAP_TEXTURE_SIZE]: get(GL.MAX_CUBE_MAP_TEXTURE_SIZE), // GLint
111
- [GL.MAX_TEXTURE_IMAGE_UNITS]: get(GL.MAX_TEXTURE_IMAGE_UNITS), // GLint
112
- [GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS]: get(GL.MAX_COMBINED_TEXTURE_IMAGE_UNITS), // GLint
113
- [GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS]: get(GL.MAX_VERTEX_TEXTURE_IMAGE_UNITS), // GLint
114
- [GL.MAX_RENDERBUFFER_SIZE]: get(GL.MAX_RENDERBUFFER_SIZE), // GLint
115
- [GL.MAX_VARYING_VECTORS]: get(GL.MAX_VARYING_VECTORS), // GLint
116
- [GL.MAX_VERTEX_ATTRIBS]: get(GL.MAX_VERTEX_ATTRIBS), // GLint
117
- [GL.MAX_VERTEX_UNIFORM_VECTORS]: get(GL.MAX_VERTEX_UNIFORM_VECTORS), // GLint
118
- [GL.MAX_FRAGMENT_UNIFORM_VECTORS]: get(GL.MAX_FRAGMENT_UNIFORM_VECTORS), // GLint
119
- [GL.MAX_VIEWPORT_DIMS]: get(GL.MAX_VIEWPORT_DIMS),
120
-
121
- // Extensions
122
- [GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT]: get(GL.MAX_TEXTURE_MAX_ANISOTROPY_EXT), // getMaxAnistropy(),
123
-
124
- // WebGL2 Limits
125
- [GL.MAX_3D_TEXTURE_SIZE]: get2(GL.MAX_3D_TEXTURE_SIZE), // GLint
126
- [GL.MAX_ARRAY_TEXTURE_LAYERS]: get2(GL.MAX_ARRAY_TEXTURE_LAYERS), // GLint
127
- [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: get2(GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL), // GLint64
128
- [GL.MAX_COLOR_ATTACHMENTS]: get2(GL.MAX_COLOR_ATTACHMENTS), // GLint
129
- [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: get2(GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS), // GLint64
130
- [GL.MAX_COMBINED_UNIFORM_BLOCKS]: get2(GL.MAX_COMBINED_UNIFORM_BLOCKS), // GLint
131
- [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: get2(GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS), // GLint64
132
- [GL.MAX_DRAW_BUFFERS]: get2(GL.MAX_DRAW_BUFFERS), // GLint
133
- [GL.MAX_ELEMENT_INDEX]: get2(GL.MAX_ELEMENT_INDEX), // GLint64
134
- [GL.MAX_ELEMENTS_INDICES]: get2(GL.MAX_ELEMENTS_INDICES), // GLint
135
- [GL.MAX_ELEMENTS_VERTICES]: get2(GL.MAX_ELEMENTS_VERTICES), // GLint
136
- [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: get2(GL.MAX_FRAGMENT_INPUT_COMPONENTS), // GLint
137
- [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: get2(GL.MAX_FRAGMENT_UNIFORM_BLOCKS), // GLint
138
- [GL.MAX_FRAGMENT_UNIFORM_COMPONENTS]: get2(GL.MAX_FRAGMENT_UNIFORM_COMPONENTS), // GLint
139
- [GL.MAX_SAMPLES]: get2(GL.MAX_SAMPLES), // GLint
140
- [GL.MAX_SERVER_WAIT_TIMEOUT]: get2(GL.MAX_SERVER_WAIT_TIMEOUT), // GLint64
141
- [GL.MAX_TEXTURE_LOD_BIAS]: get2(GL.MAX_TEXTURE_LOD_BIAS), // GLfloat
142
- [GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]: get2(GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS), // GLint
143
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS]: get2(GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS), // GLint
144
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS]: get2(GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS), // GLint
145
- [GL.MAX_UNIFORM_BLOCK_SIZE]: get2(GL.MAX_UNIFORM_BLOCK_SIZE), // GLint64
146
- [GL.MAX_UNIFORM_BUFFER_BINDINGS]: get2(GL.MAX_UNIFORM_BUFFER_BINDINGS), // GLint
147
- [GL.MAX_VARYING_COMPONENTS]: get2(GL.MAX_VARYING_COMPONENTS), // GLint
148
- [GL.MAX_VERTEX_OUTPUT_COMPONENTS]: get2(GL.MAX_VERTEX_OUTPUT_COMPONENTS), // GLint
149
- [GL.MAX_VERTEX_UNIFORM_BLOCKS]: get2(GL.MAX_VERTEX_UNIFORM_BLOCKS), // GLint
150
- [GL.MAX_VERTEX_UNIFORM_COMPONENTS]: get2(GL.MAX_VERTEX_UNIFORM_COMPONENTS), // GLint
151
- [GL.MIN_PROGRAM_TEXEL_OFFSET]: get2(GL.MIN_PROGRAM_TEXEL_OFFSET), // GLint
152
- [GL.MAX_PROGRAM_TEXEL_OFFSET]: get2(GL.MAX_PROGRAM_TEXEL_OFFSET), // GLint
153
- [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: get2(GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT) // GLint
154
- };
155
- }
@@ -1,14 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- // opts allows user agent to be overridden for testing
5
- export function isOldIE(opts = {}) {
6
- const navigator = typeof window !== 'undefined' ? window.navigator || {} : {};
7
- // @ts-expect-error
8
- const userAgent = opts.userAgent || navigator.userAgent || '';
9
- // We only care about older versions of IE (IE 11 and below). Newer versions of IE (Edge)
10
- // have much better web standards support.
11
- const isMSIE = userAgent.indexOf('MSIE ') !== -1;
12
- const isTrident = userAgent.indexOf('Trident/') !== -1;
13
- return isMSIE || isTrident;
14
- }
@@ -1,51 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- const ERR_HEADLESSGL_FAILED =
5
- 'Failed to create WebGL context in Node.js, headless gl returned null';
6
-
7
- const ERR_HEADLESSGL_LOAD = '\
8
- luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
9
- contexts can not be created. This may not be an error. For example, this is a \
10
- typical configuration for isorender applications running on the server.';
11
-
12
- const CONTEXT_DEFAULTS = {
13
- width: 1,
14
- height: 1,
15
- debug: true,
16
- throwOnError: false
17
- };
18
-
19
- /** Duck typing for the main headless gl export, a function to create contexts */
20
- export type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;
21
-
22
- let headlessGL: HeadlessGL | null = null;
23
-
24
- /** By importing `gl` and registering it with this function, contexts can be created under Node.js */
25
- export function registerHeadlessGL(headlessgl: HeadlessGL) {
26
- headlessGL = headlessgl;
27
- }
28
-
29
- /** @returns true if headless gl is registered */
30
- export function isHeadlessGLRegistered(): boolean {
31
- return headlessGL !== null;
32
- }
33
-
34
- /** Create headless gl context (for running under Node.js) */
35
- export function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext {
36
- options = {...CONTEXT_DEFAULTS, ...options};
37
-
38
- const {width, height, webgl1, webgl2} = options;
39
-
40
- if (webgl2 && !webgl1) {
41
- throw new Error('headless-gl does not support WebGL2');
42
- }
43
- if (!headlessGL) {
44
- throw new Error(ERR_HEADLESSGL_LOAD);
45
- }
46
- const gl = headlessGL(width, height, options);
47
- if (!gl) {
48
- throw new Error(ERR_HEADLESSGL_FAILED);
49
- }
50
- return gl;
51
- }
@@ -1,51 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- import {assert} from '@luma.gl/core';
5
-
6
- const ERR_CONTEXT = 'Invalid WebGLRenderingContext';
7
- export const ERR_WEBGL = ERR_CONTEXT;
8
- export const ERR_WEBGL2 = 'Requires WebGL2';
9
-
10
-
11
- /** Check if supplied parameter is a WebGLRenderingContext */
12
- export function isWebGL(gl: any): boolean {
13
- if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {
14
- return true;
15
- }
16
- if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
17
- return true;
18
- }
19
- // Look for debug contexts, headless gl etc
20
- return Boolean(gl && Number.isFinite(gl._version));
21
- }
22
-
23
-
24
- /** Check if supplied parameter is a WebGL2RenderingContext */
25
- export function isWebGL2(gl: any): boolean {
26
- if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
27
- return true;
28
- }
29
- // Look for debug contexts, headless gl etc
30
- return Boolean(gl && gl._version === 2);
31
- }
32
-
33
-
34
- /** Returns a properly typed WebGL2RenderingContext from a WebGL1 context, or null */
35
- export function getWebGL2Context(gl: WebGLRenderingContext): WebGL2RenderingContext | null {
36
- // @ts-expect-error
37
- return isWebGL2(gl) ? gl : null;
38
- }
39
-
40
-
41
- /** Throw if supplied parameter is not a WebGLRenderingContext, otherwise return properly typed value */
42
- export function assertWebGLContext(gl: any): WebGLRenderingContext {
43
- assert(isWebGL(gl), ERR_CONTEXT);
44
- return gl;
45
- }
46
-
47
- /** Throw if supplied parameter is not a WebGL2RenderingContext, otherwise return properly typed value */
48
- export function assertWebGL2Context(gl: any): WebGL2RenderingContext {
49
- assert(isWebGL2(gl), ERR_WEBGL2);
50
- return gl;
51
- }
@@ -1,122 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- /* eslint-disable no-inline-comments, max-len, camelcase */
5
- import {GL} from '@luma.gl/constants';
6
- import {isWebGL2} from '../context/webgl-checks';
7
-
8
- const OES_element_index = 'OES_element_index';
9
- const WEBGL_draw_buffers = 'WEBGL_draw_buffers';
10
- const EXT_disjoint_timer_query = 'EXT_disjoint_timer_query';
11
- const EXT_disjoint_timer_query_webgl2 = 'EXT_disjoint_timer_query_webgl2';
12
- const EXT_texture_filter_anisotropic = 'EXT_texture_filter_anisotropic';
13
- const WEBGL_debug_renderer_info = 'WEBGL_debug_renderer_info';
14
-
15
- const GL_FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8b8b;
16
- const GL_DONT_CARE = 0x1100;
17
- const GL_GPU_DISJOINT_EXT = 0x8fbb;
18
- const GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84ff;
19
- const GL_UNMASKED_VENDOR_WEBGL = 0x9245; // vendor string of the graphics driver.
20
- const GL_UNMASKED_RENDERER_WEBGL = 0x9246; // renderer string of the graphics driver.
21
-
22
- const getWebGL2ValueOrZero = (gl) => (!isWebGL2(gl) ? 0 : undefined);
23
-
24
- // if a function returns undefined in this table,
25
- // the original getParameter will be called, defeating the override
26
- const WEBGL_PARAMETERS = {
27
- [GL.READ_BUFFER]: (gl) => (!isWebGL2(gl) ? GL.COLOR_ATTACHMENT0 : undefined),
28
-
29
- // WebGL2 context parameters
30
- [GL_FRAGMENT_SHADER_DERIVATIVE_HINT]: (gl) => (!isWebGL2(gl) ? GL_DONT_CARE : undefined),
31
-
32
- [GL.RASTERIZER_DISCARD]: getWebGL2ValueOrZero,
33
-
34
- [GL.SAMPLES]: getWebGL2ValueOrZero,
35
-
36
- // WebGL2 extension context parameters
37
- [GL_GPU_DISJOINT_EXT]: (gl: WebGLRenderingContext, getParameter) => {
38
- const ext = isWebGL2(gl)
39
- ? gl.getExtension(EXT_disjoint_timer_query_webgl2)
40
- : gl.getExtension(EXT_disjoint_timer_query);
41
- return ext && ext.GPU_DISJOINT_EXT ? getParameter(ext.GPU_DISJOINT_EXT) : 0;
42
- },
43
-
44
- // Extension fixed values
45
- [GL_UNMASKED_VENDOR_WEBGL]: (gl: WebGLRenderingContext, getParameter) => {
46
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
47
- return getParameter((ext && ext.UNMASKED_VENDOR_WEBGL) || GL.VENDOR);
48
- },
49
-
50
- [GL_UNMASKED_RENDERER_WEBGL]: (gl: WebGLRenderingContext, getParameter) => {
51
- const ext = gl.getExtension(WEBGL_debug_renderer_info);
52
- return getParameter((ext && ext.UNMASKED_RENDERER_WEBGL) || GL.RENDERER);
53
- },
54
-
55
- // Extension LIMITS
56
- [GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT]: (gl: WebGLRenderingContext, getParameter) => {
57
- // @ts-ignore TODO - store these on the device instance instead...
58
- const ext = gl.luma?.extensions?.[EXT_texture_filter_anisotropic] ||
59
- gl.getExtension('EXT_texture_filter_anisotropic');
60
- return ext ? getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1.0;
61
- },
62
-
63
- // WebGL2 Limits
64
- [GL.MAX_3D_TEXTURE_SIZE]: getWebGL2ValueOrZero,
65
- [GL.MAX_ARRAY_TEXTURE_LAYERS]: getWebGL2ValueOrZero,
66
- [GL.MAX_CLIENT_WAIT_TIMEOUT_WEBGL]: getWebGL2ValueOrZero,
67
- [GL.MAX_COLOR_ATTACHMENTS]: (gl: WebGLRenderingContext, getParameter) => {
68
- if (!isWebGL2(gl)) {
69
- const ext = gl.getExtension(WEBGL_draw_buffers);
70
- return ext ? getParameter(ext.MAX_COLOR_ATTACHMENTS_WEBGL) : 0;
71
- }
72
- return undefined;
73
- },
74
- [GL.MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
75
- [GL.MAX_COMBINED_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
76
- [GL.MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
77
- [GL.MAX_DRAW_BUFFERS]: (gl) => {
78
- if (!isWebGL2(gl)) {
79
- const ext = gl.getExtension(WEBGL_draw_buffers);
80
- return ext ? ext.MAX_DRAW_BUFFERS_WEBGL : 0;
81
- }
82
- return undefined;
83
- },
84
- [GL.MAX_ELEMENT_INDEX]:
85
- // Guess: per webglstats.com 99.6% of webgl2 supports 2147483647
86
- (gl) => (gl.getExtension(OES_element_index) ? 2147483647 : 65535),
87
- [GL.MAX_ELEMENTS_INDICES]:
88
- // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
89
- (gl) => (gl.getExtension(OES_element_index) ? 16777216 : 65535),
90
- [GL.MAX_ELEMENTS_VERTICES]:
91
- // Guess: "Reasonably safe" per webglstats.com - could be higher/lower (on some mobile devices)
92
- (gl) => 16777216,
93
- [GL.MAX_FRAGMENT_INPUT_COMPONENTS]: getWebGL2ValueOrZero,
94
- [GL.MAX_FRAGMENT_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
95
- [GL.MAX_FRAGMENT_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
96
- [GL.MAX_SAMPLES]: getWebGL2ValueOrZero,
97
- [GL.MAX_SERVER_WAIT_TIMEOUT]: getWebGL2ValueOrZero,
98
- [GL.MAX_TEXTURE_LOD_BIAS]: getWebGL2ValueOrZero,
99
- [GL.MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS]: getWebGL2ValueOrZero,
100
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS]: getWebGL2ValueOrZero,
101
- [GL.MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS]: getWebGL2ValueOrZero,
102
- [GL.MAX_UNIFORM_BLOCK_SIZE]: getWebGL2ValueOrZero,
103
- [GL.MAX_UNIFORM_BUFFER_BINDINGS]: getWebGL2ValueOrZero,
104
- [GL.MAX_VARYING_COMPONENTS]: getWebGL2ValueOrZero,
105
- [GL.MAX_VERTEX_OUTPUT_COMPONENTS]: getWebGL2ValueOrZero,
106
- [GL.MAX_VERTEX_UNIFORM_BLOCKS]: getWebGL2ValueOrZero,
107
- [GL.MAX_VERTEX_UNIFORM_COMPONENTS]: getWebGL2ValueOrZero,
108
- [GL.MIN_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
109
- [GL.MAX_PROGRAM_TEXEL_OFFSET]: getWebGL2ValueOrZero,
110
- [GL.UNIFORM_BUFFER_OFFSET_ALIGNMENT]: getWebGL2ValueOrZero
111
- };
112
-
113
- // A "replacement" gl.getParameter that accepts "enums" from extensions and WebGL2
114
- // and returns reasonably safe defaults
115
- export function getParameterPolyfill(gl: WebGLRenderingContext, originalGetParameter, pname) {
116
- // Return mock limits (usually 0) for WebGL2 constants to ensure these
117
- // can be queries without error
118
- const limit = WEBGL_PARAMETERS[pname];
119
- const value = typeof limit === 'function' ? limit(gl, originalGetParameter, pname) : limit;
120
- const result = value !== undefined ? value : originalGetParameter(pname);
121
- return result;
122
- }
@@ -1,104 +0,0 @@
1
- // luma.gl, MIT license
2
- // Copyright (c) vis.gl contributors
3
-
4
- // WebGL1/WebGL2 extension polyfill support
5
- //
6
- // Provides a function that creates polyfills for WebGL2 functions based
7
- // on available extensions and installs them on a supplied target (could be
8
- // the WebGLContext or its prototype, or a separate object).
9
- //
10
- // This is intended to be a stand-alone file with minimal dependencies,
11
- // easy to reuse or repurpose in other projects.
12
-
13
- import {assert} from '@luma.gl/core';
14
- import {polyfillVertexArrayObject} from './polyfill-vertex-array-object';
15
-
16
- import {WEBGL2_CONTEXT_POLYFILLS, WEBGL2_CONTEXT_OVERRIDES} from './polyfill-table';
17
- import {getContextData} from './context-data';
18
-
19
- /**
20
- * Registers extensions, polyfills or mock functions for extensions in the polyfills list
21
- */
22
- export function polyfillContext(gl: WebGLRenderingContext): WebGL2RenderingContext {
23
- const contextState = getContextData(gl);
24
-
25
- if (!contextState._polyfilled) {
26
- polyfillVertexArrayObject(gl);
27
- initializeExtensions(gl);
28
- installPolyfills(gl, WEBGL2_CONTEXT_POLYFILLS);
29
- installOverrides(gl, {target: contextState, target2: gl});
30
- contextState._polyfilled = true;
31
- }
32
-
33
- // Note - only supports a subset of WebGL2
34
- return gl as WebGL2RenderingContext;
35
- }
36
-
37
- function initializeExtensions(gl: WebGLRenderingContext): void {
38
- const contextState = getContextData(gl);
39
- // `getSupportedExtensions` can return null when context is lost.
40
- const EXTENSIONS = gl.getSupportedExtensions() || [];
41
- // Generates warnings in Chrome
42
- const IGNORE_EXTENSIONS = ['WEBGL_polygon_mode'];
43
- for (const extensionName of EXTENSIONS) {
44
- if (!IGNORE_EXTENSIONS.includes(extensionName)) {
45
- const extension = gl.getExtension(extensionName);
46
- contextState._extensions[extensionName] = extension;
47
- }
48
- }
49
- }
50
-
51
- function installPolyfills(gl: WebGLRenderingContext, polyfills): void {
52
- const contextState = getContextData(gl);
53
- for (const extension of Object.getOwnPropertyNames(polyfills)) {
54
- if (extension !== 'overrides') {
55
- polyfillExtension(gl, {extension, target: contextState, target2: gl});
56
- }
57
- }
58
- }
59
-
60
- /** Polyfills a single WebGL extension into the `target` object */
61
- function polyfillExtension(gl: WebGLRenderingContext, {extension, target, target2}): void {
62
- const defaults = WEBGL2_CONTEXT_POLYFILLS[extension];
63
- assert(defaults);
64
-
65
- const {meta = {}} = defaults;
66
- const {suffix = ''} = meta;
67
-
68
- const ext = gl.getExtension(extension);
69
-
70
- for (const key of Object.keys(defaults)) {
71
- const extKey = `${key}${suffix}`;
72
-
73
- let polyfill: Function | null = null;
74
- if (key === 'meta') {
75
- // ignore
76
- } else if (typeof gl[key] === 'function') {
77
- // WebGL2 implementation is already
78
- } else if (ext && typeof ext[extKey] === 'function') {
79
- // pick extension implementation,if available
80
- polyfill = (...args) => ext[extKey](...args);
81
- } else if (typeof defaults[key] === 'function') {
82
- // pick the mock implementation, if no implementation was detected
83
- polyfill = defaults[key].bind(target);
84
- }
85
-
86
- if (polyfill) {
87
- target[key] = polyfill;
88
- target2[key] = polyfill;
89
- }
90
- }
91
- }
92
-
93
- /** Install simple overrides (mostly get* functions) */
94
- function installOverrides(gl: WebGLRenderingContext, {target, target2}) {
95
- Object.keys(WEBGL2_CONTEXT_OVERRIDES).forEach((key) => {
96
- if (typeof WEBGL2_CONTEXT_OVERRIDES[key] === 'function') {
97
- // install an override, if no implementation was detected
98
- const originalFunc = gl[key] ? gl[key].bind(gl) : () => {};
99
- const polyfill = WEBGL2_CONTEXT_OVERRIDES[key].bind(null, gl, originalFunc);
100
- target[key] = polyfill;
101
- target2[key] = polyfill;
102
- }
103
- });
104
- }