Click here to Skip to main content
11,637,176 members (69,634 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL GLSL
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 27-Jan-12 20:43pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

// 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[^]
  Permalink  

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

  Print Answers RSS
0 stibee 313
1 jyo.net 295
2 OriginalGriff 295
3 himanshu agarwal 184
4 Sergey Alexandrovich Kryukov 154
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,513
2 Mika Wendelius 6,922
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 29 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100