From 677a3f2f8847ed2de49dd60868f9d9487a546f58 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 2 Feb 2023 22:43:31 +0100 Subject: render/gles2: default to highp if available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spec [1] says that the maximum value for a mediump float is at least 2¹⁴ in section 4.5.2. However, when using a 4k resolution texture coordinates will exceed this value. This causes issues on drivers which implement mediump as a 16-bit [2]. Switch to highp. There's a twist: on GLES2, support for highp is optional. So we need to guard it with cute GL_FRAGMENT_PRECISION_HIGH ifdefs. [1]: https://registry.khronos.org/OpenGL/specs/es/2.0/GLSL_ES_Specification_1.00.pdf [2]: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21082 --- render/gles2/shaders/quad.frag | 5 +++++ render/gles2/shaders/tex_external.frag | 5 +++++ render/gles2/shaders/tex_rgba.frag | 5 +++++ render/gles2/shaders/tex_rgbx.frag | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/render/gles2/shaders/quad.frag b/render/gles2/shaders/quad.frag index f9712797..97d3a31c 100644 --- a/render/gles2/shaders/quad.frag +++ b/render/gles2/shaders/quad.frag @@ -1,4 +1,9 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else precision mediump float; +#endif + varying vec4 v_color; varying vec2 v_texcoord; uniform vec4 color; diff --git a/render/gles2/shaders/tex_external.frag b/render/gles2/shaders/tex_external.frag index 05eac503..73909fe0 100644 --- a/render/gles2/shaders/tex_external.frag +++ b/render/gles2/shaders/tex_external.frag @@ -1,6 +1,11 @@ #extension GL_OES_EGL_image_external : require +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else precision mediump float; +#endif + varying vec2 v_texcoord; uniform samplerExternalOES texture0; uniform float alpha; diff --git a/render/gles2/shaders/tex_rgba.frag b/render/gles2/shaders/tex_rgba.frag index c2e17a90..c0a0dea6 100644 --- a/render/gles2/shaders/tex_rgba.frag +++ b/render/gles2/shaders/tex_rgba.frag @@ -1,4 +1,9 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else precision mediump float; +#endif + varying vec2 v_texcoord; uniform sampler2D tex; uniform float alpha; diff --git a/render/gles2/shaders/tex_rgbx.frag b/render/gles2/shaders/tex_rgbx.frag index 42ddf92f..ae40ad53 100644 --- a/render/gles2/shaders/tex_rgbx.frag +++ b/render/gles2/shaders/tex_rgbx.frag @@ -1,4 +1,9 @@ +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else precision mediump float; +#endif + varying vec2 v_texcoord; uniform sampler2D tex; uniform float alpha; -- cgit v1.2.3