I'm getting an out of bounds error when drawing a basic element with some seemingly innocuous data. I have (apologising up front for the size):
在用一些看似无害的数据绘制基本元素时,我得到了一个超出范围的错误。我已经(为这个尺寸道歉了):
const vertexColourData = [
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0/*,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 1.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
1.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
0.0, 0.0, 1.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0*/
],
vertexPositionData = [
-1.0, -1.0, +1.0,
+1.0, -1.0, +1.0,
+1.0, +1.0, +1.0,
-1.0, +1.0, +1.0,
-1.0, -1.0, -1.0,
-1.0, +1.0, -1.0,
+1.0, +1.0, -1.0,
+1.0, -1.0, -1.0,
-1.0, +1.0, -1.0,
-1.0, +1.0, +1.0,
+1.0, +1.0, +1.0,
+1.0, +1.0, -1.0,
-1.0, -1.0, -1.0,
+1.0, -1.0, -1.0,
+1.0, -1.0, +1.0,
-1.0, -1.0, +1.0,
+1.0, -1.0, -1.0,
+1.0, +1.0, -1.0,
+1.0, +1.0, +1.0,
+1.0, -1.0, +1.0,
-1.0, -1.0, -1.0,
-1.0, -1.0, +1.0,
-1.0, +1.0, +1.0,
-1.0, +1.0, -1.0/*,
-1.0, -1.0, +1.0,
+1.0, -1.0, +1.0,
+1.0, +1.0, +1.0,
-1.0, +1.0, +1.0,
-1.0, -1.0, -1.0,
-1.0, +1.0, -1.0,
+1.0, +1.0, -1.0,
+1.0, -1.0, -1.0,
-1.0, +1.0, -1.0,
-1.0, +1.0, +1.0,
+1.0, +1.0, +1.0,
+1.0, +1.0, -1.0,
-1.0, -1.0, -1.0,
+1.0, -1.0, -1.0,
+1.0, -1.0, +1.0,
-1.0, -1.0, +1.0,
+1.0, -1.0, -1.0,
+1.0, +1.0, -1.0,
+1.0, +1.0, +1.0,
+1.0, -1.0, +1.0,
-1.0, -1.0, -1.0,
-1.0, -1.0, +1.0,
-1.0, +1.0, +1.0,
-1.0, +1.0, -1.0*/
],
vertexNormalData = [
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0/*,
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, +1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, 0.0, -1.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, +1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
0.0, -1.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
+1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0,
-1.0, 0.0, 0.0*/
],
vertexIndexData = [
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23/*,
24, 25, 26,
24, 26, 27,
28, 29, 30,
28, 30, 31,
32, 33, 34,
32, 34, 35,
36, 37, 38,
36, 38, 39,
40, 41, 42,
40, 42, 43,
44, 45, 46,
44, 46, 47*/
];
When I uncomment all but the last array, all works fine. In this case, there is twice as much colour, normal and position data and the second half of it remains unused.
当我取消注释的时候,除了最后一个数组,一切正常。在这种情况下,有两倍的颜色,正常的和位置的数据,后半部分仍未使用。
When I uncomment the last half of the vertexIndexData
array, however, effectively bringing into play the last vertices, I get the following error:
然而,当我取消对vertexIndexData数组的最后一半的注释时,有效地引入了最后一个顶点,我得到了以下错误:
ERROR :GL_INVALID_OPERATION :
glDrawElements
: range out of bounds for buffer错误:GL_INVALID_OPERATION: glDrawElements:范围超出了缓冲区的范围。
I can't see where my maths is wrong. Does anyone have any ideas?
我看不出我的数学错在哪里。有人有什么想法吗?
Update: It's nothing to do with the actual values of the vertex index data. If I try the following...
更新:这与顶点索引数据的实际值无关。如果我尝试以下…
vertexIndexData = [
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23,
0, 1, 2,
0, 2, 3,
4, 5, 6,
4, 6, 7,
8, 9, 10,
8, 10, 11,
12, 13, 14,
12, 14, 15,
16, 17, 18,
16, 18, 19,
20, 21, 22,
20, 22, 23/*,
24, 25, 26,
24, 26, 27,
28, 29, 30,
28, 30, 31,
32, 33, 34,
32, 34, 35,
36, 37, 38,
36, 38, 39,
40, 41, 42,
40, 42, 43,
44, 45, 46,
44, 46, 47*/
];
...which I thought would just draw the same triangles again, I get the same error. So it seems to me the complaint is with the size of the vertex index data's buffer.
…我想我还是会画同样的三角形,我得到了相同的误差。在我看来,抱怨就是顶点索引数据缓冲区的大小。
1 个解决方案
#1
0
The problem was not with the data, but the use of it. In short, I was binding the element buffers that held the vertex index information only once and not every time my render()
method was being called. Since there are two shaders, one for colour and one for texture, the element buffer of the texture shader was the only one that was being used, since it was the one that was bound the last. Quite how it all still worked is not worth the time to find out, I'm guessing the attribute offsets and the like were identical for the two shaders. This explains why I could choose just about any values for the vertex indices and everything would still appear to work.
问题不在于数据,而在于数据的使用。简而言之,我是绑定了只保存顶点索引信息的元素缓冲区,而不是每次调用render()方法时。因为有两个着色器,一个用于颜色,一个用于纹理,纹理着色器的元素缓冲区是唯一被使用的,因为它是最后一个被绑定的。很明显,这一切都是不值得花时间去发现的,我猜对两个着色器的属性偏移量和相似度是相同的。这解释了为什么我可以只选择顶点索引的任何值,而所有的值仍然会显示出来。
#1
0
The problem was not with the data, but the use of it. In short, I was binding the element buffers that held the vertex index information only once and not every time my render()
method was being called. Since there are two shaders, one for colour and one for texture, the element buffer of the texture shader was the only one that was being used, since it was the one that was bound the last. Quite how it all still worked is not worth the time to find out, I'm guessing the attribute offsets and the like were identical for the two shaders. This explains why I could choose just about any values for the vertex indices and everything would still appear to work.
问题不在于数据,而在于数据的使用。简而言之,我是绑定了只保存顶点索引信息的元素缓冲区,而不是每次调用render()方法时。因为有两个着色器,一个用于颜色,一个用于纹理,纹理着色器的元素缓冲区是唯一被使用的,因为它是最后一个被绑定的。很明显,这一切都是不值得花时间去发现的,我猜对两个着色器的属性偏移量和相似度是相同的。这解释了为什么我可以只选择顶点索引的任何值,而所有的值仍然会显示出来。