diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 0c1cccee..4e68877f 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "debug/Logger.hpp" #include "graphics/core/ImageData.hpp" @@ -32,6 +33,7 @@ bool Window::fullscreen = false; CursorShape Window::cursor = CursorShape::ARROW; static util::ObjectsKeeper observers_keeper; +static std::unordered_set extensionsCache; static const char* gl_error_name(int error) { switch (error) { @@ -223,8 +225,10 @@ int Window::initialize(DisplaySettings* settings) { } } - glEnable(GL_DEBUG_OUTPUT); - glDebugMessageCallback(gl_message_callback, 0); + if (isGlExtensionSupported("GL_KHR_debug")) { + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(gl_message_callback, nullptr); + } glViewport(0, 0, width, height); glClearColor(0.0f, 0.0f, 0.0f, 1); @@ -501,3 +505,29 @@ void Window::setIcon(const ImageData* image) { image->getData()}; glfwSetWindowIcon(window, 1, &icon); } + +static void initGlExtensionsCache() { + if (!extensionsCache.empty()) { + return; + } + + GLint numExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + + for (GLint i = 0; i < numExtensions; ++i) { + const char *ext = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + if (ext) { + extensionsCache.insert(ext); + } + } +} + +bool Window::isGlExtensionSupported(const char *extension) { + if (!extension || !*extension) { + return false; + } + + initGlExtensionsCache(); + + return extensionsCache.find(extension) != extensionsCache.end(); +} diff --git a/src/window/Window.hpp b/src/window/Window.hpp index 77fd7076..b81da395 100644 --- a/src/window/Window.hpp +++ b/src/window/Window.hpp @@ -24,6 +24,7 @@ class Window { static CursorShape cursor; static bool tryToMaximize(GLFWwindow* window, GLFWmonitor* monitor); + static bool isGlExtensionSupported(const char *extension); public: static int posX; static int posY;