Clamp border rects to pixels
This uses the same co-ord calculation for border rects as for text cells. DRYer and avoids borders and blank rects being drawn at haf pixel offsets.
This commit is contained in:
parent
072fe91518
commit
a867b4444d
@ -6,7 +6,7 @@ uniform vec3 inactive_border_color;
|
||||
uniform vec3 bell_border_color;
|
||||
uniform vec3 tab_bar_bg;
|
||||
uniform vec3 tab_bar_margin_color;
|
||||
in uvec4 rect; // left, top, right, bottom
|
||||
in vec4 rect; // left, top, right, bottom
|
||||
in uint rect_color;
|
||||
out vec3 color;
|
||||
|
||||
@ -24,13 +24,6 @@ const uvec2 pos_map[] = uvec2[4](
|
||||
uvec2(LEFT, TOP)
|
||||
);
|
||||
|
||||
vec2 to_opengl(uint x, uint y) {
|
||||
return vec2(
|
||||
-1.0 + 2.0 * (float(x) / float(viewport.x)),
|
||||
1.0 - 2.0 * (float(y) / float(viewport.y))
|
||||
);
|
||||
}
|
||||
|
||||
float to_color(uint c) {
|
||||
return float(c & FF) / 255.0;
|
||||
}
|
||||
@ -39,7 +32,7 @@ float to_color(uint c) {
|
||||
|
||||
void main() {
|
||||
uvec2 pos = pos_map[gl_VertexID];
|
||||
gl_Position = vec4(to_opengl(rect[pos.x], rect[pos.y]), 0, 1);
|
||||
gl_Position = vec4(rect[pos.x], rect[pos.y], 0, 1);
|
||||
int rc = int(rect_color);
|
||||
vec3 window_bg = vec3(to_color(rect_color >> 24), to_color(rect_color >> 16), to_color(rect_color >> 8));
|
||||
color = W(0, default_bg) + W(1, active_border_color) + W(2, inactive_border_color) + W(3, window_bg) + W(4, bell_border_color) + W(5, tab_bar_bg) + W(6, tab_bar_margin_color);
|
||||
|
||||
@ -946,9 +946,9 @@ create_border_vao(void) {
|
||||
|
||||
add_buffer_to_vao(vao_idx, GL_ARRAY_BUFFER);
|
||||
add_attribute_to_vao(BORDERS_PROGRAM, vao_idx, "rect",
|
||||
/*size=*/4, /*dtype=*/GL_UNSIGNED_INT, /*stride=*/sizeof(GLuint)*5, /*offset=*/0, /*divisor=*/1);
|
||||
/*size=*/4, /*dtype=*/GL_FLOAT, /*stride=*/sizeof(BorderRect), /*offset=*/(void*)offsetof(BorderRect, left), /*divisor=*/1);
|
||||
add_attribute_to_vao(BORDERS_PROGRAM, vao_idx, "rect_color",
|
||||
/*size=*/1, /*dtype=*/GL_UNSIGNED_INT, /*stride=*/sizeof(GLuint)*5, /*offset=*/(void*)(sizeof(GLuint)*4), /*divisor=*/1);
|
||||
/*size=*/1, /*dtype=*/GL_UNSIGNED_INT, /*stride=*/sizeof(BorderRect), /*offset=*/(void*)(offsetof(BorderRect, color)), /*divisor=*/1);
|
||||
|
||||
return vao_idx;
|
||||
}
|
||||
@ -967,7 +967,7 @@ draw_borders(ssize_t vao_idx, unsigned int num_border_rects, BorderRect *rect_bu
|
||||
bind_vertex_array(vao_idx);
|
||||
bind_program(BORDERS_PROGRAM);
|
||||
if (rect_data_is_dirty) {
|
||||
size_t sz = sizeof(GLuint) * 5 * num_border_rects;
|
||||
const size_t sz = sizeof(BorderRect) * num_border_rects;
|
||||
void *borders_buf_address = alloc_and_map_vao_buffer(vao_idx, sz, 0, GL_STATIC_DRAW, GL_WRITE_ONLY);
|
||||
if (borders_buf_address) memcpy(borders_buf_address, rect_buf, sz);
|
||||
unmap_vao_buffer(vao_idx, 0);
|
||||
|
||||
@ -514,7 +514,11 @@ add_borders_rect(id_type os_window_id, id_type tab_id, uint32_t left, uint32_t t
|
||||
if (!left && !top && !right && !bottom) { br->num_border_rects = 0; return; }
|
||||
ensure_space_for(br, rect_buf, BorderRect, br->num_border_rects + 1, capacity, 32, false);
|
||||
BorderRect *r = br->rect_buf + br->num_border_rects++;
|
||||
r->left = left; r->right = right; r->top = top; r->bottom = bottom; r->color = color;
|
||||
r->left = gl_pos_x(left, osw->viewport_width);
|
||||
r->top = gl_pos_y(top, osw->viewport_height);
|
||||
r->right = r->left + gl_size(right - left, osw->viewport_width);
|
||||
r->bottom = r->top - gl_size(bottom - top, osw->viewport_height);
|
||||
r->color = color;
|
||||
END_WITH_TAB
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +142,8 @@ typedef struct {
|
||||
} Window;
|
||||
|
||||
typedef struct {
|
||||
uint32_t left, top, right, bottom, color;
|
||||
float left, top, right, bottom;
|
||||
uint32_t color;
|
||||
} BorderRect;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user