Sign in to follow this  

Modify GLSL Struct Uniform

This topic is 821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this struct:

 

struct Test {
vec2 value1;
vec3 value2;
float value3;
}

 

uniform Test test0;

 

`glUniform2f` can be used to modify a vec2 type uniform. Which function allows one to set the value of a struct?

Share this post


Link to post
Share on other sites
You set structs as buffers. The easiest would be to set the structs members with primitive functions, like glsetuniform2f("test0.value1", data). I think that works.

Share this post


Link to post
Share on other sites

Which function allows one to set the value of a struct?

It will be the same glUniform1/2/3/4/fv(). You just need correct locations of struct items.

In your case there will be 3 uniforms, named "test0.value1", "test0.value2" and "test0.value3". You can query locations for those names with glGetUniformLocation().

To be perfectly sure about names - list active uniforms.

First ask uniforms count with glGetProgramiv(prog, GL_ACTIVE_UNIFORMS, &uniform_cnt), then loop from 0 till <uniform_cnt, calling glGetActiveUniform() for every index.

Edited by vstrakh

Share this post


Link to post
Share on other sites

This topic is 821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this