diff options
author | Benjamin Otte <otte@redhat.com> | 2010-05-19 18:21:06 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2010-05-20 11:02:49 +0200 |
commit | 065969d78f23c634ebcb2b931cbb1fe184f2cedf (patch) | |
tree | f39c4389a10270d59d7a9a426f72c42c0d6a3beb /src/cairo-gl-composite.c | |
parent | c53f7778bcf274f64f801ef9ee1641a088842f60 (diff) |
gl: Separate binding to shaders from setting operands
That way we only need to bind to shaders when creating them, but not
everytime we switch shaders on text output.
Diffstat (limited to 'src/cairo-gl-composite.c')
-rw-r--r-- | src/cairo-gl-composite.c | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c index 61bac273..76ae6cdd 100644 --- a/src/cairo-gl-composite.c +++ b/src/cairo-gl-composite.c @@ -539,31 +539,86 @@ _cairo_gl_composite_set_clip_region (cairo_gl_context_t *ctx, } static void -_cairo_gl_set_tex_combine_constant_color (cairo_gl_context_t *ctx, - cairo_gl_composite_t *setup, - int tex_unit, - GLfloat *color) +_cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, + cairo_gl_shader_t *shader, + cairo_gl_operand_t *operand, + const char *name) { - if (setup->shader) { - const char *uniform_name; + char uniform_name[50]; + char *custom_part; - if (tex_unit == 0) - uniform_name = "source_constant"; - else - uniform_name = "mask_constant"; + strcpy (uniform_name, name); + custom_part = uniform_name + strlen (name); + switch (operand->type) { + default: + case CAIRO_GL_OPERAND_COUNT: + ASSERT_NOT_REACHED; + case CAIRO_GL_OPERAND_NONE: + case CAIRO_GL_OPERAND_SPANS: + case CAIRO_GL_OPERAND_TEXTURE: + break; + case CAIRO_GL_OPERAND_CONSTANT: + strcpy (custom_part, "_constant"); _cairo_gl_shader_bind_vec4 (ctx, - setup->shader, - uniform_name, - color[0], - color[1], - color[2], - color[3]); - - return; + shader, + uniform_name, + operand->constant.color[0], + operand->constant.color[1], + operand->constant.color[2], + operand->constant.color[3]); + break; + case CAIRO_GL_OPERAND_LINEAR_GRADIENT: + strcpy (custom_part, "_matrix"); + _cairo_gl_shader_bind_matrix (ctx, shader, + uniform_name, + &operand->linear.m); + strcpy (custom_part, "_segment"); + _cairo_gl_shader_bind_vec2 (ctx, shader, + uniform_name, + operand->linear.segment_x, + operand->linear.segment_y); + break; + case CAIRO_GL_OPERAND_RADIAL_GRADIENT: + strcpy (custom_part, "_matrix"); + _cairo_gl_shader_bind_matrix (ctx, shader, + uniform_name, + &operand->radial.m); + strcpy (custom_part, "_circle_1"); + _cairo_gl_shader_bind_vec2 (ctx, shader, + uniform_name, + operand->radial.circle_1_x, + operand->radial.circle_1_y); + strcpy (custom_part, "_radius_0"); + _cairo_gl_shader_bind_float (ctx, shader, + uniform_name, + operand->radial.radius_0); + strcpy (custom_part, "_radius_1"); + _cairo_gl_shader_bind_float (ctx, shader, + uniform_name, + operand->radial.radius_1); + break; } +} + +static void +_cairo_gl_composite_bind_to_shader (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + cairo_gl_shader_t *shader) +{ + if (shader == NULL) + return; + + _cairo_gl_operand_bind_to_shader (ctx, shader, &setup->src, "source"); + _cairo_gl_operand_bind_to_shader (ctx, shader, &setup->mask, "mask"); +} - /* Fall back to fixed function */ +static void +_cairo_gl_set_tex_combine_constant_color (cairo_gl_context_t *ctx, + cairo_gl_composite_t *setup, + int tex_unit, + GLfloat *color) +{ glActiveTexture (GL_TEXTURE0 + tex_unit); /* Have to have a dummy texture bound in order to use the combiner unit. */ glBindTexture (ctx->tex_target, ctx->dummy_tex); @@ -638,38 +693,12 @@ _cairo_gl_set_src_operand (cairo_gl_context_t *ctx, glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_1D, setup->src.linear.tex); glEnable (GL_TEXTURE_1D); - - _cairo_gl_shader_bind_matrix (ctx, setup->shader, - "source_matrix", - &setup->src.linear.m); - - _cairo_gl_shader_bind_vec2 (ctx, setup->shader, - "source_segment", - setup->src.linear.segment_x, - setup->src.linear.segment_y); break; case CAIRO_GL_OPERAND_RADIAL_GRADIENT: glActiveTexture (GL_TEXTURE0); glBindTexture (GL_TEXTURE_1D, setup->src.linear.tex); glEnable (GL_TEXTURE_1D); - - _cairo_gl_shader_bind_matrix (ctx, setup->shader, - "source_matrix", - &setup->src.radial.m); - - _cairo_gl_shader_bind_vec2 (ctx, setup->shader, - "source_circle_1", - setup->src.radial.circle_1_x, - setup->src.radial.circle_1_y); - - _cairo_gl_shader_bind_float (ctx, setup->shader, - "source_radius_0", - setup->src.radial.radius_0); - - _cairo_gl_shader_bind_float (ctx, setup->shader, - "source_radius_1", - setup->src.radial.radius_1); break; default: case CAIRO_GL_OPERAND_COUNT: @@ -737,14 +766,6 @@ _cairo_gl_set_linear_gradient_mask_operand (cairo_gl_context_t *ctx, glActiveTexture (GL_TEXTURE1); glBindTexture (GL_TEXTURE_1D, setup->mask.linear.tex); glEnable (GL_TEXTURE_1D); - - _cairo_gl_shader_bind_matrix (ctx, setup->shader, - "mask_matrix", &setup->mask.linear.m); - - _cairo_gl_shader_bind_vec2 (ctx, setup->shader, - "mask_segment", - setup->mask.linear.segment_x, - setup->mask.linear.segment_y); } static void @@ -756,23 +777,6 @@ _cairo_gl_set_radial_gradient_mask_operand (cairo_gl_context_t *ctx, glActiveTexture (GL_TEXTURE1); glBindTexture (GL_TEXTURE_1D, setup->mask.radial.tex); glEnable (GL_TEXTURE_1D); - - _cairo_gl_shader_bind_matrix (ctx, setup->shader, - "mask_matrix", - &setup->mask.radial.m); - - _cairo_gl_shader_bind_vec2 (ctx, setup->shader, - "mask_circle_1", - setup->mask.radial.circle_1_x, - setup->mask.radial.circle_1_y); - - _cairo_gl_shader_bind_float (ctx, setup->shader, - "mask_radius_0", - setup->mask.radial.radius_0); - - _cairo_gl_shader_bind_float (ctx, setup->shader, - "mask_radius_1", - setup->mask.radial.radius_1); } /* This is like _cairo_gl_set_src_alpha_operand, for component alpha setup @@ -801,14 +805,7 @@ _cairo_gl_set_component_alpha_mask_operand (cairo_gl_context_t *ctx, switch (setup->mask.type) { case CAIRO_GL_OPERAND_CONSTANT: /* Have to have a dummy texture bound in order to use the combiner unit. */ - if (setup->shader) { - _cairo_gl_shader_bind_vec4 (ctx, setup->shader, - "mask_constant", - setup->mask.constant.color[0], - setup->mask.constant.color[1], - setup->mask.constant.color[2], - setup->mask.constant.color[3]); - } else { + if (! setup->shader) { glBindTexture (ctx->tex_target, ctx->dummy_tex); glActiveTexture (GL_TEXTURE1); glEnable (ctx->tex_target); @@ -1095,6 +1092,8 @@ _cairo_gl_composite_begin_component_alpha (cairo_gl_context_t *ctx, &setup->pre_shader); if (unlikely (status)) return status; + _cairo_gl_set_shader (ctx, setup->pre_shader); + _cairo_gl_composite_bind_to_shader (ctx, setup, setup->pre_shader); } return CAIRO_STATUS_SUCCESS; @@ -1139,6 +1138,7 @@ _cairo_gl_composite_begin (cairo_gl_context_t *ctx, setup->has_component_alpha); _cairo_gl_set_shader (ctx, setup->shader); + _cairo_gl_composite_bind_to_shader (ctx, setup, setup->shader); glBindBufferARB (GL_ARRAY_BUFFER_ARB, ctx->vbo); |