glx.pp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. {
  2. Translation of the Mesa GLX headers for FreePascal
  3. Copyright (C) 1999 Sebastian Guenther
  4. Mesa 3-D graphics library
  5. Version: 3.0
  6. Copyright (C) 1995-1998 Brian Paul
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public
  9. License as published by the Free Software Foundation; either
  10. version 2 of the License, or (at your option) any later version.
  11. This library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free
  17. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. }
  19. {$MODE delphi} // objfpc would not work because of direct proc var assignments
  20. {You have to enable Macros (compiler switch "-Sm") for compiling this unit!
  21. This is necessary for supporting different platforms with different calling
  22. conventions via a single unit.}
  23. unit GLX;
  24. interface
  25. {$MACRO ON}
  26. {$IFDEF Unix}
  27. uses
  28. X, XLib, XUtil;
  29. {$DEFINE HasGLX} // Activate GLX stuff
  30. {$ELSE}
  31. {$MESSAGE Unsupported platform.}
  32. {$ENDIF}
  33. {$IFNDEF HasGLX}
  34. {$MESSAGE GLX not present on this platform.}
  35. {$ENDIF}
  36. // =======================================================
  37. // Unit specific extensions
  38. // =======================================================
  39. // Note: Requires that the GL library has already been initialized
  40. function InitGLX: Boolean;
  41. var
  42. GLXDumpUnresolvedFunctions,
  43. GLXInitialized: Boolean;
  44. // =======================================================
  45. // GLX consts, types and functions
  46. // =======================================================
  47. // Tokens for glXChooseVisual and glXGetConfig:
  48. const
  49. GLX_USE_GL = 1;
  50. GLX_BUFFER_SIZE = 2;
  51. GLX_LEVEL = 3;
  52. GLX_RGBA = 4;
  53. GLX_DOUBLEBUFFER = 5;
  54. GLX_STEREO = 6;
  55. GLX_AUX_BUFFERS = 7;
  56. GLX_RED_SIZE = 8;
  57. GLX_GREEN_SIZE = 9;
  58. GLX_BLUE_SIZE = 10;
  59. GLX_ALPHA_SIZE = 11;
  60. GLX_DEPTH_SIZE = 12;
  61. GLX_STENCIL_SIZE = 13;
  62. GLX_ACCUM_RED_SIZE = 14;
  63. GLX_ACCUM_GREEN_SIZE = 15;
  64. GLX_ACCUM_BLUE_SIZE = 16;
  65. GLX_ACCUM_ALPHA_SIZE = 17;
  66. // GLX_EXT_visual_info extension
  67. GLX_X_VISUAL_TYPE_EXT = $22;
  68. GLX_TRANSPARENT_TYPE_EXT = $23;
  69. GLX_TRANSPARENT_INDEX_VALUE_EXT = $24;
  70. GLX_TRANSPARENT_RED_VALUE_EXT = $25;
  71. GLX_TRANSPARENT_GREEN_VALUE_EXT = $26;
  72. GLX_TRANSPARENT_BLUE_VALUE_EXT = $27;
  73. GLX_TRANSPARENT_ALPHA_VALUE_EXT = $28;
  74. // Error codes returned by glXGetConfig:
  75. GLX_BAD_SCREEN = 1;
  76. GLX_BAD_ATTRIBUTE = 2;
  77. GLX_NO_EXTENSION = 3;
  78. GLX_BAD_VISUAL = 4;
  79. GLX_BAD_CONTEXT = 5;
  80. GLX_BAD_VALUE = 6;
  81. GLX_BAD_ENUM = 7;
  82. // GLX 1.1 and later:
  83. GLX_VENDOR = 1;
  84. GLX_VERSION = 2;
  85. GLX_EXTENSIONS = 3;
  86. // GLX_visual_info extension
  87. GLX_TRUE_COLOR_EXT = $8002;
  88. GLX_DIRECT_COLOR_EXT = $8003;
  89. GLX_PSEUDO_COLOR_EXT = $8004;
  90. GLX_STATIC_COLOR_EXT = $8005;
  91. GLX_GRAY_SCALE_EXT = $8006;
  92. GLX_STATIC_GRAY_EXT = $8007;
  93. GLX_NONE_EXT = $8000;
  94. GLX_TRANSPARENT_RGB_EXT = $8008;
  95. GLX_TRANSPARENT_INDEX_EXT = $8009;
  96. type
  97. // From XLib:
  98. XPixmap = TXID;
  99. XFont = TXID;
  100. XColormap = TXID;
  101. GLXContext = Pointer;
  102. GLXPixmap = TXID;
  103. GLXDrawable = TXID;
  104. GLXContextID = TXID;
  105. TXPixmap = XPixmap;
  106. TXFont = XFont;
  107. TXColormap = XColormap;
  108. TGLXContext = GLXContext;
  109. TGLXPixmap = GLXPixmap;
  110. TGLXDrawable = GLXDrawable;
  111. TGLXContextID = GLXContextID;
  112. var
  113. glXChooseVisual: function(dpy: PDisplay; screen: Integer; attribList: PInteger): PXVisualInfo; cdecl;
  114. glXCreateContext: function(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: Boolean): GLXContext; cdecl;
  115. glXDestroyContext: procedure(dpy: PDisplay; ctx: GLXContext); cdecl;
  116. glXMakeCurrent: function(dpy: PDisplay; drawable: GLXDrawable; ctx: GLXContext): Boolean; cdecl;
  117. glXCopyContext: procedure(dpy: PDisplay; src, dst: GLXContext; mask: LongWord); cdecl;
  118. glXSwapBuffers: procedure(dpy: PDisplay; drawable: GLXDrawable); cdecl;
  119. glXCreateGLXPixmap: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap): GLXPixmap; cdecl;
  120. glXDestroyGLXPixmap: procedure(dpy: PDisplay; pixmap: GLXPixmap); cdecl;
  121. glXQueryExtension: function(dpy: PDisplay; var errorb, event: Integer): Boolean; cdecl;
  122. glXQueryVersion: function(dpy: PDisplay; var maj, min: Integer): Boolean; cdecl;
  123. glXIsDirect: function(dpy: PDisplay; ctx: GLXContext): Boolean; cdecl;
  124. glXGetConfig: function(dpy: PDisplay; visual: PXVisualInfo; attrib: Integer; var value: Integer): Integer; cdecl;
  125. glXGetCurrentContext: function: GLXContext; cdecl;
  126. glXGetCurrentDrawable: function: GLXDrawable; cdecl;
  127. glXWaitGL: procedure; cdecl;
  128. glXWaitX: procedure; cdecl;
  129. glXUseXFont: procedure(font: XFont; first, count, list: Integer); cdecl;
  130. // GLX 1.1 and later
  131. glXQueryExtensionsString: function(dpy: PDisplay; screen: Integer): PChar; cdecl;
  132. glXQueryServerString: function(dpy: PDisplay; screen, name: Integer): PChar; cdecl;
  133. glXGetClientString: function(dpy: PDisplay; name: Integer): PChar; cdecl;
  134. // Mesa GLX Extensions
  135. glXCreateGLXPixmapMESA: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap; cmap: XColormap): GLXPixmap; cdecl;
  136. glXReleaseBufferMESA: function(dpy: PDisplay; d: GLXDrawable): Boolean; cdecl;
  137. glXCopySubBufferMESA: procedure(dpy: PDisplay; drawbale: GLXDrawable; x, y, width, height: Integer); cdecl;
  138. glXGetVideoSyncSGI: function(var counter: LongWord): Integer; cdecl;
  139. glXWaitVideoSyncSGI: function(divisor, remainder: Integer; var count: LongWord): Integer; cdecl;
  140. // =======================================================
  141. //
  142. // =======================================================
  143. implementation
  144. uses GL, dynlibs;
  145. {$LINKLIB m}
  146. function GetProc(handle: PtrInt; name: PChar): Pointer;
  147. begin
  148. Result := GetProcAddress(handle, name);
  149. if (Result = nil) and GLXDumpUnresolvedFunctions then
  150. WriteLn('Unresolved: ', name);
  151. end;
  152. function InitGLX: Boolean;
  153. var
  154. OurLibGL: TLibHandle;
  155. begin
  156. Result := False;
  157. {$ifndef darwin}
  158. OurLibGL := libGl;
  159. {$else darwin}
  160. OurLibGL := LoadLibrary('/usr/X11R6/lib/libGL.dylib');
  161. {$endif darwin}
  162. if OurLibGL = 0 then
  163. exit;
  164. glXChooseVisual := GetProc(OurLibGL, 'glXChooseVisual');
  165. glXCreateContext := GetProc(OurLibGL, 'glXCreateContext');
  166. glXDestroyContext := GetProc(OurLibGL, 'glXDestroyContext');
  167. glXMakeCurrent := GetProc(OurLibGL, 'glXMakeCurrent');
  168. glXCopyContext := GetProc(OurLibGL, 'glXCopyContext');
  169. glXSwapBuffers := GetProc(OurLibGL, 'glXSwapBuffers');
  170. glXCreateGLXPixmap := GetProc(OurLibGL, 'glXCreateGLXPixmap');
  171. glXDestroyGLXPixmap := GetProc(OurLibGL, 'glXDestroyGLXPixmap');
  172. glXQueryExtension := GetProc(OurLibGL, 'glXQueryExtension');
  173. glXQueryVersion := GetProc(OurLibGL, 'glXQueryVersion');
  174. glXIsDirect := GetProc(OurLibGL, 'glXIsDirect');
  175. glXGetConfig := GetProc(OurLibGL, 'glXGetConfig');
  176. glXGetCurrentContext := GetProc(OurLibGL, 'glXGetCurrentContext');
  177. glXGetCurrentDrawable := GetProc(OurLibGL, 'glXGetCurrentDrawable');
  178. glXWaitGL := GetProc(OurLibGL, 'glXWaitGL');
  179. glXWaitX := GetProc(OurLibGL, 'glXWaitX');
  180. glXUseXFont := GetProc(OurLibGL, 'glXUseXFont');
  181. // GLX 1.1 and later
  182. glXQueryExtensionsString := GetProc(OurLibGL, 'glXQueryExtensionsString');
  183. glXQueryServerString := GetProc(OurLibGL, 'glXQueryServerString');
  184. glXGetClientString := GetProc(OurLibGL, 'glXGetClientString');
  185. // Mesa GLX Extensions
  186. glXCreateGLXPixmapMESA := GetProc(OurLibGL, 'glXCreateGLXPixmapMESA');
  187. glXReleaseBufferMESA := GetProc(OurLibGL, 'glXReleaseBufferMESA');
  188. glXCopySubBufferMESA := GetProc(OurLibGL, 'glXCopySubBufferMESA');
  189. glXGetVideoSyncSGI := GetProc(OurLibGL, 'glXGetVideoSyncSGI');
  190. glXWaitVideoSyncSGI := GetProc(OurLibGL, 'glXWaitVideoSyncSGI');
  191. GLXInitialized := True;
  192. Result := True;
  193. end;
  194. initialization
  195. InitGLX;
  196. end.