What can cause glDrawArrays to generate a GL_INVALID_OPERATION error?
Solution 1:
I figured out your problem: you are rendering to the same buffer that you're sourcing your vertex data.
glBindVertexArray(vaoPass2);
I think you meant vaoPass1
From the spec:
Buffers should not be bound or in use for both transform feedback and other purposes in the GL. Specifically, if a buffer object is simultaneously bound to a transform feedback buffer binding point and elsewhere in the GL, any writes to or reads from the buffer generate undefined values. Examples of such bindings include ReadPixels to a pixel buffer object binding point and client access to a buffer mapped with MapBuffer.
Now, you should get undefined values; I'm not sure that a GL error qualifies, but it probably should be an error.
Solution 2:
Another (apparently undocumented) case where glDrawArrays
and glDrawElements
fail with GL_INVALID_OPERATION
:
-
GL_INVALID_OPERATION
is generated if a sampler uniform is set to an invalid texture unit identifier. (I had mistakenly performedglUniform1i(location, GL_TEXTURE0);
when I meantglUniform1i(location, 0);
.)
Solution 3:
Another (undocumented) case where glDraw*()
calls can fail with GL_INVALID_OPERATION
:
-
GL_INVALID_OPERATION
is generated if a sampler uniform is set to a texture unit bound to a texture of the incorrect type. For example, if auniform sampler2D
is setglUniform1i(location, 0);
, butGL_TEXTURE0
has aGL_TEXTURE_2D_ARRAY
texture bound.