Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to send uniforms or attributes which are structs which are defined by me, or arrays of "my" structs to the shaders. They should be recognized by the application (C++) and the shader (GLSL). Is it possible? Where should I define them?

Thanks
Posted

1 solution

C++
// Inside fragment/vertex shader
struct TheStruct // user defined structure.
{
  vec3 first;
  vec4 second;
  mat4x3 third;
};
 
uniform TheStruct aUniformOfArrayType; // instance of uniform user-defined parameter.



In application(C++) code, the name " aUniformOfArrayType" does not have a location; calling glGetUniformLocation on it will return -1. However, each of aUniformOfArrayType's fields do have a location. So you can call "glGetUniformLocation(program, " aUniformOfArrayType.first");" it will give a location and you can set valut to that parameter like a vec3 parameter in shader.

Details of uniform objects are explained in this link:http://www.opengl.org/wiki/GLSL_Uniform[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900