[cairo] [patch] gl: create BGRA texture and avoid conversion
Henry (Yu) Song - SISA
hsong at sisa.samsung.com
Wed Jan 30 13:32:01 PST 2013
OK, I am not making it clear.
On Desktop with GL drivers, BGRA-format texture is not allowed (http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml). However, driver can do auto-conversion from BGRA to internal format of RGBA.
On GLES driver, if the driver supports GL_EXT_texture_format_BGRA8888, it can create BGRA texture. if the driver supports GL_EXT_read_bgra - it also supports reading BGRA data back with glReadPixels. Only if these two extensions are present, we can be sure we can upload and download BGRA image, otherwise, a conversion of BGRA to RGBA is unavoidable. On GLES driver, it is not guaranteed you create a RGBA texture and can upload BGRA data (some drivers do allow that, for example, mesa and img).
In the patch ctx->supports_bgra is TRUE only GL_EXT_texture_format_BGRA888 and GL_EXT_read_rgba are both present.
You are right on last point, I should leave PIXMAN_x8b8g8r8/PIXMAN_r8g8b8x8 in place. Better to resubmit the entire patch?
From: Martin Robinson [mrobinson at igalia.com]
Sent: Wednesday, January 30, 2013 1:07 PM
To: Henry (Yu) Song - SISA
Cc: cairo at cairographics.org
Subject: Re: [cairo] [patch] gl: create BGRA texture and avoid conversion
On 01/30/2013 12:48 PM, Henry (Yu) Song - SISA wrote:
> ctx->supports_bgra is more meaningful, it means it supports both
> creating BGRA texture and can read that back into BGRA format.
> The GL_EXT_texture_format_BGRA888 is requirement of cairo, as
> checked at line 223 in cairo-gl-device.c . There is no need
> to check it again.
Maybe I'm misunderstanding this: Cairo requires
GL_EXT_texture_format_BGRA888, which means that all drivers that support
Cairo support uploading BGRA data to textures. Thus the only distinction
necessary in the context is whether or not the hardware and driver
support reading BGRA data. That you can upload BGRA is implicit.
> ctx-supports_bgra == FALSE on desktop is to prevent create BGRA
> texture on GL drivers, OpenGL does not allow to create texture
> of internal format of BGRA.
It seems better to simply check at the time you create the texture or to
add a helper method like _cairo_gl_can_create_bgra_textures. Desktop
always supports BGRA.
> The last point is something to do with stride difference of PIXMAN_a8b8g8r8
> vs. PIXMAN_x8b8g8r8. At least I know some gles driver does not upload
> PIXMAN_x8b8g8r8 format correctly.
Driver bugs? Perhaps people who know pixman better have an idea. Seems
odd to punish all devices.
More information about the cairo