[RFCv2 7/9] gl-renderer: Don't multiply with alpha uniform when it's 1.0.

John Kåre Alsaker john.kare.alsaker at gmail.com
Fri Nov 16 18:23:58 PST 2012


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 2a1f0c6..b8140c8 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 c5b3908..5847e12 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -744,7 +744,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,
@@ -764,7 +765,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);
@@ -796,13 +800,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);
@@ -931,8 +935,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 0f49eb8..9a88ec8 100644
--- a/src/gl-shaders.c
+++ b/src/gl-shaders.c
@@ -489,8 +489,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");
 
@@ -502,7 +501,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.0



More information about the wayland-devel mailing list