Skip to content

Commit 0455a6c

Browse files
committed
Add unit test and document optional scope parameter in build*Shader methods
1 parent 0ea049e commit 0455a6c

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/webgl/material.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,13 @@ function material(p5, fn) {
732732
* @beta
733733
* @submodule p5.strands
734734
* @param {Function} callback A function building a p5.strands shader.
735+
* @param {Object} [scope] An optional scope object passed to .modify().
735736
* @returns {p5.Shader} The material shader
736737
*/
737738
/**
738739
* @method buildFilterShader
739740
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
741+
* @param {Object} [scope] An optional scope object passed to .modify().
740742
* @returns {p5.Shader} The material shader
741743
*/
742744
fn.buildFilterShader = function (callback, scope) {
@@ -1560,11 +1562,13 @@ function material(p5, fn) {
15601562
* @submodule p5.strands
15611563
* @beta
15621564
* @param {Function} callback A function building a p5.strands shader.
1565+
* @param {Object} [scope] An optional scope object passed to .modify().
15631566
* @returns {p5.Shader} The material shader.
15641567
*/
15651568
/**
15661569
* @method buildMaterialShader
15671570
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
1571+
* @param {Object} [scope] An optional scope object passed to .modify().
15681572
* @returns {p5.Shader} The material shader.
15691573
*/
15701574
fn.buildMaterialShader = function (cb, scope) {
@@ -1776,11 +1780,13 @@ function material(p5, fn) {
17761780
* @submodule p5.strands
17771781
* @beta
17781782
* @param {Function} callback A function building a p5.strands shader.
1783+
* @param {Object} [scope] An optional scope object passed to .modify().
17791784
* @returns {p5.Shader} The normal shader.
17801785
*/
17811786
/**
17821787
* @method buildNormalShader
17831788
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
1789+
* @param {Object} [scope] An optional scope object passed to .modify().
17841790
* @returns {p5.Shader} The normal shader.
17851791
*/
17861792
fn.buildNormalShader = function (cb, scope) {
@@ -1940,11 +1946,13 @@ function material(p5, fn) {
19401946
* @submodule p5.strands
19411947
* @beta
19421948
* @param {Function} callback A function building a p5.strands shader.
1949+
* @param {Object} [scope] An optional scope object passed to .modify().
19431950
* @returns {p5.Shader} The color shader.
19441951
*/
19451952
/**
19461953
* @method buildColorShader
19471954
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
1955+
* @param {Object} [scope] An optional scope object passed to .modify().
19481956
* @returns {p5.Shader} The color shader.
19491957
*/
19501958
fn.buildColorShader = function (cb, scope) {
@@ -2195,11 +2203,13 @@ function material(p5, fn) {
21952203
* @submodule p5.strands
21962204
* @beta
21972205
* @param {Function} callback A function building a p5.strands shader.
2206+
* @param {Object} [scope] An optional scope object passed to .modify().
21982207
* @returns {p5.Shader} The stroke shader.
21992208
*/
22002209
/**
22012210
* @method buildStrokeShader
22022211
* @param {Object} hooks An object specifying p5.strands hooks in GLSL.
2212+
* @param {Object} [scope] An optional scope object passed to .modify().
22032213
* @returns {p5.Shader} The stroke shader.
22042214
*/
22052215
fn.buildStrokeShader = function (cb, scope) {

test/unit/webgl/p5.Shader.scope.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import p5 from '../../../src/app.js';
2+
3+
suite('p5.Shader', function() {
4+
suite('buildMaterialShader scope forwarding', function() {
5+
test('forwards scope to modify in instance mode', function(done) {
6+
new p5((sketch) => {
7+
sketch.setup = function() {
8+
sketch.createCanvas(10, 10, sketch.WEBGL);
9+
10+
const scope = { sketch };
11+
let receivedSketch = null;
12+
13+
sketch.buildMaterialShader(function({ sketch: s }) {
14+
receivedSketch = s;
15+
}, scope);
16+
17+
assert.strictEqual(receivedSketch, sketch);
18+
19+
sketch.remove();
20+
done();
21+
};
22+
});
23+
});
24+
});
25+
});

0 commit comments

Comments
 (0)