i wrote a tiny function to switch between shaders, but unfortunatelly it doesn't work. I create the shaders and return them as shader objects.
program = gl.createProgram(vs, fs, "VertexPosition", "TextureCoord", "VertexNormal");
depthprogram = gl.createProgram(vs, fs, "VertexPosition", false, false);
I use the switch function in my update function which consists of :
function Update(){
gl.switchProgram(program);
gl.Draw(Teapot, cam);
};
All buffers of the model are bind in the draw function, (parameters: the model, camera position)
this.switchProgram = function(program){
if (this.program !== program){
this.lastprogram = this.program;
this.program = program;
gl.useProgram(this.program);
};
};
Here is the resulting error: WebGL: INVALID_OPERATION: drawElements: attribs not setup correctly If i comment all works fine, but i'm unable to switch :(
depthprogram = gl.createProgram(vs, fs, "VertexPosition", false, false);
gl.switchProgram(program);