diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c index e2797d580..70a8c757c 100644 --- a/src/cairo-gl-shaders.c +++ b/src/cairo-gl-shaders.c @@ -717,6 +717,13 @@ static const char *fs_source_texture = "{\n" " return texture2D(source_sampler, source_texcoords);\n" "}\n"; +static const char *fs_source_texture_rect = + "uniform sampler2DRect source_sampler;\n" + "varying vec2 source_texcoords;\n" + "vec4 get_source()\n" + "{\n" + " return texture2DRect(source_sampler, source_texcoords);\n" + "}\n"; static const char *fs_source_texture_alpha = "uniform sampler2D source_sampler;\n" "varying vec2 source_texcoords;\n" @@ -724,6 +731,13 @@ static const char *fs_source_texture_alpha = "{\n" " return vec4(0, 0, 0, texture2D(source_sampler, source_texcoords).a);\n" "}\n"; +static const char *fs_source_texture_alpha_rect = + "uniform sampler2DRect source_sampler;\n" + "varying vec2 source_texcoords;\n" + "vec4 get_source()\n" + "{\n" + " return vec4(0, 0, 0, texture2DRect(source_sampler, source_texcoords).a);\n" + "}\n"; static const char *fs_source_linear_gradient = "uniform sampler1D source_sampler;\n" "uniform mat4 source_matrix;\n" @@ -784,6 +798,13 @@ static const char *fs_mask_texture = "{\n" " return texture2D(mask_sampler, mask_texcoords);\n" "}\n"; +static const char *fs_mask_texture_rect = + "uniform sampler2DRect mask_sampler;\n" + "varying vec2 mask_texcoords;\n" + "vec4 get_mask()\n" + "{\n" + " return texture2DRect(mask_sampler, mask_texcoords);\n" + "}\n"; static const char *fs_mask_texture_alpha = "uniform sampler2D mask_sampler;\n" "varying vec2 mask_texcoords;\n" @@ -791,6 +812,13 @@ static const char *fs_mask_texture_alpha = "{\n" " return vec4(0, 0, 0, texture2D(mask_sampler, mask_texcoords).a);\n" "}\n"; +static const char *fs_mask_texture_alpha_rect = + "uniform sampler2DRect mask_sampler;\n" + "varying vec2 mask_texcoords;\n" + "vec4 get_mask()\n" + "{\n" + " return vec4(0, 0, 0, texture2DRect(mask_sampler, mask_texcoords).a);\n" + "}\n"; static const char *fs_mask_linear_gradient = "uniform sampler1D mask_sampler;\n" "uniform mat4 mask_matrix;\n" @@ -935,6 +963,22 @@ _cairo_gl_get_program (cairo_gl_context_t *ctx, source_source = source_sources[source]; mask_source = mask_sources[mask]; in_source = in_sources[in]; + + /* For ARB_texture_rectangle, rewrite sampler2D and texture2D to + * sampler2DRect and texture2DRect. + */ + if (ctx->tex_target == GL_TEXTURE_RECTANGLE_EXT) { + if (source_source == fs_source_texture) + source_source = fs_source_texture_rect; + else if (source_source == fs_source_texture_alpha) + source_source = fs_source_texture_alpha_rect; + + if (mask_source == fs_mask_texture) + mask_source = fs_mask_texture_rect; + else if (mask_source == fs_mask_texture_alpha) + mask_source = fs_mask_texture_alpha_rect; + } + fs_source = _cairo_malloc (strlen(source_source) + strlen(mask_source) + strlen(in_source) + diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index 6470f69b6..f86a4fd73 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -119,10 +119,10 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx) } if (! GLEW_ARB_texture_non_power_of_two && - ! GLEW_EXT_texture_rectangle ) { + ! GLEW_ARB_texture_rectangle ) { fprintf (stderr, "Required GL extensions not available:\n"); - fprintf (stderr, " GL_ARB_texture_non_power_of_two, GL_EXT_texture_rectangle\n"); + fprintf (stderr, " GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle\n"); } if (!GLEW_ARB_texture_non_power_of_two) @@ -382,11 +382,10 @@ _cairo_gl_set_texture_surface (int tex_unit, GLuint tex, { if (tex_target == GL_TEXTURE_RECTANGLE_EXT) { - if (attributes->extend == CAIRO_EXTEND_REPEAT || - attributes->extend == CAIRO_EXTEND_REFLECT) - fprintf(stderr,"cannot use rect texture for repeat/reflect\n"); + assert (attributes->extend != CAIRO_EXTEND_REPEAT && + attributes->extend != CAIRO_EXTEND_REFLECT); } - + glActiveTexture (GL_TEXTURE0 + tex_unit); glBindTexture (tex_target, tex); switch (attributes->extend) { @@ -1175,6 +1174,16 @@ _cairo_gl_pattern_texture_setup (cairo_gl_composite_operand_t *operand, if (unlikely (status)) return status; + if (ctx->tex_target == GL_TEXTURE_RECTANGLE_EXT && + (attributes->extend == CAIRO_EXTEND_REPEAT || + attributes->extend == CAIRO_EXTEND_REFLECT)) + { + _cairo_pattern_release_surface (operand->pattern, + &surface->base, + attributes); + return UNSUPPORTED ("EXT_texture_rectangle with repeat/reflect"); + } + assert (surface->base.backend == &_cairo_gl_surface_backend); operand->operand.texture.surface = surface;