Sending data to the shader

Let’s assume that I have a structure:

struct Points
{
float r,g,b;
float a,b,c;
float x[9],y[9],z[9];

};
Points Table[100];

I am sending first and second data from this structure to the shader as follows

positionLoc = glGetAttribLocation( shader, “inPosition” );
positionLoc2 = glGetAttribLocation( shader, “inPosition2” );

glVertexAttribPointer(positionLoc ,3,GL_FLOAT,0,sizeof(Points),BUFFER_OFFSET(sizeof(float) * 0));
glVertexAttribPointer(positionLoc2 ,3,GL_FLOAT,0,sizeof(Points),BUFFER_OFFSET(sizeof(float) * 3));

My question is: how send last data ( float x[9],y[9],z[9] ) from the struct to the shader ?

Well, a first question would be… what is this data?

OK, a first-first question is this: do you mean “float x[9],y[9],z[9];” as you said the first time, or “int x[9],y[9],z[9]” as you said the second?

Either way, it’s not a good idea to transfer this kind of data. If you want to transfer an array of 9 XYZs (for some reason), then you need to provide it that way: an array of 9 XYZs. Not an array of 9 Xs, 9 Ys, and 9 Zs.

You can send it that way, but it’ll be a big pain to access in your shader.

It can sometimes be easier to access big data structures like this via texture buffer objects and access the buffer object in the vertex shader via a vertex texture fetch.

I changed the array how you advised but still I don’t know how to send this array from the structure to the shader.

struct Points
{
float r,g,b;
float a,b,c;
float xyz[18];

};

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.