2015-06-07 12 views
0

所以我有這個WebGL的頂點着色器:WebGL的VBO和整數溢出根據變量的存在屬性,統一或混合

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); 

火狐抱怨:

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. 

這是怎麼回事?

編輯:鉻給出更明確的錯誤消息:

glDrawElements: attempt to access out of range vertices in attribute 1 
+1

你如何設置你的制服和屬性?你能發佈你的代碼嗎? – agmcleod

回答

0

對不起沒有公佈任何更多的代碼,我認爲原因是隻有在着色器,但它不是。

我正在使用elm-webgl,屬性應該設置。但圖書館確實(不)理解float屬性,所以他們沒有設置。

因此,如果您遇到類似錯誤,請檢查您是如何設置制服和屬性的。