compositor: Implement surface global alpha

Just a small tweak to the shader and we can control the overall surface alpha.
dev
Kristian Høgsberg 14 years ago
parent cd9ac1da5f
commit 541e5557ac
  1. 10
      compositor/compositor.c
  2. 5
      compositor/compositor.h

@ -225,6 +225,7 @@ wlsc_surface_create(struct wlsc_compositor *compositor,
surface->y = y; surface->y = y;
surface->width = width; surface->width = width;
surface->height = height; surface->height = height;
surface->alpha = 255;
surface->fullscreen_output = NULL; surface->fullscreen_output = NULL;
surface->buffer = NULL; surface->buffer = NULL;
@ -548,6 +549,12 @@ wlsc_surface_draw(struct wlsc_surface *es,
break; 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) { if (es->transform == NULL) {
filter = GL_NEAREST; filter = GL_NEAREST;
n = texture_region(es, &repaint); n = texture_region(es, &repaint);
@ -1626,9 +1633,11 @@ static const char texture_fragment_shader[] =
"precision mediump float;\n" "precision mediump float;\n"
"varying vec2 v_texcoord;\n" "varying vec2 v_texcoord;\n"
"uniform sampler2D tex;\n" "uniform sampler2D tex;\n"
"uniform float alpha;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_FragColor = texture2D(tex, v_texcoord)\n;" " gl_FragColor = texture2D(tex, v_texcoord)\n;"
" gl_FragColor = alpha * gl_FragColor;\n"
"}\n"; "}\n";
static const char solid_fragment_shader[] = 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->proj_uniform = glGetUniformLocation(shader->program, "proj");
shader->tex_uniform = glGetUniformLocation(shader->program, "tex"); shader->tex_uniform = glGetUniformLocation(shader->program, "tex");
shader->alpha_uniform = glGetUniformLocation(shader->program, "alpha");
return 0; return 0;
} }

@ -128,6 +128,7 @@ struct wlsc_shader {
GLuint vertex_shader, fragment_shader; GLuint vertex_shader, fragment_shader;
GLuint proj_uniform; GLuint proj_uniform;
GLuint tex_uniform; GLuint tex_uniform;
GLuint alpha_uniform;
GLuint color_uniform; GLuint color_uniform;
}; };
@ -173,7 +174,8 @@ struct wlsc_compositor {
EGLContext context; EGLContext context;
EGLConfig config; EGLConfig config;
GLuint fbo; 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 texture_shader;
struct wlsc_shader solid_shader; struct wlsc_shader solid_shader;
struct wl_display *wl_display; struct wl_display *wl_display;
@ -241,6 +243,7 @@ struct wlsc_surface {
struct wl_list link; struct wl_list link;
struct wl_list buffer_link; struct wl_list buffer_link;
struct wlsc_transform *transform; struct wlsc_transform *transform;
uint32_t alpha;
uint32_t visual; uint32_t visual;
/* /*

Loading…
Cancel
Save