diff --git a/src/ndv/views/_vispy/_array_canvas.py b/src/ndv/views/_vispy/_array_canvas.py index 35c12ed..7b672d3 100755 --- a/src/ndv/views/_vispy/_array_canvas.py +++ b/src/ndv/views/_vispy/_array_canvas.py @@ -16,7 +16,6 @@ from ndv._types import CursorType from ndv.views._app import filter_mouse_events -from ndv.views._vispy._utils import supports_float_textures from ndv.views.bases import ArrayCanvas from ndv.views.bases._graphics._canvas_elements import ( CanvasElement, @@ -441,7 +440,6 @@ def __init__(self) -> None: self._ndim: Literal[2, 3] | None = None self._elements: WeakKeyDictionary = WeakKeyDictionary() - self._txt_fmt = "auto" if supports_float_textures() else None @property def _camera(self) -> vispy.scene.cameras.BaseCamera: @@ -485,7 +483,7 @@ def add_image(self, data: np.ndarray | None = None) -> VispyImageHandle: data = _downcast(data) try: img = scene.visuals.Image( - data, parent=self._view.scene, texture_format=self._txt_fmt + data, parent=self._view.scene, texture_format="auto" ) except ValueError as e: warnings.warn(f"{e}. Falling back to CPUScaledTexture", stacklevel=2) @@ -506,7 +504,7 @@ def add_volume(self, data: np.ndarray | None = None) -> VispyImageHandle: data, parent=self._view.scene, interpolation="nearest", - texture_format=self._txt_fmt, + texture_format="auto", ) except ValueError as e: warnings.warn(f"{e}. Falling back to CPUScaledTexture", stacklevel=2) diff --git a/src/ndv/views/_vispy/_utils.py b/src/ndv/views/_vispy/_utils.py deleted file mode 100644 index f5ec027..0000000 --- a/src/ndv/views/_vispy/_utils.py +++ /dev/null @@ -1,45 +0,0 @@ -from __future__ import annotations - -from contextlib import contextmanager -from functools import cache -from typing import TYPE_CHECKING - -from vispy.app import Canvas -from vispy.gloo import gl -from vispy.gloo.context import get_current_canvas - -if TYPE_CHECKING: - from collections.abc import Iterator - - -@contextmanager -def _opengl_context() -> Iterator[None]: - """Assure we are running with a valid OpenGL context. - - Only create a Canvas if one doesn't exist. Creating and closing a - Canvas causes vispy to process Qt events which can cause problems. - Ideally call opengl_context() on start after creating your first - Canvas. However it will work either way. - """ - canvas = Canvas(show=False) if get_current_canvas() is None else None - try: - yield - finally: - if canvas is not None: - canvas.close() - - -@cache -def get_gl_extensions() -> set[str]: - """Get basic info about the Gl capabilities of this machine.""" - with _opengl_context(): - return set(filter(None, gl.glGetParameter(gl.GL_EXTENSIONS).split())) - - -FLOAT_EXT = {"GL_ARB_texture_float", "GL_ATI_texture_float", "GL_NV_float_buffer"} - - -@cache -def supports_float_textures() -> bool: - """Check if the current OpenGL context supports float textures.""" - return bool(FLOAT_EXT.intersection(get_gl_extensions()))