mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-08-04 14:46:03 +00:00
Cleanup shader load/recompile legacy code
Make it easier to port
This commit is contained in:
parent
9ac4e757d6
commit
5ac71ba447
6 changed files with 12 additions and 90 deletions
|
|
@ -6,8 +6,7 @@ from enum import IntFlag
|
|||
from functools import partial
|
||||
from typing import NamedTuple
|
||||
|
||||
from .fast_data_types import BORDERS_PROGRAM, current_focused_os_window_id, get_options, init_borders_program, set_borders_rects
|
||||
from .shaders.legacy import program_for
|
||||
from .fast_data_types import current_focused_os_window_id, get_options, set_borders_rects
|
||||
from .typing_compat import LayoutType
|
||||
from .utils import color_as_int
|
||||
from .window_list import WindowGroup, WindowList
|
||||
|
|
@ -67,11 +66,6 @@ def add_borders(rects: list[Border], color: BorderColor, wg: WindowGroup) -> Non
|
|||
v(pr, top, bottom, lr, wid)
|
||||
|
||||
|
||||
def load_borders_program() -> None:
|
||||
program_for('border').compile(BORDERS_PROGRAM)
|
||||
init_borders_program()
|
||||
|
||||
|
||||
class Borders:
|
||||
|
||||
def __init__(self, os_window_id: int, tab_id: int):
|
||||
|
|
|
|||
|
|
@ -567,9 +567,6 @@ def set_os_window_chrome(os_window_id: int) -> bool:
|
|||
def set_borders_rects(os_window_id: int, tab_id: int, rects: list[Border]) -> None: ...
|
||||
|
||||
|
||||
def init_borders_program() -> None:
|
||||
pass
|
||||
|
||||
def os_window_has_background_image(os_window_id: int) -> bool:
|
||||
pass
|
||||
|
||||
|
|
|
|||
60
kitty/glsl-uniforms.h
generated
60
kitty/glsl-uniforms.h
generated
|
|
@ -3,35 +3,22 @@
|
|||
|
||||
|
||||
typedef struct BgimageUniforms {
|
||||
int background;
|
||||
int image;
|
||||
int positions;
|
||||
int sizes;
|
||||
int tiled;
|
||||
} BgimageUniforms;
|
||||
|
||||
static inline void get_uniform_locations_bgimage(int program, BgimageUniforms *ans) {
|
||||
ans->background = get_uniform_location(program, "background_0");
|
||||
ans->image = get_uniform_location(program, "image_0");
|
||||
ans->positions = get_uniform_location(program, "positions_0");
|
||||
ans->sizes = get_uniform_location(program, "sizes_0");
|
||||
ans->tiled = get_uniform_location(program, "tiled_0");
|
||||
}
|
||||
|
||||
typedef struct BlitUniforms {
|
||||
int dest_rect;
|
||||
int image;
|
||||
int src_rect;
|
||||
} BlitUniforms;
|
||||
|
||||
static inline void get_uniform_locations_blit(int program, BlitUniforms *ans) {
|
||||
ans->dest_rect = get_uniform_location(program, "dest_rect_0");
|
||||
ans->image = get_uniform_location(program, "image_0");
|
||||
ans->src_rect = get_uniform_location(program, "src_rect_0");
|
||||
}
|
||||
|
||||
typedef struct BorderUniforms {
|
||||
int background_opacity;
|
||||
// Vertex Input locations
|
||||
int rect;
|
||||
int rect_color;
|
||||
|
|
@ -43,7 +30,6 @@ typedef struct BorderUniforms {
|
|||
} BorderUniforms;
|
||||
|
||||
static inline void get_uniform_locations_border(int program, BorderUniforms *ans) {
|
||||
ans->background_opacity = get_uniform_location(program, "background_opacity_0");
|
||||
ans->rect = 0;
|
||||
ans->rect_color = 1;
|
||||
ans->Colors.index = block_index(program, "block_Colors_0");
|
||||
|
|
@ -55,10 +41,7 @@ static inline void get_uniform_locations_border(int program, BorderUniforms *ans
|
|||
}
|
||||
|
||||
typedef struct CellUniforms {
|
||||
int draw_bg_bitfield;
|
||||
int sprites;
|
||||
int text_contrast;
|
||||
int text_gamma_adjustment;
|
||||
// Vertex Input locations
|
||||
int colors;
|
||||
int is_selected;
|
||||
|
|
@ -72,10 +55,7 @@ typedef struct CellUniforms {
|
|||
} CellUniforms;
|
||||
|
||||
static inline void get_uniform_locations_cell(int program, CellUniforms *ans) {
|
||||
ans->draw_bg_bitfield = get_uniform_location(program, "draw_bg_bitfield_0");
|
||||
ans->sprites = get_uniform_location(program, "sprites_0");
|
||||
ans->text_contrast = get_uniform_location(program, "text_contrast_0");
|
||||
ans->text_gamma_adjustment = get_uniform_location(program, "text_gamma_adjustment_0");
|
||||
ans->colors = 0;
|
||||
ans->is_selected = 2;
|
||||
ans->sprite_idx = 1;
|
||||
|
|
@ -90,75 +70,35 @@ static inline void get_uniform_locations_cell(int program, CellUniforms *ans) {
|
|||
}
|
||||
|
||||
typedef struct GraphicsUniforms {
|
||||
int amask_bg_premult;
|
||||
int amask_fg;
|
||||
int dest_rect;
|
||||
int extra_alpha;
|
||||
int image;
|
||||
int src_rect;
|
||||
} GraphicsUniforms;
|
||||
|
||||
static inline void get_uniform_locations_graphics(int program, GraphicsUniforms *ans) {
|
||||
ans->amask_bg_premult = get_uniform_location(program, "amask_bg_premult_0");
|
||||
ans->amask_fg = get_uniform_location(program, "amask_fg_0");
|
||||
ans->dest_rect = get_uniform_location(program, "dest_rect_0");
|
||||
ans->extra_alpha = get_uniform_location(program, "extra_alpha_0");
|
||||
ans->image = get_uniform_location(program, "image_0");
|
||||
ans->src_rect = get_uniform_location(program, "src_rect_0");
|
||||
}
|
||||
|
||||
typedef struct Rounded_rectUniforms {
|
||||
int background_color;
|
||||
int color;
|
||||
int params;
|
||||
int rect;
|
||||
} Rounded_rectUniforms;
|
||||
|
||||
static inline void get_uniform_locations_rounded_rect(int program, Rounded_rectUniforms *ans) {
|
||||
ans->background_color = get_uniform_location(program, "background_color_0");
|
||||
ans->color = get_uniform_location(program, "color_0");
|
||||
ans->params = get_uniform_location(program, "params_0");
|
||||
ans->rect = get_uniform_location(program, "rect_0");
|
||||
}
|
||||
|
||||
typedef struct ScreenshotUniforms {
|
||||
int dest_rect;
|
||||
int image;
|
||||
int src_rect;
|
||||
int src_size;
|
||||
} ScreenshotUniforms;
|
||||
|
||||
static inline void get_uniform_locations_screenshot(int program, ScreenshotUniforms *ans) {
|
||||
ans->dest_rect = get_uniform_location(program, "dest_rect_0");
|
||||
ans->image = get_uniform_location(program, "image_0");
|
||||
ans->src_rect = get_uniform_location(program, "src_rect_0");
|
||||
ans->src_size = get_uniform_location(program, "src_size_0");
|
||||
}
|
||||
|
||||
typedef struct TintUniforms {
|
||||
int edges;
|
||||
int tint_color;
|
||||
} TintUniforms;
|
||||
|
||||
static inline void get_uniform_locations_tint(int program, TintUniforms *ans) {
|
||||
ans->edges = get_uniform_location(program, "edges_0");
|
||||
ans->tint_color = get_uniform_location(program, "tint_color_0");
|
||||
}
|
||||
|
||||
typedef struct TrailUniforms {
|
||||
int cursor_edge_x;
|
||||
int cursor_edge_y;
|
||||
int trail_color;
|
||||
int trail_opacity;
|
||||
int x_coords;
|
||||
int y_coords;
|
||||
} TrailUniforms;
|
||||
|
||||
static inline void get_uniform_locations_trail(int program, TrailUniforms *ans) {
|
||||
ans->cursor_edge_x = get_uniform_location(program, "cursor_edge_x_0");
|
||||
ans->cursor_edge_y = get_uniform_location(program, "cursor_edge_y_0");
|
||||
ans->trail_color = get_uniform_location(program, "trail_color_0");
|
||||
ans->trail_opacity = get_uniform_location(program, "trail_opacity_0");
|
||||
ans->x_coords = get_uniform_location(program, "x_coords_0");
|
||||
ans->y_coords = get_uniform_location(program, "y_coords_0");
|
||||
}
|
||||
|
|
@ -10,7 +10,6 @@ from collections.abc import Generator, Sequence
|
|||
from contextlib import contextmanager, suppress
|
||||
from gettext import gettext as _
|
||||
|
||||
from .borders import load_borders_program
|
||||
from .boss import Boss
|
||||
from .child import set_default_env, set_LANG_in_default_env
|
||||
from .cli import create_opts, parse_args
|
||||
|
|
@ -91,7 +90,6 @@ def set_custom_ibeam_cursor() -> None:
|
|||
def load_all_shaders() -> None:
|
||||
try:
|
||||
load_shader_programs()
|
||||
load_borders_program()
|
||||
except CompileError as err:
|
||||
raise SystemExit(err)
|
||||
|
||||
|
|
|
|||
|
|
@ -372,6 +372,11 @@ typedef struct {
|
|||
} ScreenshotProgramLayout;
|
||||
static ScreenshotProgramLayout screenshot_program_layout;
|
||||
|
||||
typedef struct BorderProgramLayout {
|
||||
BorderUniforms uniforms;
|
||||
} BorderProgramLayout;
|
||||
static BorderProgramLayout border_program_layout;
|
||||
|
||||
static void
|
||||
init_cell_program(void) {
|
||||
for (int i = CELL_PROGRAM; i < CELL_PROGRAM_SENTINEL; i++) {
|
||||
|
|
@ -402,6 +407,9 @@ init_cell_program(void) {
|
|||
get_uniform_locations_blit(BLIT_PROGRAM, &blit_program_layout.uniforms);
|
||||
get_uniform_locations_screenshot(SCREENSHOT_PROGRAM, &screenshot_program_layout.uniforms);
|
||||
get_uniform_locations_rounded_rect(ROUNDED_RECT_PROGRAM, &rounded_rect_program_layout.uniforms);
|
||||
bind_program(BORDERS_PROGRAM);
|
||||
get_uniform_locations_border(BORDERS_PROGRAM, &border_program_layout.uniforms);
|
||||
glUniform1fv(border_program_layout.uniforms.gamma_lut, arraysz(srgb_lut), srgb_lut);
|
||||
}
|
||||
|
||||
#define CELL_BUFFERS enum { cell_data_buffer, selection_buffer, uniform_buffer, color_table_buffer };
|
||||
|
|
@ -1454,18 +1462,6 @@ draw_cells(const WindowRenderData *srd, OSWindow *os_window, bool is_active_wind
|
|||
|
||||
// Borders {{{
|
||||
|
||||
typedef struct BorderProgramLayout {
|
||||
BorderUniforms uniforms;
|
||||
} BorderProgramLayout;
|
||||
static BorderProgramLayout border_program_layout;
|
||||
|
||||
static void
|
||||
init_borders_program(void) {
|
||||
get_uniform_locations_border(BORDERS_PROGRAM, &border_program_layout.uniforms);
|
||||
bind_program(BORDERS_PROGRAM);
|
||||
glUniform1fv(border_program_layout.uniforms.gamma_lut, 256, srgb_lut);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
create_border_vao(void) {
|
||||
ssize_t vao_idx = create_vao();
|
||||
|
|
@ -1859,8 +1855,6 @@ ONE_INT(bind_vertex_array)
|
|||
NO_ARG(unbind_vertex_array)
|
||||
TWO_INT(unmap_vao_buffer)
|
||||
|
||||
NO_ARG(init_borders_program)
|
||||
|
||||
NO_ARG(init_cell_program)
|
||||
|
||||
static PyObject*
|
||||
|
|
@ -1884,7 +1878,6 @@ static PyMethodDef module_methods[] = {
|
|||
MW(unmap_vao_buffer, METH_VARARGS),
|
||||
MW(bind_program, METH_O),
|
||||
MW(unbind_program, METH_NOARGS),
|
||||
MW(init_borders_program, METH_NOARGS),
|
||||
MW(init_cell_program, METH_NOARGS),
|
||||
|
||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from kitty.fast_data_types import (
|
|||
BGIMAGE_PROGRAM,
|
||||
BLINK,
|
||||
BLIT_PROGRAM,
|
||||
BORDERS_PROGRAM,
|
||||
CELL_BG_PROGRAM,
|
||||
CELL_FG_PROGRAM,
|
||||
CELL_PROGRAM,
|
||||
|
|
@ -94,7 +95,6 @@ class Program:
|
|||
self.fragment_sources = self.original_fragment_sources if frag is identity else tuple(map(frag, self.original_fragment_sources))
|
||||
|
||||
def compile(self, program_id: int, allow_recompile: bool = False) -> None:
|
||||
cerr: CompileError = CompileError()
|
||||
try:
|
||||
compile_program(program_id, self.vertex_sources, self.fragment_sources, allow_recompile)
|
||||
return
|
||||
|
|
@ -109,8 +109,7 @@ class Program:
|
|||
|
||||
for line in lines:
|
||||
msg.append(pat.sub(sub, line))
|
||||
cerr = CompileError('\n'.join(msg))
|
||||
raise cerr
|
||||
raise CompileError('\n'.join(msg))
|
||||
|
||||
|
||||
@lru_cache(maxsize=64)
|
||||
|
|
@ -218,6 +217,7 @@ class LoadShaderPrograms:
|
|||
program_for('blit').compile(BLIT_PROGRAM, allow_recompile)
|
||||
program_for('screenshot').compile(SCREENSHOT_PROGRAM, allow_recompile)
|
||||
program_for('rounded_rect').compile(ROUNDED_RECT_PROGRAM, allow_recompile)
|
||||
program_for('border').compile(BORDERS_PROGRAM, allow_recompile)
|
||||
init_cell_program()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue