Mesa (master): mesa: Introduce a _mesa_format_has_color_component() helper.

Kenneth Graunke kwg at kemper.freedesktop.org
Mon Mar 24 21:50:42 UTC 2014


Module: Mesa
Branch: master
Commit: 92234b1b2aaf6ba68e786498806cefd4bd99dabc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=92234b1b2aaf6ba68e786498806cefd4bd99dabc

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Mon Mar 24 01:16:57 2014 -0700

mesa: Introduce a _mesa_format_has_color_component() helper.

When considering color write masks, we often want to know whether an
RGBA component actually contains any meaningful data.  This function
provides an easy way to answer that question, and handles luminance,
intensity, and alpha formats correctly.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
Tested-by: Dylan Baker <baker.dylan.c at gmail.com>

---

 src/mesa/main/formats.c |   29 +++++++++++++++++++++++++++++
 src/mesa/main/formats.h |    4 ++++
 2 files changed, 33 insertions(+)

diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c
index e74625f..fb2501c 100644
--- a/src/mesa/main/formats.c
+++ b/src/mesa/main/formats.c
@@ -2207,6 +2207,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.
  */
diff --git a/src/mesa/main/formats.h b/src/mesa/main/formats.h
index 3079f03..89bd021 100644
--- a/src/mesa/main/formats.h
+++ b/src/mesa/main/formats.h
@@ -34,6 +34,7 @@
 
 
 #include <GL/gl.h>
+#include <stdbool.h>
 
 
 #ifdef __cplusplus
@@ -474,6 +475,9 @@ _mesa_get_uncompressed_format(mesa_format format);
 extern GLuint
 _mesa_format_num_components(mesa_format format);
 
+extern bool
+_mesa_format_has_color_component(mesa_format format, int component);
+
 GLboolean
 _mesa_format_matches_format_and_type(mesa_format mesa_format,
 				     GLenum format, GLenum type,




More information about the mesa-commit mailing list