From 7a6ca85081d76ac7a6dfd3e8b9ee3d820300233b Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 12 Apr 2024 11:38:30 +0200 Subject: [PATCH] Expose OpenGL debugging as a normal setting --- builtin/settingtypes.txt | 3 ++ irr/include/SIrrCreationParameters.h | 8 +++- irr/src/CEGLManager.cpp | 6 +-- irr/src/CIrrDeviceSDL.cpp | 25 ++++++---- irr/src/COGLESDriver.cpp | 8 ++-- irr/src/COpenGLDriver.cpp | 8 ++-- irr/src/CWGLManager.cpp | 5 +- irr/src/OpenGL/Driver.cpp | 71 ++++------------------------ irr/src/OpenGL/Driver.h | 5 +- src/client/renderingengine.cpp | 1 + src/defaultsettings.cpp | 4 +- 11 files changed, 49 insertions(+), 95 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 610144067..f154e34b6 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1893,6 +1893,9 @@ texture_min_size (Base texture size) int 64 1 32768 # Systems with a low-end GPU (or no GPU) would benefit from smaller values. client_mesh_chunk (Client Mesh Chunksize) int 1 1 16 +# Enables debug and error-checking in the OpenGL driver. +opengl_debug (OpenGL debug) bool false + [**Sound] # Comma-separated list of AL and ALC extensions that should not be used. # Useful for testing. See al_extensions.[h,cpp] for details. diff --git a/irr/include/SIrrCreationParameters.h b/irr/include/SIrrCreationParameters.h index 0cd1a9218..4eedde50f 100644 --- a/irr/include/SIrrCreationParameters.h +++ b/irr/include/SIrrCreationParameters.h @@ -45,10 +45,11 @@ struct SIrrlichtCreationParameters #endif PrivateData(0), #ifdef IRR_MOBILE_PATHS - OGLES2ShaderPath("media/Shaders/") + OGLES2ShaderPath("media/Shaders/"), #else - OGLES2ShaderPath("../../media/Shaders/") + OGLES2ShaderPath("../../media/Shaders/"), #endif + DriverDebug(false) { } @@ -224,6 +225,9 @@ struct SIrrlichtCreationParameters /** This is about the shaders which can be found in media/Shaders by default. It's only necessary to set when using OGL-ES 2.0 */ irr::io::path OGLES2ShaderPath; + + //! Enable debug and error checks in video driver. + bool DriverDebug; }; } // end namespace irr diff --git a/irr/src/CEGLManager.cpp b/irr/src/CEGLManager.cpp index 465a31613..ffe7a44cf 100644 --- a/irr/src/CEGLManager.cpp +++ b/irr/src/CEGLManager.cpp @@ -529,7 +529,8 @@ bool CEGLManager::swapBuffers() bool CEGLManager::testEGLError() { -#if defined(EGL_VERSION_1_0) && defined(_DEBUG) + if (!Params.DriverDebug) + return false; EGLint status = eglGetError(); switch (status) { @@ -582,9 +583,6 @@ bool CEGLManager::testEGLError() }; return true; -#else - return false; -#endif } } diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp index d332d01c6..9362da385 100644 --- a/irr/src/CIrrDeviceSDL.cpp +++ b/irr/src/CIrrDeviceSDL.cpp @@ -388,6 +388,16 @@ bool CIrrDeviceSDL::createWindow() if (createWindowWithContext()) return true; + if (CreationParams.DriverDebug) { + CreationParams.DriverDebug = false; + if (createWindowWithContext()) { + os::Printer::log("DriverDebug reduced due to lack of support!"); + // Turn it back on because the GL driver can maybe still do something useful. + CreationParams.DriverDebug = true; + return true; + } + } + while (CreationParams.AntiAlias > 0) { CreationParams.AntiAlias--; if (createWindowWithContext()) { @@ -449,7 +459,8 @@ bool CIrrDeviceSDL::createWindow() return false; } -bool CIrrDeviceSDL::createWindowWithContext() { +bool CIrrDeviceSDL::createWindowWithContext() +{ u32 SDL_Flags = 0; if (CreationParams.Fullscreen) { @@ -465,6 +476,8 @@ bool CIrrDeviceSDL::createWindowWithContext() { SDL_Flags |= SDL_WINDOW_MAXIMIZED; SDL_Flags |= SDL_WINDOW_OPENGL; + SDL_GL_ResetAttributes(); + #ifdef _IRR_EMSCRIPTEN_PLATFORM_ if (Width != 0 || Height != 0) emscripten_set_canvas_size(Width, Height); @@ -528,13 +541,9 @@ bool CIrrDeviceSDL::createWindowWithContext() { default:; } -/* -Makes context creation fail on some Android devices. -See discussion in https://github.com/minetest/minetest/pull/14498. -#ifdef _DEBUG - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); -#endif -*/ + if (CreationParams.DriverDebug) { + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG); + } if (CreationParams.Bits == 16) { SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); diff --git a/irr/src/COGLESDriver.cpp b/irr/src/COGLESDriver.cpp index 4376fff08..524aedd50 100644 --- a/irr/src/COGLESDriver.cpp +++ b/irr/src/COGLESDriver.cpp @@ -1177,7 +1177,9 @@ void COGLES1Driver::setMaterial(const SMaterial &material) //! prints error if an error happened. bool COGLES1Driver::testGLError(int code) { -#ifdef _DEBUG + if (!Params.DriverDebug) + return false; + GLenum g = glGetError(); switch (g) { case GL_NO_ERROR: @@ -1201,11 +1203,7 @@ bool COGLES1Driver::testGLError(int code) os::Printer::log("GL_OUT_OF_MEMORY", core::stringc(code).c_str(), ELL_ERROR); break; }; - // _IRR_DEBUG_BREAK_IF(true); return true; -#else - return false; -#endif } //! sets the needed renderstates diff --git a/irr/src/COpenGLDriver.cpp b/irr/src/COpenGLDriver.cpp index ef560e331..0d3f18e2b 100644 --- a/irr/src/COpenGLDriver.cpp +++ b/irr/src/COpenGLDriver.cpp @@ -1642,7 +1642,9 @@ void COpenGLDriver::setMaterial(const SMaterial &material) //! prints error if an error happened. bool COpenGLDriver::testGLError(int code) { -#ifdef _DEBUG + if (!Params.DriverDebug) + return false; + GLenum g = glGetError(); switch (g) { case GL_NO_ERROR: @@ -1674,11 +1676,7 @@ bool COpenGLDriver::testGLError(int code) break; #endif }; - // _IRR_DEBUG_BREAK_IF(true); return true; -#else - return false; -#endif } //! sets the needed renderstates diff --git a/irr/src/CWGLManager.cpp b/irr/src/CWGLManager.cpp index 9c071a9e8..785524fbc 100644 --- a/irr/src/CWGLManager.cpp +++ b/irr/src/CWGLManager.cpp @@ -179,9 +179,8 @@ bool CWGLManager::initialize(const SIrrlichtCreationParameters ¶ms, const SE const bool pixel_format_supported = (wglExtensions.find("WGL_ARB_pixel_format") != -1); const bool multi_sample_supported = ((wglExtensions.find("WGL_ARB_multisample") != -1) || (wglExtensions.find("WGL_EXT_multisample") != -1) || (wglExtensions.find("WGL_3DFX_multisample") != -1)); -#ifdef _DEBUG - os::Printer::log("WGL_extensions", wglExtensions); -#endif + if (params.DriverDebug) + os::Printer::log("WGL_extensions", wglExtensions); // Without a GL context we can't call wglGetProcAddress so store this for later FunctionPointers[0] = (void *)wglGetProcAddress("wglCreateContextAttribsARB"); diff --git a/irr/src/OpenGL/Driver.cpp b/irr/src/OpenGL/Driver.cpp index fc66995a3..3d6a908ee 100644 --- a/irr/src/OpenGL/Driver.cpp +++ b/irr/src/OpenGL/Driver.cpp @@ -143,7 +143,7 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms MaterialRenderer2DActive(0), MaterialRenderer2DTexture(0), MaterialRenderer2DNoTexture(0), CurrentRenderMode(ERM_NONE), Transformation3DChanged(true), OGLES2ShaderPath(params.OGLES2ShaderPath), - ColorFormat(ECF_R8G8B8), ContextManager(contextManager) + ColorFormat(ECF_R8G8B8), ContextManager(contextManager), EnableErrorTest(params.DriverDebug) { #ifdef _DEBUG setDebugName("Driver"); @@ -158,7 +158,10 @@ COpenGL3DriverBase::COpenGL3DriverBase(const SIrrlichtCreationParameters ¶ms ExposedData = ContextManager->getContext(); ContextManager->activateContext(ExposedData, false); GL.LoadAllProcedures(ContextManager); - GL.DebugMessageCallback(debugCb, this); + if (EnableErrorTest) { + GL.Enable(GL_DEBUG_OUTPUT); + GL.DebugMessageCallback(debugCb, this); + } initQuadsIndices(); } @@ -1125,7 +1128,9 @@ void COpenGL3DriverBase::setMaterial(const SMaterial &material) //! prints error if an error happened. bool COpenGL3DriverBase::testGLError(int code) { -#ifdef _DEBUG + if (!EnableErrorTest) + return false; + GLenum g = GL.GetError(); switch (g) { case GL_NO_ERROR: @@ -1144,66 +1149,6 @@ bool COpenGL3DriverBase::testGLError(int code) break; }; return true; -#else - return false; -#endif -} - -//! prints error if an error happened. -bool COpenGL3DriverBase::testEGLError() -{ -#if defined(EGL_VERSION_1_0) && defined(_DEBUG) - EGLint g = eglGetError(); - switch (g) { - case EGL_SUCCESS: - return false; - case EGL_NOT_INITIALIZED: - os::Printer::log("Not Initialized", ELL_ERROR); - break; - case EGL_BAD_ACCESS: - os::Printer::log("Bad Access", ELL_ERROR); - break; - case EGL_BAD_ALLOC: - os::Printer::log("Bad Alloc", ELL_ERROR); - break; - case EGL_BAD_ATTRIBUTE: - os::Printer::log("Bad Attribute", ELL_ERROR); - break; - case EGL_BAD_CONTEXT: - os::Printer::log("Bad Context", ELL_ERROR); - break; - case EGL_BAD_CONFIG: - os::Printer::log("Bad Config", ELL_ERROR); - break; - case EGL_BAD_CURRENT_SURFACE: - os::Printer::log("Bad Current Surface", ELL_ERROR); - break; - case EGL_BAD_DISPLAY: - os::Printer::log("Bad Display", ELL_ERROR); - break; - case EGL_BAD_SURFACE: - os::Printer::log("Bad Surface", ELL_ERROR); - break; - case EGL_BAD_MATCH: - os::Printer::log("Bad Match", ELL_ERROR); - break; - case EGL_BAD_PARAMETER: - os::Printer::log("Bad Parameter", ELL_ERROR); - break; - case EGL_BAD_NATIVE_PIXMAP: - os::Printer::log("Bad Native Pixmap", ELL_ERROR); - break; - case EGL_BAD_NATIVE_WINDOW: - os::Printer::log("Bad Native Window", ELL_ERROR); - break; - case EGL_CONTEXT_LOST: - os::Printer::log("Context Lost", ELL_ERROR); - break; - }; - return true; -#else - return false; -#endif } void COpenGL3DriverBase::setRenderStates3DMode() diff --git a/irr/src/OpenGL/Driver.h b/irr/src/OpenGL/Driver.h index fefb12e2b..0807542f5 100644 --- a/irr/src/OpenGL/Driver.h +++ b/irr/src/OpenGL/Driver.h @@ -224,9 +224,6 @@ public: //! checks if an OpenGL error has happened and prints it (+ some internal code which is usually the line number) bool testGLError(int code = 0); - //! checks if an OGLES1 error has happened and prints it - bool testEGLError(); - //! Set/unset a clipping plane. bool setClipPlane(u32 index, const core::plane3df &plane, bool enable = false) override; @@ -385,7 +382,7 @@ private: void printTextureFormats(); - void addDummyMaterial(E_MATERIAL_TYPE type); + bool EnableErrorTest; unsigned QuadIndexCount; GLuint QuadIndexBuffer = 0; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 298ecadbd..b0d95bd90 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -229,6 +229,7 @@ RenderingEngine::RenderingEngine(IEventReceiver *receiver) params.Stencilbuffer = false; params.Vsync = vsync; params.EventReceiver = receiver; + params.DriverDebug = g_settings->getBool("opengl_debug"); // there is no standardized path for these on desktop std::string rel_path = std::string("client") + DIR_DELIM diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 0907c4c6d..b29746c0e 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -114,7 +114,7 @@ void set_default_settings() settings->setDefault("keymap_toggle_hud", "KEY_F1"); settings->setDefault("keymap_toggle_chat", "KEY_F2"); settings->setDefault("keymap_toggle_fog", "KEY_F3"); -#if DEBUG +#ifndef NDEBUG settings->setDefault("keymap_toggle_update_camera", "KEY_F4"); #else settings->setDefault("keymap_toggle_update_camera", ""); @@ -174,8 +174,10 @@ void set_default_settings() // Visuals #ifdef NDEBUG settings->setDefault("show_debug", "false"); + settings->setDefault("opengl_debug", "false"); #else settings->setDefault("show_debug", "true"); + settings->setDefault("opengl_debug", "true"); #endif settings->setDefault("fsaa", "2"); settings->setDefault("undersampling", "1");