I'm trying to implement picking(using colors and readPixels) in a WebGL program of mine. When I start my program I create to seperate shaderProgram. One for phong shading and another that simply give shapes a color to be use to detect which shape has been clicked on.
The phong shader has 2 attributes. Vertex position and vertex normal. The picking one simply has the position.
Now I discovered that for some odd reason, when both of these shaders exist in the same program and I'm using the picking one, my drawArray call seems to fail. The last thing to happen is my gl.vertexAttribPointer call. I've been messing around and found out that when I check for active attrib arrays using: gl.getVertexAttrib(index,gl.VERTEX_ATTRIB_ARRAY_ENABLED);
both 0,1 return true (this is when the picking shader is active with gl.useProgram(picking))
Now if I disable 1 with gl.disableVertexAttribArray(1); Everything works again. Another fix is to draw with the phong shader first and then use the picking shader and somehow that magically makes it ok. I'm guessing that in that case when attaching my vertex normals buffer while using the phong shader, it somehow stays when I then switch to the picking shader and the drawArray call works.
I'd like to know if I'm using gl.enableAttribArray wrong and should disable them when switching shaders or something like that.
I've also tried creating the shader programs in different order with no success.