1 | # Copyright (c) 2001, Stanford University
|
---|
2 | # All rights reserved.
|
---|
3 | #
|
---|
4 | # See the file LICENSE.txt for information on redistributing this software.
|
---|
5 |
|
---|
6 |
|
---|
7 | from __future__ import print_function
|
---|
8 | import sys
|
---|
9 | import apiutil
|
---|
10 |
|
---|
11 |
|
---|
12 | keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
|
---|
13 |
|
---|
14 | apiutil.CopyrightC()
|
---|
15 |
|
---|
16 | print("""
|
---|
17 | /* DO NOT EDIT - THIS FILE GENERATED BY THE glloader.py SCRIPT */
|
---|
18 | #include "cr_error.h"
|
---|
19 | #include "cr_dll.h"
|
---|
20 | #include "cr_spu.h"
|
---|
21 | #include "cr_string.h"
|
---|
22 | #include "cr_error.h"
|
---|
23 | #include "cr_environment.h"
|
---|
24 |
|
---|
25 | #include <stdio.h>
|
---|
26 | #if defined(WINDOWS)
|
---|
27 | # ifdef VBOX
|
---|
28 | # include <iprt/win/windows.h>
|
---|
29 | # else
|
---|
30 | #include <windows.h>
|
---|
31 | # endif
|
---|
32 | #include <process.h>
|
---|
33 | #include <direct.h>
|
---|
34 | #define SYSTEM_GL "opengl32.dll"
|
---|
35 | #elif defined (DARWIN)
|
---|
36 | #define SYSTEM_GL "libGL.dylib"
|
---|
37 | #define SYSTEM_CGL "OpenGL"
|
---|
38 | # ifndef VBOX_WITH_COCOA_QT
|
---|
39 | # define SYSTEM_AGL "AGL"
|
---|
40 | # endif
|
---|
41 | #include <string.h> /* VBOX */
|
---|
42 | #elif defined(IRIX) || defined(IRIX64) || defined(Linux) || defined(FreeBSD) || defined(AIX) || defined(SunOS) || defined(OSF1)
|
---|
43 | #include <string.h>
|
---|
44 | #if defined(AIX)
|
---|
45 | #define SYSTEM_GL "libGL.o"
|
---|
46 | #else
|
---|
47 | #define SYSTEM_GL "libGL.so.1"
|
---|
48 | #endif
|
---|
49 | typedef void (*glxfuncptr)(void);
|
---|
50 | extern glxfuncptr glxGetProcAddressARB( const GLubyte *name );
|
---|
51 | #else
|
---|
52 | #error I don't know where your system's GL lives. Too bad.
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | static CRDLL *glDll = NULL;
|
---|
56 |
|
---|
57 | #ifdef DARWIN
|
---|
58 | #define SYSTEM_GL_LIB_DIR "/System/Library/Frameworks/OpenGL.framework/Libraries"
|
---|
59 | #define SYSTEM_CGL_DIR "/System/Library/Frameworks/OpenGL.framework"
|
---|
60 | static CRDLL *cglDll = NULL;
|
---|
61 | # ifndef VBOX_WITH_COCOA_QT
|
---|
62 | # define SYSTEM_AGL_DIR "/System/Library/Frameworks/AGL.framework"
|
---|
63 | static CRDLL *aglDll = NULL;
|
---|
64 | # endif
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | #if defined(WINDOWS)
|
---|
68 | #define GLLOADER_APIENTRY __stdcall
|
---|
69 | #else
|
---|
70 | #define GLLOADER_APIENTRY
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | /*
|
---|
74 | * Add an entry to the SPUNamedFunctionTable
|
---|
75 | */
|
---|
76 | static int
|
---|
77 | fillin(SPUNamedFunctionTable *entry, const char *funcName, SPUGenericFunction funcPtr)
|
---|
78 | {
|
---|
79 | if (funcPtr) {
|
---|
80 | entry->name = crStrdup(funcName);
|
---|
81 | entry->fn = funcPtr;
|
---|
82 | return 1;
|
---|
83 | }
|
---|
84 | return 0;
|
---|
85 | }
|
---|
86 |
|
---|
87 | #ifndef WINDOWS
|
---|
88 | /*static int FileExists(char *directory, char *filename)
|
---|
89 | {
|
---|
90 | FILE *f;
|
---|
91 | char fullFilename[8096];
|
---|
92 |
|
---|
93 | crStrcpy(fullFilename, directory);
|
---|
94 | crStrcat(fullFilename, "/");
|
---|
95 | crStrcat(fullFilename, filename);
|
---|
96 |
|
---|
97 | f = fopen(fullFilename, "r");
|
---|
98 | if (f) {
|
---|
99 | fclose(f);
|
---|
100 | return 1;
|
---|
101 | }
|
---|
102 | else {
|
---|
103 | return 0;
|
---|
104 | }
|
---|
105 | }*/
|
---|
106 | #endif
|
---|
107 |
|
---|
108 |
|
---|
109 | /*
|
---|
110 | * Locate the native OpenGL library, open it and return shared library
|
---|
111 | * handle.
|
---|
112 | */
|
---|
113 | static CRDLL *
|
---|
114 | __findSystemLib( const char *provided_system_path, char *lib )
|
---|
115 | {
|
---|
116 | CRDLL *dll;
|
---|
117 | char system_path[8096];
|
---|
118 |
|
---|
119 | memset(system_path, 0, sizeof(system_path));
|
---|
120 |
|
---|
121 | if (provided_system_path && (crStrlen(provided_system_path) > 0) )
|
---|
122 | {
|
---|
123 | crStrcpy( system_path, provided_system_path );
|
---|
124 | }
|
---|
125 | else
|
---|
126 | {
|
---|
127 | #if defined(WINDOWS)
|
---|
128 | GetSystemDirectory(system_path, MAX_PATH);
|
---|
129 | #elif defined(IRIX) || defined(IRIX64)
|
---|
130 | #ifdef IRIX_64BIT
|
---|
131 | crStrcpy( system_path, "/usr/lib64" );
|
---|
132 | #else
|
---|
133 | crStrcpy( system_path, "/usr/lib32" );
|
---|
134 | #endif
|
---|
135 | #elif defined(PLAYSTATION2)
|
---|
136 | crStrcpy( system_path, "/usr/X11R6/lib" );
|
---|
137 | #else
|
---|
138 | /* On RedHat 9, the correct default system directory
|
---|
139 | * is /usr/lib/tls/ (and if /usr/lib/ is used,
|
---|
140 | * the dynamic loader will generate a floating point
|
---|
141 | * exception SIGFPE). On other systems, including
|
---|
142 | * earlier versions of RedHat, the OpenGL library
|
---|
143 | * lives in /usr/lib. We'll use the /usr/lib/tls/
|
---|
144 | * version if it exists; otherwise, we'll use /usr/lib.
|
---|
145 | */
|
---|
146 | /*crStrcpy(system_path, "/usr/lib");*/
|
---|
147 | #if defined(__linux__) && defined(__amd64__)
|
---|
148 | /*if (sizeof(void *) == 8 && FileExists("/usr/lib64", lib)) {
|
---|
149 | crStrcat(system_path, "64");
|
---|
150 | }*/
|
---|
151 | #endif
|
---|
152 | /*if (FileExists("/usr/lib/tls", lib) ||
|
---|
153 | FileExists("/usr/lib64/tls", lib)) {
|
---|
154 | crStrcat(system_path, "/tls");
|
---|
155 | }*/
|
---|
156 | #endif
|
---|
157 | }
|
---|
158 | #if !defined(__linux__) && !defined(SunOS) && !defined(__FreeBSD__)
|
---|
159 | crStrcat( system_path, "/" );
|
---|
160 | #endif
|
---|
161 | #if !defined(CR_NO_GL_SYSTEM_PATH)
|
---|
162 | crStrcat( system_path, lib );
|
---|
163 | dll = crDLLOpen(system_path, 1 /*resolveGlobal*/);
|
---|
164 | #else
|
---|
165 | dll = crDLLOpen(lib, 1 /*resolveGlobal*/);
|
---|
166 | #endif
|
---|
167 | return dll;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | static CRDLL *
|
---|
172 | #ifdef DARWIN
|
---|
173 | __findSystemGL( const char *provided_system_path, const char *default_system_path, char *provided_lib_name )
|
---|
174 | #else
|
---|
175 | __findSystemGL( const char *provided_system_path )
|
---|
176 | #endif
|
---|
177 | {
|
---|
178 | #ifdef DARWIN
|
---|
179 | const char *the_path = (provided_system_path && crStrlen(provided_system_path) > 0) ? provided_system_path : default_system_path;
|
---|
180 |
|
---|
181 | /* Fallback for loading frameworks */
|
---|
182 | if( !provided_lib_name )
|
---|
183 | return crDLLOpen( the_path, 1 );
|
---|
184 | else
|
---|
185 | return __findSystemLib( the_path, provided_lib_name );
|
---|
186 | #else
|
---|
187 | return __findSystemLib( provided_system_path, SYSTEM_GL );
|
---|
188 | #endif
|
---|
189 | }
|
---|
190 |
|
---|
191 | static SPUGenericFunction
|
---|
192 | findExtFunction( const crOpenGLInterface *interface, const char *funcName )
|
---|
193 | {
|
---|
194 | #ifdef WINDOWS
|
---|
195 | if (interface->wglGetProcAddress)
|
---|
196 | return (SPUGenericFunction) interface->wglGetProcAddress( funcName );
|
---|
197 | else
|
---|
198 | return (SPUGenericFunction) NULL;
|
---|
199 | #else
|
---|
200 | /* XXX for some reason, the NVIDIA glXGetProcAddressARB() function
|
---|
201 | * returns pointers that cause Chromium to crash. If we use the
|
---|
202 | * pointer returned by crDLLGetNoError() instead, we're OK.
|
---|
203 | */
|
---|
204 | SPUGenericFunction f = crDLLGetNoError(glDll, funcName);
|
---|
205 | if (f)
|
---|
206 | return f;
|
---|
207 | #if !defined(DARWIN)
|
---|
208 | else if (interface->glXGetProcAddressARB)
|
---|
209 | return interface->glXGetProcAddressARB( (const GLubyte *) funcName );
|
---|
210 | #endif
|
---|
211 | else
|
---|
212 | return NULL;
|
---|
213 | #endif
|
---|
214 | }
|
---|
215 | """)
|
---|
216 |
|
---|
217 |
|
---|
218 | def IsExtensionFunc(func_name):
|
---|
219 | """Determine if the named function is a core function, or extension."""
|
---|
220 | cat = apiutil.Category(func_name)
|
---|
221 | if cat == "1.0" or cat == "1.1" or cat == "1.2" or cat == "1.3":
|
---|
222 | return 0
|
---|
223 | else:
|
---|
224 | return 1
|
---|
225 |
|
---|
226 | #
|
---|
227 | # Generate a no-op function.
|
---|
228 | #
|
---|
229 | def GenerateNop(func_name):
|
---|
230 | return_type = apiutil.ReturnType(func_name);
|
---|
231 | params = apiutil.Parameters(func_name)
|
---|
232 | print('static %s GLLOADER_APIENTRY Nop%s(%s)' % (return_type, func_name, apiutil.MakeDeclarationString(params)))
|
---|
233 | print('{')
|
---|
234 | for (name, type, vecSize) in params:
|
---|
235 | if name != "":
|
---|
236 | print('\t(void) %s;' % name)
|
---|
237 | if apiutil.ReturnType(func_name) != 'void':
|
---|
238 | print('\treturn 0;')
|
---|
239 | print('}')
|
---|
240 | print('')
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 | #
|
---|
245 | # Make no-op funcs for all OpenGL extension functions
|
---|
246 | #
|
---|
247 | for func_name in keys:
|
---|
248 | if IsExtensionFunc(func_name):
|
---|
249 | GenerateNop(func_name)
|
---|
250 |
|
---|
251 |
|
---|
252 | #
|
---|
253 | # Generate the crLoadOpenGL() function
|
---|
254 | #
|
---|
255 | print("""
|
---|
256 | void
|
---|
257 | crUnloadOpenGL( void )
|
---|
258 | {
|
---|
259 | crDLLClose( glDll );
|
---|
260 | glDll = NULL;
|
---|
261 |
|
---|
262 | #ifdef DARWIN
|
---|
263 | crDLLClose( cglDll );
|
---|
264 | cglDll = NULL;
|
---|
265 |
|
---|
266 | # ifndef VBOX_WITH_COCOA_QT
|
---|
267 | crDLLClose( aglDll );
|
---|
268 | aglDll = NULL;
|
---|
269 | # endif
|
---|
270 | #endif
|
---|
271 | }
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * Initialize the 'interface' structure with the WGL or GLX window system
|
---|
275 | * interface functions.
|
---|
276 | * Then, fill in the table with (name, pointer) pairs for all the core
|
---|
277 | * OpenGL entrypoint functions. But only if table is not NULL
|
---|
278 | * Return: number of entries placed in table[], or 0 if error.
|
---|
279 | */
|
---|
280 | int
|
---|
281 | crLoadOpenGL( crOpenGLInterface *interface, SPUNamedFunctionTable table[] )
|
---|
282 | {
|
---|
283 | static const char *coreFunctions[] = {
|
---|
284 | """)
|
---|
285 |
|
---|
286 | for func_name in keys:
|
---|
287 | if not IsExtensionFunc(func_name):
|
---|
288 | print('\t\t"gl%s",' % func_name)
|
---|
289 |
|
---|
290 | print("""
|
---|
291 | NULL
|
---|
292 | };
|
---|
293 | SPUNamedFunctionTable *entry = table;
|
---|
294 | int i;
|
---|
295 |
|
---|
296 | const char *env_syspath = crGetenv( "CR_SYSTEM_GL_PATH" );
|
---|
297 | #ifdef DARWIN
|
---|
298 | const char *env_cgl_syspath = crGetenv( "CR_SYSTEM_CGL_PATH" );
|
---|
299 | # ifndef VBOX_WITH_COCOA_QT
|
---|
300 | const char *env_agl_syspath = crGetenv( "CR_SYSTEM_AGL_PATH" );
|
---|
301 | # endif
|
---|
302 | #endif
|
---|
303 |
|
---|
304 | crDebug( "Looking for the system's OpenGL library..." );
|
---|
305 | #ifdef DARWIN
|
---|
306 | glDll = __findSystemGL( env_syspath, SYSTEM_GL_LIB_DIR, SYSTEM_GL );
|
---|
307 | #else
|
---|
308 | glDll = __findSystemGL( env_syspath );
|
---|
309 | #endif
|
---|
310 | if (!glDll)
|
---|
311 | {
|
---|
312 | crError("Unable to find system OpenGL!");
|
---|
313 | return 0;
|
---|
314 | }
|
---|
315 |
|
---|
316 | crDebug( "Found it in %s.", !env_syspath ? "default path" : env_syspath );
|
---|
317 |
|
---|
318 | #ifdef DARWIN
|
---|
319 | crDebug( "Looking for the system's CGL library..." );
|
---|
320 | cglDll = __findSystemGL( env_cgl_syspath, SYSTEM_CGL_DIR, SYSTEM_CGL );
|
---|
321 | if (!cglDll)
|
---|
322 | {
|
---|
323 | crError("Unable to find system CGL!");
|
---|
324 | return 0;
|
---|
325 | }
|
---|
326 |
|
---|
327 | crDebug( "Found it in %s.", !env_cgl_syspath ? "default path" : env_cgl_syspath );
|
---|
328 |
|
---|
329 | # ifndef VBOX_WITH_COCOA_QT
|
---|
330 | crDebug( "Looking for the system's AGL library..." );
|
---|
331 | aglDll = __findSystemGL( env_agl_syspath, SYSTEM_AGL_DIR, SYSTEM_AGL );
|
---|
332 | if (!aglDll)
|
---|
333 | {
|
---|
334 | crError("Unable to find system AGL!");
|
---|
335 | return 0;
|
---|
336 | }
|
---|
337 |
|
---|
338 | crDebug( "Found it in %s.", !env_agl_syspath ? "default path" : env_agl_syspath );
|
---|
339 | # endif
|
---|
340 | #endif
|
---|
341 | """)
|
---|
342 |
|
---|
343 | useful_wgl_functions = [
|
---|
344 | "wglGetProcAddress",
|
---|
345 | "wglMakeCurrent",
|
---|
346 | "wglSwapBuffers",
|
---|
347 | "wglCreateContext",
|
---|
348 | "wglDeleteContext",
|
---|
349 | "wglShareLists",
|
---|
350 | "wglGetCurrentContext",
|
---|
351 | "wglChoosePixelFormat",
|
---|
352 | "wglDescribePixelFormat",
|
---|
353 | "wglSetPixelFormat",
|
---|
354 | "wglChoosePixelFormatEXT",
|
---|
355 | "wglGetPixelFormatAttribivEXT",
|
---|
356 | "wglGetPixelFormatAttribfvEXT",
|
---|
357 | "glGetString"
|
---|
358 | ]
|
---|
359 | useful_agl_functions = [
|
---|
360 | "aglCreateContext",
|
---|
361 | "aglDestroyContext",
|
---|
362 | "aglSetCurrentContext",
|
---|
363 | "aglSwapBuffers",
|
---|
364 | "aglChoosePixelFormat",
|
---|
365 | "aglDestroyPixelFormat",
|
---|
366 | "aglDescribePixelFormat",
|
---|
367 | "aglGetCurrentContext",
|
---|
368 | "aglSetDrawable",
|
---|
369 | "aglGetDrawable",
|
---|
370 | "aglSetFullScreen",
|
---|
371 | "aglUpdateContext",
|
---|
372 | "aglUseFont",
|
---|
373 | "aglSetInteger",
|
---|
374 | "aglGetInteger",
|
---|
375 | "aglGetError",
|
---|
376 | "aglEnable",
|
---|
377 | "aglDisable"
|
---|
378 | ]
|
---|
379 | in_gl_functions = [
|
---|
380 | "CGLGetCurrentContext",
|
---|
381 | "CGLSetCurrentContext"
|
---|
382 | ]
|
---|
383 | useful_cgl_functions = [
|
---|
384 | "CGLChoosePixelFormat",
|
---|
385 | "CGLDestroyPixelFormat",
|
---|
386 | "CGLDescribePixelFormat",
|
---|
387 | "CGLQueryRendererInfo",
|
---|
388 | "CGLDestroyRendererInfo",
|
---|
389 | "CGLDescribeRenderer",
|
---|
390 | "CGLCreateContext",
|
---|
391 | "CGLDestroyContext",
|
---|
392 | "CGLCopyContext",
|
---|
393 | "CGLCreatePBuffer",
|
---|
394 | "CGLDestroyPBuffer",
|
---|
395 | "CGLDescribePBuffer",
|
---|
396 | "CGLTexImagePBuffer",
|
---|
397 | "CGLSetOffScreen",
|
---|
398 | "CGLGetOffScreen",
|
---|
399 | "CGLSetFullScreen",
|
---|
400 | "CGLSetPBuffer",
|
---|
401 | "CGLGetPBuffer",
|
---|
402 | "CGLClearDrawable",
|
---|
403 | "CGLFlushDrawable",
|
---|
404 | "CGLEnable",
|
---|
405 | "CGLDisable",
|
---|
406 | "CGLIsEnabled",
|
---|
407 | "CGLSetParameter",
|
---|
408 | "CGLGetParameter",
|
---|
409 | "CGLSetVirtualScreen",
|
---|
410 | "CGLGetVirtualScreen",
|
---|
411 | "CGLSetOption",
|
---|
412 | "CGLGetOption",
|
---|
413 | "CGLGetVersion",
|
---|
414 | "CGLErrorString",
|
---|
415 | "CGLSetSurface",
|
---|
416 | "CGLGetSurface",
|
---|
417 | "CGLUpdateContext",
|
---|
418 | "glGetString"
|
---|
419 | ]
|
---|
420 | useful_glx_functions = [
|
---|
421 | "glXGetConfig",
|
---|
422 | "glXQueryExtension",
|
---|
423 | "glXQueryVersion",
|
---|
424 | "glXQueryExtensionsString",
|
---|
425 | "glXChooseVisual",
|
---|
426 | "glXCreateContext",
|
---|
427 | "glXDestroyContext",
|
---|
428 | "glXUseXFont",
|
---|
429 | "glXIsDirect",
|
---|
430 | "glXMakeCurrent",
|
---|
431 | "glGetString",
|
---|
432 | "glXSwapBuffers",
|
---|
433 | "glXGetCurrentDisplay",
|
---|
434 | "glXGetCurrentContext",
|
---|
435 | "glXGetClientString",
|
---|
436 | "glXWaitGL",
|
---|
437 | "glXWaitX",
|
---|
438 | "glXCopyContext"
|
---|
439 | ]
|
---|
440 | possibly_useful_glx_functions = [
|
---|
441 | "glXGetProcAddressARB",
|
---|
442 | "glXJoinSwapGroupNV",
|
---|
443 | "glXBindSwapBarrierNV",
|
---|
444 | "glXQuerySwapGroupNV",
|
---|
445 | "glXQueryMaxSwapGroupsNV",
|
---|
446 | "glXQueryFrameCountNV",
|
---|
447 | "glXResetFrameCountNV",
|
---|
448 | "glXChooseFBConfig",
|
---|
449 | "glXGetFBConfigs",
|
---|
450 | "glXGetFBConfigAttrib",
|
---|
451 | "glXGetVisualFromFBConfig",
|
---|
452 | "glXCreateNewContext",
|
---|
453 | "glXCreatePbuffer",
|
---|
454 | "glXDestroyPbuffer",
|
---|
455 | "glXQueryContext",
|
---|
456 | "glXQueryDrawable",
|
---|
457 | "glXMakeContextCurrent",
|
---|
458 | "glXCreateWindow",
|
---|
459 | "glXGetVisualFromFBConfig",
|
---|
460 | ]
|
---|
461 |
|
---|
462 | print('#ifdef WINDOWS')
|
---|
463 |
|
---|
464 | for fun in useful_wgl_functions:
|
---|
465 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(glDll, "%s");' % (fun,fun,fun))
|
---|
466 |
|
---|
467 | print('#elif defined(DARWIN)')
|
---|
468 | print('# ifndef VBOX_WITH_COCOA_QT')
|
---|
469 | for fun in useful_agl_functions:
|
---|
470 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(aglDll, "%s");' % (fun,fun,fun))
|
---|
471 | print('# endif')
|
---|
472 |
|
---|
473 | for fun in useful_cgl_functions:
|
---|
474 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(cglDll, "%s");' % (fun, fun,fun))
|
---|
475 |
|
---|
476 | for fun in in_gl_functions:
|
---|
477 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(glDll, "%s");' % (fun, fun,fun))
|
---|
478 |
|
---|
479 | print('#else')
|
---|
480 | print('\t/* GLX */')
|
---|
481 |
|
---|
482 | # XXX merge these loops?
|
---|
483 | for fun in useful_glx_functions:
|
---|
484 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(glDll, "%s");' % (fun, fun, fun))
|
---|
485 | for fun in possibly_useful_glx_functions:
|
---|
486 | print('\tinterface->%s = (%sFunc_t) crDLLGetNoError(glDll, "%s");' % (fun, fun, fun))
|
---|
487 | print('#endif')
|
---|
488 |
|
---|
489 | print("""
|
---|
490 | if (!entry)
|
---|
491 | return 1; /* token value */
|
---|
492 |
|
---|
493 | for (i = 0; coreFunctions[i]; i++) {
|
---|
494 | const char *name = coreFunctions[i];
|
---|
495 | if (fillin(entry, name + 2, crDLLGetNoError(glDll, name)))
|
---|
496 | entry++;
|
---|
497 | else
|
---|
498 | crDebug("glLoader: NULL function %s", name);
|
---|
499 | }
|
---|
500 |
|
---|
501 | /* end of table markers */
|
---|
502 | entry->name = NULL;
|
---|
503 | entry->fn = NULL;
|
---|
504 | return entry - table; /* number of entries filled */
|
---|
505 | }
|
---|
506 |
|
---|
507 |
|
---|
508 | /*
|
---|
509 | * Fill in table[] with all the OpenGL extension functions that we're
|
---|
510 | * interested in.
|
---|
511 | */
|
---|
512 | int
|
---|
513 | crLoadOpenGLExtensions( const crOpenGLInterface *interface, SPUNamedFunctionTable table[] )
|
---|
514 | {
|
---|
515 | struct extfunc {
|
---|
516 | const char *funcName;""")
|
---|
517 | max_aliases = apiutil.ReverseAliasesMaxCount()
|
---|
518 | for i in range(1, 1 + max_aliases):
|
---|
519 | print("\t\tconst char *aliasName%d;" % i)
|
---|
520 | print(""" SPUGenericFunction nopFunction;
|
---|
521 | };
|
---|
522 | static const struct extfunc functions[] = {
|
---|
523 | """)
|
---|
524 |
|
---|
525 | for func_name in keys:
|
---|
526 | if IsExtensionFunc(func_name):
|
---|
527 | if apiutil.Category(func_name) == "Chromium":
|
---|
528 | prefix = "cr"
|
---|
529 | else:
|
---|
530 | prefix = "gl"
|
---|
531 | s = '\t\t{ "' + prefix + func_name + '"'
|
---|
532 | aliases = apiutil.ReverseAliases(func_name)
|
---|
533 | s += ''.join([', "' + prefix + a + '"' for a in aliases]) + ', NULL' * (max_aliases - len(aliases))
|
---|
534 | s += ', (SPUGenericFunction) Nop' + func_name + ' },'
|
---|
535 | print(s)
|
---|
536 |
|
---|
537 | print('\t\t{ NULL%s, NULL}' % (', NULL' * max_aliases))
|
---|
538 | print("""
|
---|
539 | };
|
---|
540 | const struct extfunc *func;
|
---|
541 | SPUNamedFunctionTable *entry = table;
|
---|
542 |
|
---|
543 | #ifdef WINDOWS
|
---|
544 | if (interface->wglGetProcAddress == NULL)
|
---|
545 | crWarning("Unable to find wglGetProcAddress() in system GL library");
|
---|
546 | #elif !defined(DARWIN)
|
---|
547 | if (interface->glXGetProcAddressARB == NULL)
|
---|
548 | crWarning("Unable to find glXGetProcAddressARB() in system GL library");
|
---|
549 | #endif
|
---|
550 |
|
---|
551 | for (func = functions; func->funcName; func++) {
|
---|
552 | SPUGenericFunction f = findExtFunction(interface, func->funcName);""")
|
---|
553 | for i in range(1, 1 + max_aliases):
|
---|
554 | print(""" if (!f && func->aliasName%d) {
|
---|
555 | f = findExtFunction(interface, func->aliasName%d);
|
---|
556 | }"""% (i, i))
|
---|
557 | print(""" if (!f) {
|
---|
558 | f = func->nopFunction;
|
---|
559 | }
|
---|
560 | (void) fillin(entry, func->funcName + 2 , f); /* +2 to skip "gl" */
|
---|
561 | entry++;
|
---|
562 | }
|
---|
563 |
|
---|
564 | /* end of list */
|
---|
565 | entry->name = NULL;
|
---|
566 | entry->fn = NULL;
|
---|
567 | return entry - table; /* number of entries filled */
|
---|
568 | }
|
---|
569 | """)
|
---|
570 |
|
---|
571 |
|
---|
572 | print("""
|
---|
573 |
|
---|
574 | #ifdef USE_OSMESA
|
---|
575 | int crLoadOSMesa( OSMesaContext (**createContext)( GLenum format, OSMesaContext sharelist ),
|
---|
576 | GLboolean (**makeCurrent)( OSMesaContext ctx, GLubyte *buffer,
|
---|
577 | GLenum type, GLsizei width, GLsizei height ),
|
---|
578 | void (**destroyContext)( OSMesaContext ctx ))
|
---|
579 | {
|
---|
580 | static CRDLL *osMesaDll = NULL;
|
---|
581 |
|
---|
582 | const char *env_syspath = crGetenv( "CR_SYSTEM_GL_PATH" );
|
---|
583 |
|
---|
584 | crDebug( "Looking for the system's OSMesa library..." );
|
---|
585 | osMesaDll = __findSystemLib( env_syspath, "libOSMesa.so" );
|
---|
586 | if (!osMesaDll)
|
---|
587 | {
|
---|
588 | crError("Unable to find system OSMesa!");
|
---|
589 | return 0;
|
---|
590 | }
|
---|
591 |
|
---|
592 | crDebug( "Found it in %s.", !env_syspath ? "default path" : env_syspath );
|
---|
593 |
|
---|
594 | *createContext = (OSMesaContext (*) ( GLenum format, OSMesaContext sharelist ))
|
---|
595 | crDLLGetNoError(osMesaDll, "OSMesaCreateContext");
|
---|
596 |
|
---|
597 | *makeCurrent = (GLboolean (*) ( OSMesaContext ctx, GLubyte *buffer,
|
---|
598 | GLenum type, GLsizei width, GLsizei height ))
|
---|
599 | crDLLGetNoError(osMesaDll, "OSMesaMakeCurrent");
|
---|
600 |
|
---|
601 | *destroyContext = (void (*) ( OSMesaContext ctx))
|
---|
602 | crDLLGetNoError(osMesaDll, "OSMesaDestroyContext");
|
---|
603 |
|
---|
604 | return 1;
|
---|
605 | }
|
---|
606 | #endif
|
---|
607 |
|
---|
608 | """)
|
---|
609 |
|
---|