Click here to Skip to main content
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 21: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 Maciej Los 230
1 OriginalGriff 202
2 Richard MacCutchan 185
3 Tomas Takac 146
4 CPallini 125
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 29 Jan 2012
Copyright © CodeProject, 1999-2014
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