Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed Uniform Shader reset
  • Loading branch information
Forchapeatl authored Sep 3, 2024
commit 40e9973ff72d2aae2af5708b8bceca832feb0bdd
10 changes: 8 additions & 2 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ p5.Shader = class {
this.uniforms = {};
this._bound = false;
this.samplers = [];
this.previousBindings = new Set();// Set to store previous bindings
}

/**
Expand Down Expand Up @@ -554,7 +555,10 @@ p5.Shader = class {
// so we supply a default texture instead.
tex = this._renderer._getEmptyTexture();
}
gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
const textureUnit = gl.TEXTURE0 + uniform.samplerIndex;
gl.activeTexture(textureUnit);
const previousTexture = gl.getParameter(gl.TEXTURE_BINDING_2D);
this.previousBindings.add(textureUnit);
tex.bindTexture();
tex.update();
gl.uniform1i(uniform.location, uniform.samplerIndex);
Expand All @@ -572,7 +576,9 @@ p5.Shader = class {

unbindTextures() {
for (const uniform of this.samplers) {
this.setUniform(uniform.name, this._renderer._getEmptyTexture());
if (this.previousBindings.has(textureUnit) === false){
this.setUniform(uniform.name, this._renderer._getEmptyTexture());
}
}
}

Expand Down