From f464dfbefa08089433301f011b81c70f100ab18e Mon Sep 17 00:00:00 2001 From: Tom Englund Date: Tue, 1 Jul 2025 11:32:00 +0200 Subject: [PATCH] shader: replace texture2d with texture (#10893) * shader: replace texture2d with texture remove unused v_color and replace deprecated texture2d with texture. * shader: use the more modern essl3 extension GL_OES_EGL_image_external_essl3 provides support for samplerExternalOES in texture function, aquamarine already use it. apply it here too. --- src/render/shaders/glsl/blur1.frag | 10 +++++----- src/render/shaders/glsl/blur2.frag | 22 ++++++++++------------ src/render/shaders/glsl/ext.frag | 4 ++-- src/render/shaders/glsl/glitch.frag | 6 +++--- src/render/shaders/glsl/passthru.frag | 2 +- src/render/shaders/glsl/rgba.frag | 2 +- src/render/shaders/glsl/rgbamatte.frag | 2 +- src/render/shaders/glsl/rgbx.frag | 2 +- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/render/shaders/glsl/blur1.frag b/src/render/shaders/glsl/blur1.frag index f0f8cc10b..796fb42db 100644 --- a/src/render/shaders/glsl/blur1.frag +++ b/src/render/shaders/glsl/blur1.frag @@ -112,11 +112,11 @@ layout(location = 0) out vec4 fragColor; void main() { vec2 uv = v_texcoord * 2.0; - vec4 sum = texture2D(tex, uv) * 4.0; - sum += texture2D(tex, uv - halfpixel.xy * radius); - sum += texture2D(tex, uv + halfpixel.xy * radius); - sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius); - sum += texture2D(tex, uv - vec2(halfpixel.x, -halfpixel.y) * radius); + vec4 sum = texture(tex, uv) * 4.0; + sum += texture(tex, uv - halfpixel.xy * radius); + sum += texture(tex, uv + halfpixel.xy * radius); + sum += texture(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius); + sum += texture(tex, uv - vec2(halfpixel.x, -halfpixel.y) * radius); vec4 color = sum / 8.0; diff --git a/src/render/shaders/glsl/blur2.frag b/src/render/shaders/glsl/blur2.frag index 2483bcf41..bfe448d5f 100644 --- a/src/render/shaders/glsl/blur2.frag +++ b/src/render/shaders/glsl/blur2.frag @@ -1,27 +1,25 @@ #version 300 es precision highp float; -uniform sampler2D tex; +uniform sampler2D tex; uniform float radius; uniform vec2 halfpixel; in vec2 v_texcoord; - -out vec4 v_color; - layout(location = 0) out vec4 fragColor; + void main() { vec2 uv = v_texcoord / 2.0; - vec4 sum = texture2D(tex, uv + vec2(-halfpixel.x * 2.0, 0.0) * radius); + vec4 sum = texture(tex, uv + vec2(-halfpixel.x * 2.0, 0.0) * radius); - sum += texture2D(tex, uv + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, uv + vec2(0.0, halfpixel.y * 2.0) * radius); - sum += texture2D(tex, uv + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, uv + vec2(halfpixel.x * 2.0, 0.0) * radius); - sum += texture2D(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0; - sum += texture2D(tex, uv + vec2(0.0, -halfpixel.y * 2.0) * radius); - sum += texture2D(tex, uv + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0; + sum += texture(tex, uv + vec2(-halfpixel.x, halfpixel.y) * radius) * 2.0; + sum += texture(tex, uv + vec2(0.0, halfpixel.y * 2.0) * radius); + sum += texture(tex, uv + vec2(halfpixel.x, halfpixel.y) * radius) * 2.0; + sum += texture(tex, uv + vec2(halfpixel.x * 2.0, 0.0) * radius); + sum += texture(tex, uv + vec2(halfpixel.x, -halfpixel.y) * radius) * 2.0; + sum += texture(tex, uv + vec2(0.0, -halfpixel.y * 2.0) * radius); + sum += texture(tex, uv + vec2(-halfpixel.x, -halfpixel.y) * radius) * 2.0; fragColor = sum / 12.0; } diff --git a/src/render/shaders/glsl/ext.frag b/src/render/shaders/glsl/ext.frag index d8a12c39d..f540a9f9f 100644 --- a/src/render/shaders/glsl/ext.frag +++ b/src/render/shaders/glsl/ext.frag @@ -1,7 +1,7 @@ #version 300 es #extension GL_ARB_shading_language_include : enable -#extension GL_OES_EGL_image_external : require +#extension GL_OES_EGL_image_external_essl3 : require precision highp float; in vec2 v_texcoord; @@ -20,7 +20,7 @@ uniform vec3 tint; layout(location = 0) out vec4 fragColor; void main() { - vec4 pixColor = texture2D(texture0, v_texcoord); + vec4 pixColor = texture(texture0, v_texcoord); if (discardOpaque == 1 && pixColor[3] * alpha == 1.0) discard; diff --git a/src/render/shaders/glsl/glitch.frag b/src/render/shaders/glsl/glitch.frag index 2b03b4985..e399a8b16 100644 --- a/src/render/shaders/glsl/glitch.frag +++ b/src/render/shaders/glsl/glitch.frag @@ -54,9 +54,9 @@ void main() { vec2 pixCoord = vec2(v_texcoord.x + offset + NOISE * 3.0 / screenSize.x + blockOffset.x, v_texcoord.y - meltAmount + 0.02 * NOISE / screenSize.x + NOISE * 3.0 / screenSize.y + blockOffset.y); - vec4 pixColor = texture2D(tex, pixCoord); - vec4 pixColorLeft = texture2D(tex, pixCoord + vec2(ABERR_OFFSET / screenSize.x, 0)); - vec4 pixColorRight = texture2D(tex, pixCoord + vec2(-ABERR_OFFSET / screenSize.x, 0)); + vec4 pixColor = texture(tex, pixCoord); + vec4 pixColorLeft = texture(tex, pixCoord + vec2(ABERR_OFFSET / screenSize.x, 0)); + vec4 pixColorRight = texture(tex, pixCoord + vec2(-ABERR_OFFSET / screenSize.x, 0)); pixColor[0] = pixColorLeft[0]; pixColor[2] = pixColorRight[2]; diff --git a/src/render/shaders/glsl/passthru.frag b/src/render/shaders/glsl/passthru.frag index a5075abf9..e33b71216 100644 --- a/src/render/shaders/glsl/passthru.frag +++ b/src/render/shaders/glsl/passthru.frag @@ -6,5 +6,5 @@ uniform sampler2D tex; layout(location = 0) out vec4 fragColor; void main() { - fragColor = texture2D(tex, v_texcoord); + fragColor = texture(tex, v_texcoord); } diff --git a/src/render/shaders/glsl/rgba.frag b/src/render/shaders/glsl/rgba.frag index 86ea6d87f..e4e045004 100644 --- a/src/render/shaders/glsl/rgba.frag +++ b/src/render/shaders/glsl/rgba.frag @@ -18,7 +18,7 @@ uniform vec3 tint; layout(location = 0) out vec4 fragColor; void main() { - vec4 pixColor = texture2D(tex, v_texcoord); + vec4 pixColor = texture(tex, v_texcoord); if (discardOpaque == 1 && pixColor[3] * alpha == 1.0) discard; diff --git a/src/render/shaders/glsl/rgbamatte.frag b/src/render/shaders/glsl/rgbamatte.frag index bf295f735..a7213cfe0 100644 --- a/src/render/shaders/glsl/rgbamatte.frag +++ b/src/render/shaders/glsl/rgbamatte.frag @@ -7,5 +7,5 @@ uniform sampler2D texMatte; layout(location = 0) out vec4 fragColor; void main() { - fragColor = texture2D(tex, v_texcoord) * texture2D(texMatte, v_texcoord)[0]; // I know it only uses R, but matte should be black/white anyways. + fragColor = texture(tex, v_texcoord) * texture(texMatte, v_texcoord)[0]; // I know it only uses R, but matte should be black/white anyways. } diff --git a/src/render/shaders/glsl/rgbx.frag b/src/render/shaders/glsl/rgbx.frag index 5376a2579..84672d767 100644 --- a/src/render/shaders/glsl/rgbx.frag +++ b/src/render/shaders/glsl/rgbx.frag @@ -20,7 +20,7 @@ void main() { if (discardOpaque == 1 && alpha == 1.0) discard; - vec4 pixColor = vec4(texture2D(tex, v_texcoord).rgb, 1.0); + vec4 pixColor = vec4(texture(tex, v_texcoord).rgb, 1.0); if (applyTint == 1) { pixColor[0] = pixColor[0] * tint[0];