add check for OpenGL Debug extension support (#498)
* Fix crash on Osx Arm * Check OpenGL extension support safely * Replace on cstring * Moved to Window.cpp and added extensions cache
This commit is contained in:
parent
7b90fa15db
commit
0042d8a60c
@ -6,6 +6,7 @@
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
||||
#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<std::string> 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<const char *>(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();
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user