diff options
| -rw-r--r-- | sway/desktop/fx_renderer.c | 18 | ||||
| -rw-r--r-- | sway/desktop/shaders/meson.build | 6 | ||||
| -rw-r--r-- | sway/desktop/shaders/tex.frag | 29 | ||||
| -rw-r--r-- | sway/desktop/shaders/tex_decorated.frag | 63 | 
4 files changed, 39 insertions, 77 deletions
diff --git a/sway/desktop/fx_renderer.c b/sway/desktop/fx_renderer.c index 7ad209d7..80ede4d3 100644 --- a/sway/desktop/fx_renderer.c +++ b/sway/desktop/fx_renderer.c @@ -1,9 +1,8 @@ -// The original wlr_renderer was heavily referenced in making this project -// https://gitlab.freedesktop.org/wlroots/wlroots/-/tree/master/render/gles2 +/* +	The original wlr_renderer was heavily referenced in making this project +	https://gitlab.freedesktop.org/wlroots/wlroots/-/tree/master/render/gles2 +*/ -// TODO: add push / pop_gles2_debug(renderer)? - -#define _POSIX_C_SOURCE 200809L  #include <assert.h>  #include <GLES2/gl2.h>  #include <stdlib.h> @@ -18,15 +17,14 @@  #include "sway/server.h"  // shaders +#include "box_shadow_frag_src.h"  #include "common_vert_src.h" +#include "corner_frag_src.h"  #include "quad_frag_src.h"  #include "quad_round_frag_src.h"  #include "quad_round_tl_frag_src.h"  #include "quad_round_tr_frag_src.h" -#include "corner_frag_src.h" -#include "box_shadow_frag_src.h" -//#include "tex_frag_src.h" -#include "tex_decorated_frag_src.h" +#include "tex_frag_src.h"  static const GLfloat verts[] = {  	1, 0, // top right @@ -166,7 +164,7 @@ error:  static bool link_tex_program(struct fx_renderer *renderer,  		struct gles2_tex_shader *shader, enum fx_gles2_shader_source source) {  	GLuint prog; -	const GLchar *frag_src = tex_decorated_frag_src; +	const GLchar *frag_src = tex_frag_src;  	shader->program = prog = link_program(frag_src, source);  	if (!shader->program) { diff --git a/sway/desktop/shaders/meson.build b/sway/desktop/shaders/meson.build index ff5e04b2..14014c7d 100644 --- a/sway/desktop/shaders/meson.build +++ b/sway/desktop/shaders/meson.build @@ -1,14 +1,14 @@  embed = find_program('./embed.sh', native: true)  shaders = [ +    'box_shadow.frag',      'common.vert', +    'corner.frag',      'quad.frag',      'quad_round.frag',      'quad_round_tl.frag',      'quad_round_tr.frag', -    'corner.frag', -    'box_shadow.frag', -    'tex_decorated.frag', +    'tex.frag',  ]  foreach name : shaders diff --git a/sway/desktop/shaders/tex.frag b/sway/desktop/shaders/tex.frag index 3f529137..40320f9b 100644 --- a/sway/desktop/shaders/tex.frag +++ b/sway/desktop/shaders/tex.frag @@ -22,6 +22,15 @@ uniform sampler2D tex;  #endif  uniform float alpha; +uniform float dim; +uniform vec4 dim_color; +uniform vec2 size; +uniform vec2 position; +uniform float radius; +uniform bool has_titlebar; +uniform float saturation; + +const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721);  vec4 sample_texture() {  #if SOURCE == SOURCE_TEXTURE_RGBA || SOURCE == SOURCE_TEXTURE_EXTERNAL @@ -32,5 +41,23 @@ vec4 sample_texture() {  }  void main() { -    gl_FragColor = sample_texture() * alpha; +    vec4 color = sample_texture(); +    // Saturation +    if (saturation != 1.0) { +        vec4 pixColor = texture2D(tex, v_texcoord); +        vec3 irgb = pixColor.rgb; +        vec3 target = vec3(dot(irgb, saturation_weight)); +        color = vec4(mix(target, irgb, saturation), pixColor.a); +    } +    // Dimming +    gl_FragColor = mix(color, dim_color, dim) * alpha; + +    if (!has_titlebar || gl_FragCoord.y - position.y > radius) { +        vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); +        if (max(corner_distance.x, corner_distance.y) < radius) { +            float d = radius - distance(corner_distance, vec2(radius)); +            float smooth = smoothstep(-1.0f, 0.5f, d); +            gl_FragColor = mix(vec4(0), gl_FragColor, smooth); +        } +    }  } diff --git a/sway/desktop/shaders/tex_decorated.frag b/sway/desktop/shaders/tex_decorated.frag deleted file mode 100644 index 40320f9b..00000000 --- a/sway/desktop/shaders/tex_decorated.frag +++ /dev/null @@ -1,63 +0,0 @@ -/* enum wlr_gles2_shader_source */ -#define SOURCE_TEXTURE_RGBA 1 -#define SOURCE_TEXTURE_RGBX 2 -#define SOURCE_TEXTURE_EXTERNAL 3 - -#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; -#endif - -uniform float alpha; -uniform float dim; -uniform vec4 dim_color; -uniform vec2 size; -uniform vec2 position; -uniform float radius; -uniform bool has_titlebar; -uniform float saturation; - -const vec3 saturation_weight = vec3(0.2125, 0.7154, 0.0721); - -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); -#endif -} - -void main() { -    vec4 color = sample_texture(); -    // Saturation -    if (saturation != 1.0) { -        vec4 pixColor = texture2D(tex, v_texcoord); -        vec3 irgb = pixColor.rgb; -        vec3 target = vec3(dot(irgb, saturation_weight)); -        color = vec4(mix(target, irgb, saturation), pixColor.a); -    } -    // Dimming -    gl_FragColor = mix(color, dim_color, dim) * alpha; - -    if (!has_titlebar || gl_FragCoord.y - position.y > radius) { -        vec2 corner_distance = min(gl_FragCoord.xy - position, size + position - gl_FragCoord.xy); -        if (max(corner_distance.x, corner_distance.y) < radius) { -            float d = radius - distance(corner_distance, vec2(radius)); -            float smooth = smoothstep(-1.0f, 0.5f, d); -            gl_FragColor = mix(vec4(0), gl_FragColor, smooth); -        } -    } -}  | 
