Nikola Lukic
Nikola Lukic

Reputation: 4238

twgl.setUniforms analog call in native webgl

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 ?

Upvotes: 2

Views: 45

Answers (1)

Krokomot
Krokomot

Reputation: 5803

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.

Upvotes: 1

Related Questions