Skip to content

Allow OpenGL without enableExperimental#3277

Merged
j9ac9k merged 5 commits intopyqtgraph:masterfrom
pijyoi:opengl-no-experimental
Mar 21, 2025
Merged

Allow OpenGL without enableExperimental#3277
j9ac9k merged 5 commits intopyqtgraph:masterfrom
pijyoi:opengl-no-experimental

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Mar 7, 2025

There are currently two GraphicsItems that have an OpenGL implementation:

  • PlotCurveItem
  • PColorMeshItem

Their use was conditional on useOpenGL and enableExperimental.

Originally, the OpenGL implementation for PlotCurveItem was limited to a small subset of the PlotCurveItem api. Now that it supports most of the common use cases, it should be fine to remove it from "experimental" status.
(The example MouseSelection exercises much of the implemented functionality)

PColorMeshItem's implementation was complete from the beginning, but it also required enableExperimental, but only to follow PlotCurveItem.

Note that PyOpenGL is not required at all to use this OpenGL mode.

@pijyoi pijyoi force-pushed the opengl-no-experimental branch from e172ea7 to f3e2cfc Compare March 8, 2025 01:30
@pijyoi pijyoi force-pushed the opengl-no-experimental branch from f3e2cfc to 510165c Compare March 12, 2025 11:46
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Mar 12, 2025

The commit that changes glBlendFunc to glBlendFuncSeparate fixes an issue that is most evident when running under WSL. e.g. GLVolumeItem example will be see-through such that the contents behind the window will bleed through.
e.g. OpenGL lines with anti-aliasing enabled will also be see-through.

The blend equation SRC_ALPHA * SRC_CHAN + (1 - SRC_ALPHA) * DST_CHAN is not the correct action to perform on the alpha channel. An originally opaque destination pixel blended with a source pixel with transparency will result in a pixel with transparency, which is not the intention.

pijyoi added 2 commits March 12, 2025 21:24
OpenGL implementation may not support thick lines. So we also change the
color on click in order to give feedback to the user.
@pijyoi
Copy link
Copy Markdown
Contributor Author

pijyoi commented Mar 15, 2025

The following script demonstrates the issue that the last commit is fixing.
This issue is actually present in 0.13.7 and before.

The issue is that the rendering performed by GLScatterPlotItem assumes that blending is enabled. The natively square point is given a circular alpha, which then relies on blending to achieve a circular point.
This is fixed by simply using the discard command at the areas outside the circle.

import numpy as np
import pyqtgraph as pg
import pyqtgraph.opengl as gl

pg.setConfigOptions(background=(128, 128, 128))

pg.mkQApp()
win = gl.GLViewWidget()

pos = np.array([[0, 0, 0]])
item = gl.GLScatterPlotItem(pos=pos, size=10, color=(1.0, 0.0, 0.0, 0.5), pxMode=False)
item.setGLOptions('opaque')

win.addItem(item)
win.show()
pg.exec()

before the fix:
red_square

after the fix:
red_circle

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Mar 21, 2025

Thanks for your work in this area @pijyoi this looks great.

@j9ac9k j9ac9k merged commit 77347c3 into pyqtgraph:master Mar 21, 2025
36 checks passed
@pijyoi pijyoi deleted the opengl-no-experimental branch March 21, 2025 04:43
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