2 * Mesa 3-D graphics library
5 * Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
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.
28 * Remap table management.
30 * Entries in the dispatch table are either static or dynamic. The
31 * dispatch table is shared by mesa core and glapi. When they are
32 * built separately, it is possible that a static entry in mesa core
33 * is dynamic, or assigned a different static offset, in glapi. The
34 * remap table is in charge of mapping a static entry in mesa core to
35 * a dynamic entry, or the corresponding static entry, in glapi.
41 #include "glapi/dispatch.h"
44 #if FEATURE_remap_table
47 #define need_MESA_remap_table
48 #include "remap_helper.h"
50 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
51 #define MAX_ENTRY_POINTS 16
54 /* this is global for quick access */
55 int driDispatchRemapTable
[driDispatchRemapTable_size
];
59 * Return the spec string associated with the given function index.
60 * The index is available from including remap_helper.h.
62 * \param func_index an opaque function index.
64 * \return the spec string associated with the function index, or NULL.
67 _mesa_get_function_spec(GLint func_index
)
69 if (func_index
< ARRAY_SIZE(_mesa_function_pool
))
70 return _mesa_function_pool
+ func_index
;
77 * Map a function by its spec. The function will be added to glapi,
78 * and the dispatch offset will be returned.
80 * \param spec a '\0'-separated string array specifying a function.
81 * It begins with the parameter signature of the function,
82 * followed by the names of the entry points. An empty entry
83 * point name terminates the array.
85 * \return the offset of the (re-)mapped function in the dispatch
89 _mesa_map_function_spec(const char *spec
)
91 const char *signature
;
92 const char *names
[MAX_ENTRY_POINTS
+ 1];
99 spec
+= strlen(spec
) + 1;
101 /* spec is terminated by an empty string */
103 names
[num_names
] = spec
;
105 if (num_names
>= MAX_ENTRY_POINTS
)
107 spec
+= strlen(spec
) + 1;
112 names
[num_names
] = NULL
;
114 /* add the entry points to the dispatch table */
115 return _glapi_add_dispatch(names
, signature
);
120 * Map an array of functions. This is a convenient function for
121 * use with arrays available from including remap_helper.h.
123 * Note that the dispatch offsets of the functions are not returned.
124 * If they are needed, _mesa_map_function_spec() should be used.
126 * \param func_array an array of function remaps.
129 _mesa_map_function_array(const struct gl_function_remap
*func_array
)
136 for (i
= 0; func_array
[i
].func_index
!= -1; i
++) {
140 spec
= _mesa_get_function_spec(func_array
[i
].func_index
);
142 _mesa_problem(NULL
, "invalid function index %d",
143 func_array
[i
].func_index
);
147 offset
= _mesa_map_function_spec(spec
);
150 const char *name
= spec
+ strlen(spec
) + 1;
151 _mesa_warning(NULL
, "failed to remap %s", name
);
153 else if (func_array
[i
].dispatch_offset
>= 0 &&
154 offset
!= func_array
[i
].dispatch_offset
) {
155 const char *name
= spec
+ strlen(spec
) + 1;
156 _mesa_problem(NULL
, "%s should be mapped to %d, not %d",
157 name
, func_array
[i
].dispatch_offset
, offset
);
164 * Map the functions which are already static.
166 * When a extension function are incorporated into the ABI, the
167 * extension suffix is usually stripped. Mapping such functions
168 * makes sure the alternative names are available.
170 * Note that functions mapped by _mesa_init_remap_table() are
174 _mesa_map_static_functions(void)
176 /* Remap static functions which have alternative names and are in the ABI.
177 * This is to be on the safe side. glapi should have defined those names.
179 _mesa_map_function_array(MESA_alt_functions
);
184 * Initialize the remap table. This is called in one_time_init().
185 * The remap table needs to be initialized before calling the
186 * CALL/GET/SET macros defined in glapi/dispatch.h.
189 _mesa_init_remap_table(void)
191 static GLboolean initialized
= GL_FALSE
;
196 initialized
= GL_TRUE
;
198 /* initialize the remap table */
199 for (i
= 0; i
< ARRAY_SIZE(driDispatchRemapTable
); i
++) {
204 ASSERT(i
== MESA_remap_table_functions
[i
].remap_index
);
205 spec
= _mesa_function_pool
+ MESA_remap_table_functions
[i
].pool_index
;
207 offset
= _mesa_map_function_spec(spec
);
208 /* store the dispatch offset in the remap table */
209 driDispatchRemapTable
[i
] = offset
;
211 _mesa_warning(NULL
, "failed to remap index %d", i
);
216 #endif /* FEATURE_remap_table */