diff options
Diffstat (limited to 'render/gles2/renderer.c')
-rw-r--r-- | render/gles2/renderer.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 325e1571..94c50b9a 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -208,7 +208,23 @@ static bool wlr_gles2_buffer_is_drm(struct wlr_renderer *_renderer, (struct wlr_gles2_renderer *)_renderer; EGLint format; return wlr_egl_query_buffer(renderer->egl, buffer, - EGL_TEXTURE_FORMAT, &format); + EGL_TEXTURE_FORMAT, &format); +} + +static void rgba_to_argb(uint32_t *data, size_t height, size_t stride) { + size_t n = height*stride/4; + for (size_t i = 0; i < n; ++i) { + uint32_t v = data[i]; + uint32_t rgb = (v & 0xffffff00) >> 8; + uint32_t a = v & 0x000000ff; + data[i] = rgb | (a << 24); + } +} + +static void wlr_gles2_read_pixels(struct wlr_renderer *renderer, int x, int y, + int width, int height, void *out_data) { + glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, out_data); + rgba_to_argb(out_data, height, width*4); } static struct wlr_renderer_impl wlr_renderer_impl = { @@ -220,6 +236,7 @@ static struct wlr_renderer_impl wlr_renderer_impl = { .render_ellipse = wlr_gles2_render_ellipse, .formats = wlr_gles2_formats, .buffer_is_drm = wlr_gles2_buffer_is_drm, + .read_pixels = wlr_gles2_read_pixels, }; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend) { |