In OpenGL is there a way to get a list of all uniforms & attribs used by a shader program?

后端 未结 4 1336
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-12 11:01

I\'d like to get a list of all the uniforms & attribs used by a shader program object. glGetAttribLocation() & glGetUniformLocation() can

4条回答
  •  遥遥无期
    2020-12-12 11:29

    For anyone out there that finds this question looking to do this in WebGL, here's the WebGL equivalent:

    var program = gl.createProgram();
    // ...attach shaders, link...
    
    var na = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
    console.log(na, 'attributes');
    for (var i = 0; i < na; ++i) {
      var a = gl.getActiveAttrib(program, i);
      console.log(i, a.size, a.type, a.name);
    }
    var nu = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
    console.log(nu, 'uniforms');
    for (var i = 0; i < nu; ++i) {
      var u = gl.getActiveUniform(program, i);
      console.log(i, u.size, u.type, u.name);
    }
    

提交回复
热议问题