mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 11:11:47 +02:00
A VAO is not needed to draw background images
This commit is contained in:
@@ -6,17 +6,16 @@ uniform float bgimage_opacity;
|
|||||||
#ifdef TILED
|
#ifdef TILED
|
||||||
uniform float bgimage_scale;
|
uniform float bgimage_scale;
|
||||||
|
|
||||||
// These are of the window, not the screen.
|
uniform float window_width;
|
||||||
uniform float width;
|
uniform float window_height;
|
||||||
uniform float height;
|
|
||||||
#endif
|
#endif
|
||||||
in vec2 texcoord;
|
in vec2 texcoord;
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
#ifdef TILED
|
#ifdef TILED
|
||||||
vec2 txsz = vec2(width,height) / textureSize(image,0);
|
ivec2 image_size = textureSize(image, 0);
|
||||||
txsz /= bgimage_scale;
|
vec2 txsz = vec2(window_width / (float(image_size[0]) * bgimage_scale), window_height / (float(image_size[1]) * bgimage_scale));
|
||||||
color = texture(image, texcoord * txsz);
|
color = texture(image, texcoord * txsz);
|
||||||
#endif
|
#endif
|
||||||
#ifdef SIMPLE
|
#ifdef SIMPLE
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
#version GLSL_VERSION
|
#version GLSL_VERSION
|
||||||
|
#define left -1.0f
|
||||||
|
#define top 1.0f
|
||||||
|
#define right 1.0f
|
||||||
|
#define bottom -1.0f
|
||||||
|
|
||||||
layout(location=0) in vec4 src;
|
|
||||||
out vec2 texcoord;
|
out vec2 texcoord;
|
||||||
|
|
||||||
|
const vec2 pos_map[] = vec2[4](
|
||||||
|
vec2(left, top),
|
||||||
|
vec2(left, bottom),
|
||||||
|
vec2(right, bottom),
|
||||||
|
vec2(right, top)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
texcoord = clamp(vec2(src[0], src[1]*-1), 0, 1);
|
vec2 vertex = pos_map[gl_VertexID];
|
||||||
gl_Position = src;
|
texcoord = clamp(vec2(vertex[0], vertex[1]*-1), 0, 1);
|
||||||
|
gl_Position = vec4(vertex, 0, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,28 +334,11 @@ cell_prepare_to_render(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, GLfloa
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
draw_bg(int program, OSWindow *w) {
|
draw_bg(int program, OSWindow *w) {
|
||||||
if (w->bvao_idx == 0) {
|
|
||||||
const GLfloat screenrect[4][2] = {
|
|
||||||
{ -1.0, 1.0 },
|
|
||||||
{ -1.0, -1.0 },
|
|
||||||
{ 1.0, -1.0 },
|
|
||||||
{ 1.0, 1.0 },
|
|
||||||
};
|
|
||||||
w->bvao_idx = create_vao();
|
|
||||||
bind_vertex_array(w->bvao_idx);
|
|
||||||
glGenBuffers(1, &w->vbo_idx);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(screenrect), screenrect, GL_STATIC_DRAW);
|
|
||||||
}
|
|
||||||
bind_vertex_array(w->bvao_idx);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, w->vbo_idx);
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
|
|
||||||
bind_program(program);
|
bind_program(program);
|
||||||
static bool bgimage_constants_set;
|
bind_vertex_array(blit_vertex_array);
|
||||||
|
|
||||||
|
static bool bgimage_constants_set = false;
|
||||||
if (!bgimage_constants_set) {
|
if (!bgimage_constants_set) {
|
||||||
glUniform1i(glGetUniformLocation(program_id(program), "image"), BGIMAGE_UNIT);
|
glUniform1i(glGetUniformLocation(program_id(program), "image"), BGIMAGE_UNIT);
|
||||||
glUniform1f(glGetUniformLocation(program_id(program), "bgimage_scale"), OPT(background_image_scale));
|
glUniform1f(glGetUniformLocation(program_id(program), "bgimage_scale"), OPT(background_image_scale));
|
||||||
@@ -658,15 +641,11 @@ create_border_vao(void) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height, color_type active_window_bg, unsigned int num_visible_windows, bool all_windows_have_same_bg, OSWindow *w) {
|
draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_buf, bool rect_data_is_dirty, uint32_t viewport_width, uint32_t viewport_height, color_type active_window_bg, unsigned int num_visible_windows, bool all_windows_have_same_bg, OSWindow *w) {
|
||||||
glEnable(GL_BLEND);
|
|
||||||
BLEND_ONTO_OPAQUE;
|
|
||||||
|
|
||||||
if (w->bgimage != NULL) {
|
if (w->bgimage != NULL) {
|
||||||
int program;
|
glEnable(GL_BLEND);
|
||||||
if (OPT(background_image_layout) == TILING || OPT(background_image_layout) == MIRRORED) program = BGIMAGE_TILED_PROGRAM;
|
BLEND_ONTO_OPAQUE;
|
||||||
else program = BGIMAGE_PROGRAM;
|
draw_bg((OPT(background_image_layout) == TILING || OPT(background_image_layout) == MIRRORED) ? BGIMAGE_TILED_PROGRAM : BGIMAGE_PROGRAM, w);
|
||||||
|
|
||||||
draw_bg(program, w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_border_rects) {
|
if (num_border_rects) {
|
||||||
@@ -691,7 +670,7 @@ draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_bu
|
|||||||
unbind_vertex_array();
|
unbind_vertex_array();
|
||||||
unbind_program();
|
unbind_program();
|
||||||
}
|
}
|
||||||
glDisable(GL_BLEND);
|
if (w->bgimage != NULL) glDisable(GL_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|||||||
@@ -169,8 +169,7 @@ typedef struct {
|
|||||||
monotonic_t last_render_frame_received_at;
|
monotonic_t last_render_frame_received_at;
|
||||||
uint64_t render_calls;
|
uint64_t render_calls;
|
||||||
id_type last_focused_counter;
|
id_type last_focused_counter;
|
||||||
ssize_t gvao_idx, bvao_idx;
|
ssize_t gvao_idx;
|
||||||
unsigned int vbo_idx;
|
|
||||||
} OSWindow;
|
} OSWindow;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user