1

I need to send a set of data to shader like.

//Application OpenGL

uniform vec3 *variable; 
variable = (uniform vec3 *)malloc(80 * sizeof(uniform vec3));  

//or    
uniform vec3 variable[80];

I need to send data such as indexes, and many other data.

Hulk1991
  • 3,079
  • 13
  • 31
  • 46
Javier Ramírez
  • 1,001
  • 2
  • 12
  • 23
  • 1
    First of all, what GL/GLSL version are you using? Maybe you are looking for Uniform Buffer Objects? Can you use a texture for this? Maybe also include a more concrete example of what you are trying to achieve here? – Grimmy Jun 03 '13 at 00:32
  • My gl/glsl version is 2.0. I try to send indices for skin animation. Thank you – Javier Ramírez Jun 03 '13 at 00:38
  • 1
    Update the actual question and include the GLSL #version directive you are currently using. – Grimmy Jun 03 '13 at 00:41
  • I just have to guess that you are looking for something like this : http://stackoverflow.com/questions/8099979/glsl-c-arrays-of-uniforms – Grimmy Jun 03 '13 at 04:03

1 Answers1

3

The latter case is correct. GLSL is built on having as simple and straightforward execution as possible. You cannot allocate memory in the shader, iterating is expensive. A well-written GLSL or HLSL shader takes in a fixed set of data, and outputs a fixed set of data. This makes it very fast to execute in parallel. This is my skeletal vertex shader.

 #version 110

uniform mat4 transform[ 32 ];

in int boneID;

void main()
{

    gl_FrontColor = gl_Color;
    gl_Position = transform[ boneID ] * gl_Vertex;

}

On the C/++ side, when calling glUniformMatrix4fv, point it to an array of several matrices and tell it how many there are, and it'll bring them through into GLSL as separate values.

Please note that my code is built on an old version of GLSL, and uses many now-deprecated elements such as gl_Vertex.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
jameswilddev
  • 582
  • 7
  • 16
  • Thank you very much for your help, my friend :-) P. D. How you increase the value of boneID? – Javier Ramírez Jun 03 '13 at 14:32
  • You can set it using vertex attributes. (attribs) Use glGetAttribLocation to get the attribute ID of "boneID", which you can then enable using glEnableVertexAttribArray (similar to glEnableClientState) before telling it where to find the data using glVertexAttribIPointer. (similar to glVertexPointer, but for attributes, of an integer type.) If you're using VBOs, put the data in the VBO like you might location or colour or UVs. This means you can set one bone index per vertex. More advanced shaders use multiple bone indices and weights for smooth blending on shoulders/etc. – jameswilddev Jun 03 '13 at 15:27