glfwinfo.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. //========================================================================
  2. // Context creation and information tool
  3. // Copyright (c) Camilla Löwy <[email protected]>
  4. //
  5. // This software is provided 'as-is', without any express or implied
  6. // warranty. In no event will the authors be held liable for any damages
  7. // arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it
  11. // freely, subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented; you must not
  14. // claim that you wrote the original software. If you use this software
  15. // in a product, an acknowledgment in the product documentation would
  16. // be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such, and must not
  19. // be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. //
  24. //========================================================================
  25. #define GLAD_GL_IMPLEMENTATION
  26. #include <glad/gl.h>
  27. #define GLAD_VULKAN_IMPLEMENTATION
  28. #include <glad/vulkan.h>
  29. #define GLFW_INCLUDE_NONE
  30. #include <GLFW/glfw3.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <stdbool.h>
  35. #include "getopt.h"
  36. #ifdef _MSC_VER
  37. #define strcasecmp(x, y) _stricmp(x, y)
  38. #endif
  39. #define API_NAME_OPENGL "gl"
  40. #define API_NAME_OPENGL_ES "es"
  41. #define API_NAME_NATIVE "native"
  42. #define API_NAME_EGL "egl"
  43. #define API_NAME_OSMESA "osmesa"
  44. #define PROFILE_NAME_CORE "core"
  45. #define PROFILE_NAME_COMPAT "compat"
  46. #define STRATEGY_NAME_NONE "none"
  47. #define STRATEGY_NAME_LOSE "lose"
  48. #define BEHAVIOR_NAME_NONE "none"
  49. #define BEHAVIOR_NAME_FLUSH "flush"
  50. #define ANGLE_TYPE_OPENGL "gl"
  51. #define ANGLE_TYPE_OPENGLES "es"
  52. #define ANGLE_TYPE_D3D9 "d3d9"
  53. #define ANGLE_TYPE_D3D11 "d3d11"
  54. #define ANGLE_TYPE_VULKAN "vk"
  55. #define ANGLE_TYPE_METAL "mtl"
  56. #define PLATFORM_NAME_ANY "any"
  57. #define PLATFORM_NAME_WIN32 "win32"
  58. #define PLATFORM_NAME_COCOA "cooca"
  59. #define PLATFORM_NAME_WL "wayland"
  60. #define PLATFORM_NAME_X11 "x11"
  61. #define PLATFORM_NAME_NULL "null"
  62. static void usage(void)
  63. {
  64. printf("Usage: glfwinfo [OPTION]...\n");
  65. printf("Options:\n");
  66. printf(" --platform=PLATFORM the platform to use ("
  67. PLATFORM_NAME_ANY " or "
  68. PLATFORM_NAME_WIN32 " or "
  69. PLATFORM_NAME_COCOA " or "
  70. PLATFORM_NAME_X11 " or "
  71. PLATFORM_NAME_WL " or "
  72. PLATFORM_NAME_NULL ")\n");
  73. printf(" -a, --client-api=API the client API to use ("
  74. API_NAME_OPENGL " or "
  75. API_NAME_OPENGL_ES ")\n");
  76. printf(" -b, --behavior=BEHAVIOR the release behavior to use ("
  77. BEHAVIOR_NAME_NONE " or "
  78. BEHAVIOR_NAME_FLUSH ")\n");
  79. printf(" -c, --context-api=API the context creation API to use ("
  80. API_NAME_NATIVE " or "
  81. API_NAME_EGL " or "
  82. API_NAME_OSMESA ")\n");
  83. printf(" -d, --debug request a debug context\n");
  84. printf(" -f, --forward require a forward-compatible context\n");
  85. printf(" -h, --help show this help\n");
  86. printf(" -l, --list-extensions list all Vulkan and client API extensions\n");
  87. printf(" --list-layers list all Vulkan layers\n");
  88. printf(" -m, --major=MAJOR the major number of the required "
  89. "client API version\n");
  90. printf(" -n, --minor=MINOR the minor number of the required "
  91. "client API version\n");
  92. printf(" -p, --profile=PROFILE the OpenGL profile to use ("
  93. PROFILE_NAME_CORE " or "
  94. PROFILE_NAME_COMPAT ")\n");
  95. printf(" -s, --robustness=STRATEGY the robustness strategy to use ("
  96. STRATEGY_NAME_NONE " or "
  97. STRATEGY_NAME_LOSE ")\n");
  98. printf(" -v, --version print version information\n");
  99. printf(" --red-bits=N the number of red bits to request\n");
  100. printf(" --green-bits=N the number of green bits to request\n");
  101. printf(" --blue-bits=N the number of blue bits to request\n");
  102. printf(" --alpha-bits=N the number of alpha bits to request\n");
  103. printf(" --depth-bits=N the number of depth bits to request\n");
  104. printf(" --stencil-bits=N the number of stencil bits to request\n");
  105. printf(" --accum-red-bits=N the number of red bits to request\n");
  106. printf(" --accum-green-bits=N the number of green bits to request\n");
  107. printf(" --accum-blue-bits=N the number of blue bits to request\n");
  108. printf(" --accum-alpha-bits=N the number of alpha bits to request\n");
  109. printf(" --aux-buffers=N the number of aux buffers to request\n");
  110. printf(" --samples=N the number of MSAA samples to request\n");
  111. printf(" --stereo request stereo rendering\n");
  112. printf(" --srgb request an sRGB capable framebuffer\n");
  113. printf(" --singlebuffer request single-buffering\n");
  114. printf(" --no-error request a context that does not emit errors\n");
  115. printf(" --angle-type=TYPE the ANGLE platform type to use ("
  116. ANGLE_TYPE_OPENGL ", "
  117. ANGLE_TYPE_OPENGLES ", "
  118. ANGLE_TYPE_D3D9 ", "
  119. ANGLE_TYPE_D3D11 ", "
  120. ANGLE_TYPE_VULKAN " or "
  121. ANGLE_TYPE_METAL ")\n");
  122. printf(" --graphics-switching request macOS graphics switching\n");
  123. printf(" --disable-xcb-surface disable VK_KHR_xcb_surface extension\n");
  124. }
  125. static void error_callback(int error, const char* description)
  126. {
  127. fprintf(stderr, "Error: %s\n", description);
  128. }
  129. static const char* get_platform_name(int platform)
  130. {
  131. if (platform == GLFW_PLATFORM_WIN32)
  132. return "Win32";
  133. else if (platform == GLFW_PLATFORM_COCOA)
  134. return "Cocoa";
  135. else if (platform == GLFW_PLATFORM_WAYLAND)
  136. return "Wayland";
  137. else if (platform == GLFW_PLATFORM_X11)
  138. return "X11";
  139. else if (platform == GLFW_PLATFORM_NULL)
  140. return "Null";
  141. return "unknown";
  142. }
  143. static const char* get_device_type_name(VkPhysicalDeviceType type)
  144. {
  145. if (type == VK_PHYSICAL_DEVICE_TYPE_OTHER)
  146. return "other";
  147. else if (type == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
  148. return "integrated GPU";
  149. else if (type == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
  150. return "discrete GPU";
  151. else if (type == VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU)
  152. return "virtual GPU";
  153. else if (type == VK_PHYSICAL_DEVICE_TYPE_CPU)
  154. return "CPU";
  155. return "unknown";
  156. }
  157. static const char* get_api_name(int api)
  158. {
  159. if (api == GLFW_OPENGL_API)
  160. return "OpenGL";
  161. else if (api == GLFW_OPENGL_ES_API)
  162. return "OpenGL ES";
  163. return "Unknown API";
  164. }
  165. static const char* get_profile_name_gl(GLint mask)
  166. {
  167. if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
  168. return PROFILE_NAME_COMPAT;
  169. if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
  170. return PROFILE_NAME_CORE;
  171. return "unknown";
  172. }
  173. static const char* get_profile_name_glfw(int profile)
  174. {
  175. if (profile == GLFW_OPENGL_COMPAT_PROFILE)
  176. return PROFILE_NAME_COMPAT;
  177. if (profile == GLFW_OPENGL_CORE_PROFILE)
  178. return PROFILE_NAME_CORE;
  179. return "unknown";
  180. }
  181. static const char* get_strategy_name_gl(GLint strategy)
  182. {
  183. if (strategy == GL_LOSE_CONTEXT_ON_RESET_ARB)
  184. return STRATEGY_NAME_LOSE;
  185. if (strategy == GL_NO_RESET_NOTIFICATION_ARB)
  186. return STRATEGY_NAME_NONE;
  187. return "unknown";
  188. }
  189. static const char* get_strategy_name_glfw(int strategy)
  190. {
  191. if (strategy == GLFW_LOSE_CONTEXT_ON_RESET)
  192. return STRATEGY_NAME_LOSE;
  193. if (strategy == GLFW_NO_RESET_NOTIFICATION)
  194. return STRATEGY_NAME_NONE;
  195. return "unknown";
  196. }
  197. static void list_context_extensions(int client, int major, int minor)
  198. {
  199. printf("%s context extensions:\n", get_api_name(client));
  200. if (client == GLFW_OPENGL_API && major > 2)
  201. {
  202. GLint count;
  203. glGetIntegerv(GL_NUM_EXTENSIONS, &count);
  204. for (int i = 0; i < count; i++)
  205. printf(" %s\n", (const char*) glGetStringi(GL_EXTENSIONS, i));
  206. }
  207. else
  208. {
  209. const GLubyte* extensions = glGetString(GL_EXTENSIONS);
  210. while (*extensions != '\0')
  211. {
  212. putchar(' ');
  213. while (*extensions != '\0' && *extensions != ' ')
  214. {
  215. putchar(*extensions);
  216. extensions++;
  217. }
  218. while (*extensions == ' ')
  219. extensions++;
  220. putchar('\n');
  221. }
  222. }
  223. }
  224. static void list_vulkan_instance_layers(void)
  225. {
  226. printf("Vulkan instance layers:\n");
  227. uint32_t lp_count;
  228. vkEnumerateInstanceLayerProperties(&lp_count, NULL);
  229. VkLayerProperties* lp = calloc(lp_count, sizeof(VkLayerProperties));
  230. vkEnumerateInstanceLayerProperties(&lp_count, lp);
  231. for (uint32_t i = 0; i < lp_count; i++)
  232. {
  233. printf(" %s (spec version %u.%u) \"%s\"\n",
  234. lp[i].layerName,
  235. VK_VERSION_MAJOR(lp[i].specVersion),
  236. VK_VERSION_MINOR(lp[i].specVersion),
  237. lp[i].description);
  238. }
  239. free(lp);
  240. }
  241. static void list_vulkan_device_layers(VkInstance instance, VkPhysicalDevice device)
  242. {
  243. printf("Vulkan device layers:\n");
  244. uint32_t lp_count;
  245. vkEnumerateDeviceLayerProperties(device, &lp_count, NULL);
  246. VkLayerProperties* lp = calloc(lp_count, sizeof(VkLayerProperties));
  247. vkEnumerateDeviceLayerProperties(device, &lp_count, lp);
  248. for (uint32_t i = 0; i < lp_count; i++)
  249. {
  250. printf(" %s (spec version %u.%u) \"%s\"\n",
  251. lp[i].layerName,
  252. VK_VERSION_MAJOR(lp[i].specVersion),
  253. VK_VERSION_MINOR(lp[i].specVersion),
  254. lp[i].description);
  255. }
  256. free(lp);
  257. }
  258. static bool valid_version(void)
  259. {
  260. int major, minor, revision;
  261. glfwGetVersion(&major, &minor, &revision);
  262. if (major != GLFW_VERSION_MAJOR)
  263. {
  264. printf("*** ERROR: GLFW major version mismatch! ***\n");
  265. return false;
  266. }
  267. if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
  268. printf("*** WARNING: GLFW version mismatch! ***\n");
  269. return true;
  270. }
  271. static void print_version(void)
  272. {
  273. int major, minor, revision;
  274. glfwGetVersion(&major, &minor, &revision);
  275. printf("GLFW header version: %u.%u.%u\n",
  276. GLFW_VERSION_MAJOR,
  277. GLFW_VERSION_MINOR,
  278. GLFW_VERSION_REVISION);
  279. printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
  280. printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
  281. }
  282. static void print_platform(void)
  283. {
  284. const int platforms[] =
  285. {
  286. GLFW_PLATFORM_WIN32,
  287. GLFW_PLATFORM_COCOA,
  288. GLFW_PLATFORM_WAYLAND,
  289. GLFW_PLATFORM_X11,
  290. GLFW_PLATFORM_NULL
  291. };
  292. printf("GLFW platform: %s\n", get_platform_name(glfwGetPlatform()));
  293. printf("GLFW supported platforms:\n");
  294. for (size_t i = 0; i < sizeof(platforms) / sizeof(platforms[0]); i++)
  295. {
  296. if (glfwPlatformSupported(platforms[i]))
  297. printf(" %s\n", get_platform_name(platforms[i]));
  298. }
  299. }
  300. int main(int argc, char** argv)
  301. {
  302. int ch;
  303. bool list_extensions = false, list_layers = false;
  304. // These duplicate the defaults for each hint
  305. int platform = GLFW_ANY_PLATFORM;
  306. int client_api = GLFW_OPENGL_API;
  307. int context_major = 1;
  308. int context_minor = 0;
  309. int context_release = GLFW_ANY_RELEASE_BEHAVIOR;
  310. int context_creation_api = GLFW_NATIVE_CONTEXT_API;
  311. int context_robustness = GLFW_NO_ROBUSTNESS;
  312. bool context_debug = false;
  313. bool context_no_error = false;
  314. bool opengl_forward = false;
  315. int opengl_profile = GLFW_OPENGL_ANY_PROFILE;
  316. int fb_red_bits = 8;
  317. int fb_green_bits = 8;
  318. int fb_blue_bits = 8;
  319. int fb_alpha_bits = 8;
  320. int fb_depth_bits = 24;
  321. int fb_stencil_bits = 8;
  322. int fb_accum_red_bits = 0;
  323. int fb_accum_green_bits = 0;
  324. int fb_accum_blue_bits = 0;
  325. int fb_accum_alpha_bits = 0;
  326. int fb_aux_buffers = 0;
  327. int fb_samples = 0;
  328. bool fb_stereo = false;
  329. bool fb_srgb = false;
  330. bool fb_doublebuffer = true;
  331. int angle_type = GLFW_ANGLE_PLATFORM_TYPE_NONE;
  332. bool cocoa_graphics_switching = false;
  333. bool disable_xcb_surface = false;
  334. enum { PLATFORM, CLIENT, CONTEXT, BEHAVIOR, DEBUG_CONTEXT, FORWARD, HELP,
  335. EXTENSIONS, LAYERS,
  336. MAJOR, MINOR, PROFILE, ROBUSTNESS, VERSION,
  337. REDBITS, GREENBITS, BLUEBITS, ALPHABITS, DEPTHBITS, STENCILBITS,
  338. ACCUMREDBITS, ACCUMGREENBITS, ACCUMBLUEBITS, ACCUMALPHABITS,
  339. AUXBUFFERS, SAMPLES, STEREO, SRGB, SINGLEBUFFER, NOERROR_SRSLY,
  340. ANGLE_TYPE, GRAPHICS_SWITCHING, XCB_SURFACE };
  341. const struct option options[] =
  342. {
  343. { "platform", 1, NULL, PLATFORM },
  344. { "behavior", 1, NULL, BEHAVIOR },
  345. { "client-api", 1, NULL, CLIENT },
  346. { "context-api", 1, NULL, CONTEXT },
  347. { "debug", 0, NULL, DEBUG_CONTEXT },
  348. { "forward", 0, NULL, FORWARD },
  349. { "help", 0, NULL, HELP },
  350. { "list-extensions", 0, NULL, EXTENSIONS },
  351. { "list-layers", 0, NULL, LAYERS },
  352. { "major", 1, NULL, MAJOR },
  353. { "minor", 1, NULL, MINOR },
  354. { "profile", 1, NULL, PROFILE },
  355. { "robustness", 1, NULL, ROBUSTNESS },
  356. { "version", 0, NULL, VERSION },
  357. { "red-bits", 1, NULL, REDBITS },
  358. { "green-bits", 1, NULL, GREENBITS },
  359. { "blue-bits", 1, NULL, BLUEBITS },
  360. { "alpha-bits", 1, NULL, ALPHABITS },
  361. { "depth-bits", 1, NULL, DEPTHBITS },
  362. { "stencil-bits", 1, NULL, STENCILBITS },
  363. { "accum-red-bits", 1, NULL, ACCUMREDBITS },
  364. { "accum-green-bits", 1, NULL, ACCUMGREENBITS },
  365. { "accum-blue-bits", 1, NULL, ACCUMBLUEBITS },
  366. { "accum-alpha-bits", 1, NULL, ACCUMALPHABITS },
  367. { "aux-buffers", 1, NULL, AUXBUFFERS },
  368. { "samples", 1, NULL, SAMPLES },
  369. { "stereo", 0, NULL, STEREO },
  370. { "srgb", 0, NULL, SRGB },
  371. { "singlebuffer", 0, NULL, SINGLEBUFFER },
  372. { "no-error", 0, NULL, NOERROR_SRSLY },
  373. { "angle-type", 1, NULL, ANGLE_TYPE },
  374. { "graphics-switching", 0, NULL, GRAPHICS_SWITCHING },
  375. { "vk-xcb-surface", 0, NULL, XCB_SURFACE },
  376. { NULL, 0, NULL, 0 }
  377. };
  378. while ((ch = getopt_long(argc, argv, "a:b:c:dfhlm:n:p:s:v", options, NULL)) != -1)
  379. {
  380. switch (ch)
  381. {
  382. case PLATFORM:
  383. if (strcasecmp(optarg, PLATFORM_NAME_ANY) == 0)
  384. platform = GLFW_ANY_PLATFORM;
  385. else if (strcasecmp(optarg, PLATFORM_NAME_WIN32) == 0)
  386. platform = GLFW_PLATFORM_WIN32;
  387. else if (strcasecmp(optarg, PLATFORM_NAME_COCOA) == 0)
  388. platform = GLFW_PLATFORM_COCOA;
  389. else if (strcasecmp(optarg, PLATFORM_NAME_WL) == 0)
  390. platform = GLFW_PLATFORM_WAYLAND;
  391. else if (strcasecmp(optarg, PLATFORM_NAME_X11) == 0)
  392. platform = GLFW_PLATFORM_X11;
  393. else if (strcasecmp(optarg, PLATFORM_NAME_NULL) == 0)
  394. platform = GLFW_PLATFORM_NULL;
  395. else
  396. {
  397. usage();
  398. exit(EXIT_FAILURE);
  399. }
  400. break;
  401. case 'a':
  402. case CLIENT:
  403. if (strcasecmp(optarg, API_NAME_OPENGL) == 0)
  404. client_api = GLFW_OPENGL_API;
  405. else if (strcasecmp(optarg, API_NAME_OPENGL_ES) == 0)
  406. client_api = GLFW_OPENGL_ES_API;
  407. else
  408. {
  409. usage();
  410. exit(EXIT_FAILURE);
  411. }
  412. break;
  413. case 'b':
  414. case BEHAVIOR:
  415. if (strcasecmp(optarg, BEHAVIOR_NAME_NONE) == 0)
  416. context_release = GLFW_RELEASE_BEHAVIOR_NONE;
  417. else if (strcasecmp(optarg, BEHAVIOR_NAME_FLUSH) == 0)
  418. context_release = GLFW_RELEASE_BEHAVIOR_FLUSH;
  419. else
  420. {
  421. usage();
  422. exit(EXIT_FAILURE);
  423. }
  424. break;
  425. case 'c':
  426. case CONTEXT:
  427. if (strcasecmp(optarg, API_NAME_NATIVE) == 0)
  428. context_creation_api = GLFW_NATIVE_CONTEXT_API;
  429. else if (strcasecmp(optarg, API_NAME_EGL) == 0)
  430. context_creation_api = GLFW_EGL_CONTEXT_API;
  431. else if (strcasecmp(optarg, API_NAME_OSMESA) == 0)
  432. context_creation_api = GLFW_OSMESA_CONTEXT_API;
  433. else
  434. {
  435. usage();
  436. exit(EXIT_FAILURE);
  437. }
  438. break;
  439. case 'd':
  440. case DEBUG_CONTEXT:
  441. context_debug = true;
  442. break;
  443. case 'f':
  444. case FORWARD:
  445. opengl_forward = true;
  446. break;
  447. case 'h':
  448. case HELP:
  449. usage();
  450. exit(EXIT_SUCCESS);
  451. case 'l':
  452. case EXTENSIONS:
  453. list_extensions = true;
  454. break;
  455. case LAYERS:
  456. list_layers = true;
  457. break;
  458. case 'm':
  459. case MAJOR:
  460. context_major = atoi(optarg);
  461. break;
  462. case 'n':
  463. case MINOR:
  464. context_minor = atoi(optarg);
  465. break;
  466. case 'p':
  467. case PROFILE:
  468. if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
  469. opengl_profile = GLFW_OPENGL_CORE_PROFILE;
  470. else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
  471. opengl_profile = GLFW_OPENGL_COMPAT_PROFILE;
  472. else
  473. {
  474. usage();
  475. exit(EXIT_FAILURE);
  476. }
  477. break;
  478. case 's':
  479. case ROBUSTNESS:
  480. if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
  481. context_robustness = GLFW_NO_RESET_NOTIFICATION;
  482. else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
  483. context_robustness = GLFW_LOSE_CONTEXT_ON_RESET;
  484. else
  485. {
  486. usage();
  487. exit(EXIT_FAILURE);
  488. }
  489. break;
  490. case 'v':
  491. case VERSION:
  492. print_version();
  493. exit(EXIT_SUCCESS);
  494. case REDBITS:
  495. if (strcmp(optarg, "-") == 0)
  496. fb_red_bits = GLFW_DONT_CARE;
  497. else
  498. fb_red_bits = atoi(optarg);
  499. break;
  500. case GREENBITS:
  501. if (strcmp(optarg, "-") == 0)
  502. fb_green_bits = GLFW_DONT_CARE;
  503. else
  504. fb_green_bits = atoi(optarg);
  505. break;
  506. case BLUEBITS:
  507. if (strcmp(optarg, "-") == 0)
  508. fb_blue_bits = GLFW_DONT_CARE;
  509. else
  510. fb_blue_bits = atoi(optarg);
  511. break;
  512. case ALPHABITS:
  513. if (strcmp(optarg, "-") == 0)
  514. fb_alpha_bits = GLFW_DONT_CARE;
  515. else
  516. fb_alpha_bits = atoi(optarg);
  517. break;
  518. case DEPTHBITS:
  519. if (strcmp(optarg, "-") == 0)
  520. fb_depth_bits = GLFW_DONT_CARE;
  521. else
  522. fb_depth_bits = atoi(optarg);
  523. break;
  524. case STENCILBITS:
  525. if (strcmp(optarg, "-") == 0)
  526. fb_stencil_bits = GLFW_DONT_CARE;
  527. else
  528. fb_stencil_bits = atoi(optarg);
  529. break;
  530. case ACCUMREDBITS:
  531. if (strcmp(optarg, "-") == 0)
  532. fb_accum_red_bits = GLFW_DONT_CARE;
  533. else
  534. fb_accum_red_bits = atoi(optarg);
  535. break;
  536. case ACCUMGREENBITS:
  537. if (strcmp(optarg, "-") == 0)
  538. fb_accum_green_bits = GLFW_DONT_CARE;
  539. else
  540. fb_accum_green_bits = atoi(optarg);
  541. break;
  542. case ACCUMBLUEBITS:
  543. if (strcmp(optarg, "-") == 0)
  544. fb_accum_blue_bits = GLFW_DONT_CARE;
  545. else
  546. fb_accum_blue_bits = atoi(optarg);
  547. break;
  548. case ACCUMALPHABITS:
  549. if (strcmp(optarg, "-") == 0)
  550. fb_accum_alpha_bits = GLFW_DONT_CARE;
  551. else
  552. fb_accum_alpha_bits = atoi(optarg);
  553. break;
  554. case AUXBUFFERS:
  555. if (strcmp(optarg, "-") == 0)
  556. fb_aux_buffers = GLFW_DONT_CARE;
  557. else
  558. fb_aux_buffers = atoi(optarg);
  559. break;
  560. case SAMPLES:
  561. if (strcmp(optarg, "-") == 0)
  562. fb_samples = GLFW_DONT_CARE;
  563. else
  564. fb_samples = atoi(optarg);
  565. break;
  566. case STEREO:
  567. fb_stereo = true;
  568. break;
  569. case SRGB:
  570. fb_srgb = true;
  571. break;
  572. case SINGLEBUFFER:
  573. fb_doublebuffer = false;
  574. break;
  575. case NOERROR_SRSLY:
  576. context_no_error = true;
  577. break;
  578. case ANGLE_TYPE:
  579. if (strcmp(optarg, ANGLE_TYPE_OPENGL) == 0)
  580. angle_type = GLFW_ANGLE_PLATFORM_TYPE_OPENGL;
  581. else if (strcmp(optarg, ANGLE_TYPE_OPENGLES) == 0)
  582. angle_type = GLFW_ANGLE_PLATFORM_TYPE_OPENGLES;
  583. else if (strcmp(optarg, ANGLE_TYPE_D3D9) == 0)
  584. angle_type = GLFW_ANGLE_PLATFORM_TYPE_D3D9;
  585. else if (strcmp(optarg, ANGLE_TYPE_D3D11) == 0)
  586. angle_type = GLFW_ANGLE_PLATFORM_TYPE_D3D11;
  587. else if (strcmp(optarg, ANGLE_TYPE_VULKAN) == 0)
  588. angle_type = GLFW_ANGLE_PLATFORM_TYPE_VULKAN;
  589. else if (strcmp(optarg, ANGLE_TYPE_METAL) == 0)
  590. angle_type = GLFW_ANGLE_PLATFORM_TYPE_METAL;
  591. else
  592. {
  593. usage();
  594. exit(EXIT_FAILURE);
  595. }
  596. break;
  597. case GRAPHICS_SWITCHING:
  598. cocoa_graphics_switching = true;
  599. break;
  600. case XCB_SURFACE:
  601. disable_xcb_surface = true;
  602. break;
  603. default:
  604. usage();
  605. exit(EXIT_FAILURE);
  606. }
  607. }
  608. // Initialize GLFW and create window
  609. if (!valid_version())
  610. exit(EXIT_FAILURE);
  611. glfwSetErrorCallback(error_callback);
  612. glfwInitHint(GLFW_PLATFORM, platform);
  613. glfwInitHint(GLFW_COCOA_MENUBAR, false);
  614. glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, angle_type);
  615. glfwInitHint(GLFW_X11_XCB_VULKAN_SURFACE, !disable_xcb_surface);
  616. if (!glfwInit())
  617. exit(EXIT_FAILURE);
  618. print_version();
  619. print_platform();
  620. glfwWindowHint(GLFW_VISIBLE, false);
  621. glfwWindowHint(GLFW_CLIENT_API, client_api);
  622. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, context_major);
  623. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, context_minor);
  624. glfwWindowHint(GLFW_CONTEXT_RELEASE_BEHAVIOR, context_release);
  625. glfwWindowHint(GLFW_CONTEXT_CREATION_API, context_creation_api);
  626. glfwWindowHint(GLFW_CONTEXT_ROBUSTNESS, context_robustness);
  627. glfwWindowHint(GLFW_CONTEXT_DEBUG, context_debug);
  628. glfwWindowHint(GLFW_CONTEXT_NO_ERROR, context_no_error);
  629. glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, opengl_forward);
  630. glfwWindowHint(GLFW_OPENGL_PROFILE, opengl_profile);
  631. glfwWindowHint(GLFW_RED_BITS, fb_red_bits);
  632. glfwWindowHint(GLFW_BLUE_BITS, fb_blue_bits);
  633. glfwWindowHint(GLFW_GREEN_BITS, fb_green_bits);
  634. glfwWindowHint(GLFW_ALPHA_BITS, fb_alpha_bits);
  635. glfwWindowHint(GLFW_DEPTH_BITS, fb_depth_bits);
  636. glfwWindowHint(GLFW_STENCIL_BITS, fb_stencil_bits);
  637. glfwWindowHint(GLFW_ACCUM_RED_BITS, fb_accum_red_bits);
  638. glfwWindowHint(GLFW_ACCUM_GREEN_BITS, fb_accum_green_bits);
  639. glfwWindowHint(GLFW_ACCUM_BLUE_BITS, fb_accum_blue_bits);
  640. glfwWindowHint(GLFW_ACCUM_ALPHA_BITS, fb_accum_alpha_bits);
  641. glfwWindowHint(GLFW_AUX_BUFFERS, fb_aux_buffers);
  642. glfwWindowHint(GLFW_SAMPLES, fb_samples);
  643. glfwWindowHint(GLFW_STEREO, fb_stereo);
  644. glfwWindowHint(GLFW_SRGB_CAPABLE, fb_srgb);
  645. glfwWindowHint(GLFW_DOUBLEBUFFER, fb_doublebuffer);
  646. glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, cocoa_graphics_switching);
  647. GLFWwindow* window = glfwCreateWindow(200, 200, "Version", NULL, NULL);
  648. if (window)
  649. {
  650. glfwMakeContextCurrent(window);
  651. gladLoadGL(glfwGetProcAddress);
  652. const GLenum error = glGetError();
  653. if (error != GL_NO_ERROR)
  654. printf("*** OpenGL error after make current: 0x%08x ***\n", error);
  655. // Report client API version
  656. const int client = glfwGetWindowAttrib(window, GLFW_CLIENT_API);
  657. const int major = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
  658. const int minor = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
  659. const int revision = glfwGetWindowAttrib(window, GLFW_CONTEXT_REVISION);
  660. const int profile = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
  661. printf("%s context version string: \"%s\"\n",
  662. get_api_name(client),
  663. glGetString(GL_VERSION));
  664. printf("%s context version parsed by GLFW: %u.%u.%u\n",
  665. get_api_name(client),
  666. major, minor, revision);
  667. // Report client API context properties
  668. if (client == GLFW_OPENGL_API)
  669. {
  670. if (major >= 3)
  671. {
  672. GLint flags;
  673. glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
  674. printf("%s context flags (0x%08x):", get_api_name(client), flags);
  675. if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
  676. printf(" forward-compatible");
  677. if (flags & 2/*GL_CONTEXT_FLAG_DEBUG_BIT*/)
  678. printf(" debug");
  679. if (flags & GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB)
  680. printf(" robustness");
  681. if (flags & 8/*GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR*/)
  682. printf(" no-error");
  683. putchar('\n');
  684. printf("%s context flags parsed by GLFW:", get_api_name(client));
  685. if (glfwGetWindowAttrib(window, GLFW_OPENGL_FORWARD_COMPAT))
  686. printf(" forward-compatible");
  687. if (glfwGetWindowAttrib(window, GLFW_CONTEXT_DEBUG))
  688. printf(" debug");
  689. if (glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS) == GLFW_LOSE_CONTEXT_ON_RESET)
  690. printf(" robustness");
  691. if (glfwGetWindowAttrib(window, GLFW_CONTEXT_NO_ERROR))
  692. printf(" no-error");
  693. putchar('\n');
  694. }
  695. if (major >= 4 || (major == 3 && minor >= 2))
  696. {
  697. GLint mask;
  698. glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
  699. printf("%s profile mask (0x%08x): %s\n",
  700. get_api_name(client),
  701. mask,
  702. get_profile_name_gl(mask));
  703. printf("%s profile mask parsed by GLFW: %s\n",
  704. get_api_name(client),
  705. get_profile_name_glfw(profile));
  706. }
  707. if (GLAD_GL_ARB_robustness)
  708. {
  709. const int robustness = glfwGetWindowAttrib(window, GLFW_CONTEXT_ROBUSTNESS);
  710. GLint strategy;
  711. glGetIntegerv(GL_RESET_NOTIFICATION_STRATEGY_ARB, &strategy);
  712. printf("%s robustness strategy (0x%08x): %s\n",
  713. get_api_name(client),
  714. strategy,
  715. get_strategy_name_gl(strategy));
  716. printf("%s robustness strategy parsed by GLFW: %s\n",
  717. get_api_name(client),
  718. get_strategy_name_glfw(robustness));
  719. }
  720. }
  721. printf("%s context renderer string: \"%s\"\n",
  722. get_api_name(client),
  723. glGetString(GL_RENDERER));
  724. printf("%s context vendor string: \"%s\"\n",
  725. get_api_name(client),
  726. glGetString(GL_VENDOR));
  727. if (major >= 2)
  728. {
  729. printf("%s context shading language version: \"%s\"\n",
  730. get_api_name(client),
  731. glGetString(GL_SHADING_LANGUAGE_VERSION));
  732. }
  733. printf("%s framebuffer:\n", get_api_name(client));
  734. GLint redbits, greenbits, bluebits, alphabits, depthbits, stencilbits;
  735. if (client == GLFW_OPENGL_API && profile == GLFW_OPENGL_CORE_PROFILE)
  736. {
  737. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  738. GL_BACK_LEFT,
  739. GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE,
  740. &redbits);
  741. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  742. GL_BACK_LEFT,
  743. GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE,
  744. &greenbits);
  745. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  746. GL_BACK_LEFT,
  747. GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE,
  748. &bluebits);
  749. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  750. GL_BACK_LEFT,
  751. GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE,
  752. &alphabits);
  753. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  754. GL_DEPTH,
  755. GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE,
  756. &depthbits);
  757. glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER,
  758. GL_STENCIL,
  759. GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE,
  760. &stencilbits);
  761. }
  762. else
  763. {
  764. glGetIntegerv(GL_RED_BITS, &redbits);
  765. glGetIntegerv(GL_GREEN_BITS, &greenbits);
  766. glGetIntegerv(GL_BLUE_BITS, &bluebits);
  767. glGetIntegerv(GL_ALPHA_BITS, &alphabits);
  768. glGetIntegerv(GL_DEPTH_BITS, &depthbits);
  769. glGetIntegerv(GL_STENCIL_BITS, &stencilbits);
  770. }
  771. printf(" red: %u green: %u blue: %u alpha: %u depth: %u stencil: %u\n",
  772. redbits, greenbits, bluebits, alphabits, depthbits, stencilbits);
  773. if (client == GLFW_OPENGL_ES_API ||
  774. GLAD_GL_ARB_multisample ||
  775. major > 1 || minor >= 3)
  776. {
  777. GLint samples, samplebuffers;
  778. glGetIntegerv(GL_SAMPLES, &samples);
  779. glGetIntegerv(GL_SAMPLE_BUFFERS, &samplebuffers);
  780. printf(" samples: %u sample buffers: %u\n", samples, samplebuffers);
  781. }
  782. if (client == GLFW_OPENGL_API && profile != GLFW_OPENGL_CORE_PROFILE)
  783. {
  784. GLint accumredbits, accumgreenbits, accumbluebits, accumalphabits;
  785. GLint auxbuffers;
  786. glGetIntegerv(GL_ACCUM_RED_BITS, &accumredbits);
  787. glGetIntegerv(GL_ACCUM_GREEN_BITS, &accumgreenbits);
  788. glGetIntegerv(GL_ACCUM_BLUE_BITS, &accumbluebits);
  789. glGetIntegerv(GL_ACCUM_ALPHA_BITS, &accumalphabits);
  790. glGetIntegerv(GL_AUX_BUFFERS, &auxbuffers);
  791. printf(" accum red: %u accum green: %u accum blue: %u accum alpha: %u aux buffers: %u\n",
  792. accumredbits, accumgreenbits, accumbluebits, accumalphabits, auxbuffers);
  793. }
  794. if (list_extensions)
  795. list_context_extensions(client, major, minor);
  796. glfwDestroyWindow(window);
  797. }
  798. glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
  799. window = glfwCreateWindow(200, 200, "Version", NULL, NULL);
  800. if (!window)
  801. {
  802. glfwTerminate();
  803. exit(EXIT_FAILURE);
  804. }
  805. printf("Vulkan loader: %s\n",
  806. glfwVulkanSupported() ? "available" : "missing");
  807. if (glfwVulkanSupported())
  808. {
  809. gladLoadVulkanUserPtr(NULL, (GLADuserptrloadfunc) glfwGetInstanceProcAddress, NULL);
  810. uint32_t loader_version = VK_API_VERSION_1_0;
  811. if (vkEnumerateInstanceVersion)
  812. {
  813. uint32_t version;
  814. if (vkEnumerateInstanceVersion(&version) == VK_SUCCESS)
  815. loader_version = version;
  816. }
  817. printf("Vulkan loader API version: %i.%i\n",
  818. VK_VERSION_MAJOR(loader_version),
  819. VK_VERSION_MINOR(loader_version));
  820. uint32_t glfw_re_count;
  821. const char** glfw_re = glfwGetRequiredInstanceExtensions(&glfw_re_count);
  822. uint32_t re_count = glfw_re_count;
  823. const char** re = calloc(glfw_re_count, sizeof(char*));
  824. if (glfw_re)
  825. {
  826. printf("Vulkan window surface required instance extensions:\n");
  827. for (uint32_t i = 0; i < glfw_re_count; i++)
  828. {
  829. printf(" %s\n", glfw_re[i]);
  830. re[i] = glfw_re[i];
  831. }
  832. }
  833. else
  834. printf("Vulkan window surface extensions missing\n");
  835. uint32_t ep_count;
  836. vkEnumerateInstanceExtensionProperties(NULL, &ep_count, NULL);
  837. VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
  838. vkEnumerateInstanceExtensionProperties(NULL, &ep_count, ep);
  839. if (list_extensions)
  840. {
  841. printf("Vulkan instance extensions:\n");
  842. for (uint32_t i = 0; i < ep_count; i++)
  843. printf(" %s (spec version %u)\n", ep[i].extensionName, ep[i].specVersion);
  844. }
  845. bool portability_enumeration = false;
  846. for (uint32_t i = 0; i < ep_count; i++)
  847. {
  848. if (strcmp(ep[i].extensionName, "VK_KHR_portability_enumeration") != 0)
  849. continue;
  850. re_count++;
  851. re = realloc((void*) re, sizeof(char*) * re_count);
  852. re[re_count - 1] = "VK_KHR_portability_enumeration";
  853. portability_enumeration = true;
  854. }
  855. free(ep);
  856. if (list_layers)
  857. list_vulkan_instance_layers();
  858. VkApplicationInfo ai = { VK_STRUCTURE_TYPE_APPLICATION_INFO };
  859. ai.pApplicationName = "glfwinfo";
  860. ai.applicationVersion = VK_MAKE_VERSION(GLFW_VERSION_MAJOR,
  861. GLFW_VERSION_MINOR,
  862. GLFW_VERSION_REVISION);
  863. if (loader_version >= VK_API_VERSION_1_1)
  864. ai.apiVersion = VK_API_VERSION_1_1;
  865. else
  866. ai.apiVersion = VK_API_VERSION_1_0;
  867. VkInstanceCreateInfo ici = { VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO };
  868. ici.pApplicationInfo = &ai;
  869. ici.enabledExtensionCount = re_count;
  870. ici.ppEnabledExtensionNames = re;
  871. if (portability_enumeration)
  872. ici.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
  873. VkInstance instance = VK_NULL_HANDLE;
  874. if (vkCreateInstance(&ici, NULL, &instance) != VK_SUCCESS)
  875. {
  876. glfwTerminate();
  877. exit(EXIT_FAILURE);
  878. }
  879. free((void*) re);
  880. gladLoadVulkanUserPtr(NULL, (GLADuserptrloadfunc) glfwGetInstanceProcAddress, instance);
  881. if (glfw_re_count)
  882. {
  883. VkSurfaceKHR surface = VK_NULL_HANDLE;
  884. if (glfwCreateWindowSurface(instance, window, NULL, &surface) == VK_SUCCESS)
  885. {
  886. printf("Vulkan window surface created successfully\n");
  887. vkDestroySurfaceKHR(instance, surface, NULL);
  888. }
  889. else
  890. printf("Failed to create Vulkan window surface\n");
  891. }
  892. uint32_t pd_count;
  893. vkEnumeratePhysicalDevices(instance, &pd_count, NULL);
  894. VkPhysicalDevice* pd = calloc(pd_count, sizeof(VkPhysicalDevice));
  895. vkEnumeratePhysicalDevices(instance, &pd_count, pd);
  896. for (uint32_t i = 0; i < pd_count; i++)
  897. {
  898. VkPhysicalDeviceProperties pdp;
  899. vkGetPhysicalDeviceProperties(pd[i], &pdp);
  900. uint32_t qfp_count;
  901. vkGetPhysicalDeviceQueueFamilyProperties(pd[i], &qfp_count, NULL);
  902. uint32_t ep_count;
  903. vkEnumerateDeviceExtensionProperties(pd[i], NULL, &ep_count, NULL);
  904. VkExtensionProperties* ep = calloc(ep_count, sizeof(VkExtensionProperties));
  905. vkEnumerateDeviceExtensionProperties(pd[i], NULL, &ep_count, ep);
  906. if (portability_enumeration)
  907. {
  908. bool conformant = true;
  909. for (uint32_t j = 0; j < ep_count; j++)
  910. {
  911. if (strcmp(ep[j].extensionName, "VK_KHR_portability_subset") == 0)
  912. {
  913. conformant = false;
  914. break;
  915. }
  916. }
  917. printf("Vulkan %s %s device: \"%s\" (API version %i.%i)\n",
  918. conformant ? "conformant" : "non-conformant",
  919. get_device_type_name(pdp.deviceType),
  920. pdp.deviceName,
  921. VK_VERSION_MAJOR(pdp.apiVersion),
  922. VK_VERSION_MINOR(pdp.apiVersion));
  923. }
  924. else
  925. {
  926. printf("Vulkan %s device: \"%s\" (API version %i.%i)\n",
  927. get_device_type_name(pdp.deviceType),
  928. pdp.deviceName,
  929. VK_VERSION_MAJOR(pdp.apiVersion),
  930. VK_VERSION_MINOR(pdp.apiVersion));
  931. }
  932. if (glfw_re_count)
  933. {
  934. printf("Vulkan device queue family presentation support:\n");
  935. for (uint32_t j = 0; j < qfp_count; j++)
  936. {
  937. printf(" %u: ", j);
  938. if (glfwGetPhysicalDevicePresentationSupport(instance, pd[i], j))
  939. printf("supported\n");
  940. else
  941. printf("no\n");
  942. }
  943. }
  944. if (list_extensions)
  945. {
  946. printf("Vulkan device extensions:\n");
  947. for (uint32_t j = 0; j < ep_count; j++)
  948. printf(" %s (spec version %u)\n", ep[j].extensionName, ep[j].specVersion);
  949. }
  950. free(ep);
  951. if (list_layers)
  952. list_vulkan_device_layers(instance, pd[i]);
  953. }
  954. free(pd);
  955. vkDestroyInstance(instance, NULL);
  956. }
  957. glfwDestroyWindow(window);
  958. glfwTerminate();
  959. exit(EXIT_SUCCESS);
  960. }