@lightningjs/renderer 3.0.0 → 3.0.1

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 (75) hide show
  1. package/dist/src/core/CoreNode.d.ts +1 -1
  2. package/dist/src/core/CoreTextNode.js +8 -0
  3. package/dist/src/core/CoreTextNode.js.map +1 -1
  4. package/dist/src/core/lib/ImageWorker.d.ts +2 -2
  5. package/dist/src/core/lib/ImageWorker.js +12 -31
  6. package/dist/src/core/lib/ImageWorker.js.map +1 -1
  7. package/dist/src/core/lib/WebGlContextWrapper.d.ts +60 -109
  8. package/dist/src/core/lib/WebGlContextWrapper.js +158 -164
  9. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  10. package/dist/src/core/lib/textureCompression.js +10 -19
  11. package/dist/src/core/lib/textureCompression.js.map +1 -1
  12. package/dist/src/core/lib/validateImageBitmap.d.ts +1 -2
  13. package/dist/src/core/lib/validateImageBitmap.js +4 -4
  14. package/dist/src/core/lib/validateImageBitmap.js.map +1 -1
  15. package/dist/src/core/platform.js +5 -2
  16. package/dist/src/core/platform.js.map +1 -1
  17. package/dist/src/core/platforms/web/WebGlContextWrapper.d.ts +5 -5
  18. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.d.ts +1 -0
  19. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js +2 -0
  20. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js.map +1 -0
  21. package/dist/src/core/renderers/webgl/WebGlRenderer.js +5 -3
  22. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  23. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +4 -1
  24. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  25. package/dist/src/core/renderers/webgl/internal/RendererUtils.js +1 -2
  26. package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -1
  27. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.d.ts +0 -1
  28. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +14 -35
  29. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
  30. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +8 -25
  31. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +1 -1
  32. package/dist/src/core/text-rendering/SdfFontHandler.js +5 -7
  33. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
  34. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  35. package/package.json +1 -1
  36. package/src/core/CoreTextNode.ts +9 -0
  37. package/src/core/renderers/webgl/WebGlCtxTexture.test.ts +113 -0
  38. package/src/core/renderers/webgl/WebGlRenderer.ts +4 -3
  39. package/src/core/renderers/webgl/WebGlShaderProgram.ts +3 -1
  40. package/src/core/renderers/webgl/internal/RendererUtils.ts +1 -2
  41. package/src/core/text-rendering/SdfFontHandler.ts +5 -8
  42. package/dist/src/core/AutosizeManager.d.ts +0 -29
  43. package/dist/src/core/AutosizeManager.js +0 -169
  44. package/dist/src/core/AutosizeManager.js.map +0 -1
  45. package/dist/src/core/animations/Animation.d.ts +0 -21
  46. package/dist/src/core/animations/Animation.js +0 -194
  47. package/dist/src/core/animations/Animation.js.map +0 -1
  48. package/dist/src/core/animations/Playback.d.ts +0 -64
  49. package/dist/src/core/animations/Playback.js +0 -169
  50. package/dist/src/core/animations/Playback.js.map +0 -1
  51. package/dist/src/core/animations/Transition.d.ts +0 -27
  52. package/dist/src/core/animations/Transition.js +0 -52
  53. package/dist/src/core/animations/Transition.js.map +0 -1
  54. package/dist/src/core/animations/utils.d.ts +0 -2
  55. package/dist/src/core/animations/utils.js +0 -136
  56. package/dist/src/core/animations/utils.js.map +0 -1
  57. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +0 -45
  58. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +0 -127
  59. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +0 -1
  60. package/dist/src/core/shaders/webgl/SdfShadowShader.d.ts +0 -9
  61. package/dist/src/core/shaders/webgl/SdfShadowShader.js +0 -100
  62. package/dist/src/core/shaders/webgl/SdfShadowShader.js.map +0 -1
  63. package/dist/src/core/text-rendering/CanvasFont.d.ts +0 -14
  64. package/dist/src/core/text-rendering/CanvasFont.js +0 -111
  65. package/dist/src/core/text-rendering/CanvasFont.js.map +0 -1
  66. package/dist/src/core/text-rendering/CoreFont.d.ts +0 -33
  67. package/dist/src/core/text-rendering/CoreFont.js +0 -48
  68. package/dist/src/core/text-rendering/CoreFont.js.map +0 -1
  69. package/dist/src/core/text-rendering/FontManager.d.ts +0 -11
  70. package/dist/src/core/text-rendering/FontManager.js +0 -42
  71. package/dist/src/core/text-rendering/FontManager.js.map +0 -1
  72. package/dist/src/core/text-rendering/SdfFont.d.ts +0 -29
  73. package/dist/src/core/text-rendering/SdfFont.js +0 -142
  74. package/dist/src/core/text-rendering/SdfFont.js.map +0 -1
  75. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-return */
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
- import { assertTruthy, isProductionEnvironment } from '../../utils.js';
4
+ import { assertTruthy } from '../../utils.js';
5
5
  import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
6
6
  /**
7
7
  * Optimized WebGL Context Wrapper
@@ -41,7 +41,6 @@ export class WebGlContextWrapper {
41
41
  boundArrayBuffer;
42
42
  boundElementArrayBuffer;
43
43
  curProgram;
44
- curUniformLocations = {};
45
44
  //#endregion Cached WebGL State
46
45
  //#region Canvas
47
46
  canvas;
@@ -179,8 +178,9 @@ export class WebGlContextWrapper {
179
178
  * @param textureUnit
180
179
  */
181
180
  activeTexture(textureUnit) {
181
+ const { gl } = this;
182
182
  if (this.activeTextureUnit !== textureUnit) {
183
- this.gl.activeTexture(textureUnit + this.gl.TEXTURE0);
183
+ gl.activeTexture(textureUnit + gl.TEXTURE0);
184
184
  this.activeTextureUnit = textureUnit;
185
185
  }
186
186
  }
@@ -194,14 +194,16 @@ export class WebGlContextWrapper {
194
194
  * @param texture
195
195
  */
196
196
  bindTexture(texture) {
197
- if (this.texture2dUnits[this.activeTextureUnit] === texture) {
197
+ const { gl, activeTextureUnit, texture2dUnits } = this;
198
+ if (texture2dUnits[activeTextureUnit] === texture) {
198
199
  return;
199
200
  }
200
- this.texture2dUnits[this.activeTextureUnit] = texture;
201
- this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
201
+ texture2dUnits[activeTextureUnit] = texture;
202
+ gl.bindTexture(this.gl.TEXTURE_2D, texture);
202
203
  }
203
204
  _getActiveTexture() {
204
- return this.texture2dUnits[this.activeTextureUnit];
205
+ const { activeTextureUnit, texture2dUnits } = this;
206
+ return texture2dUnits[activeTextureUnit];
205
207
  }
206
208
  /**
207
209
  * ```
@@ -215,27 +217,29 @@ export class WebGlContextWrapper {
215
217
  * @returns
216
218
  */
217
219
  texParameteri(pname, param) {
220
+ const { gl, texture2dParams } = this;
218
221
  const activeTexture = this._getActiveTexture();
219
222
  if (!activeTexture) {
220
223
  throw new Error('No active texture');
221
224
  }
222
- let textureParams = this.texture2dParams.get(activeTexture);
225
+ let textureParams = texture2dParams.get(activeTexture);
223
226
  if (!textureParams) {
224
227
  textureParams = {};
225
- this.texture2dParams.set(activeTexture, textureParams);
228
+ texture2dParams.set(activeTexture, textureParams);
226
229
  }
227
230
  if (textureParams[pname] === param) {
228
231
  return;
229
232
  }
230
233
  textureParams[pname] = param;
231
- this.gl.texParameteri(this.gl.TEXTURE_2D, pname, param);
234
+ gl.texParameteri(gl.TEXTURE_2D, pname, param);
232
235
  }
233
236
  texImage2D(level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels) {
237
+ const { gl } = this;
234
238
  if (format) {
235
- this.gl.texImage2D(this.gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels);
239
+ gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels);
236
240
  }
237
241
  else {
238
- this.gl.texImage2D(this.gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource);
242
+ gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource);
239
243
  }
240
244
  }
241
245
  /**
@@ -247,7 +251,8 @@ export class WebGlContextWrapper {
247
251
  * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
248
252
  */
249
253
  compressedTexImage2D(level, internalformat, width, height, border, data) {
250
- this.gl.compressedTexImage2D(this.gl.TEXTURE_2D, level, internalformat, width, height, border, data);
254
+ const { gl } = this;
255
+ gl.compressedTexImage2D(gl.TEXTURE_2D, level, internalformat, width, height, border, data);
251
256
  }
252
257
  /**
253
258
  * ```
@@ -258,7 +263,8 @@ export class WebGlContextWrapper {
258
263
  * @param param
259
264
  */
260
265
  pixelStorei(pname, param) {
261
- this.gl.pixelStorei(pname, param);
266
+ const { gl } = this;
267
+ gl.pixelStorei(pname, param);
262
268
  }
263
269
  /**
264
270
  * ```
@@ -269,7 +275,8 @@ export class WebGlContextWrapper {
269
275
  * **WebGL Difference**: Bind target is always `gl.TEXTURE_2D`
270
276
  */
271
277
  generateMipmap() {
272
- this.gl.generateMipmap(this.gl.TEXTURE_2D);
278
+ const { gl } = this;
279
+ gl.generateMipmap(gl.TEXTURE_2D);
273
280
  }
274
281
  /**
275
282
  * ```
@@ -279,7 +286,8 @@ export class WebGlContextWrapper {
279
286
  * @returns
280
287
  */
281
288
  createTexture() {
282
- return this.gl.createTexture();
289
+ const { gl } = this;
290
+ return gl.createTexture();
283
291
  }
284
292
  /**
285
293
  * ```
@@ -289,10 +297,11 @@ export class WebGlContextWrapper {
289
297
  * @param texture
290
298
  */
291
299
  deleteTexture(texture) {
300
+ const { gl } = this;
292
301
  if (texture) {
293
302
  this.texture2dParams.delete(texture);
294
303
  }
295
- this.gl.deleteTexture(texture);
304
+ gl.deleteTexture(texture);
296
305
  }
297
306
  /**
298
307
  * ```
@@ -309,7 +318,8 @@ export class WebGlContextWrapper {
309
318
  * ```
310
319
  */
311
320
  viewport(x, y, width, height) {
312
- this.gl.viewport(x, y, width, height);
321
+ const { gl } = this;
322
+ gl.viewport(x, y, width, height);
313
323
  }
314
324
  /**
315
325
  * ```
@@ -322,7 +332,8 @@ export class WebGlContextWrapper {
322
332
  * @param alpha
323
333
  */
324
334
  clearColor(red, green, blue, alpha) {
325
- this.gl.clearColor(red, green, blue, alpha);
335
+ const { gl } = this;
336
+ gl.clearColor(red, green, blue, alpha);
326
337
  }
327
338
  /**
328
339
  * ```
@@ -331,14 +342,15 @@ export class WebGlContextWrapper {
331
342
  * @param enable
332
343
  */
333
344
  setScissorTest(enable) {
334
- if (enable === this.scissorEnabled) {
345
+ const { gl, scissorEnabled } = this;
346
+ if (enable === scissorEnabled) {
335
347
  return;
336
348
  }
337
349
  if (enable) {
338
- this.gl.enable(this.gl.SCISSOR_TEST);
350
+ gl.enable(gl.SCISSOR_TEST);
339
351
  }
340
352
  else {
341
- this.gl.disable(this.gl.SCISSOR_TEST);
353
+ gl.disable(gl.SCISSOR_TEST);
342
354
  }
343
355
  this.scissorEnabled = enable;
344
356
  }
@@ -353,11 +365,12 @@ export class WebGlContextWrapper {
353
365
  * @param height
354
366
  */
355
367
  scissor(x, y, width, height) {
356
- if (x !== this.scissorX ||
357
- y !== this.scissorY ||
358
- width !== this.scissorWidth ||
359
- height !== this.scissorHeight) {
360
- this.gl.scissor(x, y, width, height);
368
+ const { gl, scissorX, scissorY, scissorWidth, scissorHeight } = this;
369
+ if (x !== scissorX ||
370
+ y !== scissorY ||
371
+ width !== scissorWidth ||
372
+ height !== scissorHeight) {
373
+ gl.scissor(x, y, width, height);
361
374
  this.scissorX = x;
362
375
  this.scissorY = y;
363
376
  this.scissorWidth = width;
@@ -373,14 +386,15 @@ export class WebGlContextWrapper {
373
386
  * @returns
374
387
  */
375
388
  setBlend(blend) {
376
- if (blend === this.blendEnabled) {
389
+ const { gl, blendEnabled } = this;
390
+ if (blend === blendEnabled) {
377
391
  return;
378
392
  }
379
393
  if (blend) {
380
- this.gl.enable(this.gl.BLEND);
394
+ gl.enable(gl.BLEND);
381
395
  }
382
396
  else {
383
- this.gl.disable(this.gl.BLEND);
397
+ gl.disable(gl.BLEND);
384
398
  }
385
399
  this.blendEnabled = blend;
386
400
  }
@@ -393,11 +407,12 @@ export class WebGlContextWrapper {
393
407
  * @param dst
394
408
  */
395
409
  blendFunc(src, dst) {
396
- if (src !== this.blendSrcRgb ||
397
- dst !== this.blendDstRgb ||
398
- src !== this.blendSrcAlpha ||
399
- dst !== this.blendDstAlpha) {
400
- this.gl.blendFunc(src, dst);
410
+ const { gl, blendSrcRgb, blendDstRgb, blendSrcAlpha, blendDstAlpha } = this;
411
+ if (src !== blendSrcRgb ||
412
+ dst !== blendDstRgb ||
413
+ src !== blendSrcAlpha ||
414
+ dst !== blendDstAlpha) {
415
+ gl.blendFunc(src, dst);
401
416
  this.blendSrcRgb = src;
402
417
  this.blendDstRgb = dst;
403
418
  this.blendSrcAlpha = src;
@@ -412,7 +427,8 @@ export class WebGlContextWrapper {
412
427
  * @returns
413
428
  */
414
429
  createBuffer() {
415
- return this.gl.createBuffer();
430
+ const { gl } = this;
431
+ return gl.createBuffer();
416
432
  }
417
433
  /**
418
434
  * ```
@@ -421,7 +437,8 @@ export class WebGlContextWrapper {
421
437
  * @returns
422
438
  */
423
439
  createFramebuffer() {
424
- return this.gl.createFramebuffer();
440
+ const { gl } = this;
441
+ return gl.createFramebuffer();
425
442
  }
426
443
  /**
427
444
  * ```
@@ -431,7 +448,8 @@ export class WebGlContextWrapper {
431
448
  * @param framebuffer
432
449
  */
433
450
  bindFramebuffer(framebuffer) {
434
- this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, framebuffer);
451
+ const { gl } = this;
452
+ gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
435
453
  }
436
454
  /**
437
455
  * ```
@@ -441,7 +459,7 @@ export class WebGlContextWrapper {
441
459
  * **WebGL Difference**: Bind target is always `gl.FRAMEBUFFER` and textarget is always `gl.TEXTURE_2D`
442
460
  */
443
461
  framebufferTexture2D(attachment, texture, level) {
444
- const gl = this.gl;
462
+ const { gl } = this;
445
463
  gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, texture, level);
446
464
  }
447
465
  /**
@@ -453,7 +471,8 @@ export class WebGlContextWrapper {
453
471
  * **WebGL Difference**: Clear mask is always `gl.COLOR_BUFFER_BIT`
454
472
  */
455
473
  clear() {
456
- this.gl.clear(this.gl.COLOR_BUFFER_BIT);
474
+ const { gl } = this;
475
+ gl.clear(gl.COLOR_BUFFER_BIT);
457
476
  }
458
477
  /**
459
478
  * ```
@@ -469,11 +488,12 @@ export class WebGlContextWrapper {
469
488
  * @param usage
470
489
  */
471
490
  arrayBufferData(buffer, data, usage) {
472
- if (this.boundArrayBuffer !== buffer) {
473
- this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
491
+ const { gl, boundArrayBuffer } = this;
492
+ if (boundArrayBuffer !== buffer) {
493
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
474
494
  this.boundArrayBuffer = buffer;
475
495
  }
476
- this.gl.bufferData(this.gl.ARRAY_BUFFER, data, usage);
496
+ gl.bufferData(gl.ARRAY_BUFFER, data, usage);
477
497
  }
478
498
  /**
479
499
  * ```
@@ -488,11 +508,12 @@ export class WebGlContextWrapper {
488
508
  * @param usage
489
509
  */
490
510
  elementArrayBufferData(buffer, data, usage) {
491
- if (this.boundElementArrayBuffer !== buffer) {
492
- this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, buffer);
511
+ const { gl, boundElementArrayBuffer } = this;
512
+ if (boundElementArrayBuffer !== buffer) {
513
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, buffer);
493
514
  this.boundElementArrayBuffer = buffer;
494
515
  }
495
- this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER, data, usage);
516
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, data, usage);
496
517
  }
497
518
  /**
498
519
  * ```
@@ -512,11 +533,12 @@ export class WebGlContextWrapper {
512
533
  * @param offset
513
534
  */
514
535
  vertexAttribPointer(buffer, index, size, type, normalized, stride, offset) {
515
- if (this.boundArrayBuffer !== buffer) {
516
- this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
536
+ const { gl, boundArrayBuffer } = this;
537
+ if (boundArrayBuffer !== buffer) {
538
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
517
539
  this.boundArrayBuffer = buffer;
518
540
  }
519
- this.gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
541
+ gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
520
542
  }
521
543
  /**
522
544
  * Returns object with Attribute names as key and numbers as location values
@@ -559,13 +581,13 @@ export class WebGlContextWrapper {
559
581
  * @param program
560
582
  * @returns
561
583
  */
562
- useProgram(program, uniformLocations) {
563
- if (this.curProgram === program) {
584
+ useProgram(program) {
585
+ const { gl, curProgram } = this;
586
+ if (curProgram === program) {
564
587
  return;
565
588
  }
566
- this.gl.useProgram(program);
589
+ gl.useProgram(program);
567
590
  this.curProgram = program;
568
- this.curUniformLocations = uniformLocations;
569
591
  }
570
592
  /**
571
593
  * Sets the value of a single float uniform variable.
@@ -574,7 +596,8 @@ export class WebGlContextWrapper {
574
596
  * @param v0 - The value to set.
575
597
  */
576
598
  uniform1f(location, v0) {
577
- this.gl.uniform1f(this.curUniformLocations[location] || null, v0);
599
+ const { gl } = this;
600
+ gl.uniform1f(location, v0);
578
601
  }
579
602
  /**
580
603
  * Sets the value of a float array uniform variable.
@@ -583,7 +606,8 @@ export class WebGlContextWrapper {
583
606
  * @param value - The array of values to set.
584
607
  */
585
608
  uniform1fv(location, value) {
586
- this.gl.uniform1fv(this.curUniformLocations[location] || null, value);
609
+ const { gl } = this;
610
+ gl.uniform1fv(location, value);
587
611
  }
588
612
  /**
589
613
  * Sets the value of a single integer uniform variable.
@@ -592,7 +616,8 @@ export class WebGlContextWrapper {
592
616
  * @param v0 - The value to set.
593
617
  */
594
618
  uniform1i(location, v0) {
595
- this.gl.uniform1i(this.curUniformLocations[location] || null, v0);
619
+ const { gl } = this;
620
+ gl.uniform1i(location, v0);
596
621
  }
597
622
  /**
598
623
  * Sets the value of an integer array uniform variable.
@@ -601,7 +626,8 @@ export class WebGlContextWrapper {
601
626
  * @param value - The array of values to set.
602
627
  */
603
628
  uniform1iv(location, value) {
604
- this.gl.uniform1iv(this.curUniformLocations[location] || null, value);
629
+ const { gl } = this;
630
+ gl.uniform1iv(location, value);
605
631
  }
606
632
  /**
607
633
  * Sets the value of a vec2 uniform variable.
@@ -611,16 +637,8 @@ export class WebGlContextWrapper {
611
637
  * @param v1 - The second component of the vector.
612
638
  */
613
639
  uniform2f(location, v0, v1) {
614
- this.gl.uniform2f(this.curUniformLocations[location] || null, v0, v1);
615
- }
616
- /**
617
- * Sets the value of a vec3 uniform variable.
618
- *
619
- * @param location - The location of the uniform variable.
620
- * @param v - array of 4 numbers.
621
- */
622
- uniform2fa(location, value) {
623
- this.gl.uniform2f(this.curUniformLocations[location] || null, value[0], value[1]);
640
+ const { gl } = this;
641
+ gl.uniform2f(location, v0, v1);
624
642
  }
625
643
  /**
626
644
  * Sets the value of a vec2 array uniform variable.
@@ -629,7 +647,8 @@ export class WebGlContextWrapper {
629
647
  * @param value - The array of vec2 values to set.
630
648
  */
631
649
  uniform2fv(location, value) {
632
- this.gl.uniform2fv(this.curUniformLocations[location] || null, value);
650
+ const { gl } = this;
651
+ gl.uniform2fv(location, value);
633
652
  }
634
653
  /**
635
654
  * Sets the value of a ivec2 uniform variable.
@@ -639,7 +658,8 @@ export class WebGlContextWrapper {
639
658
  * @param v1 - The second component of the vector.
640
659
  */
641
660
  uniform2i(location, v0, v1) {
642
- this.gl.uniform2i(this.curUniformLocations[location] || null, v0, v1);
661
+ const { gl } = this;
662
+ gl.uniform2i(location, v0, v1);
643
663
  }
644
664
  /**
645
665
  * Sets the value of an ivec2 array uniform variable.
@@ -648,7 +668,8 @@ export class WebGlContextWrapper {
648
668
  * @param value - The array of ivec2 values to set.
649
669
  */
650
670
  uniform2iv(location, value) {
651
- this.gl.uniform2iv(this.curUniformLocations[location] || null, value);
671
+ const { gl } = this;
672
+ gl.uniform2iv(location, value);
652
673
  }
653
674
  /**
654
675
  * Sets the value of a vec3 uniform variable.
@@ -659,16 +680,8 @@ export class WebGlContextWrapper {
659
680
  * @param v2 - The third component of the vector.
660
681
  */
661
682
  uniform3f(location, v0, v1, v2) {
662
- this.gl.uniform3f(this.curUniformLocations[location] || null, v0, v1, v2);
663
- }
664
- /**
665
- * Sets the value of a vec3 uniform variable.
666
- *
667
- * @param location - The location of the uniform variable.
668
- * @param v - array of 4 numbers.
669
- */
670
- uniform3fa(location, value) {
671
- this.gl.uniform3f(this.curUniformLocations[location] || null, value[0], value[1], value[2]);
683
+ const { gl } = this;
684
+ gl.uniform3f(location, v0, v1, v2);
672
685
  }
673
686
  /**
674
687
  * Sets the value of a vec3 array uniform variable.
@@ -677,7 +690,8 @@ export class WebGlContextWrapper {
677
690
  * @param value - The array of vec3 values to set.
678
691
  */
679
692
  uniform3fv(location, value) {
680
- this.gl.uniform3fv(this.curUniformLocations[location] || null, value);
693
+ const { gl } = this;
694
+ gl.uniform3fv(location, value);
681
695
  }
682
696
  /**
683
697
  * Sets the value of a ivec3 uniform variable.
@@ -688,7 +702,8 @@ export class WebGlContextWrapper {
688
702
  * @param v2 - The third component of the vector.
689
703
  */
690
704
  uniform3i(location, v0, v1, v2) {
691
- this.gl.uniform3i(this.curUniformLocations[location] || null, v0, v1, v2);
705
+ const { gl } = this;
706
+ gl.uniform3i(location, v0, v1, v2);
692
707
  }
693
708
  /**
694
709
  * Sets the value of an ivec3 array uniform variable.
@@ -697,7 +712,8 @@ export class WebGlContextWrapper {
697
712
  * @param value - The array of ivec3 values to set.
698
713
  */
699
714
  uniform3iv(location, value) {
700
- this.gl.uniform3iv(this.curUniformLocations[location] || null, value);
715
+ const { gl } = this;
716
+ gl.uniform3iv(location, value);
701
717
  }
702
718
  /**
703
719
  * Sets the value of a vec4 uniform variable.
@@ -709,16 +725,8 @@ export class WebGlContextWrapper {
709
725
  * @param v3 - The fourth component of the vector.
710
726
  */
711
727
  uniform4f(location, v0, v1, v2, v3) {
712
- this.gl.uniform4f(this.curUniformLocations[location] || null, v0, v1, v2, v3);
713
- }
714
- /**
715
- * Sets the value of a vec4 uniform variable.
716
- *
717
- * @param location - The location of the uniform variable.
718
- * @param v - array of 4 numbers.
719
- */
720
- uniform4fa(location, value) {
721
- this.gl.uniform4f(this.curUniformLocations[location] || null, value[0], value[1], value[2], value[3]);
728
+ const { gl } = this;
729
+ gl.uniform4f(location, v0, v1, v2, v3);
722
730
  }
723
731
  /**
724
732
  * Sets the value of a vec4 array uniform variable.
@@ -727,7 +735,8 @@ export class WebGlContextWrapper {
727
735
  * @param value - The array of vec4 values to set.
728
736
  */
729
737
  uniform4fv(location, value) {
730
- this.gl.uniform4fv(this.curUniformLocations[location] || null, value);
738
+ const { gl } = this;
739
+ gl.uniform4fv(location, value);
731
740
  }
732
741
  /**
733
742
  * Sets the value of a ivec4 uniform variable.
@@ -739,7 +748,8 @@ export class WebGlContextWrapper {
739
748
  * @param v3 - The fourth component of the vector.
740
749
  */
741
750
  uniform4i(location, v0, v1, v2, v3) {
742
- this.gl.uniform4i(this.curUniformLocations[location] || null, v0, v1, v2, v3);
751
+ const { gl } = this;
752
+ gl.uniform4i(location, v0, v1, v2, v3);
743
753
  }
744
754
  /**
745
755
  * Sets the value of an ivec4 array uniform variable.
@@ -748,7 +758,8 @@ export class WebGlContextWrapper {
748
758
  * @param value - The array of ivec4 values to set.
749
759
  */
750
760
  uniform4iv(location, value) {
751
- this.gl.uniform4iv(this.curUniformLocations[location] || null, value);
761
+ const { gl } = this;
762
+ gl.uniform4iv(location, value);
752
763
  }
753
764
  /**
754
765
  * Sets the value of a mat2 uniform variable.
@@ -758,7 +769,8 @@ export class WebGlContextWrapper {
758
769
  * @param value - The array of mat2 values to set.
759
770
  */
760
771
  uniformMatrix2fv(location, value) {
761
- this.gl.uniformMatrix2fv(this.curUniformLocations[location] || null, false, value);
772
+ const { gl } = this;
773
+ gl.uniformMatrix2fv(location, false, value);
762
774
  }
763
775
  /**
764
776
  * Sets the value of a mat2 uniform variable.
@@ -766,7 +778,8 @@ export class WebGlContextWrapper {
766
778
  * @param value - The array of mat2 values to set.
767
779
  */
768
780
  uniformMatrix3fv(location, value) {
769
- this.gl.uniformMatrix3fv(this.curUniformLocations[location] || null, false, value);
781
+ const { gl } = this;
782
+ gl.uniformMatrix3fv(location, false, value);
770
783
  }
771
784
  /**
772
785
  * Sets the value of a mat4 uniform variable.
@@ -774,7 +787,8 @@ export class WebGlContextWrapper {
774
787
  * @param value - The array of mat4 values to set.
775
788
  */
776
789
  uniformMatrix4fv(location, value) {
777
- this.gl.uniformMatrix4fv(this.curUniformLocations[location] || null, false, value);
790
+ const { gl } = this;
791
+ gl.uniformMatrix4fv(location, false, value);
778
792
  }
779
793
  /**
780
794
  * ```
@@ -785,7 +799,8 @@ export class WebGlContextWrapper {
785
799
  * @returns
786
800
  */
787
801
  getParameter(pname) {
788
- return this.gl.getParameter(pname);
802
+ const { gl } = this;
803
+ return gl.getParameter(pname);
789
804
  }
790
805
  /**
791
806
  * ```
@@ -798,19 +813,8 @@ export class WebGlContextWrapper {
798
813
  * @param offset
799
814
  */
800
815
  drawElements(mode, count, type, offset) {
801
- this.gl.drawElements(mode, count, type, offset);
802
- }
803
- /**
804
- * ```
805
- * gl.drawArrays(mode, first, count);
806
- * ```
807
- *
808
- * @param mode
809
- * @param first
810
- * @param count
811
- */
812
- drawArrays(mode, first, count) {
813
- this.gl.drawArrays(mode, first, count);
816
+ const { gl } = this;
817
+ gl.drawElements(mode, count, type, offset);
814
818
  }
815
819
  /**
816
820
  * ```
@@ -821,7 +825,8 @@ export class WebGlContextWrapper {
821
825
  * @returns
822
826
  */
823
827
  getExtension(name) {
824
- return this.gl.getExtension(name);
828
+ const { gl } = this;
829
+ return gl.getExtension(name);
825
830
  }
826
831
  /**
827
832
  * ```
@@ -831,7 +836,8 @@ export class WebGlContextWrapper {
831
836
  * @returns
832
837
  */
833
838
  getError() {
834
- return this.gl.getError();
839
+ const { gl } = this;
840
+ return gl.getError();
835
841
  }
836
842
  /**
837
843
  * ```
@@ -841,10 +847,9 @@ export class WebGlContextWrapper {
841
847
  * @returns
842
848
  */
843
849
  createVertexArray() {
844
- if (this.gl instanceof WebGL2RenderingContext) {
845
- return this.gl.createVertexArray();
846
- }
847
- return undefined;
850
+ const { gl } = this;
851
+ assertTruthy(gl instanceof WebGL2RenderingContext);
852
+ return gl.createVertexArray();
848
853
  }
849
854
  /**
850
855
  * ```
@@ -854,9 +859,9 @@ export class WebGlContextWrapper {
854
859
  * @param vertexArray
855
860
  */
856
861
  bindVertexArray(vertexArray) {
857
- if (this.gl instanceof WebGL2RenderingContext) {
858
- this.gl.bindVertexArray(vertexArray);
859
- }
862
+ const { gl } = this;
863
+ assertTruthy(gl instanceof WebGL2RenderingContext);
864
+ gl.bindVertexArray(vertexArray);
860
865
  }
861
866
  /**
862
867
  * ```
@@ -868,7 +873,8 @@ export class WebGlContextWrapper {
868
873
  * @returns
869
874
  */
870
875
  getAttribLocation(program, name) {
871
- return this.gl.getAttribLocation(program, name);
876
+ const { gl } = this;
877
+ return gl.getAttribLocation(program, name);
872
878
  }
873
879
  /**
874
880
  * ```
@@ -880,7 +886,8 @@ export class WebGlContextWrapper {
880
886
  * @returns
881
887
  */
882
888
  getUniformLocation(program, name) {
883
- return this.gl.getUniformLocation(program, name);
889
+ const { gl } = this;
890
+ return gl.getUniformLocation(program, name);
884
891
  }
885
892
  /**
886
893
  * ```
@@ -890,7 +897,8 @@ export class WebGlContextWrapper {
890
897
  * @param index
891
898
  */
892
899
  enableVertexAttribArray(index) {
893
- this.gl.enableVertexAttribArray(index);
900
+ const { gl } = this;
901
+ gl.enableVertexAttribArray(index);
894
902
  }
895
903
  /**
896
904
  * ```
@@ -900,7 +908,8 @@ export class WebGlContextWrapper {
900
908
  * @param index
901
909
  */
902
910
  disableVertexAttribArray(index) {
903
- this.gl.disableVertexAttribArray(index);
911
+ const { gl } = this;
912
+ gl.disableVertexAttribArray(index);
904
913
  }
905
914
  /**
906
915
  * ```
@@ -911,7 +920,8 @@ export class WebGlContextWrapper {
911
920
  * @returns
912
921
  */
913
922
  createShader(type) {
914
- return this.gl.createShader(type);
923
+ const { gl } = this;
924
+ return gl.createShader(type);
915
925
  }
916
926
  /**
917
927
  * ```
@@ -922,7 +932,8 @@ export class WebGlContextWrapper {
922
932
  * @returns
923
933
  */
924
934
  compileShader(shader) {
925
- this.gl.compileShader(shader);
935
+ const { gl } = this;
936
+ gl.compileShader(shader);
926
937
  }
927
938
  /**
928
939
  * ```
@@ -933,7 +944,8 @@ export class WebGlContextWrapper {
933
944
  * @param shader
934
945
  */
935
946
  attachShader(program, shader) {
936
- this.gl.attachShader(program, shader);
947
+ const { gl } = this;
948
+ gl.attachShader(program, shader);
937
949
  }
938
950
  /**
939
951
  * ```
@@ -943,7 +955,8 @@ export class WebGlContextWrapper {
943
955
  * @param program
944
956
  */
945
957
  linkProgram(program) {
946
- this.gl.linkProgram(program);
958
+ const { gl } = this;
959
+ gl.linkProgram(program);
947
960
  }
948
961
  /**
949
962
  * ```
@@ -953,7 +966,8 @@ export class WebGlContextWrapper {
953
966
  * @param shader
954
967
  */
955
968
  deleteProgram(shader) {
956
- this.gl.deleteProgram(shader);
969
+ const { gl } = this;
970
+ gl.deleteProgram(shader);
957
971
  }
958
972
  /**
959
973
  * ```
@@ -964,7 +978,8 @@ export class WebGlContextWrapper {
964
978
  * @param pname
965
979
  */
966
980
  getShaderParameter(shader, pname) {
967
- return this.gl.getShaderParameter(shader, pname);
981
+ const { gl } = this;
982
+ return gl.getShaderParameter(shader, pname);
968
983
  }
969
984
  /**
970
985
  * ```
@@ -974,7 +989,8 @@ export class WebGlContextWrapper {
974
989
  * @param shader
975
990
  */
976
991
  getShaderInfoLog(shader) {
977
- return this.gl.getShaderInfoLog(shader);
992
+ const { gl } = this;
993
+ return gl.getShaderInfoLog(shader);
978
994
  }
979
995
  /**
980
996
  * ```
@@ -984,7 +1000,8 @@ export class WebGlContextWrapper {
984
1000
  * @returns
985
1001
  */
986
1002
  createProgram() {
987
- return this.gl.createProgram();
1003
+ const { gl } = this;
1004
+ return gl.createProgram();
988
1005
  }
989
1006
  /**
990
1007
  * ```
@@ -996,7 +1013,8 @@ export class WebGlContextWrapper {
996
1013
  * @returns
997
1014
  */
998
1015
  getProgramParameter(program, pname) {
999
- return this.gl.getProgramParameter(program, pname);
1016
+ const { gl } = this;
1017
+ return gl.getProgramParameter(program, pname);
1000
1018
  }
1001
1019
  /**
1002
1020
  * ```
@@ -1007,7 +1025,8 @@ export class WebGlContextWrapper {
1007
1025
  * @returns
1008
1026
  */
1009
1027
  getProgramInfoLog(program) {
1010
- return this.gl.getProgramInfoLog(program);
1028
+ const { gl } = this;
1029
+ return gl.getProgramInfoLog(program);
1011
1030
  }
1012
1031
  /**
1013
1032
  * ```
@@ -1018,7 +1037,8 @@ export class WebGlContextWrapper {
1018
1037
  * @param source
1019
1038
  */
1020
1039
  shaderSource(shader, source) {
1021
- this.gl.shaderSource(shader, source);
1040
+ const { gl } = this;
1041
+ gl.shaderSource(shader, source);
1022
1042
  }
1023
1043
  /**
1024
1044
  * ```
@@ -1028,34 +1048,8 @@ export class WebGlContextWrapper {
1028
1048
  * @param shader
1029
1049
  */
1030
1050
  deleteShader(shader) {
1031
- this.gl.deleteShader(shader);
1032
- }
1033
- /**
1034
- * ```
1035
- * gl.deleteBuffer(buffer);
1036
- * ```
1037
- *
1038
- * @param buffer - The buffer to delete
1039
- */
1040
- deleteBuffer(buffer) {
1041
1051
  const { gl } = this;
1042
- gl.deleteBuffer(buffer);
1043
- // Reset bound buffers if they match the deleted buffer
1044
- if (this.boundArrayBuffer === buffer) {
1045
- this.boundArrayBuffer = null;
1046
- }
1047
- }
1048
- /**
1049
- * ```
1050
- * gl.deleteVertexArray(vertexArray);
1051
- * ```
1052
- *
1053
- * @param vertexArray - The vertex array object to delete
1054
- */
1055
- deleteVertexArray(vertexArray) {
1056
- if (this.isWebGl2()) {
1057
- this.gl.deleteVertexArray(vertexArray);
1058
- }
1052
+ gl.deleteShader(shader);
1059
1053
  }
1060
1054
  /**
1061
1055
  * Check for WebGL errors and return error information