General comment: Maybe this would be better in gltypes rather than in
mesa_formats
On Tue, Nov 18, 2014 at 1:23 AM, Iago Toral Quiroga
wrote:
> ---
> src/mesa/main/formats.c | 285
>
> src/mesa/main/formats.h | 3 +
> 2 files changed, 288 insertions(+)
>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
> index 06e8973..7464d89 100644
> --- a/src/mesa/main/formats.c
> +++ b/src/mesa/main/formats.c
> @@ -325,6 +325,291 @@ _mesa_format_from_array_format(uint32_t array_format)
> return MESA_FORMAT_NONE;
> }
>
> +static void
> +_mesa_array_format_set_swizzle(mesa_array_format *array_format,
> + int x, int y, int z, int w)
> +{
> + array_format->swizzle_x = x;
> + array_format->swizzle_y = y;
> + array_format->swizzle_z = z;
> + array_format->swizzle_w = w;
> +}
> +
> +static bool
> +_mesa_array_format_set_swizzle_from_format(mesa_array_format
> *array_format,
> + GLenum format)
> +{
> + switch (format) {
> + case GL_RGBA:
> + case GL_RGBA_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 0, 1, 2, 3);
> + return true;
> + case GL_BGRA:
> + case GL_BGRA_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 2, 1, 0, 3);
> + return true;
> + case GL_ABGR_EXT:
> + _mesa_array_format_set_swizzle(array_format, 3, 2, 1, 0);
> + return true;
> + case GL_RGB:
> + case GL_RGB_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 0, 1, 2, 5);
> + return true;
> + case GL_BGR:
> + case GL_BGR_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 2, 1, 0, 5);
> + return true;
> + case GL_LUMINANCE_ALPHA:
> + case GL_LUMINANCE_ALPHA_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 1);
> + return true;
> + case GL_RG:
> + case GL_RG_INTEGER:
> + _mesa_array_format_set_swizzle(array_format, 0, 1, 4, 5);
> + return true;
> + case GL_RED:
> + case GL_RED_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 0, 4, 4, 5);
> + return true;
> + case GL_GREEN:
> + case GL_GREEN_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 4, 0, 4, 5);
> + return true;
> + case GL_BLUE:
> + case GL_BLUE_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 4, 4, 0, 5);
> + return true;
> + case GL_ALPHA:
> + case GL_ALPHA_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 4, 4, 4, 0);
> + return true;
> + case GL_LUMINANCE:
> + case GL_LUMINANCE_INTEGER_EXT:
> + _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 5);
> + return true;
> + case GL_INTENSITY:
> + _mesa_array_format_set_swizzle(array_format, 0, 0, 0, 0);
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> +/**
> +* Take an OpenGL format (GL_RGB, GL_RGBA, etc), OpenGL data type (GL_INT,
> +* GL_FOAT, etc) and return a matching mesa_array_format or a mesa_format
> +* otherwise (for non-array formats).
> +*
> +* This function will typically be used to compute a mesa format from a GL
> type
> +* so we can then call _mesa_format_convert. This function does
> +* not consider byte swapping, so it returns types assuming that no byte
> +* swapping is involved. If byte swapping is involved then clients are
> supposed
> +* to handle that on their side before calling _mesa_format_convert.
> +*
> +* This function returns an uint32_t that can pack a mesa_format or a
> +* mesa_array_format. Clients must check the mesa array format bit
> +* (MESA_ARRAY_FORMAT_BIT) on the return value to know if the returned
> +* format is a mesa_array_format or a mesa_format.
> +*/
> +uint32_t
> +_mesa_format_from_format_and_type(GLenum format, GLenum type)
> +{
> + mesa_array_format array_format;
> +
> + bool is_array_format = true;
> +
> + /* Map the OpenGL data type to an array format data type */
> + switch (type) {
> + case GL_UNSIGNED_BYTE:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_UBYTE;
> + break;
> + case GL_BYTE:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_BYTE;
> + break;
> + case GL_UNSIGNED_SHORT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_USHORT;
> + break;
> + case GL_SHORT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_SHORT;
> + break;
> + case GL_UNSIGNED_INT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_UINT;
> + break;
> + case GL_INT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_INT;
> + break;
> + case GL_HALF_FLOAT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_HALF;
> + break;
> + case GL_FLOAT:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_FLOAT;
> + break;
> + case GL_UNSIGNED_INT_8_8_8_8:
> + case GL_UNSIGNED_INT_8_8_8_8_REV:
> + array_format.type = MESA_ARRAY_FORMAT_TYPE_UBYTE;
>
If you put these in the GL typ