Click here to Skip to main content
13,002,133 members (80,248 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 20: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)

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 29 Jan 2012
Copyright © CodeProject, 1999-2017
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