Skip to content

fix: declare default float precision for gles fragment shaders - #244

Merged
parkergrt merged 2 commits into
pixpark:mainfrom
avosa:fix/gles-default-float-precision
Sep 26, 2026
Merged

parkergrt merged 2 commits into
pixpark:mainfrom
avosa:fix/gles-default-float-precision

Conversation

@avosa

@avosa avosa commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Problem

GLSL ES defines no default float precision for fragment shaders, unlike vertex shaders. A fragment shader that never declares one relies on the driver being lenient. Strict compilers reject it outright: ANGLE reports "No precision specified for (float)", WebGL validation does the same, and some mobile drivers behave likewise. This bites both in-tree shaders that carry no precision statement (for example the generated gaussian blur fragment shaders) and any custom shader passed through Filter::CreateWithFragmentShaderString.

Fix

Before compiling a fragment shader in GPUPixelGLProgram::InitWithShaderString, prepend precision mediump float; when the source contains no precision declaration. The injected line sits behind #ifdef GL_ES, so desktop GLSL compilers that predate precision qualifiers never see it. Shaders that already declare precision, including all per-declaration qualified ones, are passed through untouched, so rendering output is unchanged for them.

Verification

  • script/build_macos.sh builds clean (Release, library plus desktop demo)
  • on a macOS OpenGL 2.1 / GLSL 1.20 context, a fragment shader with the injected prefix compiles and the guard is inert, so there is no desktop regression
  • clang-format --dry-run --Werror is clean for the changed lines

avosa added 2 commits August 27, 2026 09:43
- glsl es gives fragment shaders no default float precision, so sources
  that never declare one are rejected by strict compilers such as angle,
  webgl and some mobile drivers even though lenient drivers accept them
- inject a mediump default when the source declares no precision, kept
  behind an ifdef GL_ES guard so desktop glsl is unaffected
@avosa

avosa commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@parkergrt

@parkergrt
parkergrt merged commit ef552bf into pixpark:main Sep 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants