Skip to content

#11371 Remove GLEW dependency and use Qt's QOpenGLFunctions#13631

Merged
kriben merged 2 commits intoOPM:devfrom
kriben:11371-remove-glew
Apr 9, 2026
Merged

#11371 Remove GLEW dependency and use Qt's QOpenGLFunctions#13631
kriben merged 2 commits intoOPM:devfrom
kriben:11371-remove-glew

Conversation

@kriben
Copy link
Copy Markdown
Collaborator

@kriben kriben commented Feb 18, 2026

Replace embedded GLEW library with Qt's native OpenGL function loading (QOpenGLFunctions/QOpenGLExtraFunctions) to resolve Qt 6 compatibility warnings about GLEW conflicts with qopenglfunctions.h.

  • Update CVF_CALLSITE_OPENGL macro to provide QOpenGLExtraFunctions pointer
  • Replace GLEW initialization with Qt OpenGL context validation
  • Keep direct calls for fixed-function GL (glBegin, glEnd, glMatrixMode, etc.)
  • Remove glew/ directory containing embedded GLEW source

@kriben
Copy link
Copy Markdown
Collaborator Author

kriben commented Feb 18, 2026

Hi @sigurdp!

@magnesj and I would like your input on this PR.

Qt6 provides its own OpenGL function resolution infrastructure that replaces the need for GLEW.
Here's what Qt6 offers instead:

  1. QOpenGLFunctions — This class resolves OpenGL ES 2.0 (and desktop GL equivalent) functions portably. You inherit from it or access it via QOpenGLContext::functions(). It handles all the platform-specific function pointer loading that GLEW traditionally did.
  2. QOpenGLExtraFunctions — Extends the above with OpenGL ES 3.0/3.1/3.2 functions (and their desktop equivalents), available via QOpenGLContext::extraFunctions().

Pros:

  • GLEW manages its own global state and context assumptions, which can clash with Qt's context management (especially with multiple contexts or context sharing).
  • Qt's wrappers are context-aware and integrate cleanly with QOpenGLContext, QOpenGLWidget, and the rest of the Qt rendering pipeline.
  • We eliminate an external dependency for something Qt already handles well.

Cons:

  • Even more dependent on Qt.

@kriben kriben requested a review from sigurdp February 18, 2026 13:22
@kriben
Copy link
Copy Markdown
Collaborator Author

kriben commented Feb 18, 2026

[1022/2965] Building CXX object Fwk/AppFwk/cafViewer/CMakeFiles/cafViewer.dir/cafViewer.cpp.o
Warning that started the investigation:

In file included from /usr/include/x86_64-linux-gnu/qt5/QtGui/QOpenGLContext:1,
                 from /home/resinsight/projects/ResInsight/Fwk/AppFwk/cafViewer/cafViewer.cpp:75:
/usr/include/x86_64-linux-gnu/qt5/QtGui/qopenglcontext.h:55:2: warning: #warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined [-Wcpp]
   55 | #warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined
      |  ^~~~~~~
/usr/include/x86_64-linux-gnu/qt5/QtGui/qopenglcontext.h:56:2: warning: #warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h [-Wcpp]
   56 | #warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h
      |  ^~~~~~~

@magnesj
Copy link
Copy Markdown
Member

magnesj commented Feb 18, 2026

@magnesj
Copy link
Copy Markdown
Member

magnesj commented Feb 18, 2026

Here are some Qt links related to the work:

  1. [QOpenGLFunctions](https://doc.qt.io/qt-6/qopenglfunctions.html) — Cross-platform OpenGL ES 2.0 function resolution
  2. [QOpenGLExtraFunctions](https://doc.qt.io/qt-6/qopenglextrafunctions.html) — ES 3.x extensions used in the CVF_CALLSITE_OPENGL macro
  3. [Changes to Qt OpenGL (Qt 6)](https://doc.qt.io/qt-6/opengl-changes-qt6.html) — Qt 6 OpenGL module restructuring and porting notes
  4. [QOpenGLWidget](https://doc.qt.io/qt-6/qopenglwidget.html) — Widget base class used throughout ResInsight

@kriben kriben force-pushed the 11371-remove-glew branch from 739d695 to 516b7f6 Compare April 8, 2026 18:59
kriben added 2 commits April 9, 2026 08:33
Replace embedded GLEW library with Qt's native OpenGL function loading
(QOpenGLFunctions/QOpenGLExtraFunctions) to resolve Qt 6 compatibility
warnings about GLEW conflicts with qopenglfunctions.h.

- Update CVF_CALLSITE_OPENGL macro to provide QOpenGLExtraFunctions pointer
- Replace GLEW initialization with Qt OpenGL context validation
- Keep direct calls for fixed-function GL (glBegin, glEnd, glMatrixMode, etc.)
- Remove glew/ directory containing embedded GLEW source
GL/glu.h conflicts with Qt's OpenGL headers on Windows due to APIENTRY
redefinition. Replace gluBuild2DMipmaps with glTexImage2D + glGenerateMipmap,
and gluOrtho2D with glOrtho.
@kriben kriben force-pushed the 11371-remove-glew branch from 516b7f6 to e752f0d Compare April 9, 2026 06:43
@magnesj
Copy link
Copy Markdown
Member

magnesj commented Apr 9, 2026

I have tested on Windows, and the regression tests are OK. I suggest squashing to a single commit before merging.

Copy link
Copy Markdown
Member

@magnesj magnesj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest squash before merge

@kriben kriben merged commit 7897e41 into OPM:dev Apr 9, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants