user1175197
user1175197

Reputation: 379

OpenGL shader multiple vertex attributes

I am trying to plot a graph using shaders. I have x and y data seperately and I want to pass them both to the shader seperatedly. The way I am currently doing is interleaving them like x0,y0,x1,y1,... and using a single vertex attribute

attribute vec2  coord2d;

I pass the interleaved data and then by

coord2d.xy

I acquire the sample points. However I do not want to load CPU with interleaving the data. Is there any way I can pass my x and y data to separate vertex attributes and let the shader fetch the samples from those.

Upvotes: 0

Views: 373

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

Use scalar attributes, you would have something like this in your vertex shader:

attribute float coord_x;
attribute float coord_y;

And when it comes time to use these coordinates for sampling:

vec2 (coord_x, coord_y)

Outside of the shader, you would have two vertex attrib pointers instead of 1. Each having 1 component, so they would look like something like this:

glVertexAttribPointer (coord_x_loc, 1, GL_FLOAT, GL_FALSE, 0, ...);
glVertexAttribPointer (coord_y_loc, 1, GL_FLOAT, GL_FALSE, 0, ...);

Upvotes: 3

Related Questions