Skip to content

Commit

Permalink
Ensure OS windows have both buffers cleared after a resize/on first r…
Browse files Browse the repository at this point in the history
…ender
  • Loading branch information
kovidgoyal committed Nov 24, 2017
1 parent c7e9082 commit b61c959
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions kitty/child-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ render(double now) {
if (!w->num_tabs || !should_os_window_be_rendered(w)) continue;
make_os_window_context_current(w);
if (w->viewport_size_dirty) {
w->clear_count = 0;
update_surface_size(w->viewport_width, w->viewport_height, w->offscreen_texture_id);
w->viewport_size_dirty = false;
}
Expand Down
1 change: 1 addition & 0 deletions kitty/gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ gl_init() {

void
update_surface_size(int w, int h, GLuint offscreen_texture_id) {
glViewport(0, 0, w, h);
if (offscreen_texture_id) {
glBindTexture(GL_TEXTURE_2D, offscreen_texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
Expand Down
8 changes: 8 additions & 0 deletions kitty/shaders.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ draw_cells_interleaved(ssize_t vao_idx, ssize_t gvao_idx, Screen *screen, OSWind

void
draw_cells(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, Screen *screen, OSWindow *os_window) {
if (os_window->clear_count < 2) {
os_window->clear_count++;
#define C(shift) (((GLfloat)((OPT(background) >> shift) & 0xFF)) / 255.0f)
glClearColor(C(16), C(8), C(0), os_window->is_semi_transparent ? OPT(background_opacity) : 1.0f);
#undef C
glClear(GL_COLOR_BUFFER_BIT);
}

cell_prepare_to_render(vao_idx, gvao_idx, screen, xstart, ystart, dx, dy);
GLfloat w = (GLfloat)screen->columns * dx, h = (GLfloat)screen->lines * dy;
#define SCALE(w, x) ((GLfloat)(os_window->viewport_##w) * (GLfloat)(x))
Expand Down
1 change: 1 addition & 0 deletions kitty/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef struct {
bool has_pending_resizes;
bool is_semi_transparent;
uint32_t offscreen_texture_id;
unsigned int clear_count;
} OSWindow;


Expand Down

0 comments on commit b61c959

Please sign in to comment.