From d89e68f5e9ea40ba684e705057391cd2580565e9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Apr 2024 08:55:56 +0530 Subject: [PATCH] Output OpenGL version in debug config --- kitty/debug_config.py | 3 ++- kitty/fast_data_types.pyi | 1 + kitty/gl.c | 21 +++++++++++++++------ kitty/gl.h | 1 + kitty/glfw.c | 6 ++++++ kitty/state.h | 1 + 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/kitty/debug_config.py b/kitty/debug_config.py index 9de16ca06..e660fe893 100644 --- a/kitty/debug_config.py +++ b/kitty/debug_config.py @@ -17,7 +17,7 @@ from kittens.tui.operations import colored, styled from .child import cmdline_of_pid from .cli import version from .constants import extensions_dir, is_macos, is_wayland, kitty_base_dir, kitty_exe, shell_path -from .fast_data_types import Color, SingleKey, num_users, wayland_compositor_data +from .fast_data_types import Color, SingleKey, num_users, opengl_version_string, wayland_compositor_data from .options.types import Options as KittyOpts from .options.types import defaults from .options.utils import KeyboardMode, KeyDefinition @@ -246,6 +246,7 @@ def debug_config(opts: KittyOpts) -> str: p(f.read().strip()) if not is_macos: p('Running under:', green(compositor_name())) + p(green('OpenGL:'), opengl_version_string()) p(green('Frozen:'), 'True' if getattr(sys, 'frozen', False) else 'False') p(green('Paths:')) p(yellow(' kitty:'), os.path.realpath(kitty_exe())) diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 8e2244176..316e37d0d 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -1580,3 +1580,4 @@ def terminfo_data() -> bytes:... def wayland_compositor_data() -> Tuple[int, Optional[str]]:... def monotonic() -> float: ... def timed_debug_print(x: str) -> None: ... +def opengl_version_string() -> str: ... diff --git a/kitty/gl.c b/kitty/gl.c index ce4a21e10..8245b4f9e 100644 --- a/kitty/gl.c +++ b/kitty/gl.c @@ -38,12 +38,22 @@ check_for_gl_error(void UNUSED *ret, const char *name, GLADapiproc UNUSED funcpt } } +const char* +gl_version_string(void) { + static char buf[256]; + int gl_major = GLAD_VERSION_MAJOR(global_state.gl_version); + int gl_minor = GLAD_VERSION_MINOR(global_state.gl_version); + const char *gvs = (const char*)glGetString(GL_VERSION); + snprintf(buf, sizeof(buf), "'%s' Detected version: %d.%d", gvs, gl_major, gl_minor); + return buf; +} + void gl_init(void) { static bool glad_loaded = false; if (!glad_loaded) { - int gl_version = gladLoadGL(glfwGetProcAddress); - if (!gl_version) { + global_state.gl_version = gladLoadGL(glfwGetProcAddress); + if (!global_state.gl_version) { fatal("Loading the OpenGL library failed"); } if (!global_state.debug_rendering) { @@ -57,10 +67,9 @@ gl_init(void) { ARB_TEST(texture_storage); #undef ARB_TEST glad_loaded = true; - int gl_major = GLAD_VERSION_MAJOR(gl_version); - int gl_minor = GLAD_VERSION_MINOR(gl_version); - const char *gvs = (const char*)glGetString(GL_VERSION); - if (global_state.debug_rendering) printf("[%.3f] GL version string: '%s' Detected version: %d.%d\n", monotonic_t_to_s_double(monotonic()), gvs, gl_major, gl_minor); + int gl_major = GLAD_VERSION_MAJOR(global_state.gl_version); + int gl_minor = GLAD_VERSION_MINOR(global_state.gl_version); + if (global_state.debug_rendering) printf("[%.3f] GL version string: %s\n", monotonic_t_to_s_double(monotonic()), gl_version_string()); if (gl_major < OPENGL_REQUIRED_VERSION_MAJOR || (gl_major == OPENGL_REQUIRED_VERSION_MAJOR && gl_minor < OPENGL_REQUIRED_VERSION_MINOR)) { fatal("OpenGL version is %d.%d, version >= 3.3 required for kitty", gl_major, gl_minor); } diff --git a/kitty/gl.h b/kitty/gl.h index 432b6643e..629d0f0f2 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -31,6 +31,7 @@ typedef struct { void gl_init(void); +const char* gl_version_string(void); void update_surface_size(int w, int h, GLuint offscreen_texture_id); void free_texture(GLuint *tex_id); void free_framebuffer(GLuint *fb_id); diff --git a/kitty/glfw.c b/kitty/glfw.c index c9550833b..2a0a17515 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1406,6 +1406,11 @@ dbus_user_notification_activated(uint32_t notification_id, const char* action) { } #endif +static PyObject* +opengl_version_string(PyObject *self UNUSED, PyObject *args UNUSED) { + return PyUnicode_FromString(global_state.gl_version ? gl_version_string() : ""); +} + static PyObject* glfw_init(PyObject UNUSED *self, PyObject *args) { const char* path; @@ -2228,6 +2233,7 @@ static PyMethodDef module_methods[] = { METHODB(cocoa_hide_other_apps, METH_NOARGS), METHODB(cocoa_minimize_os_window, METH_VARARGS), {"glfw_init", (PyCFunction)glfw_init, METH_VARARGS, ""}, + METHODB(opengl_version_string, METH_NOARGS), {"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""}, {"glfw_get_physical_dpi", (PyCFunction)glfw_get_physical_dpi, METH_NOARGS, ""}, {"glfw_get_key_name", (PyCFunction)glfw_get_key_name, METH_VARARGS, ""}, diff --git a/kitty/state.h b/kitty/state.h index a1d1c2b84..b956a653e 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -274,6 +274,7 @@ typedef struct { CloseRequest quit_request; bool redirect_mouse_handling; WindowLogoTable *all_window_logos; + int gl_version; } GlobalState; extern GlobalState global_state;