mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-19 06:47:02 -04:00
Instead of having 3 different fragment shaders for textures and 1 more for quads, unify them all and compile different variants via a SOURCE constant. In the future, we will have more variant dimensions: pre-multiplied alpha on/off, color transformation, etc. It will become inpractical to have one file per combination. Weston has a similar approach: https://gitlab.freedesktop.org/wayland/weston/-/blob/main/libweston/renderer-gl/fragment.glsl
45 lines
1 KiB
GLSL
45 lines
1 KiB
GLSL
/* enum wlr_gles2_shader_source */
|
|
#define SOURCE_SINGLE_COLOR 1
|
|
#define SOURCE_TEXTURE_RGBA 2
|
|
#define SOURCE_TEXTURE_RGBX 3
|
|
#define SOURCE_TEXTURE_EXTERNAL 4
|
|
|
|
#if !defined(SOURCE)
|
|
#error "Missing shader preamble"
|
|
#endif
|
|
|
|
#if SOURCE == SOURCE_TEXTURE_EXTERNAL
|
|
#extension GL_OES_EGL_image_external : require
|
|
#endif
|
|
|
|
precision mediump float;
|
|
|
|
varying vec2 v_texcoord;
|
|
|
|
#if SOURCE == SOURCE_TEXTURE_EXTERNAL
|
|
uniform samplerExternalOES tex;
|
|
#elif SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_RGBX
|
|
uniform sampler2D tex;
|
|
#elif SOURCE == SOURCE_SINGLE_COLOR
|
|
uniform vec4 color;
|
|
#endif
|
|
|
|
#if SOURCE != SOURCE_SINGLE_COLOR
|
|
uniform float alpha;
|
|
#else
|
|
const float alpha = 1.0;
|
|
#endif
|
|
|
|
vec4 sample_texture() {
|
|
#if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL
|
|
return texture2D(tex, v_texcoord);
|
|
#elif SOURCE == SOURCE_TEXTURE_RGBX
|
|
return vec4(texture2D(tex, v_texcoord).rgb, 1.0);
|
|
#elif SOURCE == SOURCE_SINGLE_COLOR
|
|
return color;
|
|
#endif
|
|
}
|
|
|
|
void main() {
|
|
gl_FragColor = sample_texture() * alpha;
|
|
}
|