From a9f3a698d275bf13bbba440e95fc2e58748e370f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Aug 2017 11:21:57 +0530 Subject: [PATCH] Also check for required OpenGL extensions on OS X --- kitty/gl.h | 24 ++++++++++++++++++++++++ kitty/main.py | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/kitty/gl.h b/kitty/gl.h index 5f6ecfc52..ffe580246 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -652,6 +652,29 @@ VertexAttribPointer(PyObject UNUSED *self, PyObject *args) { Py_RETURN_NONE; } + +static PyObject* +check_for_extensions(PyObject UNUSED *self) { + GLint n = 0, i, left = 2; + glGetIntegerv(GL_NUM_EXTENSIONS, &n); + bool texture_storage = false, texture_buffer_object_rgb32 = false; +#define CHECK(name) if (!name) { \ + if (strstr((const char*)ext, "GL_ARB_" #name) == (const char *)ext) { left--; name = true; } \ +} + for (i = 0; i < n; i++) { + const GLubyte *ext = glGetStringi(GL_EXTENSIONS, i); + CHECK(texture_storage); CHECK(texture_buffer_object_rgb32); + if (left < 1) break; + } +#undef CHECK + if (left > 0) { +#define CHECK(name) if (!name) { PyErr_Format(PyExc_RuntimeError, "The OpenGL driver on this system is missing the required extension: GL_ARB_%s", #name); return NULL; } + CHECK(texture_storage); CHECK(texture_buffer_object_rgb32); +#undef CHECK + } + Py_RETURN_NONE; +} + int add_module_gl_constants(PyObject *module) { #define GLC(x) if (PyModule_AddIntConstant(module, #x, x) != 0) { PyErr_NoMemory(); return 0; } GLC(GL_VERSION); @@ -686,6 +709,7 @@ int add_module_gl_constants(PyObject *module) { {"enable_automatic_opengl_error_checking", (PyCFunction)enable_automatic_error_checking, METH_O, NULL}, \ {"copy_image_sub_data", (PyCFunction)copy_image_sub_data, METH_VARARGS, NULL}, \ {"glewInit", (PyCFunction)_glewInit, METH_NOARGS, NULL}, \ + {"check_for_extensions", (PyCFunction)check_for_extensions, METH_NOARGS, NULL}, \ METH(Viewport, METH_VARARGS) \ METH(CheckError, METH_NOARGS) \ METH(ClearColor, METH_VARARGS) \ diff --git a/kitty/main.py b/kitty/main.py index 3e9e0d870..f865745b5 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -25,7 +25,7 @@ from .fast_data_types import ( GLFW_STENCIL_BITS, Window, change_wcwidth, enable_automatic_opengl_error_checking, glClear, glClearColor, glewInit, glfw_init, glfw_set_error_callback, glfw_swap_interval, glfw_terminate, - glfw_wait_events, glfw_window_hint, glfw_init_hint_string + glfw_wait_events, glfw_window_hint, glfw_init_hint_string, check_for_extensions ) try: from .fast_data_types import GLFW_X11_WM_CLASS_NAME, GLFW_X11_WM_CLASS_CLASS @@ -220,6 +220,8 @@ def run_app(opts, args): viewport_size.x_ratio = viewport_size.width / float(w) viewport_size.y_ratio = viewport_size.height / float(h) glewInit() + if isosx: + check_for_extensions() boss = Boss(window, opts, args) boss.start() clear_buffers(window, opts)