I have an existing WebGL renderer (too much code to be useful to share) which used to be very simple: it only had one vertex shader, one fragment shader, and one shader program with both. It was for rendering quads.
I'm trying to extend it to have a second shader program it switches to and from, for rendering point sprites. It has its own vertex attribute array, and a second vertex shader, fragment shader and shader program.
I can't seem to switch between the two properly: I keep getting display glitches, randomly disappearing objects and such. Here's the two functions I have to switch between them. Any idea what I'm missing?
GLWrapProto.switchQuadProgram = function ()
{
var gl = this.gl;
gl.useProgram(this.shaderProgramPoint);
gl.disableVertexAttribArray(this.locAPosPoint);
gl.useProgram(this.shaderProgram);
gl.enableVertexAttribArray(this.locAPos);
gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
gl.vertexAttribPointer(this.locAPos, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(this.locATex);
gl.bindBuffer(gl.ARRAY_BUFFER, this.texcoordBuffer);
gl.vertexAttribPointer(this.locATex, 2, gl.FLOAT, false, 0, 0);
};
GLWrapProto.switchPointProgram = function ()
{
var gl = this.gl;
gl.useProgram(this.shaderProgram);
gl.disableVertexAttribArray(this.locAPos);
gl.disableVertexAttribArray(this.locATex);
gl.useProgram(this.shaderProgramPoint);
gl.enableVertexAttribArray(this.locAPosPoint);
gl.bindBuffer(gl.ARRAY_BUFFER, this.pointBuffer);
gl.vertexAttribPointer(this.locAPosPoint, 4, gl.FLOAT, false, 0, 0);
};