1 /* Copyright © 2012, 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
24 #include "fips-dispatch.h"
26 #define GL_GLEXT_PROTOTYPES
32 static bool fips_initialized;
33 static fips_api_t fips_api;
36 fips_dispatch_init (fips_api_t api)
40 fips_initialized = true;
44 check_initialized (void)
50 "Internal error: fips_dispatch_init must be called before\n"
51 "any OpenGL function supported via fips_dispatch.\n");
56 unsupported (const char *name)
58 fprintf (stderr, "Error: fips failed to find support for %s\n", name);
64 lookup (const char *name)
66 if (fips_api == FIPS_API_GLX)
67 return glXGetProcAddressARB ((const GLubyte *)name);
69 return eglGetProcAddress (name);
73 resolve_glGenQueries (void)
75 fips_dispatch_glGenQueries = lookup ("glGenQueries");
77 if (! fips_dispatch_glGenQueries)
78 fips_dispatch_glGenQueries = lookup ("glGenQueriesARB");
80 if (! fips_dispatch_glGenQueries)
81 unsupported ("GenQueries");
85 stub_glGenQueries (GLsizei n, GLuint *ids)
88 resolve_glGenQueries ();
89 fips_dispatch_glGenQueries (n, ids);
92 PFNGLGENQUERIESPROC fips_dispatch_glGenQueries = stub_glGenQueries;
95 resolve_glDeleteQueries (void)
97 fips_dispatch_glDeleteQueries = lookup ("glDeleteQueries");
99 if (! fips_dispatch_glDeleteQueries)
100 fips_dispatch_glDeleteQueries = lookup ("glDeleteQueriesARB");
102 if (! fips_dispatch_glDeleteQueries)
103 unsupported ("DeleteQueries");
107 stub_glDeleteQueries (GLsizei n, const GLuint * ids)
109 check_initialized ();
110 resolve_glDeleteQueries ();
111 fips_dispatch_glDeleteQueries (n, ids);
114 PFNGLDELETEQUERIESPROC fips_dispatch_glDeleteQueries = stub_glDeleteQueries;
117 resolve_glBeginQuery (void)
119 fips_dispatch_glBeginQuery = lookup ("glBeginQuery");
121 if (! fips_dispatch_glBeginQuery)
122 fips_dispatch_glBeginQuery = lookup ("glBeginQueryARB");
124 if (! fips_dispatch_glBeginQuery)
125 unsupported ("BeginQuery");
129 stub_glBeginQuery (GLenum target, GLuint id)
131 check_initialized ();
132 resolve_glBeginQuery ();
133 fips_dispatch_glBeginQuery (target, id);
136 PFNGLBEGINQUERYPROC fips_dispatch_glBeginQuery = stub_glBeginQuery;
139 resolve_glEndQuery (void)
141 fips_dispatch_glEndQuery = lookup ("glEndQuery");
143 if (! fips_dispatch_glEndQuery)
144 fips_dispatch_glEndQuery = lookup ("glEndQueryARB");
146 if (! fips_dispatch_glEndQuery)
147 unsupported ("EndQuery");
151 stub_glEndQuery (GLenum target)
153 check_initialized ();
154 resolve_glEndQuery ();
155 fips_dispatch_glEndQuery (target);
158 PFNGLENDQUERYPROC fips_dispatch_glEndQuery = stub_glEndQuery;
161 resolve_glGetQueryObjectuiv (void)
163 fips_dispatch_glGetQueryObjectuiv = (PFNGLGETQUERYOBJECTUIVARBPROC) lookup("glGetQueryObjectuivARB");
165 if (! fips_dispatch_glGetQueryObjectuiv)
166 unsupported ("GetQueryObjectuiv");
170 stub_glGetQueryObjectuiv (GLuint id, GLenum pname, GLuint * params)
172 check_initialized ();
173 resolve_glGetQueryObjectuiv ();
174 fips_dispatch_glGetQueryObjectuiv (id, pname, params);
177 PFNGLGETQUERYOBJECTUIVPROC fips_dispatch_glGetQueryObjectuiv = stub_glGetQueryObjectuiv;