gl_common: fix coordinate mismatch
Xorg uses top left as origin, OpenGL uses lower left. So we need to flip the y axis, and make sure we are using the right points as origin of windows. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
3b21365e94
commit
198dcdb987
|
@ -611,12 +611,31 @@ static int glx_buffer_age(void *backend_data, session_t *ps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glx_compose(void *backend_data, session_t *ps, win *w, void *win_data,
|
static void glx_compose(void *backend_data, session_t *ps, win *w, void *win_data,
|
||||||
int dst_x, int dst_y, const region_t *region) {
|
int dst_x, int dst_y, const region_t *region) {
|
||||||
struct _glx_data *gd = backend_data;
|
struct _glx_data *gd = backend_data;
|
||||||
struct _glx_win_data *wd = win_data;
|
struct _glx_win_data *wd = win_data;
|
||||||
|
|
||||||
gl_compose(&wd->texture, 0, 0, dst_x, dst_y, w->widthb, w->heightb, 0, 1, true,
|
// OpenGL and Xorg uses different coordinate systems.
|
||||||
false, region, &gd->win_shader);
|
// First, We need to flip the y axis of the paint region
|
||||||
|
region_t region_yflipped;
|
||||||
|
pixman_region32_init(®ion_yflipped);
|
||||||
|
pixman_region32_copy(®ion_yflipped, (region_t *)region);
|
||||||
|
|
||||||
|
int nrects;
|
||||||
|
auto rect = pixman_region32_rectangles(®ion_yflipped, &nrects);
|
||||||
|
for (int i = 0; i < nrects; i++) {
|
||||||
|
auto tmp = rect[i].y1;
|
||||||
|
rect[i].y1 = ps->root_height - rect[i].y2;
|
||||||
|
rect[i].y2 = ps->root_height - tmp;
|
||||||
|
}
|
||||||
|
dump_region(®ion_yflipped);
|
||||||
|
|
||||||
|
// Then, we still need to convert the origin of painting.
|
||||||
|
// Note, in GL coordinates, we need to specified the bottom left corner of the
|
||||||
|
// rectangle, while what we get from the arguments are the top left corner.
|
||||||
|
gl_compose(&wd->texture, 0, 0, dst_x, ps->root_height - dst_y - w->heightb, w->widthb,
|
||||||
|
w->heightb, 0, 1, true, false, ®ion_yflipped, &gd->win_shader);
|
||||||
|
pixman_region32_fini(®ion_yflipped);
|
||||||
}
|
}
|
||||||
|
|
||||||
backend_info_t glx_backend = {
|
backend_info_t glx_backend = {
|
||||||
|
|
Loading…
Reference in New Issue