glx.pp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. {
  2. $Id$
  3. Translation of the Mesa GLX headers for FreePascal
  4. Copyright (C) 1999 Sebastian Guenther
  5. Mesa 3-D graphics library
  6. Version: 3.0
  7. Copyright (C) 1995-1998 Brian Paul
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public
  10. License as published by the Free Software Foundation; either
  11. version 2 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Library General Public License for more details.
  16. You should have received a copy of the GNU Library General Public
  17. License along with this library; if not, write to the Free
  18. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 Linux}
  28. uses
  29. 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. // GLX_EXT_visual_info extension
  68. GLX_X_VISUAL_TYPE_EXT = $22;
  69. GLX_TRANSPARENT_TYPE_EXT = $23;
  70. GLX_TRANSPARENT_INDEX_VALUE_EXT = $24;
  71. GLX_TRANSPARENT_RED_VALUE_EXT = $25;
  72. GLX_TRANSPARENT_GREEN_VALUE_EXT = $26;
  73. GLX_TRANSPARENT_BLUE_VALUE_EXT = $27;
  74. GLX_TRANSPARENT_ALPHA_VALUE_EXT = $28;
  75. // Error codes returned by glXGetConfig:
  76. GLX_BAD_SCREEN = 1;
  77. GLX_BAD_ATTRIBUTE = 2;
  78. GLX_NO_EXTENSION = 3;
  79. GLX_BAD_VISUAL = 4;
  80. GLX_BAD_CONTEXT = 5;
  81. GLX_BAD_VALUE = 6;
  82. GLX_BAD_ENUM = 7;
  83. // GLX 1.1 and later:
  84. GLX_VENDOR = 1;
  85. GLX_VERSION = 2;
  86. GLX_EXTENSIONS = 3;
  87. // GLX_visual_info extension
  88. GLX_TRUE_COLOR_EXT = $8002;
  89. GLX_DIRECT_COLOR_EXT = $8003;
  90. GLX_PSEUDO_COLOR_EXT = $8004;
  91. GLX_STATIC_COLOR_EXT = $8005;
  92. GLX_GRAY_SCALE_EXT = $8006;
  93. GLX_STATIC_GRAY_EXT = $8007;
  94. GLX_NONE_EXT = $8000;
  95. GLX_TRANSPARENT_RGB_EXT = $8008;
  96. GLX_TRANSPARENT_INDEX_EXT = $8009;
  97. type
  98. // From XLib:
  99. XPixmap = TXID;
  100. XFont = TXID;
  101. XColormap = TXID;
  102. GLXContext = Pointer;
  103. GLXPixmap = TXID;
  104. GLXDrawable = TXID;
  105. GLXContextID = TXID;
  106. var
  107. glXChooseVisual: function(dpy: PDisplay; screen: Integer; var attribList: Integer): PXVisualInfo; cdecl; cdecl;
  108. glXCreateContext: function(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: Boolean): GLXContext; cdecl; cdecl;
  109. glXDestroyContext: procedure(dpy: PDisplay; ctx: GLXContext); cdecl; cdecl;
  110. glXMakeCurrent: function(dpy: PDisplay; drawable: GLXDrawable; ctx: GLXContext): Boolean; cdecl; cdecl;
  111. glXCopyContext: procedure(dpy: PDisplay; src, dst: GLXContext; mask: LongWord); cdecl; cdecl;
  112. glXSwapBuffers: procedure(dpy: PDisplay; drawable: GLXDrawable); cdecl; cdecl;
  113. glXCreateGLXPixmap: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap): GLXPixmap; cdecl; cdecl;
  114. glXDestroyGLXPixmap: procedure(dpy: PDisplay; pixmap: GLXPixmap); cdecl; cdecl;
  115. glXQueryExtension: function(dpy: PDisplay; var errorb, event: Integer): Boolean; cdecl; cdecl;
  116. glXQueryVersion: function(dpy: PDisplay; var maj, min: Integer): Boolean; cdecl; cdecl;
  117. glXIsDirect: function(dpy: PDisplay; ctx: GLXContext): Boolean; cdecl; cdecl;
  118. glXGetConfig: function(dpy: PDisplay; visual: PXVisualInfo; attrib: Integer; var value: Integer): Integer; cdecl; cdecl;
  119. glXGetCurrentContext: function: GLXContext; cdecl; cdecl;
  120. glXGetCurrentDrawable: function: GLXDrawable; cdecl; cdecl;
  121. glXWaitGL: procedure; cdecl; cdecl;
  122. glXWaitX: procedure; cdecl; cdecl;
  123. glXUseXFont: procedure(font: XFont; first, count, list: Integer); cdecl; cdecl;
  124. // GLX 1.1 and later
  125. glXQueryExtensionsString: function(dpy: PDisplay; screen: Integer): PChar; cdecl; cdecl;
  126. glXQueryServerString: function(dpy: PDisplay; screen, name: Integer): PChar; cdecl; cdecl;
  127. glXGetClientString: function(dpy: PDisplay; name: Integer): PChar; cdecl; cdecl;
  128. // Mesa GLX Extensions
  129. glXCreateGLXPixmapMESA: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap; cmap: XColormap): GLXPixmap; cdecl; cdecl;
  130. glXReleaseBufferMESA: function(dpy: PDisplay; d: GLXDrawable): Boolean; cdecl; cdecl;
  131. glXCopySubBufferMESA: procedure(dpy: PDisplay; drawbale: GLXDrawable; x, y, width, height: Integer); cdecl; cdecl;
  132. glXGetVideoSyncSGI: function(var counter: LongWord): Integer; cdecl; cdecl;
  133. glXWaitVideoSyncSGI: function(divisor, remainder: Integer; var count: LongWord): Integer; cdecl; cdecl;
  134. // =======================================================
  135. //
  136. // =======================================================
  137. implementation
  138. {$LINKLIB m}
  139. function dlopen(AFile: PChar; mode: LongInt): Pointer; external 'dl';
  140. function dlclose(handle: Pointer): LongInt; external 'dl';
  141. function dlsym(handle: Pointer; name: PChar): Pointer; external 'dl';
  142. function LoadLibrary(name: PChar): Pointer;
  143. begin
  144. Result := dlopen(name, $101 {RTLD_GLOBAL or RTLD_LAZY});
  145. end;
  146. function GetProc(handle: Pointer; name: PChar): Pointer;
  147. begin
  148. Result := dlsym(handle, name);
  149. if (Result = nil) and GLXDumpUnresolvedFunctions then
  150. WriteLn('Unresolved: ', name);
  151. end;
  152. var
  153. libGLX: Pointer;
  154. function InitGLXFromLibrary(libname:pchar): Boolean;
  155. begin
  156. Result := False;
  157. libGLX := LoadLibrary(libname);
  158. if not Assigned(libGLX) then exit;
  159. glXChooseVisual := GetProc(libglx, 'glXChooseVisual');
  160. glXCreateContext := GetProc(libglx, 'glXCreateContext');
  161. glXDestroyContext := GetProc(libglx, 'glXDestroyContext');
  162. glXMakeCurrent := GetProc(libglx, 'glXMakeCurrent');
  163. glXCopyContext := GetProc(libglx, 'glXCopyContext');
  164. glXSwapBuffers := GetProc(libglx, 'glXSwapBuffers');
  165. glXCreateGLXPixmap := GetProc(libglx, 'glXCreateGLXPixmap');
  166. glXDestroyGLXPixmap := GetProc(libglx, 'glXDestroyGLXPixmap');
  167. glXQueryExtension := GetProc(libglx, 'glXQueryExtension');
  168. glXQueryVersion := GetProc(libglx, 'glXQueryVersion');
  169. glXIsDirect := GetProc(libglx, 'glXIsDirect');
  170. glXGetConfig := GetProc(libglx, 'glXGetConfig');
  171. glXGetCurrentContext := GetProc(libglx, 'glXGetCurrentContext');
  172. glXGetCurrentDrawable := GetProc(libglx, 'glXGetCurrentDrawable');
  173. glXWaitGL := GetProc(libglx, 'glXWaitGL');
  174. glXWaitX := GetProc(libglx, 'glXWaitX');
  175. glXUseXFont := GetProc(libglx, 'glXUseXFont');
  176. // GLX 1.1 and later
  177. glXQueryExtensionsString := GetProc(libglx, 'glXQueryExtensionsString');
  178. glXQueryServerString := GetProc(libglx, 'glXQueryServerString');
  179. glXGetClientString := GetProc(libglx, 'glXGetClientString');
  180. // Mesa GLX Extensions
  181. glXCreateGLXPixmapMESA := GetProc(libglx, 'glXCreateGLXPixmapMESA');
  182. glXReleaseBufferMESA := GetProc(libglx, 'glXReleaseBufferMESA');
  183. glXCopySubBufferMESA := GetProc(libglx, 'glXCopySubBufferMESA');
  184. glXGetVideoSyncSGI := GetProc(libglx, 'glXGetVideoSyncSGI');
  185. glXWaitVideoSyncSGI := GetProc(libglx, 'glXWaitVideoSyncSGI');
  186. GLXInitialized := True;
  187. Result := True;
  188. end;
  189. function InitGLX: Boolean;
  190. begin
  191. Result := InitGLXFromLibrary('libGL.so') or
  192. InitGLXFromLibrary('libGL.so.1') or
  193. InitGLXFromLibrary('libMesaGL.so') or
  194. InitGLXFromLibrary('libMesaGL.so.3');
  195. end;
  196. initialization
  197. InitGLX;
  198. finalization
  199. if Assigned(libGLX) then dlclose(libGLX);
  200. end.
  201. {
  202. $Log$
  203. Revision 1.2 2000-10-01 22:17:59 peter
  204. * new bounce demo
  205. Revision 1.1.2.1 2000/10/01 22:12:28 peter
  206. * new demo
  207. Revision 1.1 2000/07/13 06:34:18 michael
  208. + Initial import
  209. Revision 1.1 2000/05/31 00:36:08 alex
  210. dummy - incomplete code.
  211. }
  212. {
  213. $Log$
  214. Revision 1.2 2000-10-01 22:17:59 peter
  215. * new bounce demo
  216. Revision 1.1.2.1 2000/10/01 22:12:28 peter
  217. * new demo
  218. }