4 * Copyright 2014 Intel Corporation
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 <%block filter='fake_whitespace'>\
27 #include "piglit-util-gl.h"
30 piglit_get_gl_enum_name(GLenum param)
32 <% gl_accum = gl_registry.enums['GL_ACCUM'] %>\
33 >-------switch (param) {
34 >-------case 0x0000: return "GL_NONE/GL_FALSE/GL_NO_ERROR";
35 >-------case 0x0001: return "GL_TRUE";
36 % for enum in sorted_unique_enums_in_default_namespace:
37 % if enum.num_value >= gl_accum.num_value:
38 >-------case ${enum.c_num_literal}: return "${enum.name}";
42 >------->-------static const char *format = "(unrecognized enum: 0x%X)";
43 >------->-------static char buffer[4096];
44 >------->-------static char *position = buffer;
45 >------->-------const ptrdiff_t size_left = 4096 - (position - buffer);
46 >------->-------const size_t size_needed = strlen(format) + 8 - 2 + 1;
47 >------->-------if (size_left < size_needed)
48 >------->------->-------position = buffer;
49 >------->-------const int len = sprintf(position, format, param);
50 >------->-------const char *old_position = position;
51 >------->-------position += len + 1;
52 >------->-------return old_position;
58 piglit_get_prim_name(GLenum prim)
60 >-------switch (prim) {
61 % for enum in sorted_unique_enums_in_default_namespace:
62 % if enum.num_value < gl_accum.num_value:
63 >-------case ${enum.c_num_literal}: return "${enum.name}";
66 >-------default: return "(unrecognized enum)";
70 struct gl_name_to_enum {
71 >-------const char *name;
76 compare_enum_name(const void *a, const void *b)
78 >-------return strcmp(((struct gl_name_to_enum*)a)->name,
79 >------- ((struct gl_name_to_enum*)b)->name);
83 piglit_get_gl_memory_barrier_enum_from_name(const char *name)
85 >-------static const struct gl_name_to_enum names[] = {
86 % for enum in sorted_by_name_memory_barrier_enums:
87 >------->-------{ "${enum.name}", ${enum.c_num_literal} },
90 >-------struct gl_name_to_enum key = { name, 0 };
91 >-------struct gl_name_to_enum *result;
93 >-------result = (struct gl_name_to_enum*)
94 >------->-------bsearch(&key,
95 >------->------- names, ARRAY_SIZE(names), sizeof names[0],
96 >------->------- compare_enum_name);
98 >-------if (result == NULL) {
99 >------->-------fprintf(stderr, "No known enum named %s!\n", name);
100 >------->-------abort();
103 >-------return result->_enum;
107 piglit_get_gl_enum_from_name(const char *name)
109 >-------static const struct gl_name_to_enum names[] = {
110 % for enum in sorted_enums_by_name:
111 >------->-------{ "${enum.name}", ${enum.c_num_literal} },
114 >-------struct gl_name_to_enum key = { name, 0 };
115 >-------struct gl_name_to_enum *result;
117 >-------result = (struct gl_name_to_enum*)
118 >------->-------bsearch(&key,
119 >------->------- names, ARRAY_SIZE(names), sizeof names[0],
120 >------->------- compare_enum_name);
122 >-------if (result == NULL) {
123 >------->-------fprintf(stderr, "No known enum named %s!\n", name);
124 >------->-------abort();
127 >-------return result->_enum;