mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 12:55:58 +01:00
render/gles2: use byte-aligned rows for glReadPixels
Setting the GLESv2 parameter GL_PACK_ALIGNMENT to 1 ensures that the stride of the glReadPixels output matches the value computed in `pack_stride`. Since the default value of GL_PACK_ALIGNMENT is 4, this does not make a difference under normal use; but without this patch the stride can be incorrect; for example, with RGB565 buffers and screenshots of regions with odd width.
This commit is contained in:
parent
9affcaa93c
commit
40dde59475
1 changed files with 2 additions and 1 deletions
|
@ -473,6 +473,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
||||||
glGetError(); // Clear the error flag
|
glGetError(); // Clear the error flag
|
||||||
|
|
||||||
unsigned char *p = (unsigned char *)data + dst_y * stride;
|
unsigned char *p = (unsigned char *)data + dst_y * stride;
|
||||||
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
uint32_t pack_stride = width * drm_fmt->bpp / 8;
|
uint32_t pack_stride = width * drm_fmt->bpp / 8;
|
||||||
if (pack_stride == stride && dst_x == 0) {
|
if (pack_stride == stride && dst_x == 0) {
|
||||||
// Under these particular conditions, we can read the pixels with only
|
// Under these particular conditions, we can read the pixels with only
|
||||||
|
@ -480,7 +481,7 @@ static bool gles2_read_pixels(struct wlr_renderer *wlr_renderer,
|
||||||
|
|
||||||
glReadPixels(src_x, src_y, width, height, fmt->gl_format, fmt->gl_type, p);
|
glReadPixels(src_x, src_y, width, height, fmt->gl_format, fmt->gl_type, p);
|
||||||
} else {
|
} else {
|
||||||
// Unfortunately GLES2 doesn't support GL_PACK_*, so we have to read
|
// Unfortunately GLES2 doesn't support GL_PACK_ROW_LENGTH, so we have to read
|
||||||
// the lines out row by row
|
// the lines out row by row
|
||||||
for (size_t i = 0; i < height; ++i) {
|
for (size_t i = 0; i < height; ++i) {
|
||||||
uint32_t y = src_y + i;
|
uint32_t y = src_y + i;
|
||||||
|
|
Loading…
Reference in a new issue