0

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.

0

1 Answer 1

3

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, ...);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.