diff options
Diffstat (limited to 'render/gles2')
-rw-r--r-- | render/gles2/renderer.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index d6c22ebe..94c50b9a 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -12,8 +12,8 @@ #include <wlr/render/matrix.h> #include <wlr/util/log.h> #include "render/gles2.h" +#include "render/glapi.h" -PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES = NULL; struct shaders shaders; static bool compile_shader(GLuint type, const GLchar *src, GLuint *shader) { @@ -101,25 +101,7 @@ error: wlr_log(L_ERROR, "Failed to set up default shaders!"); } -static void init_image_ext() { - if (glEGLImageTargetTexture2DOES) { - return; - } - - const char *exts = (const char*) glGetString(GL_EXTENSIONS); - if (strstr(exts, "GL_OES_EGL_image_external")) { - glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) - eglGetProcAddress("glEGLImageTargetTexture2DOES"); - } - - if (!glEGLImageTargetTexture2DOES) { - wlr_log(L_INFO, "Failed to load glEGLImageTargetTexture2DOES " - "Will not be able to attach drm buffers"); - } -} - static void init_globals() { - init_image_ext(); init_default_shaders(); } @@ -226,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 = { @@ -238,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) { |