Summary
Add a highPrecisionShader boolean to Application settings that controls the default WebGL shader float precision.
true (default) — uses the highest available precision (current behavior)
false — forces mediump precision, which is faster on mobile GPUs that support highp but run faster at mediump
Motivation
Mobile GPUs often support highp but execute mediump shaders 2-4x faster in fragment shaders. Currently melonJS auto-detects the highest precision and always uses it. Developers targeting mobile have no way to opt into lower precision for a performance boost without configuring each shader individually.
PixiJS v8 offers preferredFragmentPrecision / preferredVertexPrecision per-shader. A global boolean is simpler and covers the common case.
Implementation
- Add
highPrecisionShader: boolean to ApplicationSettings (default true)
- Add to
defaultApplicationSettings
- Pass through to the WebGL renderer as
settings.highPrecisionShader
- In
GLShader constructor, when no explicit precision parameter: use "mediump" if highPrecisionShader === false, otherwise auto-detect via getMaxShaderPrecision()
- The per-shader
precision parameter still overrides the global setting
References
GLShader: src/video/webgl/glshader.js — already accepts precision parameter
ShaderEffect: src/video/webgl/shadereffect.js — passes precision to GLShader
getMaxShaderPrecision: src/video/webgl/utils/precision.js
Summary
Add a
highPrecisionShaderboolean to Application settings that controls the default WebGL shader float precision.true(default) — uses the highest available precision (current behavior)false— forcesmediumpprecision, which is faster on mobile GPUs that supporthighpbut run faster atmediumpMotivation
Mobile GPUs often support
highpbut executemediumpshaders 2-4x faster in fragment shaders. Currently melonJS auto-detects the highest precision and always uses it. Developers targeting mobile have no way to opt into lower precision for a performance boost without configuring each shader individually.PixiJS v8 offers
preferredFragmentPrecision/preferredVertexPrecisionper-shader. A global boolean is simpler and covers the common case.Implementation
highPrecisionShader: booleantoApplicationSettings(defaulttrue)defaultApplicationSettingssettings.highPrecisionShaderGLShaderconstructor, when no explicitprecisionparameter: use"mediump"ifhighPrecisionShader === false, otherwise auto-detect viagetMaxShaderPrecision()precisionparameter still overrides the global settingReferences
GLShader:src/video/webgl/glshader.js— already acceptsprecisionparameterShaderEffect:src/video/webgl/shadereffect.js— passes precision to GLShadergetMaxShaderPrecision:src/video/webgl/utils/precision.js