glx.pp 29 KB

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