root / trunk / linux / linux_gl.cpp

Revision 316, 5.7 kB (checked in by leo, 6 years ago)

Default OpenGL library is now libGL.so.1 to follow the LSB.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1//
2// Linux OpenGL functions
3//
4
5#include <dlfcn.h>
6#include <stdio.h>
7#include "opengl.h"
8
9static void* gl_module;
10
11// =============================================================================
12// Function pointers
13
14PFNGLXCHOOSEVISUAL pfnglXChooseVisual;
15PFNGLXCREATECONTEXT pfnglXCreateContext;
16PFNGLXDESTROYCONTEXT pfnglXDestroyContext;
17PFNGLXMAKECURRENT pfnglXMakeCurrent;
18PFNGLXCOPYCONTEXT pfnglXCopyContext;
19PFNGLXSWAPBUFFERS pfnglXSwapBuffers;
20PFNGLXCREATEGLXPIXMAP pfnglXCreateGLXPixmap;
21PFNGLXDESTROYGLXPIXMAP pfnglXDestroyGLXPixmap;
22PFNGLXQUERYEXTENSION pfnglXQueryExtension;
23PFNGLXQUERYVERSION pfnglXQueryVersion;
24PFNGLXISDIRECT pfnglXIsDirect;
25PFNGLXGETCONFIG pfnglXGetConfig;
26PFNGLXGETCURRENTCONTEXT pfnglXGetCurrentContext;
27PFNGLXGETCURRENTDRAWABLE pfnglXGetCurrentDrawable;
28PFNGLXWAITGL pfnglXWaitGL;
29PFNGLXWAITX pfnglXWaitX;
30PFNGLXUSEXFONT pfnglXUseXFont;
31PFNGLXQUERYEXTENSIONSSTRING pfnglXQueryExtensionsString;
32PFNGLXQUERYSERVERSTRING pfnglXQueryServerString;
33PFNGLXGETCLIENTSTRING pfnglXGetClientString;
34//PFNGLXCREATEGLXPIXMAPMESA pfnglXCreateGLXPixmapMESA;
35//PFNGLXRELEASEBUFFERSMESA pfnglXReleaseBuffersMESA;
36//PFNGLXCOPYSUBBUFFERMESA pfnglXCopySubBufferMESA;
37//PFNGLXSET3DFXMODEMESA pfnglXSet3DfxModeMESA;
38//PFNGLXGETVIDEOSYNCSGI pfnglXGetVideoSyncSGI;
39//PFNGLXWAITVIDEOSYNCSGI pfnglXWaitVideoSyncSGI;
40PFNGLXGETPROCADDRESSARB pfnglXGetProcAddressARB;
41
42// =============================================================================
43// Global functions
44
45void* Sys_GLGetProc (const char *symbol)
46{
47  void* func =  dlsym (gl_module, symbol);
48  const char* error = dlerror ();
49  if (error)
50    printf ("Error loading OpenGL library.\n%s\n", error);
51  return func;
52}
53
54void* Sys_GLGetExtension (const char *symbol)
55{
56  if (pfnglXGetProcAddressARB == NULL)
57    return NULL;
58  else
59    return pfnglXGetProcAddressARB ((GLubyte*)symbol);
60}
61
62bool Sys_GLOpenLibrary (const char* libname)
63{
64  const char *error;
65
66  if (libname)
67  {
68    gl_module = dlopen (libname, RTLD_LAZY|RTLD_GLOBAL);
69    error = dlerror ();
70    if (error)
71      printf ("Error loading OpenGL library.\n%s\n", error);
72  }
73
74  if (gl_module == NULL)
75  {
76    gl_module = dlopen ("libGL.so.1", RTLD_LAZY|RTLD_GLOBAL);
77    error = dlerror ();
78    if (error)
79      printf ("Error loading OpenGL library.\n%s\n", error);
80  }
81
82  if (gl_module == NULL)
83  {
84    gl_module = dlopen ("libMesaGL.so.1", RTLD_LAZY|RTLD_GLOBAL);
85    error = dlerror ();
86    if (error)
87      printf ("Error loading OpenGL library.\n%s\n", error);
88  }
89
90  if (gl_module == NULL)
91    return false;
92
93  pfnglXChooseVisual = (PFNGLXCHOOSEVISUAL) Sys_GLGetProc ("glXChooseVisual");
94  pfnglXCreateContext = (PFNGLXCREATECONTEXT) Sys_GLGetProc ("glXCreateContext");
95  pfnglXDestroyContext = (PFNGLXDESTROYCONTEXT) Sys_GLGetProc ("glXDestroyContext");
96  pfnglXMakeCurrent = (PFNGLXMAKECURRENT) Sys_GLGetProc ("glXMakeCurrent");
97  pfnglXCopyContext = (PFNGLXCOPYCONTEXT) Sys_GLGetProc ("glXCopyContext");
98  pfnglXSwapBuffers = (PFNGLXSWAPBUFFERS) Sys_GLGetProc ("glXSwapBuffers");
99  pfnglXCreateGLXPixmap = (PFNGLXCREATEGLXPIXMAP) Sys_GLGetProc ("glXCreateGLXPixmap");
100  pfnglXDestroyGLXPixmap = (PFNGLXDESTROYGLXPIXMAP) Sys_GLGetProc ("glXDestroyGLXPixmap");
101  pfnglXQueryExtension = (PFNGLXQUERYEXTENSION) Sys_GLGetProc ("glXQueryExtension");
102  pfnglXQueryVersion = (PFNGLXQUERYVERSION) Sys_GLGetProc ("glXQueryVersion");
103  pfnglXIsDirect = (PFNGLXISDIRECT) Sys_GLGetProc ("glXIsDirect");
104  pfnglXGetConfig = (PFNGLXGETCONFIG) Sys_GLGetProc ("glXGetConfig");
105  pfnglXGetCurrentContext = (PFNGLXGETCURRENTCONTEXT) Sys_GLGetProc ("glXGetCurrentContext");
106  pfnglXGetCurrentDrawable = (PFNGLXGETCURRENTDRAWABLE) Sys_GLGetProc ("glXGetCurrentDrawable");
107  pfnglXWaitGL = (PFNGLXWAITGL) Sys_GLGetProc ("glXWaitGL");
108  pfnglXWaitX = (PFNGLXWAITX) Sys_GLGetProc ("glXWaitX");
109  pfnglXUseXFont = (PFNGLXUSEXFONT) Sys_GLGetProc ("glXUseXFont");
110  pfnglXQueryExtensionsString = (PFNGLXQUERYEXTENSIONSSTRING) Sys_GLGetProc ("glXQueryExtensionsString");
111  pfnglXQueryServerString = (PFNGLXQUERYSERVERSTRING) Sys_GLGetProc ("glXQueryServerString");
112  pfnglXGetClientString = (PFNGLXGETCLIENTSTRING) Sys_GLGetProc ("glXGetClientString");
113  //  pfnglXCreateGLXPixmapMESA = (PFNGLXCREATEGLXPIXMAPMESA) Sys_GLGetProc ("glXCreateGLXPixmapMESA");
114  //  pfnglXReleaseBuffersMESA = (PFNGLXRELEASEBUFFERSMESA) Sys_GLGetProc ("glXReleaseBuffersMESA");
115  //  pfnglXCopySubBufferMESA = (PFNGLXCOPYSUBBUFFERMESA) Sys_GLGetProc ("glXCopySubBufferMESA");
116  //  pfnglXSet3DfxModeMESA = (PFNGLXSET3DFXMODEMESA) Sys_GLGetProc ("glXSet3DfxModeMESA");
117  //  pfnglXGetVideoSyncSGI = (PFNGLXGETVIDEOSYNCSGI) Sys_GLGetProc ("glXGetVideoSyncSGI");
118  //  pfnglXWaitVideoSyncSGI = (PFNGLXWAITVIDEOSYNCSGI) Sys_GLGetProc ("glXWaitVideoSyncSGI");
119  pfnglXGetProcAddressARB = (PFNGLXGETPROCADDRESSARB) Sys_GLGetProc ("glXGetProcAddressARB");
120
121  return true;
122}
123
124void Sys_GLCloseLibrary ()
125{
126  if (gl_module)
127  {
128    dlclose (gl_module);
129    gl_module = NULL;
130  }
131
132  pfnglXChooseVisual = NULL;
133  pfnglXCreateContext = NULL;
134  pfnglXDestroyContext = NULL;
135  pfnglXMakeCurrent = NULL;
136  pfnglXCopyContext = NULL;
137  pfnglXSwapBuffers = NULL;
138  pfnglXCreateGLXPixmap = NULL;
139  pfnglXDestroyGLXPixmap = NULL;
140  pfnglXQueryExtension = NULL;
141  pfnglXQueryVersion = NULL;
142  pfnglXIsDirect = NULL;
143  pfnglXGetConfig = NULL;
144  pfnglXGetCurrentContext = NULL;
145  pfnglXGetCurrentDrawable = NULL;
146  pfnglXWaitGL = NULL;
147  pfnglXWaitX = NULL;
148  pfnglXUseXFont = NULL;
149  pfnglXQueryExtensionsString = NULL;
150  pfnglXQueryServerString = NULL;
151  pfnglXGetClientString = NULL;
152  //  pfnglXCreateGLXPixmapMESA = NULL;
153  //  pfnglXReleaseBuffersMESA = NULL;
154  //  pfnglXCopySubBufferMESA = NULL;
155  //  pfnglXSet3DfxModeMESA = NULL;
156  //  pfnglXGetVideoSyncSGI = NULL;
157  //  pfnglXWaitVideoSyncSGI = NULL;
158  pfnglXGetProcAddressARB = NULL;
159}
Note: See TracBrowser for help on using the browser.