@luma.gl/webgl 9.0.0-alpha.5 → 9.0.0-alpha.7

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 (236) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +11 -1
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/converters/device-parameters.js +15 -2
  4. package/dist/adapter/converters/device-parameters.js.map +1 -1
  5. package/dist/adapter/converters/sampler-parameters.d.ts +4 -4
  6. package/dist/adapter/converters/sampler-parameters.d.ts.map +1 -1
  7. package/dist/adapter/converters/sampler-parameters.js +21 -2
  8. package/dist/adapter/converters/sampler-parameters.js.map +1 -1
  9. package/dist/adapter/converters/texture-formats.js +3 -3
  10. package/dist/adapter/converters/texture-formats.js.map +1 -1
  11. package/dist/adapter/device-helpers/device-features.d.ts.map +1 -1
  12. package/dist/adapter/device-helpers/device-features.js +12 -2
  13. package/dist/adapter/device-helpers/device-features.js.map +1 -1
  14. package/dist/adapter/device-helpers/device-limits.js.map +1 -1
  15. package/dist/adapter/helpers/get-shader-layout.d.ts.map +1 -1
  16. package/dist/adapter/helpers/get-shader-layout.js +40 -16
  17. package/dist/adapter/helpers/get-shader-layout.js.map +1 -1
  18. package/dist/adapter/helpers/uniforms.d.ts +1 -1
  19. package/dist/adapter/helpers/uniforms.d.ts.map +1 -1
  20. package/dist/adapter/helpers/uniforms.js +4 -4
  21. package/dist/adapter/helpers/uniforms.js.map +1 -1
  22. package/dist/adapter/objects/webgl-vertex-array-object.d.ts +1 -1
  23. package/dist/adapter/objects/webgl-vertex-array-object.d.ts.map +1 -1
  24. package/dist/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  25. package/dist/adapter/resources/webgl-buffer.d.ts +1 -1
  26. package/dist/adapter/resources/webgl-buffer.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgl-buffer.js +2 -2
  28. package/dist/adapter/resources/webgl-buffer.js.map +1 -1
  29. package/dist/adapter/resources/webgl-framebuffer.d.ts +2 -1
  30. package/dist/adapter/resources/webgl-framebuffer.d.ts.map +1 -1
  31. package/dist/adapter/resources/webgl-framebuffer.js +5 -3
  32. package/dist/adapter/resources/webgl-framebuffer.js.map +1 -1
  33. package/dist/adapter/resources/webgl-render-pass.d.ts.map +1 -1
  34. package/dist/adapter/resources/webgl-render-pass.js +2 -0
  35. package/dist/adapter/resources/webgl-render-pass.js.map +1 -1
  36. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
  37. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  38. package/dist/adapter/resources/webgl-render-pipeline.js +40 -24
  39. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  40. package/dist/adapter/resources/webgl-sampler.d.ts +2 -2
  41. package/dist/adapter/resources/webgl-sampler.d.ts.map +1 -1
  42. package/dist/adapter/resources/webgl-sampler.js.map +1 -1
  43. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  44. package/dist/adapter/resources/webgl-shader.js +4 -3
  45. package/dist/adapter/resources/webgl-shader.js.map +1 -1
  46. package/dist/adapter/resources/webgl-texture.d.ts +19 -19
  47. package/dist/adapter/resources/webgl-texture.d.ts.map +1 -1
  48. package/dist/adapter/resources/webgl-texture.js +14 -13
  49. package/dist/adapter/resources/webgl-texture.js.map +1 -1
  50. package/dist/adapter/webgl-canvas-context.d.ts.map +1 -1
  51. package/dist/adapter/webgl-canvas-context.js +1 -1
  52. package/dist/adapter/webgl-canvas-context.js.map +1 -1
  53. package/dist/adapter/webgl-device.d.ts.map +1 -1
  54. package/dist/adapter/webgl-device.js +13 -4
  55. package/dist/adapter/webgl-device.js.map +1 -1
  56. package/dist/classic/buffer.js +14 -6
  57. package/dist/classic/buffer.js.map +1 -1
  58. package/dist/classic/typed-array-utils.d.ts +1 -1
  59. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  60. package/dist/classic/typed-array-utils.js.map +1 -1
  61. package/dist/context/context/{create-context.d.ts → create-browser-context.d.ts} +1 -1
  62. package/dist/context/context/create-browser-context.d.ts.map +1 -0
  63. package/dist/context/context/{create-context.js → create-browser-context.js} +9 -3
  64. package/dist/context/context/create-browser-context.js.map +1 -0
  65. package/dist/context/context/create-headless-context.d.ts +9 -0
  66. package/dist/context/context/create-headless-context.d.ts.map +1 -0
  67. package/dist/context/context/create-headless-context.js +43 -0
  68. package/dist/context/context/create-headless-context.js.map +1 -0
  69. package/dist/context/context/device-pixels.d.ts.map +1 -1
  70. package/dist/context/context/device-pixels.js +13 -8
  71. package/dist/context/context/device-pixels.js.map +1 -1
  72. package/dist/context/debug/spector.js +1 -1
  73. package/dist/context/debug/spector.js.map +1 -1
  74. package/dist/context/debug/webgl-developer-tools.js +1 -1
  75. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  76. package/dist/context/parameters/unified-parameter-api.d.ts +5 -4
  77. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  78. package/dist/context/parameters/unified-parameter-api.js +1 -3
  79. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  80. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  81. package/dist/context/polyfill/polyfill-table.d.ts +1 -1
  82. package/dist/context/polyfill/polyfill-table.d.ts.map +1 -1
  83. package/dist/context/polyfill/polyfill-table.js +1 -1
  84. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  85. package/dist/context/state-tracker/track-context-state.js +1 -1
  86. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  87. package/dist/es5/adapter/converters/device-parameters.js +17 -2
  88. package/dist/es5/adapter/converters/device-parameters.js.map +1 -1
  89. package/dist/es5/adapter/converters/sampler-parameters.js +21 -2
  90. package/dist/es5/adapter/converters/sampler-parameters.js.map +1 -1
  91. package/dist/es5/adapter/converters/texture-formats.js +3 -3
  92. package/dist/es5/adapter/converters/texture-formats.js.map +1 -1
  93. package/dist/es5/adapter/device-helpers/device-features.js +15 -4
  94. package/dist/es5/adapter/device-helpers/device-features.js.map +1 -1
  95. package/dist/es5/adapter/device-helpers/device-limits.js.map +1 -1
  96. package/dist/es5/adapter/helpers/get-shader-layout.js +48 -28
  97. package/dist/es5/adapter/helpers/get-shader-layout.js.map +1 -1
  98. package/dist/es5/adapter/helpers/uniforms.js +4 -4
  99. package/dist/es5/adapter/helpers/uniforms.js.map +1 -1
  100. package/dist/es5/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  101. package/dist/es5/adapter/resources/webgl-buffer.js +2 -2
  102. package/dist/es5/adapter/resources/webgl-buffer.js.map +1 -1
  103. package/dist/es5/adapter/resources/webgl-framebuffer.js +4 -3
  104. package/dist/es5/adapter/resources/webgl-framebuffer.js.map +1 -1
  105. package/dist/es5/adapter/resources/webgl-render-pass.js +1 -0
  106. package/dist/es5/adapter/resources/webgl-render-pass.js.map +1 -1
  107. package/dist/es5/adapter/resources/webgl-render-pipeline.js +43 -30
  108. package/dist/es5/adapter/resources/webgl-render-pipeline.js.map +1 -1
  109. package/dist/es5/adapter/resources/webgl-sampler.js.map +1 -1
  110. package/dist/es5/adapter/resources/webgl-shader.js +4 -3
  111. package/dist/es5/adapter/resources/webgl-shader.js.map +1 -1
  112. package/dist/es5/adapter/resources/webgl-texture.js +16 -16
  113. package/dist/es5/adapter/resources/webgl-texture.js.map +1 -1
  114. package/dist/es5/adapter/webgl-canvas-context.js +1 -1
  115. package/dist/es5/adapter/webgl-canvas-context.js.map +1 -1
  116. package/dist/es5/adapter/webgl-device.js +14 -4
  117. package/dist/es5/adapter/webgl-device.js.map +1 -1
  118. package/dist/es5/classic/buffer.js +14 -6
  119. package/dist/es5/classic/buffer.js.map +1 -1
  120. package/dist/es5/classic/typed-array-utils.js.map +1 -1
  121. package/dist/es5/context/context/{create-context.js → create-browser-context.js} +9 -3
  122. package/dist/es5/context/context/create-browser-context.js.map +1 -0
  123. package/dist/es5/context/context/create-headless-context.js +60 -0
  124. package/dist/es5/context/context/create-headless-context.js.map +1 -0
  125. package/dist/es5/context/context/device-pixels.js +14 -8
  126. package/dist/es5/context/context/device-pixels.js.map +1 -1
  127. package/dist/es5/context/debug/spector.js +1 -1
  128. package/dist/es5/context/debug/spector.js.map +1 -1
  129. package/dist/es5/context/debug/webgl-developer-tools.js +1 -1
  130. package/dist/es5/context/debug/webgl-developer-tools.js.map +1 -1
  131. package/dist/es5/context/parameters/unified-parameter-api.js +2 -2
  132. package/dist/es5/context/parameters/unified-parameter-api.js.map +1 -1
  133. package/dist/es5/context/polyfill/polyfill-context.js.map +1 -1
  134. package/dist/es5/context/polyfill/polyfill-table.js +1 -1
  135. package/dist/es5/context/polyfill/polyfill-table.js.map +1 -1
  136. package/dist/es5/context/state-tracker/track-context-state.js +1 -1
  137. package/dist/es5/context/state-tracker/track-context-state.js.map +1 -1
  138. package/dist/es5/index.js +30 -16
  139. package/dist/es5/index.js.map +1 -1
  140. package/dist/es5/types/webgl.js.map +1 -1
  141. package/dist/esm/adapter/converters/device-parameters.js +15 -2
  142. package/dist/esm/adapter/converters/device-parameters.js.map +1 -1
  143. package/dist/esm/adapter/converters/sampler-parameters.js +21 -2
  144. package/dist/esm/adapter/converters/sampler-parameters.js.map +1 -1
  145. package/dist/esm/adapter/converters/texture-formats.js +3 -3
  146. package/dist/esm/adapter/converters/texture-formats.js.map +1 -1
  147. package/dist/esm/adapter/device-helpers/device-features.js +12 -2
  148. package/dist/esm/adapter/device-helpers/device-features.js.map +1 -1
  149. package/dist/esm/adapter/device-helpers/device-limits.js.map +1 -1
  150. package/dist/esm/adapter/helpers/get-shader-layout.js +40 -16
  151. package/dist/esm/adapter/helpers/get-shader-layout.js.map +1 -1
  152. package/dist/esm/adapter/helpers/uniforms.js +4 -4
  153. package/dist/esm/adapter/helpers/uniforms.js.map +1 -1
  154. package/dist/esm/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  155. package/dist/esm/adapter/resources/webgl-buffer.js +2 -2
  156. package/dist/esm/adapter/resources/webgl-buffer.js.map +1 -1
  157. package/dist/esm/adapter/resources/webgl-framebuffer.js +5 -3
  158. package/dist/esm/adapter/resources/webgl-framebuffer.js.map +1 -1
  159. package/dist/esm/adapter/resources/webgl-render-pass.js +2 -0
  160. package/dist/esm/adapter/resources/webgl-render-pass.js.map +1 -1
  161. package/dist/esm/adapter/resources/webgl-render-pipeline.js +40 -24
  162. package/dist/esm/adapter/resources/webgl-render-pipeline.js.map +1 -1
  163. package/dist/esm/adapter/resources/webgl-sampler.js.map +1 -1
  164. package/dist/esm/adapter/resources/webgl-shader.js +4 -3
  165. package/dist/esm/adapter/resources/webgl-shader.js.map +1 -1
  166. package/dist/esm/adapter/resources/webgl-texture.js +14 -13
  167. package/dist/esm/adapter/resources/webgl-texture.js.map +1 -1
  168. package/dist/esm/adapter/webgl-canvas-context.js +1 -1
  169. package/dist/esm/adapter/webgl-canvas-context.js.map +1 -1
  170. package/dist/esm/adapter/webgl-device.js +13 -4
  171. package/dist/esm/adapter/webgl-device.js.map +1 -1
  172. package/dist/esm/classic/buffer.js +14 -6
  173. package/dist/esm/classic/buffer.js.map +1 -1
  174. package/dist/esm/classic/typed-array-utils.js.map +1 -1
  175. package/dist/esm/context/context/{create-context.js → create-browser-context.js} +9 -3
  176. package/dist/esm/context/context/create-browser-context.js.map +1 -0
  177. package/dist/esm/context/context/create-headless-context.js +43 -0
  178. package/dist/esm/context/context/create-headless-context.js.map +1 -0
  179. package/dist/esm/context/context/device-pixels.js +13 -8
  180. package/dist/esm/context/context/device-pixels.js.map +1 -1
  181. package/dist/esm/context/debug/spector.js +1 -1
  182. package/dist/esm/context/debug/spector.js.map +1 -1
  183. package/dist/esm/context/debug/webgl-developer-tools.js +1 -1
  184. package/dist/esm/context/debug/webgl-developer-tools.js.map +1 -1
  185. package/dist/esm/context/parameters/unified-parameter-api.js +1 -3
  186. package/dist/esm/context/parameters/unified-parameter-api.js.map +1 -1
  187. package/dist/esm/context/polyfill/polyfill-context.js.map +1 -1
  188. package/dist/esm/context/polyfill/polyfill-table.js +1 -1
  189. package/dist/esm/context/polyfill/polyfill-table.js.map +1 -1
  190. package/dist/esm/context/state-tracker/track-context-state.js +1 -1
  191. package/dist/esm/context/state-tracker/track-context-state.js.map +1 -1
  192. package/dist/esm/index.js +3 -2
  193. package/dist/esm/index.js.map +1 -1
  194. package/dist/esm/types/webgl.js.map +1 -1
  195. package/dist/index.d.ts +5 -3
  196. package/dist/index.d.ts.map +1 -1
  197. package/dist/index.js +3 -2
  198. package/dist/index.js.map +1 -1
  199. package/dist/types/webgl.d.ts +3 -3
  200. package/dist/types/webgl.d.ts.map +1 -1
  201. package/dist/types/webgl.js.map +1 -1
  202. package/package.json +4 -4
  203. package/src/adapter/converters/device-parameters.ts +28 -2
  204. package/src/adapter/converters/sampler-parameters.ts +16 -7
  205. package/src/adapter/converters/texture-formats.ts +3 -3
  206. package/src/adapter/device-helpers/device-features.ts +9 -1
  207. package/src/adapter/device-helpers/device-limits.ts +1 -1
  208. package/src/adapter/helpers/get-shader-layout.ts +40 -21
  209. package/src/adapter/helpers/uniforms.ts +21 -10
  210. package/src/adapter/objects/webgl-vertex-array-object.ts +1 -1
  211. package/src/adapter/resources/webgl-buffer.ts +3 -3
  212. package/src/adapter/resources/webgl-framebuffer.ts +6 -3
  213. package/src/adapter/resources/webgl-render-pass.ts +1 -0
  214. package/src/adapter/resources/webgl-render-pipeline.ts +43 -35
  215. package/src/adapter/resources/webgl-sampler.ts +5 -3
  216. package/src/adapter/resources/webgl-shader.ts +5 -4
  217. package/src/adapter/resources/webgl-texture.ts +37 -25
  218. package/src/adapter/webgl-canvas-context.ts +1 -1
  219. package/src/adapter/webgl-device.ts +16 -4
  220. package/src/classic/buffer.ts +7 -7
  221. package/src/classic/typed-array-utils.ts +3 -1
  222. package/src/context/context/{create-context.ts → create-browser-context.ts} +9 -5
  223. package/src/context/context/create-headless-context.ts +48 -0
  224. package/src/context/context/device-pixels.ts +15 -9
  225. package/src/context/debug/spector.ts +1 -1
  226. package/src/context/debug/webgl-developer-tools.ts +1 -1
  227. package/src/context/parameters/unified-parameter-api.ts +12 -9
  228. package/src/context/polyfill/polyfill-context.ts +1 -1
  229. package/src/context/polyfill/polyfill-table.ts +1 -1
  230. package/src/context/state-tracker/track-context-state.ts +1 -1
  231. package/src/index.ts +13 -5
  232. package/src/types/webgl.ts +3 -3
  233. package/dist/context/context/create-context.d.ts.map +0 -1
  234. package/dist/context/context/create-context.js.map +0 -1
  235. package/dist/es5/context/context/create-context.js.map +0 -1
  236. package/dist/esm/context/context/create-context.js.map +0 -1
@@ -10,11 +10,12 @@ import {
10
10
  Sampler,
11
11
  SamplerProps,
12
12
  SamplerParameters,
13
+ TypedArray,
13
14
  isObjectEmpty
14
15
  } from '@luma.gl/api';
15
16
  import {Texture, cast, log, assert, isPowerOfTwo, loadImage} from '@luma.gl/api';
16
17
  import GL from '@luma.gl/constants';
17
- import type {WebGLSamplerParameters} from '../../types/webgl';
18
+ import type {GLSamplerParameters} from '../../types/webgl';
18
19
  import {withParameters} from '../../context/state-tracker/with-parameters';
19
20
  import {
20
21
  getWebGLTextureFormat,
@@ -31,22 +32,31 @@ import WEBGLSampler from './webgl-sampler';
31
32
 
32
33
  export type {TextureProps};
33
34
 
35
+ export type TextureSourceData =
36
+ TypedArray |
37
+ ImageData |
38
+ HTMLImageElement |
39
+ HTMLCanvasElement |
40
+ ImageBitmap |
41
+ HTMLVideoElement
42
+ ;
43
+
34
44
  type SetImageDataOptions = {
35
45
  target?: number;
36
46
  level?: number;
37
47
  dataFormat?: any;
38
- width: number;
39
- height: number;
48
+ width?: number;
49
+ height?: number;
40
50
  depth?: number;
41
- format: any;
51
+ format?: any;
42
52
  type?: any;
43
53
  offset?: number;
44
- data: any;
54
+ data: any; // TextureSourceData;
45
55
  compressed?: boolean;
46
56
  parameters?: Record<GL, any>;
47
57
  /** @deprecated */
48
58
  pixels?: any;
49
- };
59
+ }
50
60
 
51
61
  /**
52
62
  * @param {*} pixels, data -
@@ -92,10 +102,10 @@ type SetSubImageDataOptions = {
92
102
  type SetImageData3DOptions = {
93
103
  level?: number;
94
104
  dataFormat?: any;
95
- width: number;
96
- height: number;
105
+ width?: number;
106
+ height?: number;
97
107
  depth?: number;
98
- format: any;
108
+ format?: any;
99
109
  type?: any;
100
110
  offset?: number;
101
111
  data: any;
@@ -189,8 +199,8 @@ export default class WEBGLTexture extends Texture {
189
199
  this.gl.deleteTexture(this.handle);
190
200
  this.removeStats();
191
201
  this.trackDeallocatedMemory('Texture');
192
- // @ts-expect-error
193
- this.handle = null;
202
+ // this.handle = null;
203
+ this.destroyed = true;
194
204
  }
195
205
  }
196
206
 
@@ -714,7 +724,7 @@ export default class WEBGLTexture extends Texture {
714
724
 
715
725
  // HELPER METHODS
716
726
 
717
- _deduceParameters(opts) {
727
+ _deduceParameters(opts: TextureProps) {
718
728
  const {format, data} = opts;
719
729
  let {width, height, dataFormat, type, compressed} = opts;
720
730
 
@@ -857,18 +867,20 @@ export default class WEBGLTexture extends Texture {
857
867
  }
858
868
 
859
869
  /** Image 3D copies from Typed Array or WebGLBuffer */
860
- setImageData3D({
861
- level = 0,
862
- dataFormat,
863
- format,
864
- type, // = GL.UNSIGNED_BYTE,
865
- width,
866
- height,
867
- depth = 1,
868
- offset = 0,
869
- data,
870
- parameters = {} as Record<GL, any> as Record<GL, any>
871
- }: SetImageData3DOptions) {
870
+ setImageData3D(options: SetImageData3DOptions) {
871
+ const {
872
+ level = 0,
873
+ dataFormat,
874
+ format,
875
+ type, // = GL.UNSIGNED_BYTE,
876
+ width,
877
+ height,
878
+ depth = 1,
879
+ offset = 0,
880
+ data,
881
+ parameters = {}
882
+ } = options;
883
+
872
884
  this.trackDeallocatedMemory('Texture');
873
885
 
874
886
  this.gl.bindTexture(this.target, this.handle);
@@ -928,7 +940,7 @@ export default class WEBGLTexture extends Texture {
928
940
  * Sets sampler parameters on texture
929
941
  * @note: Applies NPOT workaround if appropriate
930
942
  */
931
- _setSamplerParameters(parameters: WebGLSamplerParameters) {
943
+ _setSamplerParameters(parameters: GLSamplerParameters) {
932
944
  // Work around WebGL1 sampling restrictions on NPOT textures
933
945
  if (this.device.isWebGL1 && isNPOT(this.width, this.height)) {
934
946
  parameters = updateSamplerParametersForNPOT(parameters);
@@ -12,7 +12,7 @@ import WEBGLFramebuffer from './resources/webgl-framebuffer';
12
12
  export default class WebGLCanvasContext extends CanvasContext {
13
13
  readonly device: WebGLDevice;
14
14
  presentationSize: [number, number];
15
- private _framebuffer: WEBGLFramebuffer;
15
+ private _framebuffer: WEBGLFramebuffer | null = null;
16
16
 
17
17
  constructor(device: WebGLDevice, props: CanvasContextProps) {
18
18
  // Note: Base class creates / looks up the canvas (unless under Node.js)
@@ -12,7 +12,8 @@ import {isBrowser} from '@probe.gl/env';
12
12
  import {polyfillContext} from '../context/polyfill/polyfill-context';
13
13
  import {trackContextState} from '../context/state-tracker/track-context-state';
14
14
  import {ContextState} from '../context/context/context-state';
15
- import {createBrowserContext} from '../context/context/create-context';
15
+ import {createBrowserContext} from '../context/context/create-browser-context';
16
+ import {createHeadlessContext, isHeadlessGLRegistered} from '../context/context/create-headless-context';
16
17
  import {getDeviceInfo} from './device-helpers/get-device-info';
17
18
  import {getDeviceFeatures} from './device-helpers/device-features';
18
19
  import {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';
@@ -65,7 +66,7 @@ export default class WebGLDevice extends Device implements ContextState {
65
66
  static type: string = 'webgl';
66
67
 
67
68
  static isSupported(): boolean {
68
- return typeof WebGLRenderingContext !== 'undefined';
69
+ return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();
69
70
  }
70
71
 
71
72
  readonly info: DeviceInfo;
@@ -171,7 +172,11 @@ export default class WebGLDevice extends Device implements ContextState {
171
172
  // Create and instrument context
172
173
  this.canvasContext = new WebGLCanvasContext(this, props);
173
174
 
174
- this.handle = props.gl || createBrowserContext(this.canvasContext.canvas, props);
175
+ let gl = props.gl;
176
+ gl = gl || (isBrowser() && createBrowserContext(this.canvasContext.canvas, props));
177
+ gl = gl || (!isBrowser() && createHeadlessContext(props));
178
+
179
+ this.handle = gl;
175
180
  this.gl = this.handle;
176
181
  this.gl2 = this.gl as WebGL2RenderingContext;
177
182
  this.isWebGL2 = isWebGL2(this.gl);
@@ -187,8 +192,15 @@ export default class WebGLDevice extends Device implements ContextState {
187
192
 
188
193
  // Add subset of WebGL2 methods to WebGL1 context
189
194
  polyfillContext(this.gl);
195
+
190
196
  // Install context state tracking
191
- trackContextState(this.gl, {copyState: false, log: (...args: any[]) => log.log(1, ...args)()});
197
+ // @ts-expect-error - hidden parameters
198
+ const {enable = true, copyState = false} = props;
199
+ trackContextState(this.gl, {
200
+ enable,
201
+ copyState,
202
+ log: (...args: any[]) => log.log(1, ...args)()
203
+ });
192
204
 
193
205
  // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
194
206
  if (isBrowser() && props.debug) {
@@ -111,8 +111,8 @@ export default class ClassicBuffer extends WEBGLBuffer {
111
111
  this.removeStats();
112
112
  this.trackDeallocatedMemory();
113
113
  this.gl.deleteBuffer(this.handle);
114
- // @ts-expect-error
115
- this.handle = null;
114
+ // this.handle = null;
115
+ this.destroyed = true;
116
116
  }
117
117
  }
118
118
 
@@ -264,7 +264,7 @@ export default class ClassicBuffer extends WEBGLBuffer {
264
264
  // Use GL.COPY_READ_BUFFER+GL.COPY_WRITE_BUFFER avoid disturbing other targets and locking type
265
265
  gl.bindBuffer(GL.COPY_READ_BUFFER, sourceBuffer.handle);
266
266
  gl.bindBuffer(GL.COPY_WRITE_BUFFER, this.handle);
267
- gl2.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
267
+ gl2?.copyBufferSubData(GL.COPY_READ_BUFFER, GL.COPY_WRITE_BUFFER, readOffset, writeOffset, size);
268
268
  gl.bindBuffer(GL.COPY_READ_BUFFER, null);
269
269
  gl.bindBuffer(GL.COPY_WRITE_BUFFER, null);
270
270
 
@@ -314,7 +314,7 @@ export default class ClassicBuffer extends WEBGLBuffer {
314
314
 
315
315
  // Use GL.COPY_READ_BUFFER to avoid disturbing other targets and locking type
316
316
  this.gl.bindBuffer(GL.COPY_READ_BUFFER, this.handle);
317
- this.gl2.getBufferSubData(GL.COPY_READ_BUFFER, srcByteOffset, dstData, dstOffset, length);
317
+ this.gl2?.getBufferSubData(GL.COPY_READ_BUFFER, srcByteOffset, dstData, dstOffset, length);
318
318
  this.gl.bindBuffer(GL.COPY_READ_BUFFER, null);
319
319
 
320
320
  // TODO - update local `data` if offsets are 0
@@ -340,10 +340,10 @@ export default class ClassicBuffer extends WEBGLBuffer {
340
340
  // uniform buffer state. Instead indexed bindings need to be made.
341
341
  if (target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER) {
342
342
  if (size !== undefined) {
343
- this.gl2.bindBufferRange(target, index, this.handle, offset, size);
343
+ this.gl2?.bindBufferRange(target, index, this.handle, offset, size);
344
344
  } else {
345
345
  assert(offset === 0); // Make sure offset wasn't supplied
346
- this.gl2.bindBufferBase(target, index, this.handle);
346
+ this.gl2?.bindBufferBase(target, index, this.handle);
347
347
  }
348
348
  } else {
349
349
  this.gl.bindBuffer(target, this.handle);
@@ -356,7 +356,7 @@ export default class ClassicBuffer extends WEBGLBuffer {
356
356
  const {target = this.target, index = this.accessor && this.accessor.index} = options || {};
357
357
  const isIndexedBuffer = target === GL.UNIFORM_BUFFER || target === GL.TRANSFORM_FEEDBACK_BUFFER;
358
358
  if (isIndexedBuffer) {
359
- this.gl2.bindBufferBase(target, index, null);
359
+ this.gl2?.bindBufferBase(target, index, null);
360
360
  } else {
361
361
  this.gl.bindBuffer(target, null);
362
362
  }
@@ -1,4 +1,6 @@
1
- import {TypedArray} from '@luma.gl/api/types';
1
+ // luma.gl, MIT license
2
+
3
+ import {TypedArray} from '@luma.gl/api';
2
4
  import GL from '@luma.gl/constants';
3
5
  import {GLType} from '../types/webgl'
4
6
 
@@ -55,7 +55,7 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
55
55
  canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
56
56
 
57
57
  // Create the desired context
58
- let gl = null;
58
+ let gl: WebGLRenderingContext | null = null;
59
59
 
60
60
  if (props.type === 'webgl2') {
61
61
  props = {...props, webgl1: false};
@@ -66,10 +66,10 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
66
66
 
67
67
  // Prefer webgl2 over webgl1 if both are acceptable
68
68
  if (props.webgl2) {
69
- gl = gl || canvas.getContext('webgl2', props);
69
+ gl = gl || canvas.getContext('webgl2', props) as WebGL2RenderingContext | null;
70
70
  }
71
71
  if (props.webgl1) {
72
- gl = gl || canvas.getContext('webgl', props);
72
+ gl = gl || canvas.getContext('webgl', props) as WebGLRenderingContext | null;
73
73
  }
74
74
 
75
75
  // TODO are we removing this listener before giving it a chance to fire?
@@ -83,8 +83,12 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
83
83
  );
84
84
  }
85
85
 
86
- canvas.addEventListener('webglcontextlost', props.onContextLost, false);
87
- canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);
86
+ if (props.onContextLost) {
87
+ canvas.addEventListener('webglcontextlost', props.onContextLost, false);
88
+ }
89
+ if (props.onContextRestored) {
90
+ canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);
91
+ }
88
92
 
89
93
  return gl;
90
94
  }
@@ -0,0 +1,48 @@
1
+ const ERR_HEADLESSGL_FAILED =
2
+ 'Failed to create WebGL context in Node.js, headless gl returned null';
3
+
4
+ const ERR_HEADLESSGL_LOAD = `\
5
+ luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
6
+ contexts can not be created. This may not be an error. For example, this is a \
7
+ typical configuration for isorender applications running on the server.`;
8
+
9
+ const CONTEXT_DEFAULTS = {
10
+ width: 1,
11
+ height: 1,
12
+ debug: true,
13
+ throwOnError: false
14
+ };
15
+
16
+ /** Duck typing for the main headless gl export, a function to create contexts */
17
+ export type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;
18
+
19
+ let headlessGL: HeadlessGL | null = null;
20
+
21
+ /** By importing `gl` and registering it with this function, contexts can be created under Node.js */
22
+ export function registerHeadlessGL(headlessgl: HeadlessGL) {
23
+ headlessGL = headlessgl;
24
+ }
25
+
26
+ /** @returns true if headless gl is registered */
27
+ export function isHeadlessGLRegistered(): boolean {
28
+ return headlessGL !== null;
29
+ }
30
+
31
+ /** Create headless gl context (for running under Node.js) */
32
+ export function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext {
33
+ options = {...CONTEXT_DEFAULTS, ...options};
34
+
35
+ const {width, height, webgl1, webgl2} = options;
36
+
37
+ if (webgl2 && !webgl1) {
38
+ throw new Error('headless-gl does not support WebGL2');
39
+ }
40
+ if (!headlessGL) {
41
+ throw new Error(ERR_HEADLESSGL_LOAD);
42
+ }
43
+ const gl = headlessGL(width, height, options);
44
+ if (!gl) {
45
+ throw new Error(ERR_HEADLESSGL_FAILED);
46
+ }
47
+ return gl;
48
+ }
@@ -53,16 +53,22 @@ export function cssToDeviceRatio(gl: WebGLRenderingContext): number {
53
53
 
54
54
  // use devicePixelRatio to set canvas width and height
55
55
  export function setDevicePixelRatio(gl: WebGLRenderingContext, devicePixelRatio: number, options: {width?: number, height?: number} = {}) {
56
+ if (!(gl.canvas instanceof HTMLCanvasElement)) {
57
+ return;
58
+ }
59
+
60
+ const canvas: HTMLCanvasElement = gl.canvas;
61
+
56
62
  // NOTE: if options.width and options.height not used remove in v8
57
- let clientWidth = 'width' in options ? options.width : gl.canvas.clientWidth;
58
- let clientHeight = 'height' in options ? options.height : gl.canvas.clientHeight;
63
+ let clientWidth = 'width' in options ? options.width : canvas.clientWidth;
64
+ let clientHeight = 'height' in options ? options.height : canvas.clientHeight;
59
65
 
60
66
  if (!clientWidth || !clientHeight) {
61
67
  log.log(1, 'Canvas clientWidth/clientHeight is 0')();
62
- // by forcing devicePixel ratio to 1, we do not scale gl.canvas.width and height in each frame.
68
+ // by forcing devicePixel ratio to 1, we do not scale canvas.width and height in each frame.
63
69
  devicePixelRatio = 1;
64
- clientWidth = gl.canvas.width || 1;
65
- clientHeight = gl.canvas.height || 1;
70
+ clientWidth = canvas.width || 1;
71
+ clientHeight = canvas.height || 1;
66
72
  }
67
73
 
68
74
  const contextState = getContextState(gl);
@@ -77,8 +83,8 @@ export function setDevicePixelRatio(gl: WebGLRenderingContext, devicePixelRatio:
77
83
 
78
84
  const canvasWidth = Math.floor(clientWidth * clampedPixelRatio);
79
85
  const canvasHeight = Math.floor(clientHeight * clampedPixelRatio);
80
- gl.canvas.width = canvasWidth;
81
- gl.canvas.height = canvasHeight;
86
+ canvas.width = canvasWidth;
87
+ canvas.height = canvasHeight;
82
88
 
83
89
  // Note: when devicePixelRatio is too high, it is possible we might hit system limit for
84
90
  // drawing buffer width and hight, in those cases they get clamped and resulting aspect ration may not be maintained
@@ -90,8 +96,8 @@ export function setDevicePixelRatio(gl: WebGLRenderingContext, devicePixelRatio:
90
96
  gl.drawingBufferHeight / clientHeight
91
97
  );
92
98
 
93
- gl.canvas.width = Math.floor(clientWidth * clampedPixelRatio);
94
- gl.canvas.height = Math.floor(clientHeight * clampedPixelRatio);
99
+ canvas.width = Math.floor(clientWidth * clampedPixelRatio);
100
+ canvas.height = Math.floor(clientHeight * clampedPixelRatio);
95
101
  }
96
102
 
97
103
  Object.assign(contextState._canvasSizeInfo, {clientWidth, clientHeight, devicePixelRatio});
@@ -32,7 +32,7 @@ export async function loadSpectorJS(props?: SpectorProps) {
32
32
  try {
33
33
  await loadScript(SPECTOR_CDN_URL);
34
34
  } catch(error) {
35
- log.warn(error)
35
+ log.warn(String(error))
36
36
  }
37
37
  }
38
38
  }
@@ -14,7 +14,7 @@ type DebugContextProps = {
14
14
  const DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {
15
15
  debug: true,
16
16
  throwOnError: false,
17
- break: undefined,
17
+ break: [],
18
18
  webgl2: false,
19
19
  }
20
20
 
@@ -21,7 +21,10 @@ export type {GLParameters};
21
21
  * @note requires a `cache` object to be set on the context (gl.state.cache)
22
22
  * This object is used to fill in any missing values for composite setter functions
23
23
  */
24
- export function setParameters(device: Device | WebGLRenderingContext, parameters: GLParameters): void {
24
+ export function setParameters(
25
+ device: Device | WebGLRenderingContext,
26
+ parameters: GLParameters
27
+ ): void {
25
28
  const webglDevice = WebGLDevice.attach(device);
26
29
  const gl = webglDevice.gl;
27
30
 
@@ -74,7 +77,10 @@ export function setParameters(device: Device | WebGLRenderingContext, parameters
74
77
 
75
78
  /**
76
79
  * Reads the entire WebGL state from a context
77
- * @returns - a newly created map, with values keyed by GL parameters
80
+
81
+ // default to querying all parameters
82
+
83
+ * @returns - a newly created map, with values keyed by GL parameters
78
84
  *
79
85
  * @note Copies the state from a context (gl.getParameter should not be overriden)
80
86
  * Reads the entire WebGL state from a context
@@ -83,13 +89,10 @@ export function setParameters(device: Device | WebGLRenderingContext, parameters
83
89
  * considered a very slow operation, to be used only if/when a context already manipulated
84
90
  * by external code needs to be synchronized for the first time
85
91
  */
86
- export function getParameters(gl: WebGLRenderingContext, parameters?: Record<keyof GLParameters, any>): GLParameters;
87
- export function getParameters(gl: WebGLRenderingContext, parameters?: (keyof GLParameters)[]): GLParameters;
88
- export function getParameters(gl: WebGLRenderingContext, parameters: keyof GLParameters): GLParameters;
89
-
90
- export function getParameters(gl, parameters) {
91
- // default to querying all parameters
92
- parameters = parameters || GL_PARAMETER_DEFAULTS;
92
+ export function getParameters(
93
+ gl: WebGLRenderingContext,
94
+ parameters: keyof GLParameters | (keyof GLParameters)[] | GLParameters = GL_PARAMETER_DEFAULTS
95
+ ): GLParameters {
93
96
  // support both arrays of parameters and objects (keys represent parameters)
94
97
 
95
98
  if (typeof parameters === 'number') {
@@ -65,7 +65,7 @@ function polyfillExtension(gl: WebGLRenderingContext, {extension, target, target
65
65
  for (const key of Object.keys(defaults)) {
66
66
  const extKey = `${key}${suffix}`;
67
67
 
68
- let polyfill = null;
68
+ let polyfill: Function | null = null;
69
69
  if (key === 'meta') {
70
70
  // ignore
71
71
  } else if (typeof gl[key] === 'function') {
@@ -81,7 +81,7 @@ export const WEBGL2_CONTEXT_POLYFILLS = {
81
81
  getQueryParameter(handle, pname) {
82
82
  return this.getQueryObject(handle, pname);
83
83
  },
84
- getQueryObject: () => {}
84
+ getQueryObject: (handle: unknown, pname: unknown) => {}
85
85
  }
86
86
  };
87
87
 
@@ -54,7 +54,7 @@ class GLState {
54
54
  let valueChanged = false;
55
55
  let oldValue; // = undefined
56
56
 
57
- const oldValues: {[key: number | string]: any} = this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1];
57
+ const oldValues: {[key: number | string]: any} | null = this.stateStack.length > 0 ? this.stateStack[this.stateStack.length - 1] : null;
58
58
 
59
59
  for (const key in values) {
60
60
  assert(key !== undefined);
package/src/index.ts CHANGED
@@ -8,13 +8,16 @@
8
8
  import '@luma.gl/api';
9
9
  import './init'
10
10
 
11
+ // Types
12
+ export type {WebGLLimits} from './adapter/device-helpers/device-limits';
13
+
14
+ export {registerHeadlessGL} from './context/context/create-headless-context';
15
+
16
+ // WebGL adapter classes
11
17
  export {default as WebGLDevice} from './adapter/webgl-device';
12
18
  export {default as WebGLCanvasContext} from './adapter/webgl-canvas-context';
13
19
 
14
- // Legacy WebGL Classes - will be moved to gltools
15
- export {default as Accessor} from './classic/accessor';
16
- export type {ClassicBufferProps as BufferProps} from './classic/buffer';
17
- export {default as Buffer} from './classic/buffer';
20
+ // WebGL Resource classes
18
21
  export {default as WEBGLResource, default as WebGLResource} from './adapter/objects/webgl-resource';
19
22
  export {default as WEBGLBuffer} from './adapter/resources/webgl-buffer';
20
23
  export {default as WEBGLTexture} from './adapter/resources/webgl-texture';
@@ -24,16 +27,21 @@ export {default as WEBGLSampler} from './adapter/resources/webgl-sampler';
24
27
  export {default as WEBGLFramebuffer} from './adapter/resources/webgl-framebuffer';
25
28
 
26
29
  export {default as WEBGLRenderPipeline} from './adapter/resources/webgl-render-pipeline';
27
-
28
30
  // export {default as WEBGLComputePipeline} from './adapter/resources/webgl-compute-pipeline';
29
31
  export {default as WEBGLCommandEncoder} from './adapter/resources/webgl-command-encoder';
30
32
  export {default as WEBGLRenderPass} from './adapter/resources/webgl-render-pass';
31
33
  //export {default as WEBGLComputePass} from './adapter/resources/webgl-compute-pass';
32
34
 
35
+ // non-api resources
33
36
  export type {RenderbufferProps} from './adapter/objects/webgl-renderbuffer';
34
37
  export {default as WEBGLRenderbuffer} from './adapter/objects/webgl-renderbuffer';
35
38
  export {default as WEBGLVertexArrayObject} from './adapter/objects/webgl-vertex-array-object';
36
39
 
40
+ // WebGL adapter classes (Legacy, will be moved to gltools)
41
+ export {default as Accessor} from './classic/accessor';
42
+ export type {ClassicBufferProps, ClassicBufferProps as BufferProps} from './classic/buffer';
43
+ export {default as ClassicBuffer, default as Buffer} from './classic/buffer';
44
+
37
45
  export {
38
46
  isWebGL,
39
47
  isWebGL2,
@@ -120,7 +120,7 @@ export type GLStencilOp =
120
120
  | GL.INVERT;
121
121
 
122
122
  /** Parameters for textures and samplers */
123
- export type WebGLSamplerParameters = {
123
+ export type GLSamplerParameters = {
124
124
  [GL.TEXTURE_WRAP_S]?: GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT;
125
125
  [GL.TEXTURE_WRAP_T]?: GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT;
126
126
  [GL.TEXTURE_WRAP_R]?: GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT;
@@ -241,7 +241,7 @@ export type GLFunctionParameters = {
241
241
  clearDepth?: number;
242
242
  clearStencil?: number;
243
243
 
244
- colorMask?: [boolean, boolean, boolean, boolean];
244
+ colorMask?: [boolean, boolean, boolean, boolean] | boolean[];
245
245
 
246
246
  cull?: boolean;
247
247
  cullFace?: GL.FRONT | GL.BACK | GL.FRONT_AND_BACK;
@@ -281,4 +281,4 @@ export type GLFunctionParameters = {
281
281
  };
282
282
 
283
283
  /** WebGL style parameters object (with both GL constants and function style fields) */
284
- export type GLParameters = GLValueParameters | GLFunctionParameters;
284
+ export type GLParameters = GLValueParameters & GLFunctionParameters;
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-context.d.ts","sourceRoot":"","sources":["../../../src/context/context/create-context.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;EAgBE;AACF,aAAK,YAAY,GAAG;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACvC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,SAAS,GAAI,kBAAkB,GAAG,WAAW,CAAC;IAChE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAC;AAUF;;;;GAIG;AACF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAAE,KAAK,EAAE,YAAY,GAAG,qBAAqB,CAyC7H"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/context/context/create-context.ts"],"names":["DEFAULT_CONTEXT_PROPS","webgl2","webgl1","powerPreference","onContextLost","console","error","onContextRestored","info","createBrowserContext","canvas","props","errorMessage","onCreateError","statusMessage","addEventListener","gl","type","getContext","removeEventListener","Error"],"mappings":"AAmCA,MAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE,MAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAJqB;AAK1CC,EAAAA,iBAAiB,EAAE,MAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb;AALiB,CAA5C;AAaC,OAAO,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,GAAG,EAAC,GAAGX,qBAAJ;AAA2B,OAAGW;AAA9B,GAAR;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,QAAMC,aAAa,GAAIP,KAAD,IAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAxE;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;AAGA,MAAIG,EAAE,GAAG,IAAT;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWT,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWV,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAEDF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACAM,EAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AAEA,SAAOS,EAAP;AACD","sourcesContent":["// luma.gl, MIT license\n\n/**\n * ContextProps\n* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)\n* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)\n* @param onContextLost\n* @param onContextRestored\n*\n* BROWSER CONTEXT PARAMETERS\n* @param debug Instrument context (at the expense of performance).\n* @param alpha Default render target has an alpha buffer.\n* @param depth Default render target has a depth buffer of at least 16 bits.\n* @param stencil Default render target has a stencil buffer of at least 8 bits.\n* @param antialias Boolean that indicates whether or not to perform anti-aliasing.\n* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.\n*/\ntype ContextProps = {\n type?: 'webgl' | 'webgl1' | 'webgl2' | string;\n webgl1?: boolean;\n webgl2?: boolean;\n onContextLost?: (event: Event) => void;\n onContextRestored?: (event: Event) => void;\n alpha?: boolean; // indicates if the canvas contains an alpha buffer.\n desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop\n antialias?: boolean; // indicates whether or not to perform anti-aliasing.\n depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.\n failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.\n powerPreference?: 'default' | 'high-performance' | 'low-power',\n premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.\n};\n\nconst DEFAULT_CONTEXT_PROPS: ContextProps = {\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons\n onContextLost: () => console.error('WebGL context lost'),\n onContextRestored: () => console.info('WebGL context restored'),\n};\n\n/**\n * Create a WebGL context for a canvas\n * Note calling this multiple time on the same canvas does return the same context\n* @param canvas A canvas element or offscreen canvas\n */\n export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n // Create the desired context\n let gl = null;\n\n if (props.type === 'webgl2') {\n props = {...props, webgl1: false};\n }\n if (props.type === 'webgl1') {\n props = {...props, webgl2: false};\n }\n\n // Prefer webgl2 over webgl1 if both are acceptable\n if (props.webgl2) {\n gl = gl || canvas.getContext('webgl2', props);\n }\n if (props.webgl1) {\n gl = gl || canvas.getContext('webgl', props);\n }\n\n // TODO are we removing this listener before giving it a chance to fire?\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n if (!gl) {\n throw new Error(\n `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${\n errorMessage || 'Unknown error'\n }`\n );\n }\n\n canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);\n\n return gl;\n}\n\n/* TODO - can we call this asynchronously to catch the error events?\nexport async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n const gl = createBrowserContext(canvas, props);\n\n // Give the listener a chance to fire\n await new Promise(resolve => setTimeout(resolve, 0));\n\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n return gl;\n}\n*/\n"],"file":"create-context.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/context/context/create-context.ts"],"names":["DEFAULT_CONTEXT_PROPS","webgl2","webgl1","powerPreference","onContextLost","console","error","onContextRestored","info","createBrowserContext","canvas","props","errorMessage","onCreateError","statusMessage","addEventListener","gl","type","getContext","removeEventListener","Error"],"mappings":";;;;;;;;;;;;;;;AAmCA,IAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE;AAAA,WAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAAN;AAAA,GAJ2B;AAK1CC,EAAAA,iBAAiB,EAAE;AAAA,WAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb,CAAN;AAAA;AALuB,CAA5C;;AAaQ,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,mCAAOX,qBAAP,GAAiCW,KAAjC,CAAL;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,MAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACP,KAAD;AAAA,WAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAlD;AAAA,GAAtB;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;AAGA,MAAIG,EAAE,GAAG,IAAT;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,mCAAOA,KAAP;AAAcT,MAAAA,MAAM,EAAE;AAAtB,MAAL;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,mCAAOA,KAAP;AAAcV,MAAAA,MAAM,EAAE;AAAtB,MAAL;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAEDF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACAM,EAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AAEA,SAAOS,EAAP;AACD","sourcesContent":["// luma.gl, MIT license\n\n/**\n * ContextProps\n* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)\n* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)\n* @param onContextLost\n* @param onContextRestored\n*\n* BROWSER CONTEXT PARAMETERS\n* @param debug Instrument context (at the expense of performance).\n* @param alpha Default render target has an alpha buffer.\n* @param depth Default render target has a depth buffer of at least 16 bits.\n* @param stencil Default render target has a stencil buffer of at least 8 bits.\n* @param antialias Boolean that indicates whether or not to perform anti-aliasing.\n* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.\n*/\ntype ContextProps = {\n type?: 'webgl' | 'webgl1' | 'webgl2' | string;\n webgl1?: boolean;\n webgl2?: boolean;\n onContextLost?: (event: Event) => void;\n onContextRestored?: (event: Event) => void;\n alpha?: boolean; // indicates if the canvas contains an alpha buffer.\n desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop\n antialias?: boolean; // indicates whether or not to perform anti-aliasing.\n depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.\n failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.\n powerPreference?: 'default' | 'high-performance' | 'low-power',\n premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.\n};\n\nconst DEFAULT_CONTEXT_PROPS: ContextProps = {\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons\n onContextLost: () => console.error('WebGL context lost'),\n onContextRestored: () => console.info('WebGL context restored'),\n};\n\n/**\n * Create a WebGL context for a canvas\n * Note calling this multiple time on the same canvas does return the same context\n* @param canvas A canvas element or offscreen canvas\n */\n export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n // Create the desired context\n let gl = null;\n\n if (props.type === 'webgl2') {\n props = {...props, webgl1: false};\n }\n if (props.type === 'webgl1') {\n props = {...props, webgl2: false};\n }\n\n // Prefer webgl2 over webgl1 if both are acceptable\n if (props.webgl2) {\n gl = gl || canvas.getContext('webgl2', props);\n }\n if (props.webgl1) {\n gl = gl || canvas.getContext('webgl', props);\n }\n\n // TODO are we removing this listener before giving it a chance to fire?\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n if (!gl) {\n throw new Error(\n `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${\n errorMessage || 'Unknown error'\n }`\n );\n }\n\n canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);\n\n return gl;\n}\n\n/* TODO - can we call this asynchronously to catch the error events?\nexport async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n const gl = createBrowserContext(canvas, props);\n\n // Give the listener a chance to fire\n await new Promise(resolve => setTimeout(resolve, 0));\n\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n return gl;\n}\n*/\n"],"file":"create-context.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/context/context/create-context.ts"],"names":["DEFAULT_CONTEXT_PROPS","webgl2","webgl1","powerPreference","onContextLost","console","error","onContextRestored","info","createBrowserContext","canvas","props","errorMessage","onCreateError","statusMessage","addEventListener","gl","type","getContext","removeEventListener","Error"],"mappings":"AAmCA,MAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE,MAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAJqB;AAK1CC,EAAAA,iBAAiB,EAAE,MAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb;AALiB,CAA5C;AAaC,OAAO,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,GAAG,EAAC,GAAGX,qBAAJ;AAA2B,OAAGW;AAA9B,GAAR;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,QAAMC,aAAa,GAAIP,KAAD,IAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAxE;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;AAGA,MAAIG,EAAE,GAAG,IAAT;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWT,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWV,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAEDF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACAM,EAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AAEA,SAAOS,EAAP;AACD","sourcesContent":["// luma.gl, MIT license\n\n/**\n * ContextProps\n* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)\n* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)\n* @param onContextLost\n* @param onContextRestored\n*\n* BROWSER CONTEXT PARAMETERS\n* @param debug Instrument context (at the expense of performance).\n* @param alpha Default render target has an alpha buffer.\n* @param depth Default render target has a depth buffer of at least 16 bits.\n* @param stencil Default render target has a stencil buffer of at least 8 bits.\n* @param antialias Boolean that indicates whether or not to perform anti-aliasing.\n* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.\n*/\ntype ContextProps = {\n type?: 'webgl' | 'webgl1' | 'webgl2' | string;\n webgl1?: boolean;\n webgl2?: boolean;\n onContextLost?: (event: Event) => void;\n onContextRestored?: (event: Event) => void;\n alpha?: boolean; // indicates if the canvas contains an alpha buffer.\n desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop\n antialias?: boolean; // indicates whether or not to perform anti-aliasing.\n depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.\n failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.\n powerPreference?: 'default' | 'high-performance' | 'low-power',\n premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.\n};\n\nconst DEFAULT_CONTEXT_PROPS: ContextProps = {\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons\n onContextLost: () => console.error('WebGL context lost'),\n onContextRestored: () => console.info('WebGL context restored'),\n};\n\n/**\n * Create a WebGL context for a canvas\n * Note calling this multiple time on the same canvas does return the same context\n* @param canvas A canvas element or offscreen canvas\n */\n export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n // Create the desired context\n let gl = null;\n\n if (props.type === 'webgl2') {\n props = {...props, webgl1: false};\n }\n if (props.type === 'webgl1') {\n props = {...props, webgl2: false};\n }\n\n // Prefer webgl2 over webgl1 if both are acceptable\n if (props.webgl2) {\n gl = gl || canvas.getContext('webgl2', props);\n }\n if (props.webgl1) {\n gl = gl || canvas.getContext('webgl', props);\n }\n\n // TODO are we removing this listener before giving it a chance to fire?\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n if (!gl) {\n throw new Error(\n `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${\n errorMessage || 'Unknown error'\n }`\n );\n }\n\n canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);\n\n return gl;\n}\n\n/* TODO - can we call this asynchronously to catch the error events?\nexport async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n const gl = createBrowserContext(canvas, props);\n\n // Give the listener a chance to fire\n await new Promise(resolve => setTimeout(resolve, 0));\n\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n return gl;\n}\n*/\n"],"file":"create-context.js"}