Skip to content

Commit c4d2e85

Browse files
committed
feat: detect opengl version
1 parent e7e72ff commit c4d2e85

5 files changed

Lines changed: 76 additions & 8 deletions

File tree

ou_dedetai/installer.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import sys
55
from pathlib import Path
66

7-
from ou_dedetai import system
87
from ou_dedetai.app import App, UserExitedFromAsk
98

109
from . import constants
1110
from . import network
11+
from . import system
1212
from . import utils
1313
from . import wine
1414

15+
from .system import OpenGLIncompatible
1516

1617
# This step doesn't do anything per-say, but "collects" all the choices in one step
1718
# The app would continue to work without this function
@@ -271,11 +272,23 @@ def ensure_launcher_shortcuts(app: App):
271272
f"Runmode is '{constants.RUNMODE}'. Won't create desktop shortcuts",
272273
)
273274

275+
276+
def ensure_opengl(app: App):
277+
app.status("Checking available OpenGL version…")
278+
opengl_version, reason = system.get_opengl_version()
279+
app.status(reason)
280+
if not opengl_version:
281+
raise OpenGLIncompatible
282+
283+
274284
def install(app: App):
275285
"""Entrypoint for installing"""
276286
app.status('Installing…')
277287
try:
288+
ensure_opengl(app)
278289
ensure_launcher_shortcuts(app)
290+
except OpenGLIncompatible:
291+
app.status(f"Incompatible OpenGL version.")
279292
except UserExitedFromAsk:
280293
# Reset choices, it's possible that the user didn't mean to select
281294
# one of the options they did - that is why they are exiting

ou_dedetai/logos.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ def run_logos():
123123
self.processes[self.app.conf.logos_exe] = process
124124
self.logos_state = State.RUNNING
125125

126+
# Ensure OpenGL version is compatible with Logos on Wine.
127+
opengl_version, reason = system.get_opengl_version()
128+
if not opengl_version:
129+
self.app.exit(reason)
130+
126131
# Ensure wine version is compatible with Logos release version.
127132
good_wine, reason = wine.check_wine_rules(
128133
wine_release,

ou_dedetai/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414
import sys
1515

16-
from ou_dedetai.repair import detect_and_recover
16+
from .repair import detect_and_recover
1717

1818
from . import cli
1919
from . import constants

ou_dedetai/system.py

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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
61
import distro
2+
import glfw
73
import logging
84
import os
95
import psutil
@@ -13,12 +9,20 @@
139
import subprocess
1410
import sys
1511
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
1620

1721
from ou_dedetai import constants, network
1822
from ou_dedetai.app import App
1923

2024

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]:
2226
"""Removes pyinstaller bundled dynamic linked libraries when executing commands
2327
2428
- https://pyinstaller.org/en/latest/common-issues-and-pitfalls.html#launching-external-programs-from-the-frozen-application
@@ -366,6 +370,50 @@ class SuperuserCommandNotFound(Exception):
366370
"""Superuser command not found. Install pkexec or sudo or doas"""
367371

368372

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+
369417
def get_superuser_command() -> str:
370418
if shutil.which('pkexec'):
371419
return "pkexec"

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ dependencies = [
88
# "certifi",
99
# "charset-normalizer",
1010
"distro",
11+
"glfw",
1112
# "idna",
13+
"pyopengl",
1214
"packaging",
1315
"psutil",
1416
"pythondialog",

0 commit comments

Comments
 (0)