glx.pp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 Win32}
  28. {$DEFINE glx_dll := external 'unknown.dll'}
  29. uses Windows;
  30. {x$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; glx_dll
  108. glXCreateContext: function(dpy: PDisplay; vis: PXVisualInfo; shareList: GLXContext; direct: Boolean): GLXContext; cdecl; glx_dll
  109. glXDestroyContext: procedure(dpy: PDisplay; ctx: GLXContext); cdecl; glx_dll
  110. glXMakeCurrent: function(dpy: PDisplay; drawable: GLXDrawable; ctx: GLXContext): Boolean; cdecl; glx_dll
  111. glXCopyContext: procedure(dpy: PDisplay; src, dst: GLXContext; mask: LongWord); cdecl; glx_dll
  112. glXSwapBuffers: procedure(dpy: PDisplay; drawable: GLXDrawable); cdecl; glx_dll
  113. glXCreateGLXPixmap: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap): GLXPixmap; cdecl; glx_dll
  114. glXDestroyGLXPixmap: procedure(dpy: PDisplay; pixmap: GLXPixmap); cdecl; glx_dll
  115. glXQueryExtension: function(dpy: PDisplay; var errorb, event: Integer): Boolean; cdecl; glx_dll
  116. glXQueryVersion: function(dpy: PDisplay; var maj, min: Integer): Boolean; cdecl; glx_dll
  117. glXIsDirect: function(dpy: PDisplay; ctx: GLXContext): Boolean; cdecl; glx_dll
  118. glXGetConfig: function(dpy: PDisplay; visual: PXVisualInfo; attrib: Integer; var value: Integer): Integer; cdecl; glx_dll
  119. glXGetCurrentContext: function: GLXContext; cdecl; glx_dll
  120. glXGetCurrentDrawable: function: GLXDrawable; cdecl; glx_dll
  121. glXWaitGL: procedure; cdecl; glx_dll
  122. glXWaitX: procedure; cdecl; glx_dll
  123. glXUseXFont: procedure(font: XFont; first, count, list: Integer); cdecl; glx_dll
  124. // GLX 1.1 and later
  125. glXQueryExtensionsString: function(dpy: PDisplay; screen: Integer): PChar; cdecl; glx_dll
  126. glXQueryServerString: function(dpy: PDisplay; screen, name: Integer): PChar; cdecl; glx_dll
  127. glXGetClientString: function(dpy: PDisplay; name: Integer): PChar; cdecl; glx_dll
  128. // Mesa GLX Extensions
  129. glXCreateGLXPixmapMESA: function(dpy: PDisplay; visual: PXVisualInfo; pixmap: XPixmap; cmap: XColormap): GLXPixmap; cdecl; glx_dll
  130. glXReleaseBufferMESA: function(dpy: PDisplay; d: GLXDrawable): Boolean; cdecl; glx_dll
  131. glXCopySubBufferMESA: procedure(dpy: PDisplay; drawbale: GLXDrawable; x, y, width, height: Integer); cdecl; glx_dll
  132. glXGetVideoSyncSGI: function(var counter: LongWord): Integer; cdecl; glx_dll
  133. glXWaitVideoSyncSGI: function(divisor, remainder: Integer; var count: LongWord): Integer; cdecl; glx_dll
  134. // =======================================================
  135. //
  136. // =======================================================
  137. implementation
  138. type
  139. HInstance = LongWord;
  140. {$IFDEF HasGLX}
  141. var
  142. libGLX : HInstance;
  143. function GetProc(handle: HInstance; name: PChar): Pointer;
  144. begin
  145. Result := GetProcAddress(handle, name);
  146. if (Result = nil) and GLXDumpUnresolvedFunctions then
  147. WriteLn('Unresolved: ', name);
  148. end;
  149. function InitGLX: Boolean;
  150. begin
  151. Result := False;
  152. { Unix GLX is implemented as special subset of the GL interface }
  153. if libGL = 0 then exit;
  154. glXQueryVersion := GetProcAddress(libGL, 'glXQueryVersion');
  155. if @glXQueryVersion = nil then exit;
  156. glXChooseVisual := GetProc(libGLX, 'glXChooseVisual');
  157. glXCreateContext := GetProc(libGLX, 'glXCreateContext');
  158. glXDestroyContext := GetProc(libGLX, 'glXDestroyContext');
  159. glXMakeCurrent := GetProc(libGLX, 'glXMakeCurrent');
  160. glXCopyContext := GetProc(libGLX, 'glXCopyContext');
  161. glXSwapBuffers := GetProc(libGLX, 'glXSwapBuffers');
  162. glXCreateGLXPixmap := GetProc(libGLX, 'glXCreateGLXPixmap');
  163. glXDestroyGLXPixmap := GetProc(libGLX, 'glXDestroyGLXPixmap');
  164. glXQueryExtension := GetProc(libGLX, 'glXQueryExtension');
  165. glXQueryVersion := GetProc(libGLX, 'glXQueryVersion');
  166. glXIsDirect := GetProc(libGLX, 'glXIsDirect');
  167. glXGetConfig := GetProc(libGLX, 'glXGetConfig');
  168. glXGetCurrentContext := GetProc(libGLX, 'glXGetCurrentContext');
  169. glXGetCurrentDrawable := GetProc(libGLX, 'glXGetCurrentDrawable');
  170. glXWaitGL := GetProc(libGLX, 'glXWaitGL');
  171. glXWaitX := GetProc(libGLX, 'glXWaitX');
  172. glXUseXFont := GetProc(libGLX, 'glXUseXFont');
  173. // GLX 1.1 and later
  174. glXQueryExtensionsString := GetProc(libGLX, 'glXQueryExtensionsString');
  175. glXQueryServerString := GetProc(libGLX, 'glXQueryServerString');
  176. glXGetClientString := GetProc(libGLX, 'glXGetClientString');
  177. // Mesa GLX Extensions
  178. glXCreateGLXPixmapMESA := GetProc(libGLX, 'glXCreateGLXPixmapMESA');
  179. glXReleaseBufferMESA := GetProc(libGLX, 'glXReleaseBufferMESA');
  180. glXCopySubBufferMESA := GetProc(libGLX, 'glXCopySubBufferMESA');
  181. glXGetVideoSyncSGI := GetProc(libGLX, 'glXGetVideoSyncSGI');
  182. glXWaitVideoSyncSGI := GetProc(libGLX, 'glXWaitVideoSyncSGI');
  183. GLXInitialized := True;
  184. Result := True;
  185. end;
  186. {$ENDIF IFDEF HasGLX}
  187. initialization
  188. InitGLX;
  189. finalization
  190. if libGLX <> 0 then FreeLibrary(libGLX);
  191. end.
  192. {
  193. $Log$
  194. Revision 1.2 2000-09-03 22:17:18 peter
  195. * merged
  196. Revision 1.1.2.1 2000/09/03 22:14:41 peter
  197. * regenerated
  198. Revision 1.1 2000/07/13 06:34:18 michael
  199. + Initial import
  200. Revision 1.1 2000/05/31 00:36:08 alex
  201. dummy - incomplete code.
  202. }
  203. {
  204. $Log$
  205. Revision 1.2 2000-09-03 22:17:18 peter
  206. * merged
  207. Revision 1.1.2.1 2000/09/03 22:14:41 peter
  208. * regenerated
  209. }