1 /* Copyright © 2013, Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 typedef struct options {
35 char *shading_language_version;
37 char *extensions_whitelist;
38 char *extensions_blacklist;
42 export_options (options_t *options)
45 setenv ("GLENV_QUERY", "1", 1);
47 unsetenv ("GLENV_QUERY");
50 setenv ("GLENV_GL_VENDOR", options->vendor, 1);
52 unsetenv ("GLENV_GL_VENDOR");
54 if (options->renderer)
55 setenv ("GLENV_GL_RENDERER", options->renderer, 1);
57 unsetenv ("GLENV_GL_RENDERER");
60 setenv ("GLENV_GL_VERSION", options->version, 1);
62 unsetenv ("GLENV_GL_VERSION");
64 if (options->shading_language_version)
65 setenv ("GLENV_GL_SHADING_LANGUAGE_VERSION",
66 options->shading_language_version, 1);
68 unsetenv ("GLENV_GL_SHADING_LANGUAGE_VERSION");
70 if (options->extensions)
71 setenv ("GLENV_EXTENSIONS", options->extensions, 1);
73 unsetenv ("GLENV_EXTENSIONS");
75 if (options->extensions_whitelist)
76 setenv ("GLENV_EXTENSIONS_WHITELIST", options->extensions_whitelist, 1);
78 unsetenv ("GLENV_EXTENSIONS_WHITELIST");
80 if (options->extensions_blacklist)
81 setenv ("GLENV_EXTENSIONS_BLACKLIST", options->extensions_blacklist, 1);
83 unsetenv ("GLENV_EXTENSIONS_BLACKLIST");
89 printf ("Usage: glenv [OPTIONS...] <program> [program args...]\n"
91 "Execute <program> with alternate OpenGL environment.\n"
94 " -h, --help Show this help message.\n"
95 " -q, --query Query and report current environment\n"
96 " then terminate program.\n"
97 " --vendor=STR Set GL_VENDOR to STR.\n"
98 " --renderer=STR Set GL_RENDERER to STR.\n"
99 " --version=STR Set GL_VERSION to STR.\n"
100 " --shading-language-version=STR Set GL_SHADING_LANGUAGE_VERSION to STR.\n"
101 " --extensions=STR Set GL_EXTENSIONS to STR.\n"
102 " --extensions-whitelist=STR Remove from GL_EXTENSIONS all names\n"
103 " not appearing in STR (space-separated).\n"
104 " --extensions-blacklist=STR Remove from GL_EXTENSIONS any names\n"
105 " appearing in STR (space-separated).\n");
109 VENDOR_OPT = CHAR_MAX + 1,
112 SHADING_LANGUAGE_VERSION_OPT,
114 EXTENSIONS_WHITELIST_OPT,
115 EXTENSIONS_BLACKLIST_OPT
119 main (int argc, char *argv[])
122 options_t options = {
127 .shading_language_version = NULL,
129 .extensions_whitelist = NULL,
130 .extensions_blacklist = NULL
133 const char *short_options="hq";
134 const struct option long_options[] = {
135 {"help", no_argument, 0, 'h'},
136 {"query", no_argument, 0, 'q'},
137 {"vendor", required_argument, 0, VENDOR_OPT},
138 {"renderer", required_argument, 0, RENDERER_OPT},
139 {"version", required_argument, 0, VERSION_OPT},
140 {"shading-language-version", required_argument, 0, SHADING_LANGUAGE_VERSION_OPT},
141 {"extensions", required_argument, 0, EXTENSIONS_OPT},
142 {"extensions-whitelist", required_argument, 0, EXTENSIONS_WHITELIST_OPT},
143 {"extensions-blacklist", required_argument, 0, EXTENSIONS_BLACKLIST_OPT},
149 opt = getopt_long (argc, argv, short_options, long_options, NULL);
161 options.query = true;
164 options.vendor = optarg;
167 options.renderer = optarg;
170 options.version = optarg;
172 case SHADING_LANGUAGE_VERSION_OPT:
173 options.shading_language_version = optarg;
176 options.extensions = optarg;
178 case EXTENSIONS_WHITELIST_OPT:
179 options.extensions_whitelist = optarg;
181 case EXTENSIONS_BLACKLIST_OPT:
182 options.extensions_blacklist = optarg;
185 fprintf (stderr, "Internal error: "
186 "unexpected getopt value: %d\n", opt);
191 if (optind >= argc) {
192 fprintf (stderr, "Error: No program name provided, "
193 "see (glenv --help)\n");
197 export_options (&options);
199 glaze_execute (argc - optind, &argv[optind], "libglenv.so");
201 /* If glaze_execute returns then something went wrong. */