gpu: Add a version of a function

With the changes in !7473 we now use sampler2D arguments in functions.
However, when there's a function we call with a samplerExternalOES -
which means we need to overload it with that shader variant.
This commit is contained in:
Benjamin Otte 2024-07-25 18:43:54 +02:00
parent de1dfb99bc
commit 6f9a70bd4e

View File

@ -35,6 +35,7 @@ uniform PushConstants
#ifdef GSK_TEXTURE0_IS_EXTERNAL
uniform samplerExternalOES GSK_TEXTURE0;
#define HAS_EXTERNAL_TEXTURES
#else
uniform sampler2D GSK_TEXTURE0;
#endif
@ -43,6 +44,9 @@ uniform sampler2D GSK_TEXTURE0;
#ifdef GSK_TEXTURE1_IS_EXTERNAL
uniform samplerExternalOES GSK_TEXTURE1;
#ifndef HAS_EXTERNAL_TEXTURES
#define HAS_EXTERNAL_TEXTURES
#endif
#else
uniform sampler2D GSK_TEXTURE1;
#endif
@ -50,6 +54,30 @@ uniform sampler2D GSK_TEXTURE1;
#endif
#endif
#ifdef HAS_EXTERNAL_TEXTURES
vec4
gsk_texture_straight_alpha (samplerExternalOES tex,
vec2 pos)
{
vec2 size = vec2 (textureSize (tex, 0));
pos *= size;
size -= vec2 (1.0);
/* GL_CLAMP_TO_EDGE */
pos = clamp (pos - 0.5, vec2 (0.0), size);
ivec2 ipos = ivec2 (pos);
pos = fract (pos);
vec4 tl = texelFetch (tex, ipos, 0);
tl.rgb *= tl.a;
vec4 tr = texelFetch (tex, ipos + ivec2(1, 0), 0);
tr.rgb *= tr.a;
vec4 bl = texelFetch (tex, ipos + ivec2(0, 1), 0);
bl.rgb *= bl.a;
vec4 br = texelFetch (tex, ipos + ivec2(1, 1), 0);
br.rgb *= br.a;
return mix (mix (tl, tr, pos.x), mix (bl, br, pos.x), pos.y);
}
#endif
layout(location = 0) out vec4 out_color;
void
gsk_set_output_color (vec4 color)