@lightningjs/renderer 3.0.0-beta1 → 3.0.0-beta2

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 (60) hide show
  1. package/dist/src/core/CoreNode.d.ts +1 -0
  2. package/dist/src/core/CoreNode.js +17 -13
  3. package/dist/src/core/CoreNode.js.map +1 -1
  4. package/dist/src/core/CoreTextNode.js +0 -7
  5. package/dist/src/core/CoreTextNode.js.map +1 -1
  6. package/dist/src/core/Stage.js +2 -4
  7. package/dist/src/core/Stage.js.map +1 -1
  8. package/dist/src/core/lib/ImageWorker.js +2 -1
  9. package/dist/src/core/lib/ImageWorker.js.map +1 -1
  10. package/dist/src/core/lib/RenderCoords.d.ts +9 -10
  11. package/dist/src/core/lib/RenderCoords.js +43 -55
  12. package/dist/src/core/lib/RenderCoords.js.map +1 -1
  13. package/dist/src/core/lib/WebGlContextWrapper.d.ts +22 -0
  14. package/dist/src/core/lib/WebGlContextWrapper.js +27 -0
  15. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  16. package/dist/src/core/lib/utils.d.ts +1 -0
  17. package/dist/src/core/lib/utils.js +20 -0
  18. package/dist/src/core/lib/utils.js.map +1 -1
  19. package/dist/src/core/renderers/CoreShaderNode.d.ts +1 -2
  20. package/dist/src/core/renderers/CoreShaderNode.js +0 -3
  21. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -1
  22. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -1
  23. package/dist/src/core/renderers/canvas/CanvasTexture.js +3 -2
  24. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -1
  25. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +10 -2
  26. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +27 -16
  27. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -1
  28. package/dist/src/core/renderers/webgl/WebGlRenderer.js +14 -13
  29. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -1
  30. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +2 -1
  31. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -1
  32. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +1 -1
  33. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +32 -26
  34. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -1
  35. package/dist/src/core/shaders/webgl/SdfShader.js +1 -1
  36. package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -1
  37. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js +0 -1
  38. package/dist/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.js.map +1 -1
  39. package/dist/src/core/textures/ImageTexture.d.ts +2 -2
  40. package/dist/src/core/textures/ImageTexture.js +24 -4
  41. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  42. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  43. package/package.json +1 -1
  44. package/src/core/CoreNode.ts +24 -14
  45. package/src/core/CoreTextNode.ts +0 -9
  46. package/src/core/Stage.ts +2 -4
  47. package/src/core/lib/ImageWorker.ts +2 -1
  48. package/src/core/lib/RenderCoords.ts +52 -67
  49. package/src/core/lib/WebGlContextWrapper.ts +50 -0
  50. package/src/core/lib/utils.ts +25 -0
  51. package/src/core/renderers/CoreShaderNode.ts +1 -5
  52. package/src/core/renderers/canvas/CanvasRenderer.ts +0 -1
  53. package/src/core/renderers/canvas/CanvasTexture.ts +5 -2
  54. package/src/core/renderers/webgl/WebGlRenderOp.ts +32 -16
  55. package/src/core/renderers/webgl/WebGlRenderer.ts +22 -17
  56. package/src/core/renderers/webgl/WebGlShaderNode.ts +5 -1
  57. package/src/core/renderers/webgl/WebGlShaderProgram.ts +39 -31
  58. package/src/core/shaders/webgl/SdfShader.ts +1 -4
  59. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +0 -1
  60. package/src/core/textures/ImageTexture.ts +31 -8
@@ -3,6 +3,11 @@
3
3
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
4
4
 
5
5
  import { assertTruthy } from '../../utils.js';
6
+ import type {
7
+ Vec2,
8
+ Vec3,
9
+ Vec4,
10
+ } from '../renderers/webgl/internal/ShaderUtils.js';
6
11
  import { isWebGl2 } from '../renderers/webgl/internal/WebGlUtils.js';
7
12
 
8
13
  /**
@@ -800,6 +805,20 @@ export class WebGlContextWrapper {
800
805
  );
801
806
  }
802
807
 
808
+ /**
809
+ * Sets the value of a vec3 uniform variable.
810
+ *
811
+ * @param location - The location of the uniform variable.
812
+ * @param v - array of 4 numbers.
813
+ */
814
+ uniform2fa(location: string, value: Vec2) {
815
+ this.gl.uniform2f(
816
+ this.gl.getUniformLocation(this.curProgram!, location),
817
+ value[0],
818
+ value[1],
819
+ );
820
+ }
821
+
803
822
  /**
804
823
  * Sets the value of a vec2 array uniform variable.
805
824
  *
@@ -858,6 +877,21 @@ export class WebGlContextWrapper {
858
877
  );
859
878
  }
860
879
 
880
+ /**
881
+ * Sets the value of a vec3 uniform variable.
882
+ *
883
+ * @param location - The location of the uniform variable.
884
+ * @param v - array of 4 numbers.
885
+ */
886
+ uniform3fa(location: string, value: Vec3) {
887
+ this.gl.uniform3f(
888
+ this.gl.getUniformLocation(this.curProgram!, location),
889
+ value[0],
890
+ value[1],
891
+ value[2],
892
+ );
893
+ }
894
+
861
895
  /**
862
896
  * Sets the value of a vec3 array uniform variable.
863
897
  *
@@ -920,6 +954,22 @@ export class WebGlContextWrapper {
920
954
  );
921
955
  }
922
956
 
957
+ /**
958
+ * Sets the value of a vec4 uniform variable.
959
+ *
960
+ * @param location - The location of the uniform variable.
961
+ * @param v - array of 4 numbers.
962
+ */
963
+ uniform4fa(location: string, value: Vec4) {
964
+ this.gl.uniform4f(
965
+ this.gl.getUniformLocation(this.curProgram!, location),
966
+ value[0],
967
+ value[1],
968
+ value[2],
969
+ value[3],
970
+ );
971
+ }
972
+
923
973
  /**
924
974
  * Sets the value of a vec4 array uniform variable.
925
975
  *
@@ -359,3 +359,28 @@ export function calcFactoredRadiusArray(
359
359
  result[3] *= factor;
360
360
  return result;
361
361
  }
362
+
363
+ export function dataURIToBlob(dataURI: string): Blob {
364
+ dataURI = dataURI.replace(/^data:/, '');
365
+
366
+ const type = dataURI.match(/image\/[^;]+/)?.[0] || '';
367
+ const base64 = dataURI.replace(/^[^,]+,/, '');
368
+
369
+ const sliceSize = 1024;
370
+ const byteCharacters = atob(base64);
371
+ const bytesLength = byteCharacters.length;
372
+ const slicesCount = Math.ceil(bytesLength / sliceSize);
373
+ const byteArrays = new Array(slicesCount);
374
+
375
+ for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
376
+ const begin = sliceIndex * sliceSize;
377
+ const end = Math.min(begin + sliceSize, bytesLength);
378
+
379
+ const bytes = new Array(end - begin);
380
+ for (let offset = begin, i = 0; offset < end; ++i, ++offset) {
381
+ bytes[i] = byteCharacters[offset]?.charCodeAt(0);
382
+ }
383
+ byteArrays[sliceIndex] = new Uint8Array(bytes);
384
+ }
385
+ return new Blob(byteArrays, { type });
386
+ }
@@ -88,7 +88,7 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
88
88
  readonly stage: Stage;
89
89
  readonly shaderType: CoreShaderType<Props>;
90
90
  protected propsConfig: ShaderProps<Props> | undefined;
91
- protected resolvedProps: Props | undefined = undefined;
91
+ readonly resolvedProps: Props | undefined = undefined;
92
92
  protected definedProps: Props | undefined = undefined;
93
93
  protected node: CoreNode | null = null;
94
94
  update: (() => void) | undefined = undefined;
@@ -152,10 +152,6 @@ export class CoreShaderNode<Props extends object = Record<string, unknown>> {
152
152
  this.node = node;
153
153
  }
154
154
 
155
- getResolvedProps() {
156
- return this.resolvedProps;
157
- }
158
-
159
155
  get props(): Props | undefined {
160
156
  return this.definedProps;
161
157
  }
@@ -33,7 +33,6 @@ import {
33
33
  } from './internal/ColorUtils.js';
34
34
  import { assertTruthy } from '../../../utils.js';
35
35
  import { CanvasShaderNode, type CanvasShaderType } from './CanvasShaderNode.js';
36
- import type { CoreShaderType } from '../CoreShaderNode.js';
37
36
 
38
37
  export class CanvasRenderer extends CoreRenderer {
39
38
  private context: CanvasRenderingContext2D;
@@ -64,8 +64,11 @@ export class CanvasTexture extends CoreContextTexture {
64
64
  // - tinted image
65
65
  const mult = this.tintCache ? 8 : 4;
66
66
  if (this.textureSource.dimensions) {
67
- const { width, height } = this.textureSource.dimensions;
68
- this.setTextureMemUse(width * height * mult);
67
+ this.setTextureMemUse(
68
+ this.textureSource.dimensions.width *
69
+ this.textureSource.dimensions.height *
70
+ mult,
71
+ );
69
72
  }
70
73
  }
71
74
 
@@ -24,6 +24,8 @@ import type { BufferCollection } from './internal/BufferCollection.js';
24
24
  import type { WebGlShaderNode } from './WebGlShaderNode.js';
25
25
  import type { QuadOptions } from '../CoreRenderer.js';
26
26
  import type { CoreTextNode } from '../../CoreTextNode.js';
27
+ import type { RectWithValid } from '../../lib/utils.js';
28
+ import type { Dimensions } from '../../../common/CommonTypes.js';
27
29
 
28
30
  type ReqQuad =
29
31
  | 'alpha'
@@ -44,7 +46,6 @@ type RenderOpQuadOptions = Pick<QuadOptions, ReqQuad> &
44
46
  *
45
47
  */
46
48
  export class WebGlRenderOp extends CoreRenderOp {
47
- length = 0;
48
49
  numQuads = 0;
49
50
  textures: WebGlCtxTexture[] = [];
50
51
 
@@ -56,15 +57,32 @@ export class WebGlRenderOp extends CoreRenderOp {
56
57
  readonly maxTextures: number;
57
58
  readonly buffers: BufferCollection;
58
59
  readonly shader: WebGlShaderNode;
60
+ readonly width: number;
61
+ readonly height: number;
62
+ readonly clippingRect: RectWithValid;
63
+ readonly rtt: boolean;
64
+ readonly parentHasRenderTexture: boolean;
65
+ readonly framebufferDimensions?: Dimensions;
66
+ readonly alpha: number;
67
+ readonly pixelRatio: number;
59
68
 
60
69
  constructor(
61
70
  readonly renderer: WebGlRenderer,
62
- readonly quad: RenderOpQuadOptions,
71
+ quad: RenderOpQuadOptions,
63
72
  readonly bufferIdx: number,
64
73
  ) {
65
74
  super();
66
75
  this.buffers = quad.sdfBuffers || renderer.quadBufferCollection;
67
76
  this.shader = quad.shader as WebGlShaderNode;
77
+ this.width = quad.width;
78
+ this.height = quad.height;
79
+ this.clippingRect = quad.clippingRect;
80
+ this.parentHasRenderTexture = quad.parentHasRenderTexture;
81
+ this.framebufferDimensions = quad.framebufferDimensions;
82
+ this.rtt = quad.rtt;
83
+ this.alpha = quad.alpha;
84
+ this.pixelRatio =
85
+ this.parentHasRenderTexture === true ? 1 : renderer.stage.pixelRatio;
68
86
 
69
87
  /**
70
88
  * related to line 51
@@ -110,22 +128,20 @@ export class WebGlRenderOp extends CoreRenderOp {
110
128
  // TODO: Reduce calculations required
111
129
  const quadIdx = (this.bufferIdx / 32) * 6 * 2;
112
130
  // Clipping
113
- if (this.quad.clippingRect.valid) {
114
- const { x, y, width, height } = this.quad.clippingRect;
115
- const pixelRatio = this.quad.parentHasRenderTexture
116
- ? 1
117
- : stage.pixelRatio;
118
- const canvasHeight = options.canvas.height;
119
-
120
- const clipX = Math.round(x * pixelRatio);
121
- const clipWidth = Math.round(width * pixelRatio);
122
- const clipHeight = Math.round(height * pixelRatio);
123
- let clipY = Math.round(canvasHeight - clipHeight - y * pixelRatio);
131
+ if (this.clippingRect.valid === true) {
132
+ const clipX = Math.round(this.clippingRect.x * this.pixelRatio);
133
+ const clipWidth = Math.round(this.clippingRect.width * this.pixelRatio);
134
+ const clipHeight = Math.round(this.clippingRect.height * this.pixelRatio);
135
+ let clipY = Math.round(
136
+ options.canvas.height -
137
+ clipHeight -
138
+ this.clippingRect.y * this.pixelRatio,
139
+ );
124
140
  // if parent has render texture, we need to adjust the scissor rect
125
141
  // to be relative to the parent's framebuffer
126
- if (this.quad.parentHasRenderTexture) {
127
- clipY = this.quad.framebufferDimensions
128
- ? this.quad.framebufferDimensions.height - this.quad.height
142
+ if (this.parentHasRenderTexture) {
143
+ clipY = this.framebufferDimensions
144
+ ? this.framebufferDimensions.height - this.height
129
145
  : 0;
130
146
  }
131
147
 
@@ -50,7 +50,7 @@ import type { WebGlShaderType } from './WebGlShaderNode.js';
50
50
  import { WebGlShaderNode } from './WebGlShaderNode.js';
51
51
  import type { CoreShaderType } from '../CoreShaderNode.js';
52
52
 
53
- const WORDS_PER_QUAD = 24;
53
+ const WORDS_PER_QUAD = 32;
54
54
  // const BYTES_PER_QUAD = WORDS_PER_QUAD * 4;
55
55
 
56
56
  export type WebGlRendererOptions = CoreRendererOptions;
@@ -252,12 +252,10 @@ export class WebGlRenderer extends CoreRenderer {
252
252
 
253
253
  assertTruthy(texture !== null, 'Texture is required');
254
254
 
255
- let { curBufferIdx: bufferIdx, curRenderOp } = this;
255
+ let { curBufferIdx: bufferIdx } = this;
256
256
 
257
257
  if (this.reuseRenderOp(params) === false) {
258
258
  this.newRenderOp(params, bufferIdx);
259
- curRenderOp = this.curRenderOp;
260
- assertTruthy(curRenderOp);
261
259
  }
262
260
 
263
261
  let texCoordX1 = 0;
@@ -374,7 +372,6 @@ export class WebGlRenderer extends CoreRenderer {
374
372
  fQuadBuffer[bufferIdx++] = 1; //node y coord
375
373
 
376
374
  // Update the length of the current render op
377
- this.curRenderOp.length += WORDS_PER_QUAD;
378
375
  this.curRenderOp.numQuads++;
379
376
  this.curBufferIdx = bufferIdx;
380
377
  }
@@ -386,7 +383,7 @@ export class WebGlRenderer extends CoreRenderer {
386
383
  * @param shader
387
384
  * @param bufferIdx
388
385
  */
389
- private newRenderOp(quad: QuadOptions, bufferIdx: number) {
386
+ private newRenderOp(quad: QuadOptions | WebGlRenderOp, bufferIdx: number) {
390
387
  const curRenderOp = new WebGlRenderOp(this, quad, bufferIdx);
391
388
  this.curRenderOp = curRenderOp;
392
389
  this.renderOps.push(curRenderOp);
@@ -416,7 +413,7 @@ export class WebGlRenderer extends CoreRenderer {
416
413
  if (recursive) {
417
414
  throw new Error('Unable to add texture to render op');
418
415
  }
419
- this.newRenderOp(this.curRenderOp.quad as QuadOptions, bufferIdx);
416
+ this.newRenderOp(this.curRenderOp, bufferIdx);
420
417
  return this.addTexture(texture, bufferIdx, true);
421
418
  }
422
419
  return textureIdx;
@@ -428,19 +425,17 @@ export class WebGlRenderer extends CoreRenderer {
428
425
  * @returns
429
426
  */
430
427
  reuseRenderOp(params: QuadOptions): boolean {
431
- const { shader, parentHasRenderTexture, rtt, clippingRect } = params;
432
-
433
428
  // Switching shader program will require a new render operation
434
429
  if (
435
430
  this.curRenderOp?.shader.shaderKey !==
436
- (shader as WebGlShaderNode).shaderKey
431
+ (params.shader as WebGlShaderNode).shaderKey
437
432
  ) {
438
433
  return false;
439
434
  }
440
435
 
441
436
  // Switching clipping rect will require a new render operation
442
437
  if (
443
- compareRect(this.curRenderOp.quad.clippingRect, clippingRect) === false
438
+ compareRect(this.curRenderOp.clippingRect, params.clippingRect) === false
444
439
  ) {
445
440
  return false;
446
441
  }
@@ -448,16 +443,26 @@ export class WebGlRenderer extends CoreRenderer {
448
443
  // Force new render operation if rendering to texture
449
444
  // @todo: This needs to be improved, render operations could also be reused
450
445
  // for rendering to texture
451
- if (parentHasRenderTexture !== undefined || rtt !== undefined) {
446
+ if (
447
+ params.parentHasRenderTexture !== undefined ||
448
+ params.rtt !== undefined
449
+ ) {
452
450
  return false;
453
451
  }
454
452
 
453
+ if (
454
+ this.curRenderOp.shader.shaderKey === 'default' &&
455
+ params.shader?.shaderKey === 'default'
456
+ ) {
457
+ return true;
458
+ }
459
+
455
460
  // Check if the shader can batch the shader properties
456
461
  if (
457
- !this.curRenderOp.shader.program.reuseRenderOp(
462
+ this.curRenderOp.shader.program.reuseRenderOp(
458
463
  params,
459
- this.curRenderOp.quad as QuadOptions,
460
- )
464
+ this.curRenderOp,
465
+ ) === false
461
466
  ) {
462
467
  return false;
463
468
  }
@@ -682,9 +687,9 @@ export class WebGlRenderer extends CoreRenderer {
682
687
  if (this.defaultShaderNode !== null) {
683
688
  return this.defaultShaderNode as WebGlShaderNode;
684
689
  }
685
- this.stage.shManager.registerShaderType('Default', Default);
690
+ this.stage.shManager.registerShaderType('default', Default);
686
691
  this.defaultShaderNode = this.stage.shManager.createShader(
687
- 'Default',
692
+ 'default',
688
693
  ) as WebGlShaderNode;
689
694
  return this.defaultShaderNode;
690
695
  }
@@ -11,6 +11,7 @@ import type {
11
11
  Vec4,
12
12
  } from './internal/ShaderUtils.js';
13
13
  import type { WebGlRenderer } from './WebGlRenderer.js';
14
+ import type { WebGlRenderOp } from './WebGlRenderOp.js';
14
15
  import type { WebGlShaderProgram } from './WebGlShaderProgram.js';
15
16
 
16
17
  export type ShaderSource<T> =
@@ -46,7 +47,10 @@ export type WebGlShaderType<T extends object = Record<string, unknown>> =
46
47
  * This function is used to check if the shader can be reused based on quad info
47
48
  * @param props
48
49
  */
49
- canBatch?: (renderOpA: QuadOptions, renderOpB: QuadOptions) => boolean;
50
+ canBatch?: (
51
+ incomingQuad: QuadOptions,
52
+ currentRenderOp: WebGlRenderOp,
53
+ ) => boolean;
50
54
  /**
51
55
  * extensions required for specific shader?
52
56
  */
@@ -141,31 +141,45 @@ export class WebGlShaderProgram implements CoreShaderProgram {
141
141
  }
142
142
  }
143
143
 
144
- reuseRenderOp(renderOpA: QuadOptions, renderOpB: QuadOptions): boolean {
145
- const lifecycleCheck = this.lifecycle.canBatch
146
- ? this.lifecycle.canBatch(renderOpA, renderOpB)
147
- : true;
148
- if (!lifecycleCheck) {
149
- return false;
144
+ reuseRenderOp(
145
+ incomingQuad: QuadOptions,
146
+ currentRenderOp: WebGlRenderOp,
147
+ ): boolean {
148
+ if (this.lifecycle.canBatch !== undefined) {
149
+ return this.lifecycle.canBatch(incomingQuad, currentRenderOp);
150
150
  }
151
151
 
152
- if (this.useSystemAlpha) {
153
- if (renderOpA.alpha !== renderOpB.alpha) {
152
+ if (this.useSystemAlpha === true) {
153
+ if (incomingQuad.alpha !== currentRenderOp.alpha) {
154
154
  return false;
155
155
  }
156
156
  }
157
157
 
158
- if (this.useSystemDimensions) {
158
+ if (this.useSystemDimensions === true) {
159
159
  if (
160
- renderOpA.width !== renderOpB.width ||
161
- renderOpA.height !== renderOpB.height
160
+ incomingQuad.width !== currentRenderOp.width ||
161
+ incomingQuad.height !== currentRenderOp.height
162
162
  ) {
163
163
  return false;
164
164
  }
165
165
  }
166
+ let shaderPropsA: Record<string, unknown> | undefined = undefined;
167
+ let shaderPropsB: Record<string, unknown> | undefined = undefined;
168
+
169
+ if (incomingQuad.shader !== null) {
170
+ shaderPropsA = incomingQuad.shader.resolvedProps;
171
+ }
172
+ if (currentRenderOp.shader !== null) {
173
+ shaderPropsB = currentRenderOp.shader.resolvedProps;
174
+ }
175
+
176
+ if (
177
+ (shaderPropsA === undefined && shaderPropsB !== undefined) ||
178
+ (shaderPropsA !== undefined && shaderPropsB === undefined)
179
+ ) {
180
+ return false;
181
+ }
166
182
 
167
- const shaderPropsA = renderOpA.shader?.getResolvedProps();
168
- const shaderPropsB = renderOpB.shader?.getResolvedProps();
169
183
  if (shaderPropsA !== undefined && shaderPropsB !== undefined) {
170
184
  for (const key in shaderPropsA) {
171
185
  if (shaderPropsA[key] !== shaderPropsB[key]) {
@@ -181,17 +195,17 @@ export class WebGlShaderProgram implements CoreShaderProgram {
181
195
  this.bindBufferCollection(renderOp.buffers);
182
196
  this.bindTextures(renderOp.textures);
183
197
 
184
- const { parentHasRenderTexture } = renderOp.quad;
198
+ const { parentHasRenderTexture } = renderOp;
185
199
 
186
200
  // Skip if the parent and current operation both have render textures
187
- if (renderOp.quad.rtt && parentHasRenderTexture) {
201
+ if (renderOp.rtt === true && parentHasRenderTexture === true) {
188
202
  return;
189
203
  }
190
204
 
191
205
  // Bind render texture framebuffer dimensions as resolution
192
206
  // if the parent has a render texture
193
- if (parentHasRenderTexture) {
194
- const { width, height } = renderOp.quad.framebufferDimensions!;
207
+ if (parentHasRenderTexture === true) {
208
+ const { width, height } = renderOp.framebufferDimensions!;
195
209
  // Force pixel ratio to 1.0 for render textures since they are always 1:1
196
210
  // the final render texture will be rendered to the screen with the correct pixel ratio
197
211
  this.glw.uniform1f('u_pixelRatio', 1.0);
@@ -207,19 +221,13 @@ export class WebGlShaderProgram implements CoreShaderProgram {
207
221
  );
208
222
  }
209
223
 
210
- this.glw.uniform1f('u_rtt', renderOp.quad.rtt ? 1 : 0);
211
-
212
- if (this.useSystemAlpha) {
213
- this.glw.uniform1f('u_alpha', renderOp.quad.alpha);
214
- }
224
+ // if (this.useSystemAlpha) {
225
+ this.glw.uniform1f('u_alpha', renderOp.alpha);
226
+ // }
215
227
 
216
- if (this.useSystemDimensions) {
217
- this.glw.uniform2f(
218
- 'u_dimensions',
219
- renderOp.quad.width,
220
- renderOp.quad.height,
221
- );
222
- }
228
+ // if (this.useSystemDimensions) {
229
+ this.glw.uniform2f('u_dimensions', renderOp.width, renderOp.height);
230
+ // }
223
231
 
224
232
  /**temporary fix to make sdf texts work */
225
233
  if (renderOp.sdfShaderProps !== undefined) {
@@ -230,7 +238,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
230
238
  return;
231
239
  }
232
240
 
233
- if (renderOp.shader.props) {
241
+ if (renderOp.shader.props !== undefined) {
234
242
  /**
235
243
  * loop over all precalculated uniform types
236
244
  */
@@ -276,7 +284,7 @@ export class WebGlShaderProgram implements CoreShaderProgram {
276
284
  const name = attribs[i]!;
277
285
  const resolvedBuffer = buffer.getBuffer(name);
278
286
  const resolvedInfo = buffer.getAttributeInfo(name);
279
- if (!resolvedBuffer || !resolvedInfo) {
287
+ if (resolvedBuffer === undefined || resolvedInfo === undefined) {
280
288
  continue;
281
289
  }
282
290
  glw.enableVertexAttribArray(i);
@@ -62,10 +62,7 @@ export const Sdf: WebGlShaderType<SdfShaderProps> = {
62
62
  onSdfBind(props) {
63
63
  this.uniformMatrix3fv('u_transform', props.transform);
64
64
  this.uniform1f('u_scrollY', props.scrollY);
65
- this.uniform4fv(
66
- 'u_color',
67
- new Float32Array(getNormalizedRgbaComponents(props.color)),
68
- );
65
+ this.uniform4fa('u_color', getNormalizedRgbaComponents(props.color));
69
66
  this.uniform1f('u_size', props.size);
70
67
  this.uniform1f('u_distanceRange', props.distanceRange);
71
68
  this.uniform1i('u_debug', props.debug ? 1 : 0);
@@ -712,7 +712,6 @@ export class SdfTextRenderer extends TextRenderer<SdfTextRendererState> {
712
712
  const ctxTexture = texture.ctxTexture;
713
713
 
714
714
  renderOp.addTexture(ctxTexture as WebGlCtxTexture);
715
- renderOp.length = state.bufferNumFloats;
716
715
  renderOp.numQuads = state.bufferNumQuads;
717
716
 
718
717
  renderer.addRenderOp(renderOp);
@@ -23,7 +23,11 @@ import {
23
23
  isCompressedTextureContainer,
24
24
  loadCompressedTexture,
25
25
  } from '../lib/textureCompression.js';
26
- import { convertUrlToAbsolute, isBase64Image } from '../lib/utils.js';
26
+ import {
27
+ convertUrlToAbsolute,
28
+ dataURIToBlob,
29
+ isBase64Image,
30
+ } from '../lib/utils.js';
27
31
  import { isSvgImage, loadSvg } from '../lib/textureSvg.js';
28
32
  import { fetchJson } from '../text-rendering/font-face-types/utils.js';
29
33
 
@@ -40,7 +44,7 @@ export interface ImageTextureProps {
40
44
  *
41
45
  * @default ''
42
46
  */
43
- src?: string | ImageData | (() => ImageData | null);
47
+ src?: string | Blob | ImageData | (() => ImageData | null);
44
48
  /**
45
49
  * Whether to premultiply the alpha channel into the color channels of the
46
50
  * image.
@@ -133,10 +137,10 @@ export class ImageTexture extends Texture {
133
137
  return mimeType.indexOf('image/png') !== -1;
134
138
  }
135
139
 
136
- async loadImageFallback(src: string, hasAlpha: boolean) {
140
+ async loadImageFallback(src: string | Blob, hasAlpha: boolean) {
137
141
  const img = new Image();
138
142
 
139
- if (isBase64Image(src) === false) {
143
+ if (typeof src === 'string' && isBase64Image(src) === false) {
140
144
  img.crossOrigin = 'anonymous';
141
145
  }
142
146
 
@@ -151,7 +155,11 @@ export class ImageTexture extends Texture {
151
155
  resolve({ data: img, premultiplyAlpha: hasAlpha });
152
156
  };
153
157
 
154
- img.src = src;
158
+ if (src instanceof Blob) {
159
+ img.src = URL.createObjectURL(src);
160
+ } else {
161
+ img.src = src;
162
+ }
155
163
  },
156
164
  );
157
165
  }
@@ -215,9 +223,16 @@ export class ImageTexture extends Texture {
215
223
  );
216
224
  }
217
225
 
218
- const blob = await fetchJson(src, 'blob').then(
219
- (response) => response as Blob,
220
- );
226
+ let blob;
227
+
228
+ if (isBase64Image(src) === true) {
229
+ blob = dataURIToBlob(src);
230
+ } else {
231
+ blob = await fetchJson(src, 'blob').then(
232
+ (response) => response as Blob,
233
+ );
234
+ }
235
+
221
236
  return this.createImageBitmap(blob, premultiplyAlpha, sx, sy, sw, sh);
222
237
  }
223
238
 
@@ -274,6 +289,14 @@ export class ImageTexture extends Texture {
274
289
  }
275
290
 
276
291
  if (typeof src !== 'string') {
292
+ if (src instanceof Blob) {
293
+ if (this.txManager.hasCreateImageBitmap === true) {
294
+ const { sx, sy, sw, sh } = this.props;
295
+ return this.createImageBitmap(src, premultiplyAlpha, sx, sy, sw, sh);
296
+ } else {
297
+ return this.loadImageFallback(src, premultiplyAlpha ?? true);
298
+ }
299
+ }
277
300
  if (src instanceof ImageData) {
278
301
  return {
279
302
  data: src,