@geastack/native-webgl-angle 0.1.17 → 0.1.18

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.
@@ -349,42 +349,86 @@ export function isUniformNumberArray( value ) {
349
349
 
350
350
  }
351
351
 
352
- /** @param {NativeUniformValue} value @return {value is Vector2[]} */
353
- function isVector2Array( value ) {
352
+ /**
353
+ * One element of a uniform array whose first element is the given kind. Read
354
+ * through \`Array.isArray\` and \`instanceof\` on the element itself rather than
355
+ * through the value narrowed to that array type: the value is stored as the
356
+ * uniform union, and claiming one array arm for it is an array-to-array
357
+ * conversion with no runtime form.
358
+ */
359
+
360
+ /** @param {NativeUniformValue} value @param {number} index @return {Vector2} */
361
+ function vector2ArrayElement( value, index ) {
362
+
363
+ \tif ( Array.isArray( value ) ) {
364
+
365
+ \t\tconst element = value[ index ];
366
+
367
+ \t\tif ( element instanceof Vector2 ) return element;
368
+
369
+ \t}
354
370
 
355
- \treturn Array.isArray( value ) && value.length > 0 && value[ 0 ] instanceof Vector2;
371
+ \tthrow new Error( 'THREE.UniformsUtils: a uniform array mixes Vector2 with other values.' );
356
372
 
357
373
  }
358
374
 
359
- /** @param {NativeUniformValue} value @return {value is Vector3[]} */
360
- function isVector3Array( value ) {
375
+ /** @param {NativeUniformValue} value @param {number} index @return {Vector3} */
376
+ function vector3ArrayElement( value, index ) {
377
+
378
+ \tif ( Array.isArray( value ) ) {
361
379
 
362
- \treturn Array.isArray( value ) && value.length > 0 && value[ 0 ] instanceof Vector3;
380
+ \t\tconst element = value[ index ];
381
+
382
+ \t\tif ( element instanceof Vector3 ) return element;
383
+
384
+ \t}
385
+
386
+ \tthrow new Error( 'THREE.UniformsUtils: a uniform array mixes Vector3 with other values.' );
363
387
 
364
388
  }
365
389
 
366
- /** @param {NativeUniformValue} value @return {value is Vector4[]} */
367
- function isVector4Array( value ) {
390
+ /** @param {NativeUniformValue} value @param {number} index @return {Vector4} */
391
+ function vector4ArrayElement( value, index ) {
392
+
393
+ \tif ( Array.isArray( value ) ) {
368
394
 
369
- \treturn Array.isArray( value ) && value.length > 0 && value[ 0 ] instanceof Vector4;
395
+ \t\tconst element = value[ index ];
396
+
397
+ \t\tif ( element instanceof Vector4 ) return element;
398
+
399
+ \t}
400
+
401
+ \tthrow new Error( 'THREE.UniformsUtils: a uniform array mixes Vector4 with other values.' );
370
402
 
371
403
  }
372
404
 
373
- /** @param {NativeUniformValue} value @return {value is Matrix4[]} */
374
- function isMatrix4Array( value ) {
405
+ /** @param {NativeUniformValue} value @param {number} index @return {Matrix4} */
406
+ function matrix4ArrayElement( value, index ) {
407
+
408
+ \tif ( Array.isArray( value ) ) {
409
+
410
+ \t\tconst element = value[ index ];
411
+
412
+ \t\tif ( element instanceof Matrix4 ) return element;
375
413
 
376
- \treturn Array.isArray( value ) && value.length > 0 && value[ 0 ] instanceof Matrix4;
414
+ \t}
415
+
416
+ \tthrow new Error( 'THREE.UniformsUtils: a uniform array mixes Matrix4 with other values.' );
377
417
 
378
418
  }
379
419
 
380
- /** @param {NativeUniformValue} value @return {value is Array<Texture|null>} */
381
- export function isUniformTextureArray( value ) {
420
+ /** @param {NativeUniformValue} value @param {number} index @return {Texture|null} */
421
+ function textureArrayElement( value, index ) {
382
422
 
383
- \tif ( ! Array.isArray( value ) || value.length === 0 ) return false;
423
+ \tif ( Array.isArray( value ) ) {
384
424
 
385
- \tconst first = value[ 0 ];
425
+ \t\tconst element = value[ index ];
386
426
 
387
- \treturn first === null || first instanceof Texture;
427
+ \t\tif ( element === null || element instanceof Texture ) return element;
428
+
429
+ \t}
430
+
431
+ \tthrow new Error( 'THREE.UniformsUtils: a uniform array mixes textures with other values.' );
388
432
 
389
433
  }
390
434
 
@@ -423,63 +467,70 @@ export function cloneUniformValue( value ) {
423
467
 
424
468
  \tif ( isUniformNumberArray( value ) ) return value.slice();
425
469
 
426
- \tif ( isVector2Array( value ) ) {
470
+ \tif ( Array.isArray( value ) && value.length > 0 ) {
427
471
 
428
- \t\t/** @type {Vector2[]} */
429
- \t\tconst cloned = [];
472
+ \t\tconst first = value[ 0 ];
473
+ \t\tconst length = value.length;
430
474
 
431
- \t\tfor ( let i = 0, l = value.length; i < l; i ++ ) cloned.push( value[ i ].clone() );
475
+ \t\tif ( first instanceof Vector2 ) {
432
476
 
433
- \t\treturn cloned;
477
+ \t\t\t/** @type {Vector2[]} */
478
+ \t\t\tconst cloned = [];
434
479
 
435
- \t}
480
+ \t\t\tfor ( let i = 0; i < length; i ++ ) cloned.push( vector2ArrayElement( value, i ).clone() );
481
+
482
+ \t\t\treturn cloned;
436
483
 
437
- \tif ( isVector3Array( value ) ) {
484
+ \t\t}
438
485
 
439
- \t\t/** @type {Vector3[]} */
440
- \t\tconst cloned = [];
486
+ \t\tif ( first instanceof Vector3 ) {
441
487
 
442
- \t\tfor ( let i = 0, l = value.length; i < l; i ++ ) cloned.push( value[ i ].clone() );
488
+ \t\t\t/** @type {Vector3[]} */
489
+ \t\t\tconst cloned = [];
443
490
 
444
- \t\treturn cloned;
491
+ \t\t\tfor ( let i = 0; i < length; i ++ ) cloned.push( vector3ArrayElement( value, i ).clone() );
445
492
 
446
- \t}
493
+ \t\t\treturn cloned;
447
494
 
448
- \tif ( isVector4Array( value ) ) {
495
+ \t\t}
449
496
 
450
- \t\t/** @type {Vector4[]} */
451
- \t\tconst cloned = [];
497
+ \t\tif ( first instanceof Vector4 ) {
452
498
 
453
- \t\tfor ( let i = 0, l = value.length; i < l; i ++ ) cloned.push( value[ i ].clone() );
499
+ \t\t\t/** @type {Vector4[]} */
500
+ \t\t\tconst cloned = [];
454
501
 
455
- \t\treturn cloned;
502
+ \t\t\tfor ( let i = 0; i < length; i ++ ) cloned.push( vector4ArrayElement( value, i ).clone() );
456
503
 
457
- \t}
504
+ \t\t\treturn cloned;
458
505
 
459
- \tif ( isMatrix4Array( value ) ) {
506
+ \t\t}
460
507
 
461
- \t\t/** @type {Matrix4[]} */
462
- \t\tconst cloned = [];
508
+ \t\tif ( first instanceof Matrix4 ) {
463
509
 
464
- \t\tfor ( let i = 0, l = value.length; i < l; i ++ ) cloned.push( value[ i ].clone() );
510
+ \t\t\t/** @type {Matrix4[]} */
511
+ \t\t\tconst cloned = [];
465
512
 
466
- \t\treturn cloned;
513
+ \t\t\tfor ( let i = 0; i < length; i ++ ) cloned.push( matrix4ArrayElement( value, i ).clone() );
467
514
 
468
- \t}
515
+ \t\t\treturn cloned;
516
+
517
+ \t\t}
469
518
 
470
- \tif ( isUniformTextureArray( value ) ) {
519
+ \t\tif ( first === null || first instanceof Texture ) {
471
520
 
472
- \t\t/** @type {Array<Texture|null>} */
473
- \t\tconst cloned = [];
521
+ \t\t\t/** @type {Array<Texture|null>} */
522
+ \t\t\tconst cloned = [];
474
523
 
475
- \t\tfor ( let i = 0, l = value.length; i < l; i ++ ) {
524
+ \t\t\tfor ( let i = 0; i < length; i ++ ) {
476
525
 
477
- \t\t\tconst texture = value[ i ];
478
- \t\t\tcloned.push( texture === null ? null : texture.clone() );
526
+ \t\t\t\tconst texture = textureArrayElement( value, i );
527
+ \t\t\t\tcloned.push( texture === null ? null : texture.clone() );
479
528
 
480
- \t\t}
529
+ \t\t\t}
481
530
 
482
- \t\treturn cloned;
531
+ \t\t\treturn cloned;
532
+
533
+ \t\t}
483
534
 
484
535
  \t}
485
536
 
@@ -856,8 +907,7 @@ function ${name}( gl, v, textures ) {
856
907
 
857
908
  \t}
858
909
 
859
- \tconst list = requireTextureArray( v );
860
- \tconst n = list.length;
910
+ \tconst n = requireTextureArrayLength( v );
861
911
 
862
912
  \tconst units = allocTexUnits( manager, n );
863
913
 
@@ -887,7 +937,7 @@ ${
887
937
  }
888
938
  \tfor ( let i = 0; i !== n; ++ i ) {
889
939
 
890
- \t\tconst texture = list[ i ];
940
+ \t\tconst texture = textureArrayElement( v, i );
891
941
  \t\tmanager.${setter}( texture === null ? ${shadowAware ? 'emptyTexture2D' : empty} : texture, units[ i ] );
892
942
 
893
943
  \t}
@@ -1033,7 +1083,7 @@ import { Matrix4 } from '../../math/Matrix4.js';
1033
1083
  import { Vector2 } from '../../math/Vector2.js';
1034
1084
  import { Vector3 } from '../../math/Vector3.js';
1035
1085
  import { Vector4 } from '../../math/Vector4.js';
1036
- import { isUniformNumberArray, isUniformTextureArray } from '../shaders/UniformsUtils.js';
1086
+ import { isUniformNumberArray } from '../shaders/UniformsUtils.js';
1037
1087
  import {
1038
1088
  ${nativeLightUniformClassNames.map((name) => `\t${name},`).join('\n')}
1039
1089
  } from '../shaders/UniformsLib.js';
@@ -1124,10 +1174,39 @@ function requireUintUniformArray( value ) {
1124
1174
 
1125
1175
  }
1126
1176
 
1127
- /** @param {NativeUniformValue} value @return {Array<Texture|null>} */
1128
- function requireTextureArray( value ) {
1177
+ /**
1178
+ * A sampler array value is read element by element, never returned as a
1179
+ * narrowed \`Array<Texture|null>\`: a call site can hand the setter a value whose
1180
+ * static carrier is another array arm (a \`number[]\` passed to \`setValue\` by
1181
+ * name), and claiming that array for the texture arm is an array-to-array
1182
+ * conversion with no runtime form. Validated up front, as before, so a value
1183
+ * that is not a texture array throws before any texture unit is allocated.
1184
+ * @param {NativeUniformValue} value @return {number}
1185
+ */
1186
+ function requireTextureArrayLength( value ) {
1187
+
1188
+ \tif ( Array.isArray( value ) && value.length > 0 ) {
1189
+
1190
+ \t\tconst first = value[ 0 ];
1191
+
1192
+ \t\tif ( first === null || first instanceof Texture ) return value.length;
1193
+
1194
+ \t}
1195
+
1196
+ \tthrow new Error( 'THREE.WebGLUniforms: sampler array uniform value must be an array of textures.' );
1197
+
1198
+ }
1199
+
1200
+ /** @param {NativeUniformValue} value @param {number} index @return {Texture|null} */
1201
+ function textureArrayElement( value, index ) {
1202
+
1203
+ \tif ( Array.isArray( value ) ) {
1129
1204
 
1130
- \tif ( isUniformTextureArray( value ) ) return value;
1205
+ \t\tconst element = value[ index ];
1206
+
1207
+ \t\tif ( element === null || element instanceof Texture ) return element;
1208
+
1209
+ \t}
1131
1210
 
1132
1211
  \tthrow new Error( 'THREE.WebGLUniforms: sampler array uniform value must be an array of textures.' );
1133
1212
 
package/geatsc-plugin.mjs CHANGED
@@ -678,7 +678,7 @@ inline double gea_three_resource_read_native(std::string name, const gea::Ref<ge
678
678
  "threeWebGLDrawBuffers",
679
679
  "gea_three_webgl_draw_buffers",
680
680
  "void",
681
- 'extern "C" void gea_three_webgl_draw_buffers(double attachment);',
681
+ 'extern "C" void gea_three_webgl_draw_buffers(double count, double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7);',
682
682
  ],
683
683
 
684
684
  [
@@ -2327,8 +2327,11 @@ extern "C" void gea_three_webgl_renderbuffer_storage(double target, double inter
2327
2327
  geaTrapCheck("gea_three_webgl_renderbuffer_storage"); GEA_WEBGL_VOID("renderbufferStorage"); gWebGL.glRenderbufferStorage(asGLenum(target), asGLenum(internalFormat), asGLsizei(width), asGLsizei(height)); }
2328
2328
  extern "C" void gea_three_webgl_framebuffer_renderbuffer(double target, double attachment, double renderbuffertarget, double renderbuffer) {
2329
2329
  geaTrapCheck("gea_three_webgl_framebuffer_renderbuffer"); GEA_WEBGL_VOID("framebufferRenderbuffer"); gWebGL.glFramebufferRenderbuffer(asGLenum(target), asGLenum(attachment), asGLenum(renderbuffertarget), asGLuint(renderbuffer)); }
2330
- extern "C" void gea_three_webgl_draw_buffers(double attachment) {
2331
- geaTrapCheck("gea_three_webgl_draw_buffers"); GEA_WEBGL_VOID("drawBuffers"); const GLenum glAttachment = asGLenum(attachment); gWebGL.glDrawBuffers(1, &glAttachment); }
2330
+ extern "C" void gea_three_webgl_draw_buffers(double count, double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7) {
2331
+ geaTrapCheck("gea_three_webgl_draw_buffers"); GEA_WEBGL_VOID("drawBuffers");
2332
+ const GLenum attachments[8] = {asGLenum(a0), asGLenum(a1), asGLenum(a2), asGLenum(a3), asGLenum(a4), asGLenum(a5), asGLenum(a6), asGLenum(a7)};
2333
+ const GLsizei n = std::max<GLsizei>(0, std::min<GLsizei>(asGLsizei(count), 8));
2334
+ gWebGL.glDrawBuffers(n, attachments); }
2332
2335
 
2333
2336
  extern "C" void gea_three_webgl_clear_color(double r, double g, double b, double a) {
2334
2337
  geaTrapCheck("gea_three_webgl_clear_color"); GEA_WEBGL_VOID("clearColor");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/native-webgl-angle",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Typed native WebGL compatibility layer backed by ANGLE/Metal",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -1213,7 +1213,12 @@ export class NativeWebGL2RenderingContext {
1213
1213
  framebufferTextureLayer(target: number, attachment: number, texture: NativeHandle | null, level: number, layer: number): void {
1214
1214
  threeWebGLFramebufferTextureLayer(target, attachment, nullableNativeHandle(texture), level, layer)
1215
1215
  }
1216
- drawBuffers(buffers: number[]): void { nativeWebGLDrawBuffers(buffers[0] ?? this.COLOR_ATTACHMENT0) }
1216
+ /** Every listed buffer reaches GL (up to 8, the MRT limit the host passes), so multiple render targets write all their attachments. */
1217
+ drawBuffers(buffers: number[]): void {
1218
+ const count = Math.min(buffers.length, 8)
1219
+ const at = (index: number): number => index < count ? buffers[index] : this.NONE
1220
+ nativeWebGLDrawBuffers(count, at(0), at(1), at(2), at(3), at(4), at(5), at(6), at(7))
1221
+ }
1217
1222
 
1218
1223
  clearColor(r: number, g: number, b: number, a: number): void { nativeWebGLClearColor(r, g, b, a) }
1219
1224
  clear(mask: number): void { nativeWebGLClear(mask) }
@@ -148,7 +148,7 @@ export function nativeWebGLBindRenderbuffer(target: number, renderbuffer: number
148
148
  export function nativeWebGLDeleteRenderbuffer(renderbuffer: number): void { threeWebGLDeleteRenderbuffer(renderbuffer) }
149
149
  export function nativeWebGLRenderbufferStorage(target: number, internalFormat: number, width: number, height: number): void { threeWebGLRenderbufferStorage(target, internalFormat, width, height) }
150
150
  export function nativeWebGLFramebufferRenderbuffer(target: number, attachment: number, renderbuffertarget: number, renderbuffer: number): void { threeWebGLFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer) }
151
- export function nativeWebGLDrawBuffers(attachment: number): void { threeWebGLDrawBuffers(attachment) }
151
+ export function nativeWebGLDrawBuffers(count: number, a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7: number): void { threeWebGLDrawBuffers(count, a0, a1, a2, a3, a4, a5, a6, a7) }
152
152
 
153
153
  export function nativeWebGLClearColor(r: number, g: number, b: number, a: number): void { threeWebGLClearColor(r, g, b, a) }
154
154
  export function nativeWebGLClear(mask: number): void { threeWebGLClear(mask) }
@@ -303,7 +303,7 @@ declare function threeWebGLRenderbufferStorage(target: number, internalFormat: n
303
303
  /** @gea-host-inert Native state only; retains no script references and invokes no script. */
304
304
  declare function threeWebGLFramebufferRenderbuffer(target: number, attachment: number, renderbuffertarget: number, renderbuffer: number): void
305
305
  /** @gea-host-inert Native state only; retains no script references and invokes no script. */
306
- declare function threeWebGLDrawBuffers(attachment: number): void
306
+ declare function threeWebGLDrawBuffers(count: number, a0: number, a1: number, a2: number, a3: number, a4: number, a5: number, a6: number, a7: number): void
307
307
  /** @gea-host-inert Copies scalar arguments into GL state; retains no script references and invokes no script. */
308
308
  declare function threeWebGLClearColor(r: number, g: number, b: number, a: number): void
309
309
  /** @gea-host-inert Native state only; retains no script references and invokes no script. */