ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
GLInfo.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "CloudViewer.h"
9 
10 void GLFWErrorCallback(int error, const char *description) {
11  cloudViewer::utility::LogWarning("GLFW Error: {}", description);
12 }
13 
14 void TryGLVersion(int major,
15  int minor,
16  bool forwardCompat,
17  bool setProfile,
18  int profileId) {
19  using namespace cloudViewer;
20  using namespace visualization;
21 
22  std::string forwardCompatStr =
23  (forwardCompat ? "GLFW_OPENGL_FORWARD_COMPAT " : "");
24  std::string profileStr = "UnknownProfile";
25 #define CLOUDVIEWER_CHECK_PROFILESTR(p) \
26  if (profileId == p) { \
27  profileStr = #p; \
28  }
29  CLOUDVIEWER_CHECK_PROFILESTR(GLFW_OPENGL_CORE_PROFILE);
30  CLOUDVIEWER_CHECK_PROFILESTR(GLFW_OPENGL_COMPAT_PROFILE);
31  CLOUDVIEWER_CHECK_PROFILESTR(GLFW_OPENGL_ANY_PROFILE);
32 #undef CLOUDVIEWER_CHECK_PROFILESTR
33 
34  cloudViewer::utility::LogInfo("TryGLVersion: {:d}.{:d} {}{}", major, minor,
35  forwardCompatStr, profileStr);
36 
39 
40  glfwSetErrorCallback(GLFWErrorCallback);
41 #ifdef HEADLESS_RENDERING
42  glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
43 #endif
44  if (!glfwInit()) {
45  cloudViewer::utility::LogError("Failed to initialize GLFW");
46  }
47 
48  glfwWindowHint(GLFW_SAMPLES, 4);
49  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
50  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
51  if (forwardCompat) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
52  if (setProfile) glfwWindowHint(GLFW_OPENGL_PROFILE, profileId);
53  glfwWindowHint(GLFW_VISIBLE, 0);
54 
55  GLFWwindow *window_ = glfwCreateWindow(640, 480, "GLInfo", NULL, NULL);
56  if (!window_) {
57  cloudViewer::utility::LogDebug("Failed to create window");
58  glfwTerminate();
59  return;
60  } else {
61  glfwMakeContextCurrent(window_);
62  }
63 
64  auto reportGlStringFunc = [](GLenum id, std::string name) {
65 // Note: with GLFW 3.3.9 it appears that OpenGL entry points are no longer auto
66 // loaded? The else part crashes on Apple with a null pointer.
67 #ifdef __APPLE__
68  PFNGLGETSTRINGIPROC _glGetString =
69  (PFNGLGETSTRINGIPROC)glfwGetProcAddress("glGetString");
70  const auto r = _glGetString(id, 0);
71 #else
72  const auto r = glGetString(id);
73 #endif
74  if (!r) {
75  cloudViewer::utility::LogWarning("Unable to get info on {} id {:d}",
76  name, id);
77  } else {
79  reinterpret_cast<const char *>(r));
80  }
81  };
82 #define CLOUDVIEWER_REPORT_GL_STRING(n) reportGlStringFunc(n, #n)
83  CLOUDVIEWER_REPORT_GL_STRING(GL_VERSION);
84  CLOUDVIEWER_REPORT_GL_STRING(GL_RENDERER);
86  CLOUDVIEWER_REPORT_GL_STRING(GL_SHADING_LANGUAGE_VERSION);
87  // CLOUDVIEWER_REPORT_GL_STRING(GL_EXTENSIONS);
88 #undef CLOUDVIEWER_REPORT_GL_STRING
89 
90  if (window_) glfwDestroyWindow(window_);
91  glfwTerminate();
92 }
93 
94 int main(int argc, char **argv) {
95  TryGLVersion(1, 0, false, false, GLFW_OPENGL_ANY_PROFILE);
96  TryGLVersion(3, 2, true, true, GLFW_OPENGL_CORE_PROFILE);
97  TryGLVersion(4, 1, false, false, GLFW_OPENGL_ANY_PROFILE);
98  TryGLVersion(3, 3, false, true, GLFW_OPENGL_CORE_PROFILE);
99  TryGLVersion(3, 3, true, true, GLFW_OPENGL_CORE_PROFILE);
100  TryGLVersion(3, 3, false, true, GLFW_OPENGL_COMPAT_PROFILE);
101  TryGLVersion(3, 3, false, true, GLFW_OPENGL_ANY_PROFILE);
102  TryGLVersion(1, 0, false, true, GLFW_OPENGL_ANY_PROFILE);
103  return 0;
104 }
std::string name
#define CLOUDVIEWER_REPORT_GL_STRING(n)
int main(int argc, char **argv)
Definition: GLInfo.cpp:94
void TryGLVersion(int major, int minor, bool forwardCompat, bool setProfile, int profileId)
Definition: GLInfo.cpp:14
#define CLOUDVIEWER_CHECK_PROFILESTR(p)
void GLFWErrorCallback(int error, const char *description)
Definition: GLInfo.cpp:10
#define NULL
#define LogWarning(...)
Definition: Logging.h:72
#define LogInfo(...)
Definition: Logging.h:81
#define LogError(...)
Definition: Logging.h:60
#define LogDebug(...)
Definition: Logging.h:90
static void error(char *msg)
Definition: lsd.c:159
void SetVerbosityLevel(VerbosityLevel level)
Definition: Logging.cpp:89
Generic file read and write utility for python interface.