util: Utility function to determine the channels that can be written in a color format.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 3 Sep 2010 19:21:33 +0000 (20:21 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Sun, 5 Sep 2010 09:17:51 +0000 (10:17 +0100)
src/gallium/auxiliary/util/u_format.h

index 8e786a390a0a4c69e8e7008951ed13cd258857e0..59bd03b77406669da10225b10fbc82c298601cb3 100644 (file)
@@ -440,6 +440,39 @@ util_format_is_depth_and_stencil(enum pipe_format format)
            desc->swizzle[1] != UTIL_FORMAT_SWIZZLE_NONE) ? TRUE : FALSE;
 }
 
+
+/**
+ * Give the RGBA colormask of the channels that can be represented in this
+ * format.
+ *
+ * That is, the channels whose values are preserved.
+ */
+static INLINE unsigned
+util_format_colormask(const struct util_format_description *desc)
+{
+   unsigned colormask;
+   unsigned chan;
+
+   switch (desc->colorspace) {
+   case UTIL_FORMAT_COLORSPACE_RGB:
+   case UTIL_FORMAT_COLORSPACE_SRGB:
+   case UTIL_FORMAT_COLORSPACE_YUV:
+      colormask = 0;
+      for (chan = 0; chan < 4; ++chan) {
+         if (desc->swizzle[chan] < 4) {
+            colormask |= (1 << chan);
+         }
+      }
+      return colormask;
+   case UTIL_FORMAT_COLORSPACE_ZS:
+      return 0;
+   default:
+      assert(0);
+      return 0;
+   }
+}
+
+
 /**
  * Whether this format is a rgab8 variant.
  *