From 2da78fd4666faa27d037ae3625ca83353a6e7629 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 1 Jun 2009 14:04:21 -0700 Subject: [PATCH] [gl] Drop use of packed datatypes where it's disallowed. I had naively assumed that GL image specification let you do useful things and describe the most common datatypes in graphics, since we do things that way inside of the DRI drivers. Silly me. GL_BGR and GL_RGB can't do GL_UNSIGNED_INT_8_8_8_8{,_REV}, so no specifying 24-depth 32-bpp data with implicit alpha. GL_BGR can't even do r5g6b5! This fixes 20 regressions in the test suite. --- src/cairo-gl-surface.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index c052794ab..2d601eed5 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -840,6 +840,12 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, image_surface = (cairo_image_surface_t *)surface_pattern->surface; + /* The textures we create almost always has appropriate alpha channel + * contents. But sometimes GL sucks at image specification and we end up + * with junk in the alpha. + */ + operand->operand.texture.has_alpha = TRUE; + switch (image_surface->pixman_format) { case PIXMAN_a8r8g8b8: internal_format = GL_RGBA; @@ -848,8 +854,9 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, break; case PIXMAN_x8r8g8b8: internal_format = GL_RGB; - format = GL_BGR; + format = GL_BGRA; type = GL_UNSIGNED_INT_8_8_8_8_REV; + operand->operand.texture.has_alpha = FALSE; break; case PIXMAN_a8b8g8r8: internal_format = GL_RGBA; @@ -858,8 +865,9 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, break; case PIXMAN_x8b8g8r8: internal_format = GL_RGB; - format = GL_RGB; + format = GL_RGBA; type = GL_UNSIGNED_INT_8_8_8_8_REV; + operand->operand.texture.has_alpha = FALSE; break; case PIXMAN_b8g8r8a8: internal_format = GL_BGRA; @@ -881,17 +889,13 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, format = GL_RGB; type = GL_UNSIGNED_SHORT_5_6_5; break; - case PIXMAN_b5g6r5: - internal_format = GL_RGB; - format = GL_BGR; - type = GL_UNSIGNED_SHORT_5_6_5; - break; case PIXMAN_a8: internal_format = GL_ALPHA; format = GL_ALPHA; type = GL_UNSIGNED_BYTE; break; + case PIXMAN_b5g6r5: case PIXMAN_a1r5g5b5: case PIXMAN_x1r5g5b5: case PIXMAN_a1b5g5r5: @@ -932,7 +936,8 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, assert(((image_surface->stride * image_surface->depth) % image_surface->depth) == 0); glPixelStorei (GL_UNPACK_ROW_LENGTH, - image_surface->stride / (image_surface->depth / 8)); + image_surface->stride / + (PIXMAN_FORMAT_BPP(image_surface->pixman_format) / 8)); /* The filter will be correctly set up later, but for now we want to * hint to glTexImage that we're not mipmapping. */ @@ -948,10 +953,6 @@ _cairo_gl_pattern_image_texture_setup (cairo_gl_composite_operand_t *operand, operand->type = OPERAND_TEXTURE; operand->operand.texture.tex = tex; operand->operand.texture.surface = NULL; - /* The textures we create always have appropriate alpha channels -- - * we aren't uploading x8 channels to a8 channels. - */ - operand->operand.texture.has_alpha = TRUE; attributes->matrix = src->matrix; attributes->extend = src->extend; attributes->filter = src->filter;