My code works fine if I invoke gl.useProgram
at the very beginning. On the other hand, If I never invoke gl.useProgram
, nothing displayed and get two kind of waring in the console:
First:
WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program
Second:
WebGL: INVALID_OPERATION: drawElements: no valid shader program in use
The second warning makes sense to me, here is the signature for drawElements
drawElements(mode: GLenum, count: GLsizei, type: GLenum, offset: GLintptr):
When you issue a draw call, you need to know which program to run but the call signature has no hint for program, so a global program is necessary, so I put gl.useProgram
just before gl.drawElements
and everything works fine, but the first kind of warning persists which makes no sense to me! let see the signature for set Uniform
vertexAttrib4fv(index: GLuint, values: Iterable<GLfloat>): void;
the first is effectively an address in memory the program can refer to at the runtime and the address should be got from the program like
getUniformLocation(program: WebGLProgram, name: string): WebGLUniformLocation | null;
The program is already used to get the address, why the current global state is necessary when setting the uniform? Is there any kind of case I missed which does cause a problem?