glfwinfo.c 35 KB

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