如何在GLSL(OpenGL ES 2.0)中定义常量数组? [英] How to define constant array in GLSL (OpenGL ES 2.0)?

查看:637
本文介绍了如何在GLSL(OpenGL ES 2.0)中定义常量数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想存储每个片段计算所需的权重数组。

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

这个:

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

抛出这个:

ERROR: 0:30: ']' : syntax error syntax error
ERROR: 0:30: ';' : syntax error syntax error


推荐答案

来自 OpenGL ES SL 1.0规范,段落 4.1.9数组(p.24):

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.

请注意,故意遗漏。根据这篇文章,OpenGL ES 2的OpenGL ES SL版本基于 OpenGL SL 1.2 。同一段(第20页)包含:

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


这篇关于如何在GLSL(OpenGL ES 2.0)中定义常量数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆