WebGL VBO和Integer Overflow取决于变量属性,统一或混合

时间:2015-06-07 08:14:16

标签: glsl webgl vertex-shader

所以我有这个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

1 个答案:

答案 0 :(得分:0)

很抱歉没有发布更多代码,我认为原因只在着色器中,但事实并非如此。

我正在使用elm-webgl,并且应该设置属性。但是库(确实)不理解float属性,所以它们没有被设置。

因此,如果您遇到类似的错误,请检查您如何设置制服和属性。