1 | //======================================================================== |
2 | // GLFW 3.4 - www.glfw.org |
3 | //------------------------------------------------------------------------ |
4 | // Copyright (c) 2002-2006 Marcus Geelnard |
5 | // Copyright (c) 2006-2018 Camilla Löwy <[email protected]> |
6 | // |
7 | // This software is provided 'as-is', without any express or implied |
8 | // warranty. In no event will the authors be held liable for any damages |
9 | // arising from the use of this software. |
10 | // |
11 | // Permission is granted to anyone to use this software for any purpose, |
12 | // including commercial applications, and to alter it and redistribute it |
13 | // freely, subject to the following restrictions: |
14 | // |
15 | // 1. The origin of this software must not be misrepresented; you must not |
16 | // claim that you wrote the original software. If you use this software |
17 | // in a product, an acknowledgment in the product documentation would |
18 | // be appreciated but is not required. |
19 | // |
20 | // 2. Altered source versions must be plainly marked as such, and must not |
21 | // be misrepresented as being the original software. |
22 | // |
23 | // 3. This notice may not be removed or altered from any source |
24 | // distribution. |
25 | // |
26 | //======================================================================== |
27 | // Please use C89 style variable declarations in this file because VS 2010 |
28 | //======================================================================== |
29 | |
30 | #include "internal.h" |
31 | |
32 | ////////////////////////////////////////////////////////////////////////// |
33 | ////// GLFW internal API ////// |
34 | ////////////////////////////////////////////////////////////////////////// |
35 | |
36 | static const struct |
37 | { |
38 | int ID; |
39 | GLFWbool (*connect)(int,_GLFWplatform*); |
40 | } supportedPlatforms[] = |
41 | { |
42 | #if defined(_GLFW_WIN32) |
43 | { GLFW_PLATFORM_WIN32, _glfwConnectWin32 }, |
44 | #endif |
45 | #if defined(_GLFW_COCOA) |
46 | { GLFW_PLATFORM_COCOA, _glfwConnectCocoa }, |
47 | #endif |
48 | #if defined(_GLFW_X11) |
49 | { GLFW_PLATFORM_X11, _glfwConnectX11 }, |
50 | #endif |
51 | #if defined(_GLFW_WAYLAND) |
52 | { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland }, |
53 | #endif |
54 | }; |
55 | |
56 | GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform) |
57 | { |
58 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); |
59 | size_t i; |
60 | |
61 | if (desiredID != GLFW_ANY_PLATFORM && |
62 | desiredID != GLFW_PLATFORM_WIN32 && |
63 | desiredID != GLFW_PLATFORM_COCOA && |
64 | desiredID != GLFW_PLATFORM_WAYLAND && |
65 | desiredID != GLFW_PLATFORM_X11 && |
66 | desiredID != GLFW_PLATFORM_NULL) |
67 | { |
68 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X" , desiredID); |
69 | return GLFW_FALSE; |
70 | } |
71 | |
72 | // Only allow the Null platform if specifically requested |
73 | if (desiredID == GLFW_PLATFORM_NULL) |
74 | return _glfwConnectNull(desiredID, platform); |
75 | |
76 | if (desiredID == GLFW_ANY_PLATFORM) |
77 | { |
78 | // If there is exactly one platform available for auto-selection, let it emit the |
79 | // error on failure as the platform-specific error description may be more helpful |
80 | if (count == 1) |
81 | return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform); |
82 | |
83 | for (i = 0; i < count; i++) |
84 | { |
85 | if (supportedPlatforms[i].connect(desiredID, platform)) |
86 | return GLFW_TRUE; |
87 | } |
88 | |
89 | if (count) |
90 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform" ); |
91 | else |
92 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform" ); |
93 | } |
94 | else |
95 | { |
96 | for (i = 0; i < count; i++) |
97 | { |
98 | if (supportedPlatforms[i].ID == desiredID) |
99 | return supportedPlatforms[i].connect(desiredID, platform); |
100 | } |
101 | |
102 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported" ); |
103 | } |
104 | |
105 | return GLFW_FALSE; |
106 | } |
107 | |
108 | ////////////////////////////////////////////////////////////////////////// |
109 | ////// GLFW public API ////// |
110 | ////////////////////////////////////////////////////////////////////////// |
111 | |
112 | GLFWAPI int glfwGetPlatform(void) |
113 | { |
114 | _GLFW_REQUIRE_INIT_OR_RETURN(0); |
115 | return _glfw.platform.platformID; |
116 | } |
117 | |
118 | GLFWAPI int glfwPlatformSupported(int platformID) |
119 | { |
120 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); |
121 | size_t i; |
122 | |
123 | if (platformID != GLFW_PLATFORM_WIN32 && |
124 | platformID != GLFW_PLATFORM_COCOA && |
125 | platformID != GLFW_PLATFORM_WAYLAND && |
126 | platformID != GLFW_PLATFORM_X11 && |
127 | platformID != GLFW_PLATFORM_NULL) |
128 | { |
129 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X" , platformID); |
130 | return GLFW_FALSE; |
131 | } |
132 | |
133 | if (platformID == GLFW_PLATFORM_NULL) |
134 | return GLFW_TRUE; |
135 | |
136 | for (i = 0; i < count; i++) |
137 | { |
138 | if (platformID == supportedPlatforms[i].ID) |
139 | return GLFW_TRUE; |
140 | } |
141 | |
142 | return GLFW_FALSE; |
143 | } |
144 | |
145 | GLFWAPI const char* glfwGetVersionString(void) |
146 | { |
147 | return _GLFW_VERSION_NUMBER |
148 | #if defined(_GLFW_WIN32) |
149 | " Win32 WGL" |
150 | #endif |
151 | #if defined(_GLFW_COCOA) |
152 | " Cocoa NSGL" |
153 | #endif |
154 | #if defined(_GLFW_WAYLAND) |
155 | " Wayland" |
156 | #endif |
157 | #if defined(_GLFW_X11) |
158 | " X11 GLX" |
159 | #endif |
160 | " Null" |
161 | " EGL" |
162 | " OSMesa" |
163 | #if defined(__MINGW64_VERSION_MAJOR) |
164 | " MinGW-w64" |
165 | #elif defined(__MINGW32__) |
166 | " MinGW" |
167 | #elif defined(_MSC_VER) |
168 | " VisualC" |
169 | #endif |
170 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) |
171 | " hybrid-GPU" |
172 | #endif |
173 | #if defined(_POSIX_MONOTONIC_CLOCK) |
174 | " monotonic" |
175 | #endif |
176 | #if defined(_GLFW_BUILD_DLL) |
177 | #if defined(_WIN32) |
178 | " DLL" |
179 | #elif defined(__APPLE__) |
180 | " dynamic" |
181 | #else |
182 | " shared" |
183 | #endif |
184 | #endif |
185 | ; |
186 | } |
187 | |
188 | |