Click here to Skip to main content
11,484,941 members (75,776 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ OpenGL GLSL
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?

Posted 27-Jan-12 21:43pm

1 solution

Rate this: bad
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:[^]

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 330
1 Maciej Los 280
2 Raje_ 155
3 Mehdi Gholam 150
4 OriginalGriff 133
0 Sergey Alexandrovich Kryukov 8,494
1 OriginalGriff 7,948
2 Sascha Lefèvre 3,199
3 Maciej Los 2,681
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web04 | 2.8.150520.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