From 7bd5ea3641d216e6426ee48a74ad5af2944e944e Mon Sep 17 00:00:00 2001 From: Jaswant Panchumarti Date: Wed, 17 Dec 2025 15:13:25 -0500 Subject: [PATCH] Fix OpenGL initialization error handling and version check - address paraview/paraview#18549 - the logic regressed when glad was added to warn about incompatible version when opengl functions failed to initialize. - this commit fixes the logic to warn about incompatible version only after validating that the version is actually < 3.2 --- .../dev/fix-opengl-version-check-warning.md | 7 ++++ Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx | 40 +++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 Documentation/release/dev/fix-opengl-version-check-warning.md diff --git a/Documentation/release/dev/fix-opengl-version-check-warning.md b/Documentation/release/dev/fix-opengl-version-check-warning.md new file mode 100644 index 00000000000..869a412e774 --- /dev/null +++ b/Documentation/release/dev/fix-opengl-version-check-warning.md @@ -0,0 +1,7 @@ +## Fix OpenGL initialization error handling and version check + +VTK now properly handles OpenGL initialization errors and validates version compatibility. Previously, the OpenGL version check logic would incorrectly warn about incompatible versions even when OpenGL functions failed to initialize for other reasons. + +The fix ensures that compatibility warnings only appear when the OpenGL version is actually below 3.2, rather than whenever initialization fails. This resolves issues where users would see misleading version warnings when the actual problem was unrelated to OpenGL version compatibility. + +This change addresses [paraview/paraview#18549](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12731) by correcting a regression introduced when GLAD was integrated for OpenGL function loading. diff --git a/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx b/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx index 9fb19abc35e..5e45d57d894 100644 --- a/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx +++ b/Rendering/OpenGL2/vtkOpenGLRenderWindow.cxx @@ -907,32 +907,28 @@ void vtkOpenGLRenderWindow::OpenGLInitContext() #if defined(GLAD_GL) if (this->SymbolLoader.LoadFunction != nullptr) { - if (gladLoadGLUserPtr(this->SymbolLoader.LoadFunction, this->SymbolLoader.UserData) > 0) - { - this->Initialized = true; - } - else - { - vtkWarningMacro(<< "Failed to initialize OpenGL functions!"); - } + this->Initialized = + gladLoadGLUserPtr(this->SymbolLoader.LoadFunction, this->SymbolLoader.UserData) > 0; } else { - if (gladLoaderLoadGL() > 0) - { - this->Initialized = true; - } - else - { - vtkWarningMacro(<< "Failed to initialize OpenGL functions!"); - } + this->Initialized = gladLoaderLoadGL() > 0; } -#else // gles - this->Initialized = true; -#endif if (!this->Initialized) + { + vtkWarningMacro(<< "Failed to initialize OpenGL functions!"); + return; + } + int major = 0; + int minor = 0; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + // Require at least OpenGL 3.2 + if (major < 3 || (major == 3 && minor < 2)) { vtkWarningMacro(<< "Unable to find a valid OpenGL 3.2 or later implementation. " + << "(" << major << "." << minor + << " found). " "Please update your video card driver to the latest version. " "If you are using Mesa please make sure you have version 11.2 or " "later and make sure your driver in Mesa supports OpenGL 3.2 such " @@ -942,7 +938,9 @@ void vtkOpenGLRenderWindow::OpenGLInitContext() "to avoid this issue."); return; } - +#else // gles + this->Initialized = true; +#endif // Enable debug output if OpenGL version supports attaching debug callbacks. #if defined(VTK_REPORT_OPENGL_ERRORS) && defined(GLAD_GL) if (GLAD_GL_ARB_debug_output) @@ -976,7 +974,7 @@ void vtkOpenGLRenderWindow::OpenGLInitContext() } } #endif - } + } // end if not initialized } //------------------------------------------------------------------------------ -- GitLab