你可以用 GLSL ES 中的整数做什么?
What can you do with integers in GLSL ES?
在 GLSL ES 2.0 中,您可以使用整数做的事情似乎非常有限。
例如:
- 不支持按位运算。
- 似乎没有内部函数接受
int
类型
所以,看起来你唯一能用整数做的事情是:
- 将整数赋值给整数
- 通过索引访问数组元素
- 基本算术(
-
、+
、*
、/
),但仅限于其他整数之间。不存在允许您将 float
和 int
相加的运算符。
- 相互比较。
- 将它们转换为其他类型
vec
构造函数允许您传递整数
真的是这样吗?除了 vec
构造函数之外,是否有 任何 接受 int
参数的内部函数?在 float
和 int
之间,您可以执行 任何 操作吗?
你是对的,整数的用例是有限的。根据 OpenGL ES Shading Language spec、4.1.3:
Integers are mainly supported as a programming aid. At the hardware level, real integers would aid efficient implementation of loops and array indices, and referencing texture units. However, there is no requirement that integers in the language map to an integer type in hardware. It is not expected that underlying hardware has full support for a wide range of integer operations. An OpenGL ES Shading Language implementation may convert integers to floats to operate on them. Hence, there is no portable wrapping behavior.
由于不能保证 GLSL ES 整数类型映射到硬件整数类型,它仅对编译时类型检查有用,在运行时几乎没有影响。 需要整数的所有地方都在规范中列出。
在 GLSL ES 2.0 中,您可以使用整数做的事情似乎非常有限。
例如:
- 不支持按位运算。
- 似乎没有内部函数接受
int
类型
所以,看起来你唯一能用整数做的事情是:
- 将整数赋值给整数
- 通过索引访问数组元素
- 基本算术(
-
、+
、*
、/
),但仅限于其他整数之间。不存在允许您将float
和int
相加的运算符。 - 相互比较。
- 将它们转换为其他类型
vec
构造函数允许您传递整数
真的是这样吗?除了 vec
构造函数之外,是否有 任何 接受 int
参数的内部函数?在 float
和 int
之间,您可以执行 任何 操作吗?
你是对的,整数的用例是有限的。根据 OpenGL ES Shading Language spec、4.1.3:
Integers are mainly supported as a programming aid. At the hardware level, real integers would aid efficient implementation of loops and array indices, and referencing texture units. However, there is no requirement that integers in the language map to an integer type in hardware. It is not expected that underlying hardware has full support for a wide range of integer operations. An OpenGL ES Shading Language implementation may convert integers to floats to operate on them. Hence, there is no portable wrapping behavior.
由于不能保证 GLSL ES 整数类型映射到硬件整数类型,它仅对编译时类型检查有用,在运行时几乎没有影响。 需要整数的所有地方都在规范中列出。