]> git.mxchange.org Git - simgear.git/blob - simgear/screen/extensions.cxx
4acf0e260160efcea9e8492fc48f75dc080f1bdf
[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 #ifdef WIN32
28 #include <windows.h>
29 #endif
30
31 #if !defined( WIN32 ) && !defined( __APPLE__ )
32 #include <dlfcn.h>
33 #endif
34
35 #include "extensions.hxx"
36
37 bool SGSearchExtensionsString(char *extString, char *extName) {
38     // Returns GL_TRUE if the *extName string appears in the *extString string,
39     // surrounded by white spaces, or GL_FALSE otherwise.
40
41     char *p, *end;
42     int n, extNameLen;
43
44     extNameLen = strlen(extName);
45
46     p=extString;
47     end = p + strlen(p);
48
49     while (p < end) {
50         n = strcspn(p, " ");
51         if ((extNameLen == n) && (strncmp(extName, p, n) == 0))
52             return GL_TRUE;
53
54         p += (n + 1);
55     }
56
57     return GL_FALSE;
58 }
59
60 bool SGIsOpenGLExtensionSupported(char *extName) {
61    // Returns GL_TRUE if the OpenGL Extension whose name is *extName
62    // is supported by the system, or GL_FALSE otherwise.
63    //
64    // The *extName string must follow the OpenGL extensions naming scheme
65    // (ie: "GL_type_extension", like GL_EXT_convolution)
66
67     return SGSearchExtensionsString((char *)glGetString(GL_EXTENSIONS),
68 extName);
69 }
70
71 #ifdef __APPLE__
72
73 #include <CoreFoundation/CoreFoundation.h>
74
75 void* macosxGetGLProcAddress(const char *func) {
76
77   /* We may want to cache the bundleRef at some point */
78   static CFBundleRef bundle = 0;
79
80   if (!bundle) {
81
82     CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
83                                                         CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
84
85     bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
86     CFRelease (bundleURL);
87   }
88
89   if (!bundle)
90     return 0;
91
92   CFStringRef functionName = CFStringCreateWithCString
93     (kCFAllocatorDefault, func, kCFStringEncodingASCII);
94   
95   void *function;
96   
97   function = CFBundleGetFunctionPointerForName (bundle, functionName);
98
99   CFRelease (functionName);
100
101   return function;
102 }
103
104 #endif