|
1 | | -from dataclasses import dataclass |
2 | | -from pathlib import Path |
3 | | -from typing import Optional, Tuple |
4 | | -from collections.abc import MutableMapping |
5 | | -import zipfile |
6 | 1 | import distro |
| 2 | +import glfw |
7 | 3 | import logging |
8 | 4 | import os |
9 | 5 | import psutil |
|
13 | 9 | import subprocess |
14 | 10 | import sys |
15 | 11 | import time |
| 12 | +import zipfile |
| 13 | + |
| 14 | +from collections.abc import MutableMapping |
| 15 | +from dataclasses import dataclass |
| 16 | +from OpenGL.GL import glGetString, GL_VERSION |
| 17 | +from packaging.version import Version |
| 18 | +from pathlib import Path |
| 19 | +from typing import Optional, Tuple |
16 | 20 |
|
17 | 21 | from ou_dedetai import constants, network |
18 | 22 | from ou_dedetai.app import App |
19 | 23 |
|
20 | 24 |
|
21 | | -def fix_ld_library_path(env: Optional[MutableMapping[str, str]]) -> dict[str, str]: |
| 25 | +def fix_ld_library_path(env: Optional[MutableMapping[str, str]]) -> dict[str, str]: |
22 | 26 | """Removes pyinstaller bundled dynamic linked libraries when executing commands |
23 | 27 |
|
24 | 28 | - https://pyinstaller.org/en/latest/common-issues-and-pitfalls.html#launching-external-programs-from-the-frozen-application |
@@ -366,6 +370,50 @@ class SuperuserCommandNotFound(Exception): |
366 | 370 | """Superuser command not found. Install pkexec or sudo or doas""" |
367 | 371 |
|
368 | 372 |
|
| 373 | +def get_opengl_version(required_version="3.2"): |
| 374 | + window = None |
| 375 | + try: |
| 376 | + if not glfw.init(): |
| 377 | + return False, "Failed to initialize GLFW." |
| 378 | + |
| 379 | + glfw.window_hint(glfw.VISIBLE, glfw.FALSE) |
| 380 | + glfw.window_hint(glfw.RESIZABLE, glfw.FALSE) |
| 381 | + |
| 382 | + window = glfw.create_window(1, 1, "Hidden OpenGL Context", None, None) |
| 383 | + if not window: |
| 384 | + glfw.terminate() |
| 385 | + return False, "Failed to create an OpenGL context." |
| 386 | + |
| 387 | + glfw.make_context_current(window) |
| 388 | + |
| 389 | + opengl_version = glGetString(GL_VERSION) |
| 390 | + if opengl_version is None: |
| 391 | + raise RuntimeError("Failed to retrieve OpenGL version. Ensure OpenGL drivers are installed.") |
| 392 | + |
| 393 | + opengl_version = opengl_version.decode().split()[0] |
| 394 | + |
| 395 | + except Exception as e: |
| 396 | + return False, f"OpenGL check failed: {e}" |
| 397 | + |
| 398 | + finally: |
| 399 | + if window: |
| 400 | + glfw.destroy_window(window) |
| 401 | + glfw.terminate() |
| 402 | + |
| 403 | + if Version(opengl_version) >= Version(required_version): |
| 404 | + message = f"OpenGL Version: {opengl_version} is supported (>= {required_version})." |
| 405 | + logging.info(message) |
| 406 | + return True, message |
| 407 | + else: |
| 408 | + message = f"OpenGL Version: {opengl_version} is not supported (must be >= {required_version})." |
| 409 | + logging.info(message) |
| 410 | + return False, message |
| 411 | + |
| 412 | + |
| 413 | +class OpenGLIncompatible(Exception): |
| 414 | + """Superuser command not found. Install pkexec or sudo or doas""" |
| 415 | + |
| 416 | + |
369 | 417 | def get_superuser_command() -> str: |
370 | 418 | if shutil.which('pkexec'): |
371 | 419 | return "pkexec" |
|
0 commit comments