Bitwise operators in GLSL

I store terrain texture data in RGBA textures that define the alpha level of each layer, packing one texture layer into each channel. I’ve implemented a virtual texturing system that allows me any number of texture layers at good speed. With so many texture layers possible, the bottleneck becomes the memory usage of these alpha textures. If the terrain is 2048x2048 points, every four texture layers consumes 16 mb video memory.

If I could perform bitwise operations in GLSL and just store a boolean for each texture layer, I could pack 32 texture layers into a single RGBA texture, greatly reducing the memory requirements of large terrains with many layers.

> If I could perform bitwise operations in GLSL and just store a boolean for each texture layer,

GLSL has had bitwise operators since at least GLSL version 1.3, which released in 2008. Which operations do you need?

[QUOTE=Foobarbazqux;1253742]> If I could perform bitwise operations in GLSL and just store a boolean for each texture layer,

GLSL has had bitwise operators since at least GLSL version 1.3, which released in 2008. Which operations do you need?[/QUOTE]
Really? I just need OR to store some bitwise flags. I did a google search and everything said it wasn’t supported. :slight_smile:

Since version 1.3, GLSL supports all of C’s operators except address-of (unary-&), pointer dereference (unary-* and ->) and type casts (constructors are used instead).

The first programmable GPUs had weak support for integer types in general, which was reflected in the early versions of GLSL (prior to 1.3), which didn’t support bitwise and (&), or (|), xor (^), ones-complement (~), and shifts (<<,>>), or modulo (%), or the corresponding modify-assign operators (&=,|=,^=,<<=,>>=,%=).

I think the issue is this: the bitwise operation works on integer types only. For the OP, the solution you are hunting for is to make an integer texture (there is the whole matrix: {number_channels=1,2,3 or 4} X { size of each channel = 8, 16 or 32 bits} X {unsigned or signed}, which is comes to 24 different integer texture choices.