Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can you do with integers in GLSL ES?

There seems to be an extremely limited amount of things you can do with integers in GLSL ES 2.0.

For example:

  • No bitwise operations are supported.
  • No intrinsic functions seems to accept int types

So, it seems the only thing you can really do with integers is:

  • Assign integer to integer
  • Access array element by index
  • Basic arithmetic (-, +, *, /), but only between other integers. No operator exists which allows you to add a float and int together.
  • Compare them between each other.
  • Convert them to other types
  • vec constructors allow you to pass integers

Is that really it? Are there any intrinsic functions that take int parameters other than vec constructors? Are there any operations you can do between float and int?

like image 810
tenfour Avatar asked Aug 31 '25 04:08

tenfour


1 Answers

You are correct, use cases of integers are limited. Per 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.

Since there's no guarantee GLSL ES integer type maps to a hardware integer type, it's only useful for compile-time type checking with little to no effect at runtime. All places that require integers are listed in the spec.

like image 126
D-side Avatar answered Sep 12 '25 04:09

D-side