]> git.cworth.org Git - fips/blob - fips-dispatch-gl.c
fips-dispatch: Simplify dispatch code by abstracting resolve functions
[fips] / fips-dispatch-gl.c
1 /* Copyright © 2012, Intel Corporation
2  *
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:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
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
19  * THE SOFTWARE.
20  */
21
22 #include "fips-dispatch-gl.h"
23
24 static void
25 check_initialized (void)
26 {
27         if (fips_dispatch_initialized)
28                 return;
29
30         fprintf (stderr,
31                  "Internal error: fips_dispatch_init must be called before\n"
32                  "any OpenGL function supported via fips_dispatch.\n");
33         exit (1);
34 }
35
36 static void
37 unsupported (const char *name)
38 {
39         fprintf (stderr, "Error: fips failed to find support for %s\n", name);
40
41         exit (1);
42 }
43
44 #define resolve(dispatch, name)                 \
45         dispatch = fips_dispatch_lookup (name); \
46         if (! dispatch)                         \
47                 unsupported (name);
48
49 #define resolve2(dispatch, name_a, name_b)                \
50         dispatch = fips_dispatch_lookup (name_a);         \
51         if (! dispatch)                                   \
52                 dispatch = fips_dispatch_lookup (name_b); \
53         if (! dispatch)                                   \
54                 unsupported (name_a);
55
56 static void
57 stub_glGenQueries (GLsizei n, GLuint *ids)
58 {
59         check_initialized ();
60         resolve2 (fips_dispatch_glGenQueries,
61                   "glGenQueries", "glGenQueriesARB")
62         fips_dispatch_glGenQueries (n, ids);
63 }
64
65 PFNGLGENQUERIESPROC fips_dispatch_glGenQueries = stub_glGenQueries;
66
67 static void
68 stub_glDeleteQueries (GLsizei n, const GLuint * ids)
69 {
70         check_initialized ();
71         resolve2 (fips_dispatch_glDeleteQueries,
72                   "glDeleteQueries", "glDeleteQueriesARB");
73         fips_dispatch_glDeleteQueries (n, ids);
74 }
75
76 PFNGLDELETEQUERIESPROC fips_dispatch_glDeleteQueries = stub_glDeleteQueries;
77
78 static void
79 stub_glBeginQuery (GLenum target, GLuint id)
80 {
81         check_initialized ();
82         resolve2 (fips_dispatch_glBeginQuery,
83                   "glBeginQuery", "glBeginQueryARB");
84         fips_dispatch_glBeginQuery (target, id);
85 }
86
87 PFNGLBEGINQUERYPROC fips_dispatch_glBeginQuery = stub_glBeginQuery;
88
89 static void
90 stub_glEndQuery (GLenum target)
91 {
92         check_initialized ();
93         resolve2 (fips_dispatch_glEndQuery, "glEndQuery", "glEndQueryARB");
94         fips_dispatch_glEndQuery (target);
95 }
96
97 PFNGLENDQUERYPROC fips_dispatch_glEndQuery = stub_glEndQuery;
98
99 static void
100 stub_glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint * params)
101 {
102         check_initialized ();
103         resolve2 (fips_dispatch_glGetQueryObjectuiv,
104                   "glGetQueryObjectuiv", "glGetQueryObjectuivARB");
105         fips_dispatch_glGetQueryObjectuiv (id, pname, params);
106 }
107
108 PFNGLGETQUERYOBJECTUIVPROC fips_dispatch_glGetQueryObjectuiv =
109         stub_glGetQueryObjectuiv;