<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 2:10 PM, Marek Olšák <span dir="ltr"><<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On Thu, Jul 17, 2014 at 8:04 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> wrote:<br>
> Signed-off-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>><br>
> ---<br>
> src/mesa/main/format_info.py | 11 +++++++++++<br>
> src/mesa/main/formats.c | 46 ++++++++++++++++++++++++++++++++++++++++++++<br>
> src/mesa/main/formats.h | 29 ++++++++++++++++++++++++++++<br>
> 3 files changed, 86 insertions(+)<br>
><br>
> diff --git a/src/mesa/main/format_info.py b/src/mesa/main/format_info.py<br>
> index b8956a5..448bd00 100644<br>
> --- a/src/mesa/main/format_info.py<br>
> +++ b/src/mesa/main/format_info.py<br>
> @@ -96,6 +96,14 @@ def get_gl_data_type(fmat):<br>
> else:<br>
> assert False<br>
><br>
> +def get_mesa_layout(fmat):<br>
> + if fmat.layout == 'array':<br>
> + return 'MESA_FORMAT_LAYOUT_ARRAY'<br>
> + elif fmat.layout == 'packed':<br>
> + return 'MESA_FORMAT_LAYOUT_PACKED'<br>
> + else:<br>
> + return 'MESA_FORMAT_LAYOUT_OTHER'<br>
> +<br>
> def get_channel_bits(fmat, chan_name):<br>
> if fmat.is_compressed():<br>
> # These values are pretty-much bogus, but OpenGL requires that we<br>
> @@ -166,6 +174,7 @@ for fmat in formats:<br>
> print ' {'<br>
> print ' {0},'.format(<a href="http://fmat.name" target="_blank">fmat.name</a>)<br>
> print ' "{0}",'.format(<a href="http://fmat.name" target="_blank">fmat.name</a>)<br>
> + print ' {0},'.format(get_mesa_layout(fmat))<br>
> print ' {0},'.format(get_gl_base_format(fmat))<br>
> print ' {0},'.format(get_gl_data_type(fmat))<br>
><br>
> @@ -176,6 +185,8 @@ for fmat in formats:<br>
><br>
> print ' {0}, {1}, {2},'.format(fmat.block_width, fmat.block_height,<br>
> int(fmat.block_size() / 8))<br>
> +<br>
> + print ' {{ {0} }},'.format(', '.join(map(str, fmat.swizzle)))<br>
> print ' },'<br>
><br>
> print '};'<br>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c<br>
> index 39cc5f1..f03425e 100644<br>
> --- a/src/mesa/main/formats.c<br>
> +++ b/src/mesa/main/formats.c<br>
> @@ -40,6 +40,8 @@ struct gl_format_info<br>
> /** text name for debugging */<br>
> const char *StrName;<br>
><br>
> + enum mesa_format_layout Layout;<br>
> +<br>
> /**<br>
> * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,<br>
> * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,<br>
> @@ -67,6 +69,8 @@ struct gl_format_info<br>
> */<br>
> GLubyte BlockWidth, BlockHeight;<br>
> GLubyte BytesPerBlock;<br>
> +<br>
> + uint8_t Swizzle[4];<br>
> };<br>
><br>
> #include "format_info.c"<br>
> @@ -178,6 +182,21 @@ _mesa_get_format_max_bits(mesa_format format)<br>
><br>
><br>
> /**<br>
> + * Return the layout type of the given format.<br>
> + * The return value will be one of:<br>
> + * MESA_FORMAT_LAYOUT_ARRAY<br>
> + * MESA_FORMAT_LAYOUT_PACKED<br>
> + * MESA_FORMAT_LAYOUT_OTHER<br>
> + */<br>
> +extern enum mesa_format_layout<br>
> +_mesa_get_format_layout(mesa_format format)<br>
> +{<br>
> + const struct gl_format_info *info = _mesa_get_format_info(format);<br>
> + return info->Layout;<br>
> +}<br>
> +<br>
> +<br>
> +/**<br>
> * Return the data type (or more specifically, the data representation)<br>
> * for the given format.<br>
> * The return value will be one of:<br>
> @@ -224,6 +243,33 @@ _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh)<br>
> }<br>
><br>
><br>
> +/**<br>
> + * Returns the an array of four numbers representing the transformation<br>
> + * from the RGBA or SZ colorspace to the given format. For array formats,<br>
> + * the i'th RGBA component is given by:<br>
> + *<br>
> + * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W)<br>
> + * comp = data[swizzle[i]];<br>
> + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO)<br>
> + * comp = 0;<br>
> + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE)<br>
> + * comp = 1;<br>
> + * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE)<br>
> + * // data does not contain a channel of this format<br>
> + *<br>
> + * For packed formats, the swizzle gives the number of components left of<br>
> + * the least significant bit.<br>
> + *<br>
> + * Compressed formats have no swizzle.<br>
> + */<br>
> +void<br>
> +_mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4])<br>
> +{<br>
> + const struct gl_format_info *info = _mesa_get_format_info(format);<br>
> + memcpy(swizzle_out, info->Swizzle, sizeof(info->Swizzle));<br>
> +}<br>
> +<br>
> +<br>
> /** Is the given format a compressed format? */<br>
> GLboolean<br>
> _mesa_is_format_compressed(mesa_format format)<br>
> diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h<br>
> index dc50bc8..48aad44 100644<br>
> --- a/src/mesa/main/formats.h<br>
> +++ b/src/mesa/main/formats.h<br>
> @@ -56,6 +56,15 @@ extern "C" {<br>
> */<br>
> #define MAX_PIXEL_BYTES 16<br>
><br>
> +/**<br>
> + * Specifies the layout of a pixel format. See the MESA_FORMAT<br>
> + * documentation below.<br>
> + */<br>
> +enum mesa_format_layout {<br>
> + MESA_FORMAT_LAYOUT_ARRAY,<br>
> + MESA_FORMAT_LAYOUT_PACKED,<br>
> + MESA_FORMAT_LAYOUT_OTHER,<br>
> +};<br>
><br>
> /**<br>
> * Mesa texture/renderbuffer image formats.<br>
> @@ -419,6 +428,9 @@ _mesa_get_format_bits(mesa_format format, GLenum pname);<br>
> extern GLuint<br>
> _mesa_get_format_max_bits(mesa_format format);<br>
><br>
> +extern enum mesa_format_layout<br>
> +_mesa_get_format_layout(mesa_format format);<br>
> +<br>
> extern GLenum<br>
> _mesa_get_format_datatype(mesa_format format);<br>
><br>
> @@ -428,6 +440,23 @@ _mesa_get_format_base_format(mesa_format format);<br>
> extern void<br>
> _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh);<br>
><br>
> +/**<br>
> + * An enum representing different possible swizzling values. This is used<br>
> + * to interpret the output of _mesa_get_format_swizzle<br>
> + */<br>
> +enum {<br>
> + MESA_FORMAT_SWIZZLE_X = 0,<br>
> + MESA_FORMAT_SWIZZLE_Y = 1,<br>
> + MESA_FORMAT_SWIZZLE_Z = 2,<br>
> + MESA_FORMAT_SWIZZLE_W = 3,<br>
> + MESA_FORMAT_SWIZZLE_ZERO = 4,<br>
> + MESA_FORMAT_SWIZZLE_ONE = 5,<br>
> + MESA_FORMAT_SWIZZLE_NONE = 6,<br>
> +};<br>
<br>
</div></div>It would be nicer to declare all enums at one place in the file (e.g.<br>
at the beginning) and not between function prototypes.<br></blockquote><div><br></div><div>That's fair. I'll change that.<br></div><div>--Jason Ekstrand<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
Marek<br>
</font></span></blockquote></div><br></div></div>