[Piglit] [PATCH 1/3] piglit-util-gl: Add piglit_get_gl_enum_from_name
Jordan Justen
jordan.l.justen at intel.com
Wed Feb 18 14:32:29 PST 2015
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
Reviewed-by: Chad Versace <chad.versace at intel.com>
---
tests/util/gen_dispatch.py | 21 ++++++++++++++++++-
tests/util/piglit-util-gl-enum-gen.c.mako | 35 +++++++++++++++++++++++++++++++
tests/util/piglit-util-gl.h | 9 ++++++++
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
index 4d7d756..d4715e8 100644
--- a/tests/util/gen_dispatch.py
+++ b/tests/util/gen_dispatch.py
@@ -132,11 +132,13 @@ class EnumCode(object):
def emit(cls, out_dir, gl_registry):
assert isinstance(gl_registry, registry.gl.Registry)
enums = cls.get_unique_enums_in_default_namespace(gl_registry)
+ enums_by_name = cls.get_enums_by_name_in_default_namespace(gl_registry)
render_template(
cls.C_TEMPLATE,
out_dir,
gl_registry=gl_registry,
- sorted_unique_enums_in_default_namespace=enums)
+ sorted_unique_enums_in_default_namespace=enums,
+ sorted_enums_by_name=enums_by_name)
@classmethod
def get_unique_enums_in_default_namespace(cls, gl_registry):
@@ -155,6 +157,23 @@ class EnumCode(object):
enums = reduce(append_enum_if_new_value, enums[1:], [enums[0]])
return enums
+ @classmethod
+ def get_enums_by_name_in_default_namespace(cls, gl_registry):
+ def append_enum_if_new_value(enum_list, enum):
+ if enum_list[-1].name != enum.name:
+ enum_list.append(enum)
+ return enum_list
+
+ enums = (
+ enum
+ for enum_group in gl_registry.enum_groups
+ if enum_group.type == 'default_namespace'
+ for enum in enum_group.enums
+ )
+ enums = sorted(enums, lambda a, b: cmp(a.name, b.name))
+ enums = reduce(append_enum_if_new_value, enums[1:], [enums[0]])
+ return enums
+
if __name__ == '__main__':
main()
diff --git a/tests/util/piglit-util-gl-enum-gen.c.mako b/tests/util/piglit-util-gl-enum-gen.c.mako
index e22a75d..729abef 100644
--- a/tests/util/piglit-util-gl-enum-gen.c.mako
+++ b/tests/util/piglit-util-gl-enum-gen.c.mako
@@ -50,4 +50,39 @@ piglit_get_prim_name(GLenum prim)
>-------default: return "(unrecognized enum)";
>-------}
}
+
+struct gl_name_to_enum {
+>-------const char *name;
+>-------GLenum _enum;
+};
+
+static int
+compare_enum_name(const void *a, const void *b)
+{
+>-------return strcmp(((struct gl_name_to_enum*)a)->name,
+>------- ((struct gl_name_to_enum*)b)->name);
+}
+
+GLenum
+piglit_get_gl_enum_from_name(const char *name)
+{
+>-------static struct gl_name_to_enum names[] = {
+% for enum in sorted_enums_by_name:
+>------->-------{ "${enum.name}", ${enum.c_num_literal} },
+% endfor
+>-------};
+>-------struct gl_name_to_enum key = { name, 0 };
+>-------struct gl_name_to_enum *result;
+
+>-------result = (struct gl_name_to_enum*)
+>------->-------bsearch(&key,
+>------->------- names, ARRAY_SIZE(names), sizeof names[0],
+>------->------- compare_enum_name);
+
+>-------if (result == NULL)
+>------->-------abort();
+
+>-------return result->_enum;
+}
+
</%block>\
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 0f8eb81..fa4a6e4 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -87,6 +87,15 @@ const char* piglit_get_gl_error_name(GLenum error);
const char *piglit_get_gl_enum_name(GLenum param);
/**
+ * \brief Convert a string to a GL enum.
+ *
+ * For example, given "GL_INVALID_ENUM", return GL_INVALID_ENUM.
+ *
+ * abort() if the string is not recognized.
+ */
+GLenum piglit_get_gl_enum_from_name(const char *name);
+
+/**
* \brief Convert a GL primitive type enum value to a string.
*
* For example, given GL_POLYGON, return "GL_POLYGON".
--
2.1.4
More information about the Piglit
mailing list