1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 18:58:52 -05:00
glfw/tests/glfwinfo.c

289 lines
8.4 KiB
C
Raw Normal View History

2010-09-07 11:34:51 -04: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
//
//========================================================================
#include <GL/glfw3.h>
#include <GL/glext.h>
2010-09-07 11:34:51 -04:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "getopt.h"
2011-10-08 18:55:39 -04:00
#ifdef _MSC_VER
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#define PROFILE_NAME_CORE "core"
#define PROFILE_NAME_COMPAT "compat"
#define PROFILE_NAME_ES2 "es2"
#define STRATEGY_NAME_NONE "none"
#define STRATEGY_NAME_LOSE "lose"
2010-09-07 11:34:51 -04:00
static void usage(void)
{
2012-02-06 20:30:52 -05:00
printf("Usage: glfwinfo [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
2011-10-08 18:55:39 -04:00
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
2010-09-07 11:34:51 -04:00
}
2010-11-23 11:45:23 -05:00
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description);
}
static const char* get_glfw_profile_name(int profile)
{
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
2011-10-08 18:55:39 -04:00
return PROFILE_NAME_COMPAT;
else if (profile == GLFW_OPENGL_CORE_PROFILE)
2011-10-08 18:55:39 -04:00
return PROFILE_NAME_CORE;
2010-11-15 13:28:06 -05:00
else if (profile == GLFW_OPENGL_ES2_PROFILE)
2011-10-08 18:55:39 -04:00
return PROFILE_NAME_ES2;
return "unknown";
}
2010-09-07 11:34:51 -04:00
static const char* get_profile_name(GLint mask)
{
2010-09-11 08:33:24 -04:00
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
2011-10-08 18:55:39 -04:00
return PROFILE_NAME_COMPAT;
2010-09-11 08:33:24 -04:00
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
2011-10-08 18:55:39 -04:00
return PROFILE_NAME_CORE;
2010-09-07 11:34:51 -04:00
return "unknown";
2010-09-07 11:34:51 -04:00
}
static void list_extensions(int major, int minor)
{
int i;
GLint count;
const GLubyte* extensions;
printf("OpenGL context supported extensions:\n");
if (major > 2)
{
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
2010-09-07 11:34:51 -04:00
if (!glGetStringi)
exit(EXIT_FAILURE);
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');
}
int main(int argc, char** argv)
{
2011-03-07 14:51:34 -05:00
int ch, profile = 0, strategy = 0, major = 1, minor = 0, revision;
2010-09-07 11:34:51 -04:00
GLboolean debug = GL_FALSE, forward = GL_FALSE, list = GL_FALSE;
GLint flags, mask;
GLFWwindow window;
2010-09-07 11:34:51 -04:00
2011-03-07 14:51:34 -05:00
while ((ch = getopt(argc, argv, "dfhlm:n:p:r:")) != -1)
2010-09-07 11:34:51 -04:00
{
switch (ch)
{
case 'd':
debug = GL_TRUE;
break;
case 'f':
forward = GL_TRUE;
break;
case 'h':
usage();
2010-09-20 14:22:26 -04:00
exit(EXIT_SUCCESS);
2010-09-07 11:34:51 -04:00
case 'l':
list = GL_TRUE;
break;
case 'm':
major = atoi(optarg);
break;
case 'n':
minor = atoi(optarg);
break;
case 'p':
2011-10-08 18:55:39 -04:00
if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
2010-09-07 11:34:51 -04:00
profile = GLFW_OPENGL_CORE_PROFILE;
2011-10-08 18:55:39 -04:00
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
2010-09-07 11:34:51 -04:00
profile = GLFW_OPENGL_COMPAT_PROFILE;
2011-10-08 18:55:39 -04:00
else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
2010-11-15 13:28:06 -05:00
profile = GLFW_OPENGL_ES2_PROFILE;
2010-09-07 11:34:51 -04:00
else
{
usage();
exit(EXIT_FAILURE);
}
break;
2011-03-07 14:51:34 -05:00
case 'r':
2011-10-08 18:55:39 -04:00
if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
2011-03-07 14:51:34 -05:00
strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
2011-10-08 18:55:39 -04:00
else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
2011-03-07 14:51:34 -05:00
strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
else
{
usage();
exit(EXIT_FAILURE);
}
break;
2010-09-07 11:34:51 -04:00
default:
usage();
exit(EXIT_FAILURE);
}
}
argc -= optind;
argv += optind;
glfwSetErrorCallback(error_callback);
2012-02-07 08:58:58 -05:00
if (!glfwInit())
2010-09-07 11:34:51 -04:00
{
fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError()));
2010-09-07 11:34:51 -04:00
exit(EXIT_FAILURE);
}
2010-09-11 09:13:23 -04:00
if (major != 1 || minor != 0)
2010-09-07 11:34:51 -04:00
{
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
}
if (debug)
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
if (forward)
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
if (profile != 0)
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, profile);
2011-03-07 14:51:34 -05:00
if (strategy)
glfwOpenWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
2010-09-07 11:34:51 -04:00
// We assume here that we stand a better chance of success by leaving all
// possible details of pixel format selection to GLFW
2010-10-04 12:17:53 -04:00
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
if (!window)
2010-09-07 11:34:51 -04:00
exit(EXIT_FAILURE);
// Report GLFW version
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 ||
minor != GLFW_VERSION_MINOR ||
revision != GLFW_VERSION_REVISION)
2011-10-08 18:55:39 -04:00
{
2010-09-07 11:34:51 -04:00
printf("*** WARNING: GLFW version mismatch! ***\n");
2011-10-08 18:55:39 -04:00
}
2010-09-07 11:34:51 -04:00
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
2010-09-07 11:34:51 -04:00
// Report OpenGL version
printf("OpenGL context version string: \"%s\"\n", glGetString(GL_VERSION));
major = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MAJOR);
minor = glfwGetWindowParam(window, GLFW_OPENGL_VERSION_MINOR);
revision = glfwGetWindowParam(window, GLFW_OPENGL_REVISION);
2010-09-07 11:34:51 -04:00
printf("OpenGL context version parsed by GLFW: %u.%u.%u\n", major, minor, revision);
// Report OpenGL context properties
if (major >= 3)
{
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
printf("OpenGL context flags:");
if (flags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT)
puts(" forward-compatible");
else
puts(" none");
printf("OpenGL forward-compatible flag parsed by GLFW: %s\n",
glfwGetWindowParam(window, GLFW_OPENGL_FORWARD_COMPAT) ? "true" : "false");
2010-09-07 11:34:51 -04:00
}
if (major > 3 || (major == 3 && minor >= 2))
{
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
2012-03-05 14:22:23 -05:00
printf("OpenGL profile mask: %s (0x%08x)\n", get_profile_name(mask), mask);
printf("OpenGL profile parsed by GLFW: %s\n",
get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE)));
2010-09-07 11:34:51 -04:00
}
printf("OpenGL context renderer string: \"%s\"\n", glGetString(GL_RENDERER));
printf("OpenGL context vendor string: \"%s\"\n", glGetString(GL_VENDOR));
if (major > 1)
{
printf("OpenGL context shading language version: \"%s\"\n",
2011-10-08 18:55:39 -04:00
glGetString(GL_SHADING_LANGUAGE_VERSION));
2010-09-07 11:34:51 -04:00
}
// Report OpenGL extensions
if (list)
list_extensions(major, minor);
glfwTerminate();
exit(EXIT_SUCCESS);
}