diff --git a/__main__.py b/__main__.py index 44819ba2a..8551d818c 100644 --- a/__main__.py +++ b/__main__.py @@ -2,6 +2,8 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal +import sys +sys.debug_gl = '--debug-kitty-gl' in sys.argv -from kitty.main import main +from kitty.main import main # noqa main() diff --git a/kitty/data-types.c b/kitty/data-types.c index c3e61bdfe..3529386b4 100644 --- a/kitty/data-types.c +++ b/kitty/data-types.c @@ -100,6 +100,7 @@ extern bool init_fontconfig_library(PyObject*); extern bool init_glfw(PyObject *m); extern bool init_sprites(PyObject *module); extern bool init_shaders(PyObject *module); +extern bool init_shaders_debug(PyObject *module); #ifdef __APPLE__ extern int init_CoreText(PyObject *); extern bool init_cocoa(PyObject *module); @@ -125,7 +126,11 @@ PyInit_fast_data_types(void) { if (!add_module_gl_constants(m)) return NULL; if (!init_glfw(m)) return NULL; if (!init_sprites(m)) return NULL; - if (!init_shaders(m)) return NULL; + if (PySys_GetObject("debug_gl") == Py_True) { + if (!init_shaders_debug(m)) return NULL; + } else { + if (!init_shaders(m)) return NULL; + } if (!init_Window(m)) return NULL; #ifdef __APPLE__ if (!init_CoreText(m)) return NULL; diff --git a/kitty/main.py b/kitty/main.py index 7ac340ae3..944851a23 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -17,13 +17,13 @@ from .constants import ( appname, config_dir, isosx, logo_data_file, str_version, viewport_size ) from .fast_data_types import ( - GL_COLOR_BUFFER_BIT, GLFW_CONTEXT_VERSION_MAJOR, GL_VERSION_REQUIRED, + GL_COLOR_BUFFER_BIT, GL_VERSION_REQUIRED, GLFW_CONTEXT_VERSION_MAJOR, GLFW_CONTEXT_VERSION_MINOR, GLFW_DECORATED, GLFW_OPENGL_CORE_PROFILE, GLFW_OPENGL_FORWARD_COMPAT, GLFW_OPENGL_PROFILE, GLFW_SAMPLES, - GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions, - enable_automatic_opengl_error_checking, glClear, glClearColor, glewInit, - glfw_init, glfw_init_hint_string, glfw_set_error_callback, - glfw_swap_interval, glfw_terminate, glfw_window_hint + GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions, glClear, + glClearColor, glewInit, glfw_init, glfw_init_hint_string, + glfw_set_error_callback, glfw_swap_interval, glfw_terminate, + glfw_window_hint ) from .layout import all_layouts from .utils import detach, safe_print @@ -109,7 +109,7 @@ def option_parser(): ' child process. Useful for debugging.') ) a( - '--debug-gl', + '--debug-kitty-gl', action='store_true', default=False, help=_('Debug OpenGL commands. This will cause all OpenGL calls' @@ -294,7 +294,6 @@ def main(): opts = load_config(*config, overrides=overrides) change_wcwidth(not opts.use_system_wcwidth) glfw_set_error_callback(on_glfw_error) - enable_automatic_opengl_error_checking(args.debug_gl) if GLFW_X11_WM_CLASS_CLASS is not None: glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, opts.cls) if not glfw_init(): diff --git a/kitty/shaders.c b/kitty/shaders.c index 7dc0ea049..9e4f859f0 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -34,6 +34,7 @@ static char glbuf[4096]; #define fatal(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(EXIT_FAILURE); } #define fatal_msg(msg) fatal("%s", msg); +#ifdef ENABLE_DEBUG_GL static void check_for_gl_error(int line) { #define f(msg) fatal("%s (at line: %d)", msg, line); break; @@ -60,8 +61,10 @@ check_for_gl_error(int line) { } } -static bool _enable_error_checking = false; -#define check_gl() { if (_enable_error_checking) check_for_gl_error(__LINE__); } +#define check_gl() { check_for_gl_error(__LINE__); } +#else +#define check_gl() {} +#endif static PyObject* glew_init(PyObject UNUSED *self) { @@ -582,12 +585,6 @@ send_borders_rects(GLuint vw, GLuint vh) { // }}} // Python API {{{ -static PyObject* -enable_automatic_opengl_error_checking(PyObject UNUSED *self, PyObject *val) { - _enable_error_checking = PyObject_IsTrue(val) ? true : false; - Py_RETURN_NONE; -} - static PyObject* compile_program(PyObject UNUSED *self, PyObject *args) { const char *vertex_shader, *fragment_shader; @@ -686,7 +683,6 @@ PYWRAP1(draw_cells) { #define M(name, arg_type) {#name, (PyCFunction)name, arg_type, NULL} #define MW(name, arg_type) {#name, (PyCFunction)py##name, arg_type, NULL} static PyMethodDef module_methods[] = { - M(enable_automatic_opengl_error_checking, METH_O), {"glewInit", (PyCFunction)glew_init, METH_NOARGS, NULL}, M(compile_program, METH_VARARGS), MW(create_vao, METH_NOARGS), @@ -711,7 +707,11 @@ static PyMethodDef module_methods[] = { }; bool +#ifdef ENABLE_DEBUG_GL +init_shaders_debug(PyObject *module) { +#else init_shaders(PyObject *module) { +#endif #define C(x) if (PyModule_AddIntConstant(module, #x, x) != 0) { PyErr_NoMemory(); return false; } C(CELL_PROGRAM); C(CURSOR_PROGRAM); C(BORDERS_PROGRAM); C(GLSL_VERSION); diff --git a/setup.py b/setup.py index 9b86f8fa2..ce2d22fcc 100755 --- a/setup.py +++ b/setup.py @@ -194,6 +194,7 @@ def run_tool(cmd): SPECIAL_SOURCES = { 'kitty/parser_dump.c': ('kitty/parser.c', ['DUMP_COMMANDS']), + 'kitty/shaders_debug.c': ('kitty/shaders.c', ['ENABLE_DEBUG_GL']), } @@ -287,6 +288,7 @@ def find_c_files(): key=lambda x: os.path.getmtime(os.path.join(base, x)), reverse=True ) ans.append('kitty/parser_dump.c') + ans.append('kitty/shaders_debug.c') return tuple(ans), tuple(headers)