From 3f8b2184a6081c616378e34452c5dba9a47f2620 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 13 Oct 2017 10:06:12 +0530 Subject: [PATCH] Add a sanity check to ensure the attribute location binding worked --- kitty/cell_vertex.glsl | 8 ++++---- kitty/graphics_vertex.glsl | 2 +- kitty/shaders.c | 8 ++++++++ kitty/window.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 55117a9bc..f772099a7 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -13,10 +13,10 @@ layout(std140) uniform CellRenderData { }; // Have to use fixed locations here as all variants of the cell program share the same VAO -// locations after 2 are used in the graphics program which also shares the same VAO -layout(location=0) in uvec3 colors; -layout(location=1) in uvec4 sprite_coords; -layout(location=2) in float is_selected; +// location 0 is used in the graphics program which uses the same VAO +layout(location=1) in uvec3 colors; +layout(location=2) in uvec4 sprite_coords; +layout(location=3) in float is_selected; #if defined(FOREGROUND) || defined(ALL) diff --git a/kitty/graphics_vertex.glsl b/kitty/graphics_vertex.glsl index 9345339b4..8fe913fb3 100644 --- a/kitty/graphics_vertex.glsl +++ b/kitty/graphics_vertex.glsl @@ -1,6 +1,6 @@ #version GLSL_VERSION -layout(location=3) in vec4 src; +layout(location=0) in vec4 src; out vec2 texcoord; void main() { diff --git a/kitty/shaders.c b/kitty/shaders.c index a4ca95e6f..d1de716ba 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -191,6 +191,14 @@ init_cell_program() { cell_program_layouts[i].color_table.offset = get_uniform_information(i, "color_table[0]", GL_UNIFORM_OFFSET); cell_program_layouts[i].color_table.stride = get_uniform_information(i, "color_table[0]", GL_UNIFORM_ARRAY_STRIDE); } + // Sanity check to ensure the attribute location binding worked +#define C(p, name, expected) { int aloc = attrib_location(p, #name); if (aloc != expected && aloc != -1) fatal("The attribute location for %s is %d != %d in program: %d", #name, aloc, expected, p); } + for (int p = CELL_PROGRAM; p <= CELL_FOREGROUND_PROGRAM; p++) { + C(p, colors, 1); C(p, sprite_coords, 2); C(p, is_selected, 3); + } + C(GRAPHICS_PROGRAM, src, 0); +#undef C + } #define CELL_BUFFERS enum { cell_data_buffer, selection_buffer, uniform_buffer, graphics_buffer }; diff --git a/kitty/window.py b/kitty/window.py index fa1f1222d..f187f3447 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -53,6 +53,7 @@ def calculate_gl_geometry(window_geometry, viewport_width, viewport_height, cell def load_shader_programs(): v, f = load_shaders('cell') + compile_program(GRAPHICS_PROGRAM, *load_shaders('graphics')) for which, p in { 'ALL': CELL_PROGRAM, 'BACKGROUND': CELL_BACKGROUND_PROGRAM, 'SPECIAL': CELL_SPECIAL_PROGRAM, 'FOREGROUND': CELL_FOREGROUND_PROGRAM @@ -62,7 +63,6 @@ def load_shader_programs(): init_cell_program() compile_program(CURSOR_PROGRAM, *load_shaders('cursor')) init_cursor_program() - compile_program(GRAPHICS_PROGRAM, *load_shaders('graphics')) class Window: