From 2971ca049881298cd171cf27cd3beb49d2c0572f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 28 May 2010 20:39:22 +0200 Subject: gl: bind all shader variables at the same place Avoids the need to bind the shader when creating it. --- src/cairo-gl-composite.c | 26 ++++++++++++++++++++------ src/cairo-gl-shaders.c | 11 ----------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c index 29e26e7b..edab8b3b 100644 --- a/src/cairo-gl-composite.c +++ b/src/cairo-gl-composite.c @@ -486,13 +486,14 @@ _cairo_gl_composite_set_clip_region (cairo_gl_composite_t *setup, static void _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, cairo_gl_operand_t *operand, - const char *name) + cairo_gl_tex_t tex_unit) { char uniform_name[50]; char *custom_part; + static const char *names[] = { "source", "mask" }; - strcpy (uniform_name, name); - custom_part = uniform_name + strlen (name); + strcpy (uniform_name, names[tex_unit]); + custom_part = uniform_name + strlen (names[tex_unit]); switch (operand->type) { default: @@ -500,7 +501,6 @@ _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, 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"); @@ -521,6 +521,10 @@ _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, uniform_name, operand->linear.segment_x, operand->linear.segment_y); + strcpy (custom_part, "_sampler"); + _cairo_gl_shader_bind_texture(ctx, + uniform_name, + tex_unit); break; case CAIRO_GL_OPERAND_RADIAL_GRADIENT: strcpy (custom_part, "_matrix"); @@ -540,6 +544,16 @@ _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, _cairo_gl_shader_bind_float (ctx, uniform_name, operand->radial.radius_1); + strcpy (custom_part, "_sampler"); + _cairo_gl_shader_bind_texture(ctx, + uniform_name, + tex_unit); + break; + case CAIRO_GL_OPERAND_TEXTURE: + strcpy (custom_part, "_sampler"); + _cairo_gl_shader_bind_texture(ctx, + uniform_name, + tex_unit); break; } } @@ -551,8 +565,8 @@ _cairo_gl_composite_bind_to_shader (cairo_gl_context_t *ctx, if (ctx->current_shader == NULL) return; - _cairo_gl_operand_bind_to_shader (ctx, &setup->src, "source"); - _cairo_gl_operand_bind_to_shader (ctx, &setup->mask, "mask"); + _cairo_gl_operand_bind_to_shader (ctx, &setup->src, CAIRO_GL_TEX_SOURCE); + _cairo_gl_operand_bind_to_shader (ctx, &setup->mask, CAIRO_GL_TEX_MASK); } static void diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c index 2b551192..c61f73fb 100644 --- a/src/cairo-gl-shaders.c +++ b/src/cairo-gl-shaders.c @@ -990,16 +990,5 @@ _cairo_gl_set_shader_by_type (cairo_gl_context_t *ctx, _cairo_gl_set_shader (ctx, &entry->shader); - if (source != CAIRO_GL_OPERAND_CONSTANT && - source != CAIRO_GL_OPERAND_SPANS && - source != CAIRO_GL_OPERAND_NONE) { - _cairo_gl_shader_bind_texture (ctx, "source_sampler", 0); - } - if (mask != CAIRO_GL_OPERAND_CONSTANT && - mask != CAIRO_GL_OPERAND_SPANS && - mask != CAIRO_GL_OPERAND_NONE) { - _cairo_gl_shader_bind_texture (ctx, "mask_sampler", 1); - } - return CAIRO_STATUS_SUCCESS; } -- cgit v1.2.3