[SOLVED] Why only set the precision if GL_ES is defined?

Issue

This Content is from Stack Overflow. Question asked by I got a question for ya

When writing code for a fragment shader, it starts as follows:

            #ifdef GL_ES
            precision mediump float;
            #endif

Why does the “precision mediump float;” line have to depend on whether GL_ES was defined or not?



Solution

It doesn’t "have to"; it simply does.

Desktop GL will ignore any precision declarations. So there’s no need to ifdef around it.

That being said, if one wants to share GLSL code with very old versions of desktop GLSL (1.20 or before), then the #ifdef is useful, as such versions did not allow the precision declaration.


This Question was asked in StackOverflow by I got a question for ya and Answered by Nicol Bolas It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?