diff options
author | Alexandros Frantzis <alexandros.frantzis@linaro.org> | 2011-03-01 16:41:21 +0200 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2011-05-10 08:19:52 +0100 |
commit | d308eee918f569227d289208e3ef1b5152bbd3f5 (patch) | |
tree | 231d5d73f3166fb29440f3b0d236aa36d1887296 /src/cairo-gl-composite.c | |
parent | 63aa65cfbb0fa25d679c24cd78139d2557bbed37 (diff) |
gl: Provide a shader implementation of GL_CLAMP_TO_BORDER for GLES2
The GL_CLAMP_TO_BORDER wrapping method (used with CAIRO_EXTEND_NONE) is not
available in GLES2. We use shaders to implement similar functionality for
GLES2.
If bilinear filtering is used, the shader performs a linear fade to
transparency effect in the texel coordinate intervals [-1/2n, 1/2n]
and [1 - 1/2n, 1 + 1/2n] (n: texture size).
If nearest filtering is used, the shader ensures that a clear color is
used for all texel coordinate values outside [0, 1).
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'src/cairo-gl-composite.c')
-rw-r--r-- | src/cairo-gl-composite.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c index 1a4467e9..4b0ead84 100644 --- a/src/cairo-gl-composite.c +++ b/src/cairo-gl-composite.c @@ -458,9 +458,30 @@ _cairo_gl_operand_bind_to_shader (cairo_gl_context_t *ctx, _cairo_gl_shader_bind_float (ctx, uniform_name, operand->gradient.radius_0); - break; + /* fall through */ case CAIRO_GL_OPERAND_LINEAR_GRADIENT: case CAIRO_GL_OPERAND_TEXTURE: + /* + * For GLES2 we use shaders to implement GL_CLAMP_TO_BORDER (used + * with CAIRO_EXTEND_NONE). When bilinear filtering is enabled, + * these shaders need the texture dimensions for their calculations. + */ + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES && + _cairo_gl_operand_get_extend (operand) == CAIRO_EXTEND_NONE && + _cairo_gl_operand_get_gl_filter (operand) == GL_LINEAR) + { + float width, height; + if (operand->type == CAIRO_GL_OPERAND_TEXTURE) { + width = operand->texture.surface->width; + height = operand->texture.surface->height; + } + else { + width = operand->gradient.gradient->cache_entry.size, + height = 1; + } + strcpy (custom_part, "_texdims"); + _cairo_gl_shader_bind_vec2 (ctx, uniform_name, width, height); + } break; } } @@ -485,8 +506,14 @@ _cairo_gl_texture_set_extend (cairo_gl_context_t *ctx, switch (extend) { case CAIRO_EXTEND_NONE: - glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + } + else { + glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri (target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + } break; case CAIRO_EXTEND_PAD: glTexParameteri (target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |