所以我有这个WebGL顶点着色器:
precision mediump float;
uniform mat4 camera;
uniform vec3 pos0;
uniform float time;
attribute float t0;
attribute vec3 dir0;
void main() {
float t = time - t0;
gl_Position = camera * vec4(dir0, 1);
gl_PointSize = 10.0;
}
可以正常工作,但是如果我只更改下面的行
gl_Position = camera * vec4(pos0 + dir0 * t, 1);
Firefox抱怨:
Error: WebGL: drawElements: no VBO bound to enabled vertex attrib index 0!
如果我把同一行改成下面的
gl_Position = camera * vec4(pos0, 1);
错误不同:
Error: WebGL: Drawing without vertex attrib 0 array enabled forces the browser to do expensive emulation work when running on desktop OpenGL platforms, for example on Mac. It is preferable to always draw with vertex attrib 0 array enabled, by using bindAttribLocation to bind some always-used attribute to location 0.
Error: WebGL: Integer overflow trying to construct a fake vertex attrib 0 array for a draw-operation with -1 vertices. Try reducing the number of vertices.
怎么回事?
编辑:Chromium给出了一个更清晰的错误信息:
glDrawElements: attempt to access out of range vertices in attribute 1
抱歉没有张贴任何更多的代码,我认为原因只是在着色器,但它不是。
我正在使用elm-webgl
,并且应该设置属性。但是库不理解float
属性,所以没有设置它们。
所以,如果你遇到类似的错误,检查一下你是如何设置你的制服和属性的。