gl_capabilities.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #pragma once
  2. #include <QDebug>
  3. #include <QOpenGLContext>
  4. #include <QOpenGLExtraFunctions>
  5. #include <QString>
  6. namespace Render::GL {
  7. class GLCapabilities {
  8. public:
  9. static void log_capabilities() {
  10. auto *ctx = QOpenGLContext::currentContext();
  11. if (ctx == nullptr) {
  12. qWarning() << "GLCapabilities: No current OpenGL context";
  13. return;
  14. }
  15. auto *gl = ctx->extraFunctions();
  16. const auto format = ctx->format();
  17. qInfo() << "=== OpenGL Context Information ===";
  18. qInfo() << "Vendor:"
  19. << reinterpret_cast<const char *>(gl->glGetString(GL_VENDOR));
  20. qInfo() << "Renderer:"
  21. << reinterpret_cast<const char *>(gl->glGetString(GL_RENDERER));
  22. qInfo() << "Version:"
  23. << reinterpret_cast<const char *>(gl->glGetString(GL_VERSION));
  24. qInfo() << "GLSL Version:"
  25. << reinterpret_cast<const char *>(
  26. gl->glGetString(GL_SHADING_LANGUAGE_VERSION));
  27. qInfo() << "Context Version:" << format.majorVersion() << "."
  28. << format.minorVersion();
  29. qInfo() << "Profile:"
  30. << (format.profile() == QSurfaceFormat::CoreProfile ? "Core"
  31. : format.profile() == QSurfaceFormat::CompatibilityProfile
  32. ? "Compatibility"
  33. : "NoProfile");
  34. #ifdef Q_OS_WIN
  35. qInfo() << "Platform: Windows";
  36. #elif defined(Q_OS_LINUX)
  37. qInfo() << "Platform: Linux";
  38. #elif defined(Q_OS_MAC)
  39. qInfo() << "Platform: macOS";
  40. #else
  41. qInfo() << "Platform: Unknown";
  42. #endif
  43. const QString extensions = QString::fromLatin1(
  44. reinterpret_cast<const char *>(gl->glGetString(GL_EXTENSIONS)));
  45. qInfo() << "=== Extension Support ===";
  46. qInfo() << "GL_ARB_buffer_storage:"
  47. << extensions.contains("GL_ARB_buffer_storage");
  48. qInfo() << "GL_ARB_direct_state_access:"
  49. << extensions.contains("GL_ARB_direct_state_access");
  50. qInfo() << "GL_ARB_vertex_array_object:"
  51. << extensions.contains("GL_ARB_vertex_array_object");
  52. qInfo() << "GL_ARB_uniform_buffer_object:"
  53. << extensions.contains("GL_ARB_uniform_buffer_object");
  54. const bool hasPersistentMapping =
  55. (format.majorVersion() > 4 ||
  56. (format.majorVersion() == 4 && format.minorVersion() >= 4)) ||
  57. extensions.contains("GL_ARB_buffer_storage");
  58. qInfo() << "Persistent Buffer Mapping:"
  59. << (hasPersistentMapping ? "Supported" : "Not Supported");
  60. qInfo() << "==================================";
  61. }
  62. static auto is_extension_supported(const char *extension) -> bool {
  63. auto *ctx = QOpenGLContext::currentContext();
  64. if (ctx == nullptr) {
  65. return false;
  66. }
  67. auto *gl = ctx->extraFunctions();
  68. const QString extensions = QString::fromLatin1(
  69. reinterpret_cast<const char *>(gl->glGetString(GL_EXTENSIONS)));
  70. return extensions.contains(extension);
  71. }
  72. };
  73. } // namespace Render::GL