[Mesa-dev] [PATCH 07/14] mesa: use swapBytes parameter in _mesa_format_matches_format_and_type()

Jose Fonseca jfonseca at vmware.com
Fri Jan 27 07:27:05 PST 2012



----- Original Message -----
> On Fri, Jan 27, 2012 at 2:33 AM, Jose Fonseca <jfonseca at vmware.com>
> wrote:
> > Brian,
> >
> > This is probably right but a tad verbose, and error prone.
> >
> > I'm not sure what's the best way to simplify this though. It's not
> > possible to canonize the comparisons because there are missing
> > combinations.
> >
> > But I think that at least using ternary operators would make the
> > code more compact and help ensuring thar cases don't follow
> > through the cracks. For example:
> >
> >    case MESA_FORMAT_RGBA8888:
> >
> >        if (format == GL_RGBA &&
> >            type == (!swapBytes ? GL_UNSIGNED_INT_8_8_8_8 :
> >            GL_UNSIGNED_INT_8_8_8_8_REV))
> >            return GL_TRUE;
> >
> >        if (format == GL_ABGR_EXT &&
> >            type == (!swapBytes ? GL_UNSIGNED_INT_8_8_8_8_REV :
> >            GL_UNSIGNED_INT_8_8_8_8))
> >            return GL_TRUE;
> >
> >       if (format == (!littleEndian ? GL_RGBA : GL_ABGR_EXT) &&
> >           type == GL_UNSIGNED_BYTE)
> >           return GL_TRUE;
> 
> Honestly, I find my approach easier to read and understand than that.
> 
> I don't think there's an ideal way to express all the various
> combinations.  I opted for simple (if verbose) logic over more
> sophisticated logic (which can be error-prone too).

Fair enough.

Jose


More information about the mesa-dev mailing list