Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 3 | * Version: 6.3 |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 6 | * |
| 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: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | |
Brian Paul | 7e1161b | 1999-11-25 18:17:04 +0000 | [diff] [blame] | 26 | /* |
| 27 | * This file manages the OpenGL API dispatch layer. |
| 28 | * The dispatch table (struct _glapi_table) is basically just a list |
| 29 | * of function pointers. |
| 30 | * There are functions to set/get the current dispatch table for the |
| 31 | * current thread and to manage registration/dispatch of dynamically |
| 32 | * added extension functions. |
Brian Paul | 9f94399 | 2000-01-28 19:03:33 +0000 | [diff] [blame] | 33 | * |
| 34 | * It's intended that this file and the other glapi*.[ch] files are |
| 35 | * flexible enough to be reused in several places: XFree86, DRI- |
| 36 | * based libGL.so, and perhaps the SGI SI. |
| 37 | * |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 38 | * NOTE: There are no dependencies on Mesa in this code. |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 39 | * |
| 40 | * Versions (API changes): |
| 41 | * 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0 |
| 42 | * 2001/01/16 - added dispatch override feature for Mesa 3.5 |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 43 | * 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1. |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 44 | * 2002/10/01 - _glapi_get_proc_address() will now generate new entrypoints |
| 45 | * itself (using offset ~0). _glapi_add_entrypoint() can be |
| 46 | * called afterward and it'll fill in the correct dispatch |
| 47 | * offset. This allows DRI libGL to avoid probing for DRI |
| 48 | * drivers! No changes to the public glapi interface. |
Brian Paul | 7e1161b | 1999-11-25 18:17:04 +0000 | [diff] [blame] | 49 | */ |
| 50 | |
| 51 | |
| 52 | |
Brian Paul | 3c27be3 | 2000-02-10 21:27:48 +0000 | [diff] [blame] | 53 | #include "glheader.h" |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 54 | #include "glapi.h" |
Brian Paul | 0c239fc | 1999-12-16 12:38:11 +0000 | [diff] [blame] | 55 | #include "glapioffsets.h" |
| 56 | #include "glapitable.h" |
Brian Paul | 9f94399 | 2000-01-28 19:03:33 +0000 | [diff] [blame] | 57 | #include "glthread.h" |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 58 | |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 59 | /***** BEGIN NO-OP DISPATCH *****/ |
| 60 | |
| 61 | static GLboolean WarnFlag = GL_FALSE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 62 | static _glapi_warning_func warning_func; |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 63 | |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Enable/disable printing of warning messages. |
| 67 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 68 | PUBLIC void |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 69 | _glapi_noop_enable_warnings(GLboolean enable) |
| 70 | { |
| 71 | WarnFlag = enable; |
| 72 | } |
| 73 | |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 74 | /* |
| 75 | * Register a callback function for reporting errors. |
| 76 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 77 | PUBLIC void |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 78 | _glapi_set_warning_func( _glapi_warning_func func ) |
| 79 | { |
| 80 | warning_func = func; |
| 81 | } |
| 82 | |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 83 | static GLboolean |
| 84 | warn(void) |
| 85 | { |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 86 | if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) |
| 87 | && warning_func) { |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 88 | return GL_TRUE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 89 | } |
| 90 | else { |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 91 | return GL_FALSE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 92 | } |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
| 96 | #define KEYWORD1 static |
Daniel Borca | 722cb89 | 2004-01-07 12:37:09 +0000 | [diff] [blame] | 97 | #define KEYWORD2 GLAPIENTRY |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 98 | #define NAME(func) NoOp##func |
| 99 | |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 100 | #define F NULL |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 101 | |
Brian Paul | 5849e3d | 2004-11-05 18:32:02 +0000 | [diff] [blame] | 102 | #define DISPATCH(func, args, msg) \ |
| 103 | if (warn()) { \ |
| 104 | warning_func(NULL, "GL User Error: called without context: %s", #func); \ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Brian Paul | 5849e3d | 2004-11-05 18:32:02 +0000 | [diff] [blame] | 107 | #define RETURN_DISPATCH(func, args, msg) \ |
| 108 | if (warn()) { \ |
| 109 | warning_func(NULL, "GL User Error: called without context: %s", #func); \ |
| 110 | } \ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 111 | return 0 |
| 112 | |
| 113 | #define DISPATCH_TABLE_NAME __glapi_noop_table |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 114 | #define UNUSED_TABLE_NAME __unused_noop_functions |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 115 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 116 | #define TABLE_ENTRY(name) (_glapi_proc) NoOp##name |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 117 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 118 | static GLint NoOpUnused(void) |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 119 | { |
| 120 | if (warn()) { |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 121 | warning_func(NULL, "GL User Error: calling extension function without a current context\n"); |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 122 | } |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | #include "glapitemp.h" |
| 127 | |
| 128 | /***** END NO-OP DISPATCH *****/ |
| 129 | |
| 130 | |
| 131 | |
| 132 | /***** BEGIN THREAD-SAFE DISPATCH *****/ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 133 | |
| 134 | #if defined(THREADS) |
| 135 | |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 136 | /** |
| 137 | * \name Multi-threaded control support variables |
| 138 | * |
| 139 | * If thread-safety is supported, there are two potential mechanisms that can |
| 140 | * be used. The old-style mechanism would set \c _glapi_Dispatch to a special |
| 141 | * thread-safe dispatch table. These dispatch routines would call |
| 142 | * \c _glapi_get_dispatch to get the actual dispatch pointer. In this |
| 143 | * setup \c _glapi_Dispatch could never be \c NULL. This dual layered |
| 144 | * dispatch setup performed great for single-threaded apps, but didn't |
| 145 | * perform well for multithreaded apps. |
| 146 | * |
| 147 | * In the new mechansim, there are two variables. The first is |
| 148 | * \c _glapi_DispatchTSD. In the single-threaded case, this variable points |
| 149 | * to the dispatch table. In the multi-threaded case, this variable is |
| 150 | * \c NULL, and thread-specific variable \c _gl_DispatchTSD points to the |
| 151 | * actual dispatch table. \c _glapi_DispatchTSD is used to signal to the |
| 152 | * static dispatch functions to call \c _glapi_get_dispatch to get the real |
| 153 | * dispatch table. |
| 154 | * |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 155 | * There is a race condition in setting \c _glapi_DispatchTSD to \c NULL. |
| 156 | * It is possible for the original thread to be setting it at the same instant |
| 157 | * a new thread, perhaps running on a different processor, is clearing it. |
| 158 | * Because of that, \c ThreadSafe, which can only ever be changed to |
Ian Romanick | 10b3bf6 | 2004-07-05 22:42:14 +0000 | [diff] [blame] | 159 | * \c GL_TRUE, is used to determine whether or not the application is |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 160 | * multithreaded. |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 161 | */ |
| 162 | /*@{*/ |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 163 | static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */ |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 164 | _glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */ |
| 165 | static _glthread_TSD RealDispatchTSD; /**< only when using override */ |
| 166 | static _glthread_TSD ContextTSD; /**< Per-thread context pointer */ |
| 167 | /*@}*/ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 168 | |
| 169 | |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 170 | #define DISPATCH_TABLE_NAME __glapi_threadsafe_table |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 171 | #define UNUSED_TABLE_NAME __unused_threadsafe_functions |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 172 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 173 | #define TABLE_ENTRY(name) (_glapi_proc) gl##name |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 174 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 175 | static GLint glUnused(void) |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 176 | { |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | #include "glapitemp.h" |
| 181 | |
| 182 | #endif |
| 183 | |
| 184 | /***** END THREAD-SAFE DISPATCH *****/ |
| 185 | |
| 186 | |
| 187 | |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 188 | PUBLIC struct _glapi_table *_glapi_Dispatch = (struct _glapi_table *) __glapi_noop_table; |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 189 | #if defined( THREADS ) |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 190 | PUBLIC struct _glapi_table *_glapi_DispatchTSD = (struct _glapi_table *) __glapi_noop_table; |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 191 | #endif |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 192 | PUBLIC struct _glapi_table *_glapi_RealDispatch = (struct _glapi_table *) __glapi_noop_table; |
Brian Paul | 0f71025 | 1999-12-15 15:02:30 +0000 | [diff] [blame] | 193 | |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 194 | |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 195 | /* Used when thread safety disabled */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 196 | PUBLIC void *_glapi_Context = NULL; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 197 | |
Brian Paul | 0f71025 | 1999-12-15 15:02:30 +0000 | [diff] [blame] | 198 | |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 199 | static GLboolean DispatchOverride = GL_FALSE; |
| 200 | |
| 201 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 202 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 203 | /** |
| 204 | * strdup() is actually not a standard ANSI C or POSIX routine. |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 205 | * Irix will not define it if ANSI mode is in effect. |
| 206 | */ |
| 207 | static char * |
| 208 | str_dup(const char *str) |
Randy Frank | d7361e1 | 2000-03-27 21:13:58 +0000 | [diff] [blame] | 209 | { |
Brian Paul | fffb809 | 2000-03-29 18:46:11 +0000 | [diff] [blame] | 210 | char *copy; |
| 211 | copy = (char*) malloc(strlen(str) + 1); |
| 212 | if (!copy) |
| 213 | return NULL; |
| 214 | strcpy(copy, str); |
| 215 | return copy; |
Randy Frank | d7361e1 | 2000-03-27 21:13:58 +0000 | [diff] [blame] | 216 | } |
| 217 | |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 218 | |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 219 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 220 | /** |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 221 | * We should call this periodically from a function such as glXMakeCurrent |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 222 | * in order to test if multiple threads are being used. |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 223 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 224 | PUBLIC void |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 225 | _glapi_check_multithread(void) |
| 226 | { |
| 227 | #if defined(THREADS) |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 228 | if (!ThreadSafe) { |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 229 | static unsigned long knownID; |
| 230 | static GLboolean firstCall = GL_TRUE; |
| 231 | if (firstCall) { |
| 232 | knownID = _glthread_GetID(); |
| 233 | firstCall = GL_FALSE; |
| 234 | } |
| 235 | else if (knownID != _glthread_GetID()) { |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 236 | ThreadSafe = GL_TRUE; |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 237 | _glapi_set_dispatch(NULL); |
| 238 | } |
| 239 | } |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 240 | else if (!_glapi_get_dispatch()) { |
| 241 | /* make sure that this thread's dispatch pointer isn't null */ |
| 242 | _glapi_set_dispatch(NULL); |
| 243 | } |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 244 | #endif |
| 245 | } |
| 246 | |
| 247 | |
| 248 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 249 | /** |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 250 | * Set the current context pointer for this thread. |
| 251 | * The context pointer is an opaque type which should be cast to |
| 252 | * void from the real context pointer type. |
| 253 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 254 | PUBLIC void |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 255 | _glapi_set_context(void *context) |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 256 | { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 257 | (void) __unused_noop_functions; /* silence a warning */ |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 258 | #if defined(THREADS) |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 259 | (void) __unused_threadsafe_functions; /* silence a warning */ |
Brian Paul | 3c27be3 | 2000-02-10 21:27:48 +0000 | [diff] [blame] | 260 | _glthread_SetTSD(&ContextTSD, context); |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 261 | _glapi_Context = (ThreadSafe) ? NULL : context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 262 | #else |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 263 | _glapi_Context = context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 264 | #endif |
| 265 | } |
| 266 | |
| 267 | |
| 268 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 269 | /** |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 270 | * Get the current context pointer for this thread. |
| 271 | * The context pointer is an opaque type which should be cast from |
| 272 | * void to the real context pointer type. |
| 273 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 274 | PUBLIC void * |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 275 | _glapi_get_context(void) |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 276 | { |
| 277 | #if defined(THREADS) |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 278 | if (ThreadSafe) { |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 279 | return _glthread_GetTSD(&ContextTSD); |
| 280 | } |
| 281 | else { |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 282 | return _glapi_Context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 283 | } |
| 284 | #else |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 285 | return _glapi_Context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 286 | #endif |
| 287 | } |
| 288 | |
| 289 | |
| 290 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 291 | /** |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 292 | * Set the global or per-thread dispatch table pointer. |
| 293 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 294 | PUBLIC void |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 295 | _glapi_set_dispatch(struct _glapi_table *dispatch) |
| 296 | { |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 297 | if (!dispatch) { |
| 298 | /* use the no-op functions */ |
| 299 | dispatch = (struct _glapi_table *) __glapi_noop_table; |
| 300 | } |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 301 | #ifdef DEBUG |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 302 | else { |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 303 | _glapi_check_table(dispatch); |
| 304 | } |
| 305 | #endif |
| 306 | |
| 307 | #if defined(THREADS) |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 308 | if (DispatchOverride) { |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 309 | _glthread_SetTSD(&RealDispatchTSD, (void *) dispatch); |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 310 | if (ThreadSafe) |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 311 | _glapi_RealDispatch = (struct _glapi_table*) __glapi_threadsafe_table; |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 312 | else |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 313 | _glapi_RealDispatch = dispatch; |
Brian Paul | 3b18a36 | 2000-09-26 15:27:20 +0000 | [diff] [blame] | 314 | } |
| 315 | else { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 316 | /* normal operation */ |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 317 | _glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch); |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 318 | if (ThreadSafe) { |
| 319 | _glapi_Dispatch = (struct _glapi_table *) __glapi_threadsafe_table; |
| 320 | _glapi_DispatchTSD = NULL; |
| 321 | } |
| 322 | else { |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 323 | _glapi_Dispatch = dispatch; |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 324 | _glapi_DispatchTSD = dispatch; |
| 325 | } |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 326 | } |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 327 | #else /*THREADS*/ |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 328 | if (DispatchOverride) { |
| 329 | _glapi_RealDispatch = dispatch; |
| 330 | } |
| 331 | else { |
| 332 | _glapi_Dispatch = dispatch; |
| 333 | } |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 334 | #endif /*THREADS*/ |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 338 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 339 | /** |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 340 | * Return pointer to current dispatch table for calling thread. |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 341 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 342 | PUBLIC struct _glapi_table * |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 343 | _glapi_get_dispatch(void) |
| 344 | { |
| 345 | #if defined(THREADS) |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 346 | if (ThreadSafe) { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 347 | if (DispatchOverride) { |
| 348 | return (struct _glapi_table *) _glthread_GetTSD(&RealDispatchTSD); |
| 349 | } |
| 350 | else { |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 351 | return (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD); |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 352 | } |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 353 | } |
Brian Paul | 590d347 | 1999-12-17 12:20:23 +0000 | [diff] [blame] | 354 | else { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 355 | if (DispatchOverride) { |
| 356 | assert(_glapi_RealDispatch); |
| 357 | return _glapi_RealDispatch; |
| 358 | } |
| 359 | else { |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 360 | assert(_glapi_DispatchTSD); |
| 361 | return _glapi_DispatchTSD; |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 362 | } |
Brian Paul | 590d347 | 1999-12-17 12:20:23 +0000 | [diff] [blame] | 363 | } |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 364 | #else |
Brian Paul | c2319b4 | 2000-01-17 19:28:31 +0000 | [diff] [blame] | 365 | return _glapi_Dispatch; |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 366 | #endif |
| 367 | } |
| 368 | |
| 369 | |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 370 | /* |
| 371 | * Notes on dispatch overrride: |
| 372 | * |
| 373 | * Dispatch override allows an external agent to hook into the GL dispatch |
| 374 | * mechanism before execution goes into the core rendering library. For |
| 375 | * example, a trace mechanism would insert itself as an overrider, print |
| 376 | * logging info for each GL function, then dispatch to the real GL function. |
| 377 | * |
| 378 | * libGLS (GL Stream library) is another agent that might use override. |
| 379 | * |
| 380 | * We don't allow more than one layer of overriding at this time. |
| 381 | * In the future we may allow nested/layered override. In that case |
| 382 | * _glapi_begin_dispatch_override() will return an override layer, |
| 383 | * _glapi_end_dispatch_override(layer) will remove an override layer |
| 384 | * and _glapi_get_override_dispatch(layer) will return the dispatch |
| 385 | * table for a given override layer. layer = 0 will be the "real" |
| 386 | * dispatch table. |
| 387 | */ |
| 388 | |
| 389 | /* |
| 390 | * Return: dispatch override layer number. |
| 391 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 392 | PUBLIC int |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 393 | _glapi_begin_dispatch_override(struct _glapi_table *override) |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 394 | { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 395 | struct _glapi_table *real = _glapi_get_dispatch(); |
| 396 | |
| 397 | assert(!DispatchOverride); /* can't nest at this time */ |
| 398 | DispatchOverride = GL_TRUE; |
| 399 | |
| 400 | _glapi_set_dispatch(real); |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 401 | |
| 402 | #if defined(THREADS) |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 403 | _glthread_SetTSD(&_gl_DispatchTSD, (void *) override); |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 404 | if ( ThreadSafe ) { |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 405 | _glapi_Dispatch = (struct _glapi_table *) __glapi_threadsafe_table; |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 406 | _glapi_DispatchTSD = NULL; |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 407 | } |
| 408 | else { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 409 | _glapi_Dispatch = override; |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 410 | _glapi_DispatchTSD = override; |
| 411 | } |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 412 | #else |
| 413 | _glapi_Dispatch = override; |
| 414 | #endif |
| 415 | return 1; |
| 416 | } |
| 417 | |
| 418 | |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 419 | PUBLIC void |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 420 | _glapi_end_dispatch_override(int layer) |
| 421 | { |
| 422 | struct _glapi_table *real = _glapi_get_dispatch(); |
| 423 | (void) layer; |
| 424 | DispatchOverride = GL_FALSE; |
| 425 | _glapi_set_dispatch(real); |
| 426 | /* the rest of this isn't needed, just play it safe */ |
| 427 | #if defined(THREADS) |
| 428 | _glthread_SetTSD(&RealDispatchTSD, NULL); |
| 429 | #endif |
| 430 | _glapi_RealDispatch = NULL; |
| 431 | } |
| 432 | |
| 433 | |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 434 | PUBLIC struct _glapi_table * |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 435 | _glapi_get_override_dispatch(int layer) |
| 436 | { |
| 437 | if (layer == 0) { |
| 438 | return _glapi_get_dispatch(); |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 439 | } |
| 440 | else { |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 441 | if (DispatchOverride) { |
| 442 | #if defined(THREADS) |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 443 | return (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD); |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 444 | #else |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 445 | return _glapi_Dispatch; |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 446 | #endif |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 447 | } |
| 448 | else { |
| 449 | return NULL; |
| 450 | } |
| 451 | } |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 452 | } |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 453 | |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 454 | |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 455 | #if !defined( USE_X86_ASM ) |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 456 | #define NEED_FUNCTION_POINTER |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 457 | #endif |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 458 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 459 | /* The code in this file is auto-generated with Python */ |
Brian Paul | b5fd886 | 2001-11-18 22:48:11 +0000 | [diff] [blame] | 460 | #include "glprocs.h" |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 461 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 462 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 463 | /** |
| 464 | * Search the table of static entrypoint functions for the named function |
| 465 | * and return the corresponding glprocs_table_t entry. |
| 466 | */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 467 | static const glprocs_table_t * |
| 468 | find_entry( const char * n ) |
| 469 | { |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 470 | GLuint i; |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 471 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 472 | for (i = 0; static_functions[i].Name_offset >= 0; i++) { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 473 | const char * test_name; |
| 474 | |
| 475 | test_name = gl_string_table + static_functions[i].Name_offset; |
| 476 | if (strcmp(test_name, n) == 0) { |
| 477 | return & static_functions[i]; |
| 478 | } |
| 479 | } |
| 480 | return NULL; |
| 481 | } |
| 482 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 483 | |
| 484 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 485 | * Return dispatch table offset of the named static (built-in) function. |
| 486 | * Return -1 if function not found. |
| 487 | */ |
| 488 | static GLint |
| 489 | get_static_proc_offset(const char *funcName) |
| 490 | { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 491 | const glprocs_table_t * const f = find_entry( funcName ); |
| 492 | |
| 493 | if ( f != NULL ) { |
| 494 | return f->Offset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 495 | } |
| 496 | return -1; |
| 497 | } |
| 498 | |
| 499 | |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 500 | #ifdef USE_X86_ASM |
| 501 | extern const GLubyte gl_dispatch_functions_start[]; |
| 502 | |
Roland Scheidegger | d2dbb25 | 2004-07-06 00:32:03 +0000 | [diff] [blame] | 503 | # if defined(THREADS) |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 504 | # define X86_DISPATCH_FUNCTION_SIZE 32 |
| 505 | # else |
| 506 | # define X86_DISPATCH_FUNCTION_SIZE 16 |
| 507 | # endif |
| 508 | |
| 509 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 510 | /** |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 511 | * Return dispatch function address the named static (built-in) function. |
| 512 | * Return NULL if function not found. |
| 513 | */ |
Brian Paul | 209bd3a | 2004-11-27 04:02:32 +0000 | [diff] [blame] | 514 | static const _glapi_proc |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 515 | get_static_proc_address(const char *funcName) |
| 516 | { |
| 517 | const glprocs_table_t * const f = find_entry( funcName ); |
| 518 | |
| 519 | if ( f != NULL ) { |
Brian Paul | 209bd3a | 2004-11-27 04:02:32 +0000 | [diff] [blame] | 520 | return (_glapi_proc) (gl_dispatch_functions_start |
| 521 | + (X86_DISPATCH_FUNCTION_SIZE * f->Offset)); |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 522 | } |
| 523 | else { |
| 524 | return NULL; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | #else |
| 529 | |
| 530 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 531 | /** |
| 532 | * Return pointer to the named static (built-in) function. |
| 533 | * \return NULL if function not found. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 534 | */ |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 535 | static const _glapi_proc |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 536 | get_static_proc_address(const char *funcName) |
| 537 | { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 538 | const glprocs_table_t * const f = find_entry( funcName ); |
| 539 | return ( f != NULL ) ? f->Address : NULL; |
| 540 | } |
| 541 | |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 542 | #endif /* USE_X86_ASM */ |
| 543 | |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 544 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 545 | /** |
| 546 | * Return the name of the function at the given offset in the dispatch |
| 547 | * table. For debugging only. |
| 548 | */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 549 | static const char * |
| 550 | get_static_proc_name( GLuint offset ) |
| 551 | { |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 552 | GLuint i; |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 553 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 554 | for (i = 0; static_functions[i].Name_offset >= 0; i++) { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 555 | if (static_functions[i].Offset == offset) { |
| 556 | return gl_string_table + static_functions[i].Name_offset; |
Brian Paul | 9c7ca85 | 2000-10-19 20:13:12 +0000 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | return NULL; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | |
| 563 | |
| 564 | /********************************************************************** |
| 565 | * Extension function management. |
| 566 | */ |
| 567 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 568 | /* |
| 569 | * Number of extension functions which we can dynamically add at runtime. |
| 570 | */ |
| 571 | #define MAX_EXTENSION_FUNCS 300 |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 572 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 573 | |
| 574 | /* |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 575 | * The dispatch table size (number of entries) is the size of the |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 576 | * _glapi_table struct plus the number of dynamic entries we can add. |
| 577 | * The extra slots can be filled in by DRI drivers that register new extension |
| 578 | * functions. |
| 579 | */ |
| 580 | #define DISPATCH_TABLE_SIZE (sizeof(struct _glapi_table) / sizeof(void *) + MAX_EXTENSION_FUNCS) |
| 581 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 582 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 583 | struct name_address_offset { |
| 584 | const char *Name; |
| 585 | _glapi_proc Address; |
| 586 | GLuint Offset; |
| 587 | }; |
| 588 | |
| 589 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 590 | static struct name_address_offset ExtEntryTable[MAX_EXTENSION_FUNCS]; |
| 591 | static GLuint NumExtEntryPoints = 0; |
| 592 | |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 593 | #ifdef USE_SPARC_ASM |
| 594 | extern void __glapi_sparc_icache_flush(unsigned int *); |
| 595 | #endif |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 596 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 597 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 598 | * Generate a dispatch function (entrypoint) which jumps through |
| 599 | * the given slot number (offset) in the current dispatch table. |
| 600 | * We need assembly language in order to accomplish this. |
| 601 | */ |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 602 | static _glapi_proc |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 603 | generate_entrypoint(GLuint functionOffset) |
| 604 | { |
| 605 | #if defined(USE_X86_ASM) |
| 606 | /* |
| 607 | * This x86 code contributed by Josh Vanderhoof. |
| 608 | * |
| 609 | * 0: a1 10 32 54 76 movl __glapi_Dispatch,%eax |
| 610 | * 00 01 02 03 04 |
| 611 | * 5: 85 c0 testl %eax,%eax |
| 612 | * 05 06 |
| 613 | * 7: 74 06 je f <entrypoint+0xf> |
| 614 | * 07 08 |
| 615 | * 9: ff a0 10 32 54 76 jmp *0x76543210(%eax) |
| 616 | * 09 0a 0b 0c 0d 0e |
| 617 | * f: e8 fc ff ff ff call __glapi_get_dispatch |
| 618 | * 0f 10 11 12 13 |
| 619 | * 14: ff a0 10 32 54 76 jmp *0x76543210(%eax) |
| 620 | * 14 15 16 17 18 19 |
| 621 | */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 622 | static const unsigned char insn_template[] = { |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 623 | 0xa1, 0x00, 0x00, 0x00, 0x00, |
| 624 | 0x85, 0xc0, |
| 625 | 0x74, 0x06, |
| 626 | 0xff, 0xa0, 0x00, 0x00, 0x00, 0x00, |
| 627 | 0xe8, 0x00, 0x00, 0x00, 0x00, |
| 628 | 0xff, 0xa0, 0x00, 0x00, 0x00, 0x00 |
| 629 | }; |
Brian Paul | dec2a4d | 2002-10-29 15:03:14 +0000 | [diff] [blame] | 630 | unsigned char *code = (unsigned char *) malloc(sizeof(insn_template)); |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 631 | unsigned int next_insn; |
| 632 | if (code) { |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 633 | memcpy(code, insn_template, sizeof(insn_template)); |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 634 | |
Daniel Borca | fd00382 | 2004-07-05 06:15:37 +0000 | [diff] [blame] | 635 | #if defined( THREADS ) |
Ian Romanick | 8e77da1c | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 636 | *(unsigned int *)(code + 0x01) = (unsigned int)&_glapi_DispatchTSD; |
Daniel Borca | fd00382 | 2004-07-05 06:15:37 +0000 | [diff] [blame] | 637 | #else |
| 638 | *(unsigned int *)(code + 0x01) = (unsigned int)&_glapi_Dispatch; |
| 639 | #endif |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 640 | *(unsigned int *)(code + 0x0b) = (unsigned int)functionOffset * 4; |
| 641 | next_insn = (unsigned int)(code + 0x14); |
| 642 | *(unsigned int *)(code + 0x10) = (unsigned int)_glapi_get_dispatch - next_insn; |
| 643 | *(unsigned int *)(code + 0x16) = (unsigned int)functionOffset * 4; |
| 644 | } |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 645 | return (_glapi_proc) code; |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 646 | #elif defined(USE_SPARC_ASM) |
| 647 | |
Brian Paul | c247c7f | 2004-11-22 19:27:40 +0000 | [diff] [blame] | 648 | #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__))) |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 649 | static const unsigned int insn_template[] = { |
| 650 | 0x05000000, /* sethi %uhi(_glapi_Dispatch), %g2 */ |
| 651 | 0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */ |
| 652 | 0x8410a000, /* or %g2, %ulo(_glapi_Dispatch), %g2 */ |
| 653 | 0x82106000, /* or %g1, %lo(_glapi_Dispatch), %g1 */ |
| 654 | 0x8528b020, /* sllx %g2, 32, %g2 */ |
| 655 | 0xc2584002, /* ldx [%g1 + %g2], %g1 */ |
| 656 | 0x05000000, /* sethi %hi(8 * glapioffset), %g2 */ |
| 657 | 0x8410a000, /* or %g2, %lo(8 * glapioffset), %g2 */ |
| 658 | 0xc6584002, /* ldx [%g1 + %g2], %g3 */ |
| 659 | 0x81c0c000, /* jmpl %g3, %g0 */ |
| 660 | 0x01000000 /* nop */ |
| 661 | }; |
| 662 | #else |
| 663 | static const unsigned int insn_template[] = { |
| 664 | 0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */ |
| 665 | 0xc2006000, /* ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ |
| 666 | 0xc6006000, /* ld [%g1 + %lo(4*glapioffset)], %g3 */ |
| 667 | 0x81c0c000, /* jmpl %g3, %g0 */ |
| 668 | 0x01000000 /* nop */ |
| 669 | }; |
| 670 | #endif |
Brian Paul | dec2a4d | 2002-10-29 15:03:14 +0000 | [diff] [blame] | 671 | unsigned int *code = (unsigned int *) malloc(sizeof(insn_template)); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 672 | unsigned long glapi_addr = (unsigned long) &_glapi_Dispatch; |
| 673 | if (code) { |
| 674 | memcpy(code, insn_template, sizeof(insn_template)); |
| 675 | |
Brian Paul | c247c7f | 2004-11-22 19:27:40 +0000 | [diff] [blame] | 676 | #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__))) |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 677 | code[0] |= (glapi_addr >> (32 + 10)); |
| 678 | code[1] |= ((glapi_addr & 0xffffffff) >> 10); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 679 | __glapi_sparc_icache_flush(&code[0]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 680 | code[2] |= ((glapi_addr >> 32) & ((1 << 10) - 1)); |
| 681 | code[3] |= (glapi_addr & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 682 | __glapi_sparc_icache_flush(&code[2]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 683 | code[6] |= ((functionOffset * 8) >> 10); |
| 684 | code[7] |= ((functionOffset * 8) & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 685 | __glapi_sparc_icache_flush(&code[6]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 686 | #else |
| 687 | code[0] |= (glapi_addr >> 10); |
| 688 | code[1] |= (glapi_addr & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 689 | __glapi_sparc_icache_flush(&code[0]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 690 | code[2] |= (functionOffset * 4); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 691 | __glapi_sparc_icache_flush(&code[2]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 692 | #endif |
| 693 | } |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 694 | return (_glapi_proc) code; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 695 | #else |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 696 | (void) functionOffset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 697 | return NULL; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 698 | #endif /* USE_*_ASM */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 702 | /** |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 703 | * This function inserts a new dispatch offset into the assembly language |
| 704 | * stub that was generated with the preceeding function. |
| 705 | */ |
| 706 | static void |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 707 | fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 708 | { |
| 709 | #if defined(USE_X86_ASM) |
| 710 | |
| 711 | unsigned char *code = (unsigned char *) entrypoint; |
| 712 | *(unsigned int *)(code + 0x0b) = offset * 4; |
| 713 | *(unsigned int *)(code + 0x16) = offset * 4; |
| 714 | |
| 715 | #elif defined(USE_SPARC_ASM) |
| 716 | |
| 717 | /* XXX this hasn't been tested! */ |
| 718 | unsigned int *code = (unsigned int *) entrypoint; |
Brian Paul | c247c7f | 2004-11-22 19:27:40 +0000 | [diff] [blame] | 719 | #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__))) |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 720 | code[6] = 0x05000000; /* sethi %hi(8 * glapioffset), %g2 */ |
| 721 | code[7] = 0x8410a000; /* or %g2, %lo(8 * glapioffset), %g2 */ |
| 722 | code[6] |= ((offset * 8) >> 10); |
| 723 | code[7] |= ((offset * 8) & ((1 << 10) - 1)); |
| 724 | __glapi_sparc_icache_flush(&code[6]); |
Brian Paul | 9a90cd4 | 2003-12-01 22:40:26 +0000 | [diff] [blame] | 725 | #else /* __sparc_v9__ && !linux */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 726 | code[2] = 0xc6006000; /* ld [%g1 + %lo(4*glapioffset)], %g3 */ |
Brian Paul | 944ea20 | 2002-10-17 16:29:17 +0000 | [diff] [blame] | 727 | code[2] |= (offset * 4); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 728 | __glapi_sparc_icache_flush(&code[2]); |
Brian Paul | 9a90cd4 | 2003-12-01 22:40:26 +0000 | [diff] [blame] | 729 | #endif /* __sparc_v9__ && !linux */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 730 | |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 731 | #else |
| 732 | |
| 733 | /* an unimplemented architecture */ |
| 734 | (void) entrypoint; |
| 735 | (void) offset; |
| 736 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 737 | #endif /* USE_*_ASM */ |
| 738 | } |
| 739 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 740 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 741 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 742 | * Add a new extension function entrypoint. |
| 743 | * Return: GL_TRUE = success or GL_FALSE = failure |
| 744 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 745 | PUBLIC GLboolean |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 746 | _glapi_add_entrypoint(const char *funcName, GLuint offset) |
| 747 | { |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 748 | /* trivial rejection test */ |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 749 | #ifdef MANGLE |
| 750 | if (!funcName || funcName[0] != 'm' || funcName[1] != 'g' || funcName[2] != 'l') |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 751 | return GL_FALSE; |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 752 | #else |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 753 | if (!funcName || funcName[0] != 'g' || funcName[1] != 'l') |
| 754 | return GL_FALSE; |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 755 | #endif |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 756 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 757 | /* first check if the named function is already statically present */ |
| 758 | { |
| 759 | GLint index = get_static_proc_offset(funcName); |
| 760 | if (index >= 0) { |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 761 | return (GLboolean) ((GLuint) index == offset); /* bad offset! */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 765 | /* See if this function has already been dynamically added */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 766 | { |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 767 | GLuint i; |
| 768 | for (i = 0; i < NumExtEntryPoints; i++) { |
| 769 | if (strcmp(ExtEntryTable[i].Name, funcName) == 0) { |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 770 | /* function already registered */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 771 | if (ExtEntryTable[i].Offset == offset) { |
| 772 | return GL_TRUE; /* offsets match */ |
| 773 | } |
Brian Paul | e4fcea2 | 2003-09-19 15:38:15 +0000 | [diff] [blame] | 774 | else if (ExtEntryTable[i].Offset == (GLuint) ~0 |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 775 | && offset < DISPATCH_TABLE_SIZE) { |
| 776 | /* need to patch-up the dispatch code */ |
Brian Paul | e4fcea2 | 2003-09-19 15:38:15 +0000 | [diff] [blame] | 777 | if (offset != (GLuint) ~0) { |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 778 | fill_in_entrypoint_offset(ExtEntryTable[i].Address, offset); |
| 779 | ExtEntryTable[i].Offset = offset; |
| 780 | } |
| 781 | return GL_TRUE; |
| 782 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 783 | else { |
| 784 | return GL_FALSE; /* bad offset! */ |
| 785 | } |
| 786 | } |
| 787 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 790 | /* This is a new function, try to add it. */ |
| 791 | if (NumExtEntryPoints >= MAX_EXTENSION_FUNCS || |
| 792 | offset >= DISPATCH_TABLE_SIZE) { |
| 793 | /* No space left */ |
| 794 | return GL_FALSE; |
| 795 | } |
| 796 | else { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 797 | _glapi_proc entrypoint = generate_entrypoint(offset); |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 798 | if (!entrypoint) |
| 799 | return GL_FALSE; /* couldn't generate assembly */ |
| 800 | |
| 801 | /* OK! */ |
| 802 | ExtEntryTable[NumExtEntryPoints].Name = str_dup(funcName); |
| 803 | ExtEntryTable[NumExtEntryPoints].Offset = offset; |
| 804 | ExtEntryTable[NumExtEntryPoints].Address = entrypoint; |
| 805 | NumExtEntryPoints++; |
| 806 | |
| 807 | return GL_TRUE; /* success */ |
| 808 | } |
| 809 | |
| 810 | /* should never get here, silence compiler warnings */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 811 | return GL_FALSE; |
| 812 | } |
| 813 | |
| 814 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 815 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 816 | * Return offset of entrypoint for named function within dispatch table. |
| 817 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 818 | PUBLIC GLint |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 819 | _glapi_get_proc_offset(const char *funcName) |
| 820 | { |
| 821 | /* search extension functions first */ |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 822 | GLuint i; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 823 | for (i = 0; i < NumExtEntryPoints; i++) { |
| 824 | if (strcmp(ExtEntryTable[i].Name, funcName) == 0) { |
| 825 | return ExtEntryTable[i].Offset; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | /* search static functions */ |
| 830 | return get_static_proc_offset(funcName); |
| 831 | } |
| 832 | |
| 833 | |
| 834 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 835 | /** |
| 836 | * Return pointer to the named function. If the function name isn't found |
| 837 | * in the name of static functions, try generating a new API entrypoint on |
| 838 | * the fly with assembly language. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 839 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 840 | PUBLIC const _glapi_proc |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 841 | _glapi_get_proc_address(const char *funcName) |
| 842 | { |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 843 | GLuint i; |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 844 | |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 845 | #ifdef MANGLE |
| 846 | if (funcName[0] != 'm' || funcName[1] != 'g' || funcName[2] != 'l') |
| 847 | return NULL; |
| 848 | #else |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 849 | if (funcName[0] != 'g' || funcName[1] != 'l') |
| 850 | return NULL; |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 851 | #endif |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 852 | |
| 853 | /* search extension functions first */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 854 | for (i = 0; i < NumExtEntryPoints; i++) { |
| 855 | if (strcmp(ExtEntryTable[i].Name, funcName) == 0) { |
| 856 | return ExtEntryTable[i].Address; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | /* search static functions */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 861 | { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 862 | const _glapi_proc func = get_static_proc_address(funcName); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 863 | if (func) |
| 864 | return func; |
| 865 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 866 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 867 | /* generate new entrypoint - use a temporary dispatch offset of |
| 868 | * ~0 (i.e. -1). Later, when the driver calls _glapi_add_entrypoint() |
| 869 | * we'll put in the proper offset. If that never happens, and the |
| 870 | * user calls this function, he'll segfault. That's what you get |
| 871 | * when you try calling a GL function that doesn't really exist. |
| 872 | */ |
| 873 | if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 874 | _glapi_proc entrypoint = generate_entrypoint(~0); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 875 | if (!entrypoint) |
| 876 | return GL_FALSE; |
| 877 | |
| 878 | ExtEntryTable[NumExtEntryPoints].Name = str_dup(funcName); |
| 879 | ExtEntryTable[NumExtEntryPoints].Offset = ~0; |
| 880 | ExtEntryTable[NumExtEntryPoints].Address = entrypoint; |
| 881 | NumExtEntryPoints++; |
| 882 | |
| 883 | return entrypoint; |
| 884 | } |
| 885 | else { |
| 886 | /* no space for new functions! */ |
| 887 | return NULL; |
| 888 | } |
| 889 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 890 | |
| 891 | |
| 892 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 893 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 894 | * Return the name of the function at the given dispatch offset. |
| 895 | * This is only intended for debugging. |
| 896 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 897 | PUBLIC const char * |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 898 | _glapi_get_proc_name(GLuint offset) |
| 899 | { |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 900 | GLuint i; |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 901 | const char * n; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 902 | |
| 903 | /* search built-in functions */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 904 | n = get_static_proc_name(offset); |
| 905 | if ( n != NULL ) { |
| 906 | return n; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /* search added extension functions */ |
| 910 | for (i = 0; i < NumExtEntryPoints; i++) { |
| 911 | if (ExtEntryTable[i].Offset == offset) { |
| 912 | return ExtEntryTable[i].Name; |
| 913 | } |
| 914 | } |
| 915 | return NULL; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 920 | /** |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 921 | * Return size of dispatch table struct as number of functions (or |
| 922 | * slots). |
| 923 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 924 | PUBLIC GLuint |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 925 | _glapi_get_dispatch_table_size(void) |
| 926 | { |
| 927 | return DISPATCH_TABLE_SIZE; |
| 928 | } |
| 929 | |
| 930 | |
| 931 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 932 | /** |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 933 | * Get API dispatcher version string. |
| 934 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 935 | PUBLIC const char * |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 936 | _glapi_get_version(void) |
| 937 | { |
| 938 | return "20021001"; /* YYYYMMDD */ |
| 939 | } |
| 940 | |
| 941 | |
| 942 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 943 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 944 | * Make sure there are no NULL pointers in the given dispatch table. |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 945 | * Intended for debugging purposes. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 946 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame^] | 947 | PUBLIC void |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 948 | _glapi_check_table(const struct _glapi_table *table) |
| 949 | { |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 950 | #ifdef DEBUG |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 951 | const GLuint entries = _glapi_get_dispatch_table_size(); |
| 952 | const void **tab = (const void **) table; |
| 953 | GLuint i; |
| 954 | for (i = 1; i < entries; i++) { |
| 955 | assert(tab[i]); |
| 956 | } |
| 957 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 958 | /* Do some spot checks to be sure that the dispatch table |
| 959 | * slots are assigned correctly. |
| 960 | */ |
| 961 | { |
| 962 | GLuint BeginOffset = _glapi_get_proc_offset("glBegin"); |
| 963 | char *BeginFunc = (char*) &table->Begin; |
| 964 | GLuint offset = (BeginFunc - (char *) table) / sizeof(void *); |
| 965 | assert(BeginOffset == _gloffset_Begin); |
| 966 | assert(BeginOffset == offset); |
| 967 | } |
| 968 | { |
| 969 | GLuint viewportOffset = _glapi_get_proc_offset("glViewport"); |
| 970 | char *viewportFunc = (char*) &table->Viewport; |
| 971 | GLuint offset = (viewportFunc - (char *) table) / sizeof(void *); |
| 972 | assert(viewportOffset == _gloffset_Viewport); |
| 973 | assert(viewportOffset == offset); |
| 974 | } |
| 975 | { |
| 976 | GLuint VertexPointerOffset = _glapi_get_proc_offset("glVertexPointer"); |
| 977 | char *VertexPointerFunc = (char*) &table->VertexPointer; |
| 978 | GLuint offset = (VertexPointerFunc - (char *) table) / sizeof(void *); |
| 979 | assert(VertexPointerOffset == _gloffset_VertexPointer); |
| 980 | assert(VertexPointerOffset == offset); |
| 981 | } |
| 982 | { |
| 983 | GLuint ResetMinMaxOffset = _glapi_get_proc_offset("glResetMinmax"); |
| 984 | char *ResetMinMaxFunc = (char*) &table->ResetMinmax; |
| 985 | GLuint offset = (ResetMinMaxFunc - (char *) table) / sizeof(void *); |
| 986 | assert(ResetMinMaxOffset == _gloffset_ResetMinmax); |
| 987 | assert(ResetMinMaxOffset == offset); |
| 988 | } |
| 989 | { |
| 990 | GLuint blendColorOffset = _glapi_get_proc_offset("glBlendColor"); |
| 991 | char *blendColorFunc = (char*) &table->BlendColor; |
| 992 | GLuint offset = (blendColorFunc - (char *) table) / sizeof(void *); |
| 993 | assert(blendColorOffset == _gloffset_BlendColor); |
| 994 | assert(blendColorOffset == offset); |
| 995 | } |
| 996 | { |
| 997 | GLuint istextureOffset = _glapi_get_proc_offset("glIsTextureEXT"); |
| 998 | char *istextureFunc = (char*) &table->IsTextureEXT; |
| 999 | GLuint offset = (istextureFunc - (char *) table) / sizeof(void *); |
| 1000 | assert(istextureOffset == _gloffset_IsTextureEXT); |
| 1001 | assert(istextureOffset == offset); |
| 1002 | } |
Brian Paul | a14cbff | 2000-10-27 18:31:21 +0000 | [diff] [blame] | 1003 | { |
| 1004 | GLuint secondaryColor3fOffset = _glapi_get_proc_offset("glSecondaryColor3fEXT"); |
| 1005 | char *secondaryColor3fFunc = (char*) &table->SecondaryColor3fEXT; |
| 1006 | GLuint offset = (secondaryColor3fFunc - (char *) table) / sizeof(void *); |
| 1007 | assert(secondaryColor3fOffset == _gloffset_SecondaryColor3fEXT); |
| 1008 | assert(secondaryColor3fOffset == offset); |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 1009 | assert(_glapi_get_proc_address("glSecondaryColor3fEXT") == (_glapi_proc) &glSecondaryColor3fEXT); |
Brian Paul | a14cbff | 2000-10-27 18:31:21 +0000 | [diff] [blame] | 1010 | } |
Brian Paul | 91d6f12 | 2002-05-29 15:23:16 +0000 | [diff] [blame] | 1011 | { |
| 1012 | GLuint pointParameterivOffset = _glapi_get_proc_offset("glPointParameterivNV"); |
| 1013 | char *pointParameterivFunc = (char*) &table->PointParameterivNV; |
| 1014 | GLuint offset = (pointParameterivFunc - (char *) table) / sizeof(void *); |
| 1015 | assert(pointParameterivOffset == _gloffset_PointParameterivNV); |
| 1016 | assert(pointParameterivOffset == offset); |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 1017 | assert(_glapi_get_proc_address("glPointParameterivNV") == (_glapi_proc) &glPointParameterivNV); |
Brian Paul | 91d6f12 | 2002-05-29 15:23:16 +0000 | [diff] [blame] | 1018 | } |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 1019 | { |
| 1020 | GLuint setFenceOffset = _glapi_get_proc_offset("glSetFenceNV"); |
| 1021 | char *setFenceFunc = (char*) &table->SetFenceNV; |
| 1022 | GLuint offset = (setFenceFunc - (char *) table) / sizeof(void *); |
| 1023 | assert(setFenceOffset == _gloffset_SetFenceNV); |
| 1024 | assert(setFenceOffset == offset); |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 1025 | assert(_glapi_get_proc_address("glSetFenceNV") == (_glapi_proc) &glSetFenceNV); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 1026 | } |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 1027 | #else |
| 1028 | (void) table; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 1029 | #endif |
| 1030 | } |