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

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 (208) 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/classic/buffer.js +14 -6
  54. package/dist/classic/buffer.js.map +1 -1
  55. package/dist/context/context/create-context.d.ts.map +1 -1
  56. package/dist/context/context/create-context.js +8 -2
  57. package/dist/context/context/create-context.js.map +1 -1
  58. package/dist/context/context/device-pixels.d.ts.map +1 -1
  59. package/dist/context/context/device-pixels.js +13 -8
  60. package/dist/context/context/device-pixels.js.map +1 -1
  61. package/dist/context/debug/spector.js +1 -1
  62. package/dist/context/debug/spector.js.map +1 -1
  63. package/dist/context/debug/webgl-developer-tools.js +1 -1
  64. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  65. package/dist/context/parameters/unified-parameter-api.d.ts +5 -4
  66. package/dist/context/parameters/unified-parameter-api.d.ts.map +1 -1
  67. package/dist/context/parameters/unified-parameter-api.js +1 -3
  68. package/dist/context/parameters/unified-parameter-api.js.map +1 -1
  69. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  70. package/dist/context/polyfill/polyfill-table.d.ts +1 -1
  71. package/dist/context/polyfill/polyfill-table.d.ts.map +1 -1
  72. package/dist/context/polyfill/polyfill-table.js +1 -1
  73. package/dist/context/polyfill/polyfill-table.js.map +1 -1
  74. package/dist/context/state-tracker/track-context-state.js +1 -1
  75. package/dist/context/state-tracker/track-context-state.js.map +1 -1
  76. package/dist/es5/adapter/converters/device-parameters.js +17 -2
  77. package/dist/es5/adapter/converters/device-parameters.js.map +1 -1
  78. package/dist/es5/adapter/converters/sampler-parameters.js +21 -2
  79. package/dist/es5/adapter/converters/sampler-parameters.js.map +1 -1
  80. package/dist/es5/adapter/converters/texture-formats.js +3 -3
  81. package/dist/es5/adapter/converters/texture-formats.js.map +1 -1
  82. package/dist/es5/adapter/device-helpers/device-features.js +15 -4
  83. package/dist/es5/adapter/device-helpers/device-features.js.map +1 -1
  84. package/dist/es5/adapter/device-helpers/device-limits.js.map +1 -1
  85. package/dist/es5/adapter/helpers/get-shader-layout.js +48 -28
  86. package/dist/es5/adapter/helpers/get-shader-layout.js.map +1 -1
  87. package/dist/es5/adapter/helpers/uniforms.js +4 -4
  88. package/dist/es5/adapter/helpers/uniforms.js.map +1 -1
  89. package/dist/es5/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  90. package/dist/es5/adapter/resources/webgl-buffer.js +2 -2
  91. package/dist/es5/adapter/resources/webgl-buffer.js.map +1 -1
  92. package/dist/es5/adapter/resources/webgl-framebuffer.js +4 -3
  93. package/dist/es5/adapter/resources/webgl-framebuffer.js.map +1 -1
  94. package/dist/es5/adapter/resources/webgl-render-pass.js +1 -0
  95. package/dist/es5/adapter/resources/webgl-render-pass.js.map +1 -1
  96. package/dist/es5/adapter/resources/webgl-render-pipeline.js +43 -30
  97. package/dist/es5/adapter/resources/webgl-render-pipeline.js.map +1 -1
  98. package/dist/es5/adapter/resources/webgl-sampler.js.map +1 -1
  99. package/dist/es5/adapter/resources/webgl-shader.js +4 -3
  100. package/dist/es5/adapter/resources/webgl-shader.js.map +1 -1
  101. package/dist/es5/adapter/resources/webgl-texture.js +16 -16
  102. package/dist/es5/adapter/resources/webgl-texture.js.map +1 -1
  103. package/dist/es5/adapter/webgl-canvas-context.js +1 -1
  104. package/dist/es5/adapter/webgl-canvas-context.js.map +1 -1
  105. package/dist/es5/classic/buffer.js +14 -6
  106. package/dist/es5/classic/buffer.js.map +1 -1
  107. package/dist/es5/context/context/create-context.js +8 -2
  108. package/dist/es5/context/context/create-context.js.map +1 -1
  109. package/dist/es5/context/context/device-pixels.js +14 -8
  110. package/dist/es5/context/context/device-pixels.js.map +1 -1
  111. package/dist/es5/context/debug/spector.js +1 -1
  112. package/dist/es5/context/debug/spector.js.map +1 -1
  113. package/dist/es5/context/debug/webgl-developer-tools.js +1 -1
  114. package/dist/es5/context/debug/webgl-developer-tools.js.map +1 -1
  115. package/dist/es5/context/parameters/unified-parameter-api.js +2 -2
  116. package/dist/es5/context/parameters/unified-parameter-api.js.map +1 -1
  117. package/dist/es5/context/polyfill/polyfill-context.js.map +1 -1
  118. package/dist/es5/context/polyfill/polyfill-table.js +1 -1
  119. package/dist/es5/context/polyfill/polyfill-table.js.map +1 -1
  120. package/dist/es5/context/state-tracker/track-context-state.js +1 -1
  121. package/dist/es5/context/state-tracker/track-context-state.js.map +1 -1
  122. package/dist/es5/index.js +22 -16
  123. package/dist/es5/index.js.map +1 -1
  124. package/dist/es5/types/webgl.js.map +1 -1
  125. package/dist/esm/adapter/converters/device-parameters.js +15 -2
  126. package/dist/esm/adapter/converters/device-parameters.js.map +1 -1
  127. package/dist/esm/adapter/converters/sampler-parameters.js +21 -2
  128. package/dist/esm/adapter/converters/sampler-parameters.js.map +1 -1
  129. package/dist/esm/adapter/converters/texture-formats.js +3 -3
  130. package/dist/esm/adapter/converters/texture-formats.js.map +1 -1
  131. package/dist/esm/adapter/device-helpers/device-features.js +12 -2
  132. package/dist/esm/adapter/device-helpers/device-features.js.map +1 -1
  133. package/dist/esm/adapter/device-helpers/device-limits.js.map +1 -1
  134. package/dist/esm/adapter/helpers/get-shader-layout.js +40 -16
  135. package/dist/esm/adapter/helpers/get-shader-layout.js.map +1 -1
  136. package/dist/esm/adapter/helpers/uniforms.js +4 -4
  137. package/dist/esm/adapter/helpers/uniforms.js.map +1 -1
  138. package/dist/esm/adapter/objects/webgl-vertex-array-object.js.map +1 -1
  139. package/dist/esm/adapter/resources/webgl-buffer.js +2 -2
  140. package/dist/esm/adapter/resources/webgl-buffer.js.map +1 -1
  141. package/dist/esm/adapter/resources/webgl-framebuffer.js +5 -3
  142. package/dist/esm/adapter/resources/webgl-framebuffer.js.map +1 -1
  143. package/dist/esm/adapter/resources/webgl-render-pass.js +2 -0
  144. package/dist/esm/adapter/resources/webgl-render-pass.js.map +1 -1
  145. package/dist/esm/adapter/resources/webgl-render-pipeline.js +40 -24
  146. package/dist/esm/adapter/resources/webgl-render-pipeline.js.map +1 -1
  147. package/dist/esm/adapter/resources/webgl-sampler.js.map +1 -1
  148. package/dist/esm/adapter/resources/webgl-shader.js +4 -3
  149. package/dist/esm/adapter/resources/webgl-shader.js.map +1 -1
  150. package/dist/esm/adapter/resources/webgl-texture.js +14 -13
  151. package/dist/esm/adapter/resources/webgl-texture.js.map +1 -1
  152. package/dist/esm/adapter/webgl-canvas-context.js +1 -1
  153. package/dist/esm/adapter/webgl-canvas-context.js.map +1 -1
  154. package/dist/esm/classic/buffer.js +14 -6
  155. package/dist/esm/classic/buffer.js.map +1 -1
  156. package/dist/esm/context/context/create-context.js +8 -2
  157. package/dist/esm/context/context/create-context.js.map +1 -1
  158. package/dist/esm/context/context/device-pixels.js +13 -8
  159. package/dist/esm/context/context/device-pixels.js.map +1 -1
  160. package/dist/esm/context/debug/spector.js +1 -1
  161. package/dist/esm/context/debug/spector.js.map +1 -1
  162. package/dist/esm/context/debug/webgl-developer-tools.js +1 -1
  163. package/dist/esm/context/debug/webgl-developer-tools.js.map +1 -1
  164. package/dist/esm/context/parameters/unified-parameter-api.js +1 -3
  165. package/dist/esm/context/parameters/unified-parameter-api.js.map +1 -1
  166. package/dist/esm/context/polyfill/polyfill-context.js.map +1 -1
  167. package/dist/esm/context/polyfill/polyfill-table.js +1 -1
  168. package/dist/esm/context/polyfill/polyfill-table.js.map +1 -1
  169. package/dist/esm/context/state-tracker/track-context-state.js +1 -1
  170. package/dist/esm/context/state-tracker/track-context-state.js.map +1 -1
  171. package/dist/esm/index.js +2 -2
  172. package/dist/esm/index.js.map +1 -1
  173. package/dist/esm/types/webgl.js.map +1 -1
  174. package/dist/index.d.ts +4 -3
  175. package/dist/index.d.ts.map +1 -1
  176. package/dist/index.js +2 -2
  177. package/dist/index.js.map +1 -1
  178. package/dist/types/webgl.d.ts +2 -2
  179. package/dist/types/webgl.d.ts.map +1 -1
  180. package/dist/types/webgl.js.map +1 -1
  181. package/package.json +7 -4
  182. package/src/adapter/converters/device-parameters.ts +28 -2
  183. package/src/adapter/converters/sampler-parameters.ts +16 -7
  184. package/src/adapter/converters/texture-formats.ts +3 -3
  185. package/src/adapter/device-helpers/device-features.ts +9 -1
  186. package/src/adapter/device-helpers/device-limits.ts +1 -1
  187. package/src/adapter/helpers/get-shader-layout.ts +40 -21
  188. package/src/adapter/helpers/uniforms.ts +21 -10
  189. package/src/adapter/objects/webgl-vertex-array-object.ts +1 -1
  190. package/src/adapter/resources/webgl-buffer.ts +3 -3
  191. package/src/adapter/resources/webgl-framebuffer.ts +6 -3
  192. package/src/adapter/resources/webgl-render-pass.ts +1 -0
  193. package/src/adapter/resources/webgl-render-pipeline.ts +43 -35
  194. package/src/adapter/resources/webgl-sampler.ts +5 -3
  195. package/src/adapter/resources/webgl-shader.ts +5 -4
  196. package/src/adapter/resources/webgl-texture.ts +37 -25
  197. package/src/adapter/webgl-canvas-context.ts +1 -1
  198. package/src/classic/buffer.ts +7 -7
  199. package/src/context/context/create-context.ts +9 -5
  200. package/src/context/context/device-pixels.ts +15 -9
  201. package/src/context/debug/spector.ts +1 -1
  202. package/src/context/debug/webgl-developer-tools.ts +1 -1
  203. package/src/context/parameters/unified-parameter-api.ts +12 -9
  204. package/src/context/polyfill/polyfill-context.ts +1 -1
  205. package/src/context/polyfill/polyfill-table.ts +1 -1
  206. package/src/context/state-tracker/track-context-state.ts +1 -1
  207. package/src/index.ts +11 -5
  208. package/src/types/webgl.ts +2 -2
@@ -1,6 +1,6 @@
1
1
  import {UniformFormat, VertexFormat} from '@luma.gl/api';
2
2
  import GL from '@luma.gl/constants';
3
- import {GLUniformType, GLSamplerType, GLCompositeType, GLType} from '../../types/webgl'
3
+ import {GLUniformType, GLSamplerType, GLCompositeType, GLType} from '../../types/webgl';
4
4
 
5
5
  /** Check is uniform is of sampler type */
6
6
  export function isSamplerUniform(type: GLUniformType): boolean {
@@ -25,8 +25,11 @@ const SAMPLER_TYPES: GLSamplerType[] = [
25
25
  GL.UNSIGNED_INT_SAMPLER_2D_ARRAY
26
26
  ];
27
27
 
28
- // Composite types table
29
- const COMPOSITE_GL_TYPES: Record<GLCompositeType, [GLType, number, string, UniformFormat, VertexFormat?]> = {
28
+ // Composite types table
29
+ const COMPOSITE_GL_TYPES: Record<
30
+ GLCompositeType,
31
+ [GLType, number, string, UniformFormat, VertexFormat?]
32
+ > = {
30
33
  [GL.FLOAT]: [GL.FLOAT, 1, 'float', 'f32', 'float32'],
31
34
  [GL.FLOAT_VEC2]: [GL.FLOAT, 2, 'vec2', 'vec2<f32>', 'float32x2'],
32
35
  [GL.FLOAT_VEC3]: [GL.FLOAT, 3, 'vec3', 'vec3<f32>', 'float32x3'],
@@ -61,26 +64,34 @@ const COMPOSITE_GL_TYPES: Record<GLCompositeType, [GLType, number, string, Unifo
61
64
  };
62
65
 
63
66
  /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
64
- export function decodeUniformType(uniformType: GL): {format: UniformFormat, components: number, glType: GLType} {
67
+ export function decodeUniformType(
68
+ uniformType: GL
69
+ ): {format: UniformFormat; components: number; glType: GLType} {
65
70
  const typeAndSize = COMPOSITE_GL_TYPES[uniformType];
66
71
  if (!typeAndSize) {
67
- return null;
72
+ throw new Error('uniform');
68
73
  }
69
74
  const [glType, components, , format] = typeAndSize;
70
75
  return {format, components, glType};
71
76
  }
72
77
 
73
- export function decodeAttributeType(uniformType: GL): {format: VertexFormat, components: number, glType: GLType} {
74
- const typeAndSize = COMPOSITE_GL_TYPES[uniformType];
78
+ export function decodeAttributeType(attributeType: GL): {
79
+ format: VertexFormat;
80
+ components: number;
81
+ glType: GLType;
82
+ } {
83
+ const typeAndSize = COMPOSITE_GL_TYPES[attributeType];
75
84
  if (!typeAndSize) {
76
- return null;
85
+ throw new Error('attribute')
77
86
  }
78
87
  const [glType, components, , , format] = typeAndSize;
79
88
  return {format, components, glType};
80
89
  }
81
90
 
82
91
  /** Decomposes a composite type GL.VEC3 into a basic type (GL.FLOAT) and components (3) */
83
- export function decomposeCompositeGLType(compositeGLType: GLCompositeType): {type: GLType, components: number} | null {
92
+ export function decomposeCompositeGLType(
93
+ compositeGLType: GLCompositeType
94
+ ): {type: GLType; components: number} | null {
84
95
  const typeAndSize = COMPOSITE_GL_TYPES[compositeGLType];
85
96
  if (!typeAndSize) {
86
97
  return null;
@@ -89,7 +100,7 @@ export function decomposeCompositeGLType(compositeGLType: GLCompositeType): {typ
89
100
  return {type, components};
90
101
  }
91
102
 
92
- export function getCompositeGLType(type: GL, components): {glType: GLType, name: string} | null {
103
+ export function getCompositeGLType(type: GL, components): {glType: GLType; name: string} | null {
93
104
  switch (type) {
94
105
  case GL.BYTE:
95
106
  case GL.UNSIGNED_BYTE:
@@ -43,7 +43,7 @@ export default class WEBGLVertexArrayObject extends WebGLResource<VertexArrayObj
43
43
 
44
44
  // Set (bind) an elements buffer, for indexed rendering.
45
45
  // Must be a Buffer bound to GL.ELEMENT_ARRAY_BUFFER. Constants not supported
46
- setElementBuffer(elementBuffer: Buffer = null, opts = {}) {
46
+ setElementBuffer(elementBuffer: Buffer | null = null, opts = {}) {
47
47
  assert(!elementBuffer || elementBuffer.target === GL.ELEMENT_ARRAY_BUFFER, ERR_ELEMENTS);
48
48
 
49
49
  // The GL.ELEMENT_ARRAY_BUFFER_BINDING is stored on the VertexArrayObject...
@@ -15,7 +15,7 @@ export default class WEBGLBuffer extends Buffer {
15
15
 
16
16
  byteLength: number;
17
17
  bytesUsed: number;
18
- debugData: ArrayBuffer;
18
+ debugData: ArrayBuffer | null = null;
19
19
 
20
20
  webglUsage: number;
21
21
 
@@ -106,8 +106,8 @@ export default class WEBGLBuffer extends Buffer {
106
106
  this.removeStats();
107
107
  this.trackDeallocatedMemory();
108
108
  this.gl.deleteBuffer(this.handle);
109
- // @ts-expect-error
110
- this.handle = null;
109
+ // this.handle = null;
110
+ this.destroyed = true;
111
111
  }
112
112
  }
113
113
 
@@ -1,3 +1,5 @@
1
+ // luma.gl, MIT license
2
+
1
3
  import type {FramebufferProps, DepthStencilTextureFormat, ColorTextureFormat} from '@luma.gl/api';
2
4
  import {Framebuffer, Texture, log, assert} from '@luma.gl/api';
3
5
  import GL from '@luma.gl/constants';
@@ -17,7 +19,7 @@ export default class WEBGLFramebuffer extends Framebuffer {
17
19
 
18
20
  get texture() { return this.colorAttachments[0]; }
19
21
  readonly colorAttachments: WebGLTexture[] = [];
20
- readonly depthStencilAttachment: WebGLTexture | undefined = undefined;
22
+ readonly depthStencilAttachment: WebGLTexture | null = null; d
21
23
  protected _ownResources: (WebGLTexture | Renderbuffer)[] = [];
22
24
 
23
25
  constructor(device: WebGLDevice, props: FramebufferProps) {
@@ -66,7 +68,8 @@ export default class WEBGLFramebuffer extends Framebuffer {
66
68
  resource.destroy();
67
69
  }
68
70
  this.gl.deleteFramebuffer(this.handle);
69
- this.handle = null;
71
+ // this.handle = null;
72
+ this.destroyed = true;
70
73
  }
71
74
  }
72
75
 
@@ -224,7 +227,7 @@ export default class WEBGLFramebuffer extends Framebuffer {
224
227
  case GL.TEXTURE_2D_ARRAY:
225
228
  case GL.TEXTURE_3D:
226
229
  this.device.assertWebGL2();
227
- gl2.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
230
+ gl2?.framebufferTextureLayer(GL.FRAMEBUFFER, attachment, texture.target, level, layer);
228
231
  break;
229
232
 
230
233
  case GL.TEXTURE_CUBE_MAP:
@@ -6,6 +6,7 @@ export default class WEBGLRenderPass extends RenderPass {
6
6
 
7
7
  constructor(device: WebGLDevice, props: RenderPassProps) {
8
8
  super(device, props);
9
+ this.device = device;
9
10
  }
10
11
 
11
12
  endPass(): void {}
@@ -1,6 +1,5 @@
1
1
  import type {
2
2
  RenderPipelineProps,
3
- RenderPipelineParameters,
4
3
  RenderPass,
5
4
  Buffer,
6
5
  Binding,
@@ -11,9 +10,11 @@ import type {
11
10
  } from '@luma.gl/api';
12
11
  import {RenderPipeline, cast, log, decodeVertexFormat} from '@luma.gl/api';
13
12
  import GL from '@luma.gl/constants';
13
+
14
+ import type {GLParameters} from '../../types/webgl';
14
15
  import {getWebGLDataType} from '../converters/texture-formats';
15
16
  import {getShaderLayout} from '../helpers/get-shader-layout';
16
- import {withDeviceParameters} from '../converters/device-parameters';
17
+ import {withDeviceParameters, withGLParameters} from '../converters/device-parameters';
17
18
  import {setUniform} from '../helpers/set-uniform';
18
19
  // import {copyUniform, checkUniformValues} from '../../classes/uniforms';
19
20
 
@@ -35,7 +36,7 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
35
36
 
36
37
  // configuration: ProgramConfiguration;
37
38
  // Experimental flag to avoid deleting Program object while it is cached
38
- varyings: string[];
39
+ varyings: string[] | null = null;
39
40
  vertexArrayObject: WEBGLVertexArrayObject;
40
41
  _indexBuffer?: Buffer;
41
42
  uniforms: Record<string, any> = {};
@@ -43,7 +44,7 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
43
44
  _textureUniforms: Record<string, any> = {};
44
45
  _textureIndexCounter: number = 0;
45
46
  _uniformCount: number = 0;
46
- _uniformSetters: Record<string, Function>;
47
+ _uniformSetters: Record<string, Function> = {}; // TODO are these used?
47
48
 
48
49
  constructor(device: WebGLDevice, props: RenderPipelineProps) {
49
50
  super(device, props);
@@ -64,7 +65,7 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
64
65
  if (varyings && varyings.length > 0) {
65
66
  this.device.assertWebGL2();
66
67
  this.varyings = varyings;
67
- this.device.gl2.transformFeedbackVaryings(this.handle, varyings, bufferMode);
68
+ this.device.gl2?.transformFeedbackVaryings(this.handle, varyings, bufferMode);
68
69
  }
69
70
 
70
71
  this._compileAndLink();
@@ -76,7 +77,8 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
76
77
  destroy(): void {
77
78
  if (this.handle) {
78
79
  this.device.gl.deleteProgram(this.handle);
79
- this.handle = null;
80
+ // this.handle = null;
81
+ this.destroyed = true;
80
82
  }
81
83
  }
82
84
 
@@ -121,6 +123,7 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
121
123
  const binding = this.layout.bindings.find((binding) => binding.name === name);
122
124
  if (!binding) {
123
125
  log.warn(`Unknown binding ${name} in render pipeline ${this.id}`)();
126
+ continue;
124
127
  }
125
128
  if (!value) {
126
129
  log.warn(`Unsetting binding ${name} in render pipeline ${this.id}`)();
@@ -181,7 +184,7 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
181
184
  const drawMode = getDrawMode(this.props.topology);
182
185
  const isIndexed: boolean = Boolean(this._indexBuffer);
183
186
  const indexType = this._indexBuffer?.props.indexType === 'uint16' ? GL.UNSIGNED_SHORT : GL.UNSIGNED_INT;
184
- const isInstanced: boolean = options.instanceCount > 0;
187
+ const isInstanced: boolean = Number(options.instanceCount) > 0;
185
188
 
186
189
  // Avoid WebGL draw call when not rendering any data or values are incomplete
187
190
  // Note: async textures set as uniforms might still be loading.
@@ -195,8 +198,6 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
195
198
  this.device.gl.useProgram(this.handle);
196
199
 
197
200
  this.vertexArrayObject.bind(() => {
198
- const parameters = {...this.props.parameters, framebuffer: renderPass.props.framebuffer};
199
-
200
201
  const primitiveMode = getGLPrimitive(this.props.topology);
201
202
  const transformFeedback: any = null;
202
203
  if (transformFeedback) {
@@ -208,31 +209,33 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
208
209
  this._applyUniforms();
209
210
 
210
211
  // TODO - double context push/pop
211
- withDeviceParameters(this.device, parameters, () => {
212
- // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension
213
- if (isIndexed && isInstanced) {
214
- // ANGLE_instanced_arrays extension
215
- this.device.gl2.drawElementsInstanced(
216
- drawMode,
217
- vertexCount,
218
- indexType,
219
- firstVertex,
220
- instanceCount
221
- );
222
- // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {
223
- // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);
224
- } else if (isIndexed) {
225
- this.device.gl.drawElements(drawMode, vertexCount, indexType, firstVertex);
226
- } else if (isInstanced) {
227
- this.device.gl2.drawArraysInstanced(drawMode, firstVertex, vertexCount, instanceCount);
228
- } else {
229
- this.device.gl.drawArrays(drawMode, firstVertex, vertexCount);
212
+ withDeviceParameters(this.device, this.props.parameters, () => {
213
+ withGLParameters(this.device, {framebuffer: renderPass.props.framebuffer}, () => {
214
+ // TODO - Use polyfilled WebGL2RenderingContext instead of ANGLE extension
215
+ if (isIndexed && isInstanced) {
216
+ // ANGLE_instanced_arrays extension
217
+ this.device.gl2?.drawElementsInstanced(
218
+ drawMode,
219
+ vertexCount || 0, // indexCount?
220
+ indexType,
221
+ firstVertex,
222
+ instanceCount || 0
223
+ );
224
+ // } else if (isIndexed && this.device.isWebGL2 && !isNaN(start) && !isNaN(end)) {
225
+ // this.device.gl2.drawRangeElements(drawMode, start, end, vertexCount, indexType, offset);
226
+ } else if (isIndexed) {
227
+ this.device.gl.drawElements(drawMode, vertexCount || 0, indexType, firstVertex); // indexCount?
228
+ } else if (isInstanced) {
229
+ this.device.gl2?.drawArraysInstanced(drawMode, firstVertex, vertexCount || 0, instanceCount || 0);
230
+ } else {
231
+ this.device.gl.drawArrays(drawMode, firstVertex, vertexCount || 0);
232
+ }
233
+ });
234
+
235
+ if (transformFeedback) {
236
+ transformFeedback.end();
230
237
  }
231
238
  });
232
-
233
- if (transformFeedback) {
234
- transformFeedback.end();
235
- }
236
239
  });
237
240
 
238
241
  return true;
@@ -295,6 +298,9 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
295
298
  this.device.gl.useProgram(this.handle);
296
299
 
297
300
  const {gl2} = this.device;
301
+ if (!gl2) {
302
+ throw new Error('bindings');
303
+ }
298
304
 
299
305
  let textureUnit = 0;
300
306
  let uniformBufferIndex = 0;
@@ -395,13 +401,15 @@ function getAttributesByLocation(
395
401
  const byLocation: Record<number, Buffer> = {};
396
402
  for (const [name, buffer] of Object.entries(attributes)) {
397
403
  const attribute = getAttributeLayout(layout, name);
398
- byLocation[attribute.location] = buffer;
404
+ if (attribute) {
405
+ byLocation[attribute.location] = buffer;
406
+ }
399
407
  }
400
408
  return byLocation;
401
409
  }
402
410
 
403
- function getAttributeLayout(layout: ShaderLayout, name: string): AttributeLayout | undefined {
404
- return layout.attributes.find((binding) => binding.name === name);
411
+ function getAttributeLayout(layout: ShaderLayout, name: string): AttributeLayout | null {
412
+ return layout.attributes.find((binding) => binding.name === name) || null;
405
413
  }
406
414
 
407
415
  function getBindingLayout(layout: ShaderLayout, name: string): BindingLayout {
@@ -1,6 +1,8 @@
1
+ // luma.gl, MIT license
2
+
1
3
  import {Sampler, SamplerProps} from '@luma.gl/api';
2
4
  import GL from '@luma.gl/constants';
3
- import type {WebGLSamplerParameters} from '../../types/webgl';
5
+ import type {GLSamplerParameters} from '../../types/webgl';
4
6
  import {convertSamplerParametersToWebGL} from '../converters/sampler-parameters';
5
7
  import type WebGLDevice from '../webgl-device';
6
8
 
@@ -14,7 +16,7 @@ import type WebGLDevice from '../webgl-device';
14
16
  export default class WEBGLSampler extends Sampler {
15
17
  readonly device: WebGLDevice;
16
18
  readonly handle: WebGLSampler;
17
- readonly parameters: WebGLSamplerParameters;
19
+ readonly parameters: GLSamplerParameters;
18
20
 
19
21
  constructor(device: WebGLDevice, props: SamplerProps) {
20
22
  super(device, props);
@@ -35,7 +37,7 @@ export default class WEBGLSampler extends Sampler {
35
37
  }
36
38
 
37
39
  /** Set sampler parameters on the sampler */
38
- private _setSamplerParameters(parameters: WebGLSamplerParameters): void {
40
+ private _setSamplerParameters(parameters: GLSamplerParameters): void {
39
41
  for (const [pname, value] of Object.entries(parameters)) {
40
42
  // Apparently there are integer/float conversion issues requires two parameter setting functions in JavaScript.
41
43
  // For now, pick the float version for parameters specified as GLfloat.
@@ -32,14 +32,14 @@ import WebGLDevice from '../webgl-device';
32
32
  if (this.handle) {
33
33
  this.removeStats();
34
34
  this.device.gl.deleteShader(this.handle);
35
- // @ts-expect-error
36
- this.handle = null;
35
+ // this.handle = null;
36
+ this.destroyed = true;
37
37
  }
38
38
  }
39
39
 
40
40
  async compilationInfo(): Promise<readonly CompilerMessage[]> {
41
41
  const log = this.device.gl.getShaderInfoLog(this.handle);
42
- return parseShaderCompilerLog(log);
42
+ return log ? parseShaderCompilerLog(log) : [];
43
43
  }
44
44
 
45
45
  // PRIVATE METHODS
@@ -58,7 +58,8 @@ import WebGLDevice from '../webgl-device';
58
58
  const compileStatus = gl.getShaderParameter(this.handle, GL.COMPILE_STATUS);
59
59
  if (!compileStatus) {
60
60
  const shaderLog = gl.getShaderInfoLog(this.handle);
61
- const messages = parseShaderCompilerLog(shaderLog).filter(message => message.type === 'error');
61
+ const parsedLog = shaderLog ? parseShaderCompilerLog(shaderLog) : [];
62
+ const messages = parsedLog.filter(message => message.type === 'error');
62
63
  const formattedLog = formatCompilerLog(messages, source);
63
64
  const shaderName: string = getShaderInfo(source).name;
64
65
  const shaderDescription = `${this.stage} shader ${shaderName}`;
@@ -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)
@@ -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
  }
@@ -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
  }
@@ -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