Make --debug-gl have zero runtime cost when absent
This commit is contained in:
parent
44f456089b
commit
9eea178890
@ -2,6 +2,8 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.debug_gl = '--debug-kitty-gl' in sys.argv
|
||||||
|
|
||||||
from kitty.main import main
|
from kitty.main import main # noqa
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -100,6 +100,7 @@ extern bool init_fontconfig_library(PyObject*);
|
|||||||
extern bool init_glfw(PyObject *m);
|
extern bool init_glfw(PyObject *m);
|
||||||
extern bool init_sprites(PyObject *module);
|
extern bool init_sprites(PyObject *module);
|
||||||
extern bool init_shaders(PyObject *module);
|
extern bool init_shaders(PyObject *module);
|
||||||
|
extern bool init_shaders_debug(PyObject *module);
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
extern int init_CoreText(PyObject *);
|
extern int init_CoreText(PyObject *);
|
||||||
extern bool init_cocoa(PyObject *module);
|
extern bool init_cocoa(PyObject *module);
|
||||||
@ -125,7 +126,11 @@ PyInit_fast_data_types(void) {
|
|||||||
if (!add_module_gl_constants(m)) return NULL;
|
if (!add_module_gl_constants(m)) return NULL;
|
||||||
if (!init_glfw(m)) return NULL;
|
if (!init_glfw(m)) return NULL;
|
||||||
if (!init_sprites(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;
|
if (!init_Window(m)) return NULL;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
if (!init_CoreText(m)) return NULL;
|
if (!init_CoreText(m)) return NULL;
|
||||||
|
|||||||
@ -17,13 +17,13 @@ from .constants import (
|
|||||||
appname, config_dir, isosx, logo_data_file, str_version, viewport_size
|
appname, config_dir, isosx, logo_data_file, str_version, viewport_size
|
||||||
)
|
)
|
||||||
from .fast_data_types import (
|
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_CONTEXT_VERSION_MINOR, GLFW_DECORATED, GLFW_OPENGL_CORE_PROFILE,
|
||||||
GLFW_OPENGL_FORWARD_COMPAT, GLFW_OPENGL_PROFILE, GLFW_SAMPLES,
|
GLFW_OPENGL_FORWARD_COMPAT, GLFW_OPENGL_PROFILE, GLFW_SAMPLES,
|
||||||
GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions,
|
GLFW_STENCIL_BITS, Window, change_wcwidth, check_for_extensions, glClear,
|
||||||
enable_automatic_opengl_error_checking, glClear, glClearColor, glewInit,
|
glClearColor, glewInit, glfw_init, glfw_init_hint_string,
|
||||||
glfw_init, glfw_init_hint_string, glfw_set_error_callback,
|
glfw_set_error_callback, glfw_swap_interval, glfw_terminate,
|
||||||
glfw_swap_interval, glfw_terminate, glfw_window_hint
|
glfw_window_hint
|
||||||
)
|
)
|
||||||
from .layout import all_layouts
|
from .layout import all_layouts
|
||||||
from .utils import detach, safe_print
|
from .utils import detach, safe_print
|
||||||
@ -109,7 +109,7 @@ def option_parser():
|
|||||||
' child process. Useful for debugging.')
|
' child process. Useful for debugging.')
|
||||||
)
|
)
|
||||||
a(
|
a(
|
||||||
'--debug-gl',
|
'--debug-kitty-gl',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help=_('Debug OpenGL commands. This will cause all OpenGL calls'
|
help=_('Debug OpenGL commands. This will cause all OpenGL calls'
|
||||||
@ -294,7 +294,6 @@ def main():
|
|||||||
opts = load_config(*config, overrides=overrides)
|
opts = load_config(*config, overrides=overrides)
|
||||||
change_wcwidth(not opts.use_system_wcwidth)
|
change_wcwidth(not opts.use_system_wcwidth)
|
||||||
glfw_set_error_callback(on_glfw_error)
|
glfw_set_error_callback(on_glfw_error)
|
||||||
enable_automatic_opengl_error_checking(args.debug_gl)
|
|
||||||
if GLFW_X11_WM_CLASS_CLASS is not None:
|
if GLFW_X11_WM_CLASS_CLASS is not None:
|
||||||
glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, opts.cls)
|
glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, opts.cls)
|
||||||
if not glfw_init():
|
if not glfw_init():
|
||||||
|
|||||||
@ -34,6 +34,7 @@ static char glbuf[4096];
|
|||||||
#define fatal(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(EXIT_FAILURE); }
|
#define fatal(...) { fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); exit(EXIT_FAILURE); }
|
||||||
#define fatal_msg(msg) fatal("%s", msg);
|
#define fatal_msg(msg) fatal("%s", msg);
|
||||||
|
|
||||||
|
#ifdef ENABLE_DEBUG_GL
|
||||||
static void
|
static void
|
||||||
check_for_gl_error(int line) {
|
check_for_gl_error(int line) {
|
||||||
#define f(msg) fatal("%s (at line: %d)", msg, line); break;
|
#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() { check_for_gl_error(__LINE__); }
|
||||||
#define check_gl() { if (_enable_error_checking) check_for_gl_error(__LINE__); }
|
#else
|
||||||
|
#define check_gl() {}
|
||||||
|
#endif
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
glew_init(PyObject UNUSED *self) {
|
glew_init(PyObject UNUSED *self) {
|
||||||
@ -582,12 +585,6 @@ send_borders_rects(GLuint vw, GLuint vh) {
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
// Python API {{{
|
// 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*
|
static PyObject*
|
||||||
compile_program(PyObject UNUSED *self, PyObject *args) {
|
compile_program(PyObject UNUSED *self, PyObject *args) {
|
||||||
const char *vertex_shader, *fragment_shader;
|
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 M(name, arg_type) {#name, (PyCFunction)name, arg_type, NULL}
|
||||||
#define MW(name, arg_type) {#name, (PyCFunction)py##name, arg_type, NULL}
|
#define MW(name, arg_type) {#name, (PyCFunction)py##name, arg_type, NULL}
|
||||||
static PyMethodDef module_methods[] = {
|
static PyMethodDef module_methods[] = {
|
||||||
M(enable_automatic_opengl_error_checking, METH_O),
|
|
||||||
{"glewInit", (PyCFunction)glew_init, METH_NOARGS, NULL},
|
{"glewInit", (PyCFunction)glew_init, METH_NOARGS, NULL},
|
||||||
M(compile_program, METH_VARARGS),
|
M(compile_program, METH_VARARGS),
|
||||||
MW(create_vao, METH_NOARGS),
|
MW(create_vao, METH_NOARGS),
|
||||||
@ -711,7 +707,11 @@ static PyMethodDef module_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
#ifdef ENABLE_DEBUG_GL
|
||||||
|
init_shaders_debug(PyObject *module) {
|
||||||
|
#else
|
||||||
init_shaders(PyObject *module) {
|
init_shaders(PyObject *module) {
|
||||||
|
#endif
|
||||||
#define C(x) if (PyModule_AddIntConstant(module, #x, x) != 0) { PyErr_NoMemory(); return false; }
|
#define C(x) if (PyModule_AddIntConstant(module, #x, x) != 0) { PyErr_NoMemory(); return false; }
|
||||||
C(CELL_PROGRAM); C(CURSOR_PROGRAM); C(BORDERS_PROGRAM);
|
C(CELL_PROGRAM); C(CURSOR_PROGRAM); C(BORDERS_PROGRAM);
|
||||||
C(GLSL_VERSION);
|
C(GLSL_VERSION);
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -194,6 +194,7 @@ def run_tool(cmd):
|
|||||||
|
|
||||||
SPECIAL_SOURCES = {
|
SPECIAL_SOURCES = {
|
||||||
'kitty/parser_dump.c': ('kitty/parser.c', ['DUMP_COMMANDS']),
|
'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
|
key=lambda x: os.path.getmtime(os.path.join(base, x)), reverse=True
|
||||||
)
|
)
|
||||||
ans.append('kitty/parser_dump.c')
|
ans.append('kitty/parser_dump.c')
|
||||||
|
ans.append('kitty/shaders_debug.c')
|
||||||
return tuple(ans), tuple(headers)
|
return tuple(ans), tuple(headers)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user