Advertisement

OGLES 3 + Pass vec3 structure as an array

Started by February 21, 2018 12:35 PM
1 comment, last by cgrant 6 years, 11 months ago

I need to pass 24 vec3, to a shader

However glUniform3fv requires an array of GLfloat,

Since my vec3 structure looks like:

struct vec3{float x; float y; float z;};

Can i just pass that safely, to float parray[24 * 3] using memcpy?

Dont bother about GLfloat and float sizes i just gave pseudocode i just need to know if sent array will have first vertex at position 0 second one will be in pos 3, thrid one in 6 and so on, cause im not sure when even float and GLfloat match the sizes i could get some extra bytes anywhere,

 

And another question is how then i define an uniform in shader?

uniform vec3 box[24];. ?

 

Cheers

7 hours ago, Cat's machete said:

Can i just pass that safely, to float parray[24 * 3] using memcpy?

Yes and no, depending on the alignment of uniform, you may find that you may have issue with indexing and getting the expected values at correct indices ( the GLSL ES specification discusses this ).

 

 

7 hours ago, Cat's machete said:

And another question is how then i define an uniform in shader?

uniform vec3 box[24];. ?

Yes that is how uniform array are define.

I would suggest downloading the OpenGL GLSL ES specification for the version you are using as a reference while development as it comes in really handy at times. Cheers.

This topic is closed to new replies.

Advertisement