twgl.setUniforms analog call in native webgl

42 views Asked by At

I dont use twgl i wanna pure webgl to set uniforms for "gl.createTexture()".

Source Code:


  const depthTexture = gl.createTexture();
  ...

    twgl.setUniforms(programInfo, {
      u_projectedTexture: depthTexture
    }

Any suggestion ?

1

There are 1 answers

1
Krokomot On BEST ANSWER

twgl.setUniforms() is equivalent to a combo of WebGL functions to bind the texture and set the uniforms. The scheme is:

const tex = gl.createTexture();
//...

// Bind the texture
gl.activeTexture(...);
gl.bindTexture(...);
gl.uniform1i(...); // for the texture

/*
* Set the uniforms -- For each uniform, depending
* on its type, a call of a corresponding function
* from the 'uniform' function group
*/ 
gl.uniform<...>(...);
//...

A more extensive example of how to translate setUniforms() into native WebGL can be found in the TWGL documentation of setUniforms(). An overview of all WebGL functions, including the uniform variants, can be found in the official WebGL 2.0 API Quick Reference Guide.