diff options
author | Kristian Høgsberg <krh@bitplanet.net> | 2011-12-14 09:24:11 -0500 |
---|---|---|
committer | Kristian Høgsberg <krh@bitplanet.net> | 2011-12-15 11:15:12 -0500 |
commit | 541e5557aca1d77632c21372a0aed6e8c5fd5696 (patch) | |
tree | f224432086fe2ad8e6dfa10524200425381e46e3 /compositor | |
parent | cd9ac1da5f83691051fc9168e544fc82d7d884d0 (diff) |
compositor: Implement surface global alpha
Just a small tweak to the shader and we can control the overall surface alpha.
Diffstat (limited to 'compositor')
-rw-r--r-- | compositor/compositor.c | 10 | ||||
-rw-r--r-- | compositor/compositor.h | 5 |
2 files changed, 14 insertions, 1 deletions
diff --git a/compositor/compositor.c b/compositor/compositor.c index 220f51ca..cb9b41fd 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -225,6 +225,7 @@ wlsc_surface_create(struct wlsc_compositor *compositor, surface->y = y; surface->width = width; surface->height = height; + surface->alpha = 255; surface->fullscreen_output = NULL; surface->buffer = NULL; @@ -548,6 +549,12 @@ wlsc_surface_draw(struct wlsc_surface *es, break; } + if (es->alpha != ec->current_alpha) { + glUniform1f(ec->texture_shader.alpha_uniform, + es->alpha / 255.0); + ec->current_alpha = es->alpha; + } + if (es->transform == NULL) { filter = GL_NEAREST; n = texture_region(es, &repaint); @@ -1626,9 +1633,11 @@ static const char texture_fragment_shader[] = "precision mediump float;\n" "varying vec2 v_texcoord;\n" "uniform sampler2D tex;\n" + "uniform float alpha;\n" "void main()\n" "{\n" " gl_FragColor = texture2D(tex, v_texcoord)\n;" + " gl_FragColor = alpha * gl_FragColor;\n" "}\n"; static const char solid_fragment_shader[] = @@ -1687,6 +1696,7 @@ wlsc_shader_init(struct wlsc_shader *shader, shader->proj_uniform = glGetUniformLocation(shader->program, "proj"); shader->tex_uniform = glGetUniformLocation(shader->program, "tex"); + shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha"); return 0; } diff --git a/compositor/compositor.h b/compositor/compositor.h index cbcbcfce..0b3f82e1 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -128,6 +128,7 @@ struct wlsc_shader { GLuint vertex_shader, fragment_shader; GLuint proj_uniform; GLuint tex_uniform; + GLuint alpha_uniform; GLuint color_uniform; }; @@ -173,7 +174,8 @@ struct wlsc_compositor { EGLContext context; EGLConfig config; GLuint fbo; - GLuint proj_uniform, tex_uniform; + GLuint proj_uniform, tex_uniform, alpha_uniform; + uint32_t current_alpha; struct wlsc_shader texture_shader; struct wlsc_shader solid_shader; struct wl_display *wl_display; @@ -241,6 +243,7 @@ struct wlsc_surface { struct wl_list link; struct wl_list buffer_link; struct wlsc_transform *transform; + uint32_t alpha; uint32_t visual; /* |