调用 gl.enableVertexAttribArray(); 的目的是什么? WebGL 中的函数

What is the purpose of calling gl.enableVertexAttribArray(); function in WebGL

在 WebGL 中,在我们调用 drawArrays() 函数之前,我们将此函数称为 enableVertexAttribArray() 传递对我编译的 glsl 程序中存储我们将要访问的对象的顶点位置的变量的引用画。谁能给我解释一下它的作用以及为什么我们必须调用该函数。

默认情况下禁用顶点着色器中的属性。要使用一个,你必须先启用它的这个功能。

您仍然需要将缓冲区绑定到已启用的属性,specification 表示:

If a vertex attribute is enabled as an array via enableVertexAttribArray but no buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls to drawArrays or drawElements will generate an INVALID_OPERATION error.