p5.EasyCam icon indicating copy to clipboard operation
p5.EasyCam copied to clipboard

BUG FOUND AND FIXED: dwgl.js bug in uniformT

Open tomviolin opened this issue 2 years ago • 0 comments

In dwgl.js the uniformT function does not work when you try to pass more than 1 texture as uniforms to a fragment shader. I have discovered the fix. You need to make the texture active BEFORE you bind it. The fixed function is below. The two lines that need to be switched are the gl.activeTexture and gl.bindTexture lines, which currently are lines 630 and 631 in dwgl.js.

FIXED FUNCTION:

  uniformT(name, val){
    var gl = this.gl;
    var loc = this.uniformLoc(name);
    if(loc){
      gl.activeTexture(gl.TEXTURE0 + this.tex_loc);  // these are the two lines
      gl.bindTexture(gl.TEXTURE_2D, val);            // that needed to be switched 
      gl.uniform1i(loc, this.tex_loc);
      this.tex_loc++;
    } 
  }

tomviolin avatar Jul 26 '21 16:07 tomviolin