make antialiasing optional for paintGL in PlotCurveItem#1932
make antialiasing optional for paintGL in PlotCurveItem#1932j9ac9k merged 3 commits intopyqtgraph:masterfrom
Conversation
| gl.glEnable(gl.GL_BLEND) | ||
| gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) | ||
| gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) | ||
|
|
There was a problem hiding this comment.
If aa is False, you would need to glDisable whatever got enabled when aa is True.
I tried out this PR with #1910 and toggling AA from False->True->False would get a plot different from the initial plot.
There was a problem hiding this comment.
@pijyoi Thank you for the hint, I haven't thought of that. I am no OpenGL-expert so I just reverted to the default-values from the OpenGL-documentation. Now this lets me toggle between aa-states in your (really nice) example.
There was a problem hiding this comment.
In GLGridItem.py (l.68-72), there is a similar passage. Do you think it has the same problem then and should I fix it?
There was a problem hiding this comment.
There are 3 other places that setup GL_LINE_SMOOTH: GLAxisItem, GLGridItem, GLLinePlotItem. GLAxisItem doesn't enable blending, but would probably get it enabled by GLGridItem. A proper fix might require all GLGraphicsItem(s) to disable everything that they have enabled before they exit their paint.
I would suggest to leave them as is. Don't modify things that we aren't able to test ourselves. Or raise a separate issue.
There was a problem hiding this comment.
Probably after painting with antialiasing on, GL_LINE_SMOOTH should be disabled.
If we take a peek at: https://code.woboq.org/qt6/qtbase/src/opengl/qopenglpaintengine.cpp.html#_ZN28QOpenGL2PaintEngineExPrivate12resetGLStateEv
GL_LINE_SMOOTH happens to be one of the things that Qt library doesn't disable for us.
On the other hand, GL_BLEND is disabled for us, so we didn't actually need to disable it for non-antialiased mode.
There was a problem hiding this comment.
Ok, so should I remove those lines again?
gl.glDisable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO)
gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE)There was a problem hiding this comment.
That seems to work too, but performance doesn't seem to be influenced by just removing the lines. Do you think we could introduce an attribute like _aa_state to PlotCurveItem which then calls the glEnable/glDisable-functions only when the state changes?
There was a problem hiding this comment.
The problem is that when you have called beginNativePainting(), Qt makes little guarantee about the state. So things that we need, we need to set again for each frame. E.g. What would happen if we created 2 PlotWidgets in a single QMainWindow, one with antialiasing enabled and the other disabled? I would guess that because of the shared OpenGL context, they would see the last set setting of GL_LINE_SMOOTH.
There was a problem hiding this comment.
So should I just remove the above lines to have a bit less to call when AA is disabled?
There was a problem hiding this comment.
Yes. Based on my understanding, the only line needed would be
gl.glDisable(gl.GL_LINE_SMOOTH)Btw, it's not so much for performance to reduce the number of lines here. Code like this tends to get copied around, so if we can, we keep the code to only the bits necessary.
Summary
This PR makes antialiasing optional when OpenGL is used with PlotCurveItem as described in #1926.
I checked for
antialiasinself._exportOptsas it is done inpaint. Is this necessary for this to be inside paint/paintGL or could it also be in e.g.updateDatato improve performance a little bit?