Opened 5 years ago
Last modified 5 years ago
#4048 assigned enhancement
Replace PyOpenGL with Qt OpenGL API
| Reported by: | Tom Goddard | Owned by: | Tom Goddard |
|---|---|---|---|
| Priority: | moderate | Milestone: | |
| Component: | Graphics | Version: | |
| Keywords: | Cc: | ||
| Blocked By: | Blocking: | ||
| Notify when closed: | Platform: | all | |
| Project: | ChimeraX |
Description
Might want to drop PyOpenGL and call OpenGL functions through PySide2.
PyOpenGL is poorly maintained. This leads to a lot of wasted time fixing its problems. The current one I am working on is #3760 where the latest PyOpenGL 3.1.5 is generate warnings on startup about missing numpy_formathandler. This took almost a day of debugging and trying to fix so far -- it is just because the PyPi PyOpenGL builds are wrong, forgot to include numpy before building. I made a PyOpenGL ticket for it, no response.
Qt / PySide2 offers a full OpenGL API. For example, to use from PySide2 15.1
from PySide2.QtOpenGLFunctions import QOpenGLFunctions_3_3_Core as GL
GL.glClear(GL.GL_COLOR_BUFFER_BIT)
Actually this does not work. Although glClear is in GL, the constants don't appear to be, ie GL.GL_COLOR_BUFFER_BIT gets an attribute error.
It is hard to find examples using this, so it may be even less usable than PyOpenGL.
Change History (4)
comment:1 by , 5 years ago
| Owner: | changed from to |
|---|
comment:3 by , 5 years ago
There is no documentation for module PySide2.QtOpenGLFunctions.
https://doc.qt.io/qtforpython-5/modules.html
Not sure what to make of that. Is it not supported? Is it just an experiment for PySide6 for Qt6?
comment:4 by , 5 years ago
I asked on the PySide2 mailing list if desktop OpenGL is usable:
https://lists.qt-project.org/pipermail/pyside/2020-December/003041.html
Begin forwarded message:
From: Tom Goddard
Subject: Is QOpenGLFunctions_3_3_Core supported in PySide2
Date: December 11, 2020 at 8:03:09 PM PST
To: pyside@…
I am trying to figure out whether PySide2 offers an API for desktop OpenGL, e.g. 3.3 core profile. Currently I use PyOpenGL which is poorly maintained and would like to switch to using PySide2 OpenGL bindings if possible. Here is the Qt documentation of QOpenGLFunctions_3_3_Core that I would like to use from PySide2.
Here are failed attempts. I am using PySide 15.1 on macOS 10.15.
1) First the class is not in QtGui which is where the live in C++ Qt
from PySide2.QtGui import QOpenGLFunctions_3_3_Core
-> import error, no such name
2) But there is an undocumented QtOpenGLFunctions module that has it
from PySide2.QtOpenGLFunctions import QOpenGLFunctions_3_3_Core as GL
and it contains the functions, e.g. GL.glClear but does not have the constants
GL.GL_COLOR_BUFFER_BIT
-> attribute error
dir(GL) -> shows only glXYZ functions not any GL_XYZ constants.
3) If I take my QOpenGLContext instance (that I currently use with PyOpenGL) qc and try to get the functions
GL = qc.versionFunctions()
it gives a QAbstractOpenGLFunctions instance with no opengl methods
GL.glClear
-> attribute error
There is a PySide2 bug report about that from Feb 2019 with no resolution
4) In PyQt5 approach 3 works
GL = qc.versionFunctions()
GL
-> <PyQt5._QOpenGLFunctions_4_1_Core.QOpenGLFunctions_4_1_Core at 0x14e325730>
and this module has glClear and GL_COLOR_BUFFER_BIT, seems to have what is needed although I have not tried using it.
Thanks for shedding any light on the using the desktop OpenGL API from PySide2.
Tom Goddard
ChimeraX molecular visualization developer
If I instead use
GL = qc.versionFunctions()
where qc is our QOpenGLContext instance then GL is a QAbstractOpenGLFunctions and has no methods, ie GL.glClear gives an attribute error. In PyQt5 this works correctly. Here is a PySIde2 bug report about this from Feb 2019, has not been resolved
https://bugreports.qt.io/browse/PYSIDE-955