From 447835afc108fe17906a5acaecc65666786df1ab Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 Nov 2019 11:19:52 +0100 Subject: render/gles2: provide public API to access GL texture Prior to this commit, compositors needed to render the texture to an intermediate off-screen buffer using wlr_renderer APIs if they wanted to use a custom rendering path (e.g. render to a 3D scene). A new wlr_gles2_texture_get_attribs exposes the GL texture target and ID so that compositors can render wlr_textures with their own shaders. An example of a compositor doing so is available at [1]. [1]: https://git.sr.ht/~sircmpwn/wxrc/tree/3db905b7842ac42cf1878876e647005b41f00a52/src/render.c#L227 --- include/wlr/render/gles2.h | 13 +++++++++++++ render/gles2/texture.c | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index fca11ab8..b8c9a41a 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -9,6 +9,7 @@ #ifndef WLR_RENDER_GLES2_H #define WLR_RENDER_GLES2_H +#include #include #include @@ -24,4 +25,16 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl, struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, struct wlr_dmabuf_attributes *attribs); +struct wlr_gles2_texture_attribs { + GLenum target; /* either GL_TEXTURE_2D or GL_TEXTURE_EXTERNAL_OES */ + GLuint tex; + + bool inverted_y; + bool has_alpha; +}; + +bool wlr_texture_is_gles2(struct wlr_texture *texture); +void wlr_gles2_texture_get_attribs(struct wlr_texture *texture, + struct wlr_gles2_texture_attribs *attribs); + #endif diff --git a/render/gles2/texture.c b/render/gles2/texture.c index 2ea4adc9..3aa1c005 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -17,9 +17,13 @@ static const struct wlr_texture_impl texture_impl; +bool wlr_texture_is_gles2(struct wlr_texture *wlr_texture) { + return wlr_texture->impl == &texture_impl; +} + struct wlr_gles2_texture *gles2_get_texture( struct wlr_texture *wlr_texture) { - assert(wlr_texture->impl == &texture_impl); + assert(wlr_texture_is_gles2(wlr_texture)); return (struct wlr_gles2_texture *)wlr_texture; } @@ -291,3 +295,13 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl, POP_GLES2_DEBUG; return &texture->wlr_texture; } + +void wlr_gles2_texture_get_attribs(struct wlr_texture *wlr_texture, + struct wlr_gles2_texture_attribs *attribs) { + struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture); + memset(attribs, 0, sizeof(*attribs)); + attribs->target = texture->target; + attribs->tex = texture->tex; + attribs->inverted_y = texture->inverted_y; + attribs->has_alpha = texture->has_alpha; +} -- cgit v1.2.3