How to write const array in GLSL ES

孤人 提交于 2019-12-06 03:58:20

The GLSL version used with ES 2.0 does not support constant arrays. From section "4.3.2 Constant Qualifier" on page 30 of the spec:

Arrays and structures containing arrays may not be declared constant since they cannot be initialized.

This restriction is lifted in ES 3.0, where it says in the corresponding section:

The const qualifier can be used with any of the non-void transparent basic data types as well as structures and arrays of these.

As an alternative, you should be able to use a non-constant array, where you assign the values one by one (untested):

vec4 vertices[3];
vertices[0] = vec4(0.25, -0.25, 0.5, 1.0);
vertices[1] = vec4(-0.25, -0.25, 0.5, 1.0);
vertices[2] = vec4(0.25, 0.25, 0.5, 1.0);

Or you could use a series of if-statements.

Have you tried braces?

const vec4 vertices[3] = {vec4(0.25, -0.25, 0.5, 1.0),
                          vec4(-0.25, -0.25, 0.5, 1.0),
                          vec4(0.25, 0.25, 0.5, 1.0)};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!