Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

libGL.txt 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. Introduction
  2. ------------
  3. This document describes the implementation of the XFree86 4.0 libGL.so
  4. library defined by the Linux/OpenGL Base specification found at
  5. http://reality.sgi.com/opengl/linux/linuxbase.html.
  6. The documentation is divided into two sections:
  7. User's Guide
  8. Driver Developer's Guide
  9. Author: Brian Paul (brian@precisioninsight.com)
  10. Date: February 2000
  11. User's Guide
  12. ------------
  13. Using libGL.so
  14. The libGL.so library defines the gl- and glX-prefixed functions needed to
  15. run OpenGL programs. OpenGL client applications should link with the
  16. -lGL option to use it.
  17. libGL.so serves two primary functions: GLX protocol generation for indirect
  18. rendering and loading/management of hardware drivers for direct rendering.
  19. When libGL.so initializes itself it uses the DRI to determine the
  20. appropriate hardware driver for each screen on the local X display.
  21. The hardware drivers are expected to be in the /usr/X11R6/lib/modules/dri/
  22. directory. Drivers are named with the convention <name>_dri.so where
  23. <name> is a driver such as "tdfx", "i810", "gamma", etc.
  24. The LIBGL_DRIVERS_DIR environment variable may be used to specify a
  25. different DRI modules directory, overriding /usr/X11R6/lib/modules/dri/.
  26. This environment variable is ignored in setuid programs for security
  27. reasons.
  28. When libGL.so is unable to locate appropriate hardware drivers it will
  29. fall back to using indirect GLX rendering.
  30. To aid in solving problems, libGL.so will print diagnostic messages to
  31. stderr if the LIBGL_DEBUG environment variable is defined.
  32. libGL.so is thread safe. The overhead of thread safety for common,
  33. single-thread clients is negligible. However, the overhead of thread
  34. safety for multi-threaded clients is significant. Each GL API call
  35. requires two calls to pthread_get_specific() which can noticably
  36. impact performance. Warning: libGL.so is thread safe but individual
  37. DRI drivers may not be. Please consult the documentation for a driver
  38. to learn if it is thread safe.
  39. Indirect Rendering
  40. You can force indirect rendering mode by setting the LIBGL_ALWAYS_INDIRECT
  41. environment variable. Hardware acceleration will not be used.
  42. libGL.so Extensibility
  43. libGL.so is designed to be extended without upgrading. That is,
  44. drivers may install new OpenGL extension functions into libGL.so
  45. without requiring libGL.so to be replaced. Clients of libGL.so should
  46. use the glXGetProcAddressEXT() function to obtain the address of
  47. functions by name. For more details of GLX_ARB_get_proc_address see
  48. http://oss.sgi.com/projects/ogl-sample/registry/ARB/get_proc_address.spec
  49. libGL.so is also designed with flexibility such that it may be used
  50. with many generations of hardware drivers to come.
  51. Driver Developer's Guide
  52. ------------------------
  53. This section describes the requirements to make an XFree86 4.0
  54. libGL.so-compatible hardware driver. It is not intended for end
  55. users of libGL.so.
  56. XFree86 source files
  57. libGL.so is built inside XFree86 with sources found in xc/lib/GL/.
  58. Specifically, libGL.so is built from:
  59. xc/lib/GL/glx/*.c
  60. xc/lib/dri/XF86dri.c
  61. xc/lib/dri/dri_glx.c
  62. xc/lib/GL/mesa/src/glapi.c
  63. xc/lib/GL/mesa/src/glapitemp.h
  64. xc/lib/GL/mesa/src/glapitable.h
  65. xc/lib/GL/mesa/src/glapioffsets.h
  66. xc/lib/GL/mesa/src/glapinoop.c
  67. xc/lib/GL/mesa/src/glheader.h
  68. xc/lib/GL/mesa/src/glthread.c
  69. xc/lib/GL/mesa/src/glthread.h
  70. xc/lib/GL/mesa/src/X86/glapi_x86.S
  71. xc/lib/GL/mesa/src/X86/assyntax.h
  72. Understand that the mesa/src/gl*.[ch] files are not tied to Mesa. They
  73. have no dependencies on the rest of Mesa and are designed to be reusable
  74. in a number of projects.
  75. The glapi_x86.X and assyntax.h files implement x86-optimized dispatch
  76. of GL functions. They are not required; C-based dispatch can be used
  77. instead, with a slight performance penalty.
  78. Driver loading and binding
  79. When libGL.so initializes itself (via the __glXInitialize function) a
  80. call is made to driCreateDisplay(). This function uses DRI facilities
  81. to determine the driver file appropriate for each screen on the local
  82. display. Each screen's driver is then opened with dlopen() and asked
  83. for its __driCreateScreen() function. The pointers to the __driCreateScreen()
  84. functions are kept in an array, indexed by screen number, in the
  85. __DRIdisplayRec struct.
  86. When a driver's __driCreateScreen() function is called, it must initialize
  87. a __DRIscreenRec struct. This struct acts as the root of a tree of
  88. function pointers which are called to create and destroy contexts and
  89. drawables and perform all the operations needed by the GLX interface.
  90. See the xc/lib/GL/glx/glxclient.h file for details.
  91. Dynamic Extension Function Registration
  92. In order to provide forward compatibility with future drivers, libGL.so
  93. allows drivers to register new OpenGL extension functions which weren't
  94. known when libGL.so was built.
  95. The register_extensions() function in xc/lib/GL/dri/dri_glx.c is called
  96. as soon as libGL.so is loaded. This is done with gcc's constructor
  97. attribute. This mechanism will likely have to be changed for other compilers.
  98. register_extensions() loops over all local displays and screens, determines
  99. the DRI driver for each, and calls the driver's __driRegisterExtensions()
  100. function, if present.
  101. The __driRegisterExtensions() function can add new entrypoints to libGL
  102. by calling:
  103. GLboolean _glapi_add_entrypoint(const char *funcName, GLuint offset)
  104. The parameters are the name of the function (such as "glFoobarEXT") and the
  105. offset of the dispatch slot in the API dispatch table. The return value
  106. indicates success (GL_TRUE) or failure (GL_FALSE).
  107. _glapi_add_entrypoint() will synthesize entrypoint code in assembly
  108. language. Assembly languages is required since parameter passing
  109. can't be handled correctly using a C-based solution.
  110. The address of the new entrypoint is obtained by calling the
  111. glXGetProcAddressARB() function.
  112. The dispatch offset number MUST be a number allocated by SGI in the same
  113. manner in which new GL_* constants are allocated. Using an arbitrary
  114. offset number will result in many problems.
  115. Dispatch Management
  116. When a GL context is made current, the driver must install its dispatch
  117. table as the current dispatch table. This is done by calling
  118. void _glapi_set_dispatch(struct _glapi_table *dispatch);
  119. This will install the named dispatch table for the calling thread.
  120. The current dispatch table for a thread can be obtained by calling
  121. struct _glapi_table *_glapi_get_dispatch(void);
  122. For higher performance in the common single-thread case, the global
  123. variable _glapi_Dispatch will point to the current dispatch table.
  124. This variable will be NULL when in multi-thread mode.
  125. Context Management
  126. libGL.so uses the XFree86 xthreads package to manage a thread-specific
  127. current context pointer. See __glXGet/SetCurrentContext() in glext.c
  128. Drivers may use the _glapi_set/get_context() functions to maintain
  129. a private thread-specific context pointer.