2010-09-07 15:34:51 +00:00
|
|
|
//========================================================================
|
|
|
|
// Version information dumper
|
|
|
|
// Copyright (c) Camilla Berglund <elmindreda@elmindreda.org>
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//
|
|
|
|
// This test is a pale imitation of glxinfo(1), except not really
|
|
|
|
//
|
|
|
|
// It dumps GLFW and OpenGL version information
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2010-09-10 11:16:03 +00:00
|
|
|
#include <GL/glfw3.h>
|
2010-10-03 16:55:59 +00:00
|
|
|
#include <GL/glext.h>
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "getopt.h"
|
|
|
|
|
2011-10-08 22:55:39 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define strcasecmp(x, y) _stricmp(x, y)
|
|
|
|
#endif
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
#define API_OPENGL "gl"
|
|
|
|
#define API_OPENGL_ES "es"
|
|
|
|
|
2011-10-08 22:55:39 +00:00
|
|
|
#define PROFILE_NAME_CORE "core"
|
|
|
|
#define PROFILE_NAME_COMPAT "compat"
|
|
|
|
|
|
|
|
#define STRATEGY_NAME_NONE "none"
|
|
|
|
#define STRATEGY_NAME_LOSE "lose"
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
static void usage(void)
|
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("Usage: glfwinfo [-h] [-a API] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
|
|
|
|
printf("available APIs: " API_OPENGL " " API_OPENGL_ES "\n");
|
|
|
|
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT "\n");
|
2011-10-08 22:55:39 +00:00
|
|
|
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 16:45:23 +00:00
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
2012-09-30 13:51:46 +00:00
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
2010-11-23 16:45:23 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
static const char* get_client_api_name(int api)
|
2010-10-03 16:55:13 +00:00
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
if (api == GLFW_OPENGL_API)
|
|
|
|
return "OpenGL";
|
|
|
|
else if (api == GLFW_OPENGL_ES_API)
|
|
|
|
return "OpenGL ES";
|
2010-10-03 16:55:13 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
return "Unknown API";
|
2010-10-03 16:55:13 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 20:13:14 +00:00
|
|
|
static const char* get_profile_name_gl(GLint mask)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-11 12:33:24 +00:00
|
|
|
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
2012-09-30 13:32:50 +00:00
|
|
|
return "compatibility";
|
2010-09-11 12:33:24 +00:00
|
|
|
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
2012-09-30 13:32:50 +00:00
|
|
|
return "core";
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2010-10-03 16:55:13 +00:00
|
|
|
return "unknown";
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-10-21 20:13:14 +00:00
|
|
|
static const char* get_profile_name_glfw(int profile)
|
|
|
|
{
|
|
|
|
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
|
|
|
return "compatibility";
|
|
|
|
if (profile == GLFW_OPENGL_CORE_PROFILE)
|
|
|
|
return "core";
|
|
|
|
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
static void list_extensions(int api, int major, int minor)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
GLint count;
|
|
|
|
const GLubyte* extensions;
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("%s context supported extensions:\n", get_client_api_name(api));
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
if (api == GLFW_OPENGL_API && major > 2)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-10-03 16:55:59 +00:00
|
|
|
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
2010-09-07 15:34:51 +00:00
|
|
|
if (!glGetStringi)
|
2012-10-22 01:20:16 +00:00
|
|
|
{
|
|
|
|
glfwTerminate();
|
2010-09-07 15:34:51 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2012-10-22 01:20:16 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
puts((const char*) glGetStringi(GL_EXTENSIONS, i));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
extensions = glGetString(GL_EXTENSIONS);
|
|
|
|
while (*extensions != '\0')
|
|
|
|
{
|
|
|
|
if (*extensions == ' ')
|
|
|
|
putchar('\n');
|
|
|
|
else
|
|
|
|
putchar(*extensions);
|
|
|
|
|
|
|
|
extensions++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2012-08-30 00:17:08 +00:00
|
|
|
static GLboolean valid_version(void)
|
|
|
|
{
|
|
|
|
int major, minor, revision;
|
|
|
|
|
|
|
|
glfwGetVersion(&major, &minor, &revision);
|
|
|
|
|
|
|
|
printf("GLFW header version: %u.%u.%u\n",
|
|
|
|
GLFW_VERSION_MAJOR,
|
|
|
|
GLFW_VERSION_MINOR,
|
|
|
|
GLFW_VERSION_REVISION);
|
|
|
|
|
|
|
|
printf("GLFW library version: %u.%u.%u\n", major, minor, revision);
|
|
|
|
|
|
|
|
if (major != GLFW_VERSION_MAJOR)
|
|
|
|
{
|
|
|
|
printf("*** ERROR: GLFW major version mismatch! ***\n");
|
|
|
|
return GL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minor != GLFW_VERSION_MINOR || revision != GLFW_VERSION_REVISION)
|
|
|
|
printf("*** WARNING: GLFW version mismatch! ***\n");
|
|
|
|
|
|
|
|
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
int ch, api = 0, profile = 0, strategy = 0, major = 1, minor = 0, revision;
|
2010-09-07 15:34:51 +00:00
|
|
|
GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
|
|
|
|
GLint flags, mask;
|
2010-10-03 16:55:13 +00:00
|
|
|
GLFWwindow window;
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-30 00:17:08 +00:00
|
|
|
if (!valid_version())
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
while ((ch = getopt(argc, argv, "a:dfhlm:n:p:r:")) != -1)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
|
|
|
switch (ch)
|
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
case 'a':
|
|
|
|
if (strcasecmp(optarg, API_OPENGL) == 0)
|
|
|
|
api = GLFW_OPENGL_API;
|
|
|
|
else if (strcasecmp(optarg, API_OPENGL_ES) == 0)
|
|
|
|
api = GLFW_OPENGL_ES_API;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
case 'd':
|
|
|
|
debug = GL_TRUE;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
forward = GL_TRUE;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
usage();
|
2010-09-20 18:22:26 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2010-09-07 15:34:51 +00:00
|
|
|
case 'l':
|
|
|
|
list = GL_TRUE;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
major = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
minor = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'p':
|
2011-10-08 22:55:39 +00:00
|
|
|
if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
profile = GLFW_OPENGL_CORE_PROFILE;
|
2011-10-08 22:55:39 +00:00
|
|
|
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
profile = GLFW_OPENGL_COMPAT_PROFILE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2011-03-07 19:51:34 +00:00
|
|
|
case 'r':
|
2011-10-08 22:55:39 +00:00
|
|
|
if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
|
2011-03-07 19:51:34 +00:00
|
|
|
strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
|
2011-10-08 22:55:39 +00:00
|
|
|
else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
|
2011-03-07 19:51:34 +00:00
|
|
|
strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2010-09-07 15:34:51 +00:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2012-08-28 20:56:35 +00:00
|
|
|
// Initialize GLFW and create window
|
|
|
|
|
2011-09-15 23:16:31 +00:00
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
2012-02-07 13:58:58 +00:00
|
|
|
if (!glfwInit())
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2010-09-11 12:32:05 +00:00
|
|
|
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
|
2010-09-07 15:34:51 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2010-09-11 13:13:23 +00:00
|
|
|
if (major != 1 || minor != 0)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-08-06 15:56:41 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
|
|
|
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
if (api != 0)
|
|
|
|
glfwWindowHint(GLFW_CLIENT_API, api);
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
if (debug)
|
2012-08-06 15:56:41 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
if (forward)
|
2012-08-06 15:56:41 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
if (profile != 0)
|
2012-08-06 15:56:41 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2011-03-07 19:51:34 +00:00
|
|
|
if (strategy)
|
2012-08-06 15:56:41 +00:00
|
|
|
glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
|
2011-03-07 19:51:34 +00:00
|
|
|
|
2012-08-28 15:52:22 +00:00
|
|
|
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
// We assume here that we stand a better chance of success by leaving all
|
|
|
|
// possible details of pixel format selection to GLFW
|
|
|
|
|
2012-11-22 16:04:54 +00:00
|
|
|
window = glfwCreateWindow(200, 200, GLFW_WINDOWED, "Version", NULL);
|
2010-10-03 16:55:13 +00:00
|
|
|
if (!window)
|
2012-10-22 01:20:16 +00:00
|
|
|
{
|
|
|
|
glfwTerminate();
|
2010-09-07 15:34:51 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2012-10-22 01:20:16 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-08-10 13:29:45 +00:00
|
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
// Report client API version
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
api = glfwGetWindowParam(window, GLFW_CLIENT_API);
|
2011-05-21 15:16:32 +00:00
|
|
|
major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR);
|
|
|
|
minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR);
|
|
|
|
revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("%s context version string: \"%s\"\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
glGetString(GL_VERSION));
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("%s context version parsed by GLFW: %u.%u.%u\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
major, minor, revision);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
// Report client API context properties
|
2010-09-07 15:34:51 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
if (api == GLFW_OPENGL_API)
|
2010-09-07 15:34:51 +00:00
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
if (major >= 3)
|
|
|
|
{
|
|
|
|
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
|
|
|
|
printf("%s context flags (0x%08x):", get_client_api_name(api), flags);
|
|
|
|
|
|
|
|
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
|
|
|
|
printf(" forward-compatible");
|
|
|
|
if (flags & 0)
|
|
|
|
printf(" debug");
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
printf("%s context flags parsed by GLFW:", get_client_api_name(api));
|
|
|
|
|
|
|
|
if (glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT))
|
|
|
|
printf(" forward-compatible");
|
|
|
|
if (glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT))
|
|
|
|
printf(" debug");
|
|
|
|
putchar('\n');
|
|
|
|
}
|
2010-10-03 16:55:13 +00:00
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
if (major > 3 || (major == 3 && minor >= 2))
|
|
|
|
{
|
2012-10-21 20:13:14 +00:00
|
|
|
int profile = glfwGetWindowParam(window, GLFW_OPENGL_PROFILE);
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
|
|
|
|
printf("%s profile mask (0x%08x): %s\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
mask,
|
2012-10-21 20:13:14 +00:00
|
|
|
get_profile_name_gl(mask));
|
2012-09-30 13:32:50 +00:00
|
|
|
|
2012-10-21 20:13:14 +00:00
|
|
|
printf("%s profile mask parsed by GLFW: %s\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
get_profile_name_glfw(profile));
|
2012-09-30 13:32:50 +00:00
|
|
|
}
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("%s context renderer string: \"%s\"\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
glGetString(GL_RENDERER));
|
|
|
|
printf("%s context vendor string: \"%s\"\n",
|
|
|
|
get_client_api_name(api),
|
|
|
|
glGetString(GL_VENDOR));
|
|
|
|
|
2012-09-06 21:55:23 +00:00
|
|
|
printf("OpenGL context debug flag saved by GLFW: %s\n",
|
|
|
|
glfwGetWindowParam(window, GLFW_OPENGL_DEBUG_CONTEXT) ? "true" : "false");
|
|
|
|
|
2010-09-07 15:34:51 +00:00
|
|
|
if (major > 1)
|
|
|
|
{
|
2012-09-30 13:32:50 +00:00
|
|
|
printf("%s context shading language version: \"%s\"\n",
|
|
|
|
get_client_api_name(api),
|
2011-10-08 22:55:39 +00:00
|
|
|
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
2010-09-07 15:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-09-30 13:32:50 +00:00
|
|
|
// Report client API extensions
|
2010-09-07 15:34:51 +00:00
|
|
|
if (list)
|
2012-09-30 13:32:50 +00:00
|
|
|
list_extensions(api, major, minor);
|
2010-09-07 15:34:51 +00:00
|
|
|
|
|
|
|
glfwTerminate();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|