home/ atoms/ glsl-precision-qualifier-required

GLSL ES requires a precision mediump float block at the top of every shader

OpenGL ES (the GPU API used by glslViewer in browser/mobile contexts) requires an explicit precision qualifier for float variables. Without it, the compiler produces ‘No precision specified for (float)’. The canonical fix is a guarded block at the top of the shader: #ifdef GL_ES\nprecision mediump float;\n#endif. The #ifdef guard makes the block harmless on desktop GL where precision is implicit. This block appears in the rig’s hello.frag template.

Examples

#ifdef GL_ES
precision mediump float;
#endif

Assessment

Write the guarded precision block required for GL ES and explain why the #ifdef guard is used rather than adding the declaration unconditionally.

“Missing precision = no compile on ES.** GL ES has *no default precision for `float`* in the fragment stage → you MUST include `#ifdef GL_ES precision mediump float; #endif`.”
context/ · L1-instruments/glsl/gotchas.md · chunk 1
“GL2 | **Missing precision qualifier** | on GL ES, no `precision …float;` before first `float` use | `ERROR: … No precision specified for (float)` (representative) | Add the guarded block at top: `#ifdef GL_ES precision mediump float; #endif`”
context/ · L5-debug/glsl.md · chunk 1