@luma.gl/webgl 9.0.0-alpha.48 → 9.0.0-alpha.50

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.
@@ -29,7 +29,10 @@ export function convertSamplerParametersToWebGL(props: SamplerParameters): GLSam
29
29
  }
30
30
  if (props.minFilter || props.mipmapFilter) {
31
31
  // TODO - arbitrary choice of linear?
32
- params[GL.TEXTURE_MIN_FILTER] = convertMinFilterMode(props.minFilter || 'linear', props.mipmapFilter);
32
+ params[GL.TEXTURE_MIN_FILTER] = convertMinFilterMode(
33
+ props.minFilter || 'linear',
34
+ props.mipmapFilter
35
+ );
33
36
  }
34
37
  if (props.lodMinClamp !== undefined) {
35
38
  params[GL.TEXTURE_MIN_LOD] = props.lodMinClamp;
@@ -54,30 +57,40 @@ export function convertSamplerParametersToWebGL(props: SamplerParameters): GLSam
54
57
  /** Convert address more */
55
58
  function convertAddressMode(addressMode: 'clamp-to-edge' | 'repeat' | 'mirror-repeat'): GL {
56
59
  switch (addressMode) {
57
- case 'clamp-to-edge': return GL.CLAMP_TO_EDGE;
58
- case 'repeat': return GL.REPEAT;
59
- case 'mirror-repeat': return GL.MIRRORED_REPEAT;
60
+ case 'clamp-to-edge':
61
+ return GL.CLAMP_TO_EDGE;
62
+ case 'repeat':
63
+ return GL.REPEAT;
64
+ case 'mirror-repeat':
65
+ return GL.MIRRORED_REPEAT;
60
66
  }
61
67
  }
62
68
 
63
69
  function convertMaxFilterMode(maxFilter: 'nearest' | 'linear'): GL {
64
70
  switch (maxFilter) {
65
- case 'nearest': return GL.NEAREST;
66
- case 'linear': return GL.LINEAR;
71
+ case 'nearest':
72
+ return GL.NEAREST;
73
+ case 'linear':
74
+ return GL.LINEAR;
67
75
  }
68
76
  }
69
77
 
70
- /**
71
- * WebGPU has separate min filter and mipmap filter,
78
+ /**
79
+ * WebGPU has separate min filter and mipmap filter,
72
80
  * WebGL is combined and effectively offers 6 options
73
81
  */
74
- function convertMinFilterMode(minFilter: 'nearest' | 'linear', mipmapFilter?: 'nearest' | 'linear'): GL {
82
+ function convertMinFilterMode(
83
+ minFilter: 'nearest' | 'linear',
84
+ mipmapFilter?: 'nearest' | 'linear'
85
+ ): GL {
75
86
  if (!mipmapFilter) {
76
87
  return convertMaxFilterMode(minFilter);
77
88
  }
78
89
  switch (minFilter) {
79
- case 'nearest': return mipmapFilter === 'nearest' ? GL.NEAREST_MIPMAP_NEAREST : GL.NEAREST_MIPMAP_LINEAR;
80
- case 'linear': return mipmapFilter === 'nearest' ? GL.LINEAR_MIPMAP_NEAREST : GL.LINEAR_MIPMAP_LINEAR;
90
+ case 'nearest':
91
+ return mipmapFilter === 'nearest' ? GL.NEAREST_MIPMAP_NEAREST : GL.NEAREST_MIPMAP_LINEAR;
92
+ case 'linear':
93
+ return mipmapFilter === 'nearest' ? GL.LINEAR_MIPMAP_NEAREST : GL.LINEAR_MIPMAP_LINEAR;
81
94
  }
82
95
  }
83
96
 
@@ -115,7 +128,10 @@ export function convertToSamplerParameters(params: GLSamplerParameters): Sampler
115
128
  props.lodMaxClamp = params[GL.TEXTURE_MAX_LOD];
116
129
  }
117
130
  if (params[GL.TEXTURE_COMPARE_MODE]) {
118
- props.type = params[GL.TEXTURE_COMPARE_MODE] === GL.COMPARE_REF_TO_TEXTURE ? 'comparison-sampler' : 'color-sampler';
131
+ props.type =
132
+ params[GL.TEXTURE_COMPARE_MODE] === GL.COMPARE_REF_TO_TEXTURE
133
+ ? 'comparison-sampler'
134
+ : 'color-sampler';
119
135
  }
120
136
  if (params[GL.TEXTURE_COMPARE_FUNC]) {
121
137
  props.compare = convertToCompareFunction('compare', params[GL.TEXTURE_COMPARE_FUNC]);
@@ -128,54 +144,87 @@ export function convertToSamplerParameters(params: GLSamplerParameters): Sampler
128
144
  }
129
145
 
130
146
  /** Convert address more */
131
- function convertToAddressMode(addressMode: number): 'clamp-to-edge' | 'repeat' | 'mirror-repeat' {
147
+ function convertToAddressMode(
148
+ addressMode: GL.CLAMP_TO_EDGE | GL.REPEAT | GL.MIRRORED_REPEAT
149
+ ): 'clamp-to-edge' | 'repeat' | 'mirror-repeat' {
132
150
  switch (addressMode) {
133
- case GL.CLAMP_TO_EDGE: return 'clamp-to-edge';
134
- case GL.REPEAT: return 'repeat';
135
- case GL.MIRRORED_REPEAT: return 'mirror-repeat';
136
- default: throw new Error('address');
151
+ case GL.CLAMP_TO_EDGE:
152
+ return 'clamp-to-edge';
153
+ case GL.REPEAT:
154
+ return 'repeat';
155
+ case GL.MIRRORED_REPEAT:
156
+ return 'mirror-repeat';
157
+ default:
158
+ throw new Error('address');
137
159
  }
138
160
  }
139
161
 
140
- function convertToMaxFilterMode(filterMode: number): 'nearest' | 'linear' {
162
+ function convertToMaxFilterMode(filterMode: GL.NEAREST | GL.LINEAR): 'nearest' | 'linear' {
141
163
  switch (filterMode) {
142
- case GL.NEAREST: return 'nearest';
143
- case GL.LINEAR: return 'linear';
144
- default: throw new Error('maxfilter');
164
+ case GL.NEAREST:
165
+ return 'nearest';
166
+ case GL.LINEAR:
167
+ return 'linear';
168
+ default:
169
+ throw new Error('maxfilter');
145
170
  }
146
171
  }
147
172
 
173
+ type GLMinFilter =
174
+ | GL.NEAREST
175
+ | GL.LINEAR
176
+ | GL.NEAREST_MIPMAP_NEAREST
177
+ | GL.LINEAR_MIPMAP_NEAREST
178
+ | GL.NEAREST_MIPMAP_LINEAR
179
+ | GL.LINEAR_MIPMAP_LINEAR;
180
+
148
181
  /** WebGPU has separate min filter and mipmap filter, WebGL is combined */
149
- function convertToMinFilterMode(filterMode: number): 'nearest' | 'linear' {
182
+ function convertToMinFilterMode(filterMode: GLMinFilter): 'nearest' | 'linear' {
150
183
  switch (filterMode) {
151
184
  // TODO is this correct?
152
- case GL.NEAREST: return 'nearest';
153
- case GL.LINEAR: return 'linear';
154
- case GL.NEAREST_MIPMAP_NEAREST: return 'nearest';
155
- case GL.LINEAR_MIPMAP_NEAREST: return 'linear';
156
- case GL.NEAREST_MIPMAP_LINEAR: return 'nearest';
157
- case GL.LINEAR_MIPMAP_LINEAR: return 'linear';
158
- default: throw new Error('minfilter');
185
+ case GL.NEAREST:
186
+ return 'nearest';
187
+ case GL.LINEAR:
188
+ return 'linear';
189
+ case GL.NEAREST_MIPMAP_NEAREST:
190
+ return 'nearest';
191
+ case GL.LINEAR_MIPMAP_NEAREST:
192
+ return 'linear';
193
+ case GL.NEAREST_MIPMAP_LINEAR:
194
+ return 'nearest';
195
+ case GL.LINEAR_MIPMAP_LINEAR:
196
+ return 'linear';
197
+ default:
198
+ throw new Error('minfilter');
159
199
  }
160
200
  }
161
201
 
162
- function convertToMipmapFilterMode(filterMode: number): 'nearest' | 'linear' {
202
+ function convertToMipmapFilterMode(filterMode: GLMinFilter): 'nearest' | 'linear' {
163
203
  switch (filterMode) {
164
204
  // TODO is this correct?
165
- case GL.NEAREST: return 'nearest';
166
- case GL.LINEAR: return 'linear';
167
- case GL.NEAREST_MIPMAP_NEAREST: return 'nearest';
168
- case GL.LINEAR_MIPMAP_NEAREST: return 'nearest';
169
- case GL.NEAREST_MIPMAP_LINEAR: return 'linear';
170
- case GL.LINEAR_MIPMAP_LINEAR: return 'linear';
171
- default: throw new Error('mipmap');
205
+ case GL.NEAREST:
206
+ return 'nearest';
207
+ case GL.LINEAR:
208
+ return 'linear';
209
+ case GL.NEAREST_MIPMAP_NEAREST:
210
+ return 'nearest';
211
+ case GL.LINEAR_MIPMAP_NEAREST:
212
+ return 'nearest';
213
+ case GL.NEAREST_MIPMAP_LINEAR:
214
+ return 'linear';
215
+ case GL.LINEAR_MIPMAP_LINEAR:
216
+ return 'linear';
217
+ default:
218
+ throw new Error('mipmap');
172
219
  }
173
220
  }
174
221
 
175
222
  /**
176
223
  * Override sampler settings that are not supported by Non-Power-of-Two textures in WebGL1.
177
- */
178
- export function updateSamplerParametersForNPOT(parameters: GLSamplerParameters): GLSamplerParameters {
224
+ */
225
+ export function updateSamplerParametersForNPOT(
226
+ parameters: GLSamplerParameters
227
+ ): GLSamplerParameters {
179
228
  const newParameters = {...parameters};
180
229
  if (parameters[GL.TEXTURE_MIN_FILTER] !== GL.NEAREST) {
181
230
  // log.warn(`texture: ${this} is Non-Power-Of-Two, forcing TEXTURE_MIN_FILTER to LINEAR`)();
@@ -660,7 +660,7 @@ export function _checkFloat32ColorAttachment(
660
660
  framebuffer = gl.createFramebuffer();
661
661
  gl.bindFramebuffer(GL.FRAMEBUFFER, framebuffer);
662
662
  gl.framebufferTexture2D(GL.FRAMEBUFFER, GL.COLOR_ATTACHMENT0, GL.TEXTURE_2D, texture, 0);
663
- const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) === GL.FRAMEBUFFER_COMPLETE;
663
+ const status = gl.checkFramebufferStatus(GL.FRAMEBUFFER) as GL === GL.FRAMEBUFFER_COMPLETE;
664
664
 
665
665
  gl.bindTexture(GL.TEXTURE_2D, null);
666
666
  return status;
@@ -207,7 +207,7 @@ export class WEBGLFramebuffer extends Framebuffer {
207
207
  function mapIndexToCubeMapFace(layer: number | GL): GL {
208
208
  // TEXTURE_CUBE_MAP_POSITIVE_X is a big value (0x8515)
209
209
  // if smaller assume layer is index, otherwise assume it is already a cube map face constant
210
- return layer < GL.TEXTURE_CUBE_MAP_POSITIVE_X ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;
210
+ return layer < (GL.TEXTURE_CUBE_MAP_POSITIVE_X as number) ? layer + GL.TEXTURE_CUBE_MAP_POSITIVE_X : layer;
211
211
  }
212
212
 
213
213
  // Helper METHODS
@@ -178,7 +178,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
178
178
  const {bindings} = splitUniformsAndBindings(uniforms);
179
179
  Object.keys(bindings).forEach(name => {
180
180
  log.warn(
181
- `Unsupported value "${bindings[name]}" used in setUniforms() for key ${name}. Use setBindings() instead?`
181
+ `Unsupported value "${JSON.stringify(bindings[name])}" used in setUniforms() for key ${name}. Use setBindings() instead?`
182
182
  )();
183
183
  });
184
184
  // TODO - check against layout
@@ -403,7 +403,7 @@ export class WEBGLRenderPipeline extends RenderPipeline {
403
403
  // Set buffer
404
404
  const {name} = binding;
405
405
  const location = gl2.getUniformBlockIndex(this.handle, name);
406
- if (location === GL.INVALID_INDEX) {
406
+ if (location as GL === GL.INVALID_INDEX) {
407
407
  throw new Error(`Invalid uniform block name ${name}`);
408
408
  }
409
409
  gl2.uniformBlockBinding(this.handle, uniformBufferIndex, location);
@@ -45,7 +45,7 @@ export class WEBGLSampler extends Sampler {
45
45
  for (const [pname, value] of Object.entries(parameters)) {
46
46
  // Apparently there are integer/float conversion issues requires two parameter setting functions in JavaScript.
47
47
  // For now, pick the float version for parameters specified as GLfloat.
48
- const param = Number(pname);
48
+ const param = Number(pname) as GL.TEXTURE_MIN_LOD | GL.TEXTURE_MAX_LOD;
49
49
  switch (param) {
50
50
  case GL.TEXTURE_MIN_LOD:
51
51
  case GL.TEXTURE_MAX_LOD:
@@ -56,17 +56,16 @@ export const DEFAULT_WEBGL_TEXTURE_PROPS = {
56
56
  border: 0,
57
57
  dataFormat: undefined!,
58
58
  textureUnit: undefined!,
59
- target: undefined!,
59
+ target: undefined!
60
60
  };
61
61
 
62
- export type TextureSourceData =
63
- TypedArray |
64
- ImageData |
65
- HTMLImageElement |
66
- HTMLCanvasElement |
67
- ImageBitmap |
68
- HTMLVideoElement
69
- ;
62
+ export type TextureSourceData =
63
+ | TypedArray
64
+ | ImageData
65
+ | HTMLImageElement
66
+ | HTMLCanvasElement
67
+ | ImageBitmap
68
+ | HTMLVideoElement;
70
69
 
71
70
  type SetImageDataOptions = {
72
71
  target?: number;
@@ -83,7 +82,7 @@ type SetImageDataOptions = {
83
82
  parameters?: Record<GL, any>;
84
83
  /** @deprecated */
85
84
  pixels?: any;
86
- }
85
+ };
87
86
 
88
87
  /**
89
88
  * @param {*} pixels, data -
@@ -139,7 +138,6 @@ type SetImageData3DOptions = {
139
138
  parameters?: Record<GL, any>;
140
139
  };
141
140
 
142
-
143
141
  // Polyfill
144
142
  export class WEBGLTexture extends Texture<WEBGLTextureProps> {
145
143
  // TODO - remove?
@@ -241,7 +239,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
241
239
  let data = props.data;
242
240
 
243
241
  if (data instanceof Promise) {
244
- data.then((resolvedImageData) =>
242
+ data.then(resolvedImageData =>
245
243
  this.initialize(
246
244
  Object.assign({}, props, {
247
245
  pixels: resolvedImageData,
@@ -261,10 +259,9 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
261
259
  return this;
262
260
  }
263
261
 
264
- const {parameters = {} as Record<GL, any>} = props;
262
+ const {parameters = {} as Record<GL, any>} = props;
265
263
 
266
- const {
267
- pixels = null, pixelStore = {}, textureUnit = undefined} = props;
264
+ const {pixels = null, pixelStore = {}, textureUnit = undefined} = props;
268
265
 
269
266
  // pixels variable is for API compatibility purpose
270
267
  if (!data) {
@@ -319,7 +316,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
319
316
  format: glFormat,
320
317
  type,
321
318
  dataFormat,
322
- // @ts-expect-error
319
+ // @ts-expect-error
323
320
  parameters: pixelStore,
324
321
  compressed
325
322
  });
@@ -345,7 +342,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
345
342
  }
346
343
 
347
344
  initializeCube(props?: WEBGLTextureProps): this {
348
- const {mipmaps = true, parameters = {} as Record<GL, any>} = props;
345
+ const {mipmaps = true, parameters = {} as Record<GL, any>} = props;
349
346
 
350
347
  // Store props for accessors
351
348
  // this.props = props;
@@ -386,7 +383,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
386
383
  * If size has changed, reinitializes with current format
387
384
  * @note note clears image and mipmaps
388
385
  */
389
- resize(options: {height: number, width: number, mipmaps?: boolean}): this {
386
+ resize(options: {height: number; width: number; mipmaps?: boolean}): this {
390
387
  const {height, width, mipmaps = false} = options;
391
388
  if (width !== this.width || height !== this.height) {
392
389
  return this.initialize({
@@ -471,7 +468,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
471
468
  level = 0,
472
469
  glFormat = this.glFormat,
473
470
  offset = 0,
474
- parameters = {} as Record<GL, any>
471
+ parameters = {} as Record<GL, any>
475
472
  } = options;
476
473
 
477
474
  let {
@@ -509,7 +506,17 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
509
506
  withGLParameters(this.gl, parameters, () => {
510
507
  switch (dataType) {
511
508
  case 'null':
512
- gl.texImage2D(target, level, glFormat, width, height, 0 /* border*/, dataFormat, type, data);
509
+ gl.texImage2D(
510
+ target,
511
+ level,
512
+ glFormat,
513
+ width,
514
+ height,
515
+ 0 /* border*/,
516
+ dataFormat,
517
+ type,
518
+ data
519
+ );
513
520
  break;
514
521
  case 'typed-array':
515
522
  // Looks like this assert is not necessary, as offset is ignored under WebGL1
@@ -821,7 +828,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
821
828
  // ... }
822
829
 
823
830
  const resolvedFaces = await Promise.all(
824
- WEBGLTexture.FACES.map((face) => {
831
+ WEBGLTexture.FACES.map(face => {
825
832
  const facePixels = imageDataMap[face];
826
833
  return Promise.all(Array.isArray(facePixels) ? facePixels : [facePixels]);
827
834
  })
@@ -867,7 +874,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
867
874
 
868
875
  this.bind();
869
876
  if (imageData instanceof Promise) {
870
- imageData.then((resolvedImageData) =>
877
+ imageData.then(resolvedImageData =>
871
878
  this.setImageDataForFace(
872
879
  Object.assign({}, options, {
873
880
  face,
@@ -974,7 +981,7 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
974
981
 
975
982
  this.gl.bindTexture(this.target, this.handle);
976
983
  for (const [pname, pvalue] of Object.entries(parameters)) {
977
- const param = Number(pname);
984
+ const param = Number(pname) as GL.TEXTURE_MIN_LOD | GL.TEXTURE_MAX_LOD;
978
985
  const value = pvalue;
979
986
 
980
987
  // Apparently there are integer/float conversion issues requires two parameter setting functions in JavaScript.
@@ -995,7 +1002,10 @@ export class WEBGLTexture extends Texture<WEBGLTextureProps> {
995
1002
  }
996
1003
 
997
1004
  /** @deprecated For LegacyTexture subclass */
998
- protected _getWebGL1NPOTParameterOverride(pname: number, value: number): number {
1005
+ protected _getWebGL1NPOTParameterOverride(
1006
+ pname: GL.TEXTURE_MIN_FILTER | GL.TEXTURE_WRAP_S | GL.TEXTURE_WRAP_T,
1007
+ value: GL.LINEAR | GL.NEAREST
1008
+ ): number {
999
1009
  // NOTE: Apply NPOT workaround
1000
1010
  const npot = this.device.isWebGL1 && isNPOT(this.width, this.height);
1001
1011
  if (npot) {
@@ -87,7 +87,7 @@ export class Accessor implements AccessorObject {
87
87
  this.type = props.type;
88
88
 
89
89
  // Auto-deduce integer type?
90
- if (props.type === GL.INT || props.type === GL.UNSIGNED_INT) {
90
+ if ((props.type as GL) === GL.INT || (props.type as GL) === GL.UNSIGNED_INT) {
91
91
  this.integer = true;
92
92
  }
93
93
  }