glx.pp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  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., 51 Franklin Street, Fifth Floor, Boston,
  18. MA 02110-1301, USA.
  19. }
  20. {$MODE delphi} // objfpc would not work because of direct proc var assignments
  21. {You have to enable Macros (compiler switch "-Sm") for compiling this unit!
  22. This is necessary for supporting different platforms with different calling
  23. conventions via a single unit.}
  24. {$IFNDEF FPC_DOTTEDUNITS}
  25. unit GLX;
  26. {$ENDIF FPC_DOTTEDUNITS}
  27. interface
  28. {$MACRO ON}
  29. {$IFDEF Unix}
  30. {$IFDEF FPC_DOTTEDUNITS}
  31. uses
  32. System.CTypes, Api.X11.X, Api.X11.Xlib, Api.X11.Xutil;
  33. {$ELSE FPC_DOTTEDUNITS}
  34. uses
  35. ctypes, X, XLib, XUtil;
  36. {$ENDIF FPC_DOTTEDUNITS}
  37. {$DEFINE HasGLX} // Activate GLX stuff
  38. {$ELSE}
  39. {$MESSAGE Unsupported platform.}
  40. {$ENDIF}
  41. {$IFNDEF HasGLX}
  42. {$MESSAGE GLX not present on this platform.}
  43. {$ENDIF}
  44. // =======================================================
  45. // Unit specific extensions
  46. // =======================================================
  47. // Note: Requires that the GL library has already been initialized
  48. function InitGLX: Boolean;
  49. var
  50. GLXDumpUnresolvedFunctions,
  51. GLXInitialized: Boolean;
  52. // =======================================================
  53. // GLX consts, types and functions
  54. // =======================================================
  55. // Tokens for glXChooseVisual and glXGetConfig:
  56. const
  57. GLX_USE_GL = 1;
  58. GLX_BUFFER_SIZE = 2;
  59. GLX_LEVEL = 3;
  60. GLX_RGBA = 4;
  61. GLX_DOUBLEBUFFER = 5;
  62. GLX_STEREO = 6;
  63. GLX_AUX_BUFFERS = 7;
  64. GLX_RED_SIZE = 8;
  65. GLX_GREEN_SIZE = 9;
  66. GLX_BLUE_SIZE = 10;
  67. GLX_ALPHA_SIZE = 11;
  68. GLX_DEPTH_SIZE = 12;
  69. GLX_STENCIL_SIZE = 13;
  70. GLX_ACCUM_RED_SIZE = 14;
  71. GLX_ACCUM_GREEN_SIZE = 15;
  72. GLX_ACCUM_BLUE_SIZE = 16;
  73. GLX_ACCUM_ALPHA_SIZE = 17;
  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 1.3 and later:
  87. GLX_CONFIG_CAVEAT = $20;
  88. GLX_DONT_CARE = $FFFFFFFF;
  89. GLX_X_VISUAL_TYPE = $22;
  90. GLX_TRANSPARENT_TYPE = $23;
  91. GLX_TRANSPARENT_INDEX_VALUE = $24;
  92. GLX_TRANSPARENT_RED_VALUE = $25;
  93. GLX_TRANSPARENT_GREEN_VALUE = $26;
  94. GLX_TRANSPARENT_BLUE_VALUE = $27;
  95. GLX_TRANSPARENT_ALPHA_VALUE = $28;
  96. GLX_WINDOW_BIT = $00000001;
  97. GLX_PIXMAP_BIT = $00000002;
  98. GLX_PBUFFER_BIT = $00000004;
  99. GLX_AUX_BUFFERS_BIT = $00000010;
  100. GLX_FRONT_LEFT_BUFFER_BIT = $00000001;
  101. GLX_FRONT_RIGHT_BUFFER_BIT = $00000002;
  102. GLX_BACK_LEFT_BUFFER_BIT = $00000004;
  103. GLX_BACK_RIGHT_BUFFER_BIT = $00000008;
  104. GLX_DEPTH_BUFFER_BIT = $00000020;
  105. GLX_STENCIL_BUFFER_BIT = $00000040;
  106. GLX_ACCUM_BUFFER_BIT = $00000080;
  107. GLX_NONE = $8000;
  108. GLX_SLOW_CONFIG = $8001;
  109. GLX_TRUE_COLOR = $8002;
  110. GLX_DIRECT_COLOR = $8003;
  111. GLX_PSEUDO_COLOR = $8004;
  112. GLX_STATIC_COLOR = $8005;
  113. GLX_GRAY_SCALE = $8006;
  114. GLX_STATIC_GRAY = $8007;
  115. GLX_TRANSPARENT_RGB = $8008;
  116. GLX_TRANSPARENT_INDEX = $8009;
  117. GLX_VISUAL_ID = $800B;
  118. GLX_SCREEN = $800C;
  119. GLX_NON_CONFORMANT_CONFIG = $800D;
  120. GLX_DRAWABLE_TYPE = $8010;
  121. GLX_RENDER_TYPE = $8011;
  122. GLX_X_RENDERABLE = $8012;
  123. GLX_FBCONFIG_ID = $8013;
  124. GLX_RGBA_TYPE = $8014;
  125. GLX_COLOR_INDEX_TYPE = $8015;
  126. GLX_MAX_PBUFFER_WIDTH = $8016;
  127. GLX_MAX_PBUFFER_HEIGHT = $8017;
  128. GLX_MAX_PBUFFER_PIXELS = $8018;
  129. GLX_PRESERVED_CONTENTS = $801B;
  130. GLX_LARGEST_PBUFFER = $801C;
  131. GLX_WIDTH = $801D;
  132. GLX_HEIGHT = $801E;
  133. GLX_EVENT_MASK = $801F;
  134. GLX_DAMAGED = $8020;
  135. GLX_SAVED = $8021;
  136. GLX_WINDOW = $8022;
  137. GLX_PBUFFER = $8023;
  138. GLX_PBUFFER_HEIGHT = $8040;
  139. GLX_PBUFFER_WIDTH = $8041;
  140. GLX_RGBA_BIT = $00000001;
  141. GLX_COLOR_INDEX_BIT = $00000002;
  142. GLX_PBUFFER_CLOBBER_MASK = $08000000;
  143. // GLX 1.4 and later:
  144. GLX_SAMPLE_BUFFERS = $186a0; // 100000
  145. GLX_SAMPLES = $186a1; // 100001
  146. // Extensions:
  147. // GLX_ARB_multisample
  148. GLX_SAMPLE_BUFFERS_ARB = 100000;
  149. GLX_SAMPLES_ARB = 100001;
  150. // GLX_ARB_create_context (http://www.opengl.org/registry/specs/ARB/glx_create_context.txt)
  151. GLX_CONTEXT_DEBUG_BIT_ARB = $00000001;
  152. GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = $00000002;
  153. GLX_CONTEXT_MAJOR_VERSION_ARB = $2091;
  154. GLX_CONTEXT_MINOR_VERSION_ARB = $2092;
  155. GLX_CONTEXT_FLAGS_ARB = $2094;
  156. // GLX_ARB_create_context_profile
  157. GLX_CONTEXT_CORE_PROFILE_BIT_ARB = $00000001;
  158. GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = $00000002;
  159. GLX_CONTEXT_PROFILE_MASK_ARB = $9126;
  160. // GLX_ARB_create_context_robustness
  161. GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB = $00000004;
  162. GLX_LOSE_CONTEXT_ON_RESET_ARB = $8252;
  163. GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = $8256;
  164. GLX_NO_RESET_NOTIFICATION_ARB = $8261;
  165. // GLX_SGIS_multisample
  166. GLX_SAMPLE_BUFFERS_SGIS = 100000;
  167. GLX_SAMPLES_SGIS = 100001;
  168. // GLX_EXT_visual_info
  169. GLX_X_VISUAL_TYPE_EXT = $22;
  170. GLX_TRANSPARENT_TYPE_EXT = $23;
  171. GLX_TRANSPARENT_INDEX_VALUE_EXT = $24;
  172. GLX_TRANSPARENT_RED_VALUE_EXT = $25;
  173. GLX_TRANSPARENT_GREEN_VALUE_EXT = $26;
  174. GLX_TRANSPARENT_BLUE_VALUE_EXT = $27;
  175. GLX_TRANSPARENT_ALPHA_VALUE_EXT = $28;
  176. GLX_TRUE_COLOR_EXT = $8002;
  177. GLX_DIRECT_COLOR_EXT = $8003;
  178. GLX_PSEUDO_COLOR_EXT = $8004;
  179. GLX_STATIC_COLOR_EXT = $8005;
  180. GLX_GRAY_SCALE_EXT = $8006;
  181. GLX_STATIC_GRAY_EXT = $8007;
  182. GLX_NONE_EXT = $8000;
  183. GLX_TRANSPARENT_RGB_EXT = $8008;
  184. GLX_TRANSPARENT_INDEX_EXT = $8009;
  185. type
  186. // From XLib:
  187. XPixmap = TXID;
  188. XFont = TXID;
  189. XColormap = TXID;
  190. GLXContext = Pointer;
  191. GLXPixmap = TXID;
  192. GLXDrawable = TXID;
  193. GLXContextID = TXID;
  194. TXPixmap = XPixmap;
  195. TXFont = XFont;
  196. TXColormap = XColormap;
  197. TGLXContext = GLXContext;
  198. TGLXPixmap = GLXPixmap;
  199. TGLXDrawable = GLXDrawable;
  200. // GLX 1.3 and later
  201. TGLXFBConfigRec = record { internal, use only a pointer to this } end;
  202. TGLXFBConfig = ^TGLXFBConfigRec;
  203. { PGLXFBConfig is a pointer to TGLXFBConfig (which is also a pointer).
  204. glX uses this to represent an array of FB configs. }
  205. PGLXFBConfig = ^TGLXFBConfig;
  206. TGLXFBConfigID = TXID;
  207. TGLXContextID = GLXContextID;
  208. TGLXWindow = TXID;
  209. TGLXPbuffer = TXID;
  210. var
  211. glXChooseVisual: function(dpy: PDisplay; screen: cint; attribList: Pcint): PXVisualInfo; cdecl;
  212. //glXCreateContext -> internal_glXCreateContext in implementation
  213. glXDestroyContext: procedure(dpy: PDisplay; ctx: GLXContext); cdecl;
  214. glXMakeCurrent: function(dpy: PDisplay; drawable: GLXDrawable; ctx: GLXContext): TBoolResult; cdecl;
  215. glXCopyContext: procedure(dpy: PDisplay; src, dst: GLXContext; mask: culong); cdecl;
  216. glXSwapBuffers: procedure(dpy: PDisplay; drawable: GLXDrawable); cdecl;
  217. glXCreateGLXPixmap: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap): GLXPixmap; cdecl;
  218. glXDestroyGLXPixmap: procedure(dpy: PDisplay; pixmap: GLXPixmap); cdecl;
  219. glXQueryExtension: function(dpy: PDisplay; var errorb, event: cint): TBoolResult; cdecl;
  220. glXQueryVersion: function(dpy: PDisplay; var maj, min: cint): TBoolResult; cdecl;
  221. glXIsDirect: function(dpy: PDisplay; ctx: GLXContext): TBoolResult; cdecl;
  222. glXGetConfig: function(dpy: PDisplay; visual: PXVisualInfo; attrib: cint; var value: cint): cint; cdecl;
  223. glXGetCurrentContext: function: GLXContext; cdecl;
  224. glXGetCurrentDrawable: function: GLXDrawable; cdecl;
  225. glXWaitGL: procedure; cdecl;
  226. glXWaitX: procedure; cdecl;
  227. glXUseXFont: procedure(font: XFont; first, count, list: cint); cdecl;
  228. // GLX 1.1 and later
  229. glXQueryExtensionsString: function(dpy: PDisplay; screen: cint): PAnsiChar; cdecl;
  230. glXQueryServerString: function(dpy: PDisplay; screen, name: cint): PAnsiChar; cdecl;
  231. glXGetClientString: function(dpy: PDisplay; name: cint): PAnsiChar; cdecl;
  232. // GLX 1.2 and later
  233. glXGetCurrentDisplay: function: PDisplay; cdecl;
  234. // GLX 1.3 and later
  235. glXChooseFBConfig: function(dpy: PDisplay; screen: cint; attribList: Pcint; var nitems: cint): PGLXFBConfig; cdecl;
  236. glXGetFBConfigAttrib: function(dpy: PDisplay; config: TGLXFBConfig; attribute: cint; var value: cint): cint; cdecl;
  237. glXGetFBConfigs: function(dpy: PDisplay; screen: cint; var nelements: cint): PGLXFBConfig; cdecl;
  238. glXGetVisualFromFBConfig: function(dpy: PDisplay; config: TGLXFBConfig): PXVisualInfo; cdecl;
  239. glXCreateWindow: function(dpy: PDisplay; config: TGLXFBConfig; win: {$IFDEF FPC_DOTTEDUNITS}Api.X11.{$ENDIF}X.TWindow; attribList: Pcint): TGLXWindow; cdecl;
  240. glXDestroyWindow: procedure (dpy: PDisplay; window: TGLXWindow); cdecl;
  241. glXCreatePixmap: function(dpy: PDisplay; config: TGLXFBConfig; pixmap: TXPixmap; attribList: Pcint): TGLXPixmap; cdecl;
  242. glXDestroyPixmap: procedure (dpy: PDisplay; pixmap: TGLXPixmap); cdecl;
  243. glXCreatePbuffer: function(dpy: PDisplay; config: TGLXFBConfig; attribList: Pcint): TGLXPbuffer; cdecl;
  244. glXDestroyPbuffer: procedure (dpy: PDisplay; pbuf: TGLXPbuffer); cdecl;
  245. glXQueryDrawable: procedure (dpy: PDisplay; draw: TGLXDrawable; attribute: cint; value: Pcuint); cdecl;
  246. //glXCreateNewContext -> internal_glXCreateNewContext in implementation
  247. glXMakeContextCurrent: function(dpy: PDisplay; draw: TGLXDrawable; read: GLXDrawable; ctx: TGLXContext): TBoolResult; cdecl;
  248. glXGetCurrentReadDrawable: function: TGLXDrawable; cdecl;
  249. glXQueryContext: function(dpy: PDisplay; ctx: TGLXContext; attribute: cint; var value: cint): cint; cdecl;
  250. glXSelectEvent: procedure (dpy: PDisplay; drawable: TGLXDrawable; mask: culong); cdecl;
  251. glXGetSelectedEvent: procedure (dpy: PDisplay; drawable: TGLXDrawable; mask: Pculong); cdecl;
  252. // GLX 1.4 and later
  253. glXGetProcAddress: function(procname: PAnsiChar): Pointer; cdecl;
  254. // Extensions:
  255. // GLX_ARB_get_proc_address
  256. glXGetProcAddressARB: function(procname: PAnsiChar): Pointer; cdecl;
  257. // GLX_ARB_create_context
  258. //glXCreateContextAttribsARB -> internal_glXCreateContextAttribsARB in implementation
  259. // GLX_EXT_swap_control
  260. glXSwapIntervalEXT: function(dpy: PDisplay; drawable: TGLXDrawable; interval: cint): cint; cdecl;
  261. // GLX_MESA_pixmap_colormap
  262. glXCreateGLXPixmapMESA: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap; cmap: XColormap): GLXPixmap; cdecl;
  263. // GLX_MESA_swap_control
  264. glXSwapIntervalMESA: function(interval: cuint): cint; cdecl;
  265. glXGetSwapIntervalMESA: function: cint; cdecl;
  266. // Unknown Mesa GLX extension (undocumented in current GLX C headers?)
  267. glXReleaseBuffersMESA: function(dpy: PDisplay; d: GLXDrawable): TBoolResult; cdecl;
  268. glXCopySubBufferMESA: procedure(dpy: PDisplay; drawable: GLXDrawable; x, y, width, height: cint); cdecl;
  269. // GLX_SGI_swap_control
  270. glXSwapIntervalSGI: function(interval: cint): cint; cdecl;
  271. // GLX_SGI_video_sync
  272. glXGetVideoSyncSGI: function(var count: cuint): cint; cdecl;
  273. glXWaitVideoSyncSGI: function(divisor, remainder: cint; var count: cuint): cint; cdecl;
  274. // =======================================================
  275. //
  276. // =======================================================
  277. // Overloaded functions to handle TBool parameters as actual booleans.
  278. function glXCreateContext(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: Boolean): GLXContext;
  279. function glXCreateNewContext(dpy: PDisplay; config: TGLXFBConfig; renderType: cint; shareList: TGLXContext; direct: Boolean): TGLXContext;
  280. function glXCreateContextAttribsARB(dpy: PDisplay; config: TGLXFBConfig; share_context: TGLXContext; direct: Boolean; attrib_list: Pcint): TGLXContext;
  281. {
  282. Safe checking of glX version and extension presence.
  283. For each glX version, these functions check that
  284. - glXQueryExtension indicates that glX extension is present at all on this display.
  285. - glXQueryVersion indicates that (at least) this version is supported.
  286. - all the entry points defined for this glX version were
  287. successfully loaded from the library.
  288. For now, all glX versions are fully backward-compatible,
  289. so e.g. if GLX_version_1_3 is true, you know that also GLX_version_1_2
  290. and GLX_version_1_1 etc. are true,
  291. and all entry points up to glX 1.3 are assigned.
  292. For each extension, these functions check that
  293. - it is declared within glXQueryExtensionsString (which in turn means
  294. that glXQueryExtensionsString must be available, which requires glX 1.1)
  295. - all it's entry points were successfully loaded from library
  296. As such, these functions are the safest way to check if given
  297. extension/glX version is available.
  298. Note that the availability of glX version and extension may depend
  299. on the X display and (in case of extension) even screen number.
  300. }
  301. function GLX_version_1_0(Display: PDisplay): boolean;
  302. function GLX_version_1_1(Display: PDisplay): boolean;
  303. function GLX_version_1_2(Display: PDisplay): boolean;
  304. function GLX_version_1_3(Display: PDisplay): boolean;
  305. function GLX_version_1_4(Display: PDisplay): boolean;
  306. function GLX_ARB_get_proc_address(Display: PDisplay; Screen: Integer): boolean;
  307. function GLX_ARB_create_context(Display: PDisplay; Screen: Integer): boolean;
  308. function GLX_ARB_create_context_profile(Display: PDisplay; Screen: Integer): boolean;
  309. function GLX_ARB_create_context_robustness(Display: PDisplay; Screen: Integer): boolean;
  310. function GLX_ARB_multisample(Display: PDisplay; Screen: Integer): boolean;
  311. function GLX_EXT_swap_control(Display: PDisplay; Screen: Integer): boolean;
  312. function GLX_EXT_visual_info(Display: PDisplay; Screen: Integer): boolean;
  313. function GLX_MESA_pixmap_colormap(Display: PDisplay; Screen: Integer): boolean;
  314. function GLX_MESA_swap_control(Display: PDisplay; Screen: Integer): boolean;
  315. function GLX_SGI_swap_control(Display: PDisplay; Screen: Integer): boolean;
  316. function GLX_SGI_video_sync(Display: PDisplay; Screen: Integer): boolean;
  317. function GLX_SGIS_multisample(Display: PDisplay; Screen: Integer): boolean;
  318. implementation
  319. {$IFDEF FPC_DOTTEDUNITS}
  320. uses Api.OpenGL.Gl, System.DynLibs, Api.OpenGL.Glext { for glext_ExtensionSupported Amiga.Core.Utility };
  321. {$ELSE FPC_DOTTEDUNITS}
  322. uses GL, dynlibs, GLExt { for glext_ExtensionSupported utility };
  323. {$ENDIF FPC_DOTTEDUNITS}
  324. {$LINKLIB m}
  325. var
  326. internal_glXCreateContext: function(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: TBool): GLXContext; cdecl;
  327. internal_glXCreateNewContext: function(dpy: PDisplay; config: TGLXFBConfig; renderType: cint; shareList: TGLXContext; direct: TBool): TGLXContext; cdecl;
  328. internal_glXCreateContextAttribsARB: function (dpy: PDisplay; config: TGLXFBConfig; share_context: TGLXContext; direct: TBool; attrib_list: Pcint): TGLXContext; cdecl;
  329. function glXCreateContext(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: Boolean): GLXContext;
  330. begin
  331. Result := internal_glXCreateContext(dpy, vis, shareList, Ord(direct));
  332. end;
  333. function glXCreateNewContext(dpy: PDisplay; config: TGLXFBConfig; renderType: cint; shareList: TGLXContext; direct: Boolean): TGLXContext;
  334. begin
  335. Result := internal_glXCreateNewContext(dpy, config, renderType, shareList, Ord(direct));
  336. end;
  337. function glXCreateContextAttribsARB(dpy: PDisplay; config: TGLXFBConfig; share_context: TGLXContext; direct: Boolean; attrib_list: Pcint): TGLXContext;
  338. begin
  339. Result := internal_glXCreateContextAttribsARB(dpy, config, share_context, Ord(direct), attrib_list);
  340. end;
  341. function GLX_version_1_0(Display: PDisplay): boolean;
  342. var
  343. IgnoredErrorb, IgnoredEvent, Major, Minor: Integer;
  344. begin
  345. Result :=
  346. { check is glX present at all for this display }
  347. Assigned(glXQueryExtension) and
  348. glXQueryExtension(Display, IgnoredErrorb, IgnoredEvent) and
  349. { check glXQueryVersion, although there is no glX with version < 1 }
  350. Assigned(glXQueryVersion) and
  351. glXQueryVersion(Display, Major, Minor) and
  352. (Major >= 1) and
  353. { check entry points assigned }
  354. Assigned(glXChooseVisual) and
  355. Assigned(internal_glXCreateContext) and
  356. Assigned(glXDestroyContext) and
  357. Assigned(glXMakeCurrent) and
  358. Assigned(glXCopyContext) and
  359. Assigned(glXSwapBuffers) and
  360. Assigned(glXCreateGLXPixmap) and
  361. Assigned(glXDestroyGLXPixmap) and
  362. { Assigned(glXQueryExtension) and } { (already checked) }
  363. { Assigned(glXQueryVersion) and } { (already checked) }
  364. Assigned(glXIsDirect) and
  365. Assigned(glXGetConfig) and
  366. Assigned(glXGetCurrentContext) and
  367. Assigned(glXGetCurrentDrawable) and
  368. Assigned(glXWaitGL) and
  369. Assigned(glXWaitX) and
  370. Assigned(glXUseXFont)
  371. end;
  372. function GLX_version_1_1(Display: PDisplay): boolean;
  373. var
  374. Major, Minor: Integer;
  375. begin
  376. Result :=
  377. { check previous version Ok }
  378. GLX_version_1_0(Display) and
  379. { check glXQueryVersion }
  380. glXQueryVersion(Display, Major, Minor) and
  381. ( (Major > 1) or ((Major = 1) and (Minor >= 1)) ) and
  382. { check entry points assigned }
  383. Assigned(glXQueryExtensionsString) and
  384. Assigned(glXQueryServerString) and
  385. Assigned(glXGetClientString);
  386. end;
  387. function GLX_version_1_2(Display: PDisplay): boolean;
  388. var
  389. Major, Minor: Integer;
  390. begin
  391. Result :=
  392. { check previous version Ok }
  393. GLX_version_1_1(Display) and
  394. { check glXQueryVersion }
  395. glXQueryVersion(Display, Major, Minor) and
  396. ( (Major > 1) or ((Major = 1) and (Minor >= 2)) ) and
  397. { check entry points assigned }
  398. Assigned(glXGetCurrentDisplay);
  399. end;
  400. function GLX_version_1_3(Display: PDisplay): boolean;
  401. var
  402. Major, Minor: Integer;
  403. begin
  404. Result :=
  405. { check previous version Ok }
  406. GLX_version_1_2(Display) and
  407. { check glXQueryVersion }
  408. glXQueryVersion(Display, Major, Minor) and
  409. ( (Major > 1) or ((Major = 1) and (Minor >= 3)) ) and
  410. { check entry points assigned }
  411. Assigned(glXChooseFBConfig) and
  412. Assigned(glXGetFBConfigAttrib) and
  413. Assigned(glXGetFBConfigs) and
  414. Assigned(glXGetVisualFromFBConfig) and
  415. Assigned(glXCreateWindow) and
  416. Assigned(glXDestroyWindow) and
  417. Assigned(glXCreatePixmap) and
  418. Assigned(glXDestroyPixmap) and
  419. Assigned(glXCreatePbuffer) and
  420. Assigned(glXDestroyPbuffer) and
  421. Assigned(glXQueryDrawable) and
  422. Assigned(internal_glXCreateNewContext) and
  423. Assigned(glXMakeContextCurrent) and
  424. Assigned(glXGetCurrentReadDrawable) and
  425. Assigned(glXQueryContext) and
  426. Assigned(glXSelectEvent) and
  427. Assigned(glXGetSelectedEvent);
  428. end;
  429. function GLX_version_1_4(Display: PDisplay): boolean;
  430. var
  431. Major, Minor: Integer;
  432. begin
  433. Result :=
  434. { check previous version Ok }
  435. GLX_version_1_3(Display) and
  436. { check glXQueryVersion }
  437. glXQueryVersion(Display, Major, Minor) and
  438. ( (Major > 1) or ((Major = 1) and (Minor >= 4)) ) and
  439. { check entry points assigned }
  440. Assigned(glXGetProcAddress);
  441. end;
  442. function GLX_ARB_get_proc_address(Display: PDisplay; Screen: Integer): boolean;
  443. var
  444. GlxExtensions: PAnsiChar;
  445. begin
  446. Result := GLX_version_1_1(Display);
  447. if Result then
  448. begin
  449. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  450. Result := glext_ExtensionSupported('GLX_ARB_get_proc_address', GlxExtensions) and
  451. Assigned(glXGetProcAddressARB);
  452. end;
  453. end;
  454. function GLX_ARB_create_context(Display: PDisplay; Screen: Integer): boolean;
  455. var
  456. GlxExtensions: PAnsiChar;
  457. begin
  458. Result := GLX_version_1_1(Display);
  459. if Result then
  460. begin
  461. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  462. Result := glext_ExtensionSupported('GLX_ARB_create_context', GlxExtensions) and
  463. Assigned(internal_glXCreateContextAttribsARB);
  464. end;
  465. end;
  466. function GLX_ARB_create_context_profile(Display: PDisplay; Screen: Integer): boolean;
  467. var
  468. GlxExtensions: PAnsiChar;
  469. begin
  470. Result := GLX_version_1_1(Display);
  471. if Result then
  472. begin
  473. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  474. Result := glext_ExtensionSupported('GLX_ARB_create_context_profile', GlxExtensions);
  475. end;
  476. end;
  477. function GLX_ARB_create_context_robustness(Display: PDisplay; Screen: Integer): boolean;
  478. var
  479. GlxExtensions: PAnsiChar;
  480. begin
  481. Result := GLX_version_1_1(Display);
  482. if Result then
  483. begin
  484. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  485. Result := glext_ExtensionSupported('GLX_ARB_create_context_robustness', GlxExtensions);
  486. end;
  487. end;
  488. function GLX_ARB_multisample(Display: PDisplay; Screen: Integer): boolean;
  489. var
  490. GlxExtensions: PAnsiChar;
  491. begin
  492. Result := GLX_version_1_1(Display);
  493. if Result then
  494. begin
  495. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  496. Result := glext_ExtensionSupported('GLX_ARB_multisample', GlxExtensions);
  497. end;
  498. end;
  499. function GLX_EXT_swap_control(Display: PDisplay; Screen: Integer): boolean;
  500. var
  501. GlxExtensions: PAnsiChar;
  502. begin
  503. Result := GLX_version_1_1(Display);
  504. if Result then
  505. begin
  506. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  507. Result := glext_ExtensionSupported('GLX_EXT_swap_control', GlxExtensions) and
  508. Assigned(glXSwapIntervalEXT);
  509. end;
  510. end;
  511. function GLX_EXT_visual_info(Display: PDisplay; Screen: Integer): boolean;
  512. var
  513. GlxExtensions: PAnsiChar;
  514. begin
  515. Result := GLX_version_1_1(Display);
  516. if Result then
  517. begin
  518. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  519. Result := glext_ExtensionSupported('GLX_EXT_visual_info', GlxExtensions);
  520. end;
  521. end;
  522. function GLX_MESA_pixmap_colormap(Display: PDisplay; Screen: Integer): boolean;
  523. var
  524. GlxExtensions: PAnsiChar;
  525. begin
  526. Result := GLX_version_1_1(Display);
  527. if Result then
  528. begin
  529. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  530. Result := glext_ExtensionSupported('GLX_MESA_pixmap_colormap', GlxExtensions) and
  531. Assigned(glXCreateGLXPixmapMESA);
  532. end;
  533. end;
  534. function GLX_MESA_swap_control(Display: PDisplay; Screen: Integer): boolean;
  535. var
  536. GlxExtensions: PAnsiChar;
  537. begin
  538. Result := GLX_version_1_1(Display);
  539. if Result then
  540. begin
  541. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  542. Result := glext_ExtensionSupported('GLX_MESA_swap_control', GlxExtensions) and
  543. Assigned(glXSwapIntervalMESA) and
  544. Assigned(glXGetSwapIntervalMESA);
  545. end;
  546. end;
  547. function GLX_SGI_swap_control(Display: PDisplay; Screen: Integer): boolean;
  548. var
  549. GlxExtensions: PAnsiChar;
  550. begin
  551. Result := GLX_version_1_1(Display);
  552. if Result then
  553. begin
  554. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  555. Result := glext_ExtensionSupported('GLX_SGI_swap_control', GlxExtensions) and
  556. Assigned(glXSwapIntervalSGI);
  557. end;
  558. end;
  559. function GLX_SGI_video_sync(Display: PDisplay; Screen: Integer): boolean;
  560. var
  561. GlxExtensions: PAnsiChar;
  562. begin
  563. Result := GLX_version_1_1(Display);
  564. if Result then
  565. begin
  566. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  567. Result := glext_ExtensionSupported('GLX_SGI_video_sync', GlxExtensions) and
  568. Assigned(glXGetVideoSyncSGI) and
  569. Assigned(glXWaitVideoSyncSGI);
  570. end;
  571. end;
  572. function GLX_SGIS_multisample(Display: PDisplay; Screen: Integer): boolean;
  573. var
  574. GlxExtensions: PAnsiChar;
  575. begin
  576. Result := GLX_version_1_1(Display);
  577. if Result then
  578. begin
  579. GlxExtensions := glXQueryExtensionsString(Display, Screen);
  580. Result := glext_ExtensionSupported('GLX_SGIS_multisample', GlxExtensions);
  581. end;
  582. end;
  583. function GetProc(handle: PtrInt; name: PAnsiChar): Pointer;
  584. begin
  585. if Assigned(glXGetProcAddress) then
  586. Result := glXGetProcAddress(name)
  587. else
  588. if Assigned(glXGetProcAddressARB) then
  589. Result := glXGetProcAddressARB(name)
  590. else
  591. Result := GetProcAddress(handle, name);
  592. if (Result = nil) and GLXDumpUnresolvedFunctions then
  593. WriteLn('Unresolved: ', name);
  594. end;
  595. function InitGLX: Boolean;
  596. var
  597. OurLibGL: TLibHandle;
  598. begin
  599. Result := False;
  600. {$ifndef darwin}
  601. OurLibGL := libGl;
  602. {$else darwin}
  603. OurLibGL := LoadLibrary('/usr/X11R6/lib/libGL.dylib');
  604. {$endif darwin}
  605. if OurLibGL = 0 then
  606. exit;
  607. // glXGetProcAddress and glXGetProcAddressARB are imported first,
  608. // so we can use them (when they are available) to resolve all the
  609. // other imports
  610. // GLX 1.4 and later
  611. glXGetProcAddress := GetProc(OurLibGL, 'glXGetProcAddress');
  612. // GLX_ARB_get_proc_address
  613. glXGetProcAddressARB := GetProc(OurLibGL, 'glXGetProcAddressARB');
  614. // GLX 1.0
  615. glXChooseVisual := GetProc(OurLibGL, 'glXChooseVisual');
  616. internal_glXCreateContext := GetProc(OurLibGL, 'glXCreateContext');
  617. glXDestroyContext := GetProc(OurLibGL, 'glXDestroyContext');
  618. glXMakeCurrent := GetProc(OurLibGL, 'glXMakeCurrent');
  619. glXCopyContext := GetProc(OurLibGL, 'glXCopyContext');
  620. glXSwapBuffers := GetProc(OurLibGL, 'glXSwapBuffers');
  621. glXCreateGLXPixmap := GetProc(OurLibGL, 'glXCreateGLXPixmap');
  622. glXDestroyGLXPixmap := GetProc(OurLibGL, 'glXDestroyGLXPixmap');
  623. glXQueryExtension := GetProc(OurLibGL, 'glXQueryExtension');
  624. glXQueryVersion := GetProc(OurLibGL, 'glXQueryVersion');
  625. glXIsDirect := GetProc(OurLibGL, 'glXIsDirect');
  626. glXGetConfig := GetProc(OurLibGL, 'glXGetConfig');
  627. glXGetCurrentContext := GetProc(OurLibGL, 'glXGetCurrentContext');
  628. glXGetCurrentDrawable := GetProc(OurLibGL, 'glXGetCurrentDrawable');
  629. glXWaitGL := GetProc(OurLibGL, 'glXWaitGL');
  630. glXWaitX := GetProc(OurLibGL, 'glXWaitX');
  631. glXUseXFont := GetProc(OurLibGL, 'glXUseXFont');
  632. // GLX 1.1 and later
  633. glXQueryExtensionsString := GetProc(OurLibGL, 'glXQueryExtensionsString');
  634. glXQueryServerString := GetProc(OurLibGL, 'glXQueryServerString');
  635. glXGetClientString := GetProc(OurLibGL, 'glXGetClientString');
  636. // GLX 1.2 and later
  637. glXGetCurrentDisplay := GetProc(OurLibGL, 'glXGetCurrentDisplay');
  638. // GLX 1.3 and later
  639. glXChooseFBConfig := GetProc(OurLibGL, 'glXChooseFBConfig');
  640. glXGetFBConfigAttrib := GetProc(OurLibGL, 'glXGetFBConfigAttrib');
  641. glXGetFBConfigs := GetProc(OurLibGL, 'glXGetFBConfigs');
  642. glXGetVisualFromFBConfig := GetProc(OurLibGL, 'glXGetVisualFromFBConfig');
  643. glXCreateWindow := GetProc(OurLibGL, 'glXCreateWindow');
  644. glXDestroyWindow := GetProc(OurLibGL, 'glXDestroyWindow');
  645. glXCreatePixmap := GetProc(OurLibGL, 'glXCreatePixmap');
  646. glXDestroyPixmap := GetProc(OurLibGL, 'glXDestroyPixmap');
  647. glXCreatePbuffer := GetProc(OurLibGL, 'glXCreatePbuffer');
  648. glXDestroyPbuffer := GetProc(OurLibGL, 'glXDestroyPbuffer');
  649. glXQueryDrawable := GetProc(OurLibGL, 'glXQueryDrawable');
  650. internal_glXCreateNewContext := GetProc(OurLibGL, 'glXCreateNewContext');
  651. glXMakeContextCurrent := GetProc(OurLibGL, 'glXMakeContextCurrent');
  652. glXGetCurrentReadDrawable := GetProc(OurLibGL, 'glXGetCurrentReadDrawable');
  653. glXQueryContext := GetProc(OurLibGL, 'glXQueryContext');
  654. glXSelectEvent := GetProc(OurLibGL, 'glXSelectEvent');
  655. glXGetSelectedEvent := GetProc(OurLibGL, 'glXGetSelectedEvent');
  656. // Extensions
  657. // GLX_ARB_create_context
  658. internal_glXCreateContextAttribsARB := GetProc(OurLibGL, 'glXCreateContextAttribsARB');
  659. // GLX_EXT_swap_control
  660. glXSwapIntervalEXT := GetProc(OurLibGL, 'glXSwapIntervalEXT');
  661. // GLX_MESA_pixmap_colormap
  662. glXCreateGLXPixmapMESA := GetProc(OurLibGL, 'glXCreateGLXPixmapMESA');
  663. // GLX_MESA_swap_control
  664. glXSwapIntervalMESA := GetProc(OurLibGL, 'glXSwapIntervalMESA');
  665. glXGetSwapIntervalMESA := GetProc(OurLibGL, 'glXGetSwapIntervalMESA');
  666. // Unknown Mesa GLX extension
  667. glXReleaseBuffersMESA := GetProc(OurLibGL, 'glXReleaseBuffersMESA');
  668. glXCopySubBufferMESA := GetProc(OurLibGL, 'glXCopySubBufferMESA');
  669. // GLX_SGI_swap_control
  670. glXSwapIntervalSGI := GetProc(OurLibGL, 'glXSwapIntervalSGI');
  671. // GLX_SGI_video_sync
  672. glXGetVideoSyncSGI := GetProc(OurLibGL, 'glXGetVideoSyncSGI');
  673. glXWaitVideoSyncSGI := GetProc(OurLibGL, 'glXWaitVideoSyncSGI');
  674. GLXInitialized := True;
  675. Result := True;
  676. end;
  677. initialization
  678. InitGLX;
  679. end.