glsl es结构体变量该怎样初始化

A 但编译器会说 全局变量的初始化必须是常量表达式, 如果这个全局变量是“常量”的话,前面加一个const;如果不是“常量”的话,可以将这个变量转移到main函数中去。
全局变量如果没有uniform、attributes或者varings修饰的话,就一定得用const修饰。
B 改用ANGLE之后就没问题了, 改用ANGLE之后就没问题,有可能是ANGLE做了兼容处理,还是有可能会在某些手机上出问题的。
webgl中会出现这样的警告,但是编译以后使用时正常的。
"WARNING: 0:1: \u0026#39;=\u0026#39; : global variable initializers should be constant expressions (uniforms and globals are allowed in global initializers for legacy compatibility)\\\u0000"我之前测试的情况(不是手游,是webgl):
在iphone ios 10.0.2版本上不能用,之前和之后的版本都可以。
小米4c不可以、小米max(不论是自带的浏览器还是安装的uc、chrome等)可以、小米note自带的浏览器可以,但是安装的uc浏览器不行。
C以下是引用stackoverflow上的回答:
Is it ever reasonable to do computations outside of main in an OpenGL shader?
This is not a legal shader in GLSL ES 1.00, which is the GLSL version that is used with ES 2.0. WebGL shares the same GLSL definition, with some exceptions specified in the WebGL spec. I can\u0026#39;t find an exception for this in the WebGL spec, so I believe that the shader is illegal in both ES 2.0 and WebGL.
【glsl es结构体变量该怎样初始化】 From the GLSL ES 1.00 spec, section "4.3 Storage Qualifiers" on page 29 (emphasis added):
Declarations of globals without a storage qualifier, or with just the const qualifier, may include initializers, in which case they will be initialized before the first line of main() is executed. Such initializers must be a constant expression.Section "5.10 Constant Expressions" on page 49 defines what a constant expression is. It includes:
The following may not be used in constant expressions:Uniforms, attributes and varyings.The expression in your case includes a uniform, which makes it a non-constant expression. It can therefore not be used as the initializer of a global variable.

■网友
已确定是模拟器的问题,改用ANGLE之后就没问题了,ARM的可以去死了~
@vczh


    推荐阅读