@@ -330,11 +330,15 @@ test('Episodes', function () {
330
330
331
331
test ( 'Argument qualifiers' , function ( ) {
332
332
333
- // clone inputs
334
- test ( 'void f(float a, vec3 b, mat4 c) { b.x = 1.0; }' , function ( ) {
333
+ test ( 'Clone inputs' , function ( ) {
335
334
var compile = GLSL ( ) ;
336
335
337
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
336
+ var source = `
337
+ void f(float a, vec3 b, mat4 c) {
338
+ b.x = 1.0;
339
+ }` ;
340
+
341
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
338
342
function f (a, b, c) {
339
343
b = b.slice();
340
344
c = c.slice();
@@ -343,23 +347,35 @@ test('Argument qualifiers', function() {
343
347
` ) )
344
348
} ) ;
345
349
346
- // output w/o return statement
347
- test ( 'void f(float a, out float b) { b = 1.0; }' , function ( ) {
350
+ test ( 'Output without return statements' , function ( ) {
348
351
var compile = GLSL ( ) ;
349
352
350
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
353
+ var source = `
354
+ void f(float a, out float b) {
355
+ b = 1.0;
356
+ }` ;
357
+
358
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
351
359
function f (a, b) {
352
360
b = 1.0;
353
361
f.__out__ = [b];
354
362
};
355
363
` ) )
356
364
} ) ;
357
365
358
- // output w/ return statement
359
- test ( 'void f(float a, out float b) { if (a < 0.0) { b = -1.0; return; } b = 1.0; }' , function ( ) {
366
+ test ( 'Output with return statements' , function ( ) {
360
367
var compile = GLSL ( ) ;
361
368
362
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
369
+ var source = `
370
+ void f(float a, out float b) {
371
+ if (a < 0.0) {
372
+ b = -1.0;
373
+ return;
374
+ }
375
+ b = 1.0;
376
+ }` ;
377
+
378
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
363
379
function f (a, b) {
364
380
if (a < 0.0) {
365
381
b = -1.0;
@@ -372,11 +388,18 @@ test('Argument qualifiers', function() {
372
388
` ) )
373
389
} ) ;
374
390
375
- // multiple outputs
376
- test ( 'float f(out float a, out vec2 b, inout vec2 c) { a = 0.1; b = vec2(2.0); c = b; return 0.0; }' , function ( ) {
391
+ test ( 'Multiple outputs' , function ( ) {
377
392
var compile = GLSL ( ) ;
378
393
379
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
394
+ var source = `
395
+ float f(out float a, out vec2 b, inout vec2 c) {
396
+ a = 0.1;
397
+ b = vec2(2.0);
398
+ c = b;
399
+ return 0.0;
400
+ }` ;
401
+
402
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
380
403
function f (a, b, c) {
381
404
c = c.slice();
382
405
a = 0.1;
@@ -389,33 +412,59 @@ test('Argument qualifiers', function() {
389
412
` ) )
390
413
} ) ;
391
414
392
- // calling
393
- test ( `float f(float a, out float b, out float c) { b = 1.0; c = 2.0; return a + 1.0; }
394
- void main() { float x = 0.1; float y; float z; x = f(x, y, z); }` , function ( ) {
415
+ test ( 'Calling function with output arguments' , function ( ) {
395
416
var compile = GLSL ( ) ;
396
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
417
+
418
+ var source = `
419
+ float f(float a, out float b, out float c) {
420
+ b = 1.0;
421
+ c = 2.0;
422
+ return a + 1.0;
423
+ }
424
+ float x = 0.1;
425
+ float y;
426
+ float z;
427
+ x = f(x, y, z);
428
+ gl_Position = vec4(x, y, z, 1.0);
429
+ ` ;
430
+
431
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
397
432
function f (a, b, c) {
398
433
b = 1.0;
399
434
c = 2.0;
400
435
f.__return__ = a + 1.0;
401
436
f.__out__ = [b, c];
402
437
return f.__return__;
403
438
};
404
- function main () {
405
- var x = 0.1;
406
- var y = 0;
407
- var z = 0;
408
- x = (f(x, y, z), [y, z] = f.__out__, f.__return__);
409
- };
439
+ var x = 0.1;
440
+ var y = 0;
441
+ var z = 0;
442
+ x = (f(x, y, z), [y, z] = f.__out__, f.__return__);
443
+ gl_Position = [x, y, z, 1];
410
444
` ) )
445
+
446
+ assert . deepEqual ( eval ( source , { debug : false } ) , [ 1.1 , 1 , 2 , 1 ] ) ;
411
447
} ) ;
412
448
413
449
// recursive calling
414
- test ( `float f1(float a, out float b) { b = 1.0; return a + 1.0; }
415
- float f2(float a, out float b) { return f1(a, b) + 1.0; }
416
- void main() { float x = 0.1; float y; x = f2(x, y); }` , function ( ) {
450
+ test ( 'Calling nested functions with output arguments' , function ( ) {
417
451
var compile = GLSL ( ) ;
418
- assert . equal ( clean ( compile ( this . title ) ) , clean ( `
452
+
453
+ var source = `
454
+ float f1(float a, out float b) {
455
+ b = 1.0;
456
+ return a + 1.0;
457
+ }
458
+ float f2(float a, out float b) {
459
+ return f1(a, b) + 1.0;
460
+ }
461
+ float x = 0.1;
462
+ float y;
463
+ x = f2(x, y);
464
+ gl_Position = vec4(x, y, 0.0, 1.0);
465
+ ` ;
466
+
467
+ assert . equal ( clean ( compile ( source ) ) , clean ( `
419
468
function f1 (a, b) {
420
469
b = 1.0;
421
470
f1.__return__ = a + 1.0;
@@ -427,12 +476,13 @@ test('Argument qualifiers', function() {
427
476
f2.__out__ = [b];
428
477
return f2.__return__;
429
478
};
430
- function main () {
431
- var x = 0.1;
432
- var y = 0;
433
- x = (f2(x, y), [y] = f2.__out__, f2.__return__);
434
- };
479
+ var x = 0.1;
480
+ var y = 0;
481
+ x = (f2(x, y), [y] = f2.__out__, f2.__return__);
482
+ gl_Position = [x, y, 0, 1];
435
483
` ) )
484
+
485
+ assert . deepEqual ( eval ( source , { debug : false } ) , [ 2.1 , 1 , 0 , 1 ] ) ;
436
486
} ) ;
437
487
} )
438
488
0 commit comments