]> git.mxchange.org Git - simgear.git/blob - simgear/screen/extensions.cxx
Some small updates.
[simgear.git] / simgear / screen / extensions.cxx
1 /*
2  *
3  * Copyright (c) 2001 César Blecua Udías    All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * CESAR BLECUA UDIAS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  */
24
25 #include <string.h>
26
27 #include "extensions.hxx"
28 #include <simgear/debug/logstream.hxx>
29
30 static bool SGSearchExtensionsString(char *extString, char *extName) {
31     // Returns GL_TRUE if the *extName string appears in the *extString string,
32     // surrounded by white spaces, or GL_FALSE otherwise.
33
34     char *p, *end;
35     int n, extNameLen;
36
37     if ((extString == NULL) || (extName == NULL))
38         return false;
39
40     extNameLen = strlen(extName);
41
42     p=extString;
43     end = p + strlen(p);
44
45     while (p < end) {
46         n = strcspn(p, " ");
47         if ((extNameLen == n) && (strncmp(extName, p, n) == 0))
48             return GL_TRUE;
49
50         p += (n + 1);
51     }
52
53     return GL_FALSE;
54 }
55
56 bool SGIsOpenGLExtensionSupported(char *extName) {
57    // Returns GL_TRUE if the OpenGL Extension whose name is *extName
58    // is supported by the system, or GL_FALSE otherwise.
59    //
60    // The *extName string must follow the OpenGL extensions naming scheme
61    // (ie: "GL_type_extension", like GL_EXT_convolution)
62
63     return SGSearchExtensionsString((char *)glGetString(GL_EXTENSIONS),
64 extName);
65 }
66
67 #ifdef __APPLE__
68
69 #include <CoreFoundation/CoreFoundation.h>
70
71 void* macosxGetGLProcAddress(const char *func) {
72
73   /* We may want to cache the bundleRef at some point */
74   static CFBundleRef bundle = 0;
75
76   if (!bundle) {
77
78     CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
79                                                         CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
80
81     bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
82     CFRelease (bundleURL);
83   }
84
85   if (!bundle)
86     return 0;
87
88   CFStringRef functionName = CFStringCreateWithCString
89     (kCFAllocatorDefault, func, kCFStringEncodingASCII);
90   
91   void *function;
92   
93   function = CFBundleGetFunctionPointerForName (bundle, functionName);
94
95   CFRelease (functionName);
96
97   return function;
98 }
99
100 #else if !defined( WIN32 )
101
102 void *SGGetGLProcAddress(const char *func) {
103     static void *libHandle = NULL;
104     void *fptr = NULL;
105
106     /*
107      * Clear the error buffer
108      */
109     dlerror();
110
111     if (libHandle == NULL)
112         libHandle = dlopen("libGL.so", RTLD_LAZY);
113
114     if (libHandle != NULL) {
115         fptr = dlsym(libHandle, func);
116
117         char *error = dlerror();
118         if (error)
119             SG_LOG(SG_GENERAL, SG_INFO, error);
120     }
121
122     return fptr;
123 }
124
125 #endif
126