backend: gl: fix x_rect_to_coords when y_inverted is false

Since image_dst is in X coordinates, after flipping Y, we need to
subtract the height of the drawing area, to make it the bottom right
corner for OpenGL.

However, this breaks blur. Because we assumed the drawing area is the
same size as the texture, which is not the case for blur. So add the
height of the drawing area as another parameter.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2022-08-25 17:49:37 +01:00
parent 94e3d4d483
commit de209fd52c
No known key found for this signature in database
GPG Key ID: D3A4405BE6CC17F4
3 changed files with 18 additions and 17 deletions

View File

@ -322,16 +322,17 @@ bool gl_blur_impl(double opacity, struct gl_blur_context *bctx, void *mask,
auto coord = ccalloc(nrects * 16, GLint);
auto indices = ccalloc(nrects * 6, GLuint);
x_rect_to_coords(nrects, rects,
(coord_t){.x = extent_resized->x1, .y = extent_resized->y2},
bctx->fb_height, source_size.height, false, coord, indices);
auto extent_height = extent_resized->y2 - extent_resized->y1;
x_rect_to_coords(
nrects, rects, (coord_t){.x = extent_resized->x1, .y = extent_resized->y1},
extent_height, bctx->fb_height, source_size.height, false, coord, indices);
auto coord_resized = ccalloc(nrects_resized * 16, GLint);
auto indices_resized = ccalloc(nrects_resized * 6, GLuint);
x_rect_to_coords(nrects_resized, rects_resized,
(coord_t){.x = extent_resized->x1, .y = extent_resized->y2},
bctx->fb_height, bctx->fb_height, false, coord_resized,
indices_resized);
(coord_t){.x = extent_resized->x1, .y = extent_resized->y1},
extent_height, bctx->fb_height, bctx->fb_height, false,
coord_resized, indices_resized);
pixman_region32_fini(&reg_blur_resized);
GLuint vao[2];

View File

@ -482,16 +482,16 @@ static void _gl_compose(backend_t *base, struct backend_image *img, GLuint targe
/// @param[in] nrects, rects rectangles
/// @param[in] image_dst origin of the OpenGL texture, affect the calculated texture
/// coordinates
/// @param[in] extend_height height of the drawing extent
/// @param[in] texture_height height of the OpenGL texture
/// @param[in] root_height height of the back buffer
/// @param[in] y_inverted whether the texture is y inverted
/// @param[out] coord, indices output
void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst, int texture_height,
int root_height, bool y_inverted, GLint *coord, GLuint *indices) {
void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst,
int extent_height, int texture_height, int root_height,
bool y_inverted, GLint *coord, GLuint *indices) {
image_dst.y = root_height - image_dst.y;
if (y_inverted) {
image_dst.y -= texture_height;
}
image_dst.y -= extent_height;
for (int i = 0; i < nrects; i++) {
// Y-flip. Note after this, crect.y1 > crect.y2
@ -568,8 +568,8 @@ void gl_compose(backend_t *base, void *image_data, coord_t image_dst, void *mask
auto coord = ccalloc(nrects * 16, GLint);
auto indices = ccalloc(nrects * 6, GLuint);
coord_t mask_offset = {.x = mask_dst.x - image_dst.x, .y = mask_dst.y - image_dst.y};
x_rect_to_coords(nrects, rects, image_dst, inner->height, gd->height,
inner->y_inverted, coord, indices);
x_rect_to_coords(nrects, rects, image_dst, inner->height, inner->height,
gd->height, inner->y_inverted, coord, indices);
_gl_compose(base, img, gd->back_fbo, mask, mask_offset, coord, indices, nrects);
free(indices);
@ -1157,7 +1157,6 @@ enum device_status gl_device_status(backend_t *base) {
}
if (glGetGraphicsResetStatusARB() == GL_NO_ERROR) {
return DEVICE_STATUS_NORMAL;
} else {
return DEVICE_STATUS_RESETTING;
}
return DEVICE_STATUS_RESETTING;
}

View File

@ -118,8 +118,9 @@ typedef struct session session_t;
#define GL_PROG_MAIN_INIT \
{ .prog = 0, .unifm_opacity = -1, .unifm_invert_color = -1, .unifm_tex = -1, }
void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst, int texture_height,
int root_height, bool y_inverted, GLint *coord, GLuint *indices);
void x_rect_to_coords(int nrects, const rect_t *rects, coord_t image_dst,
int extent_height, int texture_height, int root_height,
bool y_inverted, GLint *coord, GLuint *indices);
GLuint gl_create_shader(GLenum shader_type, const char *shader_str);
GLuint gl_create_program(const GLuint *const shaders, int nshaders);