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
24 /* The prototypes for some OpenGL functions changed at one point from:
26 * const void* *indices
28 * const void* const coist *indices
30 * This makes it difficult for us to provide an implementation of
31 * these functions that is consistent with the locally-available gl.h
32 * since we don't know if the extra const will be present or not.
34 * To workaround this problem, we simply #define away const altogether
35 * before including gl.h.
37 * Kudos to Keith Packard for suggesting this kludge.
41 #define GL_GLEXT_PROTOTYPES
50 static void *gl_handle;
53 glwrap_set_gl_handle (void *handle)
55 if (gl_handle == NULL)
60 glwrap_lookup (char *name)
64 /* We don't call dlopen here to find the library in which to
65 * perform a dlsym lookup. That's because the application may
66 * be loading libGL.so or libGLESv2.so for its OpenGL symbols.
68 * So we instead watch for one of those filenames to go by in
69 * our dlopen wrapper, which will then call
70 * glwrap_set_gl_handle to give us the handle to use here.
72 * If the application hasn't called dlopen on a "libGL"
73 * library, then presumably the application is linked directly
74 * to an OpenGL implementation. In this case, we can use
75 * RTLD_NEXT to find the symbol.
77 * But just in case, we also let the user override that by
78 * specifying the FIPS_LIBGL environment variable to the path
79 * of the real libGL.so library that fips should dlopen here.
81 if (gl_handle == NULL) {
84 path = getenv ("FIPS_LIBGL");
86 gl_handle = dlopen (path, RTLD_LAZY);
88 if (gl_handle == NULL) {
89 fprintf (stderr, "Failed to dlopen FIPS_LIBGL: "
94 gl_handle = RTLD_NEXT;
98 ret = dlwrap_real_dlsym (gl_handle, name);
101 fprintf (stderr, "Error: glwrap_lookup failed to dlsym %s\n",
109 /* With a program change, we stop the counter, update the
110 * active program, then start the counter up again. */
112 glUseProgram (GLuint program)
114 metrics_counter_stop ();
116 metrics_set_current_program (program);
118 metrics_counter_start ();
120 GLWRAP_DEFER(glUseProgram, program);
124 glUseProgramObjectARB (GLhandleARB programObj)
126 metrics_counter_stop ();
128 metrics_set_current_program (programObj);
130 metrics_counter_start ();
132 GLWRAP_DEFER(glUseProgramObjectARB, programObj);