2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
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
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.
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.
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.
38 * NOTE: There are no dependencies on Mesa in this code.
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
43 * 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1.
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.
55 #include "glapioffsets.h"
56 #include "glapitable.h"
59 /***** BEGIN NO-OP DISPATCH *****/
61 static GLboolean WarnFlag
= GL_FALSE
;
62 static _glapi_warning_func warning_func
;
66 * Enable/disable printing of warning messages.
69 _glapi_noop_enable_warnings(GLboolean enable
)
75 * Register a callback function for reporting errors.
78 _glapi_set_warning_func( _glapi_warning_func func
)
86 if ((WarnFlag
|| getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
96 #define KEYWORD1 static
97 #define KEYWORD2 GLAPIENTRY
98 #define NAME(func) NoOp##func
102 #define DISPATCH(func, args, msg) \
104 warning_func(NULL, "GL User Error: called without context: %s", #func); \
107 #define RETURN_DISPATCH(func, args, msg) \
109 warning_func(NULL, "GL User Error: called without context: %s", #func); \
113 #define DISPATCH_TABLE_NAME __glapi_noop_table
114 #define UNUSED_TABLE_NAME __unused_noop_functions
116 #define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
118 static GLint
NoOpUnused(void)
121 warning_func(NULL
, "GL User Error: calling extension function without a current context\n");
126 #include "glapitemp.h"
128 /***** END NO-OP DISPATCH *****/
132 /***** BEGIN THREAD-SAFE DISPATCH *****/
137 * \name Multi-threaded control support variables
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.
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
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
159 * \c GL_TRUE, is used to determine whether or not the application is
163 static GLboolean ThreadSafe
= GL_FALSE
; /**< In thread-safe mode? */
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 */
170 #define DISPATCH_TABLE_NAME __glapi_threadsafe_table
171 #define UNUSED_TABLE_NAME __unused_threadsafe_functions
173 #define TABLE_ENTRY(name) (_glapi_proc) gl##name
175 static GLint
glUnused(void)
180 #include "glapitemp.h"
184 /***** END THREAD-SAFE DISPATCH *****/
188 struct _glapi_table
*_glapi_Dispatch
= (struct _glapi_table
*) __glapi_noop_table
;
189 #if defined( THREADS )
190 struct _glapi_table
*_glapi_DispatchTSD
= (struct _glapi_table
*) __glapi_noop_table
;
192 struct _glapi_table
*_glapi_RealDispatch
= (struct _glapi_table
*) __glapi_noop_table
;
195 /* Used when thread safety disabled */
196 void *_glapi_Context
= NULL
;
199 static GLboolean DispatchOverride
= GL_FALSE
;
204 * strdup() is actually not a standard ANSI C or POSIX routine.
205 * Irix will not define it if ANSI mode is in effect.
208 str_dup(const char *str
)
211 copy
= (char*) malloc(strlen(str
) + 1);
221 * We should call this periodically from a function such as glXMakeCurrent
222 * in order to test if multiple threads are being used.
225 _glapi_check_multithread(void)
229 static unsigned long knownID
;
230 static GLboolean firstCall
= GL_TRUE
;
232 knownID
= _glthread_GetID();
233 firstCall
= GL_FALSE
;
235 else if (knownID
!= _glthread_GetID()) {
236 ThreadSafe
= GL_TRUE
;
237 _glapi_set_dispatch(NULL
);
240 else if (!_glapi_get_dispatch()) {
241 /* make sure that this thread's dispatch pointer isn't null */
242 _glapi_set_dispatch(NULL
);
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.
255 _glapi_set_context(void *context
)
257 (void) __unused_noop_functions
; /* silence a warning */
259 (void) __unused_threadsafe_functions
; /* silence a warning */
260 _glthread_SetTSD(&ContextTSD
, context
);
261 _glapi_Context
= (ThreadSafe
) ? NULL
: context
;
263 _glapi_Context
= context
;
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.
275 _glapi_get_context(void)
279 return _glthread_GetTSD(&ContextTSD
);
282 return _glapi_Context
;
285 return _glapi_Context
;
292 * Set the global or per-thread dispatch table pointer.
295 _glapi_set_dispatch(struct _glapi_table
*dispatch
)
298 /* use the no-op functions */
299 dispatch
= (struct _glapi_table
*) __glapi_noop_table
;
303 _glapi_check_table(dispatch
);
308 if (DispatchOverride
) {
309 _glthread_SetTSD(&RealDispatchTSD
, (void *) dispatch
);
311 _glapi_RealDispatch
= (struct _glapi_table
*) __glapi_threadsafe_table
;
313 _glapi_RealDispatch
= dispatch
;
316 /* normal operation */
317 _glthread_SetTSD(&_gl_DispatchTSD
, (void *) dispatch
);
319 _glapi_Dispatch
= (struct _glapi_table
*) __glapi_threadsafe_table
;
320 _glapi_DispatchTSD
= NULL
;
323 _glapi_Dispatch
= dispatch
;
324 _glapi_DispatchTSD
= dispatch
;
328 if (DispatchOverride
) {
329 _glapi_RealDispatch
= dispatch
;
332 _glapi_Dispatch
= dispatch
;
340 * Return pointer to current dispatch table for calling thread.
342 struct _glapi_table
*
343 _glapi_get_dispatch(void)
347 if (DispatchOverride
) {
348 return (struct _glapi_table
*) _glthread_GetTSD(&RealDispatchTSD
);
351 return (struct _glapi_table
*) _glthread_GetTSD(&_gl_DispatchTSD
);
355 if (DispatchOverride
) {
356 assert(_glapi_RealDispatch
);
357 return _glapi_RealDispatch
;
360 assert(_glapi_DispatchTSD
);
361 return _glapi_DispatchTSD
;
365 return _glapi_Dispatch
;
371 * Notes on dispatch overrride:
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.
378 * libGLS (GL Stream library) is another agent that might use override.
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"
390 * Return: dispatch override layer number.
393 _glapi_begin_dispatch_override(struct _glapi_table
*override
)
395 struct _glapi_table
*real
= _glapi_get_dispatch();
397 assert(!DispatchOverride
); /* can't nest at this time */
398 DispatchOverride
= GL_TRUE
;
400 _glapi_set_dispatch(real
);
403 _glthread_SetTSD(&_gl_DispatchTSD
, (void *) override
);
405 _glapi_Dispatch
= (struct _glapi_table
*) __glapi_threadsafe_table
;
406 _glapi_DispatchTSD
= NULL
;
409 _glapi_Dispatch
= override
;
410 _glapi_DispatchTSD
= override
;
413 _glapi_Dispatch
= override
;
420 _glapi_end_dispatch_override(int layer
)
422 struct _glapi_table
*real
= _glapi_get_dispatch();
424 DispatchOverride
= GL_FALSE
;
425 _glapi_set_dispatch(real
);
426 /* the rest of this isn't needed, just play it safe */
428 _glthread_SetTSD(&RealDispatchTSD
, NULL
);
430 _glapi_RealDispatch
= NULL
;
434 struct _glapi_table
*
435 _glapi_get_override_dispatch(int layer
)
438 return _glapi_get_dispatch();
441 if (DispatchOverride
) {
443 return (struct _glapi_table
*) _glthread_GetTSD(&_gl_DispatchTSD
);
445 return _glapi_Dispatch
;
455 #if !defined( USE_X86_ASM )
456 #define NEED_FUNCTION_POINTER
459 /* The code in this file is auto-generated with Python */
464 * Search the table of static entrypoint functions for the named function
465 * and return the corresponding glprocs_table_t entry.
467 static const glprocs_table_t
*
468 find_entry( const char * n
)
472 for (i
= 0; static_functions
[i
].Name_offset
>= 0; i
++) {
473 const char * test_name
;
475 test_name
= gl_string_table
+ static_functions
[i
].Name_offset
;
476 if (strcmp(test_name
, n
) == 0) {
477 return & static_functions
[i
];
485 * Return dispatch table offset of the named static (built-in) function.
486 * Return -1 if function not found.
489 get_static_proc_offset(const char *funcName
)
491 const glprocs_table_t
* const f
= find_entry( funcName
);
501 extern const GLubyte gl_dispatch_functions_start
[];
503 # if defined(THREADS)
504 # define X86_DISPATCH_FUNCTION_SIZE 32
506 # define X86_DISPATCH_FUNCTION_SIZE 16
511 * Return dispatch function address the named static (built-in) function.
512 * Return NULL if function not found.
514 static const _glapi_proc
515 get_static_proc_address(const char *funcName
)
517 const glprocs_table_t
* const f
= find_entry( funcName
);
520 return (_glapi_proc
) (gl_dispatch_functions_start
521 + (X86_DISPATCH_FUNCTION_SIZE
* f
->Offset
));
532 * Return pointer to the named static (built-in) function.
533 * \return NULL if function not found.
535 static const _glapi_proc
536 get_static_proc_address(const char *funcName
)
538 const glprocs_table_t
* const f
= find_entry( funcName
);
539 return ( f
!= NULL
) ? f
->Address
: NULL
;
542 #endif /* USE_X86_ASM */
546 * Return the name of the function at the given offset in the dispatch
547 * table. For debugging only.
550 get_static_proc_name( GLuint offset
)
554 for (i
= 0; static_functions
[i
].Name_offset
>= 0; i
++) {
555 if (static_functions
[i
].Offset
== offset
) {
556 return gl_string_table
+ static_functions
[i
].Name_offset
;
564 /**********************************************************************
565 * Extension function management.
569 * Number of extension functions which we can dynamically add at runtime.
571 #define MAX_EXTENSION_FUNCS 300
575 * The dispatch table size (number of entries) is the size of the
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
580 #define DISPATCH_TABLE_SIZE (sizeof(struct _glapi_table) / sizeof(void *) + MAX_EXTENSION_FUNCS)
583 struct name_address_offset
{
590 static struct name_address_offset ExtEntryTable
[MAX_EXTENSION_FUNCS
];
591 static GLuint NumExtEntryPoints
= 0;
594 extern void __glapi_sparc_icache_flush(unsigned int *);
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.
603 generate_entrypoint(GLuint functionOffset
)
605 #if defined(USE_X86_ASM)
607 * This x86 code contributed by Josh Vanderhoof.
609 * 0: a1 10 32 54 76 movl __glapi_Dispatch,%eax
611 * 5: 85 c0 testl %eax,%eax
613 * 7: 74 06 je f <entrypoint+0xf>
615 * 9: ff a0 10 32 54 76 jmp *0x76543210(%eax)
617 * f: e8 fc ff ff ff call __glapi_get_dispatch
619 * 14: ff a0 10 32 54 76 jmp *0x76543210(%eax)
622 static const unsigned char insn_template
[] = {
623 0xa1, 0x00, 0x00, 0x00, 0x00,
626 0xff, 0xa0, 0x00, 0x00, 0x00, 0x00,
627 0xe8, 0x00, 0x00, 0x00, 0x00,
628 0xff, 0xa0, 0x00, 0x00, 0x00, 0x00
630 unsigned char *code
= (unsigned char *) malloc(sizeof(insn_template
));
631 unsigned int next_insn
;
633 memcpy(code
, insn_template
, sizeof(insn_template
));
635 #if defined( THREADS )
636 *(unsigned int *)(code
+ 0x01) = (unsigned int)&_glapi_DispatchTSD
;
638 *(unsigned int *)(code
+ 0x01) = (unsigned int)&_glapi_Dispatch
;
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;
645 return (_glapi_proc
) code
;
646 #elif defined(USE_SPARC_ASM)
648 #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__)))
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 */
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 */
671 unsigned int *code
= (unsigned int *) malloc(sizeof(insn_template
));
672 unsigned long glapi_addr
= (unsigned long) &_glapi_Dispatch
;
674 memcpy(code
, insn_template
, sizeof(insn_template
));
676 #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__)))
677 code
[0] |= (glapi_addr
>> (32 + 10));
678 code
[1] |= ((glapi_addr
& 0xffffffff) >> 10);
679 __glapi_sparc_icache_flush(&code
[0]);
680 code
[2] |= ((glapi_addr
>> 32) & ((1 << 10) - 1));
681 code
[3] |= (glapi_addr
& ((1 << 10) - 1));
682 __glapi_sparc_icache_flush(&code
[2]);
683 code
[6] |= ((functionOffset
* 8) >> 10);
684 code
[7] |= ((functionOffset
* 8) & ((1 << 10) - 1));
685 __glapi_sparc_icache_flush(&code
[6]);
687 code
[0] |= (glapi_addr
>> 10);
688 code
[1] |= (glapi_addr
& ((1 << 10) - 1));
689 __glapi_sparc_icache_flush(&code
[0]);
690 code
[2] |= (functionOffset
* 4);
691 __glapi_sparc_icache_flush(&code
[2]);
694 return (_glapi_proc
) code
;
696 (void) functionOffset
;
698 #endif /* USE_*_ASM */
703 * This function inserts a new dispatch offset into the assembly language
704 * stub that was generated with the preceeding function.
707 fill_in_entrypoint_offset(_glapi_proc entrypoint
, GLuint offset
)
709 #if defined(USE_X86_ASM)
711 unsigned char *code
= (unsigned char *) entrypoint
;
712 *(unsigned int *)(code
+ 0x0b) = offset
* 4;
713 *(unsigned int *)(code
+ 0x16) = offset
* 4;
715 #elif defined(USE_SPARC_ASM)
717 /* XXX this hasn't been tested! */
718 unsigned int *code
= (unsigned int *) entrypoint
;
719 #if (defined(__sparc_v9__) && (!defined(__linux__) || defined(__linux_sparc_64__)))
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]);
725 #else /* __sparc_v9__ && !linux */
726 code
[2] = 0xc6006000; /* ld [%g1 + %lo(4*glapioffset)], %g3 */
727 code
[2] |= (offset
* 4);
728 __glapi_sparc_icache_flush(&code
[2]);
729 #endif /* __sparc_v9__ && !linux */
733 /* an unimplemented architecture */
737 #endif /* USE_*_ASM */
742 * Add a new extension function entrypoint.
743 * Return: GL_TRUE = success or GL_FALSE = failure
746 _glapi_add_entrypoint(const char *funcName
, GLuint offset
)
748 /* trivial rejection test */
750 if (!funcName
|| funcName
[0] != 'm' || funcName
[1] != 'g' || funcName
[2] != 'l')
753 if (!funcName
|| funcName
[0] != 'g' || funcName
[1] != 'l')
757 /* first check if the named function is already statically present */
759 GLint index
= get_static_proc_offset(funcName
);
761 return (GLboolean
) ((GLuint
) index
== offset
); /* bad offset! */
765 /* See if this function has already been dynamically added */
768 for (i
= 0; i
< NumExtEntryPoints
; i
++) {
769 if (strcmp(ExtEntryTable
[i
].Name
, funcName
) == 0) {
770 /* function already registered */
771 if (ExtEntryTable
[i
].Offset
== offset
) {
772 return GL_TRUE
; /* offsets match */
774 else if (ExtEntryTable
[i
].Offset
== (GLuint
) ~0
775 && offset
< DISPATCH_TABLE_SIZE
) {
776 /* need to patch-up the dispatch code */
777 if (offset
!= (GLuint
) ~0) {
778 fill_in_entrypoint_offset(ExtEntryTable
[i
].Address
, offset
);
779 ExtEntryTable
[i
].Offset
= offset
;
784 return GL_FALSE
; /* bad offset! */
790 /* This is a new function, try to add it. */
791 if (NumExtEntryPoints
>= MAX_EXTENSION_FUNCS
||
792 offset
>= DISPATCH_TABLE_SIZE
) {
797 _glapi_proc entrypoint
= generate_entrypoint(offset
);
799 return GL_FALSE
; /* couldn't generate assembly */
802 ExtEntryTable
[NumExtEntryPoints
].Name
= str_dup(funcName
);
803 ExtEntryTable
[NumExtEntryPoints
].Offset
= offset
;
804 ExtEntryTable
[NumExtEntryPoints
].Address
= entrypoint
;
807 return GL_TRUE
; /* success */
810 /* should never get here, silence compiler warnings */
816 * Return offset of entrypoint for named function within dispatch table.
819 _glapi_get_proc_offset(const char *funcName
)
821 /* search extension functions first */
823 for (i
= 0; i
< NumExtEntryPoints
; i
++) {
824 if (strcmp(ExtEntryTable
[i
].Name
, funcName
) == 0) {
825 return ExtEntryTable
[i
].Offset
;
829 /* search static functions */
830 return get_static_proc_offset(funcName
);
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.
841 _glapi_get_proc_address(const char *funcName
)
846 if (funcName
[0] != 'm' || funcName
[1] != 'g' || funcName
[2] != 'l')
849 if (funcName
[0] != 'g' || funcName
[1] != 'l')
853 /* search extension functions first */
854 for (i
= 0; i
< NumExtEntryPoints
; i
++) {
855 if (strcmp(ExtEntryTable
[i
].Name
, funcName
) == 0) {
856 return ExtEntryTable
[i
].Address
;
860 /* search static functions */
862 const _glapi_proc func
= get_static_proc_address(funcName
);
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.
873 if (NumExtEntryPoints
< MAX_EXTENSION_FUNCS
) {
874 _glapi_proc entrypoint
= generate_entrypoint(~0);
878 ExtEntryTable
[NumExtEntryPoints
].Name
= str_dup(funcName
);
879 ExtEntryTable
[NumExtEntryPoints
].Offset
= ~0;
880 ExtEntryTable
[NumExtEntryPoints
].Address
= entrypoint
;
886 /* no space for new functions! */
894 * Return the name of the function at the given dispatch offset.
895 * This is only intended for debugging.
898 _glapi_get_proc_name(GLuint offset
)
903 /* search built-in functions */
904 n
= get_static_proc_name(offset
);
909 /* search added extension functions */
910 for (i
= 0; i
< NumExtEntryPoints
; i
++) {
911 if (ExtEntryTable
[i
].Offset
== offset
) {
912 return ExtEntryTable
[i
].Name
;
921 * Return size of dispatch table struct as number of functions (or
925 _glapi_get_dispatch_table_size(void)
927 return DISPATCH_TABLE_SIZE
;
933 * Get API dispatcher version string.
936 _glapi_get_version(void)
938 return "20021001"; /* YYYYMMDD */
944 * Make sure there are no NULL pointers in the given dispatch table.
945 * Intended for debugging purposes.
948 _glapi_check_table(const struct _glapi_table
*table
)
951 const GLuint entries
= _glapi_get_dispatch_table_size();
952 const void **tab
= (const void **) table
;
954 for (i
= 1; i
< entries
; i
++) {
958 /* Do some spot checks to be sure that the dispatch table
959 * slots are assigned correctly.
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
);
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
);
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
);
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
);
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
);
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
);
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
);
1009 assert(_glapi_get_proc_address("glSecondaryColor3fEXT") == (_glapi_proc
) &glSecondaryColor3fEXT
);
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
);
1017 assert(_glapi_get_proc_address("glPointParameterivNV") == (_glapi_proc
) &glPointParameterivNV
);
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
);
1025 assert(_glapi_get_proc_address("glSetFenceNV") == (_glapi_proc
) &glSetFenceNV
);