Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate opacity warning for gpu renderer and versions blacklist #411

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/geovista/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"triangulated",
"vtk_warnings_off",
"vtk_warnings_on",
"warn_opacity",
"wrap",
]

Expand Down Expand Up @@ -103,6 +104,11 @@
#: LRU cache size, which is auto-disabled for testing
LRU_CACHE_SIZE: int = 0 if "pytest" in sys.modules else 128

#: Known GPU renderer and version combinations that don't support opacity.
OPACITY_BLACKLIST = [
("llvmpipe (LLVM 7.0, 256 bits)", "3.3 (Core Profile) Mesa 18.3.4"),
]

#: Default period for wrapped longitude half-open interval, in degrees.
PERIOD: float = 360.0

Expand Down Expand Up @@ -881,6 +887,35 @@ def vtk_warnings_on() -> None:
vtkLogger.SetStderrVerbosity(vtkLogger.VERBOSITY_INFO)


def warn_opacity(plotter: pv.Plotter) -> None:
"""Add text opacity support warning to plotter scene.

Convenience for adding a text warning to the render scene for known GPU
configurations that don't support opacity.

Parameters
----------
plotter : pv.Plotter
The plotter rendering the scene.

Notes
-----
.. versionadded:: 0.4.0

"""
info = pv.GPUInfo()
renderer_version = info.renderer, info.version

if renderer_version in OPACITY_BLACKLIST:
plotter.add_text(
"Requires Opacity Support",
position="lower_right",
font_size=7,
color="red",
shadow=True,
)


def wrap(
lons: ArrayLike,
base: float | None = None,
Expand Down
2 changes: 2 additions & 0 deletions src/geovista/examples/clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from matplotlib.colors import LinearSegmentedColormap

import geovista as gv
from geovista.common import warn_opacity
from geovista.pantry import cloud_amount
import geovista.theme # noqa: F401

Expand Down Expand Up @@ -91,6 +92,7 @@ def main() -> None:
font_size=10,
shadow=True,
)
warn_opacity(plotter)
plotter.camera.zoom(1.5)
plotter.show()

Expand Down