advanced.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <h2>Automatic Code Generation</h2>
  2. <p>
  3. Starting from release 1.1.0, the source code and parts of the
  4. documentation are automatically generated from the extension
  5. specifications in a two-step process. In the first step,
  6. specification files from the OpenGL registry are downloaded and
  7. parsed. Skeleton descriptors are created for each extension. These
  8. descriptors contain all necessary information for creating the source
  9. code and documentation in a simple and compact format, including the
  10. name of the extension, url link to the specification, tokens, function
  11. declarations, typedefs and struct definitions. In the second step,
  12. the header files as well as the library and glewinfo source are
  13. generated from the descriptor files. The code generation scripts are
  14. located in the <tt>auto</tt> subdirectory.
  15. </p>
  16. <p>
  17. The code generation scripts require GNU make, wget, and perl. On
  18. Windows, the simplest way to get access to these tools is to install
  19. <a href="http://www.cygwin.com/">Cygwin</a>, but make sure that the
  20. root directory is mounted in binary mode. The makefile in the
  21. <tt>auto</tt> directory provides the following build targets:
  22. </p>
  23. <table border=0 cellpadding=0 cellspacing=5>
  24. <tr><td align="left" valign="top"><tt>make</tt></td>
  25. <td align=left>Create the source files from the descriptors.<br/> If the
  26. descriptors do not exist, create them from the spec files.<br/> If the spec
  27. files do not exist, download them from the OpenGL repository.</td></tr>
  28. <tr><td align="left" valign="top"><tt>make&nbsp;clean</tt></td>
  29. <td align=left>Delete the source files.</td></tr>
  30. <tr><td align="left" valign="top"><tt>make&nbsp;clobber</tt></td>
  31. <td align=left>Delete the source files and the descriptors.</td></tr>
  32. <tr><td align="left" valign="top"><tt>make&nbsp;destroy</tt></td>
  33. <td align=left>Delete the source files, the descriptors, and the spec files.</td></tr>
  34. <tr><td align="left" valign="top"><tt>make&nbsp;custom</tt></td>
  35. <td align=left>Create the source files for the extensions
  36. listed in <tt>auto/custom.txt</tt>.<br/> See "Custom Code
  37. Generation" below for more details.</td></tr>
  38. </table>
  39. <h3>Adding a New Extension</h3>
  40. <p>
  41. To add a new extension, create a descriptor file for the extension in
  42. <tt>auto/core</tt> and rerun the code generation scripts by typing
  43. <tt>make clean; make</tt> in the <tt>auto</tt> directory.
  44. </p>
  45. <p>
  46. The format of the descriptor file is given below. Items in
  47. brackets are optional.
  48. </p>
  49. <p class="pre">
  50. &lt;Extension Name&gt;<br>
  51. [&lt;URL of Specification File&gt;]<br>
  52. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Token Name&gt; &lt;Token Value&gt;]<br>
  53. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Token Name&gt; &lt;Token Value&gt;]<br>
  54. &nbsp;&nbsp;&nbsp;&nbsp;...<br>
  55. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Typedef&gt;]<br>
  56. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Typedef&gt;]<br>
  57. &nbsp;&nbsp;&nbsp;&nbsp;...<br>
  58. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Function Signature&gt;]<br>
  59. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Function Signature&gt;]<br>
  60. &nbsp;&nbsp;&nbsp;&nbsp;...<br>
  61. <!-- &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Function Definition&gt;]<br>
  62. &nbsp;&nbsp;&nbsp;&nbsp;[&lt;Function Definition&gt;]<br>
  63. &nbsp;&nbsp;&nbsp;&nbsp;...<br> -->
  64. </p>
  65. <!--
  66. <p>
  67. Note that <tt>Function Definitions</tt> are copied to the header files
  68. without changes and have to be terminated with a semicolon. In
  69. contrast, <tt>Tokens</tt>, <tt>Function signatures</tt>, and
  70. <tt>Typedefs</tt> should not be terminated with a semicolon.
  71. </p>
  72. -->
  73. <p>
  74. Take a look at one of the files in <tt>auto/core</tt> for an
  75. example. Note that typedefs and function signatures should not be
  76. terminated with a semicolon.
  77. </p>
  78. <h3>Custom Code Generation</h3>
  79. <p>
  80. Starting from GLEW 1.3.0, it is possible to control which extensions
  81. to include in the libarary by specifying a list in
  82. <tt>auto/custom.txt</tt>. This is useful when you do not need all the
  83. extensions and would like to reduce the size of the source files.
  84. Type <tt>make clean; make custom</tt> in the <tt>auto</tt> directory
  85. to rerun the scripts with the custom list of extensions.
  86. </p>
  87. <p>
  88. For example, the following is the list of extensions needed to get GLEW and the
  89. utilities to compile.
  90. </p>
  91. <p class="pre">
  92. WGL_ARB_extensions_string<br>
  93. WGL_ARB_multisample<br>
  94. WGL_ARB_pixel_format<br>
  95. WGL_ARB_pbuffer<br>
  96. WGL_EXT_extensions_string<br>
  97. WGL_ATI_pixel_format_float<br>
  98. WGL_NV_float_buffer<br>
  99. </p>
  100. <h2>Multiple Rendering Contexts (GLEW MX)</h2>
  101. <p>Starting with release 1.2.0, thread-safe support for multiple
  102. rendering contexts, possibly with different capabilities, is
  103. available. Since this is not required by most users, it is not added
  104. to the binary releases to maintain compatibility between different
  105. versions. To include multi-context support, you have to do the
  106. following:</p>
  107. <ol>
  108. <li>Compile and use GLEW with the <tt>GLEW_MX</tt> preprocessor token
  109. defined.</li>
  110. <li>For each rendering context, create a <tt>GLEWContext</tt> object
  111. that will be available as long as the rendering context exists.</li>
  112. <li>Define a macro or function called <tt>glewGetContext()</tt> that
  113. returns a pointer to the <tt>GLEWContext</tt> object associated with
  114. the rendering context from which OpenGL/WGL/GLX calls are issued. This
  115. dispatch mechanism is primitive, but generic.
  116. <li>Make sure that you call <tt>glewInit()</tt> after creating the
  117. <tt>GLEWContext</tt> object in each rendering context. Note, that the
  118. <tt>GLEWContext</tt> pointer returned by <tt>glewGetContext()</tt> has
  119. to reside in global or thread-local memory.
  120. </ol>
  121. <p>Note that according to the <a
  122. href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/ntopnglr_6yer.asp">MSDN
  123. WGL documentation</a>, you have to initialize the entry points for
  124. every rendering context that use pixel formats with different
  125. capabilities For example, the pixel formats provided by the generic
  126. software OpenGL implementation by Microsoft vs. the hardware
  127. accelerated pixel formats have different capabilities. <b>GLEW by
  128. default ignores this requirement, and does not define per-context
  129. entry points (you can however do this using the steps described
  130. above).</b> Assuming a global namespace for the entry points works in
  131. most situations, because typically all hardware accelerated pixel
  132. formats provide the same entry points and capabilities. This means
  133. that unless you use the multi-context version of GLEW, you need to
  134. call <tt>glewInit()</tt> only once in your program, or more precisely,
  135. once per process.</p>
  136. <h2>Separate Namespace</h2>
  137. <p>
  138. To avoid name clashes when linking with libraries that include the
  139. same symbols, extension entry points are declared in a separate
  140. namespace (release 1.1.0 and up). This is achieved by aliasing OpenGL
  141. function names to their GLEW equivalents. For instance,
  142. <tt>glFancyFunction</tt> is simply an alias to
  143. <tt>glewFancyFunction</tt>. The separate namespace does not effect
  144. token and function pointer definitions.
  145. </p>
  146. <h2>Known Issues</h2>
  147. <p>
  148. GLEW requires GLX 1.2 for compatibility with GLUT.
  149. </p>