1*61046927SAndroid Build Coastguard Worker 2*61046927SAndroid Build Coastguard Worker 3*61046927SAndroid Build Coastguard Worker 4*61046927SAndroid Build Coastguard WorkerIntroduction 5*61046927SAndroid Build Coastguard Worker------------ 6*61046927SAndroid Build Coastguard Worker 7*61046927SAndroid Build Coastguard WorkerThis document describes the implementation of the XFree86 4.0 libGL.so 8*61046927SAndroid Build Coastguard Workerlibrary defined by the Linux/OpenGL Base specification found at 9*61046927SAndroid Build Coastguard Workerhttp://reality.sgi.com/opengl/linux/linuxbase.html. 10*61046927SAndroid Build Coastguard Worker 11*61046927SAndroid Build Coastguard WorkerThe documentation is divided into two sections: 12*61046927SAndroid Build Coastguard Worker User's Guide 13*61046927SAndroid Build Coastguard Worker Driver Developer's Guide 14*61046927SAndroid Build Coastguard Worker 15*61046927SAndroid Build Coastguard WorkerAuthor: Brian Paul ([email protected]) 16*61046927SAndroid Build Coastguard WorkerDate: February 2000 17*61046927SAndroid Build Coastguard Worker 18*61046927SAndroid Build Coastguard Worker 19*61046927SAndroid Build Coastguard Worker 20*61046927SAndroid Build Coastguard WorkerUser's Guide 21*61046927SAndroid Build Coastguard Worker------------ 22*61046927SAndroid Build Coastguard Worker 23*61046927SAndroid Build Coastguard WorkerUsing libGL.so 24*61046927SAndroid Build Coastguard Worker 25*61046927SAndroid Build Coastguard WorkerThe libGL.so library defines the gl- and glX-prefixed functions needed to 26*61046927SAndroid Build Coastguard Workerrun OpenGL programs. OpenGL client applications should link with the 27*61046927SAndroid Build Coastguard Worker-lGL option to use it. 28*61046927SAndroid Build Coastguard Worker 29*61046927SAndroid Build Coastguard WorkerlibGL.so serves two primary functions: GLX protocol generation for indirect 30*61046927SAndroid Build Coastguard Workerrendering and loading/management of hardware drivers for direct rendering. 31*61046927SAndroid Build Coastguard Worker 32*61046927SAndroid Build Coastguard WorkerWhen libGL.so initializes itself it uses the DRI to determine the 33*61046927SAndroid Build Coastguard Workerappropriate hardware driver for each screen on the local X display. 34*61046927SAndroid Build Coastguard WorkerThe hardware drivers are expected to be in the /usr/X11R6/lib/modules/dri/ 35*61046927SAndroid Build Coastguard Workerdirectory. Drivers are named with the convention <name>_dri.so where 36*61046927SAndroid Build Coastguard Worker<name> is a driver such as "radeon", "i965", "nouveau", etc. 37*61046927SAndroid Build Coastguard Worker 38*61046927SAndroid Build Coastguard WorkerThe LIBGL_DRIVERS_DIR environment variable may be used to specify a 39*61046927SAndroid Build Coastguard Workerdifferent DRI modules directory, overriding /usr/X11R6/lib/modules/dri/. 40*61046927SAndroid Build Coastguard WorkerThis environment variable is ignored in setuid programs for security 41*61046927SAndroid Build Coastguard Workerreasons. 42*61046927SAndroid Build Coastguard Worker 43*61046927SAndroid Build Coastguard WorkerWhen libGL.so is unable to locate appropriate hardware drivers it will 44*61046927SAndroid Build Coastguard Workerfall back to using indirect GLX rendering. 45*61046927SAndroid Build Coastguard Worker 46*61046927SAndroid Build Coastguard WorkerTo aid in solving problems, libGL.so will print diagnostic messages to 47*61046927SAndroid Build Coastguard Workerstderr if the LIBGL_DEBUG environment variable is defined. 48*61046927SAndroid Build Coastguard Worker 49*61046927SAndroid Build Coastguard WorkerlibGL.so is thread safe. The overhead of thread safety for common, 50*61046927SAndroid Build Coastguard Workersingle-thread clients is negligible. However, the overhead of thread 51*61046927SAndroid Build Coastguard Workersafety for multi-threaded clients is significant. Each GL API call 52*61046927SAndroid Build Coastguard Workerrequires two calls to pthread_get_specific() which can noticeably 53*61046927SAndroid Build Coastguard Workerimpact performance. Warning: libGL.so is thread safe but individual 54*61046927SAndroid Build Coastguard WorkerDRI drivers may not be. Please consult the documentation for a driver 55*61046927SAndroid Build Coastguard Workerto learn if it is thread safe. 56*61046927SAndroid Build Coastguard Worker 57*61046927SAndroid Build Coastguard Worker 58*61046927SAndroid Build Coastguard Worker 59*61046927SAndroid Build Coastguard WorkerIndirect Rendering 60*61046927SAndroid Build Coastguard Worker 61*61046927SAndroid Build Coastguard WorkerYou can force indirect rendering mode by setting the LIBGL_ALWAYS_INDIRECT 62*61046927SAndroid Build Coastguard Workerenvironment variable to `true`. Hardware acceleration will not be used. 63*61046927SAndroid Build Coastguard Worker 64*61046927SAndroid Build Coastguard Worker 65*61046927SAndroid Build Coastguard Worker 66*61046927SAndroid Build Coastguard WorkerlibGL.so Extensibility 67*61046927SAndroid Build Coastguard Worker 68*61046927SAndroid Build Coastguard WorkerlibGL.so is designed to be extended without upgrading. That is, 69*61046927SAndroid Build Coastguard Workerdrivers may install new OpenGL extension functions into libGL.so 70*61046927SAndroid Build Coastguard Workerwithout requiring libGL.so to be replaced. Clients of libGL.so should 71*61046927SAndroid Build Coastguard Workeruse the glXGetProcAddressEXT() function to obtain the address of 72*61046927SAndroid Build Coastguard Workerfunctions by name. For more details of GLX_ARB_get_proc_address see 73*61046927SAndroid Build Coastguard Workerhttp://oss.sgi.com/projects/ogl-sample/registry/ARB/get_proc_address.spec 74*61046927SAndroid Build Coastguard Worker 75*61046927SAndroid Build Coastguard WorkerlibGL.so is also designed with flexibility such that it may be used 76*61046927SAndroid Build Coastguard Workerwith many generations of hardware drivers to come. 77*61046927SAndroid Build Coastguard Worker 78*61046927SAndroid Build Coastguard Worker 79*61046927SAndroid Build Coastguard Worker 80*61046927SAndroid Build Coastguard Worker 81*61046927SAndroid Build Coastguard WorkerDriver Developer's Guide 82*61046927SAndroid Build Coastguard Worker------------------------ 83*61046927SAndroid Build Coastguard Worker 84*61046927SAndroid Build Coastguard WorkerThis section describes the requirements to make an XFree86 4.0 85*61046927SAndroid Build Coastguard WorkerlibGL.so-compatible hardware driver. It is not intended for end 86*61046927SAndroid Build Coastguard Workerusers of libGL.so. 87*61046927SAndroid Build Coastguard Worker 88*61046927SAndroid Build Coastguard WorkerThe gl_x86_asm.py and assyntax.h files implement x86-optimized dispatch 89*61046927SAndroid Build Coastguard Workerof GL functions. They are not required; C-based dispatch can be used 90*61046927SAndroid Build Coastguard Workerinstead, with a slight performance penalty. 91*61046927SAndroid Build Coastguard Worker 92*61046927SAndroid Build Coastguard Worker 93*61046927SAndroid Build Coastguard Worker 94*61046927SAndroid Build Coastguard WorkerDriver loading and binding 95*61046927SAndroid Build Coastguard Worker 96*61046927SAndroid Build Coastguard WorkerWhen libGL.so initializes itself (via the __glXInitialize function) a 97*61046927SAndroid Build Coastguard Workercall is made to driCreateDisplay(). This function uses DRI facilities 98*61046927SAndroid Build Coastguard Workerto determine the driver file appropriate for each screen on the local 99*61046927SAndroid Build Coastguard Workerdisplay. Each screen's driver is then opened with dlopen() and asked 100*61046927SAndroid Build Coastguard Workerfor its __driCreateScreen() function. The pointers to the __driCreateScreen() 101*61046927SAndroid Build Coastguard Workerfunctions are kept in an array, indexed by screen number, in the 102*61046927SAndroid Build Coastguard Worker__DRIdisplayRec struct. 103*61046927SAndroid Build Coastguard Worker 104*61046927SAndroid Build Coastguard WorkerWhen a driver's __driCreateScreen() function is called, it must initialize 105*61046927SAndroid Build Coastguard Workera __DRIscreenRec struct. This struct acts as the root of a tree of 106*61046927SAndroid Build Coastguard Workerfunction pointers which are called to create and destroy contexts and 107*61046927SAndroid Build Coastguard Workerdrawables and perform all the operations needed by the GLX interface. 108*61046927SAndroid Build Coastguard WorkerSee the xc/lib/GL/glx/glxclient.h file for details. 109*61046927SAndroid Build Coastguard Worker 110*61046927SAndroid Build Coastguard Worker 111*61046927SAndroid Build Coastguard Worker 112*61046927SAndroid Build Coastguard WorkerDynamic Extension Function Registration 113*61046927SAndroid Build Coastguard Worker 114*61046927SAndroid Build Coastguard WorkerIn order to provide forward compatibility with future drivers, libGL.so 115*61046927SAndroid Build Coastguard Workerallows drivers to register new OpenGL extension functions which weren't 116*61046927SAndroid Build Coastguard Workerknown when libGL.so was built. 117*61046927SAndroid Build Coastguard Worker 118*61046927SAndroid Build Coastguard WorkerThe register_extensions() function in xc/lib/GL/dri/dri_glx.c is called 119*61046927SAndroid Build Coastguard Workeras soon as libGL.so is loaded. This is done with gcc's constructor 120*61046927SAndroid Build Coastguard Workerattribute. This mechanism will likely have to be changed for other compilers. 121*61046927SAndroid Build Coastguard Worker 122*61046927SAndroid Build Coastguard Workerregister_extensions() loops over all local displays and screens, determines 123*61046927SAndroid Build Coastguard Workerthe DRI driver for each, and calls the driver's __driRegisterExtensions() 124*61046927SAndroid Build Coastguard Workerfunction, if present. 125*61046927SAndroid Build Coastguard Worker 126*61046927SAndroid Build Coastguard WorkerThe __driRegisterExtensions() function can add new entrypoints to libGL 127*61046927SAndroid Build Coastguard Workerby calling: 128*61046927SAndroid Build Coastguard Worker 129*61046927SAndroid Build Coastguard Worker GLboolean _glapi_add_entrypoint(const char *funcName, GLuint offset) 130*61046927SAndroid Build Coastguard Worker 131*61046927SAndroid Build Coastguard WorkerThe parameters are the name of the function (such as "glFoobarEXT") and the 132*61046927SAndroid Build Coastguard Workeroffset of the dispatch slot in the API dispatch table. The return value 133*61046927SAndroid Build Coastguard Workerindicates success (GL_TRUE) or failure (GL_FALSE). 134*61046927SAndroid Build Coastguard Worker 135*61046927SAndroid Build Coastguard Worker_glapi_add_entrypoint() will synthesize entrypoint code in assembly 136*61046927SAndroid Build Coastguard Workerlanguage. Assembly languages is required since parameter passing 137*61046927SAndroid Build Coastguard Workercan't be handled correctly using a C-based solution. 138*61046927SAndroid Build Coastguard Worker 139*61046927SAndroid Build Coastguard WorkerThe address of the new entrypoint is obtained by calling the 140*61046927SAndroid Build Coastguard WorkerglXGetProcAddressARB() function. 141*61046927SAndroid Build Coastguard Worker 142*61046927SAndroid Build Coastguard WorkerThe dispatch offset number MUST be a number allocated by SGI in the same 143*61046927SAndroid Build Coastguard Workermanner in which new GL_* constants are allocated. Using an arbitrary 144*61046927SAndroid Build Coastguard Workeroffset number will result in many problems. 145*61046927SAndroid Build Coastguard Worker 146*61046927SAndroid Build Coastguard Worker 147*61046927SAndroid Build Coastguard Worker 148*61046927SAndroid Build Coastguard WorkerDispatch Management 149*61046927SAndroid Build Coastguard Worker 150*61046927SAndroid Build Coastguard WorkerWhen a GL context is made current, the driver must install its dispatch 151*61046927SAndroid Build Coastguard Workertable as the current dispatch table. This is done by calling 152*61046927SAndroid Build Coastguard Worker 153*61046927SAndroid Build Coastguard Worker void _glapi_set_dispatch(struct _glapi_table *dispatch); 154*61046927SAndroid Build Coastguard Worker 155*61046927SAndroid Build Coastguard WorkerThis will install the named dispatch table for the calling thread. 156*61046927SAndroid Build Coastguard WorkerThe current dispatch table for a thread can be obtained by calling 157*61046927SAndroid Build Coastguard Worker 158*61046927SAndroid Build Coastguard Worker struct _glapi_table *_glapi_get_dispatch(void); 159*61046927SAndroid Build Coastguard Worker 160*61046927SAndroid Build Coastguard WorkerFor higher performance in the common single-thread case, the global 161*61046927SAndroid Build Coastguard Workervariable _glapi_Dispatch will point to the current dispatch table. 162*61046927SAndroid Build Coastguard WorkerThis variable will be NULL when in multi-thread mode. 163*61046927SAndroid Build Coastguard Worker 164*61046927SAndroid Build Coastguard Worker 165*61046927SAndroid Build Coastguard Worker 166*61046927SAndroid Build Coastguard WorkerContext Management 167*61046927SAndroid Build Coastguard Worker 168*61046927SAndroid Build Coastguard WorkerlibGL.so uses the XFree86 xthreads package to manage a thread-specific 169*61046927SAndroid Build Coastguard Workercurrent context pointer. See __glXGet/SetCurrentContext() in glext.c 170*61046927SAndroid Build Coastguard Worker 171*61046927SAndroid Build Coastguard WorkerDrivers may use the _glapi_set/get_context() functions to maintain 172*61046927SAndroid Build Coastguard Workera private thread-specific context pointer. 173*61046927SAndroid Build Coastguard Worker 174