VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/spu_loader/glloader.py@ 18051

最後變更 在這個檔案從18051是 15532,由 vboxsync 提交於 16 年 前

crOpenGL: export to OSE

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette