2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2010 LunarG Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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
23 * DEALINGS IN THE SOFTWARE.
26 * Chia-I Wu <olv@lunarg.com>
30 #include "glapi/glapi.h"
31 #include "u_current.h"
32 #include "table.h" /* for MAPI_TABLE_NUM_SLOTS */
36 * Global variables, _glapi_get_context, and _glapi_get_dispatch are defined in
41 /* not used, but defined for compatibility */
42 const struct _glapi_table
*_glapi_Dispatch
;
43 const void *_glapi_Context
;
44 #endif /* GLX_USE_TLS */
47 _glapi_destroy_multithread(void)
53 _glapi_check_multithread(void)
59 _glapi_set_context(void *context
)
61 u_current_set_context((const void *) context
);
65 _glapi_set_dispatch(struct _glapi_table
*dispatch
)
67 u_current_set_table((const struct mapi_table
*) dispatch
);
71 * Return size of dispatch table struct as number of functions (or
75 _glapi_get_dispatch_table_size(void)
77 return MAPI_TABLE_NUM_SLOTS
;
81 * Fill-in the dispatch stub for the named function.
83 * This function is intended to be called by a hardware driver. When called,
84 * a dispatch stub may be created created for the function. A pointer to this
85 * dispatch function will be returned by glXGetProcAddress.
87 * \param function_names Array of pointers to function names that should
88 * share a common dispatch offset.
89 * \param parameter_signature String representing the types of the parameters
90 * passed to the named function. Parameter types
91 * are converted to characters using the following
93 * - 'i' for \c GLint, \c GLuint, and \c GLenum
94 * - 'p' for any pointer type
95 * - 'f' for \c GLfloat and \c GLclampf
96 * - 'd' for \c GLdouble and \c GLclampd
99 * The offset in the dispatch table of the named function. A pointer to the
100 * driver's implementation of the named function should be stored at
101 * \c dispatch_table[\c offset]. Return -1 if error/problem.
103 * \sa glXGetProcAddress
106 * This function can only handle up to 8 names at a time. As far as I know,
107 * the maximum number of names ever associated with an existing GL function is
108 * 4 (\c glPointParameterfSGIS, \c glPointParameterfEXT,
109 * \c glPointParameterfARB, and \c glPointParameterf), so this should not be
110 * too painful of a limitation.
113 * Check parameter_signature.
116 _glapi_add_dispatch( const char * const * function_names
,
117 const char * parameter_signature
)
119 const struct mapi_stub
*function_stubs
[8];
120 const struct mapi_stub
*alias
= NULL
;
123 (void) memset(function_stubs
, 0, sizeof(function_stubs
));
125 /* find the missing stubs, and decide the alias */
126 for (i
= 0; function_names
[i
] != NULL
&& i
< 8; i
++) {
127 const char * funcName
= function_names
[i
];
128 const struct mapi_stub
*stub
;
131 if (!funcName
|| funcName
[0] != 'g' || funcName
[1] != 'l')
135 stub
= stub_find_public(funcName
);
137 stub
= stub_find_dynamic(funcName
, 0);
139 slot
= (stub
) ? stub_get_slot(stub
) : -1;
141 if (alias
&& stub_get_slot(alias
) != slot
)
143 /* use the first existing stub as the alias */
147 function_stubs
[i
] = stub
;
151 /* generate missing stubs */
152 for (i
= 0; function_names
[i
] != NULL
&& i
< 8; i
++) {
153 const char * funcName
= function_names
[i
] + 2;
154 struct mapi_stub
*stub
;
156 if (function_stubs
[i
])
159 stub
= stub_find_dynamic(funcName
, 1);
163 stub_fix_dynamic(stub
, alias
);
168 return (alias
) ? stub_get_slot(alias
) : -1;
171 static const struct mapi_stub
*
172 _glapi_get_stub(const char *name
, int generate
)
174 const struct mapi_stub
*stub
;
176 #ifdef USE_MGL_NAMESPACE
181 if (!name
|| name
[0] != 'g' || name
[1] != 'l')
185 stub
= stub_find_public(name
);
187 stub
= stub_find_dynamic(name
, generate
);
193 * Return offset of entrypoint for named function within dispatch table.
196 _glapi_get_proc_offset(const char *funcName
)
198 const struct mapi_stub
*stub
= _glapi_get_stub(funcName
, 0);
199 return (stub
) ? stub_get_slot(stub
) : -1;
203 * Return pointer to the named function. If the function name isn't found
204 * in the name of static functions, try generating a new API entrypoint on
205 * the fly with assembly language.
208 _glapi_get_proc_address(const char *funcName
)
210 const struct mapi_stub
*stub
= _glapi_get_stub(funcName
, 1);
211 return (stub
) ? (_glapi_proc
) stub_get_addr(stub
) : NULL
;
215 * Return the name of the function at the given dispatch offset.
216 * This is only intended for debugging.
219 _glapi_get_proc_name(unsigned int offset
)
221 const struct mapi_stub
*stub
= stub_find_by_slot(offset
);
222 return stub
? stub_get_name(stub
) : NULL
;
226 * This is a deprecated function which should not be used anymore.
227 * It's only present to satisfy linking with older versions of libGL.
230 _glthread_GetID(void)
236 _glapi_noop_enable_warnings(unsigned char enable
)
241 _glapi_set_warning_func(_glapi_proc func
)