Click here to Skip to main content
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 OriginalGriff 512
1 Maciej Los 445
2 Sergey Alexandrovich Kryukov 421
3 CPallini 200
4 _Asif_ 135
0 Sergey Alexandrovich Kryukov 6,813
1 OriginalGriff 5,342
2 Peter Leow 3,837
3 Mika Wendelius 2,850
4 CHill60 2,748

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