Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
920 views
in Technique[技术] by (71.8m points)

iphone - How to define constant array in GLSL (OpenGL ES 2.0)?

I just want to store an array of weights that needs to every fragment calculation.

This:

float weights[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);

Just throws this:

ERROR: 0:30: ']' : syntax error syntax error
ERROR: 0:30: ';' : syntax error syntax error
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

From the OpenGL ES SL 1.0 spec, paragraph 4.1.9 Arrays (p. 24):

There is no mechanism for initializing arrays at declaration time from within a shader.

Note that this has been intentionally left out. According to this post, the OpenGL ES SL version for OpenGL ES 2 is based on OpenGL SL 1.2. The same paragraph (p. 20) contains:

Arrays can have initializers formed from array constructors:

      float a[5] = float[5](3.4, 4.2, 5.0, 5.2, 1.1);
      float a[5] = float[](3.4, 4.2, 5.0, 5.2, 1.1);  // same thing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...