@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.
- package/dist/src/core/CoreNode.d.ts +1 -1
- package/dist/src/core/CoreTextNode.js +8 -0
- package/dist/src/core/CoreTextNode.js.map +1 -1
- package/dist/src/core/lib/ImageWorker.d.ts +2 -2
- package/dist/src/core/lib/ImageWorker.js +12 -31
- package/dist/src/core/lib/ImageWorker.js.map +1 -1
- package/dist/src/core/lib/WebGlContextWrapper.d.ts +60 -109
- package/dist/src/core/lib/WebGlContextWrapper.js +158 -164
- package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
- package/dist/src/core/lib/textureCompression.js +10 -19
- package/dist/src/core/lib/textureCompression.js.map +1 -1
- package/dist/src/core/lib/validateImageBitmap.d.ts +1 -2
- package/dist/src/core/lib/validateImageBitmap.js +4 -4
- package/dist/src/core/lib/validateImageBitmap.js.map +1 -1
- package/dist/src/core/platform.js +5 -2
- package/dist/src/core/platform.js.map +1 -1
- package/dist/src/core/platforms/web/WebGlContextWrapper.d.ts +5 -5
- package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.d.ts +1 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js +2 -0
- package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js.map +1 -0
- package/dist/src/core/renderers/webgl/WebGlRenderer.js +5 -3
- package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +4 -1
- package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
- package/dist/src/core/renderers/webgl/internal/RendererUtils.js +1 -2
- package/dist/src/core/renderers/webgl/internal/RendererUtils.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.d.ts +0 -1
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +14 -35
- package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js.map +1 -1
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +8 -25
- package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js.map +1 -1
- package/dist/src/core/text-rendering/SdfFontHandler.js +5 -7
- package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -1
- package/dist/tsconfig.dist.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/core/CoreTextNode.ts +9 -0
- package/src/core/renderers/webgl/WebGlCtxTexture.test.ts +113 -0
- package/src/core/renderers/webgl/WebGlRenderer.ts +4 -3
- package/src/core/renderers/webgl/WebGlShaderProgram.ts +3 -1
- package/src/core/renderers/webgl/internal/RendererUtils.ts +1 -2
- package/src/core/text-rendering/SdfFontHandler.ts +5 -8
- package/dist/src/core/AutosizeManager.d.ts +0 -29
- package/dist/src/core/AutosizeManager.js +0 -169
- package/dist/src/core/AutosizeManager.js.map +0 -1
- package/dist/src/core/animations/Animation.d.ts +0 -21
- package/dist/src/core/animations/Animation.js +0 -194
- package/dist/src/core/animations/Animation.js.map +0 -1
- package/dist/src/core/animations/Playback.d.ts +0 -64
- package/dist/src/core/animations/Playback.js +0 -169
- package/dist/src/core/animations/Playback.js.map +0 -1
- package/dist/src/core/animations/Transition.d.ts +0 -27
- package/dist/src/core/animations/Transition.js +0 -52
- package/dist/src/core/animations/Transition.js.map +0 -1
- package/dist/src/core/animations/utils.d.ts +0 -2
- package/dist/src/core/animations/utils.js +0 -136
- package/dist/src/core/animations/utils.js.map +0 -1
- package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +0 -45
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js +0 -127
- package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +0 -1
- package/dist/src/core/shaders/webgl/SdfShadowShader.d.ts +0 -9
- package/dist/src/core/shaders/webgl/SdfShadowShader.js +0 -100
- package/dist/src/core/shaders/webgl/SdfShadowShader.js.map +0 -1
- package/dist/src/core/text-rendering/CanvasFont.d.ts +0 -14
- package/dist/src/core/text-rendering/CanvasFont.js +0 -111
- package/dist/src/core/text-rendering/CanvasFont.js.map +0 -1
- package/dist/src/core/text-rendering/CoreFont.d.ts +0 -33
- package/dist/src/core/text-rendering/CoreFont.js +0 -48
- package/dist/src/core/text-rendering/CoreFont.js.map +0 -1
- package/dist/src/core/text-rendering/FontManager.d.ts +0 -11
- package/dist/src/core/text-rendering/FontManager.js +0 -42
- package/dist/src/core/text-rendering/FontManager.js.map +0 -1
- package/dist/src/core/text-rendering/SdfFont.d.ts +0 -29
- package/dist/src/core/text-rendering/SdfFont.js +0 -142
- package/dist/src/core/text-rendering/SdfFont.js.map +0 -1
- 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
|
|
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
|
-
|
|
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
|
-
|
|
197
|
+
const { gl, activeTextureUnit, texture2dUnits } = this;
|
|
198
|
+
if (texture2dUnits[activeTextureUnit] === texture) {
|
|
198
199
|
return;
|
|
199
200
|
}
|
|
200
|
-
|
|
201
|
-
|
|
201
|
+
texture2dUnits[activeTextureUnit] = texture;
|
|
202
|
+
gl.bindTexture(this.gl.TEXTURE_2D, texture);
|
|
202
203
|
}
|
|
203
204
|
_getActiveTexture() {
|
|
204
|
-
|
|
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 =
|
|
225
|
+
let textureParams = texture2dParams.get(activeTexture);
|
|
223
226
|
if (!textureParams) {
|
|
224
227
|
textureParams = {};
|
|
225
|
-
|
|
228
|
+
texture2dParams.set(activeTexture, textureParams);
|
|
226
229
|
}
|
|
227
230
|
if (textureParams[pname] === param) {
|
|
228
231
|
return;
|
|
229
232
|
}
|
|
230
233
|
textureParams[pname] = param;
|
|
231
|
-
|
|
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
|
-
|
|
239
|
+
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, widthOrFormat, heightOrType, borderOrSource, format, type, pixels);
|
|
236
240
|
}
|
|
237
241
|
else {
|
|
238
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
345
|
+
const { gl, scissorEnabled } = this;
|
|
346
|
+
if (enable === scissorEnabled) {
|
|
335
347
|
return;
|
|
336
348
|
}
|
|
337
349
|
if (enable) {
|
|
338
|
-
|
|
350
|
+
gl.enable(gl.SCISSOR_TEST);
|
|
339
351
|
}
|
|
340
352
|
else {
|
|
341
|
-
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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
|
-
|
|
389
|
+
const { gl, blendEnabled } = this;
|
|
390
|
+
if (blend === blendEnabled) {
|
|
377
391
|
return;
|
|
378
392
|
}
|
|
379
393
|
if (blend) {
|
|
380
|
-
|
|
394
|
+
gl.enable(gl.BLEND);
|
|
381
395
|
}
|
|
382
396
|
else {
|
|
383
|
-
|
|
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
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
473
|
-
|
|
491
|
+
const { gl, boundArrayBuffer } = this;
|
|
492
|
+
if (boundArrayBuffer !== buffer) {
|
|
493
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
474
494
|
this.boundArrayBuffer = buffer;
|
|
475
495
|
}
|
|
476
|
-
|
|
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
|
-
|
|
492
|
-
|
|
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
|
-
|
|
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
|
-
|
|
516
|
-
|
|
536
|
+
const { gl, boundArrayBuffer } = this;
|
|
537
|
+
if (boundArrayBuffer !== buffer) {
|
|
538
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
517
539
|
this.boundArrayBuffer = buffer;
|
|
518
540
|
}
|
|
519
|
-
|
|
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
|
|
563
|
-
|
|
584
|
+
useProgram(program) {
|
|
585
|
+
const { gl, curProgram } = this;
|
|
586
|
+
if (curProgram === program) {
|
|
564
587
|
return;
|
|
565
588
|
}
|
|
566
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
845
|
-
|
|
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
|
-
|
|
858
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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
|