diff options
author | rtk0c <[email protected]> | 2022-06-10 11:20:03 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2022-06-10 11:20:03 -0700 |
commit | 123bea4fc8d828cec7b41949bab1db443387728e (patch) | |
tree | 24bda55695d9d34bd698afaf9b66c97fa98581c8 /source/30-game/main.cpp | |
parent | ab81521707d6ffa3f5d01ad315c0070b54bf468a (diff) |
Changeset: 69 Add option for enabling OpenGL debug mode
Diffstat (limited to 'source/30-game/main.cpp')
-rw-r--r-- | source/30-game/main.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/source/30-game/main.cpp b/source/30-game/main.cpp index c49fc0b..89f0e97 100644 --- a/source/30-game/main.cpp +++ b/source/30-game/main.cpp @@ -36,6 +36,10 @@ void GlfwErrorCallback(int error, const char* description) { fprintf(stderr, "[GLFW] Error %d: %s\n", error, description); } +void OpenGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam​) { + fprintf(stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n", (type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : ""), type, severity, message); +} + void GlfwFramebufferResizeCallback(GLFWwindow* window, int width, int height) { AppConfig::mainWindowWidth = width; AppConfig::mainWindowHeight = height; @@ -102,6 +106,7 @@ fs::path GetEnvVar(const char* name, const char* backup) { int main(int argc, char* argv[]) { using namespace Tags; + constexpr auto kOpenGLDebug = "opengl-debug"; constexpr auto kImGuiBackend = "imgui-backend"; constexpr auto kGameDataDir = "game-data-directory"; constexpr auto kGameAssetDir = "game-asset-directory"; @@ -109,6 +114,7 @@ int main(int argc, char* argv[]) { cxxopts::Options options(std::string(AppConfig::kAppName), ""); // clang-format off options.add_options() + (kOpenGLDebug, "Enable OpenGL debugging messages.") (kImGuiBackend, "ImGui backend. Options: opengl2, opengl3. Leave empty to default.", cxxopts::value<std::string>()) (kGameAssetDir, "Directory in which assets are looked up from. Can be relative paths to the executable.", cxxopts::value<std::string>()->default_value(".")) (kGameDataDir, "Directory in which game data (such as saves and options) are saved to. Leave empty to use the default directory on each platform.", cxxopts::value<std::string>()) @@ -206,7 +212,7 @@ int main(int argc, char* argv[]) { GlfwUserData glfwUserData; - GLFWwindow* window = glfwCreateWindow(1280, 720, "ImGui Command Palette Example", nullptr, nullptr); + GLFWwindow* window = glfwCreateWindow(1280, 720, "Project Brussel", nullptr, nullptr); if (window == nullptr) { return -2; } @@ -228,11 +234,36 @@ int main(int argc, char* argv[]) { glfwMakeContextCurrent(window); glfwSwapInterval(1); - // TODO setup opengl debug context if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { return -3; } +#if defined(BRUSSEL_DEV_ENV) + { + auto glVersionString = glGetString(GL_VERSION); + + int glMajorVersion; + glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion); + int glMinorVersion; + glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion); + + printf("OpenGL version (via glGetString(GL_VERSION)): %s\n", glVersionString); + printf("OpenGL version (via glGetIntegerv() with GL_MAJOR_VERSION and GL_MINOR_VERSION): %d.%d\n", glMajorVersion, glMinorVersion); + } +#endif + + bool useOpenGLDebug = args[kOpenGLDebug].as<bool>(); + if (useOpenGLDebug) { + printf("Using OpenGL debugging\n --%s", kOpenGLDebug); + + // TODO check extension KHR_debug availability + // TODO conan glad is not including any extensions + // NOTE: KHR_debug is a core extension, which means it may be available in lower version even though the feature is added in 4.3 + + glEnable(GL_DEBUG_OUTPUT); + glDebugMessageCallback(&OpenGLDebugCallback, 0); + } + IMGUI_CHECKVERSION(); auto ctx = ImGui::CreateContext(); auto& io = ImGui::GetIO(); |