[PATCH weston 6/8] gl-renderer: Don't multiply with alpha uniform when it's 1.0.

John Kåre Alsaker john.kare.alsaker at gmail.com
Thu Feb 21 10:19:32 PST 2013


This eliminates the multiplication of the alpha uniform for the common case
of surfaces with 1.0 as alpha.
---
 src/gl-internal.h |  1 +
 src/gl-renderer.c | 14 ++++++++------
 src/gl-shaders.c  |  6 +++---
 3 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/gl-internal.h b/src/gl-internal.h
index 44b1c75..6a46865 100644
--- a/src/gl-internal.h
+++ b/src/gl-internal.h
@@ -53,6 +53,7 @@ enum gl_conversion_attribute {
 
 enum gl_output_attribute {
 	OUTPUT_BLEND,
+	OUTPUT_TRANSPARENT,
 	OUTPUT_TO_SRGB,
 	OUTPUT_COUNT
 };
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 25f5f84..7a19b26 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -758,7 +758,8 @@ draw_surface(struct weston_surface *es, struct weston_output *output,
 	pixman_region32_t surface_blend;
 	pixman_region32_t *buffer_damage;
 	GLint filter;
-	int i;
+	int i, transparent;
+	enum gl_output_attribute output_attribute;
 
 	pixman_region32_init(&repaint);
 	pixman_region32_intersect(&repaint,
@@ -778,7 +779,10 @@ draw_surface(struct weston_surface *es, struct weston_output *output,
 		gl_shader_setup(gr->solid_shader, es, output);
 	}
 
-	shader = gl_select_shader(gr, gs->input, OUTPUT_BLEND, gs->conversion);
+	transparent = es->alpha < 1.0;
+	output_attribute = transparent ? OUTPUT_TRANSPARENT : OUTPUT_BLEND;
+
+	shader = gl_select_shader(gr, gs->input, output_attribute, gs->conversion);
 
 	gl_use_shader(gr, shader);
 	gl_shader_setup(shader, es, output);
@@ -810,13 +814,13 @@ draw_surface(struct weston_surface *es, struct weston_output *output,
 
 			struct gl_shader *rgbx_shader = gl_select_shader(gr,
 				INPUT_RGBX,
-				OUTPUT_BLEND,
+				output_attribute,
 				gs->conversion);
 			gl_use_shader(gr, rgbx_shader);
 			gl_shader_setup(rgbx_shader, es, output);
 		}
 
-		if (es->alpha < 1.0)
+		if (transparent)
 			glEnable(GL_BLEND);
 		else
 			glDisable(GL_BLEND);
@@ -945,8 +949,6 @@ draw_border(struct weston_output *output)
 
 	gl_shader_set_output(shader, output);
 
-	glUniform1f(shader->alpha_uniform, 1);
-
 	n = texture_border(output);
 
 	glActiveTexture(GL_TEXTURE0);
diff --git a/src/gl-shaders.c b/src/gl-shaders.c
index b3c81cd..8987329 100644
--- a/src/gl-shaders.c
+++ b/src/gl-shaders.c
@@ -490,8 +490,7 @@ create_shader_permutation(struct gl_renderer *renderer,
 
 	if (OPENGL_ES_VER)
 		append(&sb.global, "precision mediump float;\n");
-	append(&sb.global, "varying vec2 texture_coord;\n" \
-		"uniform float alpha;\n");
+	append(&sb.global, "varying vec2 texture_coord;\n");
 
 	append(&sb.body, "void main()\n{\n");
 
@@ -503,7 +502,8 @@ create_shader_permutation(struct gl_renderer *renderer,
 	add_conversion(&sb);
 
 	switch (sb.attributes[ATTRIBUTE_OUTPUT]) {
-	case OUTPUT_BLEND:
+	case OUTPUT_TRANSPARENT:
+		append(&sb.global, "uniform float alpha;\n");
 		append(&sb.body, "gl_FragColor *= alpha;\n");
 		break;
 	case OUTPUT_TO_SRGB:
-- 
1.8.1.3



More information about the wayland-devel mailing list