Skip to content

Commit 8a3f364

Browse files
committed
Make sure ensureCompiledOnContext is called for internal shader() calls
1 parent c402baa commit 8a3f364

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/webgl/material.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,6 @@ function material(p5, fn){
864864
this._assert3d('shader');
865865
p5._validateParameters('shader', arguments);
866866

867-
// NOTE: make generic or remove need for
868-
s.ensureCompiledOnContext(this);
869-
870867
this._renderer.shader(s);
871868

872869
return this;
@@ -1040,9 +1037,6 @@ function material(p5, fn){
10401037
this._assert3d('strokeShader');
10411038
p5._validateParameters('strokeShader', arguments);
10421039

1043-
// NOTE: make generic or remove need for
1044-
s.ensureCompiledOnContext(this);
1045-
10461040
this._renderer.strokeShader(s);
10471041

10481042
return this;
@@ -1200,9 +1194,6 @@ function material(p5, fn){
12001194
this._assert3d('imageShader');
12011195
p5._validateParameters('imageShader', arguments);
12021196

1203-
// NOTE: make generic or remove need for
1204-
s.ensureCompiledOnContext(this);
1205-
12061197
this._renderer.imageShader(s);
12071198

12081199
return this;
@@ -3633,16 +3624,19 @@ function material(p5, fn){
36333624
// Always set the shader as a fill shader
36343625
this.states.userFillShader = s;
36353626
this.states._useNormalMaterial = false;
3627+
s.ensureCompiledOnContext(this);
36363628
s.setDefaultUniforms();
36373629
}
36383630

36393631
RendererGL.prototype.strokeShader = function(s) {
36403632
this.states.userStrokeShader = s;
3633+
s.ensureCompiledOnContext(this);
36413634
s.setDefaultUniforms();
36423635
}
36433636

36443637
RendererGL.prototype.imageShader = function(s) {
36453638
this.states.userImageShader = s;
3639+
s.ensureCompiledOnContext(this);
36463640
s.setDefaultUniforms();
36473641
}
36483642

src/webgl/p5.Shader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,20 +612,20 @@ class Shader {
612612
this._vertSrc,
613613
this._fragSrc
614614
);
615-
shader.ensureCompiledOnContext(context);
615+
shader.ensureCompiledOnContext(context._renderer);
616616
return shader;
617617
}
618618

619619
/**
620620
* @private
621621
*/
622622
ensureCompiledOnContext(context) {
623-
if (this._glProgram !== 0 && this._renderer !== context._renderer) {
623+
if (this._glProgram !== 0 && this._renderer !== context) {
624624
throw new Error(
625625
'The shader being run is attached to a different context. Do you need to copy it to this context first with .copyToContext()?'
626626
);
627627
} else if (this._glProgram === 0) {
628-
this._renderer = context._renderer;
628+
this._renderer = context;
629629
this.init();
630630
}
631631
}

0 commit comments

Comments
 (0)