mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / formats.c
index e74625f236947a1e09097303e983e9addece34e4..5c670115ef7781d8acd2f191c37853348d6cfe18 100644 (file)
@@ -2035,6 +2035,15 @@ _mesa_is_format_signed(mesa_format format)
    }
 }
 
+/**
+ * Is the given format an integer format?
+ */
+GLboolean
+_mesa_is_format_integer(mesa_format format)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+   return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT);
+}
 
 /**
  * Return color encoding for given format.
@@ -2206,6 +2215,35 @@ _mesa_format_num_components(mesa_format format)
 }
 
 
+/**
+ * Returns true if a color format has data stored in the R/G/B/A channels,
+ * given an index from 0 to 3.
+ */
+bool
+_mesa_format_has_color_component(mesa_format format, int component)
+{
+   const struct gl_format_info *info = _mesa_get_format_info(format);
+
+   assert(info->BaseFormat != GL_DEPTH_COMPONENT &&
+          info->BaseFormat != GL_DEPTH_STENCIL &&
+          info->BaseFormat != GL_STENCIL_INDEX);
+
+   switch (component) {
+   case 0:
+      return (info->RedBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 1:
+      return (info->GreenBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 2:
+      return (info->BlueBits + info->IntensityBits + info->LuminanceBits) > 0;
+   case 3:
+      return (info->AlphaBits + info->IntensityBits) > 0;
+   default:
+      assert(!"Invalid color component: must be 0..3");
+      return false;
+   }
+}
+
+
 /**
  * Return number of bytes needed to store an image of the given size
  * in the given format.