mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-06-05 10:18:17 +02:00
gl: Add GLSL support for ARB_texture_rectangle, and repeat/reflect fallbacks.
Most testcases are now passing like the ARB_texture_non_power_of_two case. EXT_texture_rectangle support is dropped in favor of ARB_texture_non_power_of_two. If we have issues with drivers not having that but having EXT (which just lacks the GLSL part of the spec), we can split it out. Right now non-GLSL support in cairo-gl is probably in bad shape anyway and will require someone that cares for it in order to get fixed up.
This commit is contained in:
parent
40294377cb
commit
e845450905
2 changed files with 59 additions and 6 deletions
|
|
@ -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) +
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue