compositor: Implement surface global alpha
Just a small tweak to the shader and we can control the overall surface alpha.
This commit is contained in:
parent
cd9ac1da5f
commit
541e5557ac
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user