Search code examples
openglglslendianness

GLSL endianness macro


Is there any way to check endianness of target machine inside GLSL? For example in OpenCL I could use

#ifdef __ENDIAN_LITTLE__
uint x = v << 1;
#else
uint x = v >> 1;
#endif

Solution

  • Searching for "endian" in the GLSL 4.60 specification doesn't yield any match. A search for "order" only reveals irrelevant results. So I suppose there's no special way to query endianness of the GPU in GLSL.

    Your best bet is to detect it with a specially-crafted shader once at the beginning (like, read the supplied byte buffer as a uint and put an endianness-dependent result in the output fragment, then glReadPixels), and then, based on the result, just insert the appropriate #defines into the shaders that depend on this.