glVertexAttribPointer vec2,但转发只有一个 [英] glVertexAttribPointer vec2 but forward just one
问题描述
我有这个,wich会读入vec2,是可能转发只有一个,所以顶点着色器将收到每个0,1然后1,2 2,3等等?
I have this, wich will read in vec2, is it possible to forward just one, so the vertex shader will recieve in each 0,1 then 1,2 2,3 and so on?
float v[]{0,1,2,3,4...};
glVertexAttribPointer((GLuint)0, 2, GL_FLOAT, GL_FALSE, 0, 0);
推荐答案
这看起来像一个黑客, 参数
glVertexAttribPointer
到单个的大小 float
。
This feels like a hack, but you could explicitely set the stride
parameter of glVertexAttribPointer
to the size of a single float
.
基本上,每当GL取得索引为 i
的顶点时,它会使用 offset + i * stride
。 0
你正在使用当前作为stride参数是一个方便的快捷方式,意味着紧凑数组,因此它将等效于 2 * sizeof(GLfloat)
在你的情况下,但是没有什么在GL,阻止你设置一个步骤以下紧凑数组的值:
Basically, whenever the GL fetches a vertex with index i
, it will use the address offset + i * stride
. The 0
you are using currently as stride parameter is a convenience shortcut meaning a tightly packed array, so it will be equivalent to 2 * sizeof(GLfloat)
in your case, but there is nothing in the GL which prevents you from setting a stride below that value of a tightly packed array:
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat), 0);
这篇关于glVertexAttribPointer vec2,但转发只有一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!