VirtualBox

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

最後變更 在這個檔案從59454是 46660,由 vboxsync 提交於 11 年 前

crOpenGL: bugfix

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

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