From 6c922f72a819e6083ffc4b6a452c2493c9170e63 Mon Sep 17 00:00:00 2001 From: Alexander Nadeau Date: Wed, 30 Apr 2025 08:12:08 -0400 Subject: [PATCH] Fix text distortion on mobile devices/browsers with `glow` backend (#6893) Did not test on platforms other than my phone, but I can't imagine it causing problems. AFAIK if highp isn't supported then `precision highp float;` needs to still not cause the program to fail to link/compile or anything; it should just silently use some other precision. * Fixes https://github.com/emilk/egui/issues/4268 for me but I only tested it on a native Android app and I don't know whether backends other than glow are affected. * [x] I have followed the instructions in the PR template (but the change is trivial so I'm just doing it from the master branch) Before: ![image](https://github.com/user-attachments/assets/9f449749-5a48-4e9c-aef0-7a8ac3912eb6) After: ![image](https://github.com/user-attachments/assets/544e5977-13e0-411a-bccf-b15a15289e28) --- crates/egui_glow/src/shader/fragment.glsl | 8 +++++++- crates/egui_glow/src/shader/vertex.glsl | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/egui_glow/src/shader/fragment.glsl b/crates/egui_glow/src/shader/fragment.glsl index 30da2809..f2792ed0 100644 --- a/crates/egui_glow/src/shader/fragment.glsl +++ b/crates/egui_glow/src/shader/fragment.glsl @@ -1,5 +1,11 @@ #ifdef GL_ES - precision mediump float; + // To avoid weird distortion issues when rendering text etc, we want highp if possible. + // But apparently some devices don't support it, so we have to check first. + #if defined(GL_FRAGMENT_PRECISION_HIGH) && GL_FRAGMENT_PRECISION_HIGH == 1 + precision highp float; + #else + precision mediump float; + #endif #endif uniform sampler2D u_sampler; diff --git a/crates/egui_glow/src/shader/vertex.glsl b/crates/egui_glow/src/shader/vertex.glsl index fff31463..0c6e9d23 100644 --- a/crates/egui_glow/src/shader/vertex.glsl +++ b/crates/egui_glow/src/shader/vertex.glsl @@ -9,7 +9,13 @@ #endif #ifdef GL_ES - precision mediump float; + // To avoid weird distortion issues when rendering text etc, we want highp if possible. + // But apparently some devices don't support it, so we have to check first. + #if defined(GL_FRAGMENT_PRECISION_HIGH) && GL_FRAGMENT_PRECISION_HIGH == 1 + precision highp float; + #else + precision mediump float; + #endif #endif uniform vec2 u_screen_size;