1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// Copyright (c) 2018-2024 www.open3d.org
// SPDX-License-Identifier: MIT
// ----------------------------------------------------------------------------
#include "open3d/Open3D.h"
void GLFWErrorCallback(int error, const char *description) {
open3d::utility::LogWarning("GLFW Error: {}", description);
}
void TryGLVersion(int major,
int minor,
bool forwardCompat,
bool setProfile,
int profileId) {
using namespace open3d;
using namespace visualization;
std::string forwardCompatStr =
(forwardCompat ? "GLFW_OPENGL_FORWARD_COMPAT " : "");
std::string profileStr = "UnknownProfile";
// Some versions of GCC reports Wstringop-overflow error if string storage
// is not reserved. This might be related to a bug reported here:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96963
profileStr.reserve(32);
#define OPEN3D_CHECK_PROFILESTR(p) \
if (profileId == p) { \
profileStr = #p; \
}
OPEN3D_CHECK_PROFILESTR(GLFW_OPENGL_CORE_PROFILE);
OPEN3D_CHECK_PROFILESTR(GLFW_OPENGL_COMPAT_PROFILE);
OPEN3D_CHECK_PROFILESTR(GLFW_OPENGL_ANY_PROFILE);
#undef OPEN3D_CHECK_PROFILESTR
utility::LogInfo("TryGLVersion: {:d}.{:d} {}{}", major, minor,
forwardCompatStr, profileStr);
utility::SetVerbosityLevel(utility::VerbosityLevel::Debug);
glfwSetErrorCallback(GLFWErrorCallback);
#ifdef HEADLESS_RENDERING
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
#endif
if (!glfwInit()) {
utility::LogError("Failed to initialize GLFW");
}
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
if (forwardCompat) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
if (setProfile) glfwWindowHint(GLFW_OPENGL_PROFILE, profileId);
glfwWindowHint(GLFW_VISIBLE, 0);
GLFWwindow *window_ = glfwCreateWindow(640, 480, "GLInfo", NULL, NULL);
if (!window_) {
utility::LogDebug("Failed to create window");
glfwTerminate();
return;
} else {
glfwMakeContextCurrent(window_);
}
auto reportGlStringFunc = [](GLenum id, std::string name) {
// Note: with GLFW 3.3.9 it appears that OpenGL entry points are no longer auto
// loaded? The else part crashes on Apple with a null pointer.
#ifdef __APPLE__
PFNGLGETSTRINGIPROC _glGetString =
(PFNGLGETSTRINGIPROC)glfwGetProcAddress("glGetString");
const auto r = _glGetString(id, 0);
#else
const auto r = glGetString(id);
#endif
if (!r) {
utility::LogWarning("Unable to get info on {} id {:d}", name, id);
} else {
utility::LogDebug("{}:\t{}", name,
reinterpret_cast<const char *>(r));
}
};
#define OPEN3D_REPORT_GL_STRING(n) reportGlStringFunc(n, #n)
OPEN3D_REPORT_GL_STRING(GL_VERSION);
OPEN3D_REPORT_GL_STRING(GL_RENDERER);
OPEN3D_REPORT_GL_STRING(GL_VENDOR);
OPEN3D_REPORT_GL_STRING(GL_SHADING_LANGUAGE_VERSION);
// OPEN3D_REPORT_GL_STRING(GL_EXTENSIONS);
#undef OPEN3D_REPORT_GL_STRING
if (window_) glfwDestroyWindow(window_);
glfwTerminate();
}
int main(int argc, char **argv) {
TryGLVersion(1, 0, false, false, GLFW_OPENGL_ANY_PROFILE);
TryGLVersion(3, 2, true, true, GLFW_OPENGL_CORE_PROFILE);
TryGLVersion(4, 1, false, false, GLFW_OPENGL_ANY_PROFILE);
TryGLVersion(3, 3, false, true, GLFW_OPENGL_CORE_PROFILE);
TryGLVersion(3, 3, true, true, GLFW_OPENGL_CORE_PROFILE);
TryGLVersion(3, 3, false, true, GLFW_OPENGL_COMPAT_PROFILE);
TryGLVersion(3, 3, false, true, GLFW_OPENGL_ANY_PROFILE);
TryGLVersion(1, 0, false, true, GLFW_OPENGL_ANY_PROFILE);
return 0;
}
|