2
* Mesa 3-D graphics library
5
* Copyright (C) 1999-2006 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"
58
/***** BEGIN NO-OP DISPATCH *****/
60
static GLboolean WarnFlag = GL_FALSE;
61
static _glapi_warning_func warning_func;
63
#if defined(PTHREADS) || defined(GLX_USE_TLS)
64
static void init_glapi_relocs(void);
67
static _glapi_proc generate_entrypoint(GLuint functionOffset);
68
static void fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset);
71
* Enable/disable printing of warning messages.
74
_glapi_noop_enable_warnings(GLboolean enable)
80
* Register a callback function for reporting errors.
83
_glapi_set_warning_func( _glapi_warning_func func )
91
if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG"))
101
#define KEYWORD1 static
102
#define KEYWORD2 GLAPIENTRY
103
#define NAME(func) NoOp##func
107
#define DISPATCH(func, args, msg) \
109
warning_func(NULL, "GL User Error: called without context: %s", #func); \
112
#define RETURN_DISPATCH(func, args, msg) \
114
warning_func(NULL, "GL User Error: called without context: %s", #func); \
118
#define DISPATCH_TABLE_NAME __glapi_noop_table
119
#define UNUSED_TABLE_NAME __unused_noop_functions
121
#define TABLE_ENTRY(name) (_glapi_proc) NoOp##name
123
static GLint NoOpUnused(void)
126
warning_func(NULL, "GL User Error: calling extension function without a current context\n");
131
#include "glapitemp.h"
133
/***** END NO-OP DISPATCH *****/
138
* \name Current dispatch and current context control variables
140
* Depending on whether or not multithreading is support, and the type of
141
* support available, several variables are used to store the current context
142
* pointer and the current dispatch table pointer. In the non-threaded case,
143
* the variables \c _glapi_Dispatch and \c _glapi_Context are used for this
146
* In the "normal" threaded case, the variables \c _glapi_Dispatch and
147
* \c _glapi_Context will be \c NULL if an application is detected as being
148
* multithreaded. Single-threaded applications will use \c _glapi_Dispatch
149
* and \c _glapi_Context just like the case without any threading support.
150
* When \c _glapi_Dispatch and \c _glapi_Context are \c NULL, the thread state
151
* data \c _gl_DispatchTSD and \c ContextTSD are used. Drivers and the
152
* static dispatch functions access these variables via \c _glapi_get_dispatch
153
* and \c _glapi_get_context.
155
* There is a race condition in setting \c _glapi_Dispatch to \c NULL. It is
156
* possible for the original thread to be setting it at the same instant a new
157
* thread, perhaps running on a different processor, is clearing it. Because
158
* of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is
159
* used to determine whether or not the application is multithreaded.
161
* In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are
162
* hardcoded to \c NULL. Instead the TLS variables \c _glapi_tls_Dispatch and
163
* \c _glapi_tls_Context are used. Having \c _glapi_Dispatch and
164
* \c _glapi_Context be hardcoded to \c NULL maintains binary compatability
165
* between TLS enabled loaders and non-TLS DRI drivers.
168
#if defined(GLX_USE_TLS)
170
PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch
171
__attribute__((tls_model("initial-exec")))
172
= (struct _glapi_table *) __glapi_noop_table;
174
PUBLIC __thread void * _glapi_tls_Context
175
__attribute__((tls_model("initial-exec")));
177
PUBLIC const struct _glapi_table *_glapi_Dispatch = NULL;
178
PUBLIC const void *_glapi_Context = NULL;
184
static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */
185
_glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */
186
static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
188
#endif /* defined(THREADS) */
190
PUBLIC struct _glapi_table *_glapi_Dispatch =
191
(struct _glapi_table *) __glapi_noop_table;
192
PUBLIC void *_glapi_Context = NULL;
194
#endif /* defined(GLX_USE_TLS) */
199
* strdup() is actually not a standard ANSI C or POSIX routine.
200
* Irix will not define it if ANSI mode is in effect.
203
str_dup(const char *str)
206
copy = (char*) malloc(strlen(str) + 1);
216
* We should call this periodically from a function such as glXMakeCurrent
217
* in order to test if multiple threads are being used.
220
_glapi_check_multithread(void)
222
#if defined(THREADS) && !defined(GLX_USE_TLS)
224
static unsigned long knownID;
225
static GLboolean firstCall = GL_TRUE;
227
knownID = _glthread_GetID();
228
firstCall = GL_FALSE;
230
else if (knownID != _glthread_GetID()) {
231
ThreadSafe = GL_TRUE;
232
_glapi_set_dispatch(NULL);
235
else if (!_glapi_get_dispatch()) {
236
/* make sure that this thread's dispatch pointer isn't null */
237
_glapi_set_dispatch(NULL);
245
* Set the current context pointer for this thread.
246
* The context pointer is an opaque type which should be cast to
247
* void from the real context pointer type.
250
_glapi_set_context(void *context)
252
(void) __unused_noop_functions; /* silence a warning */
253
#if defined(GLX_USE_TLS)
254
_glapi_tls_Context = context;
255
#elif defined(THREADS)
256
_glthread_SetTSD(&ContextTSD, context);
257
_glapi_Context = (ThreadSafe) ? NULL : context;
259
_glapi_Context = context;
266
* Get the current context pointer for this thread.
267
* The context pointer is an opaque type which should be cast from
268
* void to the real context pointer type.
271
_glapi_get_context(void)
273
#if defined(GLX_USE_TLS)
274
return _glapi_tls_Context;
275
#elif defined(THREADS)
277
return _glthread_GetTSD(&ContextTSD);
280
return _glapi_Context;
283
return _glapi_Context;
290
* Set the global or per-thread dispatch table pointer.
291
* If the dispatch parameter is NULL we'll plug in the no-op dispatch
292
* table (__glapi_noop_table).
295
_glapi_set_dispatch(struct _glapi_table *dispatch)
297
#if defined(PTHREADS) || defined(GLX_USE_TLS)
298
static pthread_once_t once_control = PTHREAD_ONCE_INIT;
299
pthread_once( & once_control, init_glapi_relocs );
303
/* use the no-op functions */
304
dispatch = (struct _glapi_table *) __glapi_noop_table;
308
_glapi_check_table(dispatch);
312
#if defined(GLX_USE_TLS)
313
_glapi_tls_Dispatch = dispatch;
314
#elif defined(THREADS)
315
_glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch);
316
_glapi_Dispatch = (ThreadSafe) ? NULL : dispatch;
318
_glapi_Dispatch = dispatch;
325
* Return pointer to current dispatch table for calling thread.
327
PUBLIC struct _glapi_table *
328
_glapi_get_dispatch(void)
330
struct _glapi_table * api;
331
#if defined(GLX_USE_TLS)
332
api = _glapi_tls_Dispatch;
333
#elif defined(THREADS)
335
? (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD)
338
api = _glapi_Dispatch;
346
*** The rest of this file is pretty much concerned with GetProcAddress
350
#if !defined( USE_X86_ASM ) && !defined( XFree86Server ) && !defined ( XGLServer )
351
#define NEED_FUNCTION_POINTER
354
/* The code in this file is auto-generated with Python */
359
* Search the table of static entrypoint functions for the named function
360
* and return the corresponding glprocs_table_t entry.
362
static const glprocs_table_t *
363
find_entry( const char * n )
366
for (i = 0; static_functions[i].Name_offset >= 0; i++) {
367
const char *testName = gl_string_table + static_functions[i].Name_offset;
368
if (strcmp(testName, n) == 0) {
369
return &static_functions[i];
377
* Return dispatch table offset of the named static (built-in) function.
378
* Return -1 if function not found.
381
get_static_proc_offset(const char *funcName)
383
const glprocs_table_t * const f = find_entry( funcName );
391
#if !defined(XFree86Server) && !defined(XGLServer)
394
#if defined( GLX_USE_TLS )
395
extern GLubyte gl_dispatch_functions_start[];
396
extern GLubyte gl_dispatch_functions_end[];
398
extern const GLubyte gl_dispatch_functions_start[];
401
# if defined(THREADS) && !defined(GLX_USE_TLS)
402
# define X86_DISPATCH_FUNCTION_SIZE 32
404
# define X86_DISPATCH_FUNCTION_SIZE 16
407
#endif /* USE_X86_ASM */
411
* Return dispatch function address for the named static (built-in) function.
412
* Return NULL if function not found.
414
static const _glapi_proc
415
get_static_proc_address(const char *funcName)
417
const glprocs_table_t * const f = find_entry( funcName );
420
return (_glapi_proc) (gl_dispatch_functions_start
421
+ (X86_DISPATCH_FUNCTION_SIZE * f->Offset));
431
#endif /* !defined(XFree86Server) && !defined(XGLServer) */
436
* Return the name of the function at the given offset in the dispatch
437
* table. For debugging only.
440
get_static_proc_name( GLuint offset )
443
for (i = 0; static_functions[i].Name_offset >= 0; i++) {
444
if (static_functions[i].Offset == offset) {
445
return gl_string_table + static_functions[i].Name_offset;
453
/**********************************************************************
454
* Extension function management.
458
* Number of extension functions which we can dynamically add at runtime.
460
#define MAX_EXTENSION_FUNCS 300
464
* The dispatch table size (number of entries) is the size of the
465
* _glapi_table struct plus the number of dynamic entries we can add.
466
* The extra slots can be filled in by DRI drivers that register new extension
469
#define DISPATCH_TABLE_SIZE (sizeof(struct _glapi_table) / sizeof(void *) + MAX_EXTENSION_FUNCS)
473
* Track information about a function added to the GL API.
475
struct _glapi_function {
477
* Name of the function.
483
* Text string that describes the types of the parameters passed to the
484
* named function. Parameter types are converted to characters using the
486
* - 'i' for \c GLint, \c GLuint, and \c GLenum
487
* - 'p' for any pointer type
488
* - 'f' for \c GLfloat and \c GLclampf
489
* - 'd' for \c GLdouble and \c GLclampd
491
const char * parameter_signature;
495
* Offset in the dispatch table where the pointer to the real function is
496
* located. If the driver has not requested that the named function be
497
* added to the dispatch table, this will have the value ~0.
499
unsigned dispatch_offset;
503
* Pointer to the dispatch stub for the named function.
506
* The semantic of this field should be changed slightly. Currently, it
507
* is always expected to be non-\c NULL. However, it would be better to
508
* only allocate the entry-point stub when the application requests the
509
* function via \c glXGetProcAddress. This would save memory for all the
510
* functions that the driver exports but that the application never wants
513
_glapi_proc dispatch_stub;
517
static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS];
518
static GLuint NumExtEntryPoints = 0;
521
extern void __glapi_sparc_icache_flush(unsigned int *);
525
* Generate a dispatch function (entrypoint) which jumps through
526
* the given slot number (offset) in the current dispatch table.
527
* We need assembly language in order to accomplish this.
530
generate_entrypoint(GLuint functionOffset)
532
#if defined(USE_X86_ASM)
533
/* 32 is chosen as something of a magic offset. For x86, the dispatch
534
* at offset 32 is the first one where the offset in the
535
* "jmp OFFSET*4(%eax)" can't be encoded in a single byte.
537
const GLubyte * const template_func = gl_dispatch_functions_start
538
+ (X86_DISPATCH_FUNCTION_SIZE * 32);
539
GLubyte * const code = (GLubyte *) malloc( X86_DISPATCH_FUNCTION_SIZE );
542
if ( code != NULL ) {
543
(void) memcpy( code, template_func, X86_DISPATCH_FUNCTION_SIZE );
544
fill_in_entrypoint_offset( (_glapi_proc) code, functionOffset );
547
return (_glapi_proc) code;
548
#elif defined(USE_SPARC_ASM)
551
static const unsigned int insn_template[] = {
552
0x05000000, /* sethi %uhi(_glapi_Dispatch), %g2 */
553
0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */
554
0x8410a000, /* or %g2, %ulo(_glapi_Dispatch), %g2 */
555
0x82106000, /* or %g1, %lo(_glapi_Dispatch), %g1 */
556
0x8528b020, /* sllx %g2, 32, %g2 */
557
0xc2584002, /* ldx [%g1 + %g2], %g1 */
558
0x05000000, /* sethi %hi(8 * glapioffset), %g2 */
559
0x8410a000, /* or %g2, %lo(8 * glapioffset), %g2 */
560
0xc6584002, /* ldx [%g1 + %g2], %g3 */
561
0x81c0c000, /* jmpl %g3, %g0 */
565
static const unsigned int insn_template[] = {
566
0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */
567
0xc2006000, /* ld [%g1 + %lo(_glapi_Dispatch)], %g1 */
568
0xc6006000, /* ld [%g1 + %lo(4*glapioffset)], %g3 */
569
0x81c0c000, /* jmpl %g3, %g0 */
572
#endif /* __arch64__ */
573
unsigned int *code = (unsigned int *) malloc(sizeof(insn_template));
574
unsigned long glapi_addr = (unsigned long) &_glapi_Dispatch;
576
memcpy(code, insn_template, sizeof(insn_template));
579
code[0] |= (glapi_addr >> (32 + 10));
580
code[1] |= ((glapi_addr & 0xffffffff) >> 10);
581
__glapi_sparc_icache_flush(&code[0]);
582
code[2] |= ((glapi_addr >> 32) & ((1 << 10) - 1));
583
code[3] |= (glapi_addr & ((1 << 10) - 1));
584
__glapi_sparc_icache_flush(&code[2]);
585
code[6] |= ((functionOffset * 8) >> 10);
586
code[7] |= ((functionOffset * 8) & ((1 << 10) - 1));
587
__glapi_sparc_icache_flush(&code[6]);
589
code[0] |= (glapi_addr >> 10);
590
code[1] |= (glapi_addr & ((1 << 10) - 1));
591
__glapi_sparc_icache_flush(&code[0]);
592
code[2] |= (functionOffset * 4);
593
__glapi_sparc_icache_flush(&code[2]);
594
#endif /* __arch64__ */
596
return (_glapi_proc) code;
598
(void) functionOffset;
600
#endif /* USE_*_ASM */
605
* This function inserts a new dispatch offset into the assembly language
606
* stub that was generated with the preceeding function.
609
fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset)
611
#if defined(USE_X86_ASM)
612
GLubyte * const code = (GLubyte *) entrypoint;
614
#if X86_DISPATCH_FUNCTION_SIZE == 32
615
*((unsigned int *)(code + 11)) = 4 * offset;
616
*((unsigned int *)(code + 22)) = 4 * offset;
617
#elif X86_DISPATCH_FUNCTION_SIZE == 16 && defined( GLX_USE_TLS )
618
*((unsigned int *)(code + 8)) = 4 * offset;
619
#elif X86_DISPATCH_FUNCTION_SIZE == 16
620
*((unsigned int *)(code + 7)) = 4 * offset;
622
# error Invalid X86_DISPATCH_FUNCTION_SIZE!
625
#elif defined(USE_SPARC_ASM)
627
/* XXX this hasn't been tested! */
628
unsigned int *code = (unsigned int *) entrypoint;
630
code[6] = 0x05000000; /* sethi %hi(8 * glapioffset), %g2 */
631
code[7] = 0x8410a000; /* or %g2, %lo(8 * glapioffset), %g2 */
632
code[6] |= ((offset * 8) >> 10);
633
code[7] |= ((offset * 8) & ((1 << 10) - 1));
634
__glapi_sparc_icache_flush(&code[6]);
635
#else /* __arch64__ */
636
code[2] = 0xc6006000; /* ld [%g1 + %lo(4*glapioffset)], %g3 */
637
code[2] |= (offset * 4);
638
__glapi_sparc_icache_flush(&code[2]);
639
#endif /* __arch64__ */
643
/* an unimplemented architecture */
647
#endif /* USE_*_ASM */
652
* Generate new entrypoint
654
* Use a temporary dispatch offset of ~0 (i.e. -1). Later, when the driver
655
* calls \c _glapi_add_dispatch we'll put in the proper offset. If that
656
* never happens, and the user calls this function, he'll segfault. That's
657
* what you get when you try calling a GL function that doesn't really exist.
659
* \param funcName Name of the function to create an entry-point for.
661
* \sa _glapi_add_entrypoint
664
static struct _glapi_function *
665
add_function_name( const char * funcName )
667
struct _glapi_function * entry = NULL;
669
if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) {
670
_glapi_proc entrypoint = generate_entrypoint(~0);
671
if (entrypoint != NULL) {
672
entry = & ExtEntryTable[NumExtEntryPoints];
674
ExtEntryTable[NumExtEntryPoints].name = str_dup(funcName);
675
ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL;
676
ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0;
677
ExtEntryTable[NumExtEntryPoints].dispatch_stub = entrypoint;
687
* Fill-in the dispatch stub for the named function.
689
* This function is intended to be called by a hardware driver. When called,
690
* a dispatch stub may be created created for the function. A pointer to this
691
* dispatch function will be returned by glXGetProcAddress.
693
* \param function_names Array of pointers to function names that should
694
* share a common dispatch offset.
695
* \param parameter_signature String representing the types of the parameters
696
* passed to the named function. Parameter types
697
* are converted to characters using the following
699
* - 'i' for \c GLint, \c GLuint, and \c GLenum
700
* - 'p' for any pointer type
701
* - 'f' for \c GLfloat and \c GLclampf
702
* - 'd' for \c GLdouble and \c GLclampd
705
* The offset in the dispatch table of the named function. A pointer to the
706
* driver's implementation of the named function should be stored at
707
* \c dispatch_table[\c offset].
709
* \sa glXGetProcAddress
712
* This function can only handle up to 8 names at a time. As far as I know,
713
* the maximum number of names ever associated with an existing GL function is
714
* 4 (\c glPointParameterfSGIS, \c glPointParameterfEXT,
715
* \c glPointParameterfARB, and \c glPointParameterf), so this should not be
716
* too painful of a limitation.
719
* Determine whether or not \c parameter_signature should be allowed to be
720
* \c NULL. It doesn't seem like much of a hardship for drivers to have to
721
* pass in an empty string.
724
* Determine if code should be added to reject function names that start with
728
* Add code to compare \c parameter_signature with the parameter signature of
729
* a static function. In order to do that, we need to find a way to \b get
730
* the parameter signature of a static function.
734
_glapi_add_dispatch( const char * const * function_names,
735
const char * parameter_signature )
737
static int next_dynamic_offset = _gloffset_FIRST_DYNAMIC;
738
const char * const real_sig = (parameter_signature != NULL)
739
? parameter_signature : "";
740
struct _glapi_function * entry[8];
741
GLboolean is_static[8];
748
(void) memset( is_static, 0, sizeof( is_static ) );
749
(void) memset( entry, 0, sizeof( entry ) );
751
for ( i = 0 ; function_names[i] != NULL ; i++ ) {
752
/* Do some trivial validation on the name of the function.
755
if (!function_names[i] || function_names[i][0] != 'g' || function_names[i][1] != 'l')
758
/* Determine if the named function already exists. If the function does
759
* exist, it must have the same parameter signature as the function
763
new_offset = get_static_proc_offset(function_names[i]);
764
if (new_offset >= 0) {
765
/* FIXME: Make sure the parameter signatures match! How do we get
766
* FIXME: the parameter signature for static functions?
769
if ( (offset != ~0) && (new_offset != offset) ) {
773
is_static[i] = GL_TRUE;
778
for ( j = 0 ; j < NumExtEntryPoints ; j++ ) {
779
if (strcmp(ExtEntryTable[j].name, function_names[i]) == 0) {
780
/* The offset may be ~0 if the function name was added by
781
* glXGetProcAddress but never filled in by the driver.
784
if (ExtEntryTable[j].dispatch_offset != ~0) {
785
if (strcmp(real_sig, ExtEntryTable[j].parameter_signature)
790
if ( (offset != ~0) && (ExtEntryTable[j].dispatch_offset != offset) ) {
794
offset = ExtEntryTable[j].dispatch_offset;
797
entry[i] = & ExtEntryTable[j];
804
offset = next_dynamic_offset;
805
next_dynamic_offset++;
808
for ( i = 0 ; function_names[i] != NULL ; i++ ) {
809
if (! is_static[i] ) {
810
if (entry[i] == NULL) {
811
entry[i] = add_function_name( function_names[i] );
812
if (entry[i] == NULL) {
813
/* FIXME: Possible memory leak here.
819
entry[i]->parameter_signature = str_dup(real_sig);
820
fill_in_entrypoint_offset(entry[i]->dispatch_stub, offset);
821
entry[i]->dispatch_offset = offset;
830
* Return offset of entrypoint for named function within dispatch table.
833
_glapi_get_proc_offset(const char *funcName)
835
/* search extension functions first */
837
for (i = 0; i < NumExtEntryPoints; i++) {
838
if (strcmp(ExtEntryTable[i].name, funcName) == 0) {
839
return ExtEntryTable[i].dispatch_offset;
842
/* search static functions */
843
return get_static_proc_offset(funcName);
849
* Return pointer to the named function. If the function name isn't found
850
* in the name of static functions, try generating a new API entrypoint on
851
* the fly with assembly language.
854
_glapi_get_proc_address(const char *funcName)
856
struct _glapi_function * entry;
860
if (funcName[0] != 'm' || funcName[1] != 'g' || funcName[2] != 'l')
863
if (funcName[0] != 'g' || funcName[1] != 'l')
867
/* search extension functions first */
868
for (i = 0; i < NumExtEntryPoints; i++) {
869
if (strcmp(ExtEntryTable[i].name, funcName) == 0) {
870
return ExtEntryTable[i].dispatch_stub;
874
#if !defined( XFree86Server ) && !defined( XGLServer )
875
/* search static functions */
877
const _glapi_proc func = get_static_proc_address(funcName);
881
#endif /* !defined( XFree86Server ) */
883
entry = add_function_name(funcName);
884
return (entry == NULL) ? NULL : entry->dispatch_stub;
890
* Return the name of the function at the given dispatch offset.
891
* This is only intended for debugging.
894
_glapi_get_proc_name(GLuint offset)
899
/* search built-in functions */
900
n = get_static_proc_name(offset);
905
/* search added extension functions */
906
for (i = 0; i < NumExtEntryPoints; i++) {
907
if (ExtEntryTable[i].dispatch_offset == offset) {
908
return ExtEntryTable[i].name;
917
* Return size of dispatch table struct as number of functions (or
921
_glapi_get_dispatch_table_size(void)
923
return DISPATCH_TABLE_SIZE;
929
* Make sure there are no NULL pointers in the given dispatch table.
930
* Intended for debugging purposes.
933
_glapi_check_table(const struct _glapi_table *table)
936
const GLuint entries = _glapi_get_dispatch_table_size();
937
const void **tab = (const void **) table;
939
for (i = 1; i < entries; i++) {
943
/* Do some spot checks to be sure that the dispatch table
944
* slots are assigned correctly.
947
GLuint BeginOffset = _glapi_get_proc_offset("glBegin");
948
char *BeginFunc = (char*) &table->Begin;
949
GLuint offset = (BeginFunc - (char *) table) / sizeof(void *);
950
assert(BeginOffset == _gloffset_Begin);
951
assert(BeginOffset == offset);
954
GLuint viewportOffset = _glapi_get_proc_offset("glViewport");
955
char *viewportFunc = (char*) &table->Viewport;
956
GLuint offset = (viewportFunc - (char *) table) / sizeof(void *);
957
assert(viewportOffset == _gloffset_Viewport);
958
assert(viewportOffset == offset);
961
GLuint VertexPointerOffset = _glapi_get_proc_offset("glVertexPointer");
962
char *VertexPointerFunc = (char*) &table->VertexPointer;
963
GLuint offset = (VertexPointerFunc - (char *) table) / sizeof(void *);
964
assert(VertexPointerOffset == _gloffset_VertexPointer);
965
assert(VertexPointerOffset == offset);
968
GLuint ResetMinMaxOffset = _glapi_get_proc_offset("glResetMinmax");
969
char *ResetMinMaxFunc = (char*) &table->ResetMinmax;
970
GLuint offset = (ResetMinMaxFunc - (char *) table) / sizeof(void *);
971
assert(ResetMinMaxOffset == _gloffset_ResetMinmax);
972
assert(ResetMinMaxOffset == offset);
975
GLuint blendColorOffset = _glapi_get_proc_offset("glBlendColor");
976
char *blendColorFunc = (char*) &table->BlendColor;
977
GLuint offset = (blendColorFunc - (char *) table) / sizeof(void *);
978
assert(blendColorOffset == _gloffset_BlendColor);
979
assert(blendColorOffset == offset);
982
GLuint istextureOffset = _glapi_get_proc_offset("glIsTextureEXT");
983
char *istextureFunc = (char*) &table->IsTextureEXT;
984
GLuint offset = (istextureFunc - (char *) table) / sizeof(void *);
985
assert(istextureOffset == _gloffset_IsTextureEXT);
986
assert(istextureOffset == offset);
989
GLuint secondaryColor3fOffset = _glapi_get_proc_offset("glSecondaryColor3fEXT");
990
char *secondaryColor3fFunc = (char*) &table->SecondaryColor3fEXT;
991
GLuint offset = (secondaryColor3fFunc - (char *) table) / sizeof(void *);
992
assert(secondaryColor3fOffset == _gloffset_SecondaryColor3fEXT);
993
assert(secondaryColor3fOffset == offset);
994
assert(_glapi_get_proc_address("glSecondaryColor3fEXT") == (_glapi_proc) &glSecondaryColor3fEXT);
997
GLuint pointParameterivOffset = _glapi_get_proc_offset("glPointParameterivNV");
998
char *pointParameterivFunc = (char*) &table->PointParameterivNV;
999
GLuint offset = (pointParameterivFunc - (char *) table) / sizeof(void *);
1000
assert(pointParameterivOffset == _gloffset_PointParameterivNV);
1001
assert(pointParameterivOffset == offset);
1002
assert(_glapi_get_proc_address("glPointParameterivNV") == (_glapi_proc) &glPointParameterivNV);
1005
GLuint setFenceOffset = _glapi_get_proc_offset("glSetFenceNV");
1006
char *setFenceFunc = (char*) &table->SetFenceNV;
1007
GLuint offset = (setFenceFunc - (char *) table) / sizeof(void *);
1008
assert(setFenceOffset == _gloffset_SetFenceNV);
1009
assert(setFenceOffset == offset);
1010
assert(_glapi_get_proc_address("glSetFenceNV") == (_glapi_proc) &glSetFenceNV);
1018
#if defined(PTHREADS) || defined(GLX_USE_TLS)
1020
* Perform platform-specific GL API entry-point fixups.
1025
init_glapi_relocs( void )
1027
#if defined( USE_X86_ASM ) && defined( GLX_USE_TLS )
1028
extern void * _x86_get_dispatch(void);
1029
const GLubyte * const get_disp = (const GLubyte *) _x86_get_dispatch;
1030
GLubyte * curr_func = (GLubyte *) gl_dispatch_functions_start;
1033
while ( curr_func != (GLubyte *) gl_dispatch_functions_end ) {
1034
(void) memcpy( curr_func, get_disp, 6 );
1035
curr_func += X86_DISPATCH_FUNCTION_SIZE;
1037
#endif /* defined( USE_X86_ASM ) && defined( GLX_USE_TLS ) */