glVertexAttribPointer vec2 but forward just one [closed]

眉间皱痕 提交于 2019-12-12 06:47:36

问题


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

回答1:


This feels like a hack, but you could explicitely set the stride parameter of glVertexAttribPointer to the size of a single float.

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


来源:https://stackoverflow.com/questions/36229863/glvertexattribpointer-vec2-but-forward-just-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!