-1

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);
superbem
  • 441
  • 3
  • 10

1 Answers1

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);
derhass
  • 43,833
  • 2
  • 57
  • 78
  • That answered the question, byt I'm still having problem, what I want is to access the previous vertex values in the shader, I only need the last one. You're right, that has a kind of hack, is there a better way? – superbem Mar 26 '16 at 14:26
  • @derhass, if you have to set the stride in tightly packed vec2 array, the stride should be: 2 *sizeof(GLfloat) not sizeof(GLfloat) as in your code. – wangdq Sep 25 '16 at 05:15
  • @wangdq: that is true, but that is not what the question - and the answer - was about. I explicitely stated "but there is nothing in the GL which prevents you from setting a stride below that value of a tightly packed array:". – derhass Sep 25 '16 at 11:53