From 0763262e3dcca99f17066e8209ae83a33092a8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 25 Jan 2012 23:02:06 -0500 Subject: [PATCH] compositor: Move shader setup to weston_surface_draw() --- src/compositor.c | 30 ++++++++++++++++++------------ src/compositor.h | 3 +++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index bccd3727..427d2177 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -223,6 +223,7 @@ weston_surface_create(struct weston_compositor *compositor, surface->compositor = compositor; surface->visual = WESTON_NONE_VISUAL; + surface->shader = &compositor->texture_shader; surface->image = EGL_NO_IMAGE_KHR; surface->saved_texture = 0; surface->x = x; @@ -584,9 +585,19 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output) break; } + if (ec->current_shader != es->shader) { + glUseProgram(es->shader->program); + glUniformMatrix4fv(es->shader->proj_uniform, + 1, GL_FALSE, output->matrix.d); + if (es->shader->tex_uniform != GL_NONE) + glUniform1i(es->shader->tex_uniform, 0); + if (es->shader->color_uniform != GL_NONE) + glUniform4fv(es->shader->color_uniform,1, es->color); + ec->current_shader = es->shader; + } + if (es->alpha != ec->current_alpha) { - glUniform1f(ec->texture_shader.alpha_uniform, - es->alpha / 255.0); + glUniform1f(es->shader->alpha_uniform, es->alpha / 255.0); ec->current_alpha = es->alpha; } @@ -689,7 +700,6 @@ fade_output(struct weston_output *output, { struct weston_compositor *compositor = output->compositor; struct weston_surface surface; - GLfloat color[4] = { 0.0, 0.0, 0.0, tint }; surface.compositor = compositor; surface.x = output->x; @@ -700,6 +710,11 @@ fade_output(struct weston_output *output, surface.texture = GL_NONE; surface.transform = NULL; surface.alpha = compositor->current_alpha; + surface.shader = &compositor->solid_shader; + surface.color[0] = 0.0; + surface.color[1] = 0.0; + surface.color[2] = 0.0; + surface.color[3] = tint; pixman_region32_init(&surface.damage); pixman_region32_copy(&surface.damage, region); @@ -708,10 +723,6 @@ fade_output(struct weston_output *output, else surface.visual = WESTON_RGB_VISUAL; - glUseProgram(compositor->solid_shader.program); - glUniformMatrix4fv(compositor->solid_shader.proj_uniform, - 1, GL_FALSE, output->matrix.d); - glUniform4fv(compositor->solid_shader.color_uniform, 1, color); weston_surface_draw(&surface, output); pixman_region32_fini(&surface.damage); @@ -796,11 +807,6 @@ weston_output_repaint(struct weston_output *output) glViewport(0, 0, output->current->width, output->current->height); - glUseProgram(ec->texture_shader.program); - glUniformMatrix4fv(ec->texture_shader.proj_uniform, - 1, GL_FALSE, output->matrix.d); - glUniform1i(ec->texture_shader.tex_uniform, 0); - weston_output_set_cursor(output, ec->input_device, ec->fade.spring.current >= 0.001); diff --git a/src/compositor.h b/src/compositor.h index 529cc1ac..973901ee 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -172,6 +172,7 @@ struct weston_compositor { uint32_t current_alpha; struct weston_shader texture_shader; struct weston_shader solid_shader; + struct weston_shader *current_shader; struct wl_display *wl_display; struct weston_shell *shell; @@ -239,6 +240,8 @@ struct weston_surface { struct wl_list link; struct wl_list buffer_link; struct weston_transform *transform; + struct weston_shader *shader; + GLfloat color[4]; uint32_t alpha; uint32_t visual; int overlapped;