[Mesa-dev] [PATCH 2/7] glsl: move gl_vert_attrib_name() definition to shader_enums.h

Emil Velikov emil.l.velikov at gmail.com
Thu Oct 8 10:09:26 PDT 2015


This is a trivial enough function that can live in the header. While
we're here, add a STATIC_ASSERT for good measure.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/glsl/shader_enums.c | 40 ----------------------------------------
 src/glsl/shader_enums.h | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 41 deletions(-)

diff --git a/src/glsl/shader_enums.c b/src/glsl/shader_enums.c
index b3da3e9..4abdc328 100644
--- a/src/glsl/shader_enums.c
+++ b/src/glsl/shader_enums.c
@@ -32,46 +32,6 @@
 #define ENUM(x) [x] = #x
 #define NAME(val) ((((val) < ARRAY_SIZE(names)) && names[(val)]) ? names[(val)] : "UNKNOWN")
 
-const char * gl_vert_attrib_name(gl_vert_attrib attrib)
-{
-   static const char *names[] = {
-      ENUM(VERT_ATTRIB_POS),
-      ENUM(VERT_ATTRIB_WEIGHT),
-      ENUM(VERT_ATTRIB_NORMAL),
-      ENUM(VERT_ATTRIB_COLOR0),
-      ENUM(VERT_ATTRIB_COLOR1),
-      ENUM(VERT_ATTRIB_FOG),
-      ENUM(VERT_ATTRIB_COLOR_INDEX),
-      ENUM(VERT_ATTRIB_EDGEFLAG),
-      ENUM(VERT_ATTRIB_TEX0),
-      ENUM(VERT_ATTRIB_TEX1),
-      ENUM(VERT_ATTRIB_TEX2),
-      ENUM(VERT_ATTRIB_TEX3),
-      ENUM(VERT_ATTRIB_TEX4),
-      ENUM(VERT_ATTRIB_TEX5),
-      ENUM(VERT_ATTRIB_TEX6),
-      ENUM(VERT_ATTRIB_TEX7),
-      ENUM(VERT_ATTRIB_POINT_SIZE),
-      ENUM(VERT_ATTRIB_GENERIC0),
-      ENUM(VERT_ATTRIB_GENERIC1),
-      ENUM(VERT_ATTRIB_GENERIC2),
-      ENUM(VERT_ATTRIB_GENERIC3),
-      ENUM(VERT_ATTRIB_GENERIC4),
-      ENUM(VERT_ATTRIB_GENERIC5),
-      ENUM(VERT_ATTRIB_GENERIC6),
-      ENUM(VERT_ATTRIB_GENERIC7),
-      ENUM(VERT_ATTRIB_GENERIC8),
-      ENUM(VERT_ATTRIB_GENERIC9),
-      ENUM(VERT_ATTRIB_GENERIC10),
-      ENUM(VERT_ATTRIB_GENERIC11),
-      ENUM(VERT_ATTRIB_GENERIC12),
-      ENUM(VERT_ATTRIB_GENERIC13),
-      ENUM(VERT_ATTRIB_GENERIC14),
-      ENUM(VERT_ATTRIB_GENERIC15),
-   };
-   return NAME(attrib);
-}
-
 const char * gl_varying_slot_name(gl_varying_slot slot)
 {
    static const char *names[] = {
diff --git a/src/glsl/shader_enums.h b/src/glsl/shader_enums.h
index fbd2744..7ea953b 100644
--- a/src/glsl/shader_enums.h
+++ b/src/glsl/shader_enums.h
@@ -110,7 +110,50 @@ typedef enum
    VERT_ATTRIB_MAX = 33
 } gl_vert_attrib;
 
-const char * gl_vert_attrib_name(gl_vert_attrib attrib);
+static const char *gl_vert_attrib_names[] = {
+   ENUM(VERT_ATTRIB_POS),
+   ENUM(VERT_ATTRIB_WEIGHT),
+   ENUM(VERT_ATTRIB_NORMAL),
+   ENUM(VERT_ATTRIB_COLOR0),
+   ENUM(VERT_ATTRIB_COLOR1),
+   ENUM(VERT_ATTRIB_FOG),
+   ENUM(VERT_ATTRIB_COLOR_INDEX),
+   ENUM(VERT_ATTRIB_EDGEFLAG),
+   ENUM(VERT_ATTRIB_TEX0),
+   ENUM(VERT_ATTRIB_TEX1),
+   ENUM(VERT_ATTRIB_TEX2),
+   ENUM(VERT_ATTRIB_TEX3),
+   ENUM(VERT_ATTRIB_TEX4),
+   ENUM(VERT_ATTRIB_TEX5),
+   ENUM(VERT_ATTRIB_TEX6),
+   ENUM(VERT_ATTRIB_TEX7),
+   ENUM(VERT_ATTRIB_POINT_SIZE),
+   ENUM(VERT_ATTRIB_GENERIC0),
+   ENUM(VERT_ATTRIB_GENERIC1),
+   ENUM(VERT_ATTRIB_GENERIC2),
+   ENUM(VERT_ATTRIB_GENERIC3),
+   ENUM(VERT_ATTRIB_GENERIC4),
+   ENUM(VERT_ATTRIB_GENERIC5),
+   ENUM(VERT_ATTRIB_GENERIC6),
+   ENUM(VERT_ATTRIB_GENERIC7),
+   ENUM(VERT_ATTRIB_GENERIC8),
+   ENUM(VERT_ATTRIB_GENERIC9),
+   ENUM(VERT_ATTRIB_GENERIC10),
+   ENUM(VERT_ATTRIB_GENERIC11),
+   ENUM(VERT_ATTRIB_GENERIC12),
+   ENUM(VERT_ATTRIB_GENERIC13),
+   ENUM(VERT_ATTRIB_GENERIC14),
+   ENUM(VERT_ATTRIB_GENERIC15),
+};
+
+static inline const char *gl_vert_attrib_name(gl_vert_attrib attrib)
+{
+   STATIC_ASSERT(ARRAY_SIZE(gl_vert_attrib_names) == VERT_ATTRIB_MAX);
+   if (attrib < ARRAY_SIZE(gl_vert_attrib_names))
+      return gl_vert_attrib_names[attrib];
+   else
+      return "UNKNOWN";
+}
 
 /**
  * Symbolic constats to help iterating over
-- 
2.5.0



More information about the mesa-dev mailing list